1 
2 /*
3  * Osmo - a handy personal organizer
4  *
5  * Copyright (C) 2007 Tomasz Maka <pasp@users.sourceforge.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #include "about.h"
23 #include "calendar.h"
24 #include "backup.h"
25 #include "i18n.h"
26 #include "calendar_print.h"
27 #include "calendar_widget.h"
28 #include "calendar_jumpto.h"
29 #include "calendar_fullyear.h"
30 #include "tasks.h"
31 #include "tasks_items.h"
32 #include "contacts.h"
33 #include "utils.h"
34 #include "utils_gui.h"
35 #include "utils_date.h"
36 #include "options_prefs.h"
37 #include "tasks_utils.h"
38 #include "calendar_notes.h"
39 #include "calendar_timeline.h"
40 #include "calendar_calc.h"
41 #include "calendar_ical.h"
42 #include "check_events.h"
43 #include "stock_icons.h"
44 #include "preferences_gui.h"
45 
46 /*------------------------------------------------------------------------------*/
47 
48 static void
show_preferences_window_cb(GtkToolButton * toolbutton,gpointer data)49 show_preferences_window_cb (GtkToolButton *toolbutton, gpointer data)
50 {
51     GUI *appGUI = (GUI *) data;
52     appGUI->opt->window = opt_create_preferences_window (appGUI);
53     gtk_widget_show (appGUI->opt->window);
54 
55     gint page = gtk_notebook_page_num (GTK_NOTEBOOK (appGUI->opt->notebook), appGUI->opt->calendar);
56     gtk_notebook_set_current_page (GTK_NOTEBOOK (appGUI->opt->notebook), page);
57 }
58 
59 /*------------------------------------------------------------------------------*/
60 
61 #ifndef HAVE_LIBWEBKIT
62 
63 static GdkPixbuf *
cal_get_moon_icon(gint phase)64 cal_get_moon_icon(gint phase) {
65     GdkPixbuf *icon;
66     gchar *filename;
67     if (phase > 7) return NULL;
68     filename = g_strdup_printf(PIXMAPSDIR G_DIR_SEPARATOR_S "moonphase_%d_data.png", phase);
69     icon = gdk_pixbuf_new_from_file(filename, NULL);
70     g_free(filename);
71     return icon;
72 }
73 
74 static void
cal_set_moon_icon(gint moon_phase,GUI * appGUI)75 cal_set_moon_icon (gint moon_phase, GUI *appGUI)
76 {
77 GdkPixbuf *icon;
78 gchar tmpbuf[BUFFER_SIZE];
79 
80     icon = cal_get_moon_icon(moon_phase);
81     gtk_image_set_from_pixbuf (GTK_IMAGE (appGUI->cal->moon_icon), icon);
82     g_object_unref (icon);
83 
84     g_snprintf (tmpbuf, BUFFER_SIZE, "(%s)", utl_get_moon_phase_name (moon_phase));
85     gtk_label_set_text (GTK_LABEL (appGUI->cal->moon_phase_label), tmpbuf);
86 }
87 
88 #else
89 
90 static gchar *
cal_get_moonphase_img(guint phase)91 cal_get_moonphase_img(guint phase) {
92     gchar *moonimg = NULL;
93     static gchar *phases[8] = {NULL}; /* TODO this should be freed at some point */
94 
95     if (phase > 7) return g_strdup("");
96 
97     if (phases[phase] == NULL) {
98         gboolean rc;
99         gchar *content;
100         gsize length;
101         gchar *filename = g_strdup_printf(PIXMAPSDIR G_DIR_SEPARATOR_S "moonphase_%d_data.png", phase);
102         rc = g_file_get_contents(filename, &content, &length, NULL);
103         if(rc) {
104             phases[phase] = g_base64_encode((const guchar *)content, length);
105         } else {
106             fprintf(stderr, _("Cannot read file."));
107         }
108         g_free(content);
109         g_free(filename);
110     }
111     moonimg = g_strdup_printf("<img src=\"data:image/png;base64,%s\">", phases[phase]);
112     return moonimg;
113 }
114 
115 #endif  /* HAVE_LIBWEBKIT */
116 
117 /*------------------------------------------------------------------------------*/
118 
119 static void
cal_mark_days_with_notes(GDate * date,GUI * appGUI)120 cal_mark_days_with_notes (GDate *date, GUI *appGUI)
121 {
122 GDate *tmpdate;
123 gint i, days;
124 
125     tmpdate = g_date_new_dmy (1, g_date_get_month (date), g_date_get_year (date));
126     g_return_if_fail (tmpdate != NULL);
127 
128     if (appGUI->calendar_only == TRUE) return;
129 
130     gui_calendar_clear_marks (GUI_CALENDAR (appGUI->cal->calendar), DAY_NOTE_MARK);
131     gui_calendar_clear_marks (GUI_CALENDAR (appGUI->cal->calendar), EVENT_MARK);
132     gui_calendar_clear_marks (GUI_CALENDAR (appGUI->cal->calendar), BIRTHDAY_MARK);
133 
134     if (config.enable_day_mark == FALSE) return;
135 
136     days = utl_date_get_days_in_month (tmpdate);
137 
138     for (i = 1; i <= days; i++) {
139         g_date_set_day (tmpdate, i);
140 
141         if (cal_check_note (g_date_get_julian (tmpdate), appGUI) == TRUE) {
142             gui_calendar_set_day_color (GUI_CALENDAR (appGUI->cal->calendar), i,
143                                         cal_get_note_color (g_date_get_julian (tmpdate), appGUI));
144         }
145 
146         calendar_mark_events (appGUI->cal->calendar, g_date_get_julian (tmpdate), i, appGUI);
147     }
148 
149     g_date_free (tmpdate);
150 }
151 
152 /*------------------------------------------------------------------------------*/
153 
154 void
cal_refresh_marks(GUI * appGUI)155 cal_refresh_marks (GUI *appGUI)
156 {
157     cal_mark_days_with_notes (appGUI->cal->date, appGUI);
158 }
159 
160 /*------------------------------------------------------------------------------*/
161 
162 gint
cal_get_marked_days(GDate * date,GUI * appGUI)163 cal_get_marked_days (GDate *date, GUI *appGUI)
164 {
165     guint32 julian;
166     gint i, n, days;
167 
168     julian = utl_date_dmy_to_julian (1, g_date_get_month (date), g_date_get_year (date));
169     days = utl_date_get_days_in_month (date);
170 
171     n = 0;
172 
173     for (i = 0; i < days; i++)
174         if (cal_check_note (julian + i, appGUI) == TRUE)
175             n++;
176 
177     return n;
178 }
179 
180 /*------------------------------------------------------------------------------*/
181 
182 gint
get_marked_days(guint month,guint year,GUI * appGUI)183 get_marked_days (guint month, guint year, GUI *appGUI)
184 {
185     guint32 julian;
186     gint i, n, days;
187 
188     n = 0;
189     days = g_date_get_days_in_month (month + 1, year);
190     julian = utl_date_dmy_to_julian (1, month + 1, year);
191 
192     for (i = 0; i < days; i++)
193         if (cal_check_note (julian + i, appGUI) == TRUE)
194             n++;
195 
196     return n;
197 }
198 
199 /*------------------------------------------------------------------------------*/
200 
201 static void
calendar_store_note(GDate * date,gchar * color,GUI * appGUI)202 calendar_store_note (GDate *date, gchar *color, GUI *appGUI)
203 {
204 GtkTextBuffer *textbuffer;
205 gchar *text, *old_text, *old_color;
206 gboolean note_changed;
207 
208     textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview));
209     text = utl_gui_text_buffer_get_text_with_tags (GTK_TEXT_BUFFER (textbuffer));
210     old_text = cal_get_note(g_date_get_julian(date), appGUI);
211     old_color = cal_get_note_color(g_date_get_julian(date),appGUI);
212     note_changed = (text && old_text && g_utf8_collate(text, old_text))
213             || (text && !old_text && g_utf8_strlen (text, -1))
214             || (!text && old_text && g_utf8_strlen (old_text, -1))
215             || (color && old_color && g_utf8_collate(color, old_color))
216             || (color && !old_color)
217             || (!color && old_color);
218 
219     if (text != NULL && note_changed) {
220         if (g_utf8_strlen (text, -1)) {
221             cal_add_note (g_date_get_julian (date), color, text, appGUI);
222         } else {
223             cal_remove_note (g_date_get_julian (date), appGUI);
224         }
225 
226         g_free (text);
227     }
228     if (config.save_data_after_modification && note_changed) {
229         cal_write_notes(appGUI);
230     }
231 }
232 
233 /*------------------------------------------------------------------------------*/
234 
235 void
cal_mark_events(GtkWidget * calendar,GDate * date,GUI * appGUI)236 cal_mark_events (GtkWidget *calendar, GDate *date, GUI *appGUI)
237 {
238 guint month, year;
239 guint i, days;
240 GDate *tmpdate;
241 
242     if (appGUI->calendar_only == TRUE) return;
243 
244     tmpdate = g_date_new_julian (g_date_get_julian (date));
245 
246     month = g_date_get_month (tmpdate) - 1;
247     year = g_date_get_year (tmpdate);
248 
249     gui_calendar_select_day (GUI_CALENDAR (calendar), 1);
250     gui_calendar_select_month (GUI_CALENDAR (calendar), month, year);
251     gui_calendar_clear_marks (GUI_CALENDAR (calendar), DAY_NOTE_MARK);
252     gui_calendar_clear_marks (GUI_CALENDAR (calendar), EVENT_MARK);
253     gui_calendar_clear_marks (GUI_CALENDAR (calendar), BIRTHDAY_MARK);
254 
255     if (config.enable_day_mark == FALSE) return;
256 
257     days = utl_date_get_days_in_month (tmpdate);
258 
259     for (i = 1; i <= days; i++) {
260         g_date_set_day (tmpdate, i);
261 
262         if (cal_check_note (g_date_get_julian (tmpdate), appGUI) == TRUE) {
263             gui_calendar_set_day_color (GUI_CALENDAR (calendar), i, cal_get_note_color (g_date_get_julian (tmpdate), appGUI));
264         }
265 
266         calendar_mark_events (calendar, g_date_get_julian (tmpdate), i, appGUI);
267     }
268 
269     g_date_free (tmpdate);
270 }
271 
272 /*------------------------------------------------------------------------------*/
273 
274 void
mark_events(GtkWidget * calendar,guint month,guint year,GUI * appGUI)275 mark_events (GtkWidget *calendar, guint month, guint year, GUI *appGUI)
276 {
277     guint32 julian;
278     guint i, days;
279 
280     if (appGUI->calendar_only == TRUE) return;
281 
282     gui_calendar_select_month (GUI_CALENDAR (calendar), month, year);
283     gui_calendar_select_day (GUI_CALENDAR (calendar), 1);
284     gui_calendar_clear_marks (GUI_CALENDAR (calendar), DAY_NOTE_MARK);
285     gui_calendar_clear_marks (GUI_CALENDAR (calendar), EVENT_MARK);
286     gui_calendar_clear_marks (GUI_CALENDAR (calendar), BIRTHDAY_MARK);
287 
288     if (config.enable_day_mark == FALSE) return;
289 
290     days = g_date_get_days_in_month (month + 1, year);
291 
292     for (i = 1; i <= days; i++) {
293         julian = utl_date_dmy_to_julian (i, month + 1, year);
294         if (cal_check_note (julian, appGUI) == TRUE) {
295             gui_calendar_set_day_color (GUI_CALENDAR (calendar), i, cal_get_note_color (julian, appGUI));
296         }
297         calendar_mark_events (calendar, julian, i, appGUI);
298     }
299 }
300 
301 /*------------------------------------------------------------------------------*/
302 
303 void
update_aux_calendars(GUI * appGUI)304 update_aux_calendars (GUI *appGUI)
305 {
306 gchar buffer[BUFFER_SIZE];
307 GDate *tmpdate;
308 
309     if (appGUI->calendar_only == TRUE) return;
310 
311     if (!config.gui_layout) {
312         if (appGUI->calendar_only == TRUE || config.enable_auxilary_calendars == FALSE ||
313             config.auxilary_calendars_state == FALSE) return;
314     }
315 
316     tmpdate = g_date_new ();
317     g_return_if_fail (tmpdate != NULL);
318 
319     g_date_set_julian (tmpdate, g_date_get_julian (appGUI->cal->date));
320     g_date_subtract_months (tmpdate, 1);
321     g_date_strftime (buffer, BUFFER_SIZE, "%B %Y", tmpdate);
322     gtk_label_set_text (GTK_LABEL (appGUI->cal->prev_month_label), buffer);
323     cal_mark_events (appGUI->cal->calendar_prev, tmpdate, appGUI);
324 
325     g_date_set_julian (tmpdate, g_date_get_julian (appGUI->cal->date));
326     g_date_add_months (tmpdate, 1);
327     g_date_strftime (buffer, BUFFER_SIZE, "%B %Y", tmpdate);
328     gtk_label_set_text (GTK_LABEL (appGUI->cal->next_month_label), buffer);
329     cal_mark_events (appGUI->cal->calendar_next, tmpdate, appGUI);
330 
331     g_date_free (tmpdate);
332 }
333 
334 /*------------------------------------------------------------------------------*/
335 
336 #ifdef TASKS_ENABLED
337 
338 gint
check_add_tasks(GDate * date,gboolean count,gchar ** html,GUI * appGUI)339 check_add_tasks (GDate *date, gboolean count, gchar **html, GUI *appGUI)
340 {
341 GtkTreePath *path;
342 GtkTreeIter iter;
343 GtkTreeModel *model;
344 guint32 julian, sjulian;
345 gboolean done;
346 gint time;
347 gchar *summary, *category;
348 gchar tmpbuf[BUFFER_SIZE];
349 gint i;
350 
351     model = GTK_TREE_MODEL (appGUI->tsk->tasks_list_store);
352     g_return_val_if_fail (model != NULL, 0);
353 
354     path = gtk_tree_path_new_first ();
355     sjulian = g_date_get_julian (date);
356     i = 0;
357 
358     while (gtk_tree_model_get_iter (model, &iter, path) == TRUE) {
359         gtk_tree_model_get (model, &iter, TA_COLUMN_DUE_DATE_JULIAN, &julian, TA_COLUMN_CATEGORY, &category, -1);
360 
361         if (julian == sjulian && tsk_get_category_state (category, STATE_CALENDAR, appGUI) == TRUE) {
362             if (count == FALSE) {
363                 gtk_tree_model_get (model, &iter, TA_COLUMN_DUE_TIME, &time, TA_COLUMN_DONE, &done,
364                                     TA_COLUMN_SUMMARY, &summary, -1);
365 
366                 if (time >= 0) {
367                     g_snprintf (tmpbuf, BUFFER_SIZE, "%d. [%02d:%02d] %s", i + 1, time / 3600, time / 60 % 60, summary);
368                 } else {
369                     g_snprintf (tmpbuf, BUFFER_SIZE, "%d. %s", i + 1, summary);
370                 }
371 
372                 if (html != NULL) {
373 
374                     if (done == TRUE) {
375                         *(html) = utl_strconcat (*(html), "<s>", tmpbuf, "</s><br />", NULL);
376                     } else {
377                         *(html) = utl_strconcat (*(html), tmpbuf, "<br />", NULL);
378                     }
379 
380                 } else {
381                     if (done == TRUE) {
382                         gtk_text_buffer_insert_with_tags_by_name (appGUI->cal->day_desc_text_buffer,
383                                                                   &appGUI->cal->day_desc_iter, tmpbuf, -1, "strike", NULL);
384                     } else {
385                         gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, tmpbuf, -1);
386                     }
387                     gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n", -1);
388                 }
389 
390                 g_free (summary);
391             }
392             i++;
393         }
394 
395         g_free (category);
396         gtk_tree_path_next (path);
397     }
398     gtk_tree_path_free (path);
399 
400     return i;
401 }
402 
403 #endif  /* TASKS_ENABLED */
404 
405 /*------------------------------------------------------------------------------*/
406 
407 #ifdef CONTACTS_ENABLED
408 
409 gint
check_add_contacts(GDate * sdate,gboolean count,gchar ** html,GUI * appGUI)410 check_add_contacts (GDate *sdate, gboolean count, gchar **html, GUI *appGUI)
411 {
412 GtkTreePath *path;
413 GtkTreeIter iter;
414 GtkTreeModel *model;
415 guint32 julian;
416 gchar *first_name, *last_name;
417 gchar tmpbuf[BUFFER_SIZE], buffer[BUFFER_SIZE];
418 GDate *date;
419 gint i, age, syear;
420 
421     model = GTK_TREE_MODEL (appGUI->cnt->contacts_list_store);
422     g_return_val_if_fail (model != NULL, 0);
423 
424     date = g_date_new ();
425     g_return_val_if_fail (date != NULL, 0);
426 
427     syear = g_date_get_year (sdate);
428     path = gtk_tree_path_new_first ();
429     i = 0;
430 
431     while (gtk_tree_model_get_iter (model, &iter, path) == TRUE) {
432         gtk_tree_model_get (model, &iter, COLUMN_BIRTH_DAY_DATE, &julian, -1);
433 
434         if (g_date_valid_julian (julian)) {
435             g_date_set_julian (date, julian);
436             age = syear - g_date_get_year (date);
437 
438             if (age >= 0) {
439                 if (g_date_valid_dmy (g_date_get_day (date), g_date_get_month (date), syear) == FALSE) {
440                     g_date_subtract_days (date, 1);
441                 }
442                 g_date_set_year (date, syear);
443 
444                 if (g_date_compare (date, sdate) == 0) {
445 
446                     if (count == FALSE) {
447                         gtk_tree_model_get (model, &iter, COLUMN_FIRST_NAME, &first_name, COLUMN_LAST_NAME, &last_name, -1);
448                         utl_name_strcat (first_name, last_name, buffer);
449 
450                         if (age == 0) {
451                             g_snprintf (tmpbuf, BUFFER_SIZE, "%s %s\n", buffer, _("was born"));
452                         } else {
453                             g_snprintf (tmpbuf, BUFFER_SIZE, "%s (%d %s)\n", buffer, age,
454                                         ngettext ("year old", "years old", age));
455                         }
456 
457                         if (html != NULL) {
458                             *(html) = utl_strconcat (*(html), tmpbuf, NULL);
459                         } else {
460                             gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, tmpbuf, -1);
461                         }
462                     }
463                     i++;
464                 }
465             }
466         }
467         gtk_tree_path_next (path);
468     }
469     gtk_tree_path_free (path);
470     g_date_free (date);
471 
472     return i;
473 }
474 
475 #endif /* CONTACTS_ENABLED */
476 
477 /*------------------------------------------------------------------------------*/
478 
479 gchar *
cal_get_day_category(GDate * date,GUI * appGUI)480 cal_get_day_category (GDate *date, GUI *appGUI)
481 {
482 GtkTreeIter iter;
483 static gchar buffer[BUFFER_SIZE];
484 gchar *color_val, *color_name, *color_sel;
485 gboolean has_next;
486 
487     buffer[0] = '\0';
488     color_sel = cal_get_note_color (g_date_get_julian (date), appGUI);
489     if (color_sel == NULL) return buffer;
490 
491     has_next = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (appGUI->opt->calendar_category_store), &iter);
492     while (has_next) {
493         gtk_tree_model_get (GTK_TREE_MODEL (appGUI->opt->calendar_category_store), &iter, 1, &color_val, 2, &color_name, -1);
494 
495         if (!strcmp (color_val, color_sel)) {
496             g_snprintf (buffer, BUFFER_SIZE, "%s", color_name);
497             g_free (color_val);
498             g_free (color_name);
499             break;
500         }
501 
502         g_free (color_val);
503         g_free (color_name);
504         has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (appGUI->opt->calendar_category_store), &iter);
505     }
506 
507     return buffer;
508 }
509 
510 /*------------------------------------------------------------------------------*/
511 
512 void
update_clock(GUI * appGUI)513 update_clock (GUI *appGUI)
514 {
515 #ifdef HAVE_LIBWEBKIT
516     if (config.di_show_current_time) {
517         cal_set_day_info (appGUI);
518     }
519 
520 #else
521 
522     gchar *tstr, *text;
523 
524     tstr = utl_time_print_default (utl_time_get_current_seconds (), config.di_show_current_time_seconds);
525     text = g_strdup_printf ("<tt>%s</tt>", tstr);
526     if (appGUI->cal->time_label) {
527         gtk_label_set_markup (GTK_LABEL (appGUI->cal->time_label), text);
528     }
529     g_free (tstr);
530     g_free (text);
531 
532 #endif  /* HAVE_LIBWEBKIT */
533 }
534 
535 /*------------------------------------------------------------------------------*/
536 
537 void
cal_set_day_info(GUI * appGUI)538 cal_set_day_info (GUI *appGUI)
539 {
540 static guint cmonth = 0;
541 gchar tmpbuf[BUFFER_SIZE];
542 GDate *date;
543 guint dday, dmonth, dyear;
544 gint edays, i;
545 gchar *text;
546 
547     date = appGUI->cal->date;
548 
549     dday = g_date_get_day (date);
550     dmonth = g_date_get_month (date) - 1;
551     dyear = g_date_get_year (date);
552 
553 #ifdef HAVE_LIBWEBKIT
554 
555 gchar *output = g_strdup ("");
556 /*gchar *icon;*/
557 /*const guint8 *moon_icon;*/
558 
559     /*moon_icon = cal_get_moon_icon (utl_calc_moon_phase (date));*/
560     /*icon = utl_inline_image_to_html (moon_icon);*/
561 
562     output = utl_strconcat (output, "<html><head>", NULL);
563     output = utl_strconcat (output, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />", NULL);
564     output = utl_strconcat (output, "<style type=\"text/css\">", NULL);
565     output = utl_strconcat (output, "body {", NULL);
566 
567     output = utl_strconcat (output, "line-height: 145\%; ", NULL);
568     output = utl_strconcat (output, "font-family: ", pango_font_description_get_family (appGUI->cal->fd_notes_font), NULL);
569     output = utl_strconcat (output, "}", NULL);
570     output = utl_strconcat (output, "table { width: 100\%; vertical-align: middle; text-align: left; }", NULL);
571     output = utl_strconcat (output, "img { vertical-align: middle; }", NULL);
572     output = utl_strconcat (output, "th { width: 1\%; white-space: pre; }", NULL);
573     output = utl_strconcat (output, "</style>", NULL);
574 
575     output = utl_strconcat (output, "</head><body>", NULL);
576     output = utl_strconcat (output, "<span style=\"white-space: pre-wrap;\">", NULL);
577 
578     /* body */
579     output = utl_strconcat (output, "<table><tr>", NULL);
580 
581     if (config.di_show_current_time) {
582         gchar *tstr = utl_time_print_default (utl_time_get_current_seconds (), config.di_show_current_time_seconds);
583         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Current time"));
584         output = utl_strconcat (output, tmpbuf, tstr, "</td>", NULL);
585         g_free (tstr);
586     }
587 
588     output = utl_strconcat (output, "</tr><tr>", NULL);
589 
590     if (config.di_show_day_number) {
591         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Day number"));
592         output = utl_strconcat (output, tmpbuf, NULL);
593         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", g_date_get_day_of_year (date));
594         output = utl_strconcat (output, tmpbuf, " ", NULL);
595         edays = utl_get_days_per_year (g_date_get_year (date)) - g_date_get_day_of_year (date);
596         if (edays) {
597             g_snprintf (tmpbuf, BUFFER_SIZE, "(%d %s)", edays,
598                         ngettext ("day till end of year", "days till end of year", edays));
599         } else {
600             g_snprintf (tmpbuf, BUFFER_SIZE, "(%s)", _("the last day of the year"));
601         }
602         output = utl_strconcat (output, tmpbuf, "</td>", NULL);
603     }
604 
605     output = utl_strconcat (output, "</tr><tr>", NULL);
606 
607     if (config.di_show_current_day_distance) {
608         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Today distance"));
609         output = utl_strconcat (output, tmpbuf,
610                               get_current_date_distance_str (g_date_get_julian (date)),
611                               "</td>", NULL);
612     }
613 
614     output = utl_strconcat (output, "</tr><tr>", NULL);
615 
616     if (config.di_show_week_number) {
617         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Week number"));
618         output = utl_strconcat (output, tmpbuf, NULL);
619 
620         if (utl_get_week_number (dyear, dmonth + 1, dday) > utl_weeks_in_year (dyear)) {
621             g_snprintf (tmpbuf, BUFFER_SIZE, "1 / %d", utl_weeks_in_year (dyear+1));
622         } else {
623             g_snprintf (tmpbuf, BUFFER_SIZE, "%d / %d", utl_get_week_number (dyear, dmonth+1, dday), utl_weeks_in_year (dyear));
624         }
625         output = utl_strconcat (output, tmpbuf, "</td>", NULL);
626     }
627 
628     output = utl_strconcat (output, "</tr><tr>", NULL);
629 
630     if (config.di_show_marked_days) {
631         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Marked days"));
632         output = utl_strconcat (output, tmpbuf, NULL);
633         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", get_marked_days (g_date_get_month (date)-1, g_date_get_year (date), appGUI));
634         output = utl_strconcat (output, tmpbuf, "</td>", NULL);
635     }
636 
637     output = utl_strconcat (output, "</tr><tr>", NULL);
638 
639     if (config.di_show_weekend_days) {
640         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Weekend days"));
641         output = utl_strconcat (output, tmpbuf, NULL);
642         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", utl_get_weekend_days_in_month (date));
643         output = utl_strconcat (output, tmpbuf, "</td>", NULL);
644     }
645 
646     output = utl_strconcat (output, "</tr><tr>", NULL);
647 
648     if (config.di_show_moon_phase) {
649         gchar *img;
650         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Moon phase"));
651         output = utl_strconcat (output, tmpbuf, NULL);
652         img = cal_get_moonphase_img(utl_calc_moon_phase (date));
653         g_snprintf (tmpbuf, BUFFER_SIZE, "%s (%s)",
654 					img,
655 					utl_get_moon_phase_name (utl_calc_moon_phase (date)));
656         g_free(img);
657         output = utl_strconcat (output, tmpbuf, "</td>", NULL);
658     }
659 
660     output = utl_strconcat (output, "</tr><tr>", NULL);
661 
662     if (config.di_show_zodiac_sign) {
663         g_snprintf (tmpbuf, BUFFER_SIZE, "<th>%s:</th><td>", _("Zodiac sign"));
664         output = utl_strconcat (output, tmpbuf,
665                               utl_get_zodiac_name (g_date_get_day (date), g_date_get_month (date)),
666                               "</td>", NULL);
667     }
668 
669     output = utl_strconcat (output, "</tr></table>", NULL);
670 
671     if (config.di_show_notes && config.enable_day_mark) {
672         text = cal_get_note (g_date_get_julian (date), appGUI);
673 
674         if (text != NULL) {
675             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Day notes"));
676             output = utl_strconcat (output, "<p><b>", tmpbuf, "</b>", NULL);
677             gchar *txt = utl_text_with_tags_to_html (text);
678 
679             if (g_date_get_julian (date) < utl_date_get_current_julian () && config.strikethrough_past_notes == TRUE) {
680                 output = utl_strconcat (output, "<s>", txt, "</s></p>", NULL);
681             } else {
682                 output = utl_strconcat (output, txt, "</p>", NULL);
683             }
684 
685             g_free (txt);
686         }
687     }
688 
689     if (appGUI->calendar_only != TRUE && appGUI->all_pages_added != FALSE && config.enable_day_mark) {
690 
691 #ifdef TASKS_ENABLED
692         /* check tasks */
693         i = check_add_tasks (date, TRUE, NULL, appGUI);
694 
695         if (i) {
696             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Day tasks"));
697             output = utl_strconcat (output, "<p><b>", tmpbuf, "</b>", NULL);
698             check_add_tasks (date, FALSE, &output, appGUI);
699             output = utl_strconcat (output, "</p>", NULL);
700         }
701 #endif  /* TASKS_ENABLED */
702 
703 #ifdef CONTACTS_ENABLED
704         /* check contacts */
705         i = check_add_contacts (date, TRUE, NULL, appGUI);
706 
707         if (i) {
708             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Birthday"));
709             output = utl_strconcat (output, "<p><b>", tmpbuf, "</b>", NULL);
710             check_add_contacts (date, FALSE, &output, appGUI);
711             output = utl_strconcat (output, "</p>", NULL);
712         }
713 #endif  /* CONTACTS_ENABLED */
714 
715     }
716 
717 #ifdef HAVE_LIBICAL
718     output = utl_strconcat (output, "<p>", NULL);
719     calendar_display_ics (date, &output, appGUI);
720     output = utl_strconcat (output, "</p>", NULL);
721 #endif  /* HAVE_LIBICAL */
722 
723     output = utl_strconcat (output, "</span>", NULL);
724 
725     output = utl_strconcat (output, "</body></html>", NULL);
726 
727 #ifndef HAVE_LIBWEBKIT
728     g_free (icon);
729 #endif
730 
731     webkit_settings_set_default_font_size (webkit_web_view_get_settings(appGUI->cal->html_webkitview), PANGO_PIXELS(pango_font_description_get_size (appGUI->cal->fd_notes_font)));
732     webkit_web_view_load_html (appGUI->cal->html_webkitview, output, "file://");
733 
734     g_free (output);
735 
736 #else
737 
738 GtkTextChildAnchor *anchor = NULL;
739 GtkWidget *table = NULL, *label;
740 gint rows;
741 gchar *stripped;
742 gchar *day_category;
743 
744     day_category = cal_get_day_category (date, appGUI);
745 
746     utl_gui_clear_text_buffer (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter);
747 
748     rows = config.di_show_current_time + config.di_show_day_number + config.di_show_marked_days +
749            config.di_show_week_number + config.di_show_weekend_days + config.di_show_moon_phase +
750            config.di_show_zodiac_sign + config.di_show_current_day_distance + config.di_show_day_category;
751 
752     if (rows != 0) {
753         anchor = gtk_text_buffer_create_child_anchor (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter);
754         table = gtk_grid_new ();
755         gtk_widget_show (table);
756         gtk_grid_set_row_spacing (GTK_GRID (table), 4);
757         gtk_grid_set_column_spacing (GTK_GRID (table), 8);
758     }
759 
760     i = 0;
761 
762     if (config.di_show_current_time) {
763         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Current time"));
764         label = gtk_label_new (tmpbuf);
765         gtk_widget_show (label);
766         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
767         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
768         gtk_widget_set_valign(label, GTK_ALIGN_START);
769         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
770         i++;
771     }
772 
773     if (config.di_show_day_number) {
774         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Day number"));
775         label = gtk_label_new (tmpbuf);
776         gtk_widget_show (label);
777         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
778         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
779         gtk_widget_set_valign(label, GTK_ALIGN_START);
780         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
781         i++;
782     }
783 
784     if (config.di_show_current_day_distance) {
785         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Today distance"));
786         label = gtk_label_new (tmpbuf);
787         gtk_widget_show (label);
788         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
789         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
790         gtk_widget_set_valign(label, GTK_ALIGN_START);
791         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
792         i++;
793     }
794 
795     if (config.di_show_week_number) {
796         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Week number"));
797         label = gtk_label_new (tmpbuf);
798         gtk_widget_show (label);
799         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
800         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
801         gtk_widget_set_valign(label, GTK_ALIGN_START);
802         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
803         i++;
804     }
805 
806     if (config.di_show_marked_days) {
807         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Marked days"));
808         label = gtk_label_new (tmpbuf);
809         gtk_widget_show (label);
810         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
811         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
812         gtk_widget_set_valign(label, GTK_ALIGN_START);
813         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
814         i++;
815     }
816 
817     if (config.di_show_weekend_days) {
818         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Weekend days"));
819         label = gtk_label_new (tmpbuf);
820         gtk_widget_show (label);
821         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
822         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
823         gtk_widget_set_valign(label, GTK_ALIGN_START);
824         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
825         i++;
826     }
827 
828     if (config.di_show_day_category && g_utf8_strlen (day_category, -1) && config.enable_day_mark) {
829         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Day category"));
830         label = gtk_label_new (tmpbuf);
831         gtk_widget_show (label);
832         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
833         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
834         gtk_widget_set_valign(label, GTK_ALIGN_START);
835         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
836         i++;
837     }
838 
839     if (config.di_show_moon_phase) {
840         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Moon phase"));
841         label = gtk_label_new (tmpbuf);
842         gtk_widget_show (label);
843         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
844         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
845         gtk_widget_set_valign(label, GTK_ALIGN_START);
846         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
847         i++;
848     }
849 
850     if (config.di_show_zodiac_sign) {
851         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Zodiac sign"));
852         label = gtk_label_new (tmpbuf);
853         gtk_widget_show (label);
854         gtk_grid_attach (GTK_GRID (table), label, 0, i, 1, 1);
855         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
856         gtk_widget_set_valign(label, GTK_ALIGN_START);
857         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
858     }
859 
860     i = 0;
861 
862     appGUI->cal->time_label = gtk_label_new (NULL);
863     if (config.di_show_current_time) {
864         update_clock (appGUI);
865         gtk_widget_show (appGUI->cal->time_label);
866         gtk_grid_attach (GTK_GRID (table), appGUI->cal->time_label, 1, i, 2, 1);
867         gtk_widget_set_valign(appGUI->cal->time_label, GTK_ALIGN_START);
868         gtk_widget_set_halign(appGUI->cal->time_label, GTK_ALIGN_CENTER);
869         i++;
870     }
871 
872     if (config.di_show_day_number) {
873         appGUI->cal->day_number_label = gtk_label_new (NULL);
874         gtk_widget_show (appGUI->cal->day_number_label);
875         gtk_grid_attach (GTK_GRID (table), appGUI->cal->day_number_label, 1, i, 1, 1);
876         gtk_widget_set_valign(appGUI->cal->day_number_label, GTK_ALIGN_START);
877         gtk_widget_set_halign(appGUI->cal->day_number_label, GTK_ALIGN_CENTER);
878 
879         appGUI->cal->day_number_year_label = gtk_label_new (NULL);
880         gtk_widget_show (appGUI->cal->day_number_year_label);
881         gtk_grid_attach (GTK_GRID (table), appGUI->cal->day_number_year_label, 2, i, 1, 1);
882         gtk_widget_set_valign(appGUI->cal->day_number_year_label, GTK_ALIGN_START);
883         gtk_widget_set_halign(appGUI->cal->day_number_year_label, GTK_ALIGN_CENTER);
884         i++;
885     }
886 
887     if (config.di_show_current_day_distance) {
888         label = gtk_label_new (NULL);
889         gtk_widget_show (label);
890         gtk_grid_attach (GTK_GRID (table), label, 1, i, 2, 1);
891         gtk_widget_set_valign(label, GTK_ALIGN_START);
892         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
893         gtk_label_set_text (GTK_LABEL (label), get_current_date_distance_str (g_date_get_julian (date)));
894         i++;
895     }
896 
897     if (config.di_show_week_number) {
898         appGUI->cal->week_number_label = gtk_label_new (NULL);
899         gtk_widget_show (appGUI->cal->week_number_label);
900         gtk_grid_attach (GTK_GRID (table), appGUI->cal->week_number_label, 1, i, 2, 1);
901         gtk_widget_set_valign(appGUI->cal->week_number_label, GTK_ALIGN_START);
902         gtk_widget_set_halign(appGUI->cal->week_number_label, GTK_ALIGN_CENTER);
903         i++;
904     }
905 
906     if (config.di_show_marked_days) {
907         appGUI->cal->marked_days_label = gtk_label_new (NULL);
908         gtk_widget_show (appGUI->cal->marked_days_label);
909         gtk_grid_attach (GTK_GRID (table), appGUI->cal->marked_days_label, 1, i, 2, 1);
910         gtk_widget_set_valign(appGUI->cal->marked_days_label, GTK_ALIGN_START);
911         gtk_widget_set_halign(appGUI->cal->marked_days_label, GTK_ALIGN_CENTER);
912         i++;
913     }
914 
915     if (config.di_show_weekend_days) {
916         appGUI->cal->weekend_days_label = gtk_label_new (NULL);
917         gtk_widget_show (appGUI->cal->weekend_days_label);
918         gtk_grid_attach (GTK_GRID (table), appGUI->cal->weekend_days_label, 1, i, 2, 1);
919         gtk_widget_set_valign(appGUI->cal->weekend_days_label, GTK_ALIGN_START);
920         gtk_widget_set_halign(appGUI->cal->weekend_days_label, GTK_ALIGN_CENTER);
921         i++;
922     }
923 
924     if (config.di_show_day_category && g_utf8_strlen (day_category, -1) && config.enable_day_mark) {
925         appGUI->cal->day_category_label = gtk_label_new (NULL);
926         gtk_widget_show (appGUI->cal->day_category_label);
927         gtk_grid_attach (GTK_GRID (table), appGUI->cal->day_category_label, 1, i, 2, 1);
928         gtk_widget_set_valign(appGUI->cal->day_category_label, GTK_ALIGN_START);
929         gtk_widget_set_halign(appGUI->cal->day_category_label, GTK_ALIGN_CENTER);
930         i++;
931     }
932 
933 #ifndef HAVE_LIBWEBKIT
934     if (config.di_show_moon_phase) {
935         appGUI->cal->moon_icon = gtk_image_new();
936         gtk_widget_show (appGUI->cal->moon_icon);
937         gtk_grid_attach (GTK_GRID (table), appGUI->cal->moon_icon, 1, i, 1, 1);
938         gtk_widget_set_valign(appGUI->cal->moon_icon, GTK_ALIGN_START);
939         gtk_widget_set_halign(appGUI->cal->moon_icon, GTK_ALIGN_CENTER);
940 
941         appGUI->cal->moon_phase_label = gtk_label_new (NULL);
942         gtk_widget_show (appGUI->cal->moon_phase_label);
943         gtk_grid_attach (GTK_GRID (table), appGUI->cal->moon_phase_label, 2, i, 1, 1);
944         gtk_widget_set_valign(appGUI->cal->moon_phase_label, GTK_ALIGN_START);
945         gtk_widget_set_halign(appGUI->cal->moon_phase_label, GTK_ALIGN_CENTER);
946 
947         cal_set_moon_icon (utl_calc_moon_phase (date), appGUI);
948         i++;
949     }
950 #endif
951 
952     if (config.di_show_zodiac_sign) {
953         label = gtk_label_new (NULL);
954         gtk_widget_show (label);
955         gtk_grid_attach (GTK_GRID (table), label, 1, i, 2, 1);
956         gtk_widget_set_valign(label, GTK_ALIGN_START);
957         gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
958         gtk_label_set_text (GTK_LABEL (label), utl_get_zodiac_name (g_date_get_day (date), g_date_get_month (date)));
959     }
960 
961     if (config.di_show_day_number) {
962         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", g_date_get_day_of_year (date));
963         gtk_label_set_text (GTK_LABEL (appGUI->cal->day_number_label), tmpbuf);
964 
965         edays = utl_get_days_per_year (g_date_get_year (date)) - g_date_get_day_of_year (date);
966         if (edays) {
967             g_snprintf (tmpbuf, BUFFER_SIZE, "(%d %s)", edays,
968                         ngettext ("day till end of year", "days till end of year", edays));
969         } else {
970             g_snprintf (tmpbuf, BUFFER_SIZE, "(%s)", _("the last day of the year"));
971         }
972         gtk_label_set_text (GTK_LABEL (appGUI->cal->day_number_year_label), tmpbuf);
973     }
974 
975     if (config.di_show_week_number) {
976         if (utl_get_week_number (dyear, dmonth + 1, dday) > utl_weeks_in_year (dyear)) {
977             g_snprintf (tmpbuf, BUFFER_SIZE, "1 / %d", utl_weeks_in_year (dyear+1));
978         } else {
979             g_snprintf (tmpbuf, BUFFER_SIZE, "%d / %d", utl_get_week_number (dyear, dmonth+1, dday), utl_weeks_in_year (dyear));
980         }
981         gtk_label_set_text (GTK_LABEL (appGUI->cal->week_number_label), tmpbuf);
982     }
983 
984     if (config.di_show_marked_days) {
985         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", get_marked_days (g_date_get_month (date)-1, g_date_get_year (date), appGUI));
986         gtk_label_set_text (GTK_LABEL (appGUI->cal->marked_days_label), tmpbuf);
987     }
988 
989     if (config.di_show_weekend_days) {
990         g_snprintf (tmpbuf, BUFFER_SIZE, "%d", utl_get_weekend_days_in_month (date));
991         gtk_label_set_text (GTK_LABEL (appGUI->cal->weekend_days_label), tmpbuf);
992     }
993 
994     if (config.di_show_day_category && g_utf8_strlen (day_category, -1) && config.enable_day_mark) {
995         gtk_label_set_text (GTK_LABEL (appGUI->cal->day_category_label), day_category);
996     }
997 
998     if (rows != 0) {
999         gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), table, anchor);
1000         gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n\n", -1);
1001     }
1002 
1003     if (config.di_show_notes && config.enable_day_mark) {
1004         text = cal_get_note (g_date_get_julian (date), appGUI);
1005 
1006         if (text != NULL) {
1007             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Day notes"));
1008             gtk_text_buffer_insert_with_tags_by_name (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter,
1009                                                       tmpbuf, -1, "bold", NULL);
1010 
1011             if (g_date_get_julian (date) < utl_date_get_current_julian () && config.strikethrough_past_notes == TRUE) {
1012                 stripped = utl_gui_text_strip_tags (text);
1013                 gtk_text_buffer_insert_with_tags_by_name (appGUI->cal->day_desc_text_buffer,
1014                                                           &appGUI->cal->day_desc_iter, stripped, -1, "strike", NULL);
1015                 g_free (stripped);
1016             } else {
1017                 utl_gui_text_buffer_set_text_with_tags (appGUI->cal->day_desc_text_buffer, text, FALSE);
1018                 gtk_text_buffer_get_end_iter (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter);
1019             }
1020 
1021             if (text[g_utf8_strlen (text, -1) - 1] != '\n') {
1022                 gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n\n", -1);
1023             } else {
1024                 gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n", -1);
1025             }
1026         }
1027 
1028     }
1029 
1030     if (appGUI->calendar_only != TRUE && appGUI->all_pages_added != FALSE && config.enable_day_mark) {
1031 
1032 #ifdef TASKS_ENABLED
1033         /* check tasks */
1034         i = check_add_tasks (date, TRUE, NULL, appGUI);
1035 
1036         if (i) {
1037             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Day tasks"));
1038             gtk_text_buffer_insert_with_tags_by_name (appGUI->cal->day_desc_text_buffer,
1039                                                       &appGUI->cal->day_desc_iter, tmpbuf, -1, "bold", NULL);
1040             check_add_tasks (date, FALSE, NULL, appGUI);
1041             gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n", -1);
1042         }
1043 #endif  /* TASKS_ENABLED */
1044 
1045 #ifdef CONTACTS_ENABLED
1046         /* check contacts */
1047         i = check_add_contacts (date, TRUE, NULL, appGUI);
1048 
1049         if (i) {
1050             g_snprintf (tmpbuf, BUFFER_SIZE, "%s:\n", _("Birthday"));
1051             gtk_text_buffer_insert_with_tags_by_name (appGUI->cal->day_desc_text_buffer,
1052                                                       &appGUI->cal->day_desc_iter, tmpbuf, -1, "bold", NULL);
1053             check_add_contacts (date, FALSE, NULL, appGUI);
1054             gtk_text_buffer_insert (appGUI->cal->day_desc_text_buffer, &appGUI->cal->day_desc_iter, "\n", -1);
1055         }
1056 #endif  /* CONTACTS_ENABLED */
1057 
1058     }
1059 
1060 #ifdef HAVE_LIBICAL
1061     calendar_display_ics (date, NULL, appGUI);
1062 #endif  /* HAVE_LIBICAL */
1063 
1064 #endif  /* HAVE_LIBWEBKIT */
1065 
1066     if (cmonth != g_date_get_month (date)) {
1067         cmonth = g_date_get_month (date);
1068         update_aux_calendars (appGUI);
1069     }
1070 }
1071 
1072 /*------------------------------------------------------------------------------*/
1073 
1074 static void
calendar_display_note(GDate * date,GUI * appGUI)1075 calendar_display_note (GDate *date, GUI *appGUI)
1076 {
1077 GtkTextBuffer *textbuffer;
1078 GtkTextIter iter_start, iter_end;
1079 gchar *t;
1080 
1081     textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview));
1082     t = cal_get_note (g_date_get_julian (date), appGUI);
1083 
1084     if (t != NULL) {
1085         utl_gui_text_buffer_set_text_with_tags (GTK_TEXT_BUFFER (textbuffer), t, TRUE);
1086     } else {
1087         gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (textbuffer), &iter_start);
1088         gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (textbuffer), &iter_end);
1089         gtk_text_buffer_delete (GTK_TEXT_BUFFER (textbuffer), &iter_start, &iter_end);
1090     }
1091 }
1092 
1093 /*------------------------------------------------------------------------------*/
1094 void
cal_refresh_notes(GUI * appGUI)1095 cal_refresh_notes(GUI *appGUI) {
1096     cal_refresh_marks(appGUI);
1097     calendar_display_note(appGUI->cal->date, appGUI);
1098     cal_set_day_info(appGUI);
1099     enable_disable_note_buttons(appGUI);
1100 }
1101 
1102 /*------------------------------------------------------------------------------*/
1103 static void
calendar_update_note(guint32 note_date_julian,GUI * appGUI)1104 calendar_update_note(guint32 note_date_julian, GUI *appGUI) {
1105     if (appGUI->calendar_only == FALSE) {
1106         GDate *note_date = g_date_new_julian(note_date_julian);
1107 
1108         calendar_store_note(note_date, cal_get_note_color(note_date_julian, appGUI), appGUI);
1109         cal_refresh_notes(appGUI);
1110         g_date_free(note_date);
1111     }
1112 }
1113 
1114 /*------------------------------------------------------------------------------*/
1115 
1116 void
day_notes_toggled_cb(GtkToggleToolButton * togglebutton,gpointer user_data)1117 day_notes_toggled_cb (GtkToggleToolButton *togglebutton, gpointer user_data)
1118 {
1119     GUI *appGUI = (GUI *) user_data;
1120 
1121     config.day_notes_visible = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (appGUI->cal->notes_button));
1122 
1123     if (!config.day_notes_visible) {
1124 #ifdef HAVE_GSPELL
1125         utl_gui_set_enable_spell_check(appGUI->cal->calendar_note_spelltextview, FALSE);
1126 #endif /* HAVE_GSPELL */
1127         config.enable_day_mark = TRUE;
1128         calendar_update_note(g_date_get_julian (appGUI->cal->date), appGUI);
1129         gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), FALSE);
1130         gtk_text_view_set_editable (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), FALSE);
1131         gtk_widget_hide (appGUI->cal->notes_vbox);
1132         gtk_widget_show (appGUI->cal->day_info_vbox);
1133         gui_systray_tooltip_update (appGUI);
1134     } else {
1135         /* enable (optionally) spell checker */
1136 #ifdef HAVE_GSPELL
1137         appGUI->cal->calendar_note_spelltextview = utl_gui_create_spell_check_textview(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview),
1138                 config.day_note_spell_checker);
1139 #endif /* HAVE_GSPELL */
1140 
1141         gtk_widget_show (appGUI->cal->notes_vbox);
1142         gtk_widget_hide (appGUI->cal->day_info_vbox);
1143         gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), TRUE);
1144         gtk_text_view_set_editable (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), TRUE);
1145         gtk_widget_grab_focus (GTK_WIDGET (appGUI->cal->calendar_note_textview));
1146     }
1147 }
1148 
1149 /*------------------------------------------------------------------------------*/
1150 
1151 void
cal_set_date(GDate * date,GUI * appGUI)1152 cal_set_date (GDate *date, GUI *appGUI)
1153 {
1154     g_date_set_julian (appGUI->cal->date, g_date_get_julian (date));
1155     gui_calendar_select_day (GUI_CALENDAR (appGUI->cal->calendar), 1);     /* Trick: always select valid day number */
1156     gui_calendar_select_month (GUI_CALENDAR (appGUI->cal->calendar), g_date_get_month (date) - 1, g_date_get_year (date));
1157     gui_calendar_select_day (GUI_CALENDAR (appGUI->cal->calendar), g_date_get_day (date));
1158     gtk_label_set_text (GTK_LABEL (appGUI->cal->date_label), utl_get_date_name_format (date, config.date_header_format));
1159 }
1160 
1161 /*------------------------------------------------------------------------------*/
1162 
1163 void
cal_jump_to_date(GDate * date,GUI * appGUI)1164 cal_jump_to_date(GDate *date, GUI *appGUI) {
1165     guint32 note_date = g_date_get_julian(appGUI->cal->date);
1166     appGUI->cal->dont_update = TRUE;
1167     cal_set_date (date, appGUI);
1168 
1169     calendar_update_note(note_date, appGUI);
1170     update_aux_calendars(appGUI);
1171 
1172     appGUI->cal->dont_update = FALSE;
1173 }
1174 /*------------------------------------------------------------------------------*/
1175 
1176 void
calendar_set_today(GUI * appGUI)1177 calendar_set_today(GUI *appGUI) {
1178     GDate *date = g_date_new();
1179 
1180     g_date_set_time_t(date, time(NULL));
1181     cal_jump_to_date(date, appGUI);
1182     g_date_free(date);
1183 }
1184 
1185 /*------------------------------------------------------------------------------*/
1186 
1187 void
calendar_close_text_cb(GtkWidget * widget,gpointer user_data)1188 calendar_close_text_cb (GtkWidget *widget, gpointer user_data)
1189 {
1190     GUI *appGUI = (GUI *) user_data;
1191 
1192     gtk_widget_hide (appGUI->cal->notes_vbox);
1193     gtk_widget_show (appGUI->cal->day_info_vbox);
1194     gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (appGUI->cal->notes_button), FALSE);
1195     gtk_widget_grab_focus (GTK_WIDGET (appGUI->cal->calendar));
1196 }
1197 
1198 /*------------------------------------------------------------------------------*/
1199 
1200 gchar *
calendar_get_note_text(GUI * appGUI)1201 calendar_get_note_text (GUI *appGUI)
1202 {
1203 GtkTextBuffer *textbuffer;
1204 
1205     if (appGUI->calendar_only == TRUE) return NULL;
1206 
1207     textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview));
1208     return utl_gui_text_buffer_get_text_with_tags (GTK_TEXT_BUFFER (textbuffer));
1209 }
1210 
1211 /*------------------------------------------------------------------------------*/
1212 
1213 void
calendar_clear_text_cb(GtkWidget * widget,gpointer user_data)1214 calendar_clear_text_cb (GtkWidget *widget, gpointer user_data)
1215 {
1216     gchar *text = NULL;
1217     gchar tmpbuf[BUFFER_SIZE];
1218     gint response;
1219 
1220     GUI *appGUI = (GUI *) user_data;
1221     text = calendar_get_note_text (appGUI);
1222     if (text == NULL) return;
1223     if (!g_utf8_strlen (text, -1)) {
1224         g_free (text);
1225         return;
1226     }
1227 
1228     g_snprintf (tmpbuf, BUFFER_SIZE, "%s\n\n%s", _("Selected day note will be removed."), _("Continue?"));
1229     response = utl_gui_create_dialog (GTK_MESSAGE_QUESTION, tmpbuf, GTK_WINDOW (appGUI->main_window));
1230 
1231     if (response == GTK_RESPONSE_YES) {
1232         gtk_text_buffer_set_text (GTK_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview))), "", -1);
1233         enable_disable_note_buttons (appGUI);
1234         calendar_store_note(appGUI->cal->date, NULL, appGUI);
1235         cal_refresh_notes(appGUI);
1236         gui_systray_tooltip_update (appGUI);
1237     }
1238     g_free (text);
1239 }
1240 
1241 /*------------------------------------------------------------------------------*/
1242 
1243 void
calendar_insert_timeline_cb(GtkWidget * widget,gpointer user_data)1244 calendar_insert_timeline_cb (GtkWidget *widget, gpointer user_data)
1245 {
1246     GUI *appGUI = (GUI *) user_data;
1247     calendar_create_insert_timeline_window (appGUI);
1248 }
1249 
1250 /*------------------------------------------------------------------------------*/
1251 
1252 void
calendar_select_color_cb(GtkWidget * widget,gpointer user_data)1253 calendar_select_color_cb (GtkWidget *widget, gpointer user_data)
1254 {
1255     GUI *appGUI = (GUI *) user_data;
1256     calendar_create_color_selector_window (FALSE, appGUI);
1257 }
1258 
1259 /*------------------------------------------------------------------------------*/
1260 
1261 void
calendar_update_date(guint day,guint month,guint year,GUI * appGUI)1262 calendar_update_date (guint day, guint month, guint year, GUI *appGUI)
1263 {
1264 guint max_day;
1265 GDate *date;
1266 
1267     max_day = g_date_get_days_in_month (month, year);
1268 
1269     if (day > max_day)
1270         day = max_day;
1271 
1272     date = g_date_new_dmy (day, month, year);
1273     g_return_if_fail (date != NULL);
1274 
1275     cal_jump_to_date (date, appGUI);
1276     g_date_free (date);
1277 }
1278 
1279 /*------------------------------------------------------------------------------*/
1280 
1281 void
calendar_btn_prev_day(GUI * appGUI)1282 calendar_btn_prev_day(GUI *appGUI) {
1283     GDate *date = g_date_new();
1284 
1285     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1286     if (g_date_get_julian(date) > 1) {
1287         if ((g_date_get_day(date) > 1) || (config.display_options & GUI_CALENDAR_NO_MONTH_CHANGE) == FALSE)
1288             g_date_subtract_days(date, 1);
1289 
1290         cal_jump_to_date(date, appGUI);
1291     }
1292     g_date_free(date);
1293 }
1294 
1295 /*------------------------------------------------------------------------------*/
1296 
1297 void
calendar_btn_next_day(GUI * appGUI)1298 calendar_btn_next_day(GUI *appGUI) {
1299     GDate *date = g_date_new();
1300 
1301     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1302     if ((g_date_get_day(date) < utl_date_get_days_in_month(date) ||
1303             (config.display_options & GUI_CALENDAR_NO_MONTH_CHANGE) == FALSE)) {
1304         g_date_add_days(date, 1);
1305     }
1306     cal_jump_to_date(date, appGUI);
1307     g_date_free(date);
1308 }
1309 
1310 /*------------------------------------------------------------------------------*/
1311 
1312 static void
calendar_btn_today(GUI * appGUI)1313 calendar_btn_today (GUI *appGUI)
1314 {
1315     calendar_set_today (appGUI);
1316 }
1317 /*------------------------------------------------------------------------------*/
1318 
1319 void
calendar_btn_prev_week(GUI * appGUI)1320 calendar_btn_prev_week(GUI *appGUI) {
1321     GDate *date = g_date_new();
1322 
1323     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1324     if (g_date_get_julian(date) > 7) {
1325         if ((g_date_get_day(date) > 7) || (config.display_options & GUI_CALENDAR_NO_MONTH_CHANGE) == FALSE)
1326             g_date_subtract_days(date, 7);
1327 
1328         cal_jump_to_date(date, appGUI);
1329     }
1330     g_date_free(date);
1331 }
1332 /*------------------------------------------------------------------------------*/
1333 
1334 void
calendar_btn_next_week(GUI * appGUI)1335 calendar_btn_next_week(GUI *appGUI) {
1336     GDate *date = g_date_new();
1337 
1338     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1339     if ((g_date_get_day(date + 7) <= utl_date_get_days_in_month(date)) ||
1340             (config.display_options & GUI_CALENDAR_NO_MONTH_CHANGE) == FALSE) {
1341         g_date_add_days(date, 7);
1342     }
1343     cal_jump_to_date(date, appGUI);
1344     g_date_free(date);
1345 }
1346 /*------------------------------------------------------------------------------*/
1347 
1348 void
calendar_btn_prev_month(GUI * appGUI)1349 calendar_btn_prev_month(GUI *appGUI) {
1350     GDate *date = g_date_new();
1351 
1352     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1353     if (g_date_get_julian(date) > 31) {
1354         g_date_subtract_months(date, 1);
1355         cal_jump_to_date(date, appGUI);
1356     }
1357     g_date_free(date);
1358 }
1359 /*------------------------------------------------------------------------------*/
1360 
1361 void
calendar_btn_next_month(GUI * appGUI)1362 calendar_btn_next_month(GUI *appGUI) {
1363     GDate *date = g_date_new();
1364 
1365     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1366     g_date_add_months(date, 1);
1367     cal_jump_to_date(date, appGUI);
1368     g_date_free(date);
1369 }
1370 
1371 /*------------------------------------------------------------------------------*/
1372 
1373 void
calendar_btn_prev_year(GUI * appGUI)1374 calendar_btn_prev_year(GUI *appGUI) {
1375     GDate *date = g_date_new();
1376 
1377     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1378     if (g_date_get_year(date) > 1) {
1379         g_date_subtract_years(date, 1);
1380         cal_jump_to_date(date, appGUI);
1381     }
1382     g_date_free(date);
1383 }
1384 /*------------------------------------------------------------------------------*/
1385 
1386 void
calendar_btn_next_year(GUI * appGUI)1387 calendar_btn_next_year(GUI *appGUI) {
1388     GDate *date = g_date_new();
1389 
1390     gui_calendar_get_gdate(GUI_CALENDAR(appGUI->cal->calendar), date);
1391     g_date_add_years(date, 1);
1392     cal_jump_to_date(date, appGUI);
1393     g_date_free(date);
1394 }
1395 
1396 /*------------------------------------------------------------------------------*/
1397 
1398 void
calendar_day_selected_cb(GuiCalendar * calendar,GUI * appGUI)1399 calendar_day_selected_cb (GuiCalendar *calendar, GUI *appGUI)
1400 {
1401     guint32 prev_date = g_date_get_julian (appGUI->cal->date);
1402 
1403     if (appGUI->cal->dont_update == FALSE)
1404         gui_calendar_get_gdate (GUI_CALENDAR (calendar), appGUI->cal->date);
1405 
1406     gtk_label_set_text (GTK_LABEL (appGUI->cal->date_label), utl_get_date_name_format (appGUI->cal->date, config.date_header_format));
1407 
1408     if (appGUI->cal->dont_update == FALSE) {
1409         calendar_update_note(prev_date, appGUI);
1410     }
1411 
1412 
1413     if (appGUI->calendar_only == FALSE) {
1414         /* enable/disable 'select day color' popup entry */
1415         if (cal_check_note (g_date_get_julian (appGUI->cal->date), appGUI) == TRUE) {
1416             gtk_widget_show (appGUI->cal->popup_menu_select_day_color_entry);
1417         } else {
1418             gtk_widget_hide (appGUI->cal->popup_menu_select_day_color_entry);
1419         }
1420     }
1421 }
1422 
1423 /*------------------------------------------------------------------------------*/
1424 
1425 void
calendar_dc_day_selected_cb(GuiCalendar * calendar,gpointer user_data)1426 calendar_dc_day_selected_cb (GuiCalendar *calendar, gpointer user_data) {
1427 
1428     GUI *appGUI = (GUI *)user_data;
1429 
1430     if (appGUI->calendar_only == FALSE) {
1431         if (!config.day_notes_visible) {
1432                 enable_disable_note_buttons(appGUI);
1433                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(appGUI->cal->notes_button),
1434                                              !gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(appGUI->cal->notes_button)));
1435         }
1436     }
1437 }
1438 
1439 /*------------------------------------------------------------------------------*/
1440 
1441 void
enable_disable_note_buttons(GUI * appGUI)1442 enable_disable_note_buttons (GUI *appGUI)
1443 {
1444     gboolean state = FALSE;
1445     gchar *text = calendar_get_note_text (appGUI);
1446 
1447     if (g_utf8_strlen (text, -1))
1448         state = TRUE;
1449 
1450     gtk_widget_set_sensitive (appGUI->cal->n_clear_button, state);
1451     gtk_widget_set_sensitive (appGUI->cal->n_select_color_button, state);
1452 
1453     g_free (text);
1454 }
1455 
1456 /*------------------------------------------------------------------------------*/
1457 
1458 gint
calendar_textbuffer_changed_cb(GtkTextBuffer * textbuffer,gpointer user_data)1459 calendar_textbuffer_changed_cb (GtkTextBuffer *textbuffer, gpointer user_data)
1460 {
1461     GUI *appGUI = (GUI *) user_data;
1462     enable_disable_note_buttons (appGUI);
1463 
1464     return FALSE;
1465 }
1466 
1467 /*------------------------------------------------------------------------------*/
1468 
1469 gboolean
click_handler_cb(GtkWidget * widget,GdkEventButton * event,gpointer data)1470 click_handler_cb (GtkWidget * widget, GdkEventButton * event, gpointer data) {
1471 
1472     GUI *appGUI = (GUI *)data;
1473 
1474     if ((event->type == GDK_BUTTON_PRESS && event->button == 1) ||    /* LMB */
1475         (event->type == GDK_BUTTON_PRESS && event->button == 3)) {    /* RMB */
1476         gtk_menu_popup(GTK_MENU(appGUI->cal->month_selector_menu), NULL, NULL, NULL, NULL, event->button, event->time);
1477         return TRUE;
1478     } else if (event->type == GDK_BUTTON_PRESS && event->button == 2) {     /* MMB */
1479         calendar_update_date (g_date_get_day (appGUI->cal->date), utl_date_get_current_month (),
1480                               g_date_get_year (appGUI->cal->date), appGUI);
1481     }
1482     return FALSE;
1483 }
1484 
1485 /*------------------------------------------------------------------------------*/
1486 
1487 static void
calendar_create_jumpto_window_cb(GtkToolButton * toolbutton,gpointer data)1488 calendar_create_jumpto_window_cb (GtkToolButton *toolbutton, gpointer data)
1489 {
1490     GUI *appGUI = (GUI *) data;
1491     calendar_create_jumpto_window (appGUI);
1492 }
1493 
1494 /*------------------------------------------------------------------------------*/
1495 
1496 static void
calendar_create_fullyear_window_cb(GtkToolButton * toolbutton,gpointer data)1497 calendar_create_fullyear_window_cb (GtkToolButton *toolbutton, gpointer data) {
1498 
1499     GUI *appGUI = (GUI *)data;
1500     calendar_create_fullyear_window (appGUI);
1501 }
1502 
1503 /*------------------------------------------------------------------------------*/
1504 
1505 static void
calendar_create_datecalc_window_cb(GtkToolButton * toolbutton,gpointer data)1506 calendar_create_datecalc_window_cb (GtkToolButton *toolbutton, gpointer data) {
1507 
1508     GUI *appGUI = (GUI *)data;
1509     calendar_create_calc_window (appGUI);
1510 }
1511 
1512 /*------------------------------------------------------------------------------*/
1513 
1514 static void
calendar_btn_prev_year_cb(GtkToolButton * toolbutton,gpointer data)1515 calendar_btn_prev_year_cb (GtkToolButton *toolbutton, gpointer data) {
1516 
1517     GUI *appGUI = (GUI *)data;
1518     calendar_btn_prev_year (appGUI);
1519 }
1520 
1521 /*------------------------------------------------------------------------------*/
1522 
1523 static void
calendar_btn_next_year_cb(GtkToolButton * toolbutton,gpointer data)1524 calendar_btn_next_year_cb (GtkToolButton *toolbutton, gpointer data) {
1525 
1526     GUI *appGUI = (GUI *)data;
1527     calendar_btn_next_year (appGUI);
1528 }
1529 
1530 /*------------------------------------------------------------------------------*/
1531 
1532 static void
calendar_btn_prev_month_cb(GtkToolButton * toolbutton,gpointer data)1533 calendar_btn_prev_month_cb (GtkToolButton *toolbutton, gpointer data) {
1534 
1535     GUI *appGUI = (GUI *)data;
1536     calendar_btn_prev_month (appGUI);
1537 }
1538 
1539 /*------------------------------------------------------------------------------*/
1540 
1541 static void
calendar_btn_next_month_cb(GtkToolButton * toolbutton,gpointer data)1542 calendar_btn_next_month_cb (GtkToolButton *toolbutton, gpointer data) {
1543 
1544     GUI *appGUI = (GUI *)data;
1545     calendar_btn_next_month (appGUI);
1546 }
1547 
1548 /*------------------------------------------------------------------------------*/
1549 
1550 static void
calendar_btn_prev_day_cb(GtkToolButton * toolbutton,gpointer data)1551 calendar_btn_prev_day_cb (GtkToolButton *toolbutton, gpointer data) {
1552 
1553     GUI *appGUI = (GUI *)data;
1554     calendar_btn_prev_day (appGUI);
1555 }
1556 
1557 /*------------------------------------------------------------------------------*/
1558 
1559 static void
calendar_btn_next_day_cb(GtkToolButton * toolbutton,gpointer data)1560 calendar_btn_next_day_cb (GtkToolButton *toolbutton, gpointer data) {
1561 
1562     GUI *appGUI = (GUI *)data;
1563     calendar_btn_next_day (appGUI);
1564 }
1565 
1566 /*------------------------------------------------------------------------------*/
1567 
1568 static void
calendar_btn_today_cb(GtkToolButton * toolbutton,gpointer data)1569 calendar_btn_today_cb (GtkToolButton *toolbutton, gpointer data) {
1570 
1571     GUI *appGUI = (GUI *)data;
1572     calendar_btn_today (appGUI);
1573 }
1574 
1575 /*------------------------------------------------------------------------------*/
1576 
1577 static void
calendar_edit_note_cb(GtkToggleToolButton * toggle_tool_button,gpointer data)1578 calendar_edit_note_cb (GtkToggleToolButton *toggle_tool_button, gpointer data) {
1579 
1580     GUI *appGUI = (GUI *)data;
1581     day_notes_toggled_cb (toggle_tool_button, appGUI);
1582 }
1583 
1584 /*------------------------------------------------------------------------------*/
1585 
1586 void
aux_cal_expander_cb(GObject * object,GParamSpec * param_spec,gpointer user_data)1587 aux_cal_expander_cb (GObject *object, GParamSpec *param_spec, gpointer user_data) {
1588 
1589     GUI *appGUI = (GUI *)user_data;
1590     config.auxilary_calendars_state = gtk_expander_get_expanded (GTK_EXPANDER(appGUI->cal->aux_cal_expander));
1591     update_aux_calendars (appGUI);
1592 }
1593 
1594 /*------------------------------------------------------------------------------*/
1595 
1596 gboolean
mouse_button_click_handler_cb(GtkWidget * widget,GdkEventButton * event,gpointer data)1597 mouse_button_click_handler_cb (GtkWidget * widget, GdkEventButton * event, gpointer data) {
1598 
1599     GUI *appGUI = (GUI *)data;
1600 
1601     if (event->type == GDK_BUTTON_PRESS && event->button == 3 && appGUI->calendar_only == FALSE) {    /* RMB */
1602         gtk_menu_popup(GTK_MENU(appGUI->cal->popup_menu), NULL, NULL, NULL, NULL, event->button, event->time);
1603         return TRUE;
1604     }
1605     return FALSE;
1606 }
1607 
1608 /*------------------------------------------------------------------------------*/
1609 
1610 #ifdef TASKS_ENABLED
1611 void
popup_add_task_entry_selected_cb(gpointer user_data)1612 popup_add_task_entry_selected_cb (gpointer user_data)
1613 {
1614     GUI *appGUI = (GUI *) user_data;
1615     GDate *date = g_date_new ();
1616 
1617     gui_calendar_get_gdate (GUI_CALENDAR (appGUI->cal->calendar), date);
1618     tasks_add_edit_dialog_show (FALSE, g_date_get_julian (date), utl_time_get_current_seconds (), appGUI);
1619     g_date_free (date);
1620 }
1621 #endif  /* TASKS_ENABLED */
1622 
1623 /*------------------------------------------------------------------------------*/
1624 
1625 void
popup_select_day_color_entry_selected_cb(gpointer user_data)1626 popup_select_day_color_entry_selected_cb (gpointer user_data)
1627 {
1628     GUI *appGUI = (GUI *) user_data;
1629     calendar_create_color_selector_window (TRUE, appGUI);
1630 }
1631 
1632 /*------------------------------------------------------------------------------*/
1633 
1634 void
popup_browse_notes_cb(gpointer user_data)1635 popup_browse_notes_cb (gpointer user_data)
1636 {
1637     GUI *appGUI = (GUI *) user_data;
1638     cal_notes_browser (appGUI);
1639 }
1640 
1641 /*------------------------------------------------------------------------------*/
1642 
1643 #ifdef PRINTING_SUPPORT
1644 static void
calendar_print_cb(GtkToolButton * toolbutton,gpointer data)1645 calendar_print_cb (GtkToolButton *toolbutton, gpointer data) {
1646 
1647     GUI *appGUI = (GUI *)data;
1648     calendar_create_print_window (appGUI);
1649 }
1650 #endif /* PRINTING_SUPPORT */
1651 
1652 /*------------------------------------------------------------------------------*/
1653 
1654 #ifdef HAVE_LIBICAL
1655 void
popup_ical_export_cb(gpointer user_data)1656 popup_ical_export_cb (gpointer user_data)
1657 {
1658     GUI *appGUI = (GUI *) user_data;
1659     ical_export (appGUI);
1660 }
1661 
1662 void
popup_ical_browse_cb(gpointer user_data)1663 popup_ical_browse_cb (gpointer user_data)
1664 {
1665     GUI *appGUI = (GUI *) user_data;
1666     ical_events_browser (appGUI);
1667 }
1668 #endif  /* HAVE_LIBICAL */
1669 
1670 /*------------------------------------------------------------------------------*/
1671 
1672 void
calendar_set_text_attribute_cb(GtkWidget * widget,gpointer user_data)1673 calendar_set_text_attribute_cb (GtkWidget *widget, gpointer user_data) {
1674 
1675 GtkTextBuffer *buffer;
1676 gchar *tagname;
1677 
1678     GUI *appGUI = (GUI *)user_data;
1679 
1680     tagname = (gchar*) g_object_get_data (G_OBJECT (widget), "tag");
1681     buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview));
1682     utl_gui_text_buffer_toggle_tags (buffer, tagname);
1683     g_signal_emit_by_name(G_OBJECT(buffer), "changed");
1684 }
1685 
1686 /*------------------------------------------------------------------------------*/
1687 
1688 void
date_selected_cb(GtkCalendar * calendar,gpointer user_data)1689 date_selected_cb (GtkCalendar *calendar, gpointer user_data)
1690 {
1691     GUI *appGUI = (GUI *)user_data;
1692     GDate *date = g_date_new ();
1693 
1694     if (!config.gui_layout) {
1695         if (gtk_expander_get_expanded (GTK_EXPANDER(appGUI->cal->aux_cal_expander)) == FALSE) {
1696             g_date_free (date);
1697             return;
1698         }
1699     }
1700 
1701     gui_calendar_get_gdate (GUI_CALENDAR (calendar), date);
1702     cal_jump_to_date (date, appGUI);
1703     g_date_free (date);
1704 }
1705 
1706 /*------------------------------------------------------------------------------*/
1707 
1708 #if defined(BACKUP_SUPPORT) && defined(HAVE_LIBGRINGOTTS)
1709 
1710 static void
button_create_backup_cb(GtkToolButton * toolbutton,gpointer data)1711 button_create_backup_cb(GtkToolButton *toolbutton, gpointer data) {
1712     GUI *appGUI = (GUI *) data;
1713     backup_create(appGUI);
1714 }
1715 
1716 static void
button_restore_backup_cb(GtkToolButton * toolbutton,gpointer data)1717 button_restore_backup_cb(GtkToolButton *toolbutton, gpointer data) {
1718     GUI *appGUI = (GUI *) data;
1719     backup_restore(appGUI);
1720 }
1721 
1722 #endif  /* BACKUP_SUPPORT && HAVE_LIBGRINGOTTS */
1723 
1724 /*------------------------------------------------------------------------------*/
1725 
1726 void
gui_set_calendar_defaults(GtkWidget * calendar)1727 gui_set_calendar_defaults(GtkWidget *calendar) {
1728 
1729     gui_calendar_set_color (GUI_CALENDAR (calendar),
1730 							config.background_color, 0,  BACKGROUND_COLOR);
1731     gui_calendar_set_color (GUI_CALENDAR (calendar),
1732 							config.header_bg_color, 0,  HEADER_BG_COLOR);
1733     gui_calendar_set_color (GUI_CALENDAR (calendar),
1734 							config.header_fg_color, 0, HEADER_FG_COLOR);
1735     gui_calendar_set_color (GUI_CALENDAR (calendar),
1736 							config.day_color, 0, DAY_COLOR);
1737     gui_calendar_set_color (GUI_CALENDAR (calendar),
1738 							config.pf_day_color, 0, PF_DAY_COLOR);
1739     gui_calendar_set_color (GUI_CALENDAR (calendar),
1740 							config.weekend_color, 0, WEEKEND_COLOR);
1741     gui_calendar_set_color (GUI_CALENDAR (calendar),
1742 							config.selection_color, config.selector_alpha, SELECTOR_COLOR);
1743 	gui_calendar_set_color (GUI_CALENDAR (calendar),
1744 							config.mark_color, 0, EVENT_MARKER_COLOR);
1745     gui_calendar_set_color (GUI_CALENDAR (calendar),
1746 							config.mark_current_day_color, config.mark_current_day_alpha, TODAY_MARKER_COLOR);
1747     gui_calendar_set_color (GUI_CALENDAR (calendar),
1748 							config.birthday_mark_color, 0, BIRTHDAY_MARKER_COLOR);
1749     gui_calendar_set_marker (GUI_CALENDAR (calendar),
1750 							 config.event_marker_type, EVENT_MARKER);
1751     gui_calendar_set_marker (GUI_CALENDAR (calendar),
1752 							 config.today_marker_type, TODAY_MARKER);
1753     gui_calendar_set_day_note_marker_symbol (GUI_CALENDAR (calendar),
1754 											 config.day_note_marker);
1755 }
1756 
1757 /*------------------------------------------------------------------------------*/
1758 
1759 void
gui_create_calendar(GtkWidget * notebook,GUI * appGUI)1760 gui_create_calendar(GtkWidget *notebook, GUI *appGUI) {
1761 
1762 GtkWidget       *vbox1;
1763 GtkWidget       *vbox2;
1764 GtkWidget       *vbox3;
1765 GtkWidget       *hbox1 = NULL;
1766 GtkWidget       *hbox2;
1767 GtkWidget       *hbox3;
1768 GtkWidget       *eventbox;
1769 GtkWidget       *hseparator;
1770 GtkWidget       *label;
1771 GtkWidget       *frame;
1772 GtkWidget       *vseparator;
1773 #ifdef PRINTING_SUPPORT
1774 GtkToolItem     *print_button;
1775 #endif /* PRINTING_SUPPORT */
1776 GtkToolItem     *preferences_button, *about_button;
1777 #if defined(BACKUP_SUPPORT) && defined(HAVE_LIBGRINGOTTS)
1778 GtkToolItem     *backup_button, *restore_button;
1779 #endif  /* BACKUP_SUPPORT && HAVE_LIBGRINGOTTS */
1780 GtkWidget       *note_scrolledwindow;
1781 #ifdef TASKS_ENABLED
1782 GtkWidget       *popup_menu_add_task_entry;
1783 #endif  /* TASKS_ENABLED */
1784 GtkWidget       *popup_menu_separator;
1785 GtkWidget       *popup_menu_browse_notes;
1786 GtkTextBuffer   *buffer;
1787 
1788 #ifdef HAVE_LIBICAL
1789 GtkWidget       *popup_menu_ical_browse;
1790 GtkWidget       *popup_menu_ical_export;
1791 #endif  /* HAVE_LIBICAL */
1792 
1793 
1794 gchar tmpbuf[BUFFER_SIZE];
1795 
1796     vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1797     gtk_widget_show (vbox1);
1798     gtk_container_set_border_width (GTK_CONTAINER (vbox1), 0);
1799     g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s</b>", _("Calendar"));
1800     gui_add_to_notebook (vbox1, tmpbuf, appGUI);
1801 
1802     appGUI->cal->vbox = GTK_BOX(vbox1);
1803 
1804     if (config.hide_calendar == TRUE) {
1805         gtk_widget_hide(GTK_WIDGET(appGUI->cal->vbox));
1806     }
1807 
1808     /*-------------------------------------------------------------------------------------*/
1809 
1810     appGUI->cal->calendar_toolbar = GTK_TOOLBAR(gtk_toolbar_new());
1811     gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(appGUI->cal->calendar_toolbar), FALSE, FALSE, 0);
1812 
1813     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_PREV_YEAR, _("Previous year"), calendar_btn_prev_year_cb), -1);
1814     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_PREV_MONTH, _("Previous month"), calendar_btn_prev_month_cb), -1);
1815     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_PREV_DAY, _("Previous day"), calendar_btn_prev_day_cb), -1);
1816     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_TODAY, _("Today"), calendar_btn_today_cb), -1);
1817     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_NEXT_DAY, _("Next day"), calendar_btn_next_day_cb), -1);
1818     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_NEXT_MONTH, _("Next month"), calendar_btn_next_month_cb), -1);
1819     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_NEXT_YEAR, _("Next year"), calendar_btn_next_year_cb), -1);
1820     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gtk_separator_tool_item_new(), -1);
1821     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_JUMPTO, _("Jump to date"), calendar_create_jumpto_window_cb), -1);
1822     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_FULLYEAR, _("Full-year calendar"), calendar_create_fullyear_window_cb), -1);
1823     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gui_create_toolbar_button(appGUI, OSMO_STOCK_CALCULATOR, _("Date calculator"), calendar_create_datecalc_window_cb), -1);
1824 #ifdef PRINTING_SUPPORT
1825     print_button = gui_create_toolbar_button(appGUI, OSMO_STOCK_PRINT, _("Print calendar"), calendar_print_cb);
1826     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, print_button, -1);
1827 #endif /* PRINTING_SUPPORT */
1828     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gtk_separator_tool_item_new(), -1);
1829     appGUI->cal->notes_button = gui_create_toolbar_toggle_button(appGUI, OSMO_STOCK_EDIT_NOTE, _("Toggle day note panel"), calendar_edit_note_cb);
1830     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, appGUI->cal->notes_button, -1);
1831     gui_append_toolbar_spring(appGUI->cal->calendar_toolbar);
1832 #if defined(BACKUP_SUPPORT) && defined(HAVE_LIBGRINGOTTS)
1833     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gtk_separator_tool_item_new(), -1);
1834     backup_button = gui_create_toolbar_button(appGUI, OSMO_STOCK_BACKUP, _("Backup data"), button_create_backup_cb);
1835     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, backup_button, -1);
1836     restore_button = gui_create_toolbar_button(appGUI, OSMO_STOCK_RESTORE, _("Restore data"), button_restore_backup_cb);
1837     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, restore_button, -1);
1838     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, gtk_separator_tool_item_new(), -1);
1839 #endif  /* BACKUP_SUPPORT && HAVE_LIBGRINGOTTS */
1840     preferences_button = gui_create_toolbar_button(appGUI, OSMO_STOCK_PREFERENCES, _("Preferences"), show_preferences_window_cb);
1841     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, preferences_button, -1);
1842     about_button = gui_create_toolbar_button(appGUI, OSMO_STOCK_ABOUT, _("About"), gui_show_about_window_cb);
1843     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, about_button, -1);
1844     appGUI->cal->quit_button = gui_create_toolbar_button(appGUI, "application-exit", _("Quit"), gui_quit_osmo_cb);
1845     gtk_toolbar_insert(appGUI->cal->calendar_toolbar, appGUI->cal->quit_button, -1);
1846 
1847     gtk_toolbar_set_style (appGUI->cal->calendar_toolbar, GTK_TOOLBAR_ICONS);
1848     gtk_toolbar_set_icon_size(appGUI->cal->calendar_toolbar, GTK_ICON_SIZE_LARGE_TOOLBAR);
1849     gtk_widget_show_all(GTK_WIDGET(appGUI->cal->calendar_toolbar));
1850 
1851     if (appGUI->calendar_only == TRUE) {
1852         gtk_widget_hide(GTK_WIDGET(appGUI->cal->notes_button));
1853         gtk_widget_set_sensitive(GTK_WIDGET(appGUI->cal->notes_button), FALSE);
1854 #ifdef PRINTING_SUPPORT
1855         gtk_widget_hide (GTK_WIDGET(print_button));
1856 #endif /* PRINTING_SUPPORT */
1857         gtk_widget_hide (GTK_WIDGET(preferences_button));
1858         gtk_widget_hide (GTK_WIDGET(about_button));
1859 #if defined(BACKUP_SUPPORT) && defined(HAVE_LIBGRINGOTTS)
1860         gtk_widget_hide (GTK_WIDGET(backup_button));
1861         gtk_widget_hide (GTK_WIDGET(restore_button));
1862 #endif  /* BACKUP_SUPPORT && HAVE_LIBGRINGOTTS */
1863     }
1864 
1865     /*-------------------------------------------------------------------------------------*/
1866 
1867     vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1868     gtk_widget_show (vbox2);
1869     gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0);
1870 
1871     if (config.gui_layout && appGUI->calendar_only == FALSE) {
1872         hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1873         gtk_widget_show (hbox1);
1874         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0);
1875     }
1876 
1877     vbox3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1878 	gtk_widget_set_hexpand (vbox3, FALSE);
1879 	gtk_widget_set_margin_left(vbox3, 8);
1880 	gtk_widget_set_margin_right(vbox3, 8);
1881 	gtk_widget_set_margin_bottom(vbox3, 8);
1882     gtk_widget_show (vbox3);
1883     if (appGUI->calendar_only == TRUE) {
1884             gtk_box_pack_start (GTK_BOX (vbox2), vbox3, TRUE, TRUE, 0);
1885     } else {
1886         if (!config.gui_layout) {
1887             gtk_box_pack_start (GTK_BOX (vbox2), vbox3, TRUE, TRUE, 0);
1888         } else {
1889             gtk_box_pack_start (GTK_BOX (hbox1), vbox3, FALSE, FALSE, 0);
1890         }
1891     }
1892 
1893     hseparator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
1894     gtk_widget_show (hseparator);
1895     gtk_box_pack_start (GTK_BOX (vbox3), hseparator, FALSE, FALSE, 6);
1896 
1897     eventbox = gtk_event_box_new ();
1898     gtk_widget_show (eventbox);
1899     gtk_box_pack_start (GTK_BOX (vbox3), eventbox, FALSE, FALSE, 0);
1900     g_signal_connect (G_OBJECT(eventbox), "button_press_event", G_CALLBACK(click_handler_cb), appGUI);
1901 
1902     hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1903     gtk_widget_show (hbox2);
1904     gtk_container_add (GTK_CONTAINER (eventbox), hbox2);
1905 
1906     /* Calendar popup menu */
1907 
1908     if (appGUI->calendar_only == FALSE) {
1909 
1910         appGUI->cal->popup_menu = gtk_menu_new();
1911 
1912 #ifdef TASKS_ENABLED
1913         popup_menu_add_task_entry = gtk_menu_item_new_with_label(_("Add task"));
1914         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_add_task_entry);
1915         g_signal_connect_swapped(G_OBJECT(popup_menu_add_task_entry), "activate",
1916                                  G_CALLBACK(popup_add_task_entry_selected_cb), appGUI);
1917         gtk_widget_show(popup_menu_add_task_entry);
1918 #endif  /* TASKS_ENABLED */
1919 
1920         appGUI->cal->popup_menu_select_day_color_entry = gtk_menu_item_new_with_label(_("Select day color"));
1921         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), appGUI->cal->popup_menu_select_day_color_entry);
1922         g_signal_connect_swapped(G_OBJECT(appGUI->cal->popup_menu_select_day_color_entry), "activate",
1923                                  G_CALLBACK(popup_select_day_color_entry_selected_cb), appGUI);
1924         gtk_widget_show(appGUI->cal->popup_menu_select_day_color_entry);
1925 
1926         popup_menu_separator = gtk_separator_menu_item_new();
1927         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_separator);
1928         gtk_widget_show(popup_menu_separator);
1929 
1930         popup_menu_browse_notes = gtk_menu_item_new_with_label(_("Browse notes"));
1931         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_browse_notes);
1932         g_signal_connect_swapped(G_OBJECT(popup_menu_browse_notes), "activate",
1933                                  G_CALLBACK(popup_browse_notes_cb), appGUI);
1934         gtk_widget_show(popup_menu_browse_notes);
1935 
1936 #ifdef HAVE_LIBICAL
1937 
1938         popup_menu_ical_browse = gtk_menu_item_new_with_label(_("Browse iCal events"));
1939         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_ical_browse);
1940         g_signal_connect_swapped(G_OBJECT(popup_menu_ical_browse), "activate",
1941                                  G_CALLBACK(popup_ical_browse_cb), appGUI);
1942         gtk_widget_show(popup_menu_ical_browse);
1943 
1944         popup_menu_separator = gtk_separator_menu_item_new();
1945         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_separator);
1946         gtk_widget_show(popup_menu_separator);
1947 
1948         popup_menu_ical_export = gtk_menu_item_new_with_label(_("Export to iCal file"));
1949         gtk_menu_shell_append(GTK_MENU_SHELL(appGUI->cal->popup_menu), popup_menu_ical_export);
1950         g_signal_connect_swapped(G_OBJECT(popup_menu_ical_export), "activate",
1951                                  G_CALLBACK(popup_ical_export_cb), appGUI);
1952         gtk_widget_show(popup_menu_ical_export);
1953 
1954 #endif  /* HAVE_LIBICAL */
1955 
1956     }
1957 
1958     appGUI->cal->date_label = gtk_label_new (NULL);
1959     gtk_widget_show (appGUI->cal->date_label);
1960     gtk_box_pack_start (GTK_BOX (hbox2), appGUI->cal->date_label, TRUE, FALSE, 8);
1961 
1962     hseparator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
1963     gtk_widget_show (hseparator);
1964     gtk_box_pack_start (GTK_BOX (vbox3), hseparator, FALSE, FALSE, 6);
1965 
1966     appGUI->cal->calendar = gui_calendar_new ();
1967     gtk_widget_show (appGUI->cal->calendar);
1968     gui_calendar_set_cursor_type(GUI_CALENDAR(appGUI->cal->calendar), config.cursor_type);
1969     gtk_widget_set_can_focus (appGUI->cal->calendar, FALSE);
1970     gui_calendar_set_display_options (GUI_CALENDAR (appGUI->cal->calendar), config.display_options);
1971     gtk_widget_override_font (GTK_WIDGET(appGUI->cal->calendar), appGUI->cal->fd_cal_font);
1972     gtk_box_pack_start (GTK_BOX (vbox3), appGUI->cal->calendar, FALSE, FALSE, 0);
1973     g_signal_connect (G_OBJECT (appGUI->cal->calendar), "day-selected",
1974                       G_CALLBACK (calendar_day_selected_cb), appGUI);
1975     g_signal_connect (G_OBJECT (appGUI->cal->calendar), "day-selected-double-click",
1976                       G_CALLBACK (calendar_dc_day_selected_cb), appGUI);
1977     g_signal_connect (G_OBJECT(appGUI->cal->calendar), "button_press_event",
1978                       G_CALLBACK(mouse_button_click_handler_cb), appGUI);
1979     gui_calendar_enable_cursor (GUI_CALENDAR (appGUI->cal->calendar), TRUE);
1980 	gui_set_calendar_defaults(appGUI->cal->calendar);
1981 
1982     appGUI->cal->month_selector_menu = gtk_menu_new();
1983     calendar_create_popup_menu (appGUI->cal->month_selector_menu, appGUI);
1984 
1985     hseparator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
1986     gtk_widget_show (hseparator);
1987     gtk_box_pack_start (GTK_BOX (vbox3), hseparator, FALSE, FALSE, 6);
1988 
1989     /*-------------------------------------------------------------------------------------*/
1990 
1991     if (appGUI->calendar_only == FALSE) {
1992 
1993         if (!config.gui_layout) {
1994             appGUI->cal->aux_cal_expander = gtk_expander_new (_("Previous and next month"));
1995             gtk_widget_set_can_focus (appGUI->cal->aux_cal_expander, FALSE);
1996             gtk_box_pack_start (GTK_BOX (vbox3), appGUI->cal->aux_cal_expander, FALSE, TRUE, 0);
1997         }
1998 
1999         appGUI->cal->aux_calendars_table = gtk_grid_new ();
2000         if (!config.gui_layout) {
2001             gtk_container_add (GTK_CONTAINER (appGUI->cal->aux_cal_expander), appGUI->cal->aux_calendars_table);
2002         } else {
2003             gtk_box_pack_start (GTK_BOX (vbox3), appGUI->cal->aux_calendars_table, FALSE, TRUE, 0);
2004         }
2005         gtk_grid_set_row_spacing (GTK_GRID (appGUI->cal->aux_calendars_table), 4);
2006         gtk_grid_set_column_spacing (GTK_GRID (appGUI->cal->aux_calendars_table), 4);
2007 
2008         if (config.enable_auxilary_calendars == TRUE) {
2009             if (!config.gui_layout) {
2010                 gtk_widget_show (appGUI->cal->aux_cal_expander);
2011             }
2012             gtk_widget_show (appGUI->cal->aux_calendars_table);
2013         }
2014 
2015         appGUI->cal->prev_month_label = gtk_label_new ("");
2016         gtk_widget_show (appGUI->cal->prev_month_label);
2017         gtk_widget_set_hexpand(appGUI->cal->prev_month_label, TRUE);
2018         gtk_grid_attach (GTK_GRID (appGUI->cal->aux_calendars_table), appGUI->cal->prev_month_label, 0, 0, 1, 1);
2019 
2020         appGUI->cal->next_month_label = gtk_label_new ("");
2021         gtk_widget_show (appGUI->cal->next_month_label);
2022         gtk_widget_set_hexpand(appGUI->cal->next_month_label, TRUE);
2023         gtk_grid_attach (GTK_GRID (appGUI->cal->aux_calendars_table), appGUI->cal->next_month_label, 1, 0, 1, 1);
2024 
2025         appGUI->cal->calendar_prev = gui_calendar_new ();
2026         gtk_widget_show (appGUI->cal->calendar_prev);
2027         gtk_widget_set_can_focus (appGUI->cal->calendar_prev, FALSE);
2028         gtk_grid_attach (GTK_GRID (appGUI->cal->aux_calendars_table), appGUI->cal->calendar_prev, 0, 1, 1, 1);
2029         gui_calendar_set_display_options (GUI_CALENDAR (appGUI->cal->calendar_prev),
2030                                           (config.display_options & (GUI_CALENDAR_SHOW_DAY_NAMES | GUI_CALENDAR_WEEK_START_MONDAY)) | GUI_CALENDAR_NO_MONTH_CHANGE);
2031         gui_calendar_enable_cursor (GUI_CALENDAR (appGUI->cal->calendar_prev), FALSE);
2032  		gui_set_calendar_defaults(appGUI->cal->calendar_prev);
2033 
2034         g_signal_connect (G_OBJECT (appGUI->cal->calendar_prev), "day_selected_double_click",
2035                                   G_CALLBACK (date_selected_cb), appGUI);
2036 
2037         appGUI->cal->calendar_next = gui_calendar_new ();
2038         gtk_widget_show (appGUI->cal->calendar_next);
2039         gtk_widget_set_can_focus (appGUI->cal->calendar_next, FALSE);
2040         gtk_grid_attach (GTK_GRID (appGUI->cal->aux_calendars_table), appGUI->cal->calendar_next, 1, 1, 1, 1);
2041         gui_calendar_set_display_options (GUI_CALENDAR (appGUI->cal->calendar_next),
2042                                           (config.display_options & (GUI_CALENDAR_SHOW_DAY_NAMES | GUI_CALENDAR_WEEK_START_MONDAY)) | GUI_CALENDAR_NO_MONTH_CHANGE);
2043         gui_calendar_enable_cursor (GUI_CALENDAR (appGUI->cal->calendar_next), FALSE);
2044 		gui_set_calendar_defaults(appGUI->cal->calendar_next);
2045 
2046         g_signal_connect (G_OBJECT (appGUI->cal->calendar_next), "day_selected_double_click",
2047                                   G_CALLBACK (date_selected_cb), appGUI);
2048 
2049     /*-------------------------------------------------------------------------------------*/
2050     /* notes */
2051 
2052         appGUI->cal->notes_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2053         gtk_widget_show (appGUI->cal->notes_vbox);
2054 		gtk_widget_set_margin_right(GTK_WIDGET(appGUI->cal->notes_vbox), 8);
2055 		gtk_widget_set_margin_bottom(GTK_WIDGET(appGUI->cal->notes_vbox), 8);
2056         if (!config.gui_layout) {
2057             gtk_box_pack_start (GTK_BOX (vbox3), appGUI->cal->notes_vbox, TRUE, TRUE, 0);
2058         } else {
2059             gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->notes_vbox, TRUE, TRUE, 0);
2060         }
2061 
2062         hbox3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
2063         gtk_widget_show (hbox3);
2064         gtk_box_pack_start (GTK_BOX (appGUI->cal->notes_vbox), hbox3, FALSE, FALSE, 0);
2065 
2066         g_snprintf (tmpbuf, BUFFER_SIZE, "%s:", _("Notes"));
2067         label = gtk_label_new (tmpbuf);
2068         gtk_widget_show (label);
2069         gtk_box_pack_start (GTK_BOX (hbox3), label, FALSE, FALSE, 4);
2070 
2071         appGUI->cal->n_close_button = gtk_button_new_from_icon_name("window-close", GTK_ICON_SIZE_BUTTON);
2072         gtk_widget_set_can_focus (appGUI->cal->n_close_button, FALSE);
2073         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->n_close_button), GTK_RELIEF_NONE);
2074         if (config.enable_tooltips) {
2075             gtk_widget_set_tooltip_text (appGUI->cal->n_close_button, _("Close note panel"));
2076         }
2077         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->n_close_button, FALSE, FALSE, 1);
2078         g_signal_connect (G_OBJECT (appGUI->cal->n_close_button), "clicked",
2079                             G_CALLBACK (calendar_close_text_cb), appGUI);
2080 
2081         appGUI->cal->ta_highlight_button = gtk_button_new_from_icon_name (OSMO_STOCK_EDITOR_HIGHLIGHT_S, GTK_ICON_SIZE_BUTTON);
2082         gtk_widget_show (appGUI->cal->ta_highlight_button);
2083         gtk_widget_set_can_focus (appGUI->cal->ta_highlight_button, FALSE);
2084         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->ta_highlight_button), GTK_RELIEF_NONE);
2085         if (config.enable_tooltips) {
2086             gtk_widget_set_tooltip_text (appGUI->cal->ta_highlight_button, _("Highlight"));
2087         }
2088         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->ta_highlight_button, FALSE, FALSE, 1);
2089         g_object_set_data (G_OBJECT (appGUI->cal->ta_highlight_button), "tag", "mark_color");
2090         g_signal_connect (G_OBJECT (appGUI->cal->ta_highlight_button), "clicked",
2091                           G_CALLBACK (calendar_set_text_attribute_cb), appGUI);
2092 
2093         appGUI->cal->ta_strikethrough_button = gtk_button_new_from_icon_name (OSMO_STOCK_EDITOR_STRIKETHROUGH_S, GTK_ICON_SIZE_BUTTON);
2094         gtk_widget_show (appGUI->cal->ta_strikethrough_button);
2095         gtk_widget_set_can_focus (appGUI->cal->ta_strikethrough_button, FALSE);
2096         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->ta_strikethrough_button), GTK_RELIEF_NONE);
2097         if (config.enable_tooltips) {
2098             gtk_widget_set_tooltip_text (appGUI->cal->ta_strikethrough_button, _("Strikethrough"));
2099         }
2100         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->ta_strikethrough_button, FALSE, FALSE, 1);
2101         g_object_set_data (G_OBJECT (appGUI->cal->ta_strikethrough_button), "tag", "strike");
2102         g_signal_connect (G_OBJECT (appGUI->cal->ta_strikethrough_button), "clicked",
2103                           G_CALLBACK (calendar_set_text_attribute_cb), appGUI);
2104 
2105         appGUI->cal->ta_underline_button = gtk_button_new_from_icon_name (OSMO_STOCK_EDITOR_UNDERLINE_S, GTK_ICON_SIZE_BUTTON);
2106         gtk_widget_show (appGUI->cal->ta_underline_button);
2107         gtk_widget_set_can_focus (appGUI->cal->ta_underline_button, FALSE);
2108         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->ta_underline_button), GTK_RELIEF_NONE);
2109         if (config.enable_tooltips) {
2110             gtk_widget_set_tooltip_text (appGUI->cal->ta_underline_button, _("Underline"));
2111         }
2112         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->ta_underline_button, FALSE, FALSE, 1);
2113         g_object_set_data (G_OBJECT (appGUI->cal->ta_underline_button), "tag", "underline");
2114         g_signal_connect (G_OBJECT (appGUI->cal->ta_underline_button), "clicked",
2115                           G_CALLBACK (calendar_set_text_attribute_cb), appGUI);
2116 
2117         appGUI->cal->ta_italic_button = gtk_button_new_from_icon_name (OSMO_STOCK_EDITOR_ITALIC_S, GTK_ICON_SIZE_BUTTON);
2118         gtk_widget_show (appGUI->cal->ta_italic_button);
2119         gtk_widget_set_can_focus (appGUI->cal->ta_italic_button, FALSE);
2120         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->ta_italic_button), GTK_RELIEF_NONE);
2121         if (config.enable_tooltips) {
2122             gtk_widget_set_tooltip_text (appGUI->cal->ta_italic_button, _("Italic"));
2123         }
2124         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->ta_italic_button, FALSE, FALSE, 1);
2125         g_object_set_data (G_OBJECT (appGUI->cal->ta_italic_button), "tag", "italic");
2126         g_signal_connect (G_OBJECT (appGUI->cal->ta_italic_button), "clicked",
2127                           G_CALLBACK (calendar_set_text_attribute_cb), appGUI);
2128 
2129         appGUI->cal->ta_bold_button = gtk_button_new_from_icon_name (OSMO_STOCK_EDITOR_BOLD_S, GTK_ICON_SIZE_BUTTON);
2130         gtk_widget_show (appGUI->cal->ta_bold_button);
2131         gtk_widget_set_can_focus (appGUI->cal->ta_bold_button, FALSE);
2132         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->ta_bold_button), GTK_RELIEF_NONE);
2133         if (config.enable_tooltips) {
2134             gtk_widget_set_tooltip_text (appGUI->cal->ta_bold_button, _("Bold"));
2135         }
2136         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->ta_bold_button, FALSE, FALSE, 1);
2137         g_object_set_data (G_OBJECT (appGUI->cal->ta_bold_button), "tag", "bold");
2138         g_signal_connect (G_OBJECT (appGUI->cal->ta_bold_button), "clicked",
2139                           G_CALLBACK (calendar_set_text_attribute_cb), appGUI);
2140 
2141         vseparator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
2142         gtk_widget_show (vseparator);
2143         gtk_box_pack_end (GTK_BOX (hbox3), vseparator, FALSE, TRUE, 0);
2144 
2145         appGUI->cal->n_timeline_button = gtk_button_new_from_icon_name (OSMO_STOCK_BUTTON_INSERT_TIMELINE, GTK_ICON_SIZE_BUTTON);
2146         gtk_widget_show (appGUI->cal->n_timeline_button);
2147         gtk_widget_set_can_focus (appGUI->cal->n_timeline_button, FALSE);
2148         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->n_timeline_button), GTK_RELIEF_NONE);
2149         if (config.enable_tooltips) {
2150             gtk_widget_set_tooltip_text (appGUI->cal->n_timeline_button, _("Insert timeline"));
2151         }
2152         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->n_timeline_button, FALSE, FALSE, 1);
2153         g_signal_connect (G_OBJECT (appGUI->cal->n_timeline_button), "clicked",
2154                             G_CALLBACK (calendar_insert_timeline_cb), appGUI);
2155 
2156         appGUI->cal->n_clear_button = gtk_button_new_from_icon_name("edit-clear", GTK_ICON_SIZE_BUTTON);
2157         gtk_widget_show (appGUI->cal->n_clear_button);
2158         gtk_widget_set_can_focus  (appGUI->cal->n_clear_button, FALSE);
2159         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->n_clear_button), GTK_RELIEF_NONE);
2160         if (config.enable_tooltips) {
2161             gtk_widget_set_tooltip_text (appGUI->cal->n_clear_button, _("Clear text"));
2162         }
2163         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->n_clear_button, FALSE, FALSE, 1);
2164         g_signal_connect (G_OBJECT (appGUI->cal->n_clear_button), "clicked",
2165                             G_CALLBACK (calendar_clear_text_cb), appGUI);
2166 
2167         appGUI->cal->n_select_color_button = gtk_button_new_from_icon_name (OSMO_STOCK_BUTTON_SELECT_COLOR, GTK_ICON_SIZE_BUTTON);
2168         gtk_widget_show (appGUI->cal->n_select_color_button);
2169         gtk_widget_set_can_focus  (appGUI->cal->n_select_color_button, FALSE);
2170         gtk_button_set_relief (GTK_BUTTON(appGUI->cal->n_select_color_button), GTK_RELIEF_NONE);
2171         if (config.enable_tooltips) {
2172             gtk_widget_set_tooltip_text (appGUI->cal->n_select_color_button, _("Select day color"));
2173         }
2174         gtk_box_pack_end (GTK_BOX (hbox3), appGUI->cal->n_select_color_button, FALSE, FALSE, 1);
2175         g_signal_connect (G_OBJECT (appGUI->cal->n_select_color_button), "clicked",
2176                             G_CALLBACK (calendar_select_color_cb), appGUI);
2177 
2178         note_scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
2179         gtk_widget_show (note_scrolledwindow);
2180         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (note_scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2181         gtk_box_pack_start (GTK_BOX (appGUI->cal->notes_vbox), note_scrolledwindow, TRUE, TRUE, 0);
2182         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (note_scrolledwindow), GTK_SHADOW_IN);
2183 
2184         appGUI->cal->calendar_note_textview = gtk_text_view_new ();
2185         gtk_widget_show (appGUI->cal->calendar_note_textview);
2186         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview));
2187         g_signal_connect (G_OBJECT (buffer), "changed",
2188                           G_CALLBACK (calendar_textbuffer_changed_cb), appGUI);
2189         gtk_container_add (GTK_CONTAINER (note_scrolledwindow), appGUI->cal->calendar_note_textview);
2190         gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), TRUE);
2191         gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (appGUI->cal->calendar_note_textview), GTK_WRAP_WORD_CHAR);
2192         gtk_widget_override_font (GTK_WIDGET(appGUI->cal->calendar_note_textview), appGUI->cal->fd_notes_font);
2193         gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), 4);
2194         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), 4);
2195         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), 4);
2196 
2197         gtk_text_buffer_create_tag (buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
2198         gtk_text_buffer_create_tag (buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL);
2199         gtk_text_buffer_create_tag (buffer, "strike", "strikethrough", TRUE, NULL);
2200         gtk_text_buffer_create_tag (buffer, "underline", "underline", PANGO_UNDERLINE_SINGLE, NULL);
2201         gtk_text_buffer_create_tag (buffer, "mark_color", "background", "#FFFF00", NULL);
2202 
2203 #ifdef HAVE_GSPELL
2204         utl_gui_set_enable_spell_check(appGUI->cal->calendar_note_spelltextview, config.day_note_spell_checker);
2205 #endif  /* HAVE_GSPELL */
2206     /*-------------------------------------------------------------------------------------*/
2207     /* day info */
2208 
2209         appGUI->cal->day_info_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2210         gtk_widget_show (appGUI->cal->day_info_vbox);
2211         if (!config.gui_layout) {
2212             gtk_box_pack_start (GTK_BOX (vbox3), appGUI->cal->day_info_vbox, TRUE, TRUE, 0);
2213         } else {
2214             gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->day_info_vbox, TRUE, TRUE, 0);
2215         }
2216 
2217         frame = gtk_frame_new (NULL);
2218         gtk_widget_show (frame);
2219         gtk_box_pack_start (GTK_BOX (appGUI->cal->day_info_vbox), frame, TRUE, TRUE, 0);
2220         gtk_widget_set_margin_right(GTK_WIDGET(frame), 8);
2221         gtk_widget_set_margin_bottom(GTK_WIDGET(frame), 8);
2222         gtk_frame_set_label_align (GTK_FRAME (frame), 0.98, 0.5);
2223         gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
2224 
2225         g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s</b>", _("Info"));
2226         label = gtk_label_new (tmpbuf);
2227         gtk_widget_show (label);
2228         gtk_frame_set_label_widget (GTK_FRAME (frame), label);
2229         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2230 
2231         appGUI->cal->day_info_scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
2232         gtk_widget_show (appGUI->cal->day_info_scrolledwindow);
2233         gtk_container_add (GTK_CONTAINER (frame), appGUI->cal->day_info_scrolledwindow);
2234         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (appGUI->cal->day_info_scrolledwindow),
2235                                              GTK_SHADOW_NONE);
2236         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (appGUI->cal->day_info_scrolledwindow),
2237                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2238 
2239 #ifdef HAVE_LIBWEBKIT
2240         appGUI->cal->html_webkitview = utl_create_webkit_web_view(appGUI);
2241 
2242         g_signal_connect (appGUI->cal->html_webkitview, "context-menu",
2243                           G_CALLBACK (utl_webkit_on_menu), appGUI);
2244         g_signal_connect (appGUI->cal->html_webkitview, "decide-policy",
2245                           G_CALLBACK (utl_webkit_link_clicked), appGUI);
2246 
2247         gtk_widget_show (GTK_WIDGET(appGUI->cal->html_webkitview));
2248         gtk_container_add (GTK_CONTAINER (appGUI->cal->day_info_scrolledwindow),
2249                            GTK_WIDGET(appGUI->cal->html_webkitview));
2250 
2251 #else
2252         appGUI->cal->day_desc_textview = gtk_text_view_new ();
2253         gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (appGUI->cal->day_desc_textview), GTK_WRAP_WORD);
2254         gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), 4);
2255         gtk_text_view_set_left_margin (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), 4);
2256         gtk_text_view_set_right_margin (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), 4);
2257         gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), FALSE);
2258         gtk_text_view_set_editable (GTK_TEXT_VIEW(appGUI->cal->day_desc_textview), FALSE);
2259         gtk_widget_show (appGUI->cal->day_desc_textview);
2260         gtk_container_add (GTK_CONTAINER (appGUI->cal->day_info_scrolledwindow), appGUI->cal->day_desc_textview);
2261         gtk_widget_realize (appGUI->cal->day_desc_textview);
2262 
2263         appGUI->cal->day_desc_text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(appGUI->cal->day_desc_textview));
2264         gtk_text_buffer_create_tag (appGUI->cal->day_desc_text_buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
2265         gtk_text_buffer_create_tag (appGUI->cal->day_desc_text_buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL);
2266         gtk_text_buffer_create_tag (appGUI->cal->day_desc_text_buffer, "strike", "strikethrough", TRUE, NULL);
2267         gtk_text_buffer_create_tag (appGUI->cal->day_desc_text_buffer, "underline", "underline", PANGO_UNDERLINE_SINGLE, NULL);
2268         gtk_text_buffer_create_tag (appGUI->cal->day_desc_text_buffer, "mark_color", "background", "#FFFF00", NULL);
2269 
2270 #endif  /* HAVE_LIBWEBKIT */
2271 
2272     /*-------------------------------------------------------------------------------------*/
2273 
2274     }
2275 
2276     gtk_widget_override_font (GTK_WIDGET(appGUI->cal->date_label), appGUI->cal->fd_day_name_font);
2277 
2278     gui_calendar_get_gdate (GUI_CALENDAR (appGUI->cal->calendar), appGUI->cal->date);
2279 
2280     gui_calendar_set_frame_cursor_thickness (GUI_CALENDAR (appGUI->cal->calendar), config.frame_cursor_thickness);
2281 
2282     if (appGUI->calendar_only == FALSE) {
2283         if (!config.day_notes_visible) {
2284             gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON(appGUI->cal->notes_button), FALSE);
2285             gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), FALSE);
2286             gtk_text_view_set_editable(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), FALSE);
2287             gtk_widget_show(appGUI->cal->day_info_vbox);
2288             gtk_widget_hide(appGUI->cal->notes_vbox);
2289         } else {
2290             gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON(appGUI->cal->notes_button), TRUE);
2291             gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), TRUE);
2292             gtk_text_view_set_editable(GTK_TEXT_VIEW(appGUI->cal->calendar_note_textview), TRUE);
2293             gtk_widget_hide(appGUI->cal->day_info_vbox);
2294             gtk_widget_show(appGUI->cal->notes_vbox);
2295         }
2296 
2297         gtk_widget_realize(GTK_WIDGET(appGUI->cal->calendar_note_textview));
2298         gtk_widget_grab_focus(GTK_WIDGET(appGUI->cal->calendar_note_textview));
2299     }
2300 
2301     if (appGUI->calendar_only == FALSE) {
2302         if (!config.gui_layout) {
2303             g_signal_connect (G_OBJECT(appGUI->cal->aux_cal_expander), "notify::expanded",
2304                               G_CALLBACK(aux_cal_expander_cb), appGUI);
2305             gtk_expander_set_expanded (GTK_EXPANDER(appGUI->cal->aux_cal_expander), config.auxilary_calendars_state);
2306         } else {
2307             update_aux_calendars (appGUI);
2308         }
2309     }
2310     gtk_label_set_text (GTK_LABEL (appGUI->cal->date_label), utl_get_date_name_format (appGUI->cal->date, config.date_header_format));
2311 }
2312 
2313 /*------------------------------------------------------------------------------*/
2314 
2315 void
select_bg_color_close_cb(GtkWidget * widget,GdkEvent * event,gpointer user_data)2316 select_bg_color_close_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
2317 {
2318     GUI *appGUI = (GUI *) user_data;
2319     gtk_widget_destroy (appGUI->cal->select_bg_color_window);
2320 }
2321 
2322 /*------------------------------------------------------------------------------*/
2323 
2324 void
button_select_bg_color_close_cb(GtkWidget * widget,gpointer user_data)2325 button_select_bg_color_close_cb (GtkWidget *widget, gpointer user_data)
2326 {
2327     select_bg_color_close_cb (widget, NULL, user_data);
2328 }
2329 
2330 /*------------------------------------------------------------------------------*/
2331 
2332 void
colors_category_selected(GUI * appGUI)2333 colors_category_selected (GUI *appGUI)
2334 {
2335     GtkTreeModel *model;
2336     GtkTreeIter iter;
2337 
2338     if (gtk_tree_selection_get_selected(appGUI->cal->colors_category_select, &model, &iter)) {
2339         gchar *color_val = NULL;
2340 
2341         gtk_tree_model_get(GTK_TREE_MODEL(appGUI->cal->colors_category_store), &iter, 1, &color_val, -1);
2342         calendar_store_note(appGUI->cal->date, color_val, appGUI);
2343         cal_refresh_notes(appGUI);
2344         select_bg_color_close_cb(NULL, NULL, appGUI);
2345         g_free(color_val);
2346     }
2347 
2348 }
2349 
2350 /*------------------------------------------------------------------------------*/
2351 
2352 void
select_bg_color_apply_cb(GtkWidget * widget,gpointer user_data)2353 select_bg_color_apply_cb (GtkWidget *widget, gpointer user_data)
2354 {
2355     GUI *appGUI = (GUI *) user_data;
2356 
2357     config.enable_day_mark = TRUE;
2358     colors_category_selected (appGUI);
2359 }
2360 
2361 /*------------------------------------------------------------------------------*/
2362 
2363 gint
select_bg_color_key_press_cb(GtkWidget * widget,GdkEventKey * event,gpointer user_data)2364 select_bg_color_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
2365 {
2366     GUI *appGUI = (GUI *) user_data;
2367 
2368     switch (event->keyval) {
2369 
2370         case GDK_KEY_Return:
2371             config.enable_day_mark = TRUE;
2372             colors_category_selected (appGUI);
2373             return TRUE;
2374 
2375         case GDK_KEY_Escape:
2376             select_bg_color_close_cb (NULL, NULL, appGUI);
2377             return TRUE;
2378     }
2379 
2380     return FALSE;
2381 }
2382 
2383 /*------------------------------------------------------------------------------*/
2384 
2385 gint
colors_list_dbclick_cb(GtkWidget * widget,GdkEventButton * event,gpointer user_data)2386 colors_list_dbclick_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
2387 {
2388     GUI *appGUI = (GUI *) user_data;
2389 
2390     if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) {
2391         config.enable_day_mark = TRUE;
2392         colors_category_selected (appGUI);
2393         return TRUE;
2394     }
2395 
2396     return FALSE;
2397 }
2398 
2399 /*------------------------------------------------------------------------------*/
2400 
2401 void
calendar_create_color_selector_window(gboolean window_pos,GUI * appGUI)2402 calendar_create_color_selector_window (gboolean window_pos, GUI *appGUI) {
2403 
2404 GtkWidget *vbox1;
2405 GtkWidget *scrolledwindow;
2406 GtkWidget *colors_category_treeview;
2407 GtkWidget *hseparator;
2408 GtkWidget *hbuttonbox;
2409 GtkWidget *ok_button;
2410 GtkWidget *cancel_button;
2411 GtkTreeIter iter;
2412 GtkCellRenderer     *renderer;
2413 GtkTreeViewColumn   *column;
2414 GtkTreePath     *path;
2415 GdkPixbuf *image;
2416 gchar *color_val, *color_name, *color_sel;
2417 gboolean has_next;
2418 
2419     if (cal_check_note (g_date_get_julian (appGUI->cal->date), appGUI) == FALSE && !config.day_notes_visible) return;
2420 
2421     config.enable_day_mark = TRUE;
2422     cal_refresh_marks (appGUI);
2423     update_aux_calendars (appGUI);
2424 
2425     appGUI->cal->select_bg_color_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2426     gtk_container_set_border_width (GTK_CONTAINER (appGUI->cal->select_bg_color_window), 4);
2427     gtk_window_set_title (GTK_WINDOW (appGUI->cal->select_bg_color_window), _("Select color"));
2428     gtk_window_set_default_size (GTK_WINDOW(appGUI->cal->select_bg_color_window), 200, 280);
2429     gtk_window_set_transient_for(GTK_WINDOW(appGUI->cal->select_bg_color_window), GTK_WINDOW(appGUI->main_window));
2430     if (window_pos == TRUE) {
2431         gtk_window_set_position(GTK_WINDOW(appGUI->cal->select_bg_color_window), GTK_WIN_POS_CENTER_ON_PARENT);
2432     } else {
2433         gtk_window_set_position(GTK_WINDOW(appGUI->cal->select_bg_color_window), GTK_WIN_POS_MOUSE);
2434     }
2435     gtk_window_set_modal(GTK_WINDOW(appGUI->cal->select_bg_color_window), TRUE);
2436     g_signal_connect (G_OBJECT (appGUI->cal->select_bg_color_window), "delete_event",
2437                       G_CALLBACK(select_bg_color_close_cb), appGUI);
2438     g_signal_connect (G_OBJECT (appGUI->cal->select_bg_color_window), "key_press_event",
2439                       G_CALLBACK (select_bg_color_key_press_cb), appGUI);
2440 
2441     vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
2442     gtk_widget_show (vbox1);
2443     gtk_container_add (GTK_CONTAINER (appGUI->cal->select_bg_color_window), vbox1);
2444 
2445     scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
2446     gtk_widget_show (scrolledwindow);
2447     gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow, TRUE, TRUE, 0);
2448     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2449     gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
2450 
2451     appGUI->cal->colors_category_store = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
2452 
2453     colors_category_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(appGUI->cal->colors_category_store));
2454     g_signal_connect(G_OBJECT(colors_category_treeview), "button_press_event",
2455                      G_CALLBACK(colors_list_dbclick_cb), appGUI);
2456     appGUI->cal->colors_category_select = gtk_tree_view_get_selection(GTK_TREE_VIEW(colors_category_treeview));
2457     gtk_widget_show (colors_category_treeview);
2458     gtk_container_add (GTK_CONTAINER (scrolledwindow), colors_category_treeview);
2459     gtk_container_set_border_width (GTK_CONTAINER (colors_category_treeview), 4);
2460     gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (colors_category_treeview), FALSE);
2461     gtk_tree_view_set_enable_search (GTK_TREE_VIEW (colors_category_treeview), FALSE);
2462 
2463     renderer = gtk_cell_renderer_pixbuf_new();
2464     column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "pixbuf", 0, NULL);
2465     gtk_tree_view_append_column(GTK_TREE_VIEW(colors_category_treeview), column);
2466 
2467     renderer = gtk_cell_renderer_text_new();
2468     column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 1, NULL);
2469     gtk_tree_view_append_column(GTK_TREE_VIEW(colors_category_treeview), column);
2470     gtk_tree_view_column_set_visible (column, FALSE);
2471 
2472     renderer = gtk_cell_renderer_text_new();
2473     column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 2, NULL);
2474     gtk_tree_view_append_column(GTK_TREE_VIEW(colors_category_treeview), column);
2475 
2476     image = utl_gui_create_color_swatch ("None");
2477     gtk_list_store_append(appGUI->cal->colors_category_store, &iter);
2478     gtk_list_store_set(appGUI->cal->colors_category_store, &iter, 0, image, 1, NULL, 2, _("None"), -1);
2479     g_object_unref (image);
2480 
2481     color_sel = cal_get_note_color (g_date_get_julian (appGUI->cal->date), appGUI);
2482 
2483     has_next = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(appGUI->opt->calendar_category_store), &iter);
2484     while (has_next) {
2485         GtkTreeIter color_iter;
2486         gtk_tree_model_get(GTK_TREE_MODEL(appGUI->opt->calendar_category_store), &iter, 1, &color_val, 2, &color_name, -1);
2487         image = utl_gui_create_color_swatch (color_val);
2488         gtk_list_store_append(appGUI->cal->colors_category_store, &color_iter);
2489         gtk_list_store_set(appGUI->cal->colors_category_store, &color_iter, 0, image, 1, color_val, 2, color_name, -1);
2490 
2491         if (color_sel != NULL) {
2492             if (!strcmp(color_val, color_sel)) {
2493                 path = gtk_tree_model_get_path (GTK_TREE_MODEL(appGUI->cal->colors_category_store), &color_iter);
2494                 if (path != NULL) {
2495                     gtk_tree_view_set_cursor (GTK_TREE_VIEW (colors_category_treeview), path, NULL, FALSE);
2496                     gtk_tree_path_free(path);
2497                 }
2498             }
2499         }
2500 
2501         g_object_unref (image);
2502         g_free(color_val);
2503         g_free(color_name);
2504         has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL(appGUI->opt->calendar_category_store), &iter);
2505     }
2506 
2507     hseparator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
2508     gtk_widget_show (hseparator);
2509     gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4);
2510 
2511     hbuttonbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
2512     gtk_widget_show (hbuttonbox);
2513     gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, FALSE, 0);
2514     gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
2515     gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4);
2516 
2517     cancel_button = gtk_button_new_with_mnemonic (_("_Cancel"));
2518     gtk_widget_set_can_focus (cancel_button, FALSE);
2519     gtk_widget_show (cancel_button);
2520     gtk_container_add (GTK_CONTAINER (hbuttonbox), cancel_button);
2521     g_signal_connect (G_OBJECT (cancel_button), "clicked",
2522                         G_CALLBACK (button_select_bg_color_close_cb), appGUI);
2523 
2524     ok_button = gtk_button_new_with_mnemonic (_("_OK"));
2525     gtk_widget_set_can_focus (ok_button, FALSE);
2526     gtk_widget_show (ok_button);
2527     gtk_container_add (GTK_CONTAINER (hbuttonbox), ok_button);
2528     g_signal_connect (G_OBJECT (ok_button), "clicked",
2529                         G_CALLBACK (select_bg_color_apply_cb), appGUI);
2530 
2531     gtk_widget_show (appGUI->cal->select_bg_color_window);
2532 }
2533 
2534 /*------------------------------------------------------------------------------*/
2535 
2536 void
menu_entry_selected_cb(gpointer user_data)2537 menu_entry_selected_cb (gpointer user_data)
2538 {
2539     MESSAGE *msg = (MESSAGE *) user_data;
2540     calendar_update_date (g_date_get_day (msg->appGUI->cal->date), (size_t) msg->data,
2541                           g_date_get_year (msg->appGUI->cal->date), msg->appGUI);
2542 }
2543 
2544 /*------------------------------------------------------------------------------*/
2545 
2546 void
calendar_create_popup_menu(GtkWidget * menu,GUI * appGUI)2547 calendar_create_popup_menu (GtkWidget *menu, GUI *appGUI)
2548 {
2549 static MESSAGE msg_month[MAX_MONTHS];
2550 GtkWidget *menu_entry;
2551 gchar buffer[BUFFER_SIZE];
2552 GDate *tmpdate;
2553 gint i;
2554 
2555     tmpdate = g_date_new_dmy (1, 1, utl_date_get_current_year ());
2556     g_return_if_fail (tmpdate != NULL);
2557 
2558     for (i = G_DATE_JANUARY; i <= G_DATE_DECEMBER; i++) {
2559         g_date_set_month (tmpdate, i);
2560         g_date_strftime (buffer, BUFFER_SIZE, "%B", tmpdate);
2561 
2562         menu_entry = gtk_menu_item_new_with_label (buffer);
2563         gtk_menu_shell_append (GTK_MENU_SHELL (appGUI->cal->month_selector_menu), menu_entry);
2564         msg_month[i-1].data = (gpointer) ((size_t)i);
2565         msg_month[i-1].appGUI = appGUI;
2566         g_signal_connect_swapped (G_OBJECT (menu_entry), "activate",
2567                                   G_CALLBACK (menu_entry_selected_cb), &msg_month[i-1]);
2568         gtk_widget_show (menu_entry);
2569     }
2570 
2571     g_date_free (tmpdate);
2572 }
2573 
2574 /*------------------------------------------------------------------------------*/
2575 
2576 void
calendar_mark_events(GtkWidget * calendar,guint32 julian_day,guint i,GUI * appGUI)2577 calendar_mark_events (GtkWidget *calendar, guint32 julian_day, guint i, GUI *appGUI) {
2578 
2579 gboolean flag = FALSE;
2580 
2581     if (appGUI->calendar_only == TRUE || appGUI->all_pages_added == FALSE)
2582         return;
2583 
2584 #ifdef TASKS_ENABLED
2585     if (tsk_check_tasks (julian_day, julian_day, STATE_CALENDAR, appGUI) == TRUE) {
2586         gui_calendar_mark_day (GUI_CALENDAR (calendar), i, EVENT_MARK);
2587         flag = TRUE;
2588     }
2589 #endif  /* TASKS_ENABLED */
2590 
2591 #ifdef HAVE_LIBICAL
2592     if (flag == FALSE) {
2593         if (ics_check_event (julian_day, appGUI) == TRUE) {
2594             gui_calendar_mark_day (GUI_CALENDAR (calendar), i, EVENT_MARK);
2595         }
2596     }
2597 #endif  /* HAVE_LIBICAL */
2598 
2599 #ifdef CONTACTS_ENABLED
2600     if (check_contacts (julian_day, appGUI) == TRUE) {
2601         gui_calendar_mark_day (GUI_CALENDAR (calendar), i, BIRTHDAY_MARK);
2602     }
2603 #endif  /* CONTACTS_ENABLED */
2604 
2605 }
2606 
2607 /*------------------------------------------------------------------------------*/
2608 
2609