3 int get_datetype(int day
){return datetype
[day
][0];}
5 /*------------------------------------------------------
7 -----------------------------------------------------*/
8 void checkicalversion()
12 char* msg
= "\n\nWARNING:\nIt is highly recommended to upgrade to libical 0.24!\nOtherwise wmCalendar will not work stable!\n";
13 if(!strcmp(ICAL_VERSION
, "0.23")){
15 dialog
= gtk_dialog_new_with_buttons ("Warning",
17 GTK_DIALOG_DESTROY_WITH_PARENT
,
21 label
= gtk_label_new (msg
);
22 g_signal_connect_swapped (GTK_OBJECT (dialog
),
24 G_CALLBACK (gtk_widget_destroy
),
26 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog
)->vbox
), label
);
27 gtk_signal_connect (GTK_OBJECT (dialog
), "destroy",
28 GTK_SIGNAL_FUNC(gtk_main_quit
),
30 gtk_widget_show_all (dialog
);
36 void move(GtkWidget
*widget
, GdkEventButton
*event
)
44 void move2(GtkWidget
*widget
, GdkEventMotion
*event
)
46 gtk_widget_set_uposition((GtkWidget
*)gtk_widget_get_toplevel(widget
),event
->x_root
- xr
, event
->y_root
- yr
);
51 void widget_kill (GtkWidget
* widget
)
53 gtk_widget_destroy ((GtkWidget
*)gtk_widget_get_toplevel(widget
));
59 /*------------------------------------------------------
61 -----------------------------------------------------*/
66 const char* transp
="";
68 icalproperty
*prop
, *reocc
;
72 struct icaltimetype t1
, t2
;
73 if(get_debug())printf("check for new calendar data\n");
74 stream
= fopen((const char*)get_icsfile(),"r");
77 fstat(fileno(stream
), &filestat
);
78 if(filestat
.st_mtime
== modtime
){
82 if(get_debug())printf("read calendar data\n");
84 modtime
= filestat
.st_mtime
;
85 parser
= icalparser_new();
86 /* Tell the parser what input routie it should use. */
87 icalparser_set_gen_data(parser
, stream
);
89 line
= icalparser_get_line(parser
, read_stream
);
90 c
= icalparser_add_line(parser
, line
);
93 for(d
= icalcomponent_get_first_component(c
, ICAL_ANY_COMPONENT
);d
!= 0;
94 d
= icalcomponent_get_next_component(c
, ICAL_ANY_COMPONENT
)){
97 t1
= icalcomponent_get_dtstart(d
);
98 t2
= icalcomponent_get_dtend(d
);
99 if(icaltime_is_null_time(t2
)){
101 icaltime_adjust(&t2
, 1,0,0,0);
104 /* get transparency */
105 prop
= icalcomponent_get_first_property(d
, ICAL_TRANSP_PROPERTY
);
106 reocc
= icalcomponent_get_first_property(d
, ICAL_RRULE_PROPERTY
);
108 transp
= icalproperty_get_value_as_string(prop
);
109 if(!strcmp(transp
, "OPAQUE"))
111 else if(!strcmp(transp
, "TRANSPARENT"))
118 prop
= icalcomponent_get_first_property(d
, ICAL_SUMMARY_PROPERTY
);
120 text
= icalproperty_get_value_as_string(prop
);
121 addCalObj(t1
, t2
, value
, text
, d
);
122 if(get_debug())printf("read: %d.%d.%d - %d.%d.%d %s\n", t1
.day
, t1
.month
,
123 t1
.year
, t2
.day
, t2
.month
, t2
.year
, text
);
125 icalcomponent_free(d
);
127 icalcomponent_free(c
);
130 icalparser_free(parser
);
136 /*------------------------------------------------------
138 -----------------------------------------------------*/
139 void showDay(struct icaltimetype dt
){
140 static GtkWidget
*dayView
;
141 static GtkWidget
*table
;
142 static GtkWidget
*label1
;
143 static GtkWidget
*event_box
;
144 static GtkWidget
*event_box2
;
147 struct tm
*timptr
= NULL
;
148 time_t tt
= icaltime_as_timet(dt
);
149 timptr
= gmtime(&tt
);
150 event_box
= gtk_event_box_new ();
151 gtk_widget_show (event_box
);
152 event_box2
= gtk_event_box_new ();
153 gtk_widget_show (event_box2
);
155 /* create titlebartext */
156 strftime(buf
, 26, "%A, %x", timptr
);
157 sprintf(buf2
, "<b>%s</b>",buf
);
158 /* Create a new window with no boarder and day as titlebar*/
159 dayView
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
161 gtk_window_set_position(GTK_WINDOW (dayView
),GTK_WIN_POS_MOUSE
);
162 gtk_window_set_policy(GTK_WINDOW (dayView
), FALSE
, FALSE
, FALSE
);
163 gtk_window_set_decorated (GTK_WINDOW (dayView
), FALSE
);
164 gtk_window_set_title(GTK_WINDOW (dayView
), buf
);
166 table
= gtk_table_new(1, 4, FALSE
);
167 gtk_table_set_row_spacings ((GtkTable
*)table
, 4);
168 gtk_table_set_col_spacings ((GtkTable
*)table
, 15);
169 gtk_table_set_col_spacing ((GtkTable
*)table
,2, 0);
171 gtk_table_attach_defaults (GTK_TABLE(table
), event_box
, 0, 3, 1, 2);
172 gtk_table_attach_defaults (GTK_TABLE(table
), event_box2
, 3, 4, 1, 2);
174 label1
= gtk_label_new (NULL
);
175 gtk_label_set_markup ((GtkLabel
*)label1
, buf2
);
176 gtk_container_add (GTK_CONTAINER (event_box
), label1
);
178 gtk_table_set_row_spacing ((GtkTable
*)table
,0, 1);
179 gtk_table_set_row_spacing ((GtkTable
*)table
,1, 1);
180 gtk_widget_show (label1
);
181 label1
= gtk_label_new (" X ");
182 gtk_container_add (GTK_CONTAINER (event_box2
), label1
);
183 gtk_widget_show (label1
);
185 /* fill table with events and draw window if there are any events */
186 if(dayevents(dt
, table
)){
187 gtk_widget_show (dayView
);
189 gtk_widget_show (table
);
190 gtk_container_add (GTK_CONTAINER (dayView
), table
);
191 gtk_signal_connect(GTK_OBJECT (event_box
), "motion_notify_event",
192 GTK_SIGNAL_FUNC (move2
), NULL
);
193 gtk_signal_connect(GTK_OBJECT (event_box
), "button_press_event",
194 GTK_SIGNAL_FUNC (move
), NULL
);
195 gtk_signal_connect(GTK_OBJECT (event_box2
), "button_press_event",
196 (GtkSignalFunc
) widget_kill
, GTK_OBJECT(dayView
));
198 gtk_widget_realize(dayView
);
199 // gtk_window_set_position(GTK_WINDOW (dayView),GTK_WIN_POS_CENTER_ON_PARENT);
206 /*------------------------------------------------------
208 -----------------------------------------------------*/
209 int dayevents(struct icaltimetype dt
, GtkWidget
*table
){
210 static GtkWidget
*label1
;
212 struct icaltimetype t1
, t2
;
214 int j
; /* tablerow */
218 struct tm
*timptr
= NULL
;
221 GtkWidget
*separator
;
225 if(eventOnDay(dt
, it
)){
228 separator
= gtk_hseparator_new ();
229 gtk_widget_show (separator
);
230 gtk_table_attach_defaults (GTK_TABLE(table
),separator
, 0, 4, j
, j
+1);
232 if(daysEqual(t1
, t2
)){ /* single event */
233 /* create time entry */
234 tt
= icaltime_as_timet(t1
);
235 timptr
= gmtime(&tt
);
236 strftime(buftime1
, 26, "%X", timptr
);
237 tt
= icaltime_as_timet(t2
);
238 timptr
= gmtime(&tt
);
239 strftime(buftime2
, 26, "%X", timptr
);
240 sprintf(buf
,"%s - %s",buftime1
, buftime2
);
241 label1
= gtk_label_new (NULL
);
242 gtk_label_set_markup ((GtkLabel
*)label1
, buf
);
243 gtk_table_attach_defaults (GTK_TABLE(table
), label1
, 1, 2, j
, j
+1);
244 gtk_widget_show (label1
);
247 /* create description entry */
248 label1
= gtk_label_new (it
->text
);
249 gtk_table_attach_defaults (GTK_TABLE(table
), label1
, 2, 3, j
, j
+1);
250 gtk_widget_show (label1
);
254 /* multiday event or allday event*/
255 t2
.day
--; /* endtime always on the first day after the event ... */
262 t2
.day
= icaltime_days_in_month(t2
.month
, t2
.year
);
264 if(t2
.day
< dt
.day
&& t2
.month
== dt
.month
&& t2
.year
== dt
.year
)
265 continue; /* event ended the day before ... */
266 if(daysEqual(t1
,t2
)){
268 /* create description entry */
269 sprintf(buf
, "<i>all day event</i>");
271 else{ /* multiday event */
272 /* create description with start and enddate */
273 tt
= icaltime_as_timet(t1
);
274 timptr
= gmtime(&tt
);
275 strftime(buftime1
, 26, "%a, %x", timptr
);
276 tt
= icaltime_as_timet(t2
);
277 timptr
= gmtime(&tt
);
278 strftime(buftime2
, 26, "%a, %x", timptr
);
279 sprintf(buf
, "%s - %s", buftime1
, buftime2
);
281 label1
= gtk_label_new (NULL
);
282 gtk_label_set_markup ((GtkLabel
*)label1
, buf
);
284 gtk_table_attach_defaults (GTK_TABLE(table
), label1
, 1, 2, j
, j
+1);
285 gtk_widget_show (label1
);
287 prop
= icalcomponent_get_first_property(it
->comp
, ICAL_LOCATION_PROPERTY
);
289 sprintf(buf
, "%s\n%s", it
->text
, icalproperty_get_location(prop
));
291 sprintf(buf
, "%s", it
->text
);
292 label1
= gtk_label_new (buf
);
293 gtk_label_set_justify(GTK_LABEL(label1
),GTK_JUSTIFY_CENTER
);
294 gtk_table_attach_defaults (GTK_TABLE(table
), label1
, 2, 3, j
, j
+1);
295 gtk_widget_show (label1
);
301 label1
= gtk_label_new (NULL
);
302 gtk_table_attach_defaults (GTK_TABLE(table
), label1
, 2, 3, j
+1, j
+2);
303 gtk_table_set_row_spacing (GTK_TABLE(table
),j
, 0);
304 if(j
==2) /* no entries for this day */
311 /*------------------------------------------------------
313 -----------------------------------------------------*/
314 void deleteCalObjs(){
318 help
= (struct calobj
*) calRoot
->next
;
324 for(i
= 0; i
< 32; i
++)
330 /*------------------------------------------------------
332 -----------------------------------------------------*/
333 void addCalObj(struct icaltimetype start
, struct icaltimetype end
,
334 int type
, const char *text
, icalcomponent
* d
){
335 struct calobj
*newobj
;
336 icalcomponent
*newcomp
= malloc(sizeof(struct calobj
));
337 char* buf
= malloc (strlen(text
) + 1);
338 newcomp
= icalcomponent_new_clone(d
);
340 newobj
= malloc(sizeof(struct calobj
));
341 newobj
->comp
= newcomp
;
342 newobj
->start
= start
;
346 newobj
->next
= calRoot
;
352 /*------------------------------------------------------
354 -----------------------------------------------------*/
355 int getDayType(struct icaltimetype dt
){
358 if(datetype
[jd
% 31][1] == jd
)
359 return datetype
[jd
% 31][0];
361 return calcDayType(dt
);
366 /*------------------------------------------------------
368 -----------------------------------------------------*/
369 int isExluded(icalcomponent
*comp
, struct icaltimetype dt
){
371 prop
= icalcomponent_get_first_property(comp
, ICAL_EXDATE_PROPERTY
);
373 if(daysEqual(icalproperty_get_exdate(prop
), dt
))
375 prop
= icalcomponent_get_next_property(comp
, ICAL_EXDATE_PROPERTY
);
382 /*------------------------------------------------------
384 -----------------------------------------------------*/
385 int eventOnDay(struct icaltimetype dt
, struct calobj
* it
)
387 icalrecur_iterator
* ritr
;
389 struct icaltimetype next
;
390 if((daysEarlierEqual(dt
, it
->start
) && daysLater(dt
, it
->end
))
391 || (daysEqual(dt
, it
->start
) && daysEqual(dt
, it
->end
)))
393 rrule
= icalcomponent_get_first_property((icalcomponent
*)it
->comp
, ICAL_RRULE_PROPERTY
);
396 if(daysEarlierEqual(dt
, it
->start
)){
397 ritr
= icalrecur_iterator_new( icalproperty_get_rrule(rrule
), it
->start
);
399 next
= icalrecur_iterator_next(ritr
);
400 while(daysEarlierEqual(dt
, next
) && !icaltime_is_null_time(next
)){
401 if(daysEqual(dt
, next
) && !isExluded((icalcomponent
*)it
->comp
, dt
))
406 next
= icalrecur_iterator_next(ritr
);
416 /*------------------------------------------------------
418 -----------------------------------------------------*/
419 int calcDayType(struct icaltimetype dt
){
423 datetype
[jd
% 31][1] = jd
;
424 datetype
[jd
% 31][0] = 0;
427 if(eventOnDay(dt
, it
))
428 if(datetype
[jd
% 31][0] != 1)
429 datetype
[jd
% 31][0] = it
->type
;
432 return datetype
[jd
% 31][0];