2 void set_lang(int language
){lang
= language
;}
3 void setAppicon(int app
){appicon
= app
;}
4 void enter_callback( GtkWidget
*widget
, GtkWidget
*entry
){
5 strcpy(application
, gtk_entry_get_text(GTK_ENTRY(entry
)));}
6 int getAppicon(){return appicon
;}
7 int get_start_of_week(){return start_of_week
;}
8 int get_lang(){return lang
;}
9 int get_debug(){return debug
;}
10 void set_debug(int deb
){debug
= deb
;}
11 char* getVersion(){return WMCALENDAR_VERSION
;}
12 const char* get_application(){return application
;}
13 const char* get_icsfile(){return icsfile
;}
15 /*------------------------------------------------------
17 -----------------------------------------------------*/
18 void destroy (GtkWidget
* widget
, gpointer data
){
24 /*------------------------------------------------------
26 -----------------------------------------------------*/
29 struct tm
*timptr
= malloc(sizeof(struct tm
));
32 char *set
= malloc(4096);
37 strcpy (rcfile
, (char *) getenv ("HOME"));
38 strcat(rcfile
, "/.wmcalendarrc");
39 stream
= fopen(rcfile
,"r");
41 for(i
= 1; i
< 8; i
++){
42 timptr
->tm_wday
= (8-i
)%7;
43 strftime(buf
, 15, "%A", timptr
);
45 strcpy(daystr
[i
], buf
);
48 if(stream
== 0){ /* no rcfile */
50 printf("created %s with default settings:\nICON:evolution\nLANG:default\nAPP:%s\nICS:%s\n\n",
51 rcfile
, application
, icsfile
);
55 fseek (stream
, 0 , SEEK_END
);
56 lSize
= ftell (stream
);
58 fread (set
,1,lSize
,stream
);
60 pch
= strtok (set
,"\n=");
70 strcpy(application
, pch
);
75 if(!strcmp(pch
, "farsi"))
81 if(!strcmp(pch
, "mozilla"))
83 else if(!strcmp(pch
, "evolution"))
91 if(!strcmp(pch
,WMCALENDAR_VERSION
))
97 start_of_week
= atoi(pch
);
102 if(!strcmp(pch
, "ICS"))
104 else if(!strcmp(pch
, "APP"))
106 else if(!strcmp(pch
, "LANG"))
108 else if(!strcmp(pch
, "ICON"))
110 else if(!strcmp(pch
, "VERSION"))
112 else if(!strcmp(pch
, "STARTOFWEEK"))
117 pch
= strtok (NULL
, "=\n");
124 printf("Old rcfile detected!\nCreated new %s with default settings:", rcfile
);
125 printf("\nICON:evolution\nLANG:default\nAPP:%s\nICS:%s\n\n", application
, icsfile
);
127 if(get_debug())printf("settings:\nICON:%d\nLANG:%d\nAPP:%s\nRC:%s\nICS:%s\n\n",
128 getAppicon(), lang
, application
, rcfile
, icsfile
);
133 /*------------------------------------------------------
135 -----------------------------------------------------*/
136 void writeSettings(){
137 char *set
= malloc(1024);
138 char *bufint
= malloc(5);
140 if(debug
)printf("write settings\n");
141 stream
= fopen(rcfile
,"w");
142 if(strlen(icsfile
)==0){
143 strcpy(icsfile
, (char *) getenv ("HOME"));
144 strcat(icsfile
, "/evolution/local/Calendar/calendar.ics");
146 if(strlen(application
)==0)
147 strcpy(application
, "evolution");
149 strcat(set
, icsfile
);
150 strcat(set
, "\nAPP=");
151 strcat(set
, application
);
153 strcat(set
, "\nICON=evolution");
155 strcat(set
, "\nICON=mozilla");
157 strcat(set
, "\nICON=other");
159 strcat(set
, "\nLANG=farsi");
161 strcat(set
, "\nLANG=default");
162 strcat(set
,"\nVERSION=");
163 strcat(set
,WMCALENDAR_VERSION
);
164 strcat(set
,"\nSTARTOFWEEK=");
165 sprintf(bufint
, "%d",start_of_week
);
168 fwrite(set
, 1, strlen(set
), stream
);
176 /*------------------------------------------------------
178 -----------------------------------------------------*/
179 void SettingsSeperator(GtkWidget
*box1
){
180 GtkWidget
*separator
;
181 separator
= gtk_hseparator_new ();
182 gtk_box_pack_start (GTK_BOX (box1
), separator
, FALSE
, TRUE
, 5);
183 gtk_widget_show (separator
);
189 /*------------------------------------------------------
191 -----------------------------------------------------*/
192 void SettingsLabel(GtkWidget
*box1
, char* str
){
194 label
= gtk_label_new (str
);
195 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0);
196 gtk_box_pack_start (GTK_BOX (box1
), label
, TRUE
, TRUE
, 3);
197 gtk_widget_show (label
);
203 /*------------------------------------------------------
205 -----------------------------------------------------*/
213 GtkWidget
*optionmenu
;
218 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
219 gtk_window_set_policy(GTK_WINDOW (window
), FALSE
, FALSE
, FALSE
);
221 gtk_signal_connect (GTK_OBJECT (window
), "destroy",
222 GTK_SIGNAL_FUNC(destroy
),
224 sprintf(title
, "wmCalendar %s", WMCALENDAR_VERSION
);
225 gtk_window_set_title (GTK_WINDOW (window
), title
);
226 gtk_container_set_border_width (GTK_CONTAINER (window
), 0);
228 box1
= gtk_vbox_new (FALSE
, 0);
229 gtk_container_add (GTK_CONTAINER (window
), box1
);
230 gtk_widget_show (box1
);
232 /* -------------- Applaunch icon --------------------------*/
233 SettingsLabel(box1
, "Applaunch icon");
235 box2
= gtk_hbox_new (FALSE
, 10);
236 gtk_container_set_border_width (GTK_CONTAINER (box2
), 0);
237 gtk_box_pack_start (GTK_BOX (box1
), box2
, TRUE
, TRUE
, 3);
238 gtk_widget_show (box2
);
240 /* create appicon boxes*/
241 button
= gtk_radio_button_new_with_label (NULL
, "Evolution");
242 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
243 GTK_SIGNAL_FUNC(setAppicon
),
246 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
247 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
248 gtk_widget_show (button
);
250 group
= gtk_radio_button_group (GTK_RADIO_BUTTON (button
));
251 button
= gtk_radio_button_new_with_label(group
, "Mozilla");
252 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
253 GTK_SIGNAL_FUNC(setAppicon
),
256 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
257 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
258 gtk_widget_show (button
);
260 button
= gtk_radio_button_new_with_label(
261 gtk_radio_button_group (GTK_RADIO_BUTTON (button
)),
263 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
264 GTK_SIGNAL_FUNC(setAppicon
),
267 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
268 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
269 gtk_widget_show (button
);
271 SettingsSeperator(box1
);
273 /* -------------- Applaunch command -----------------------*/
274 SettingsLabel(box1
, "Applaunch command");
276 entry
= gtk_entry_new_with_max_length (100);
277 gtk_signal_connect(GTK_OBJECT(entry
), "changed",
278 GTK_SIGNAL_FUNC(enter_callback
),
280 gtk_entry_set_text (GTK_ENTRY (entry
), application
);
281 gtk_box_pack_start (GTK_BOX (box1
), entry
, TRUE
, TRUE
, 3);
282 gtk_widget_show (entry
);
284 SettingsSeperator(box1
);
286 /* -------------- Language -------------------------------*/
287 SettingsLabel(box1
, "Language");
289 /* create Language boxes */
290 box2
= gtk_hbox_new (FALSE
, 10);
291 gtk_container_set_border_width (GTK_CONTAINER (box2
), 0);
292 gtk_box_pack_start (GTK_BOX (box1
), box2
, TRUE
, TRUE
, 3);
293 gtk_widget_show (box2
);
295 button
= gtk_radio_button_new_with_label (NULL
, "default");
296 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
297 GTK_SIGNAL_FUNC(set_lang
),
300 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
301 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
302 gtk_widget_show (button
);
304 group
= gtk_radio_button_group (GTK_RADIO_BUTTON (button
));
305 button
= gtk_radio_button_new_with_label(group
, "farsi");
306 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
307 GTK_SIGNAL_FUNC(set_lang
),
310 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
311 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
312 gtk_widget_show (button
);
314 SettingsSeperator(box1
);
316 /* -------------- first day of week --------------------------*/
317 SettingsLabel(box1
, "Week starts");
318 optionmenu
= gtk_option_menu_new();
319 menu
= gtk_menu_new();
320 for(ii
= 7; ii
> 0; ii
--){
321 menuitem
= gtk_menu_item_new_with_label(daystr
[ii
]);
322 gtk_widget_show (menuitem
);
323 gtk_menu_append(menu
, menuitem
);
325 gtk_menu_set_active(GTK_MENU (menu
), 7 - start_of_week
);
326 gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu
),menu
);
327 gtk_box_pack_start (GTK_BOX (box1
), optionmenu
, TRUE
, TRUE
, 5);
328 gtk_widget_show (optionmenu
);
330 SettingsSeperator(box1
);
333 /* -------------- Buttons -------------------------------*/
334 button
= gtk_button_new_with_label ("change iCalendar file");
335 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
336 GTK_SIGNAL_FUNC(changeFilename
),
338 gtk_box_pack_start (GTK_BOX (box1
), button
, TRUE
, TRUE
, 2);
339 gtk_widget_show (button
);
341 button
= gtk_button_new_with_label ("save");
342 gtk_signal_connect (GTK_OBJECT (button
), "clicked",
343 (GtkSignalFunc
) setFirstDay
,
344 GTK_OPTION_MENU (optionmenu
));
345 gtk_box_pack_start (GTK_BOX (box1
), button
, TRUE
, FALSE
, 2);
346 gtk_widget_show (button
);
348 button
= gtk_button_new_with_label ("close");
349 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
350 (GtkSignalFunc
) gtk_widget_destroy
,
351 GTK_OBJECT (window
));
352 gtk_box_pack_start (GTK_BOX (box1
), button
, TRUE
, TRUE
, 2);
353 gtk_widget_show (button
);
354 gtk_widget_show (window
);
360 /*------------------------------------------------------
362 -----------------------------------------------------*/
363 void setFirstDay(GtkWidget
*widget
, GtkWidget
*optionmenu
){
366 gtk_label_get (GTK_LABEL (GTK_BIN (optionmenu
)->child
), &daystring
);
367 for(ii
= 1; ii
< 8; ii
++)
368 if(!strcmp(daystring
, daystr
[ii
]))
376 /*------------------------------------------------------
378 -----------------------------------------------------*/
379 void changeFilename(){
380 static GtkWidget
*settings
;
382 settings
= gtk_file_selection_new("iCalendar file");
384 gtk_file_selection_set_filename (GTK_FILE_SELECTION(settings
),
386 /* Connect the ok_button to file_ok_sel function */
387 gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION (settings
)->ok_button
),
388 "clicked",(GtkSignalFunc
) file_ok_sel
, (gpointer
) settings
);
389 gtk_signal_connect(GTK_OBJECT (settings
), "destroy",
390 GTK_SIGNAL_FUNC (destroy
), NULL
);
391 gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION(settings
)->cancel_button
),
392 "clicked", (GtkSignalFunc
) gtk_widget_destroy
, GTK_OBJECT (settings
));
394 gtk_window_position (GTK_WINDOW(settings
), GTK_WIN_POS_MOUSE
);
395 gtk_widget_show (settings
);
401 /*------------------------------------------------------
403 -----------------------------------------------------*/
404 static void file_ok_sel( GtkWidget
*w
,
405 GtkFileSelection
*fs
)
407 strcpy(icsfile
, gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs
)));
408 gtk_widget_destroy((GtkWidget
*)fs
);