~cairo-dock-team/ubuntu/quantal/cairo-dock-plug-ins/3.0.2

« back to all changes in this revision

Viewing changes to clock/src/applet-calendar.c

Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#include <stdlib.h>
 
21
#include <math.h>
 
22
#define __USE_POSIX
 
23
#include <signal.h>
 
24
 
 
25
#include "applet-struct.h"
 
26
#include "applet-task-editor.h"
 
27
#include "applet-calendar.h"
 
28
 
 
29
#define _cd_task_matches_month(pTask, iMonth, iYear) (((pTask)->iMonth == iMonth && ((pTask)->iYear == iYear || (pTask)->iFrequency == CD_TASK_EACH_YEAR)) || (pTask)->iFrequency == CD_TASK_EACH_MONTH)
 
30
#define _cd_task_matches_day(pTask, iDay, iMonth, iYear) ((pTask)->iDay == iDay && _cd_task_matches_month (pTask, iMonth, iYear))
 
31
 
 
32
 
 
33
  /////////////
 
34
 // BACKEND //
 
35
/////////////
 
36
 
 
37
void cd_clock_register_backend (CairoDockModuleInstance *myApplet, const gchar *cBackendName, CDClockTaskBackend *pBackend)
 
38
{
 
39
        if (myData.pBackends == NULL)
 
40
                myData.pBackends = g_hash_table_new_full (g_str_hash,
 
41
                        g_str_equal,
 
42
                        g_free,
 
43
                        g_free);
 
44
        g_hash_table_insert (myData.pBackends, g_strdup (cBackendName), pBackend);
 
45
}
 
46
 
 
47
CDClockTaskBackend *cd_clock_get_backend (CairoDockModuleInstance *myApplet, const gchar *cBackendName)
 
48
{
 
49
        CDClockTaskBackend *pBackend = NULL;
 
50
        if (cBackendName != NULL)
 
51
                pBackend = g_hash_table_lookup (myData.pBackends, cBackendName);
 
52
        
 
53
        return pBackend;
 
54
}
 
55
 
 
56
void cd_clock_set_current_backend (CairoDockModuleInstance *myApplet)
 
57
{
 
58
        if (myData.pBackend && myData.pBackend->stop)
 
59
                myData.pBackend->stop (myApplet);
 
60
        myData.pBackend = cd_clock_get_backend (myApplet, myConfig.cTaskMgrName);
 
61
        if (myData.pBackend == NULL)
 
62
                myData.pBackend = cd_clock_get_backend (myApplet, "Default");
 
63
        if (myData.pBackend->init)
 
64
                myData.pBackend->init (myApplet);
 
65
}
 
66
 
 
67
 
 
68
  ///////////
 
69
 // TASKS //
 
70
///////////
 
71
 
 
72
static int _compare_task (CDClockTask *pTask1, CDClockTask *pTask2, gpointer data)
 
73
{
 
74
        if (pTask1->iYear < pTask2->iYear)
 
75
                return -1;
 
76
        if (pTask1->iYear > pTask2->iYear)
 
77
                return 1;
 
78
        
 
79
        if (pTask1->iMonth < pTask2->iMonth)
 
80
                return -1;
 
81
        if (pTask1->iMonth > pTask2->iMonth)
 
82
                return 1;
 
83
        
 
84
        if (pTask1->iDay < pTask2->iDay)
 
85
                return -1;
 
86
        if (pTask1->iDay > pTask2->iDay)
 
87
                return 1;
 
88
        
 
89
        if (pTask1->iHour < pTask2->iHour)
 
90
                return -1;
 
91
        if (pTask1->iHour > pTask2->iHour)
 
92
                return 1;
 
93
        
 
94
        if (pTask1->iMinute < pTask2->iMinute)
 
95
                return -1;
 
96
        if (pTask1->iMinute > pTask2->iMinute)
 
97
                return 1;
 
98
        
 
99
        return 0;
 
100
        
 
101
}
 
102
void cd_clock_list_tasks (CairoDockModuleInstance *myApplet)
 
103
{
 
104
        cd_message ("%s ()", __func__);
 
105
        if (myData.pTasks != NULL)
 
106
                cd_clock_reset_tasks_list (myApplet);
 
107
        
 
108
        myData.pTasks = myData.pBackend->get_tasks (myApplet);
 
109
        CDClockTask *pTask;
 
110
        GList *t;
 
111
        for (t = myData.pTasks; t != NULL; t = t->next)
 
112
        {
 
113
                pTask = t->data;
 
114
                pTask->pApplet = myApplet;
 
115
        }
 
116
        myData.pTasks = g_list_sort_with_data (myData.pTasks,
 
117
                (GCompareDataFunc) _compare_task,
 
118
                NULL);
 
119
        myData.pNextTask = cd_clock_get_next_scheduled_task (myApplet);
 
120
        myData.pNextAnniversary = cd_clock_get_next_anniversary (myApplet);
 
121
}
 
122
 
 
123
void cd_clock_add_task_to_list (CDClockTask *pTask, CairoDockModuleInstance *myApplet)
 
124
{
 
125
        pTask->pApplet = myApplet;
 
126
        myData.pTasks = g_list_insert_sorted (myData.pTasks, pTask, (GCompareFunc)_compare_task);
 
127
        myData.pNextTask = cd_clock_get_next_scheduled_task (myApplet);
 
128
        myData.pNextAnniversary = cd_clock_get_next_anniversary (myApplet);
 
129
}
 
130
 
 
131
void cd_clock_remove_task_from_list (CDClockTask *pTask, CairoDockModuleInstance *myApplet)
 
132
{
 
133
        myData.pTasks = g_list_remove (myData.pTasks, pTask);
 
134
        myData.pNextTask = cd_clock_get_next_scheduled_task (myApplet);
 
135
        myData.pNextAnniversary = cd_clock_get_next_anniversary (myApplet);
 
136
}
 
137
 
 
138
void cd_clock_free_task (CDClockTask *pTask)
 
139
{
 
140
        if (pTask == NULL)
 
141
                return;
 
142
        if (pTask->iSidWarning != 0)
 
143
                g_source_remove (pTask->iSidWarning);
 
144
        if (pTask->pWarningDialog != NULL)
 
145
                cairo_dock_dialog_unreference (pTask->pWarningDialog);
 
146
        g_free (pTask->cTitle);
 
147
        g_free (pTask->cText);
 
148
        g_free (pTask->cTags);
 
149
        g_free (pTask->cID);
 
150
        g_free (pTask);
 
151
}
 
152
 
 
153
void cd_clock_reset_tasks_list (CairoDockModuleInstance *myApplet)
 
154
{
 
155
        g_list_foreach (myData.pTasks, (GFunc)cd_clock_free_task, NULL);
 
156
        g_list_free (myData.pTasks);
 
157
        myData.pTasks = NULL;
 
158
        myData.pNextTask = NULL;
 
159
}
 
160
 
 
161
CDClockTask *cd_clock_get_task_by_id (const gchar *cID, CairoDockModuleInstance *myApplet)
 
162
{
 
163
        if (cID == NULL)
 
164
                return NULL;
 
165
        CDClockTask *pTask;
 
166
        GList *t;
 
167
        for (t = myData.pTasks; t != NULL; t = t->next)
 
168
        {
 
169
                pTask = t->data;
 
170
                if (strcmp (pTask->cID, cID) == 0)
 
171
                        return pTask;
 
172
        }
 
173
        return NULL;
 
174
}
 
175
 
 
176
gchar *cd_clock_get_tasks_for_today (CairoDockModuleInstance *myApplet)
 
177
{
 
178
        guint iDay = myData.currentTime.tm_mday, iMonth = myData.currentTime.tm_mon, iYear = myData.currentTime.tm_year + 1900;
 
179
        
 
180
        GString *sTaskString = NULL;
 
181
        CDClockTask *pTask;
 
182
        GList *t;
 
183
        for (t = myData.pTasks; t != NULL; t = t->next)
 
184
        {
 
185
                pTask = t->data;
 
186
                if (_cd_task_matches_day (pTask, iDay, iMonth, iYear))
 
187
                {
 
188
                        if (sTaskString == NULL)
 
189
                                sTaskString = g_string_new ("");
 
190
                        g_string_append_printf (sTaskString, "<b><u>%s</u></b>\n <i>at %d:%02d</i>\n %s\n", pTask->cTitle ? pTask->cTitle : D_("No title"), pTask->iHour, pTask->iMinute, pTask->cText?pTask->cText:"");
 
191
                }
 
192
        }
 
193
        
 
194
        if (sTaskString == NULL)
 
195
                return NULL;
 
196
        
 
197
        gchar *cTasks = sTaskString->str;
 
198
        g_string_free (sTaskString, FALSE);
 
199
        return cTasks;
 
200
}
 
201
 
 
202
gchar *cd_clock_get_tasks_for_this_week (CairoDockModuleInstance *myApplet)
 
203
{
 
204
        guint iDay = myData.currentTime.tm_mday, iMonth = myData.currentTime.tm_mon, iYear = myData.currentTime.tm_year + 1900;
 
205
        
 
206
        GDate* pCurrentDate = g_date_new_dmy (iDay, iMonth + 1, iYear);
 
207
        GDate* pDate = g_date_new ();
 
208
        guint d, m, y;
 
209
        int iDelta;
 
210
        GString *sTaskString = NULL;
 
211
        CDClockTask *pTask;
 
212
        GList *t;
 
213
        for (t = myData.pTasks; t != NULL; t = t->next)
 
214
        {
 
215
                pTask = t->data;
 
216
                switch (pTask->iFrequency)
 
217
                {
 
218
                        case CD_TASK_DONT_REPEAT:
 
219
                        default:
 
220
                                d = pTask->iDay;
 
221
                                m = pTask->iMonth+1;
 
222
                                y = pTask->iYear;
 
223
                                g_date_set_dmy (pDate, d, m, y);
 
224
                                iDelta = g_date_days_between (pCurrentDate, pDate);
 
225
                        break;
 
226
                        
 
227
                        case CD_TASK_EACH_MONTH:
 
228
                                d = pTask->iDay;
 
229
                                m = iMonth+1;
 
230
                                y = iYear;
 
231
                                g_date_set_dmy (pDate, d, m, y);
 
232
                                iDelta = g_date_days_between (pCurrentDate, pDate);
 
233
                                if (iDelta < 0)  // pDate est avant pCurrentDate => on teste le mois d'apres.
 
234
                                {
 
235
                                        if (iMonth < 11)
 
236
                                        {
 
237
                                                m = iMonth+2;
 
238
                                                g_date_set_dmy (pDate, d, m, y);
 
239
                                        }
 
240
                                        else
 
241
                                        {
 
242
                                                m = 1;
 
243
                                                y = pTask->iYear + 1;
 
244
                                                g_date_set_dmy (pDate, d, m, y);
 
245
                                        }
 
246
                                        iDelta = g_date_days_between (pCurrentDate, pDate);
 
247
                                }
 
248
                        break;
 
249
                        
 
250
                        case CD_TASK_EACH_YEAR:
 
251
                                d = pTask->iDay;
 
252
                                m = pTask->iMonth+1;
 
253
                                y = iYear;
 
254
                                g_date_set_dmy (pDate, d, m, y);
 
255
                                iDelta = g_date_days_between (pCurrentDate, pDate);
 
256
                                //g_print ("iDelta : %d/%d/%d -> %d (%s)\n", d, m, y, iDelta, pTask->cTitle);
 
257
                                if (iDelta < 0)  // pDate est avant pCurrentDate => on teste l'annee d'apres.
 
258
                                {
 
259
                                        y = iYear + 1;
 
260
                                        g_date_set_dmy (pDate, d, m, y);
 
261
                                        iDelta = g_date_days_between (pCurrentDate, pDate);
 
262
                                }
 
263
                        break;
 
264
                }
 
265
                
 
266
                if (iDelta >= 0 && iDelta < 7)
 
267
                {
 
268
                        if (sTaskString == NULL)
 
269
                                sTaskString = g_string_new ("");
 
270
                        g_string_append_printf (sTaskString, "<b><u>%s</u></b>\n <i>%d/%d/%d at %d:%02d</i>\n %s\n",
 
271
                                pTask->cTitle ? pTask->cTitle : D_("No title"),
 
272
                                (myConfig.bNormalDate ? d : y), m, (myConfig.bNormalDate ? y : d),
 
273
                                pTask->iHour, pTask->iMinute,
 
274
                                pTask->cText?pTask->cText:"");
 
275
                }  // on n'arrete pas le parcours si iDelta > 7 pour prendre en compte aussi les anniv.
 
276
        }
 
277
        g_date_free (pCurrentDate);
 
278
        g_date_free (pDate);
 
279
        
 
280
        if (sTaskString == NULL)
 
281
                return NULL;
 
282
        
 
283
        gchar *cTasks = sTaskString->str;
 
284
        g_string_free (sTaskString, FALSE);
 
285
        return cTasks;
 
286
}
 
287
 
 
288
#define _compute_index(y,m,d,h,mi) ((((y*12+m)*32+d)*24+h)*60+mi)
 
289
CDClockTask *cd_clock_get_next_scheduled_task (CairoDockModuleInstance *myApplet)
 
290
{
 
291
        if (myData.pTasks == NULL)
 
292
                return NULL;
 
293
        
 
294
        guint iDay = myData.currentTime.tm_mday;
 
295
        guint iMonth = myData.currentTime.tm_mon;
 
296
        guint iYear = myData.currentTime.tm_year + 1900;
 
297
        guint iHour = myData.currentTime.tm_hour;
 
298
        guint iMinute = myData.currentTime.tm_min;
 
299
        gulong iIndex = _compute_index (iYear, iMonth, iDay, iHour, iMinute);
 
300
        gulong i, iNextIndex=0;
 
301
        //g_print ("%s (%d/%d/%d -> %ld)\n", __func__, iDay, iMonth, iYear, iIndex);
 
302
        
 
303
        CDClockTask *pNextTask = NULL;
 
304
        CDClockTask *pTask;
 
305
        GList *t;
 
306
        for (t = myData.pTasks; t != NULL; t = t->next)
 
307
        {
 
308
                pTask = t->data;
 
309
                //g_print ("test de %s (%d/%d/%d)\n", pTask->cTitle, pTask->iDay, pTask->iMonth, pTask->iYear);
 
310
                switch (pTask->iFrequency)
 
311
                {
 
312
                        case CD_TASK_DONT_REPEAT:
 
313
                        default:
 
314
                                i = _compute_index (pTask->iYear, pTask->iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);
 
315
                                //g_print (" normal : %ld\n", i);
 
316
                        break;
 
317
                        
 
318
                        case CD_TASK_EACH_MONTH:
 
319
                                i = _compute_index (iYear, iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);  // index pour le mois courant.
 
320
                                if (i < iIndex)  // on tombe avant, on calcule l'index pour le mois suivant.
 
321
                                {
 
322
                                        if (iMonth < 11)
 
323
                                                i = _compute_index (iYear, iMonth+1, pTask->iDay, pTask->iHour, pTask->iMinute);
 
324
                                        else
 
325
                                                i = _compute_index (iYear+1, 0, pTask->iDay, pTask->iHour, pTask->iMinute);
 
326
                                }
 
327
                                //g_print (" mensuel : %ld\n", i);
 
328
                        break;
 
329
                        
 
330
                        case CD_TASK_EACH_YEAR:
 
331
                                i = _compute_index (iYear, pTask->iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);
 
332
                                if (i < iIndex)  // on tombe avant, on calcule l'index pour l'annee suivante.
 
333
                                        i = _compute_index (iYear+1, pTask->iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);
 
334
                                //g_print (" annuel : %ld\n", i);
 
335
                        break;
 
336
                }
 
337
                if (i >= iIndex && (iNextIndex == 0 || i < iNextIndex))
 
338
                {
 
339
                        iNextIndex = i;
 
340
                        pNextTask = pTask;
 
341
                        //g_print ("pNextTask <- %s, index <- %ld\n", pNextTask->cTitle, iNextIndex);
 
342
                }
 
343
        }
 
344
        return pNextTask;
 
345
}
 
346
 
 
347
CDClockTask *cd_clock_get_next_anniversary (CairoDockModuleInstance *myApplet)
 
348
{
 
349
        if (myData.pTasks == NULL)
 
350
                return NULL;
 
351
        
 
352
        guint iDay = myData.currentTime.tm_mday;
 
353
        guint iMonth = myData.currentTime.tm_mon;
 
354
        guint iYear = myData.currentTime.tm_year + 1900;
 
355
        guint iHour = myData.currentTime.tm_hour;
 
356
        guint iMinute = myData.currentTime.tm_min;
 
357
        gulong iIndex = _compute_index (iYear, iMonth, iDay, iHour, iMinute);
 
358
        gulong i, iNextIndex=0;
 
359
        //g_print ("%s (%d/%d/%d -> %ld)\n", __func__, iDay, iMonth, iYear, iIndex);
 
360
        
 
361
        CDClockTask *pNextAnniversary = NULL;
 
362
        CDClockTask *pTask;
 
363
        GList *t;
 
364
        for (t = myData.pTasks; t != NULL; t = t->next)
 
365
        {
 
366
                pTask = t->data;
 
367
                if (pTask->iFrequency != CD_TASK_EACH_YEAR)
 
368
                        continue;
 
369
                //g_print ("test de %s (%d/%d/%d)\n", pTask->cTitle, pTask->iDay, pTask->iMonth, pTask->iYear);
 
370
                
 
371
                i = _compute_index (iYear, pTask->iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);
 
372
                if (i < iIndex)  // on tombe avant, on calcule l'index pour l'annee suivante.
 
373
                        i = _compute_index (iYear+1, pTask->iMonth, pTask->iDay, pTask->iHour, pTask->iMinute);
 
374
                //g_print (" annuel : %ld\n", i);
 
375
                
 
376
                if (i > iIndex && (iNextIndex == 0 || i < iNextIndex))
 
377
                {
 
378
                        iNextIndex = i;
 
379
                        pNextAnniversary = pTask;
 
380
                        //g_print ("pNextTask <- %s, index <- %ld\n", pNextTask->cTitle, iNextIndex);
 
381
                }
 
382
        }
 
383
        return pNextAnniversary;
 
384
}
 
385
 
 
386
 
 
387
  //////////////
 
388
 // CALENDAR //
 
389
//////////////
 
390
 
 
391
static void _mark_days (GtkCalendar *pCalendar, CairoDockModuleInstance *myApplet)
 
392
{
 
393
        guint iYear, iMonth, iDay;
 
394
        gtk_calendar_get_date (GTK_CALENDAR (pCalendar),
 
395
                &iYear,
 
396
                &iMonth,
 
397
                &iDay);
 
398
        
 
399
        CDClockTask *pTask;
 
400
        GList *t;
 
401
        for (t = myData.pTasks; t != NULL; t = t->next)
 
402
        {
 
403
                pTask = t->data;
 
404
                if (_cd_task_matches_month (pTask, iMonth, iYear))
 
405
                {
 
406
                        gtk_calendar_mark_day (GTK_CALENDAR (pCalendar), pTask->iDay);
 
407
                }
 
408
        }
 
409
}
 
410
void cd_clock_update_calendar_marks (CairoDockModuleInstance *myApplet)
 
411
{
 
412
        if (myData.pCalendarDialog != NULL)
 
413
        {
 
414
                gtk_calendar_clear_marks (GTK_CALENDAR (myData.pCalendarDialog->pInteractiveWidget));
 
415
                _mark_days (GTK_CALENDAR (myData.pCalendarDialog->pInteractiveWidget), myApplet);
 
416
        }
 
417
}
 
418
 
 
419
static gchar * _on_display_task_detail (GtkCalendar *calendar, guint iYear, guint iMonth, guint iDay, CairoDockModuleInstance *myApplet)
 
420
{
 
421
        if (myData.pTasks == NULL)
 
422
                return NULL;
 
423
        
 
424
        //g_print ("%s (%d/%d/%d)\n", __func__, iDay, iMonth, iYear);
 
425
        GString *sDetail = NULL;
 
426
        CDClockTask *pTask;
 
427
        GList *t;
 
428
        for (t = myData.pTasks; t != NULL; t = t->next)
 
429
        {
 
430
                pTask = t->data;
 
431
                if (_cd_task_matches_day (pTask, iDay, iMonth, iYear))
 
432
                {
 
433
                        if (sDetail == NULL)
 
434
                                sDetail = g_string_new ("");
 
435
                        if (pTask->iFrequency == CD_TASK_EACH_YEAR && iYear > pTask->iYear)
 
436
                                g_string_append_printf (sDetail, "<b><u>%s</u> (%d %s)</b>\n <i>at %d:%02d</i>\n %s\n",
 
437
                                        pTask->cTitle ? pTask->cTitle : D_("No title"),
 
438
                                        iYear - pTask->iYear, D_("years"),
 
439
                                        pTask->iHour, pTask->iMinute,
 
440
                                        pTask->cText?pTask->cText:"");
 
441
                        else
 
442
                                g_string_append_printf (sDetail, "<b><u>%s</u></b>\n <i>at %d:%02d</i>\n %s\n", pTask->cTitle ? pTask->cTitle : D_("No title"),
 
443
                                pTask->iHour, pTask->iMinute,
 
444
                                pTask->cText?pTask->cText:"");
 
445
                }
 
446
        }
 
447
        
 
448
        if (sDetail == NULL)
 
449
                return NULL;
 
450
        gchar *cDetail= sDetail->str;
 
451
        g_string_free (sDetail, FALSE);
 
452
        //g_print ("* detail : %s\n", cDetail);
 
453
        return cDetail;
 
454
}
 
455
 
 
456
static void _on_day_selected (GtkCalendar *pCalendar, CairoDockModuleInstance *myApplet)
 
457
{
 
458
        //g_print ("%s ()\n", __func__);
 
459
        
 
460
}
 
461
 
 
462
static void _on_day_selected_double_click (GtkCalendar *pCalendar, CairoDockModuleInstance *myApplet)
 
463
{
 
464
        guint iDay, iMonth, iYear;
 
465
        gtk_calendar_get_date (pCalendar,
 
466
                &iYear,
 
467
                &iMonth,
 
468
                &iDay);
 
469
        cd_clock_build_task_editor (iDay, iMonth, iYear, myApplet);
 
470
}
 
471
 
 
472
static void _on_month_changed (GtkCalendar *pCalendar, CairoDockModuleInstance *myApplet)
 
473
{
 
474
        gtk_calendar_clear_marks (pCalendar);
 
475
        _mark_days (pCalendar, myApplet);
 
476
}
 
477
 
 
478
static void _on_year_changed (GtkCalendar *pCalendar, CairoDockModuleInstance *myApplet)
 
479
{
 
480
        gtk_calendar_clear_marks (pCalendar);
 
481
        _mark_days (pCalendar, myApplet);
 
482
}
 
483
 
 
484
static gboolean on_button_press_calendar (GtkWidget *widget,
 
485
        GdkEventButton *pButton,
 
486
        CairoDockModuleInstance *myApplet)
 
487
{
 
488
        myData.iButtonPressTime = pButton->time;
 
489
        return FALSE;
 
490
}
 
491
 
 
492
static GtkWidget *cd_clock_build_calendar (CairoDockModuleInstance *myApplet)
 
493
{
 
494
        cd_message ("%s ()", __func__);
 
495
        GtkWidget *pCalendar = gtk_calendar_new ();
 
496
        g_object_set (G_OBJECT (pCalendar), "show-details", FALSE, NULL);
 
497
        
 
498
        _mark_days (GTK_CALENDAR (pCalendar), myApplet);
 
499
        
 
500
        g_signal_connect (G_OBJECT (pCalendar), "day-selected" , G_CALLBACK (_on_day_selected), myApplet);
 
501
        g_signal_connect (G_OBJECT (pCalendar), "day-selected-double-click" , G_CALLBACK (_on_day_selected_double_click), myApplet);
 
502
        g_signal_connect (G_OBJECT (pCalendar), "prev-month" , G_CALLBACK (_on_month_changed), myApplet);
 
503
        g_signal_connect (G_OBJECT (pCalendar), "next-month" , G_CALLBACK (_on_month_changed), myApplet);
 
504
        g_signal_connect (G_OBJECT (pCalendar), "prev-year" , G_CALLBACK (_on_year_changed), myApplet);
 
505
        g_signal_connect (G_OBJECT (pCalendar), "next-year" , G_CALLBACK (_on_year_changed), myApplet);
 
506
        g_signal_connect (G_OBJECT (pCalendar),
 
507
                "button-press-event",
 
508
                G_CALLBACK (on_button_press_calendar),
 
509
                myApplet);
 
510
        
 
511
#if (GTK_MAJOR_VERSION > 2 || GTK_MINOR_VERSION > 14)
 
512
        gtk_calendar_set_detail_func (GTK_CALENDAR (pCalendar),
 
513
                (GtkCalendarDetailFunc) _on_display_task_detail,
 
514
                myApplet,
 
515
                (GDestroyNotify) NULL);
 
516
#endif
 
517
        return pCalendar;
 
518
}
 
519
 
 
520
void cd_clock_hide_dialogs (CairoDockModuleInstance *myApplet)
 
521
{
 
522
        cairo_dock_remove_dialog_if_any (myIcon);
 
523
        myData.pCalendarDialog = NULL;
 
524
}
 
525
 
 
526
static gboolean on_button_press_dialog (GtkWidget *widget,
 
527
        GdkEventButton *pButton,
 
528
        CairoDockModuleInstance *myApplet)
 
529
{
 
530
        CD_APPLET_ENTER;
 
531
        if (pButton->time > myData.iButtonPressTime)
 
532
        {
 
533
                cairo_dock_dialog_unreference (myData.pCalendarDialog);
 
534
                myData.pCalendarDialog = NULL;
 
535
        }
 
536
        CD_APPLET_LEAVE (FALSE);
 
537
}
 
538
void cd_clock_show_hide_calendar (CairoDockModuleInstance *myApplet)
 
539
{
 
540
        if (myData.pCalendarDialog != NULL)
 
541
        {
 
542
                cairo_dock_dialog_unreference (myData.pCalendarDialog);
 
543
                myData.pCalendarDialog = NULL;
 
544
                if (myData.pTaskWindow != NULL)
 
545
                {
 
546
                        gtk_widget_destroy (myData.pTaskWindow);
 
547
                        myData.pTaskWindow = NULL;
 
548
                        myData.pModel = NULL;
 
549
                }
 
550
        }
 
551
        else
 
552
        {
 
553
                cairo_dock_remove_dialog_if_any (myIcon);
 
554
                GtkWidget *pCalendar = cd_clock_build_calendar (myApplet);
 
555
                myData.pCalendarDialog = cairo_dock_show_dialog_full (D_("Calendar and tasks"),
 
556
                        myIcon, myContainer,
 
557
                        0,
 
558
                        MY_APPLET_SHARE_DATA_DIR"/dates.svg",
 
559
                        pCalendar,
 
560
                        NULL, NULL, NULL);
 
561
                g_signal_connect (G_OBJECT (myData.pCalendarDialog->container.pWidget),
 
562
                        "button-press-event",
 
563
                        G_CALLBACK (on_button_press_dialog),
 
564
                        myApplet);
 
565
        }
 
566
}