42
static void _set_warning_repetition (int iClickedButton, GtkWidget *pInteractiveWidget, CDClockTask *pTask, CairoDialog *pDialog);
43
static gboolean _task_warning (CDClockTask *pTask, const gchar *cMessage)
45
cd_debug ("%s (%s)", __func__, cMessage);
46
CairoDockModuleInstance *myApplet = pTask->pApplet;
48
GtkWidget *pScale = gtk_hscale_new_with_range (1, 60, 1); // 1mn-60mn et 1 cran/mn.
49
gtk_scale_set_digits (GTK_SCALE (pScale), 0);
50
gtk_range_set_value (GTK_RANGE (pScale), pTask->iWarningDelay != 0 ? pTask->iWarningDelay : 15); // 15mn par defaut.
51
gtk_widget_set (pScale, "width-request", CAIRO_DIALOG_MIN_SCALE_WIDTH, NULL);
53
GtkWidget *pExtendedWidget = gtk_hbox_new (FALSE, 0);
54
GtkWidget *label = gtk_label_new (D_("1mn"));
55
GtkWidget *pAlign = gtk_alignment_new (1., 1., 0., 0.);
56
gtk_container_add (GTK_CONTAINER (pAlign), label);
57
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pAlign, FALSE, FALSE, 0);
58
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pScale, FALSE, FALSE, 0);
59
label = gtk_label_new (D_("1h"));
60
pAlign = gtk_alignment_new (1., 1., 0., 0.);
61
gtk_container_add (GTK_CONTAINER (pAlign), label);
62
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pAlign, FALSE, FALSE, 0);
64
cairo_dock_dialog_unreference (pTask->pWarningDialog);
65
myDialogs.dialogTextDescription.bUseMarkup = TRUE;
66
pTask->pWarningDialog = cairo_dock_show_dialog_full (cMessage,
68
(pTask->iWarningDelay != 0 ? MIN (pTask->iWarningDelay-.1, 15.) : 15) * 60e3, // on laisse le dialogue visible le plus longtemps possible, jusqu'a 15mn.
69
MY_APPLET_SHARE_DATA_DIR"/icon-task.png",
71
(CairoDockActionOnAnswerFunc) _set_warning_repetition,
74
myDialogs.dialogTextDescription.bUseMarkup = FALSE;
76
CD_APPLET_DEMANDS_ATTENTION (NULL, 3600); // ~ 1h, pour si on loupe le dialogue.
79
static gboolean _task_warning_repeat (CDClockTask *pTask, const gchar *cMessage)
81
gchar *cText = g_strdup_printf ("%s %d:%02d\n<b>%s</b>\n %s\n\n%s",
82
D_("The following task was scheduled at"), pTask->iHour, pTask->iMinute,
83
pTask->cTitle?pTask->cTitle:D_("No title"),
84
pTask->cText?pTask->cText:"",
85
D_("Repeat this message every:"));
86
_task_warning (pTask, cText);
90
static void _set_warning_repetition (int iClickedButton, GtkWidget *pInteractiveWidget, CDClockTask *pTask, CairoDialog *pDialog)
92
g_print ("%s (%d)\n", __func__, iClickedButton);
93
GList *cl = gtk_container_get_children (GTK_CONTAINER (pInteractiveWidget));
94
g_return_if_fail (cl != NULL && cl->next != NULL);
95
GtkWidget *pScale = cl->next->data;
96
g_return_if_fail (pScale != NULL);
98
int dt = gtk_range_get_value (GTK_RANGE (pScale));
99
if (dt == 0 || (iClickedButton != 0 && iClickedButton != -1))
101
if (pTask->iSidWarning != 0)
103
g_source_remove (pTask->iSidWarning);
104
pTask->iSidWarning = 0;
109
if (pTask->iSidWarning != 0 && dt != pTask->iWarningDelay)
111
g_source_remove (pTask->iSidWarning);
112
pTask->iSidWarning = 0;
114
if (pTask->iSidWarning == 0)
116
pTask->iSidWarning = g_timeout_add_seconds (dt*60, (GSourceFunc) _task_warning_repeat, pTask);
117
pTask->iWarningDelay = dt;
120
pTask->pWarningDialog = NULL;
121
CairoDockModuleInstance *myApplet = pTask->pApplet;
122
CD_APPLET_STOP_DEMANDING_ATTENTION;
41
gboolean cd_clock_update_with_time (CairoDockModuleInstance *myApplet)
125
static inline void _get_current_time (time_t epoch, CairoDockModuleInstance *myApplet)
44
//\________________ On recupere l'heure courante.
45
time_t epoch = (time_t) time (NULL);
46
127
if (myConfig.cLocation != NULL)
48
129
g_setenv ("TZ", myConfig.cLocation, TRUE);
203
299
if (bRemoveAlarm)
205
cd_message ("Cette alarme ne sera pas répétée");
301
cd_message ("Cette alarme ne sera pas repetee");
206
302
g_ptr_array_remove_index (myConfig.pAlarms, i);
207
303
cd_clock_free_alarm (pAlarm);
208
304
/// A FAIRE : effacer l'heure dans le fichier de conf pour cette alarme.
310
if (myData.pNextTask != NULL)
312
//g_print ("next task : %s\n", myData.pNextTask->cTitle);
314
st.tm_min = myData.pNextTask->iMinute;
315
st.tm_hour = myData.pNextTask->iHour;
316
st.tm_mday = myData.pNextTask->iDay;
317
st.tm_mon = myData.pNextTask->iMonth;
318
st.tm_year = myData.pNextTask->iYear - 1900;
320
st.tm_isdst = myData.currentTime.tm_isdst;
321
time_t t = mktime (&st);
322
//g_print ("time : %ld, task : %ld\n", epoch, t);
323
if (t < epoch) // la tache est depassee.
325
myData.pNextTask = cd_clock_get_next_scheduled_task (myApplet);
327
else if (t < epoch + 15*60 && t >= epoch)
329
if (! myData.pNextTask->b15mnWarning)
331
//g_print ("15 mn warning\n");
332
myData.pNextTask->b15mnWarning = TRUE;
333
myDialogs.dialogTextDescription.bUseMarkup = TRUE;
334
cairo_dock_show_temporary_dialog_with_icon_printf ("%s\n<b>%s</b>\n %s",
337
MY_APPLET_SHARE_DATA_DIR"/icon-task.png",
338
D_("This task will begin in 15 minutes:"),
339
myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"),
340
myData.pNextTask->cText?myData.pNextTask->cText:"");
341
myDialogs.dialogTextDescription.bUseMarkup = FALSE;
342
CD_APPLET_DEMANDS_ATTENTION (NULL, 60);
344
else if (t < epoch + 60)
346
if (! myData.pNextTask->bFirstWarning)
348
//g_print ("first warning\n");
349
myData.pNextTask->bFirstWarning = TRUE;
350
myDialogs.dialogTextDescription.bUseMarkup = TRUE;
351
gchar *cText = g_strdup_printf ("%s\n<b>%s</b>\n %s\n\n%s",
352
D_("It's time for the following task:"),
353
myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"),
354
myData.pNextTask->cText?myData.pNextTask->cText:"",
355
D_("Repeat this message every:"));
356
_task_warning (myData.pNextTask, cText);
362
if (myData.pNextAnniversary != NULL)
364
if (!myData.pNextAnniversary->b1DayWarning && ! myData.pNextAnniversary->bFirstWarning && ! myData.pNextTask->b15mnWarning)
366
GDate* pCurrentDate = g_date_new_dmy (myData.currentTime.tm_mday, myData.currentTime.tm_mon + 1, myData.currentTime.tm_year+1900);
367
GDate* pAnnivDate = g_date_new_dmy (myData.pNextAnniversary->iDay, myData.pNextAnniversary->iMonth + 1, myData.currentTime.tm_year+1900);
368
gint iDaysToNextAnniversary = g_date_days_between (pCurrentDate, pAnnivDate);
369
if (iDaysToNextAnniversary >= 0 && iDaysToNextAnniversary <= 1)
371
myData.pNextAnniversary->b1DayWarning = TRUE;
372
gchar *cText = g_strdup_printf ("%s\n<b>%s</b>\n %s\n\n%s",
373
iDaysToNextAnniversary == 0 ? D_("Today is the following anniversary:") : D_("Tomorrow is the following anniversary:"),
374
myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"),
375
myData.pNextTask->cText?myData.pNextTask->cText:"",
376
D_("Repeat this message every:"));
377
_task_warning (myData.pNextTask, cText);
379
myData.pNextAnniversary = cd_clock_get_next_anniversary (myApplet);
381
g_date_free (pCurrentDate);
382
g_date_free (pAnnivDate);
214
388
CD_APPLET_LEAVE(TRUE);
274
449
PangoRectangle ink2, log2;
275
450
pango_layout_get_pixel_extents (pLayout2, &ink2, &log2);
277
double h = ink.height + ink2.height + GAP;
278
double fZoomX = MIN ((double) (iWidth - 1) / ink.width, (double) (iWidth - 1) / ink2.width);
279
double fZoomY = (double) iHeight / h;
280
if (myDock && fZoomY > MAX_RATIO * fZoomX) // on ne garde pas le ratio car ca ferait un texte trop petit en hauteur, toutefois on limite un peu la deformation en hauteur.
281
fZoomY = MAX_RATIO * fZoomX;
283
if (fZoomX * MAX (ink.width, ink2.width) > myConfig.fTextRatio * iWidth)
285
fZoomY *= myConfig.fTextRatio * iWidth / (MAX (ink.width, ink2.width) * fZoomX);
286
fZoomX = myConfig.fTextRatio * iWidth / MAX (ink.width, ink2.width);
289
cairo_translate (myDrawContext, (iWidth - fZoomX * ink.width) / 2, (iHeight - fZoomY * h)/2); // centre verticalement.
290
cairo_scale (myDrawContext, fZoomX, fZoomY);
291
cairo_translate (myDrawContext, -ink.x, -ink.y);
292
pango_cairo_show_layout (myDrawContext, pLayout);
294
cairo_restore (myDrawContext);
295
cairo_save (myDrawContext);
297
cairo_translate (myDrawContext, (iWidth - fZoomX * ink2.width) / 2, (iHeight + fZoomY * GAP)/2);
298
cairo_scale (myDrawContext, fZoomX, fZoomY);
299
cairo_translate (myDrawContext, -ink2.x, -ink2.y);
300
pango_cairo_show_layout (myDrawContext, pLayout2);
452
double h=0, w=0, fZoomX=0, fZoomY=0;
453
double h_=0, w_=0, fZoomX_=0, fZoomY_=0;
454
if (myData.iTextOrientation == 1 || myData.iTextOrientation == 0)
456
h = ink.height + ink2.height + GAPY;
457
w = MAX (ink.width, ink2.width);
458
fZoomX = (double) iWidth / w;
459
fZoomY = (double) iHeight / h;
460
if (myDock && fZoomY > MAX_RATIO * fZoomX) // on ne garde pas le ratio car ca ferait un texte trop petit en hauteur, toutefois on limite un peu la deformation en hauteur.
461
fZoomY = MAX_RATIO * fZoomX;
463
if (fZoomX * w > myConfig.fTextRatio * iWidth)
465
fZoomY *= myConfig.fTextRatio * iWidth / w * fZoomX;
466
fZoomX = myConfig.fTextRatio * iWidth / w;
469
if (myData.iTextOrientation == 2 || myData.iTextOrientation == 0)
471
h_ = MAX (ink.height, ink2.height);
472
w_ = ink.width + ink2.width + GAPX;
473
fZoomX_ = (double) iWidth / w_;
474
fZoomY_ = (double) iHeight / h_;
475
if (myDock && fZoomY_ > MAX_RATIO * fZoomX_) // on ne garde pas le ratio car ca ferait un texte trop petit en hauteur, toutefois on limite un peu la deformation en hauteur.
476
fZoomY_ = MAX_RATIO * fZoomX_;
478
if (fZoomX_ * w_ > myConfig.fTextRatio * iWidth)
480
fZoomY_ *= myConfig.fTextRatio * iWidth / w_ * fZoomX_;
481
fZoomX_ = myConfig.fTextRatio * iWidth / w_;
483
if (fZoomY_ > fZoomX_)
485
double fMaxScale = cairo_dock_get_max_scale (myContainer);
486
fZoomY_ = MAX (fZoomX_, 16. * fMaxScale / h_); // en mode horizontal, on n'a pas besoin que le texte remplisse toute la hauteur de l'icone. 16 pixels de haut sont suffisant pour etre lisible.
490
if (myData.iTextOrientation == 0) // si l'orientation n'est pas encore definie, on la definit de facon a ne pas changer (si on est tres proche de la limite, la taille du texte pourrait changer suffisamment pour nous faire passer d'une orientation a l'autre.
492
double def = (fZoomX > fZoomY ? fZoomX / fZoomY : fZoomY / fZoomX); // deformation.
493
double def_ = (fZoomX_ > fZoomY_ ? fZoomX_ / fZoomY_ : fZoomY_ / fZoomX_);
494
if (def > def_) // deformation plus grande en mode vertical => on passe en mode horizontal.
495
myData.iTextOrientation = 2;
497
myData.iTextOrientation = 1;
500
if (myData.iTextOrientation == 2) // mode horizontal
502
cairo_translate (myDrawContext, (iWidth - fZoomX_ * w_) / 2, (iHeight - fZoomY_ * h_)/2); // centre verticalement.
503
cairo_scale (myDrawContext, fZoomX_, fZoomY_);
504
cairo_translate (myDrawContext, -ink2.x, -ink2.y);
505
pango_cairo_show_layout (myDrawContext, pLayout2);
507
cairo_restore (myDrawContext);
508
cairo_save (myDrawContext);
510
cairo_translate (myDrawContext, (iWidth + fZoomX_ * w_) / 2 - fZoomX_ * ink.width, (iHeight - fZoomY_ * h_)/2);
511
cairo_scale (myDrawContext, fZoomX_, fZoomY_);
512
cairo_translate (myDrawContext, -ink.x, -ink.y);
513
pango_cairo_show_layout (myDrawContext, pLayout);
515
else // mode vertical
517
cairo_translate (myDrawContext, (iWidth - fZoomX * ink.width) / 2, (iHeight - fZoomY * h)/2); // centre verticalement.
518
cairo_scale (myDrawContext, fZoomX, fZoomY);
519
cairo_translate (myDrawContext, -ink.x, -ink.y);
520
pango_cairo_show_layout (myDrawContext, pLayout);
522
cairo_restore (myDrawContext);
523
cairo_save (myDrawContext);
525
cairo_translate (myDrawContext, (iWidth - fZoomX * ink2.width) / 2, (iHeight + fZoomY * GAPY)/2);
526
cairo_scale (myDrawContext, fZoomX, fZoomY);
527
cairo_translate (myDrawContext, -ink2.x, -ink2.y);
528
pango_cairo_show_layout (myDrawContext, pLayout2);
302
530
g_object_unref (pLayout2);