"Fossies" - the Fresh Open Source Software Archive 
Member "jpilot-2_0_1/prefs_gui.c" (3 Apr 2021, 38768 Bytes) of package /linux/privat/jpilot-2_0_1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*******************************************************************************
2 * prefs_gui.c
3 * A module of J-Pilot http://jpilot.org
4 *
5 * Copyright (C) 1999-2014 by Judd Montgomery
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; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
20
21 /********************************* Includes ***********************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include <gtk/gtk.h>
26
27 #include "prefs_gui.h"
28 #include "prefs.h"
29 #include "i18n.h"
30 #include "utils.h"
31 #include "log.h"
32 #include "plugins.h"
33
34 /******************************* Global vars **********************************/
35 static GtkWidget *window;
36 static GtkWidget *main_window;
37 static GtkWidget *port_entry;
38 static GtkWidget *backups_entry;
39 static GtkWidget *ext_editor_entry;
40 static GtkWidget *alarm_command_entry;
41 static GtkWidget *mail_command_entry;
42 static GtkWidget *todo_days_due_entry;
43
44 extern int glob_app;
45 #ifdef ENABLE_PLUGINS
46 extern unsigned char skip_plugins;
47 #endif
48
49 /* Sync Port Menu */
50 static GtkWidget *port_menu;
51 static const char *port_choices[] = {
52 "other", "usb:",
53 "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3",
54 "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3",
55 NULL
56 };
57
58 /* Serial Rate Menu */
59 static GtkWidget *rate_menu;
60
61 /****************************** Main Code *************************************/
62 #ifdef COLORS
63
64 /* This doesn't work quite right. There is supposedly no way to do it in GTK. */
65 static void r(GtkWidget *w, gpointer data)
66 {
67 /* GtkStyle *style;
68
69 style = gtk_rc_get_style(GTK_WIDGET(w));
70 if (style) gtk_rc_style_unref(style);
71 if (GTK_IS_CONTAINER(w)) {
72 gtk_container_foreach(GTK_CONTAINER(w), r, w);
73 } */
74 }
75
76 static void set_colors()
77 {
78 /* GtkStyle* style;
79 int i;
80
81 r(main_window, NULL);
82 r(window, NULL);
83
84 gtk_rc_reparse_all();
85 read_gtkrc_file();
86 gtk_rc_reparse_all();
87 gtk_widget_reset_rc_styles(window);
88 gtk_widget_reset_rc_styles(main_window);
89 gtk_rc_reparse_all();
90 gtk_widget_queue_draw(window);
91 gtk_widget_queue_draw(main_window); */
92 }
93 #endif /* #ifdef COLORS */
94
95 /* Sync Port menu code */
96 static void cb_serial_port_menu(GtkComboBox *widget,
97 gpointer data) {
98 if (!widget)
99 return;
100 int choice = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
101 //don't do things if 'other' or nothing is selected..
102 if (choice < 1) {
103 return;
104 }
105
106 const char *port_str = port_choices[choice];
107 gtk_entry_set_text(GTK_ENTRY(port_entry), port_str);
108 if (!strcmp(port_str, "usb:")) {
109 gtk_widget_set_sensitive(rate_menu, FALSE);
110 } else {
111 gtk_widget_set_sensitive(rate_menu, TRUE);
112 }
113
114
115 return;
116 }
117
118 static int make_serial_port_menu(GtkWidget **port_menu) {
119 int i, selected;
120 const char *entry_text;
121
122 *port_menu = gtk_combo_box_text_new();
123
124 // menu = gtk_menu_new();
125 // group = NULL;
126 selected = 0;
127
128 entry_text = gtk_entry_get_text(GTK_ENTRY(port_entry));
129
130 for (i = 0; port_choices[i]; i++) {
131 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (*port_menu), port_choices[i]);
132 if (!strcmp(entry_text, port_choices[i])) {
133 gtk_combo_box_set_active(GTK_COMBO_BOX (*port_menu), i);
134 selected = i;
135 }
136
137 /* We don't want a callback if "other" is selected */
138 // gtk_widget_show(port_menu_item[i]);
139 }
140 g_signal_connect(G_OBJECT(*port_menu), "changed",
141 G_CALLBACK(cb_serial_port_menu),
142 GINT_TO_POINTER(selected));
143 gtk_combo_box_set_active(GTK_COMBO_BOX(*port_menu), selected);
144
145 return EXIT_SUCCESS;
146 }
147
148 /* End Sync Port Menu code */
149
150 static void cb_pref_menu(GtkComboBox *widget, gpointer data) {
151 int pref;
152
153 if (!widget) {
154 return;
155 }
156 if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) < 0) {
157 return;
158 }
159
160 pref = get_selected_category_from_combo_box(widget);
161 set_pref_possibility(pref, gtk_combo_box_get_active(GTK_COMBO_BOX(widget)), TRUE);
162
163 jp_logf(JP_LOG_DEBUG, "pref %d, value %d\n", pref, GPOINTER_TO_INT(data) & 0xFF);
164 #ifdef COLORS
165 if (pref==PREF_RCFILE) {
166 set_colors();
167 }
168 #endif
169 return;
170 }
171
172 int make_pref_menu(GtkWidget **pref_menu, int pref_num) {
173 int i, r;
174 long ivalue;
175 const char *svalue;
176 char format_text[MAX_PREF_LEN];
177 char human_text[MAX_PREF_LEN];
178 time_t ltime;
179 struct tm *now;
180 GtkListStore *catListStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
181 GtkTreeIter iter;
182
183 time(<ime);
184 now = localtime(<ime);
185
186
187 //menu = gtk_menu_new();
188 ///group = NULL;
189
190 get_pref(pref_num, &ivalue, &svalue);
191
192
193 for (i = 0; i < MAX_NUM_PREFS; i++) {
194 r = get_pref_possibility(pref_num, i, format_text);
195 if (r) {
196 break;
197 }
198 switch (pref_num) {
199 case PREF_SHORTDATE:
200 case PREF_TIME:
201 jp_strftime(human_text, MAX_PREF_LEN, format_text, now);
202 break;
203 case PREF_LONGDATE:
204 jp_strftime(human_text, MAX_PREF_LEN, _(format_text), now);
205 break;
206 default:
207 strncpy(human_text, format_text, MAX_PREF_LEN);
208 break;
209 }
210 gtk_list_store_append (catListStore, &iter);
211 gtk_list_store_set (catListStore, &iter, 0, human_text, 1, pref_num, -1);
212
213
214 }
215 *pref_menu = gtk_combo_box_new_with_model(GTK_TREE_MODEL (catListStore));
216 gtk_combo_box_set_active(GTK_COMBO_BOX(*pref_menu), ivalue);
217 g_signal_connect(G_OBJECT(*pref_menu), "changed", G_CALLBACK(cb_pref_menu),
218 GINT_TO_POINTER(pref_num));
219 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
220 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (*pref_menu), renderer, TRUE);
221 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (*pref_menu), renderer,
222 "text", 0,
223 NULL);
224 //gtk_option_menu_set_menu(GTK_(*pref_menu), menu);
225
226 return EXIT_SUCCESS;
227 }
228
229 static void cb_backups_entry(GtkWidget *widget, gpointer data) {
230 const char *entry_text;
231 int num_backups;
232
233 entry_text = gtk_entry_get_text(GTK_ENTRY(backups_entry));
234 sscanf(entry_text, "%d", &num_backups);
235
236 if (num_backups < 1) {
237 num_backups = 1;
238 }
239 if (num_backups > 99) {
240 num_backups = 99;
241 }
242
243 set_pref(PREF_NUM_BACKUPS, num_backups, NULL, FALSE);
244 }
245
246 static void cb_checkbox_todo_days_till_due(GtkWidget *widget, gpointer data) {
247 int num_days;
248 const char *entry_text;
249
250 entry_text = gtk_entry_get_text(GTK_ENTRY(todo_days_due_entry));
251
252 sscanf(entry_text, "%d", &num_days);
253
254 set_pref(PREF_TODO_DAYS_TILL_DUE, num_days, NULL, TRUE);
255 }
256
257 static void cb_checkbox_show_tooltips(GtkWidget *widget, gpointer data) {
258 set_pref(PREF_SHOW_TOOLTIPS, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)), NULL, TRUE);
259 }
260
261 static void cb_text_entry(GtkWidget *widget, gpointer data) {
262 const char *entry_text;
263 int i, found;
264
265 entry_text = gtk_entry_get_text(GTK_ENTRY(widget));
266 set_pref(GPOINTER_TO_INT(data), 0, entry_text, FALSE);
267
268 if (GPOINTER_TO_INT(data) == PREF_PORT) {
269 if (GTK_IS_WIDGET(port_menu)) {
270 found = 0;
271 for (i = 0; port_choices[i]; i++) {
272 if (!strcmp(entry_text, port_choices[i])) {
273 gtk_combo_box_set_active(GTK_COMBO_BOX(port_menu), i);
274 found = 1;
275 }
276 }
277 if (!found) {
278 gtk_combo_box_set_active(GTK_COMBO_BOX(port_menu), 0);
279 }
280 }
281 }
282 }
283
284 static void cb_checkbox_set_pref(GtkWidget *widget, gpointer data) {
285 unsigned long pref, value;
286
287 pref = GPOINTER_TO_INT(data);
288 value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
289 set_pref(pref, value, NULL, TRUE);
290 }
291
292 /*
293 * upper 16 bits of data is pref to set
294 * lower 16 bits of data is value to set it to
295 */
296 static void cb_radio_set_pref(GtkWidget *widget, gpointer data) {
297 unsigned long pref, value;
298
299 pref = GPOINTER_TO_INT(data);
300 value = pref & 0xFFFF;
301 pref >>= 16;
302 set_pref(pref, value, NULL, TRUE);
303 }
304
305
306 #ifdef ENABLE_PLUGINS
307
308 static void cb_sync_plugin(GtkWidget *widget, gpointer data) {
309 GList *plugin_list, *temp_list;
310 struct plugin_s *Pplugin;
311 int number;
312
313 number = GPOINTER_TO_INT(data);
314
315 plugin_list = NULL;
316
317 plugin_list = get_plugin_list();
318
319 for (temp_list = plugin_list; temp_list; temp_list = temp_list->next) {
320 Pplugin = (struct plugin_s *) temp_list->data;
321 if (Pplugin) {
322 if (number == Pplugin->number) {
323 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
324 Pplugin->sync_on = 1;
325 } else {
326 Pplugin->sync_on = 0;
327 }
328 }
329 }
330 }
331 write_plugin_sync_file();
332 }
333
334 #endif
335
336 static gboolean cb_destroy(GtkWidget *widget) {
337 jp_logf(JP_LOG_DEBUG, "Pref GUI Cleanup\n");
338
339 pref_write_rc_file();
340
341 window = NULL;
342
343 /* Preference changes can affect visual elements of applications.
344 * Redraw the screen to incorporate any changes made. */
345 cb_app_button(NULL, GINT_TO_POINTER(REDRAW));
346
347 return FALSE;
348 }
349
350 static void cb_quit(GtkWidget *widget, gpointer data) {
351 jp_logf(JP_LOG_DEBUG, "cb_quit\n");
352 if (GTK_IS_WIDGET(data)) {
353 gtk_widget_destroy(data);
354 }
355 }
356
357 /* This function adds a simple option checkbutton for the supplied text +
358 * option. */
359 static void add_checkbutton(const char *text,
360 int which,
361 GtkWidget *vbox,
362 void cb(GtkWidget *widget, gpointer data)) {
363 /* Create button */
364 GtkWidget *checkbutton = gtk_check_button_new_with_label(text);
365 gtk_box_pack_start(GTK_BOX(vbox), checkbutton, FALSE, FALSE, 0);
366 gtk_widget_show(checkbutton);
367
368 /* Set the button state based on option value */
369 if (get_pref_int_default(which, 0))
370 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
371
372 /* Set button callback */
373 g_signal_connect(G_OBJECT(checkbutton), "clicked", G_CALLBACK(cb),
374 GINT_TO_POINTER(which));
375 }
376
377 void cb_prefs_gui(GtkWidget *widget, gpointer data) {
378 GtkWidget *checkbutton;
379 // GtkWidget *pref_menu;
380 GtkWidget * pref_char_set;
381 GtkWidget * pref_short_date;
382 GtkWidget * pref_long_date;
383 GtkWidget * pref_time;
384 GtkWidget * pref_rc_file;
385 GtkWidget *label;
386 GtkWidget *button;
387 GtkWidget *grid;
388 GtkWidget *vbox;
389 GtkWidget *vbox_locale;
390 GtkWidget *vbox_settings;
391 GtkWidget *vbox_datebook;
392 GtkWidget *vbox_address;
393 GtkWidget *vbox_todo;
394 GtkWidget *vbox_memo;
395 GtkWidget *vbox_alarms;
396 GtkWidget *vbox_conduits;
397 GtkWidget *hbox_temp;
398 GtkWidget *hseparator;
399 GtkWidget *notebook;
400 /* FIXME: Uncomment when support for Task has been added */
401 #if 0
402 GtkWidget *radio_button_todo_version[2];
403 #endif
404 GtkWidget *radio_button_datebook_version[2];
405 GtkWidget *radio_button_address_version[2];
406 GtkWidget *radio_button_memo_version[3];
407 long ivalue;
408 const char *cstr;
409 char temp_str[10];
410 char temp[256];
411 GSList *group;
412 #ifdef ENABLE_PLUGINS
413 GList *plugin_list, *temp_list;
414 struct plugin_s *Pplugin;
415 #endif
416
417 jp_logf(JP_LOG_DEBUG, "cb_prefs_gui\n");
418 if (window) {
419 jp_logf(JP_LOG_DEBUG, "pref_window is already up\n");
420 /* Shift focus to existing window if called again
421 and window is still alive. */
422 gtk_window_present(GTK_WINDOW(window));
423 return;
424 }
425
426 main_window = data;
427
428 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
429 gtk_container_set_border_width(GTK_CONTAINER(window), 10);
430 g_snprintf(temp, sizeof(temp), "%s %s", PN, _("Preferences"));
431 gtk_window_set_title(GTK_WINDOW(window), temp);
432
433 g_signal_connect(G_OBJECT(window), "destroy",
434 G_CALLBACK(cb_destroy), window);
435
436 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
437 gtk_container_add(GTK_CONTAINER(window), vbox);
438
439 /* Boxes for each preference tax */
440 vbox_locale = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
441 vbox_settings = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
442 vbox_datebook = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
443 vbox_address = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
444 vbox_todo = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
445 vbox_memo = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
446 vbox_alarms = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
447 vbox_conduits = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
448
449 gtk_container_set_border_width(GTK_CONTAINER(vbox_locale), 5);
450 gtk_container_set_border_width(GTK_CONTAINER(vbox_settings), 5);
451 gtk_container_set_border_width(GTK_CONTAINER(vbox_datebook), 5);
452 gtk_container_set_border_width(GTK_CONTAINER(vbox_address), 5);
453 gtk_container_set_border_width(GTK_CONTAINER(vbox_todo), 5);
454 gtk_container_set_border_width(GTK_CONTAINER(vbox_memo), 5);
455 gtk_container_set_border_width(GTK_CONTAINER(vbox_alarms), 5);
456 gtk_container_set_border_width(GTK_CONTAINER(vbox_conduits), 5);
457
458 /* Notebook for preference tabs */
459 notebook = gtk_notebook_new();
460 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
461 label = gtk_label_new(_("Locale"));
462 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_locale, label);
463 label = gtk_label_new(_("Settings"));
464 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_settings, label);
465 label = gtk_label_new(_("Datebook"));
466 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_datebook, label);
467 label = gtk_label_new(C_("prefgui", "Address"));
468 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_address, label);
469 label = gtk_label_new(_("ToDo"));
470 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_todo, label);
471 label = gtk_label_new(_("Memo"));
472 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_memo, label);
473 label = gtk_label_new(_("Alarms"));
474 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_alarms, label);
475 label = gtk_label_new(_("Conduits"));
476 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_conduits, label);
477 gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, FALSE, 0);
478
479 /************************************************************/
480 /* Locale preference tab */
481 grid = gtk_grid_new();
482 gtk_grid_set_row_spacing(GTK_GRID(grid), 2);
483 gtk_grid_set_column_spacing(GTK_GRID(grid), 5);
484 gtk_box_pack_start(GTK_BOX(vbox_locale), grid, FALSE, FALSE, 0);
485
486 /* Locale preference tab */
487
488 /* Character Set */
489 label = gtk_label_new(_("Character Set"));
490 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 0, 1, 1);
491
492 make_pref_menu(&pref_char_set, PREF_CHAR_SET);
493 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(pref_char_set), 1, 0, 1, 1);
494
495 get_pref(PREF_CHAR_SET, &ivalue, NULL);
496 gtk_combo_box_set_active(GTK_COMBO_BOX(pref_char_set), ivalue);
497 /* Shortdate */
498 label = gtk_label_new(_("Short date format"));
499 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 1, 1, 1);
500
501 make_pref_menu(&pref_short_date, PREF_SHORTDATE);
502 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(pref_short_date), 1, 1, 1, 1);
503
504 get_pref(PREF_SHORTDATE, &ivalue, NULL);
505 gtk_combo_box_set_active(GTK_COMBO_BOX(pref_short_date), ivalue);
506
507 /* Longdate */
508 label = gtk_label_new(_("Long date format"));
509 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 2, 1, 1);
510
511 make_pref_menu(&pref_long_date, PREF_LONGDATE);
512 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(pref_long_date), 1, 2, 1, 1);
513
514 get_pref(PREF_LONGDATE, &ivalue, NULL);
515 gtk_combo_box_set_active(GTK_COMBO_BOX(pref_long_date), ivalue);
516
517 /* Time */
518 label = gtk_label_new(_("Time format"));
519 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 3, 1, 1);
520
521 make_pref_menu(&pref_time, PREF_TIME);
522 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(pref_time), 1, 3, 1, 1);
523
524 get_pref(PREF_TIME, &ivalue, NULL);
525 gtk_combo_box_set_active(GTK_COMBO_BOX(pref_time), ivalue);
526
527 /**********************************************************************/
528 /* Settings preference tab */
529 grid = gtk_grid_new();
530 gtk_grid_set_row_spacing(GTK_GRID(grid), 2);
531 gtk_grid_set_column_spacing(GTK_GRID(grid), 5);
532 gtk_box_pack_start(GTK_BOX(vbox_settings), grid, FALSE, FALSE, 0);
533
534 /* GTK colors file */
535 label = gtk_label_new(_("GTK color theme file"));
536 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 1, 0, 1, 1);
537
538 make_pref_menu(&pref_rc_file, PREF_RCFILE);
539 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(pref_rc_file), 2, 0, 1, 1);
540
541
542 get_pref(PREF_RCFILE, &ivalue, NULL);
543 gtk_combo_box_set_active(GTK_COMBO_BOX(pref_rc_file), ivalue);
544
545 /* Port */
546 label = gtk_label_new(_("Sync Port"));
547 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 1, 1, 1);
548
549 port_entry = gtk_entry_new();
550 gtk_entry_set_max_length(GTK_ENTRY(port_entry), MAX_PREF_LEN - 2);
551 entry_set_multiline_truncate(GTK_ENTRY(port_entry), TRUE);
552 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(port_entry), 2, 1, 1, 1);
553 get_pref(PREF_PORT, NULL, &cstr);
554 if (cstr) {
555 gtk_entry_set_text(GTK_ENTRY(port_entry), cstr);
556 }
557 g_signal_connect(G_OBJECT(port_entry),
558 "changed", G_CALLBACK(cb_text_entry),
559 GINT_TO_POINTER(PREF_PORT));
560
561 /* Sync Port Menu */
562 /* Note that port_entry must exist before we call this function */
563 make_serial_port_menu(&port_menu);
564 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(port_menu), 1, 1, 1, 1);
565
566 /* Serial Rate */
567 label = gtk_label_new(_("Serial Rate"));
568 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 1, 2, 1, 1);
569
570 make_pref_menu(&rate_menu, PREF_RATE);
571 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(rate_menu), 2, 2, 1, 1);
572
573 get_pref(PREF_RATE, &ivalue, NULL);
574 gtk_combo_box_set_active(GTK_COMBO_BOX(rate_menu), ivalue);
575
576 /* Disable Serial Rate menu if sync port is USB */
577 if (!strcmp(cstr, "usb:")) {
578 gtk_widget_set_sensitive(rate_menu, FALSE);
579 } else {
580 gtk_widget_set_sensitive(rate_menu, TRUE);
581 }
582
583 /* Number of backups */
584 label = gtk_label_new(_("Number of backups to be archived"));
585 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(label), 0, 3, 2, 1);
586
587 backups_entry = gtk_entry_new();
588 gtk_entry_set_max_length(GTK_ENTRY(backups_entry), 2);
589 entry_set_multiline_truncate(GTK_ENTRY(backups_entry), TRUE);
590 gtk_widget_set_size_request(backups_entry, 30, 0);
591 gtk_grid_attach(GTK_GRID(grid), GTK_WIDGET(backups_entry), 2, 3, 1, 1);
592 get_pref(PREF_NUM_BACKUPS, &ivalue, NULL);
593 sprintf(temp_str, "%ld", ivalue);
594 gtk_entry_set_text(GTK_ENTRY(backups_entry), temp_str);
595 g_signal_connect(G_OBJECT(backups_entry),
596 "changed", G_CALLBACK(cb_backups_entry),
597 NULL);
598
599 /* Show deleted files check box */
600 add_checkbutton(_("Show deleted records (default NO)"),
601 PREF_SHOW_DELETED, vbox_settings, cb_checkbox_set_pref);
602
603 /* Show modified files check box */
604 add_checkbutton(_("Show modified deleted records (default NO)"),
605 PREF_SHOW_MODIFIED, vbox_settings, cb_checkbox_set_pref);
606
607 /* Confirm file installation */
608 add_checkbutton(
609 _("Ask confirmation for file installation (J-Pilot -> PDA) (default YES)"),
610 PREF_CONFIRM_FILE_INSTALL, vbox_settings, cb_checkbox_set_pref);
611
612 /* Show tooltips check box */
613 add_checkbutton(_("Show popup tooltips (default YES) (requires restart)"),
614 PREF_SHOW_TOOLTIPS, vbox_settings,
615 cb_checkbox_show_tooltips);
616
617 /**********************************************************************/
618 /* Datebook preference tab */
619
620 /* Radio box to choose which database to use: Datebook/Calendar */
621 group = NULL;
622 radio_button_datebook_version[0] =
623 gtk_radio_button_new_with_label(group, _("Use Datebook database (Palm OS < 5.2.1)"));
624 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_datebook_version[0]));
625 radio_button_datebook_version[1] =
626 gtk_radio_button_new_with_label(group, _("Use Calendar database (Palm OS > 5.2)"));
627 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_datebook_version[1]));
628 gtk_box_pack_start(GTK_BOX(vbox_datebook), radio_button_datebook_version[0],
629 FALSE, FALSE, 0);
630 gtk_box_pack_start(GTK_BOX(vbox_datebook), radio_button_datebook_version[1],
631 FALSE, FALSE, 0);
632
633 g_signal_connect(G_OBJECT(radio_button_datebook_version[0]), "pressed",
634 G_CALLBACK(cb_radio_set_pref),
635 GINT_TO_POINTER((PREF_DATEBOOK_VERSION << 16) | 0));
636 g_signal_connect(G_OBJECT(radio_button_datebook_version[1]), "pressed",
637 G_CALLBACK(cb_radio_set_pref),
638 GINT_TO_POINTER((PREF_DATEBOOK_VERSION << 16) | 1));
639
640 get_pref(PREF_DATEBOOK_VERSION, &ivalue, NULL);
641 if (ivalue) {
642 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_datebook_version[1]), TRUE);
643 } else {
644 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_datebook_version[0]), TRUE);
645 }
646
647 /* Separate database selection from less important options */
648 hseparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
649 gtk_box_pack_start(GTK_BOX(vbox_datebook), hseparator, FALSE, FALSE, 3);
650
651 /* Show highlight days check box */
652 add_checkbutton(_("Highlight calendar days with appointments"),
653 PREF_DATEBOOK_HIGHLIGHT_DAYS, vbox_datebook,
654 cb_checkbox_set_pref);
655
656 /* Highlight today on month and week view */
657 add_checkbutton(_("Annotate today in day, week, and month views"),
658 PREF_DATEBOOK_HI_TODAY, vbox_datebook, cb_checkbox_set_pref);
659
660 /* Show number of years on anniversaries in month and week view */
661 add_checkbutton(_("Append years on anniversaries in day, week, and month views"),
662 PREF_DATEBOOK_ANNI_YEARS, vbox_datebook,
663 cb_checkbox_set_pref);
664
665 #ifdef ENABLE_DATEBK
666 /* Show use DateBk check box */
667 add_checkbutton(_("Use DateBk note tags"),
668 PREF_USE_DB3, vbox_datebook, cb_checkbox_set_pref);
669 #else
670 checkbutton = gtk_check_button_new_with_label(_("DateBk support disabled in this build"));
671 gtk_widget_set_sensitive(checkbutton, FALSE);
672 gtk_box_pack_start(GTK_BOX(vbox_datebook), checkbutton, FALSE, FALSE, 0);
673 gtk_widget_show(checkbutton);
674 #endif
675
676 /**********************************************************************/
677 /* Address preference tab */
678
679 /* Radio box to choose which database to use: Address/Contacts */
680 group = NULL;
681 radio_button_address_version[0] =
682 gtk_radio_button_new_with_label(group, _("Use Address database (Palm OS < 5.2.1)"));
683 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_address_version[0]));
684 radio_button_address_version[1] =
685 gtk_radio_button_new_with_label(group, _("Use Contacts database (Palm OS > 5.2)"));
686 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_address_version[1]));
687 gtk_box_pack_start(GTK_BOX(vbox_address), radio_button_address_version[0],
688 FALSE, FALSE, 0);
689 gtk_box_pack_start(GTK_BOX(vbox_address), radio_button_address_version[1],
690 FALSE, FALSE, 0);
691
692 g_signal_connect(G_OBJECT(radio_button_address_version[0]), "pressed",
693 G_CALLBACK(cb_radio_set_pref),
694 GINT_TO_POINTER((PREF_ADDRESS_VERSION << 16) | 0));
695 g_signal_connect(G_OBJECT(radio_button_address_version[1]), "pressed",
696 G_CALLBACK(cb_radio_set_pref),
697 GINT_TO_POINTER((PREF_ADDRESS_VERSION << 16) | 1));
698
699 get_pref(PREF_ADDRESS_VERSION, &ivalue, NULL);
700 if (ivalue) {
701 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_address_version[1]), TRUE);
702 } else {
703 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_address_version[0]), TRUE);
704 }
705
706 /* Separate database selection from less important options */
707 hseparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
708 gtk_box_pack_start(GTK_BOX(vbox_address), hseparator, FALSE, FALSE, 3);
709
710 /* Command to use for e-mailing from address book */
711 hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
712 gtk_box_pack_start(GTK_BOX(vbox_address), hbox_temp, FALSE, FALSE, 0);
713
714 label = gtk_label_new(_("Mail Command"));
715 gtk_box_pack_start(GTK_BOX(hbox_temp), label, FALSE, FALSE, 0);
716
717 mail_command_entry = gtk_entry_new();
718 gtk_entry_set_max_length(GTK_ENTRY(mail_command_entry), MAX_PREF_LEN - 2);
719
720 get_pref(PREF_MAIL_COMMAND, NULL, &cstr);
721 if (cstr) {
722 gtk_entry_set_text(GTK_ENTRY(mail_command_entry), cstr);
723 }
724 g_signal_connect(G_OBJECT(mail_command_entry),
725 "changed", G_CALLBACK(cb_text_entry),
726 GINT_TO_POINTER(PREF_MAIL_COMMAND));
727 gtk_box_pack_start(GTK_BOX(hbox_temp), mail_command_entry, TRUE, TRUE, 1);
728
729 label = gtk_label_new(_("%s is replaced by the e-mail address"));
730 gtk_box_pack_start(GTK_BOX(vbox_address), label, FALSE, FALSE, 0);
731 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
732
733 /**********************************************************************/
734 /* ToDo preference tab */
735
736 /* FIXME: undef when support for Task has been coded */
737 #if 0
738 /* Radio box to choose which database to use: Todo/Task */
739 group = NULL;
740 radio_button_task_version[0] =
741 gtk_radio_button_new_with_label(group, _("Use ToDo database (Palm OS < 5.2.1)"));
742 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_todo_version[0]));
743 radio_button_todo_version[1] =
744 gtk_radio_button_new_with_label(group, _("Use Task database (Palm OS > 5.2)"));
745 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_todo_version[1]));
746 gtk_box_pack_start(GTK_BOX(vbox_todo), radio_button_todo_version[0],
747 FALSE, FALSE, 0);
748 gtk_box_pack_start(GTK_BOX(vbox_todo), radio_button_todo_version[1],
749 FALSE, FALSE, 0);
750
751 g_signal_connect(G_OBJECT(radio_button_todo_version[0]), "pressed",
752 G_CALLBACK(cb_radio_set_pref),
753 GINT_TO_POINTER((PREF_TODO_VERSION<<16)|0));
754 g_signal_connect(G_OBJECT(radio_button_todo_version[1]), "pressed",
755 G_CALLBACK(cb_radio_set_pref),
756 GINT_TO_POINTER((PREF_TODO_VERSION<<16)|1));
757
758 get_pref(PREF_TODO_VERSION, &ivalue, NULL);
759 if (ivalue) {
760 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_todo_version[1]), TRUE);
761 } else {
762 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_todo_version[0]), TRUE);
763 }
764
765 /* Separate database selection from less important options */
766 hseparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
767 gtk_box_pack_start(GTK_BOX(vbox_todo), hseparator, FALSE, FALSE, 3);
768 #endif
769
770 /* hide completed check box */
771 add_checkbutton(_("Hide Completed ToDos"),
772 PREF_TODO_HIDE_COMPLETED, vbox_todo, cb_checkbox_set_pref);
773
774 /* hide todos not yet due check box */
775 add_checkbutton(_("Hide ToDos not yet due"),
776 PREF_TODO_HIDE_NOT_DUE, vbox_todo, cb_checkbox_set_pref);
777
778 /* record todo completion date check box */
779 add_checkbutton(_("Record Completion Date"),
780 PREF_TODO_COMPLETION_DATE, vbox_todo, cb_checkbox_set_pref);
781
782 #ifdef ENABLE_MANANA
783 /* Use Manana check box */
784 add_checkbutton(_("Use Manana database"),
785 PREF_MANANA_MODE, vbox_todo, cb_checkbox_set_pref);
786 #endif
787
788 /* Default Number of Days Due for ToDos */
789 hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
790 gtk_box_pack_start(GTK_BOX(vbox_todo), hbox_temp, FALSE, FALSE, 0);
791
792 add_checkbutton(_("Use default number of days due"),
793 PREF_TODO_DAYS_DUE, hbox_temp, cb_checkbox_set_pref);
794
795 todo_days_due_entry = gtk_entry_new();
796 gtk_entry_set_max_length(GTK_ENTRY(todo_days_due_entry), MAX_PREF_LEN - 2);
797 entry_set_multiline_truncate(GTK_ENTRY(todo_days_due_entry), TRUE);
798 get_pref(PREF_TODO_DAYS_TILL_DUE, &ivalue, NULL);
799 temp[0] = '\0';
800 g_snprintf(temp, sizeof(temp), "%ld", ivalue);
801 gtk_entry_set_text(GTK_ENTRY(todo_days_due_entry), temp);
802 gtk_box_pack_start(GTK_BOX(hbox_temp), todo_days_due_entry, FALSE, FALSE, 0);
803
804 g_signal_connect(G_OBJECT(todo_days_due_entry),
805 "changed", G_CALLBACK(cb_checkbox_todo_days_till_due),
806 NULL);
807
808 gtk_widget_show_all(hbox_temp);
809
810 /**********************************************************************/
811 /* Memo preference tab */
812 /* Radio box to choose which database to use: Memo/Memos/Memo32 */
813 group = NULL;
814 radio_button_memo_version[0] =
815 gtk_radio_button_new_with_label(group, _("Use Memo database (Palm OS < 5.2.1)"));
816 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_memo_version[0]));
817 radio_button_memo_version[1] =
818 gtk_radio_button_new_with_label(group, _("Use Memos database (Palm OS > 5.2)"));
819 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_memo_version[1]));
820 radio_button_memo_version[2] =
821 gtk_radio_button_new_with_label(group, _("Use Memo32 database (pedit32)"));
822 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button_memo_version[2]));
823 gtk_box_pack_start(GTK_BOX(vbox_memo), radio_button_memo_version[0],
824 FALSE, FALSE, 0);
825 gtk_box_pack_start(GTK_BOX(vbox_memo), radio_button_memo_version[1],
826 FALSE, FALSE, 0);
827 gtk_box_pack_start(GTK_BOX(vbox_memo), radio_button_memo_version[2],
828 FALSE, FALSE, 0);
829
830 g_signal_connect(G_OBJECT(radio_button_memo_version[0]), "pressed",
831 G_CALLBACK(cb_radio_set_pref),
832 GINT_TO_POINTER((PREF_MEMO_VERSION << 16) | 0));
833 g_signal_connect(G_OBJECT(radio_button_memo_version[1]), "pressed",
834 G_CALLBACK(cb_radio_set_pref),
835 GINT_TO_POINTER((PREF_MEMO_VERSION << 16) | 1));
836 g_signal_connect(G_OBJECT(radio_button_memo_version[2]), "pressed",
837 G_CALLBACK(cb_radio_set_pref),
838 GINT_TO_POINTER((PREF_MEMO_VERSION << 16) | 2));
839
840 get_pref(PREF_MEMO_VERSION, &ivalue, NULL);
841 switch (ivalue) {
842 case 0:
843 default:
844 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_memo_version[0]), TRUE);
845 break;
846 case 1:
847 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_memo_version[1]), TRUE);
848 break;
849 case 2:
850 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_memo_version[2]), TRUE);
851 break;
852 }
853
854 hseparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
855 gtk_box_pack_start(GTK_BOX(vbox_memo), hseparator, FALSE, FALSE, 3);
856
857 /* External Editor Command to execute */
858 hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
859 gtk_box_pack_start(GTK_BOX(vbox_memo), hbox_temp, FALSE, FALSE, 0);
860
861 label = gtk_label_new(_("External Editor"));
862 gtk_box_pack_start(GTK_BOX(hbox_temp), label, FALSE, FALSE, 0);
863
864 ext_editor_entry = gtk_entry_new();
865 gtk_entry_set_max_length(GTK_ENTRY(ext_editor_entry), MAX_PREF_LEN - 2);
866 get_pref(PREF_EXTERNAL_EDITOR, NULL, &cstr);
867 if (cstr) {
868 gtk_entry_set_text(GTK_ENTRY(ext_editor_entry), cstr);
869 }
870 g_signal_connect(G_OBJECT(ext_editor_entry),
871 "changed", G_CALLBACK(cb_text_entry),
872 GINT_TO_POINTER(PREF_EXTERNAL_EDITOR));
873 gtk_box_pack_start(GTK_BOX(hbox_temp), ext_editor_entry, TRUE, TRUE, 1);
874
875 label = gtk_label_new(_("Use Ctrl-E inside a memo to launch external editor for memo text"));
876 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
877 gtk_box_pack_start(GTK_BOX(vbox_memo), label, FALSE, FALSE, 0);
878
879 /**********************************************************************/
880 /* Alarms preference tab */
881
882 /* Open alarm windows check box */
883 add_checkbutton(_("Open alarm windows for appointment reminders"),
884 PREF_OPEN_ALARM_WINDOWS, vbox_alarms, cb_checkbox_set_pref);
885
886 /* Execute alarm command check box */
887 add_checkbutton(_("Execute this command"),
888 PREF_DO_ALARM_COMMAND, vbox_alarms, cb_checkbox_set_pref);
889
890 /* Shell warning label */
891 label = gtk_label_new(_("WARNING: executing arbitrary shell commands can be dangerous!!!"));
892 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
893 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
894
895 /* Alarm Command to execute */
896 hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
897 gtk_box_pack_start(GTK_BOX(vbox_alarms), hbox_temp, FALSE, FALSE, 0);
898
899 label = gtk_label_new(_("Alarm Command"));
900 gtk_box_pack_start(GTK_BOX(hbox_temp), label, FALSE, FALSE, 10);
901
902 alarm_command_entry = gtk_entry_new();
903 gtk_entry_set_max_length(GTK_ENTRY(alarm_command_entry), MAX_PREF_LEN - 2);
904 get_pref(PREF_ALARM_COMMAND, NULL, &cstr);
905 if (cstr) {
906 gtk_entry_set_text(GTK_ENTRY(alarm_command_entry), cstr);
907 }
908 g_signal_connect(G_OBJECT(alarm_command_entry),
909 "changed", G_CALLBACK(cb_text_entry),
910 GINT_TO_POINTER(PREF_ALARM_COMMAND));
911 gtk_box_pack_start(GTK_BOX(hbox_temp), alarm_command_entry, FALSE, FALSE, 0);
912
913 label = gtk_label_new(_("%t is replaced with the alarm time"));
914 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
915 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
916
917 label = gtk_label_new(_("%d is replaced with the alarm date"));
918 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
919 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
920
921 #ifdef ENABLE_ALARM_SHELL_DANGER
922 label = gtk_label_new(_("%D is replaced with the alarm description"));
923 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
924 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
925
926 label = gtk_label_new(_("%N is replaced with the alarm note"));
927 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
928 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
929 #else
930 label = gtk_label_new(_("%D (description substitution) is disabled in this build"));
931 gtk_widget_set_sensitive(label, FALSE);
932 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
933 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
934
935 label = gtk_label_new(_("%N (note substitution) is disabled in this build"));
936 gtk_widget_set_sensitive(label, FALSE);
937 gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
938 gtk_box_pack_start(GTK_BOX(vbox_alarms), label, FALSE, FALSE, 0);
939 #endif
940
941 /**********************************************************************/
942 /* Conduits preference tab */
943
944 /* Sync datebook check box */
945 add_checkbutton(_("Sync datebook"),
946 PREF_SYNC_DATEBOOK, vbox_conduits, cb_checkbox_set_pref);
947
948 /* Sync address check box */
949 add_checkbutton(_("Sync address"),
950 PREF_SYNC_ADDRESS, vbox_conduits, cb_checkbox_set_pref);
951
952 /* Sync todo check box */
953 add_checkbutton(_("Sync todo"),
954 PREF_SYNC_TODO, vbox_conduits, cb_checkbox_set_pref);
955
956 /* Sync memo check box */
957 add_checkbutton(_("Sync memo"),
958 PREF_SYNC_MEMO, vbox_conduits, cb_checkbox_set_pref);
959
960 #ifdef ENABLE_MANANA
961 /* Show sync Manana check box */
962 add_checkbutton(_("Sync Manana"),
963 PREF_SYNC_MANANA, vbox_conduits, cb_checkbox_set_pref);
964 #endif
965 get_pref(PREF_CHAR_SET, &ivalue, NULL);
966 if (ivalue == CHAR_SET_JAPANESE || ivalue == CHAR_SET_SJIS_UTF) {
967 /* Show use Japanese Kana extention check box */
968 add_checkbutton(_("Use J-OS (Not Japanese PalmOS:WorkPad/CLIE)"),
969 PREF_USE_JOS, vbox_settings, cb_checkbox_set_pref);
970 }
971
972 #ifdef ENABLE_PLUGINS
973 if (!skip_plugins) {
974 plugin_list = NULL;
975 plugin_list = get_plugin_list();
976
977 for (temp_list = plugin_list; temp_list; temp_list = temp_list->next) {
978 Pplugin = (struct plugin_s *) temp_list->data;
979 if (Pplugin) {
980 /* Make a Sync checkbox for each plugin */
981 g_snprintf(temp, sizeof(temp), _("Sync %s (%s)"), Pplugin->name, Pplugin->full_path);
982 checkbutton = gtk_check_button_new_with_label(temp);
983 gtk_box_pack_start(GTK_BOX(vbox_conduits), checkbutton, FALSE, FALSE, 0);
984 gtk_widget_show(checkbutton);
985 if (Pplugin->sync_on) {
986 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
987 }
988 g_signal_connect(G_OBJECT(checkbutton), "clicked",
989 G_CALLBACK(cb_sync_plugin),
990 GINT_TO_POINTER(Pplugin->number));
991 }
992 }
993 }
994
995 #endif
996
997 /* Done button */
998 hbox_temp = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
999 gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox_temp), GTK_BUTTONBOX_END);
1000 gtk_box_pack_start(GTK_BOX(vbox), hbox_temp, FALSE, FALSE, 1);
1001
1002 button = gtk_button_new_with_label("OK");
1003 g_signal_connect(G_OBJECT(button), "clicked",
1004 G_CALLBACK(cb_quit), window);
1005 gtk_box_pack_end(GTK_BOX(hbox_temp), button, FALSE, FALSE, 0);
1006
1007 gtk_widget_show_all(window);
1008 }
1009