1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* GnomeCalendar widget
* Copyright (C) 1998 the Free Software Foundation
*
* Authors: Miguel de Icaza (miguel@kernel.org)
* Federico Mena-Quintero <federico@helixcode.com>
*/
#include <config.h>
#include <gnome.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <gnome.h>
#include <gal/e-paned/e-hpaned.h>
#include <gal/e-paned/e-vpaned.h>
#include <cal-util/timeutil.h>
#include "dialogs/alarm-notify-dialog.h"
#include "alarm-notify.h"
#include "e-calendar-table.h"
#include "e-day-view.h"
#include "e-week-view.h"
#include "event-editor.h"
#include "gnome-cal.h"
#include "component-factory.h"
#include "calendar-commands.h"
#include "calendar-config.h"
#include "tag-calendar.h"
/* These must match the page numbers in the GtkNotebook. */
typedef enum {
VIEW_NOT_SET = -1,
VIEW_DAY = 0,
VIEW_WORK_WEEK,
VIEW_WEEK,
VIEW_MONTH
} ViewType;
/* States for the calendar loading and creation state machine */
typedef enum {
LOAD_STATE_NOT_LOADED,
LOAD_STATE_WAIT_LOAD,
LOAD_STATE_WAIT_LOAD_BEFORE_CREATE,
LOAD_STATE_WAIT_CREATE,
LOAD_STATE_LOADED
} LoadState;
/* Private part of the GnomeCalendar structure */
struct _GnomeCalendarPrivate {
/* The calendar client object we monitor */
CalClient *client;
/* Loading state; we can be loading or creating a calendar */
LoadState load_state;
/* URI being loaded, NULL if we are not being loaded */
char *loading_uri;
/* Mapping of component UIDs to event editors */
GHashTable *object_editor_hash;
/* This is the last selection explicitly selected by the user. We try
to keep it the same when we switch views, but we may have to alter
it depending on the view (e.g. the week views only select days, so
any times are lost. */
time_t selection_start_time;
time_t selection_end_time;
/* Widgets */
GtkWidget *hpane;
GtkWidget *notebook;
GtkWidget *vpane;
ECalendar *date_navigator;
GtkWidget *todo;
GtkWidget *day_view;
GtkWidget *work_week_view;
GtkWidget *week_view;
GtkWidget *month_view;
/* These are the toolbar radio buttons for switching views. */
GtkWidget *day_button;
GtkWidget *work_week_button;
GtkWidget *week_button;
GtkWidget *month_button;
/* This is the view currently shown. We use it to keep track of the
positions of the panes. range_selected is TRUE if a range of dates
was selected in the date navigator to show the view. */
ViewType current_view_type;
gboolean range_selected;
/* These are the saved positions of the panes. They are multiples of
calendar month widths & heights in the date navigator, so that they
will work OK after theme changes. */
gfloat hpane_pos;
gfloat vpane_pos;
gfloat hpane_pos_month_view;
gfloat vpane_pos_month_view;
/* The signal handler id for our GtkCalendar "day_selected" handler. */
guint day_selected_id;
/* Alarm ID for the midnight refresh function */
gpointer midnight_alarm_refresh_id;
/* UID->ObjectAlarms hash */
GHashTable *alarms;
/* Whether we are being destroyed and should not mess with the object
* editor hash table.
*/
guint in_destroy : 1;
};
/* A queued alarm for a component */
typedef struct {
/* Alarm ID from alarm.h */
gpointer alarm_id;
/* Trigger instance this queued alarm refers to */
CalAlarmInstance *instance;
} QueuedAlarm;
/* An entry in the UID->alarms hash table */
typedef struct {
/* The actual component we keep around; its UID *is* the key in the hash
* table.
*/
CalComponentAlarms *alarms;
/* List of QueuedAlarm structures */
GList *queued_alarms;
} ObjectAlarms;
static void gnome_calendar_class_init (GnomeCalendarClass *class);
static void gnome_calendar_init (GnomeCalendar *gcal);
static void gnome_calendar_destroy (GtkObject *object);
static void gnome_calendar_set_view_internal (GnomeCalendar *gcal,
char *page_name,
gboolean range_selected,
gboolean focus);
static void gnome_calendar_set_pane_positions (GnomeCalendar *gcal);
static void gnome_calendar_update_view_times (GnomeCalendar *gcal);
static void gnome_calendar_update_date_navigator (GnomeCalendar *gcal);
static void gnome_calendar_on_date_navigator_style_set (GtkWidget *widget,
GtkStyle *previous_style,
gpointer data);
static void gnome_calendar_update_paned_quanta (GnomeCalendar *gcal);
static void gnome_calendar_on_date_navigator_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data);
static void gnome_calendar_on_date_navigator_date_range_changed (ECalendarItem *calitem,
GnomeCalendar *gcal);
static void gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem,
GnomeCalendar *gcal);
static gboolean gnome_calendar_get_days_shown (GnomeCalendar *gcal,
GDate *start_date,
gint *days_shown);
static GtkVBoxClass *parent_class;
#if 0
static void setup_alarm (GnomeCalendar *cal, CalAlarmInstance *ai);
#endif
GtkType
gnome_calendar_get_type (void)
{
static GtkType gnome_calendar_type = 0;
if (!gnome_calendar_type) {
static const GtkTypeInfo gnome_calendar_info = {
"GnomeCalendar",
sizeof (GnomeCalendar),
sizeof (GnomeCalendarClass),
(GtkClassInitFunc) gnome_calendar_class_init,
(GtkObjectInitFunc) gnome_calendar_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
gnome_calendar_type = gtk_type_unique (GTK_TYPE_VBOX, &gnome_calendar_info);
}
return gnome_calendar_type;
}
/* Class initialization function for the gnome calendar */
static void
gnome_calendar_class_init (GnomeCalendarClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) class;
parent_class = gtk_type_class (GTK_TYPE_VBOX);
object_class->destroy = gnome_calendar_destroy;
}
static void
setup_widgets (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GtkWidget *w;
gchar *filename;
priv = gcal->priv;
/* The main HPaned, with the notebook of calendar views on the left
and the ECalendar and ToDo list on the right. */
priv->hpane = e_hpaned_new ();
gtk_widget_show (priv->hpane);
gtk_box_pack_start (GTK_BOX (gcal), priv->hpane, TRUE, TRUE, 0);
/* The Notebook containing the 4 calendar views. */
priv->notebook = gtk_notebook_new ();
gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
gtk_widget_show (priv->notebook);
e_paned_pack1 (E_PANED (priv->hpane), priv->notebook, TRUE, TRUE);
/* The VPaned widget, to contain the GtkCalendar & ToDo list. */
priv->vpane = e_vpaned_new ();
gtk_widget_show (priv->vpane);
e_paned_pack2 (E_PANED (priv->hpane), priv->vpane, FALSE, TRUE);
/* The ECalendar. */
w = e_calendar_new ();
priv->date_navigator = E_CALENDAR (w);
e_calendar_item_set_days_start_week_sel (priv->date_navigator->calitem, 9);
e_calendar_item_set_max_days_sel (priv->date_navigator->calitem, 42);
gtk_widget_show (w);
e_paned_pack1 (E_PANED (priv->vpane), w, FALSE, TRUE);
gtk_signal_connect (GTK_OBJECT (priv->date_navigator),
"style_set",
GTK_SIGNAL_FUNC (gnome_calendar_on_date_navigator_style_set),
gcal);
gtk_signal_connect_after (GTK_OBJECT (priv->date_navigator),
"size_allocate",
(GtkSignalFunc) gnome_calendar_on_date_navigator_size_allocate,
gcal);
gtk_signal_connect (GTK_OBJECT (priv->date_navigator->calitem),
"selection_changed",
(GtkSignalFunc) gnome_calendar_on_date_navigator_selection_changed,
gcal);
gtk_signal_connect (GTK_OBJECT (priv->date_navigator->calitem),
"date_range_changed",
GTK_SIGNAL_FUNC (gnome_calendar_on_date_navigator_date_range_changed),
gcal);
/* The ToDo list. */
priv->todo = e_calendar_table_new ();
e_paned_pack2 (E_PANED (priv->vpane), priv->todo, TRUE, TRUE);
gtk_widget_show (priv->todo);
filename = g_strdup_printf ("%s/config/TaskPad", evolution_dir);
e_calendar_table_load_state (E_CALENDAR_TABLE (priv->todo), filename);
g_free (filename);
/* The Day View. */
priv->day_view = e_day_view_new ();
e_day_view_set_calendar (E_DAY_VIEW (priv->day_view), gcal);
gtk_widget_show (priv->day_view);
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
priv->day_view, gtk_label_new (""));
/* The Work Week View. */
priv->work_week_view = e_day_view_new ();
e_day_view_set_work_week_view (E_DAY_VIEW (priv->work_week_view),
TRUE);
e_day_view_set_days_shown (E_DAY_VIEW (priv->work_week_view), 5);
e_day_view_set_calendar (E_DAY_VIEW (priv->work_week_view), gcal);
gtk_widget_show (priv->work_week_view);
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
priv->work_week_view, gtk_label_new (""));
/* The Week View. */
priv->week_view = e_week_view_new ();
e_week_view_set_calendar (E_WEEK_VIEW (priv->week_view), gcal);
gtk_widget_show (priv->week_view);
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
priv->week_view, gtk_label_new (""));
/* The Month View. */
priv->month_view = e_week_view_new ();
e_week_view_set_calendar (E_WEEK_VIEW (priv->month_view), gcal);
e_week_view_set_multi_week_view (E_WEEK_VIEW (priv->month_view), TRUE);
gtk_widget_show (priv->month_view);
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
priv->month_view, gtk_label_new (""));
gnome_calendar_update_config_settings (gcal, TRUE);
}
/* Object initialization function for the gnome calendar */
static void
gnome_calendar_init (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
priv = g_new0 (GnomeCalendarPrivate, 1);
gcal->priv = priv;
priv->load_state = LOAD_STATE_NOT_LOADED;
priv->object_editor_hash = g_hash_table_new (g_str_hash, g_str_equal);
priv->alarms = g_hash_table_new (g_str_hash, g_str_equal);
priv->current_view_type = VIEW_NOT_SET;
priv->range_selected = FALSE;
setup_widgets (gcal);
priv->selection_start_time = time_day_begin (time (NULL));
priv->selection_end_time = time_add_day (priv->selection_start_time, 1);
}
/* Used from g_hash_table_foreach(); frees an object alarms entry */
static void
free_object_alarms (gpointer key, gpointer value, gpointer data)
{
ObjectAlarms *oa;
GList *l;
oa = value;
g_assert (oa->alarms != NULL);
cal_component_alarms_free (oa->alarms);
oa->alarms = NULL;
g_assert (oa->queued_alarms != NULL);
for (l = oa->queued_alarms; l; l = l->next) {
QueuedAlarm *qa;
qa = l->data;
/* The instance structures were already freed by the call to
* cal_component_alarms_free().
*/
g_free (qa);
}
g_list_free (oa->queued_alarms);
oa->queued_alarms = NULL;
g_free (oa);
}
/* Used from g_hash_table_foreach(); frees an UID string */
static void
destroy_editor_cb (gpointer key, gpointer value, gpointer data)
{
EventEditor *ee;
ee = EVENT_EDITOR (value);
gtk_object_unref (GTK_OBJECT (ee));
}
static void
gnome_calendar_destroy (GtkObject *object)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
gchar *filename;
g_return_if_fail (object != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (object));
gcal = GNOME_CALENDAR (object);
priv = gcal->priv;
/* Save the TaskPad layout. */
filename = g_strdup_printf ("%s/config/TaskPad", evolution_dir);
e_calendar_table_save_state (E_CALENDAR_TABLE (priv->todo), filename);
g_free (filename);
priv->load_state = LOAD_STATE_NOT_LOADED;
if (priv->loading_uri) {
g_free (priv->loading_uri);
priv->loading_uri = NULL;
}
if (priv->client) {
if (cal_client_is_loaded (priv->client))
alarm_notify_remove_client (priv->client);
gtk_object_unref (GTK_OBJECT (priv->client));
priv->client = NULL;
}
g_hash_table_foreach (priv->alarms, free_object_alarms, NULL);
g_hash_table_destroy (priv->alarms);
priv->alarms = NULL;
priv->in_destroy = TRUE;
g_hash_table_foreach (priv->object_editor_hash, destroy_editor_cb, NULL);
g_hash_table_destroy (priv->object_editor_hash);
priv->object_editor_hash = NULL;
g_free (priv);
gcal->priv = NULL;
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static GtkWidget *
get_current_page (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
priv = gcal->priv;
return GTK_NOTEBOOK (priv->notebook)->cur_page->child;
}
char *
gnome_calendar_get_current_view_name (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GtkWidget *page;
g_return_val_if_fail (gcal != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
priv = gcal->priv;
page = get_current_page (gcal);
if (page == priv->day_view)
return "dayview";
else if (page == priv->work_week_view)
return "workweekview";
else if (page == priv->week_view)
return "weekview";
else if (page == priv->month_view)
return "monthview";
else {
g_assert_not_reached ();
return NULL;
}
}
void
gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time)
{
GnomeCalendarPrivate *priv;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
g_return_if_fail (new_time != -1);
priv = gcal->priv;
priv->selection_start_time = time_day_begin (new_time);
priv->selection_end_time = time_add_day (priv->selection_start_time, 1);
gnome_calendar_update_view_times (gcal);
gnome_calendar_update_date_navigator (gcal);
}
static void
gnome_calendar_update_view_times (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GtkWidget *page;
priv = gcal->priv;
page = get_current_page (gcal);
if (page == priv->day_view || page == priv->work_week_view) {
e_day_view_set_selected_time_range (E_DAY_VIEW (page),
priv->selection_start_time,
priv->selection_end_time);
} else if (page == priv->week_view || page == priv->month_view) {
e_week_view_set_selected_time_range (E_WEEK_VIEW (page),
priv->selection_start_time,
priv->selection_end_time);
} else {
g_warning ("My penguin is gone!");
g_assert_not_reached ();
}
}
static void
gnome_calendar_direction (GnomeCalendar *gcal, int direction)
{
GnomeCalendarPrivate *priv;
GtkWidget *cp;
time_t start_time, end_time;
priv = gcal->priv;
cp = get_current_page (gcal);
start_time = priv->selection_start_time;
end_time = priv->selection_end_time;
if (cp == priv->day_view) {
start_time = time_add_day (start_time, direction);
end_time = time_add_day (end_time, direction);
} else if (cp == priv->work_week_view) {
start_time = time_add_week (start_time, direction);
end_time = time_add_week (end_time, direction);
} else if (cp == priv->week_view) {
start_time = time_add_week (start_time, direction);
end_time = time_add_week (end_time, direction);
} else if (cp == priv->month_view) {
start_time = time_add_month (start_time, direction);
end_time = time_add_month (end_time, direction);
} else {
g_warning ("Weee! Where did the penguin go?");
g_assert_not_reached ();
return;
}
priv->selection_start_time = start_time;
priv->selection_end_time = end_time;
gnome_calendar_update_view_times (gcal);
gnome_calendar_update_date_navigator (gcal);
}
void
gnome_calendar_next (GnomeCalendar *gcal)
{
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
gnome_calendar_direction (gcal, 1);
}
void
gnome_calendar_previous (GnomeCalendar *gcal)
{
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
gnome_calendar_direction (gcal, -1);
}
void
gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time)
{
GnomeCalendarPrivate *priv;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
priv = gcal->priv;
priv->selection_start_time = time_day_begin (time);
priv->selection_end_time = time_add_day (priv->selection_start_time, 1);
if (priv->day_button)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->day_button), TRUE);
else
gnome_calendar_set_view (gcal, "dayview", FALSE, TRUE);
}
void
gnome_calendar_goto_today (GnomeCalendar *gcal)
{
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
gnome_calendar_goto (gcal, time (NULL));
gtk_widget_grab_focus (get_current_page (gcal));
}
/* This sets which view is currently shown. It also updates the selection time
of the view so it shows the appropriate days. */
void
gnome_calendar_set_view (GnomeCalendar *gcal,
char *page_name,
gboolean range_selected,
gboolean focus)
{
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
g_return_if_fail (page_name != NULL);
gnome_calendar_set_view_internal (gcal, page_name, range_selected, focus);
gnome_calendar_update_view_times (gcal);
gnome_calendar_update_date_navigator (gcal);
}
/* This sets the view without changing the selection or updating the date
navigator. If a range of dates isn't selected it will also reset the number
of days/weeks shown to the default (i.e. 1 day for the day view or 5 weeks
for the month view). */
static void
gnome_calendar_set_view_internal (GnomeCalendar *gcal,
char *page_name,
gboolean range_selected,
gboolean focus)
{
GnomeCalendarPrivate *priv;
int view;
gboolean round_selection;
GtkWidget *focus_widget;
priv = gcal->priv;
round_selection = FALSE;
if (!strcmp (page_name, "dayview")) {
view = VIEW_DAY;
focus_widget = priv->day_view;
if (!range_selected)
e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), 1);
} else if (!strcmp (page_name, "workweekview")) {
view = VIEW_WORK_WEEK;
focus_widget = priv->work_week_view;
} else if (!strcmp (page_name, "weekview")) {
view = VIEW_WEEK;
focus_widget = priv->week_view;
round_selection = TRUE;
} else if (!strcmp (page_name, "monthview")) {
view = VIEW_MONTH;
focus_widget = priv->month_view;
if (!range_selected)
e_week_view_set_weeks_shown (E_WEEK_VIEW (priv->month_view), 5);
round_selection = TRUE;
} else {
g_warning ("Unknown calendar view: %s", page_name);
g_assert_not_reached ();
return;
}
priv->current_view_type = view;
priv->range_selected = range_selected;
calendar_config_set_default_view (view);
gtk_notebook_set_page (GTK_NOTEBOOK (priv->notebook), view);
if (focus)
gtk_widget_grab_focus (focus_widget);
gnome_calendar_set_pane_positions (gcal);
/* For the week & month views we want the selection in the date
navigator to be rounded to the nearest week when the arrow buttons
are pressed to move to the previous/next month. */
gtk_object_set (GTK_OBJECT (priv->date_navigator->calitem),
"round_selection_when_moving", round_selection,
NULL);
}
static void
gnome_calendar_set_pane_positions (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
gint top_border, bottom_border, left_border, right_border;
gint col_width, row_height;
gfloat right_pane_width, top_pane_height;
priv = gcal->priv;
/* Get the size of the calendar month width & height. */
e_calendar_get_border_size (priv->date_navigator,
&top_border, &bottom_border,
&left_border, &right_border);
gtk_object_get (GTK_OBJECT (priv->date_navigator->calitem),
"row_height", &row_height,
"column_width", &col_width,
NULL);
if (priv->current_view_type == VIEW_MONTH && !priv->range_selected) {
right_pane_width = priv->hpane_pos_month_view;
top_pane_height = priv->vpane_pos_month_view;
} else {
right_pane_width = priv->hpane_pos;
top_pane_height = priv->vpane_pos;
}
/* We add the borders before multiplying due to the way we are using
the EPaned quantum feature. */
if (right_pane_width < 0.001)
right_pane_width = 0.0;
else
right_pane_width = (right_pane_width * (col_width + left_border + right_border)
+ 0.5);
if (top_pane_height < 0.001)
top_pane_height = 0.0;
else
top_pane_height = (top_pane_height * (row_height + top_border + bottom_border)
+ 0.5);
e_paned_set_position (E_PANED (priv->hpane), -1);
e_paned_set_position (E_PANED (priv->vpane), -1);
/* We add one to each dimension since we can't use 0. */
gtk_widget_set_usize (priv->vpane, right_pane_width + 1, -2);
gtk_widget_set_usize (GTK_WIDGET (priv->date_navigator), -2, top_pane_height + 1);
}
#if 0
/* Sends a mail notification of an alarm trigger */
static void
mail_notification (char *mail_address, char *text, time_t app_time)
{
pid_t pid;
int p [2];
char *command;
pipe (p);
pid = fork ();
if (pid == 0){
int dev_null;
dev_null = open ("/dev/null", O_RDWR);
dup2 (p [0], 0);
dup2 (dev_null, 1);
dup2 (dev_null, 2);
execl ("/usr/lib/sendmail", "/usr/lib/sendmail",
mail_address, NULL);
_exit (127);
}
command = g_strconcat ("To: ", mail_address, "\n",
"Subject: ", _("Reminder of your appointment at "),
ctime (&app_time), "\n\n", text, "\n", NULL);
write (p [1], command, strlen (command));
close (p [1]);
close (p [0]);
g_free (command);
}
static int
max_open_files (void)
{
static int files;
if (files)
return files;
files = sysconf (_SC_OPEN_MAX);
if (files != -1)
return files;
#ifdef OPEN_MAX
return files = OPEN_MAX;
#else
return files = 256;
#endif
}
/* Executes a program as a notification of an alarm trigger */
static void
program_notification (char *command, int close_standard)
{
struct sigaction ignore, save_intr, save_quit;
int status = 0, i;
pid_t pid;
ignore.sa_handler = SIG_IGN;
sigemptyset (&ignore.sa_mask);
ignore.sa_flags = 0;
sigaction (SIGINT, &ignore, &save_intr);
sigaction (SIGQUIT, &ignore, &save_quit);
if ((pid = fork ()) < 0){
fprintf (stderr, "\n\nfork () = -1\n");
return;
}
if (pid == 0){
pid = fork ();
if (pid == 0){
const int top = max_open_files ();
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
for (i = (close_standard ? 0 : 3); i < top; i++)
close (i);
/* FIXME: As an excercise to the reader, copy the
* code from mc to setup shell properly instead of
* /bin/sh. Yes, this comment is larger than a cut and paste.
*/
execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0);
_exit (127);
} else {
_exit (127);
}
}
wait (&status);
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
}
/* Queues a snooze alarm */
static void
snooze (GnomeCalendar *gcal, CalComponent *comp, time_t occur, int snooze_mins, gboolean audio)
{
time_t now, trigger;
struct tm tm;
CalAlarmInstance ai;
now = time (NULL);
tm = *localtime (&now);
tm.tm_min += snooze_mins;
trigger = mktime (&tm);
if (trigger == -1) {
g_message ("snooze(): produced invalid time_t; not queueing alarm!");
return;
}
#if 0
cal_component_get_uid (comp, &ai.uid);
ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY;
#endif
ai.trigger = trigger;
ai.occur = occur;
setup_alarm (gcal, &ai);
}
struct alarm_notify_closure {
GnomeCalendar *gcal;
CalComponent *comp;
time_t occur;
};
/* Callback used for the result of the alarm notification dialog */
static void
display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data)
{
struct alarm_notify_closure *c;
c = data;
switch (result) {
case ALARM_NOTIFY_CLOSE:
break;
case ALARM_NOTIFY_SNOOZE:
snooze (c->gcal, c->comp, c->occur, snooze_mins, FALSE);
break;
case ALARM_NOTIFY_EDIT:
gnome_calendar_edit_object (c->gcal, c->comp);
break;
default:
g_assert_not_reached ();
}
gtk_object_unref (GTK_OBJECT (c->comp));
g_free (c);
}
/* Present a display notification of an alarm trigger */
static void
display_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal)
{
gboolean result;
struct alarm_notify_closure *c;
gtk_object_ref (GTK_OBJECT (comp));
c = g_new (struct alarm_notify_closure, 1);
c->gcal = gcal;
c->comp = comp;
c->occur = occur;
result = alarm_notify_dialog (trigger, occur, comp, display_notification_cb, c);
if (!result) {
g_message ("display_notification(): could not display the alarm notification dialog");
g_free (c);
gtk_object_unref (GTK_OBJECT (comp));
}
}
/* Present an audible notification of an alarm trigger */
static void
audio_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal)
{
g_message ("AUDIO NOTIFICATION!");
/* FIXME */
}
/* Callback function used when an alarm is triggered */
static void
trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data)
{
struct trigger_alarm_closure *c;
GnomeCalendarPrivate *priv;
CalComponent *comp;
CalClientGetStatus status;
const char *uid;
ObjectAlarms *oa;
GList *l;
c = data;
priv = c->gcal->priv;
/* Fetch the object */
status = cal_client_get_object (priv->client, c->uid, &comp);
switch (status) {
case CAL_CLIENT_GET_SUCCESS:
/* Go on */
break;
case CAL_CLIENT_GET_SYNTAX_ERROR:
case CAL_CLIENT_GET_NOT_FOUND:
g_message ("trigger_alarm_cb(): syntax error in fetched object");
return;
}
g_assert (comp != NULL);
/* Present notification */
switch (c->type) {
case CAL_COMPONENT_ALARM_EMAIL:
#if 0
g_assert (ico->malarm.enabled);
mail_notification (ico->malarm.data, ico->summary, c->occur);
#endif
break;
case CAL_COMPONENT_ALARM_PROCEDURE:
#if 0
g_assert (ico->palarm.enabled);
program_notification (ico->palarm.data, FALSE);
#endif
break;
case CAL_COMPONENT_ALARM_DISPLAY:
#if 0
g_assert (ico->dalarm.enabled);
#endif
display_notification (trigger, c->occur, comp, c->gcal);
break;
case CAL_COMPONENT_ALARM_AUDIO:
#if 0
g_assert (ico->aalarm.enabled);
#endif
audio_notification (trigger, c->occur, comp, c->gcal);
break;
default:
break;
}
/* Remove the alarm from the hash table */
cal_component_get_uid (comp, &uid);
oa = g_hash_table_lookup (priv->alarms, uid);
g_assert (oa != NULL);
l = g_list_find (oa->alarm_ids, alarm_id);
g_assert (l != NULL);
oa->alarm_ids = g_list_remove_link (oa->alarm_ids, l);
g_list_free_1 (l);
if (!oa->alarm_ids) {
g_hash_table_remove (priv->alarms, uid);
g_free (oa->uid);
g_free (oa);
}
gtk_object_unref (GTK_OBJECT (comp));
}
#endif
/* Loads the initial data into the calendar; this should be called right after
* the cal_loaded signal from the client is invoked.
*/
static void
initial_load (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
priv = gcal->priv;
tag_calendar_by_client (priv->date_navigator, priv->client);
}
/* Displays an error to indicate that loading a calendar failed */
static void
load_error (GnomeCalendar *gcal, const char *uri)
{
char *msg;
msg = g_strdup_printf (_("Could not load the calendar in `%s'"), uri);
gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal))));
g_free (msg);
}
/* Displays an error to indicate that creating a calendar failed */
static void
create_error (GnomeCalendar *gcal, const char *uri)
{
char *msg;
msg = g_strdup_printf (_("Could not create a calendar in `%s'"), uri);
gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal))));
g_free (msg);
}
/* Displays an error to indicate that the specified URI method is not supported */
static void
method_error (GnomeCalendar *gcal, const char *uri)
{
char *msg;
msg = g_strdup_printf (_("The method required to load `%s' is not supported"), uri);
gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal))));
g_free (msg);
}
/* Callback from the calendar client when a calendar is loaded */
static void
cal_loaded_cb (CalClient *client, CalClientLoadStatus status, gpointer data)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
gboolean free_uri;
gcal = GNOME_CALENDAR (data);
priv = gcal->priv;
g_assert (priv->load_state != LOAD_STATE_NOT_LOADED && priv->load_state != LOAD_STATE_LOADED);
g_assert (priv->loading_uri != NULL);
free_uri = TRUE;
switch (priv->load_state) {
case LOAD_STATE_WAIT_LOAD:
if (status == CAL_CLIENT_LOAD_SUCCESS) {
priv->load_state = LOAD_STATE_LOADED;
initial_load (gcal);
} else if (status == CAL_CLIENT_LOAD_ERROR) {
priv->load_state = LOAD_STATE_NOT_LOADED;
load_error (gcal, priv->loading_uri);
} else if (status == CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED) {
priv->load_state = LOAD_STATE_NOT_LOADED;
method_error (gcal, priv->loading_uri);
} else
g_assert_not_reached ();
break;
case LOAD_STATE_WAIT_LOAD_BEFORE_CREATE:
if (status == CAL_CLIENT_LOAD_SUCCESS) {
priv->load_state = LOAD_STATE_LOADED;
initial_load (gcal);
} else if (status == CAL_CLIENT_LOAD_ERROR) {
priv->load_state = LOAD_STATE_WAIT_CREATE;
free_uri = FALSE;
if (!cal_client_create_calendar (priv->client, priv->loading_uri)) {
priv->load_state = LOAD_STATE_NOT_LOADED;
free_uri = TRUE;
g_message ("cal_loaded_cb(): Could not issue the create request");
}
} else if (status == CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED) {
priv->load_state = LOAD_STATE_NOT_LOADED;
method_error (gcal, priv->loading_uri);
} else
g_assert_not_reached ();
break;
case LOAD_STATE_WAIT_CREATE:
if (status == CAL_CLIENT_LOAD_SUCCESS) {
priv->load_state = LOAD_STATE_LOADED;
initial_load (gcal);
} else if (status == CAL_CLIENT_LOAD_ERROR) {
priv->load_state = LOAD_STATE_NOT_LOADED;
create_error (gcal, priv->loading_uri);
} else if (status == CAL_CLIENT_LOAD_IN_USE) {
/* Someone created the URI while we were issuing the
* create request, so we just try to reload.
*/
priv->load_state = LOAD_STATE_WAIT_LOAD;
free_uri = FALSE;
if (!cal_client_load_calendar (priv->client, priv->loading_uri)) {
priv->load_state = LOAD_STATE_NOT_LOADED;
free_uri = TRUE;
g_message ("cal_loaded_cb(): Could not issue the load request");
}
} else if (status == CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED) {
priv->load_state = LOAD_STATE_NOT_LOADED;
method_error (gcal, priv->loading_uri);
} else
g_assert_not_reached ();
break;
default:
g_assert_not_reached ();
}
if (free_uri) {
g_free (priv->loading_uri);
priv->loading_uri = NULL;
}
}
/* Callback from the calendar client when an object is updated */
static void
obj_updated_cb (CalClient *client, const char *uid, gpointer data)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
gcal = GNOME_CALENDAR (data);
priv = gcal->priv;
tag_calendar_by_client (priv->date_navigator, priv->client);
}
/* Callback from the calendar client when an object is removed */
static void
obj_removed_cb (CalClient *client, const char *uid, gpointer data)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
gcal = GNOME_CALENDAR (data);
priv = gcal->priv;
tag_calendar_by_client (priv->date_navigator, priv->client);
}
GtkWidget *
gnome_calendar_construct (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
gint view;
gchar *page;
g_return_val_if_fail (gcal != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
priv = gcal->priv;
priv->client = cal_client_new ();
if (!priv->client)
return NULL;
gtk_signal_connect (GTK_OBJECT (priv->client), "cal_loaded",
GTK_SIGNAL_FUNC (cal_loaded_cb), gcal);
gtk_signal_connect (GTK_OBJECT (priv->client), "obj_updated",
GTK_SIGNAL_FUNC (obj_updated_cb), gcal);
gtk_signal_connect (GTK_OBJECT (priv->client), "obj_removed",
GTK_SIGNAL_FUNC (obj_removed_cb), gcal);
alarm_notify_add_client (priv->client);
e_calendar_table_set_cal_client (E_CALENDAR_TABLE (priv->todo), priv->client);
e_day_view_set_cal_client (E_DAY_VIEW (priv->day_view), priv->client);
e_day_view_set_cal_client (E_DAY_VIEW (priv->work_week_view), priv->client);
e_week_view_set_cal_client (E_WEEK_VIEW (priv->week_view), priv->client);
e_week_view_set_cal_client (E_WEEK_VIEW (priv->month_view), priv->client);
view = calendar_config_get_default_view ();
switch (view) {
case 1:
page = "workweekview";
break;
case 2:
page = "weekview";
break;
case 3:
page = "monthview";
break;
default:
page = "dayview";
break;
}
gnome_calendar_set_view (gcal, page, FALSE, FALSE);
return GTK_WIDGET (gcal);
}
GtkWidget *
gnome_calendar_new (void)
{
GnomeCalendar *gcal;
gcal = gtk_type_new (gnome_calendar_get_type ());
if (!gnome_calendar_construct (gcal)) {
g_message ("gnome_calendar_new(): Could not construct the calendar GUI");
gtk_object_unref (GTK_OBJECT (gcal));
return NULL;
}
return GTK_WIDGET (gcal);
}
/**
* gnome_calendar_get_cal_client:
* @gcal: A calendar view.
*
* Queries the calendar client interface object that a calendar view is using.
*
* Return value: A calendar client interface object.
**/
CalClient *
gnome_calendar_get_cal_client (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
g_return_val_if_fail (gcal != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
priv = gcal->priv;
return priv->client;
}
gboolean
gnome_calendar_open (GnomeCalendar *gcal, char *file, GnomeCalendarOpenMode gcom)
{
GnomeCalendarPrivate *priv;
g_return_val_if_fail (gcal != NULL, FALSE);
g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), FALSE);
g_return_val_if_fail (file != NULL, FALSE);
priv = gcal->priv;
g_return_val_if_fail (priv->load_state == LOAD_STATE_NOT_LOADED, FALSE);
g_assert (priv->loading_uri == NULL);
priv->loading_uri = g_strdup (file);
if (gcom == CALENDAR_OPEN)
priv->load_state = LOAD_STATE_WAIT_LOAD;
else if (gcom == CALENDAR_OPEN_OR_CREATE)
priv->load_state = LOAD_STATE_WAIT_LOAD_BEFORE_CREATE;
else {
g_assert_not_reached ();
return FALSE;
}
if (!cal_client_load_calendar (priv->client, file)) {
priv->load_state = LOAD_STATE_NOT_LOADED;
g_free (priv->loading_uri);
priv->loading_uri = NULL;
g_message ("gnome_calendar_open(): Could not issue the request");
return FALSE;
}
return TRUE;
}
#if 0
static void
stop_beeping (GtkObject* object, gpointer data)
{
guint timer_tag, beep_tag;
timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag"));
beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag"));
if (beep_tag > 0) {
gtk_timeout_remove (beep_tag);
gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0));
}
if (timer_tag > 0) {
gtk_timeout_remove (timer_tag);
gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0));
}
}
static gint
start_beeping (gpointer data)
{
gdk_beep ();
return TRUE;
}
static gint
timeout_beep (gpointer data)
{
stop_beeping (data, NULL);
return FALSE;
}
void
calendar_notify (time_t activation_time, CalendarAlarm *which, void *data)
{
iCalObject *ico = data;
guint beep_tag, timer_tag;
int ret;
gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL);
time_t now, diff;
if (&ico->aalarm == which){
time_t app = ico->aalarm.trigger + ico->aalarm.offset;
GtkWidget *w;
char *msg;
msg = g_strconcat (_("Reminder of your appointment at "),
ctime (&app), "`",
ico->summary, "'", NULL);
/* Idea: we need Snooze option :-) */
w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL);
beep_tag = gtk_timeout_add (1000, start_beeping, NULL);
if (enable_aalarm_timeout)
timer_tag = gtk_timeout_add (audio_alarm_timeout*1000,
timeout_beep, w);
else
timer_tag = 0;
gtk_object_set_data (GTK_OBJECT (w), "timer_tag",
GINT_TO_POINTER (timer_tag));
gtk_object_set_data (GTK_OBJECT (w), "beep_tag",
GINT_TO_POINTER (beep_tag));
gtk_widget_ref (w);
gtk_window_set_modal (GTK_WINDOW (w), FALSE);
ret = gnome_dialog_run (GNOME_DIALOG (w));
switch (ret) {
case 1:
stop_beeping (GTK_OBJECT (w), NULL);
now = time (NULL);
diff = now - which->trigger;
which->trigger = which->trigger + diff + snooze_secs;
which->offset = which->offset - diff - snooze_secs;
alarm_add (which, &calendar_notify, data);
break;
default:
stop_beeping (GTK_OBJECT (w), NULL);
break;
}
gtk_widget_unref (w);
return;
}
if (&ico->palarm == which){
execute (ico->palarm.data, 0);
return;
}
if (&ico->malarm == which){
time_t app = ico->malarm.trigger + ico->malarm.offset;
mail_notify (ico->malarm.data, ico->summary, app);
return;
}
if (&ico->dalarm == which){
time_t app = ico->dalarm.trigger + ico->dalarm.offset;
GtkWidget *w;
char *msg;
if (beep_on_display)
gdk_beep ();
msg = g_strconcat (_("Reminder of your appointment at "),
ctime (&app), "`",
ico->summary, "'", NULL);
w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO,
_("Ok"), snooze_button, NULL);
gtk_window_set_modal (GTK_WINDOW (w), FALSE);
ret = gnome_dialog_run (GNOME_DIALOG (w));
switch (ret) {
case 1:
now = time (NULL);
diff = now - which->trigger;
which->trigger = which->trigger + diff + snooze_secs;
which->offset = which->offset - diff - snooze_secs;
alarm_add (which, &calendar_notify, data);
break;
default:
break;
}
return;
}
}
#endif
/* Tells the calendar to reload all config settings.
If initializing is TRUE it sets the pane positions as well. (We don't
want to reset the pane positions after the user clicks 'Apply' in the
preferences dialog.) */
void
gnome_calendar_update_config_settings (GnomeCalendar *gcal,
gboolean initializing)
{
GnomeCalendarPrivate *priv;
CalWeekdays working_days;
gint week_start_day, time_divisions;
gint start_hour, start_minute, end_hour, end_minute;
gboolean use_24_hour, show_event_end, compress_weekend;
gboolean dnav_show_week_no;
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
priv = gcal->priv;
working_days = calendar_config_get_working_days ();
/* CalWeekdays and EDayViewDays use the same bit-masks, so we can
use the same value. */
e_day_view_set_working_days (E_DAY_VIEW (priv->day_view),
(EDayViewDays) working_days);
e_day_view_set_working_days (E_DAY_VIEW (priv->work_week_view),
(EDayViewDays) working_days);
/* Note that this is 0 (Sun) to 6 (Sat). */
week_start_day = calendar_config_get_week_start_day ();
/* Convert it to 0 (Mon) to 6 (Sun), which is what we use. */
week_start_day = (week_start_day + 6) % 7;
e_day_view_set_week_start_day (E_DAY_VIEW (priv->day_view),
week_start_day);
e_day_view_set_week_start_day (E_DAY_VIEW (priv->work_week_view),
week_start_day);
e_week_view_set_week_start_day (E_WEEK_VIEW (priv->week_view),
week_start_day);
e_week_view_set_week_start_day (E_WEEK_VIEW (priv->month_view),
week_start_day);
gnome_canvas_item_set (GNOME_CANVAS_ITEM (E_CALENDAR (priv->date_navigator)->calitem),
"week_start_day", week_start_day,
NULL);
start_hour = calendar_config_get_day_start_hour ();
start_minute = calendar_config_get_day_start_minute ();
end_hour = calendar_config_get_day_end_hour ();
end_minute = calendar_config_get_day_end_minute ();
e_day_view_set_working_day (E_DAY_VIEW (priv->day_view),
start_hour, start_minute,
end_hour, end_minute);
e_day_view_set_working_day (E_DAY_VIEW (priv->work_week_view),
start_hour, start_minute,
end_hour, end_minute);
use_24_hour = calendar_config_get_24_hour_format ();
e_day_view_set_24_hour_format (E_DAY_VIEW (priv->day_view),
use_24_hour);
e_day_view_set_24_hour_format (E_DAY_VIEW (priv->work_week_view),
use_24_hour);
e_week_view_set_24_hour_format (E_WEEK_VIEW (priv->week_view),
use_24_hour);
e_week_view_set_24_hour_format (E_WEEK_VIEW (priv->month_view),
use_24_hour);
time_divisions = calendar_config_get_time_divisions ();
e_day_view_set_mins_per_row (E_DAY_VIEW (priv->day_view),
time_divisions);
e_day_view_set_mins_per_row (E_DAY_VIEW (priv->work_week_view),
time_divisions);
show_event_end = calendar_config_get_show_event_end ();
e_day_view_set_show_event_end_times (E_DAY_VIEW (priv->day_view),
show_event_end);
e_day_view_set_show_event_end_times (E_DAY_VIEW (priv->work_week_view),
show_event_end);
e_week_view_set_show_event_end_times (E_WEEK_VIEW (priv->week_view),
show_event_end);
e_week_view_set_show_event_end_times (E_WEEK_VIEW (priv->month_view),
show_event_end);
compress_weekend = calendar_config_get_compress_weekend ();
e_week_view_set_compress_weekend (E_WEEK_VIEW (priv->month_view),
compress_weekend);
dnav_show_week_no = calendar_config_get_dnav_show_week_no ();
gnome_canvas_item_set (GNOME_CANVAS_ITEM (E_CALENDAR (priv->date_navigator)->calitem),
"show_week_numbers", dnav_show_week_no,
NULL);
if (initializing) {
priv->hpane_pos = calendar_config_get_hpane_pos ();
priv->vpane_pos = calendar_config_get_vpane_pos ();
priv->hpane_pos_month_view = calendar_config_get_month_hpane_pos ();
priv->vpane_pos_month_view = calendar_config_get_month_vpane_pos ();
} else {
gnome_calendar_update_paned_quanta (gcal);
}
/* The range of days shown may have changed, so we update the date
navigator if needed. */
gnome_calendar_update_date_navigator (gcal);
}
void
gnome_calendar_set_selected_time_range (GnomeCalendar *gcal,
time_t start_time,
time_t end_time)
{
GnomeCalendarPrivate *priv;
priv = gcal->priv;
priv->selection_start_time = start_time;
priv->selection_end_time = end_time;
gnome_calendar_update_date_navigator (gcal);
}
/**
* gnome_calendar_get_selected_time_range:
* @gcal: A calendar view.
* @start_time: Return value for the start of the time selection.
* @end_time: Return value for the end of the time selection.
*
* Queries the time selection range on the calendar view.
**/
void
gnome_calendar_get_selected_time_range (GnomeCalendar *gcal,
time_t *start_time,
time_t *end_time)
{
GnomeCalendarPrivate *priv;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
priv = gcal->priv;
if (start_time)
*start_time = priv->selection_start_time;
if (end_time)
*end_time = priv->selection_end_time;
}
/* Callback used when an event editor dialog is closed */
struct editor_closure
{
GnomeCalendar *gcal;
char *uid;
};
static void
editor_closed_cb (GtkWidget *widget, gpointer data)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
struct editor_closure *ec;
gboolean result;
gpointer orig_key;
char *orig_uid;
ec = (struct editor_closure *) data;
gcal = ec->gcal;
priv = gcal->priv;
result = g_hash_table_lookup_extended (priv->object_editor_hash, ec->uid, &orig_key, NULL);
g_assert (result != FALSE);
orig_uid = orig_key;
if (!priv->in_destroy)
g_hash_table_remove (priv->object_editor_hash, orig_uid);
g_free (orig_uid);
g_free (ec);
}
void
gnome_calendar_edit_object (GnomeCalendar *gcal, CalComponent *comp)
{
GnomeCalendarPrivate *priv;
EventEditor *ee;
struct editor_closure *ec;
const char *uid;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
g_return_if_fail (comp != NULL);
priv = gcal->priv;
cal_component_get_uid (comp, &uid);
ee = g_hash_table_lookup (priv->object_editor_hash, uid);
if (!ee) {
ec = g_new0 (struct editor_closure, 1);
ee = event_editor_new ();
if (!ee) {
g_message ("gnome_calendar_edit_object(): Could not create the event editor");
return;
}
ec->gcal = gcal;
ec->uid = g_strdup (uid);
g_hash_table_insert (priv->object_editor_hash, ec->uid, ee);
gtk_signal_connect (GTK_OBJECT (ee), "destroy",
GTK_SIGNAL_FUNC (editor_closed_cb),
ec);
event_editor_set_cal_client (EVENT_EDITOR (ee), priv->client);
event_editor_set_event_object (EVENT_EDITOR (ee), comp);
}
event_editor_focus (ee);
}
/**
* gnome_calendar_new_appointment:
* @gcal: An Evolution calendar.
*
* Opens an event editor dialog for a new appointment. The appointment's start
* and end times are set to the currently selected time range in the calendar
* views.
**/
void
gnome_calendar_new_appointment (GnomeCalendar *gcal)
{
CalComponent *comp;
time_t dtstart, dtend;
CalComponentDateTime dt;
struct icaltimetype itt;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
gnome_calendar_get_current_time_range (gcal, &dtstart, &dtend);
dt.value = &itt;
dt.tzid = NULL;
comp = cal_component_new ();
cal_component_set_new_vtype (comp, CAL_COMPONENT_EVENT);
itt = icaltime_from_timet (dtstart, FALSE, TRUE);
cal_component_set_dtstart (comp, &dt);
itt = icaltime_from_timet (dtend, FALSE, TRUE);
cal_component_set_dtend (comp, &dt);
cal_component_commit_sequence (comp);
gnome_calendar_edit_object (gcal, comp);
gtk_object_unref (GTK_OBJECT (comp));
}
/* Returns the selected time range for the current view. Note that this may be
different from the fields in the GnomeCalendar, since the view may clip
this or choose a more appropriate time. */
void
gnome_calendar_get_current_time_range (GnomeCalendar *gcal,
time_t *start_time,
time_t *end_time)
{
GnomeCalendarPrivate *priv;
GtkWidget *page;
priv = gcal->priv;
page = get_current_page (gcal);
if (page == priv->day_view || page == priv->work_week_view)
e_day_view_get_selected_time_range (E_DAY_VIEW (page), start_time, end_time);
else if (page == priv->week_view || page == priv->month_view)
e_week_view_get_selected_time_range (E_WEEK_VIEW (page), start_time, end_time);
else {
g_message ("My penguin is gone!");
g_assert_not_reached ();
}
}
/* This updates the month shown and the days selected in the calendar, if
necessary. */
static void
gnome_calendar_update_date_navigator (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GDate start_date, end_date;
gint days_shown;
priv = gcal->priv;
/* If the ECalendar isn't visible, we just return. */
if (!GTK_WIDGET_VISIBLE (priv->date_navigator))
return;
if (gnome_calendar_get_days_shown (gcal, &start_date, &days_shown)) {
end_date = start_date;
g_date_add_days (&end_date, days_shown - 1);
e_calendar_item_set_selection (priv->date_navigator->calitem,
&start_date, &end_date);
}
}
static gboolean
gnome_calendar_get_days_shown (GnomeCalendar *gcal,
GDate *start_date,
gint *days_shown)
{
GnomeCalendarPrivate *priv;
GtkWidget *page;
priv = gcal->priv;
page = get_current_page (gcal);
if (page == priv->day_view || page == priv->work_week_view) {
g_date_clear (start_date, 1);
g_date_set_time (start_date, E_DAY_VIEW (page)->lower);
*days_shown = e_day_view_get_days_shown (E_DAY_VIEW (page));
return TRUE;
} else if (page == priv->week_view || page == priv->month_view) {
*start_date = E_WEEK_VIEW (page)->first_day_shown;
if (e_week_view_get_multi_week_view (E_WEEK_VIEW (page)))
*days_shown = e_week_view_get_weeks_shown (E_WEEK_VIEW (page)) * 7;
else
*days_shown = 7;
return TRUE;
} else {
g_assert_not_reached ();
return FALSE;
}
}
static void
gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem,
GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GDate start_date, end_date, new_start_date, new_end_date;
gint days_shown, new_days_shown;
gint start_year, start_month, start_day;
gint end_year, end_month, end_day;
gboolean starts_on_week_start_day;
struct tm tm;
priv = gcal->priv;
starts_on_week_start_day = FALSE;
if (!gnome_calendar_get_days_shown (gcal, &start_date, &days_shown))
return;
end_date = start_date;
g_date_add_days (&end_date, days_shown - 1);
e_calendar_item_get_selection (calitem, &new_start_date, &new_end_date);
/* If the selection hasn't changed just return. */
if (!g_date_compare (&start_date, &new_start_date)
&& !g_date_compare (&end_date, &new_end_date))
return;
new_days_shown = g_date_julian (&new_end_date) - g_date_julian (&new_start_date) + 1;
/* If a complete week is selected we show the Week view.
Note that if weekends are compressed and the week start day is set
to Sunday we don't actually show complete weeks in the Week view,
so this may need tweaking. */
if (g_date_weekday (&new_start_date) % 7 == calendar_config_get_week_start_day ())
starts_on_week_start_day = TRUE;
/* Switch views as appropriate, and change the number of days or weeks
shown. */
if (new_days_shown > 9) {
e_week_view_set_weeks_shown (E_WEEK_VIEW (priv->month_view),
(new_days_shown + 6) / 7);
e_week_view_set_first_day_shown (E_WEEK_VIEW (priv->month_view), &new_start_date);
gnome_calendar_set_view_internal (gcal, "monthview", TRUE, FALSE);
gnome_calendar_update_date_navigator (gcal);
} else if (new_days_shown == 7 && starts_on_week_start_day) {
e_week_view_set_first_day_shown (E_WEEK_VIEW (priv->week_view), &new_start_date);
gnome_calendar_set_view_internal (gcal, "weekview", TRUE, FALSE);
gnome_calendar_update_date_navigator (gcal);
} else {
start_year = g_date_year (&new_start_date);
start_month = g_date_month (&new_start_date) - 1;
start_day = g_date_day (&new_start_date);
end_year = g_date_year (&new_end_date);
end_month = g_date_month (&new_end_date) - 1;
end_day = g_date_day (&new_end_date);
tm.tm_year = start_year - 1900;
tm.tm_mon = start_month;
tm.tm_mday = start_day;
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = -1;
priv->selection_start_time = mktime (&tm);
tm.tm_year = end_year - 1900;
tm.tm_mon = end_month;
tm.tm_mday = end_day + 1; /* mktime() will normalize this. */
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = -1;
priv->selection_end_time = mktime (&tm);
e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), new_days_shown);
gnome_calendar_set_view (gcal, "dayview", TRUE, FALSE);
}
gnome_calendar_update_view_buttons (gcal);
gtk_widget_grab_focus (get_current_page (gcal));
}
static void
gnome_calendar_on_date_navigator_date_range_changed (ECalendarItem *calitem,
GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
priv = gcal->priv;
tag_calendar_by_client (priv->date_navigator, priv->client);
}
static void
gnome_calendar_on_date_navigator_style_set (GtkWidget *widget,
GtkStyle *previous_style,
gpointer data)
{
gnome_calendar_update_paned_quanta (GNOME_CALENDAR (data));
}
static void
gnome_calendar_update_paned_quanta (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
gint row_height, col_width;
gint top_border, bottom_border, left_border, right_border;
priv = gcal->priv;
e_calendar_get_border_size (priv->date_navigator,
&top_border, &bottom_border,
&left_border, &right_border);
gtk_object_get (GTK_OBJECT (priv->date_navigator->calitem),
"row_height", &row_height,
"column_width", &col_width,
NULL);
/* The EPaned quantum feature works better if we add on the calendar
borders to the quantum size. Otherwise if you shrink the date
navigator you get left with the border widths/heights which looks
bad. EPaned should be more flexible really. */
col_width += left_border + right_border;
row_height += top_border + bottom_border;
/* We don't have to use the EPaned quantum feature. We could just let
the calendar expand to fill the allocated space, showing as many
months as will fit. But for that to work nicely the EPaned should
resize the widgets as the bar is dragged. Otherwise the user has
to mess around to get the number of months that they want. */
#if 1
gtk_object_set (GTK_OBJECT (priv->hpane),
"quantum", (guint) col_width,
NULL);
gtk_object_set (GTK_OBJECT (priv->vpane),
"quantum", (guint) row_height,
NULL);
#endif
gnome_calendar_set_pane_positions (gcal);
}
static void
gnome_calendar_on_date_navigator_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data)
{
GnomeCalendar *gcal;
GnomeCalendarPrivate *priv;
gint width, height, row_height, col_width;
gint top_border, bottom_border, left_border, right_border;
gfloat hpane_pos, vpane_pos;
gcal = GNOME_CALENDAR (data);
priv = gcal->priv;
if (priv->current_view_type != VIEW_NOT_SET) {
e_calendar_get_border_size (priv->date_navigator,
&top_border, &bottom_border,
&left_border, &right_border);
gtk_object_get (GTK_OBJECT (priv->date_navigator->calitem),
"row_height", &row_height,
"column_width", &col_width,
NULL);
/* We subtract one from each dimension since we added 1 in
gnome_calendar_set_view_internal(). */
width = allocation->width - 1;
height = allocation->height - 1;
/* We add the border sizes to work around the EPaned
quantized feature. */
col_width += left_border + right_border;
row_height += top_border + bottom_border;
hpane_pos = (gfloat) width / col_width;
vpane_pos = (gfloat) height / row_height;
if (priv->current_view_type == VIEW_MONTH
&& !priv->range_selected) {
priv->hpane_pos_month_view = hpane_pos;
priv->vpane_pos_month_view = vpane_pos;
calendar_config_set_month_hpane_pos (hpane_pos);
calendar_config_set_month_vpane_pos (vpane_pos);
} else {
priv->hpane_pos = hpane_pos;
priv->vpane_pos = vpane_pos;
calendar_config_set_hpane_pos (hpane_pos);
calendar_config_set_vpane_pos (vpane_pos);
}
}
}
void
gnome_calendar_set_view_buttons (GnomeCalendar *gcal,
GtkWidget *day_button,
GtkWidget *work_week_button,
GtkWidget *week_button,
GtkWidget *month_button)
{
GnomeCalendarPrivate *priv;
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
g_return_if_fail (day_button != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (day_button));
g_return_if_fail (work_week_button != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (work_week_button));
g_return_if_fail (week_button != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (week_button));
g_return_if_fail (month_button != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (month_button));
priv = gcal->priv;
priv->day_button = day_button;
priv->work_week_button = work_week_button;
priv->week_button = week_button;
priv->month_button = month_button;
}
/* This makes the appropriate radio button in the toolbar active. It blocks the
* signals so that we can do a clean setup without affecting the views.
*/
void
gnome_calendar_update_view_buttons (GnomeCalendar *gcal)
{
GnomeCalendarPrivate *priv;
GtkWidget *page, *button;
priv = gcal->priv;
page = get_current_page (gcal);
if (page == priv->day_view)
button = priv->day_button;
else if (page == priv->work_week_view)
button = priv->work_week_button;
else if (page == priv->week_view)
button = priv->week_button;
else if (page == priv->month_view)
button = priv->month_button;
else {
g_assert_not_reached ();
return;
}
if (button) {
gtk_signal_handler_block_by_data (GTK_OBJECT (button), gcal);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (button), gcal);
}
}
|