66 #include <glib/gi18n.h> 68 #include "dialog-utils.h" 70 #include "gnc-date-edit.h" 78 #include <gnc-session.h> 79 #include "gnc-component-manager.h" 81 #include "dialog-doclink-utils.h" 83 #define DIALOG_PREFERENCES_CM_CLASS "dialog-newpreferences" 84 #define GNC_PREFS_GROUP "dialogs.preferences" 85 #define PREF_PREFIX_LEN sizeof("pref/") - 1 86 #define PREFS_WIDGET_HASH "prefs_widget_hash" 87 #define NOTEBOOK "notebook" 90 static QofLogModule log_module = GNC_MOD_PREFS;
95 gboolean gnc_preferences_delete_event_cb (GtkWidget *widget,
101 typedef struct addition_t
123 static gchar *gnc_account_separator_is_valid (
const gchar *separator,
124 gchar **normalized_separator)
127 GList *conflict_accts = NULL;
128 gchar *message = NULL;
130 if (!gnc_current_session_exist())
133 book = gnc_get_current_book ();
134 *normalized_separator = gnc_normalize_account_separator (separator);
140 g_list_free_full (conflict_accts, g_free);
157 GtkWidget *label, *image;
159 gchar *separator = NULL;
161 gchar *conflict_msg = gnc_account_separator_is_valid (gtk_entry_get_text (entry), &separator);
163 label = g_object_get_data (G_OBJECT(dialog),
"sample_account");
164 DEBUG(
"Sample Account pointer is %p", label);
171 sample = g_strdup_printf (_(
"Income%sSalary%sTaxable"),
172 separator, separator);
173 PINFO(
" Label set to '%s'", sample);
174 gtk_label_set_text (GTK_LABEL(label), sample);
178 image = g_object_get_data (G_OBJECT(dialog),
"separator_error");
179 DEBUG(
"Separator Error Image pointer is %p", image);
183 gtk_widget_set_tooltip_text (GTK_WIDGET(image), conflict_msg);
184 gtk_widget_show (GTK_WIDGET(image));
185 g_free (conflict_msg);
188 gtk_widget_hide (GTK_WIDGET(image));
204 gnc_account_separator_validate (GtkWidget *dialog)
206 GtkWidget *entry = g_object_get_data (G_OBJECT(dialog),
"account-separator");
208 gchar *separator = NULL;
209 gchar *conflict_msg = gnc_account_separator_is_valid (gtk_entry_get_text (GTK_ENTRY(entry)), &separator);
214 GtkWidget *msg_dialog, *msg_label;
218 builder = gtk_builder_new ();
219 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"separator_validation_dialog");
221 msg_dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"separator_validation_dialog"));
223 msg_label = GTK_WIDGET(gtk_builder_get_object (builder,
"conflict_message"));
225 gtk_label_set_text (GTK_LABEL(msg_label), conflict_msg);
227 g_object_unref (G_OBJECT(builder));
228 gtk_widget_show_all (msg_dialog);
230 response = gtk_dialog_run (GTK_DIALOG(msg_dialog));
231 if (response == GTK_RESPONSE_ACCEPT)
233 gchar *original_sep = g_object_get_data (G_OBJECT(entry),
"original_text");
235 if (original_sep != NULL)
236 gtk_entry_set_text (GTK_ENTRY(entry), original_sep);
241 g_free (conflict_msg);
242 gtk_widget_destroy (msg_dialog);
258 gnc_preferences_select_account_page (GtkDialog *dialog)
260 GtkWidget *notebook = g_object_get_data (G_OBJECT(dialog), NOTEBOOK);
261 GList *children = gtk_container_get_children (GTK_CONTAINER(notebook));
265 GtkWidget *acc_page = NULL;
268 for (node = children; node; node = node->next)
270 if (g_strcmp0 (gtk_widget_get_name (GTK_WIDGET(node->data)),
"accounts_page") == 0)
271 acc_page = node->data;
275 gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook),
276 gtk_notebook_page_num (GTK_NOTEBOOK(notebook),
279 g_list_free (children);
291 GtkWidget *spinner = g_object_get_data (G_OBJECT(dialog),
292 "save_on_close_wait_time");
293 gtk_widget_set_sensitive (spinner, gtk_toggle_button_get_active (button));
308 gnc_prefs_compare_addins (
addition *a,
311 return g_utf8_collate (a->tabname, b->
tabname);
335 gnc_preferences_add_page_internal (
const gchar *filename,
336 const gchar *widgetname,
337 const gchar *tabname,
341 gboolean error = FALSE;
344 ENTER(
"file %s, widget %s, tab %s full page %d",
345 filename, widgetname, tabname, full_page);
347 add_in = g_malloc (
sizeof(
addition));
350 g_critical (
"Unable to allocate memory.\n");
355 add_in->
filename = g_strdup (filename);
357 add_in->
tabname = g_strdup (tabname);
361 g_critical (
"Unable to allocate memory.\n");
370 ptr = g_slist_find_custom (
add_ins, add_in, (GCompareFunc)gnc_prefs_compare_addins);
374 preexisting = ptr->data;
378 g_warning (
"New tab %s(%s/%s/%s) conflicts with existing tab %s(%s/%s/full)",
386 g_warning (
"New tab %s(%s/%s/%s) conflicts with existing tab %s(%s/%s/partial)",
419 const gchar *widgetname,
420 const gchar *tabname)
422 gnc_preferences_add_page_internal (filename, widgetname, tabname, TRUE);
434 const gchar *widgetname,
435 const gchar *tabname)
437 gnc_preferences_add_page_internal (filename, widgetname, tabname, FALSE);
457 gnc_prefs_build_widget_table (GtkBuilder *builder,
460 GHashTable *prefs_table;
461 GSList *interesting, *runner;
466 prefs_table = g_object_get_data (G_OBJECT(dialog), PREFS_WIDGET_HASH);
468 interesting = gtk_builder_get_objects (builder);
470 for (runner = interesting; runner; runner = g_slist_next(runner))
472 widget = runner->data;
473 if (GTK_IS_WIDGET(widget))
475 wname = gtk_widget_get_name (widget);
476 name = gtk_buildable_get_name (GTK_BUILDABLE(widget));
477 DEBUG(
"Widget type is %s and buildable get name is %s", wname, name);
478 if (g_str_has_prefix (name,
"pref"))
479 g_hash_table_insert (prefs_table, (gchar *)name, widget);
482 g_slist_free (interesting);
504 gnc_prefs_find_page (GtkNotebook *notebook,
const gchar *name)
508 const gchar *child_name;
510 g_return_val_if_fail (GTK_IS_NOTEBOOK(notebook), NULL);
511 g_return_val_if_fail (name, NULL);
515 n_pages = gtk_notebook_get_n_pages (notebook);
517 for (i = 0; i < n_pages; i++)
519 child = gtk_notebook_get_nth_page (notebook, i);
520 g_return_val_if_fail (child, NULL);
522 child_name = gtk_notebook_get_tab_label_text (notebook, child);
523 g_return_val_if_fail (child_name, NULL);
525 if (g_utf8_collate (name, child_name) == 0)
527 LEAVE(
"found at index: %d", i);
549 gnc_prefs_get_grid_size (GtkWidget *child, gpointer data)
552 gint top, left, height, width;
554 gtk_container_child_get (GTK_CONTAINER(copydata->
grid_to), child,
555 "left-attach", &left,
561 if (left + width >= copydata->
cols)
562 copydata->
cols = left + width;
564 if (top + height >= copydata->rows)
565 copydata->rows = top + height;
582 gnc_prefs_move_grid_entry (GtkWidget *child,
586 gint top, left, height, width;
587 gboolean hexpand, vexpand;
588 GtkAlign halign, valign;
589 gint topm, bottomm, leftm, rightm;
591 ENTER(
"child %p, copy data %p", child, data);
592 gtk_container_child_get (GTK_CONTAINER(copydata->
grid_from), child,
593 "left-attach", &left,
598 hexpand = gtk_widget_get_hexpand (child);
599 vexpand = gtk_widget_get_vexpand (child);
600 halign = gtk_widget_get_halign (child);
601 valign = gtk_widget_get_valign (child);
603 g_object_get (child,
"margin-top", &topm,
"margin-bottom", &bottomm, NULL);
604 g_object_get (child,
"margin-left", &leftm,
"margin-right", &rightm, NULL);
606 g_object_ref (child);
607 gtk_container_remove (GTK_CONTAINER(copydata->
grid_from), child);
609 gtk_grid_attach (copydata->
grid_to, child, left, copydata->rows + top , width, height);
611 gtk_widget_set_hexpand (child, hexpand);
612 gtk_widget_set_vexpand (child, vexpand);
613 gtk_widget_set_halign (child, halign);
614 gtk_widget_set_valign (child, valign);
616 g_object_set (child,
"margin-left", leftm,
"margin-right", rightm, NULL);
617 g_object_set (child,
"margin-top", topm,
"margin-bottom", bottomm, NULL);
619 g_object_unref (child);
636 gnc_preferences_build_page (gpointer data,
640 GtkWidget *dialog, *existing_content, *new_content, *label;
641 GtkNotebook *notebook;
643 struct copy_data copydata = {NULL, NULL, 0, 0};
647 ENTER(
"add_in %p, dialog %p", data, user_data);
652 builder = gtk_builder_new ();
655 widgetname = g_strsplit (add_in->
widgetname,
",", -1);
657 for (i = 0; widgetname[i]; i++)
659 DEBUG(
"Opening %s to get content %s", add_in->
filename, widgetname[i]);
660 gnc_builder_add_from_file (builder, add_in->
filename, widgetname[i]);
663 DEBUG(
"Widget Content is %s", widgetname[i - 1]);
664 new_content = GTK_WIDGET(gtk_builder_get_object (builder, widgetname[i - 1]));
666 g_strfreev (widgetname);
670 gnc_prefs_build_widget_table (builder, dialog);
675 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);
678 notebook = g_object_get_data (G_OBJECT(dialog), NOTEBOOK);
682 label = gtk_label_new (add_in->
tabname);
683 gnc_label_set_alignment (label, 0.0, 0.5);
684 gtk_notebook_append_page (notebook, new_content, label);
685 g_object_unref (G_OBJECT(builder));
686 LEAVE(
"appended page");
691 if (!GTK_IS_GRID(new_content))
693 g_critical (
"The object name %s in file %s is not a GtkGrid. It cannot " 694 "be added to the preferences dialog.",
696 g_object_unref (G_OBJECT(builder));
702 existing_content = gnc_prefs_find_page (notebook, add_in->
tabname);
704 if (!existing_content)
707 existing_content = gtk_grid_new ();
708 gtk_container_set_border_width (GTK_CONTAINER(existing_content), 6);
709 label = gtk_label_new (add_in->
tabname);
710 gnc_label_set_alignment (label, 0.0, 0.5);
711 gtk_notebook_append_page (notebook, existing_content, label);
712 gtk_widget_show_all (existing_content);
713 DEBUG(
"created new page %s, appended it", add_in->
tabname);
718 copydata.
grid_to = GTK_GRID(existing_content);
719 gtk_container_foreach (GTK_CONTAINER(existing_content), gnc_prefs_get_grid_size, ©data);
721 DEBUG(
"found existing page %s, grid size is %d x %d", add_in->
tabname, copydata.rows, copydata.
cols);
725 if (copydata.rows > 0)
727 label = gtk_label_new (
"");
728 gtk_widget_show (label);
729 gtk_grid_attach (GTK_GRID(existing_content), label, 0, copydata.rows, 1, 1);
730 copydata.rows = copydata.rows + 1;
732 DEBUG(
"add spacer row");
736 copydata.
grid_from = GTK_GRID(new_content);
737 copydata.
grid_to = GTK_GRID(existing_content);
738 gtk_container_foreach (GTK_CONTAINER(new_content), gnc_prefs_move_grid_entry, ©data);
740 g_object_ref_sink (new_content);
741 g_object_unref (G_OBJECT(builder));
743 LEAVE(
"added content to page");
748 tab_cmp (GtkWidget *page_a, GtkWidget *page_b, GtkNotebook *notebook)
750 return g_utf8_collate (gtk_notebook_get_tab_label_text (notebook, page_a),
751 gtk_notebook_get_tab_label_text (notebook, page_b));
756 gnc_prefs_sort_pages (GtkNotebook *notebook)
759 GList *tabs = NULL, *iter = NULL;
761 g_return_if_fail (GTK_IS_NOTEBOOK(notebook));
764 n_pages = gtk_notebook_get_n_pages (notebook);
765 for (i = n_pages - 1; i >= 0; i--)
766 tabs = g_list_prepend (tabs, gtk_notebook_get_nth_page (notebook, i));
769 tabs = g_list_sort_with_data (tabs, (GCompareDataFunc) tab_cmp, notebook);
772 for (i = 0, iter = tabs; iter; i++, iter = iter->next)
773 gtk_notebook_reorder_child (notebook, GTK_WIDGET(iter->data), i);
784 gnc_prefs_split_widget_name (
const gchar *name, gchar **group, gchar **pref)
786 const gchar *group_with_pref = name + PREF_PREFIX_LEN;
787 gchar **splits = g_strsplit (group_with_pref,
"/", 0);
789 *group = g_strdup (splits[0]);
790 *pref = g_strdup (splits[1]);
803 gnc_prefs_connect_font_button (GtkFontButton *fb)
807 g_return_if_fail (GTK_IS_FONT_BUTTON(fb));
809 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(fb)), &group, &pref);
815 gtk_widget_show_all (GTK_WIDGET(fb));
827 file_chooser_selected_cb (GtkFileChooser *fc, gpointer user_data)
829 GtkImage *image = g_object_get_data (G_OBJECT(fc),
"path_head_error");
830 const gchar *group = g_object_get_data (G_OBJECT(fc),
"group");
831 const gchar *pref = g_object_get_data (G_OBJECT(fc),
"pref");
832 gchar *folder_uri = gtk_file_chooser_get_uri (fc);
833 gchar *old_path_head_uri = gnc_doclink_get_path_head ();
836 if (!g_str_has_suffix (folder_uri,
"/"))
838 gchar *folder_with_slash = g_strconcat (folder_uri,
"/", NULL);
840 folder_uri = g_strdup (folder_with_slash);
841 g_free (folder_with_slash);
844 gtk_widget_hide (GTK_WIDGET(image));
847 PINFO(
"Failed to save preference at %s, %s with %s", group, pref, folder_uri);
849 gnc_doclink_pref_path_head_changed (
850 GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(fc))),
853 g_free (old_path_head_uri);
866 gnc_prefs_connect_file_chooser_button (GtkFileChooserButton *fcb,
const gchar *boxname)
871 gboolean folder_set = TRUE;
873 g_return_if_fail (GTK_FILE_CHOOSER_BUTTON(fcb));
876 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(fcb)), &group, &pref);
878 gnc_prefs_split_widget_name (boxname, &group, &pref);
882 PINFO(
"Uri is %s", uri);
886 gchar *path_head = g_filename_from_uri (uri, NULL, NULL);
889 if (g_file_test (path_head, G_FILE_TEST_IS_DIR))
890 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER(fcb), uri);
897 image = g_object_get_data (G_OBJECT(fcb),
"path_head_error");
900 gtk_widget_hide (GTK_WIDGET(image));
903 gchar *path_head = gnc_doclink_get_unescape_uri (NULL, uri,
"file");
904 gchar *ttip = g_strconcat (_(
"Path does not exist, "), path_head, NULL);
906 gtk_widget_set_tooltip_text (GTK_WIDGET(image), ttip);
907 gtk_widget_show (GTK_WIDGET(image));
913 g_signal_connect (GTK_FILE_CHOOSER(fcb),
"selection-changed",
914 G_CALLBACK(file_chooser_selected_cb), NULL);
916 g_object_set_data_full (G_OBJECT(fcb),
"group", g_strdup (group), (GDestroyNotify) g_free);
917 g_object_set_data_full (G_OBJECT(fcb),
"pref", g_strdup (pref), (GDestroyNotify) g_free);
923 gtk_widget_show_all (GTK_WIDGET(fcb));
935 file_chooser_clear_cb (GtkButton *button, gpointer user_data)
937 GtkFileChooserButton *fcb = GTK_FILE_CHOOSER_BUTTON(user_data);
938 const gchar *group = g_object_get_data (G_OBJECT(fcb),
"group");
939 const gchar *pref = g_object_get_data (G_OBJECT(fcb),
"pref");
940 GtkImage *image = g_object_get_data (G_OBJECT(fcb),
"path_head_error");
944 gchar *old_path_head_uri = gnc_doclink_get_path_head ();
948 box = gtk_widget_get_parent (GTK_WIDGET(fcb));
949 g_signal_handlers_disconnect_by_func (button, file_chooser_clear_cb, fcb);
952 PINFO(
"Failed to Clear preference at %s, %s", group, pref);
954 gnc_doclink_pref_path_head_changed (
955 GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(fcb))),
958 gtk_widget_destroy (GTK_WIDGET(fcb));
960 fcb_new = gtk_file_chooser_button_new (_(
"Select a folder"),
961 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
963 g_object_set_data (G_OBJECT(fcb_new),
"path_head_error", image);
964 g_object_set_data_full (G_OBJECT(fcb_new),
"group", g_strdup (group), (GDestroyNotify) g_free);
965 g_object_set_data_full (G_OBJECT(fcb_new),
"pref", g_strdup (pref), (GDestroyNotify) g_free);
967 gtk_box_pack_start (GTK_BOX(box), fcb_new, TRUE, TRUE, 0);
968 gtk_box_reorder_child (GTK_BOX(box), fcb_new, 0);
969 gtk_widget_show (fcb_new);
971 g_signal_connect (GTK_BUTTON(button),
"clicked",
972 G_CALLBACK(file_chooser_clear_cb), fcb_new);
974 boxname = g_strconcat (
"pref/", group,
"/", pref, NULL);
976 gnc_prefs_connect_file_chooser_button (GTK_FILE_CHOOSER_BUTTON(fcb_new), boxname);
978 g_free (old_path_head_uri);
991 gnc_prefs_connect_radio_button (GtkRadioButton *button)
995 g_return_if_fail (GTK_IS_RADIO_BUTTON(button));
997 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(button)), &group, &pref);
1015 gnc_prefs_connect_check_button (GtkCheckButton *button)
1017 gchar *group, *pref;
1019 g_return_if_fail (GTK_IS_CHECK_BUTTON(button));
1021 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(button)), &group, &pref);
1039 gnc_prefs_connect_spin_button (GtkSpinButton *spin)
1041 gchar *group, *pref;
1043 g_return_if_fail (GTK_IS_SPIN_BUTTON(spin));
1045 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(spin)), &group, &pref);
1062 gnc_prefs_connect_combo_box (GtkComboBox *box)
1064 gchar *group, *pref;
1066 g_return_if_fail (GTK_IS_COMBO_BOX(box));
1068 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(box)), &group, &pref);
1085 gnc_prefs_connect_currency_edit (GNCCurrencyEdit *gce,
const gchar *boxname )
1087 gchar *group, *pref;
1089 g_return_if_fail (GNC_IS_CURRENCY_EDIT(gce));
1091 gnc_prefs_split_widget_name (boxname, &group, &pref);
1098 gtk_widget_show_all (GTK_WIDGET(gce));
1110 gnc_prefs_connect_entry (GtkEntry *entry)
1112 gchar *group, *pref;
1114 g_return_if_fail (GTK_IS_ENTRY(entry));
1116 gnc_prefs_split_widget_name (gtk_buildable_get_name (GTK_BUILDABLE(entry)), &group, &pref);
1133 gnc_prefs_connect_period_select (GncPeriodSelect *period,
const gchar *boxname )
1135 gchar *group, *pref;
1137 g_return_if_fail (GNC_IS_PERIOD_SELECT(period));
1139 gnc_prefs_split_widget_name (boxname, &group, &pref);
1156 gnc_prefs_connect_date_edit (
GNCDateEdit *gde ,
const gchar *boxname )
1158 gchar *group, *pref;
1160 g_return_if_fail (GNC_IS_DATE_EDIT(gde));
1162 gnc_prefs_split_widget_name (boxname, &group, &pref);
1178 gnc_preferences_delete_event_cb (GtkWidget *widget,
1204 case GTK_RESPONSE_HELP:
1208 case GTK_RESPONSE_DELETE_EVENT:
1210 if (gnc_account_separator_validate (GTK_WIDGET(dialog)))
1212 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(dialog));
1213 gnc_unregister_gui_component_by_data (DIALOG_PREFERENCES_CM_CLASS,
1215 gtk_widget_destroy (GTK_WIDGET(dialog));
1218 gnc_preferences_select_account_page (dialog);
1240 gnc_prefs_connect_one (
const gchar *name,
1247 if (GTK_IS_FONT_BUTTON(widget))
1249 DEBUG(
" %s - font button", name);
1250 gnc_prefs_connect_font_button (GTK_FONT_BUTTON(widget));
1252 else if (GTK_IS_FILE_CHOOSER_BUTTON(widget))
1254 DEBUG(
" %s - file chooser button", name);
1255 gnc_prefs_connect_file_chooser_button (GTK_FILE_CHOOSER_BUTTON(widget), NULL);
1257 else if (GTK_IS_RADIO_BUTTON(widget))
1259 DEBUG(
" %s - radio button", name);
1260 gnc_prefs_connect_radio_button (GTK_RADIO_BUTTON(widget));
1262 else if (GTK_IS_CHECK_BUTTON(widget))
1264 DEBUG(
" %s - check button", name);
1265 gnc_prefs_connect_check_button (GTK_CHECK_BUTTON(widget));
1267 else if (GTK_IS_SPIN_BUTTON(widget))
1269 DEBUG(
" %s - spin button", name);
1270 gnc_prefs_connect_spin_button (GTK_SPIN_BUTTON(widget));
1272 else if (GTK_IS_COMBO_BOX(widget))
1274 DEBUG(
" %s - combo box", name);
1275 gnc_prefs_connect_combo_box (GTK_COMBO_BOX(widget));
1277 else if (GTK_IS_ENTRY(widget))
1279 DEBUG(
" %s - entry", name);
1280 gnc_prefs_connect_entry (GTK_ENTRY(widget));
1282 else if (GTK_IS_BOX(widget))
1285 GtkWidget *widget_child;
1286 GList* child = gtk_container_get_children (GTK_CONTAINER(widget));
1287 widget_child = child->data;
1288 g_list_free (child);
1289 DEBUG(
" %s - box", name);
1290 DEBUG(
"Box widget type is %s and name is %s", gtk_widget_get_name (GTK_WIDGET(widget_child)), name);
1291 if (GNC_IS_CURRENCY_EDIT(widget_child))
1293 DEBUG(
" %s - currency_edit", name);
1294 gnc_prefs_connect_currency_edit (GNC_CURRENCY_EDIT(widget_child), name );
1296 else if (GNC_IS_PERIOD_SELECT(widget_child))
1298 DEBUG(
" %s - period_select", name);
1299 gnc_prefs_connect_period_select (GNC_PERIOD_SELECT(widget_child), name );
1301 else if (GNC_IS_DATE_EDIT(widget_child))
1303 DEBUG(
" %s - date_edit", name);
1304 gnc_prefs_connect_date_edit (GNC_DATE_EDIT(widget_child), name );
1306 else if (GTK_FILE_CHOOSER_BUTTON(widget_child))
1308 DEBUG(
" %s - file chooser button", name);
1309 gnc_prefs_connect_file_chooser_button (GTK_FILE_CHOOSER_BUTTON(widget_child), name );
1314 DEBUG(
" %s - unsupported %s", name,
1315 G_OBJECT_TYPE_NAME(G_OBJECT(widget)));
1332 gnc_preferences_dialog_create (GtkWindow *parent)
1334 GtkBuilder *builder;
1335 GtkWidget *dialog, *notebook, *label, *image, *spinner, *entry;
1336 GtkWidget *box, *date, *period, *currency, *fcb, *button;
1337 GHashTable *prefs_table;
1338 GDate* gdate = NULL;
1340 GtkListStore *store;
1343 gnc_commodity *locale_currency;
1344 const gchar *currency_name;
1346 gboolean date_is_valid = FALSE;
1349 DEBUG(
"Opening dialog-preferences.glade:");
1350 builder = gtk_builder_new ();
1352 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"auto_decimal_places_adj");
1353 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"autosave_interval_minutes_adj");
1354 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"save_on_close_adj");
1355 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"date_backmonth_adj");
1356 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"default_zoom_adj");
1357 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"max_transactions_adj");
1358 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"key_length_adj");
1359 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"new_search_limit_adj");
1360 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"retain_days_adj");
1361 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"tab_width_adj");
1362 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"date_formats");
1363 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"atm_fee_adj");
1364 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"auto_add_adj");
1365 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"auto_clear_adj");
1366 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"match_adj");
1367 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"likely_day_threshold");
1368 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"unlikely_day_threshold");
1369 gnc_builder_add_from_file (builder,
"dialog-preferences.glade",
"gnucash_preferences_dialog");
1371 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"gnucash_preferences_dialog"));
1374 gtk_widget_set_name (GTK_WIDGET(dialog),
"gnc-id-preferences");
1377 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(parent));
1379 label = GTK_WIDGET(gtk_builder_get_object (builder,
"sample_account"));
1380 g_object_set_data (G_OBJECT(dialog),
"sample_account", label);
1382 image = GTK_WIDGET(gtk_builder_get_object (builder,
"separator_error"));
1383 g_object_set_data (G_OBJECT(dialog),
"separator_error", image);
1385 entry = GTK_WIDGET(gtk_builder_get_object (builder,
"pref/general/account-separator"));
1386 g_object_set_data (G_OBJECT(dialog),
"account-separator", entry);
1388 spinner = GTK_WIDGET(gtk_builder_get_object (builder,
"pref/general/save-on-close-wait-time"));
1389 g_object_set_data (G_OBJECT(dialog),
"save_on_close_wait_time", spinner);
1391 DEBUG(
"autoconnect");
1392 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);
1396 notebook = GTK_WIDGET(gtk_builder_get_object (builder,
"notebook1"));
1397 prefs_table = g_hash_table_new (g_str_hash, g_str_equal);
1398 g_object_set_data (G_OBJECT(dialog), NOTEBOOK, notebook);
1399 g_object_set_data_full (G_OBJECT(dialog), PREFS_WIDGET_HASH,
1400 prefs_table, (GDestroyNotify)g_hash_table_destroy);
1403 if (gnc_current_session_exist())
1405 QofBook *book = gnc_get_current_book ();
1406 g_date_clear (&fy_end, 1);
1411 box = GTK_WIDGET(gtk_builder_get_object (builder,
1412 "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY
"/" GNC_PREF_START_PERIOD));
1414 gtk_widget_show (period);
1415 gtk_box_pack_start (GTK_BOX(box), period, TRUE, TRUE, 0);
1419 box = GTK_WIDGET(gtk_builder_get_object (builder,
1420 "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY
"/" GNC_PREF_END_PERIOD));
1422 gtk_widget_show (period);
1423 gtk_box_pack_start (GTK_BOX(box), period, TRUE, TRUE, 0);
1427 box = GTK_WIDGET(gtk_builder_get_object (builder,
1428 "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY
"/" GNC_PREF_START_DATE));
1429 date = gnc_date_edit_new (
gnc_time (NULL), FALSE, FALSE);
1430 gtk_widget_show (date);
1431 gtk_box_pack_start (GTK_BOX(box), date, TRUE, TRUE, 0);
1433 box = GTK_WIDGET(gtk_builder_get_object (builder,
1434 "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY
"/" GNC_PREF_END_DATE));
1435 date = gnc_date_edit_new (
gnc_time (NULL), FALSE, FALSE);
1436 gtk_widget_show (date);
1437 gtk_box_pack_start (GTK_BOX(box), date, TRUE, TRUE, 0);
1439 box = GTK_WIDGET(gtk_builder_get_object (builder,
1440 "pref/" GNC_PREFS_GROUP_GENERAL
"/" GNC_PREF_CURRENCY_OTHER));
1443 gtk_widget_show (currency);
1444 gtk_box_pack_start (GTK_BOX(box), currency, TRUE, TRUE, 0);
1446 box = GTK_WIDGET(gtk_builder_get_object (builder,
1447 "pref/" GNC_PREFS_GROUP_GENERAL_REPORT
"/" GNC_PREF_CURRENCY_OTHER));
1450 gtk_widget_show (currency);
1451 gtk_box_pack_start (GTK_BOX(box), currency, TRUE, TRUE, 0);
1453 box = GTK_WIDGET(gtk_builder_get_object (builder,
1454 "pref/" GNC_PREFS_GROUP_GENERAL
"/" GNC_DOC_LINK_PATH_HEAD));
1455 fcb = gtk_file_chooser_button_new (_(
"Select a folder"),
1456 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
1457 gtk_box_pack_start (GTK_BOX(box), fcb, TRUE, TRUE, 0);
1458 button = gtk_button_new_with_label (_(
"Clear"));
1459 gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0);
1460 gtk_widget_show (button);
1461 g_signal_connect (GTK_BUTTON(button),
"clicked",
1462 G_CALLBACK(file_chooser_clear_cb), fcb);
1464 image = GTK_WIDGET(gtk_builder_get_object (builder,
"path_head_error"));
1465 g_object_set_data (G_OBJECT(fcb),
"path_head_error", image);
1468 gnc_prefs_build_widget_table (builder, dialog);
1470 g_slist_foreach (
add_ins, gnc_preferences_build_page, dialog);
1473 gnc_prefs_sort_pages (GTK_NOTEBOOK(notebook));
1474 gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 0);
1476 DEBUG(
"We have the following interesting widgets:");
1478 g_hash_table_foreach (prefs_table, (GHFunc)gnc_prefs_connect_one, dialog);
1480 DEBUG(
"Done with interesting widgets.");
1483 gdate = g_date_new_dmy (31, G_DATE_JULY, 2013);
1484 g_date_strftime (buf,
sizeof(buf),
"%x", gdate);
1485 store = GTK_LIST_STORE(gtk_builder_get_object (builder,
"date_formats"));
1487 if (gtk_tree_model_get_iter (GTK_TREE_MODEL(store), &iter, path))
1488 gtk_list_store_set (store, &iter, 1, buf, -1);
1489 g_date_free (gdate);
1490 gtk_tree_path_free (path);
1494 label = GTK_WIDGET(gtk_builder_get_object (builder,
"locale_currency"));
1495 gtk_label_set_label (GTK_LABEL(label), currency_name);
1496 label = GTK_WIDGET(gtk_builder_get_object (builder,
"locale_currency2"));
1497 gtk_label_set_label (GTK_LABEL(label), currency_name);
1499 button = GTK_WIDGET(gtk_builder_get_object (builder,
"pref/general/save-on-close-expires"));
1502 g_object_unref (G_OBJECT(builder));
1505 g_object_set_data_full (G_OBJECT(entry),
"original_text",
1506 g_strdup (gtk_entry_get_text (GTK_ENTRY(entry))),
1509 LEAVE(
"dialog %p", dialog);
1535 show_handler (
const char *class_name, gint component_id,
1536 gpointer user_data, gpointer iter_data)
1541 dialog = GTK_WIDGET(user_data);
1542 gtk_window_present (GTK_WINDOW(dialog));
1555 close_handler (gpointer user_data)
1560 dialog = GTK_WIDGET(user_data);
1561 gnc_unregister_gui_component_by_data (DIALOG_PREFERENCES_CM_CLASS, dialog);
1562 gtk_widget_destroy (dialog);
1577 if (gnc_forall_gui_components (DIALOG_PREFERENCES_CM_CLASS,
1578 show_handler, NULL))
1580 LEAVE(
"existing window");
1584 dialog = gnc_preferences_dialog_create(parent);
1586 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(dialog), parent);
1587 gtk_widget_show (dialog);
1589 gnc_register_gui_component (DIALOG_PREFERENCES_CM_CLASS,
1590 NULL, close_handler, dialog);
void gnc_preferences_dialog(GtkWindow *parent)
This function creates the preferences dialog and presents it to the user.
void gnc_save_on_close_expires_cb(GtkToggleButton *button, GtkWidget *dialog)
Called when the save-on-close checkbutton is toggled.
void gnc_preferences_add_page(const gchar *filename, const gchar *widgetname, const gchar *tabname)
This function adds a full page of preferences to the preferences dialog.
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Get a string value from the preferences backend.
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
Set the widget to display a certain currency name.
GtkGrid * grid_from
The grid being copied from.
utility functions for the GnuCash UI
#define PINFO(format, args...)
Print an informational note.
#define DEBUG(format, args...)
Print a debugging message.
void gnc_preferences_add_to_page(const gchar *filename, const gchar *widgetname, const gchar *tabname)
This function adds a partial page of preferences to the preferences dialog.
GList * gnc_account_list_name_violations(QofBook *book, const gchar *separator)
Runs through all the accounts and returns a list of account names that contain the provided separator...
gboolean full_page
TRUE if this addition represents a full page in the preferences dialog.
GSList * add_ins
A list of all additions that have been made to the preferences dialog.
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
Store a string into the preferences backend.
#define ENTER(format, args...)
Print a function entry debugging message.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
Currency selection widget.
GtkGrid * grid_to
The grid being copied to.
Account handling public routines.
gchar * gnc_account_name_violations_errmsg(const gchar *separator, GList *invalid_account_names)
Composes a translatable error message showing which account names clash with the current account sepa...
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, gpointer object, const gchar *property)
Bind a setting to a g_object property.
This data structure is used while building the preferences dialog to copy a grid from a glade file to...
gint cols
The number of columns and rows in the grid.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
gchar * tabname
The name of the tab within the preferences dialog where these widgets should be placed.
void gnc_period_select_set_fy_end(GncPeriodSelect *period, const GDate *fy_end)
Set the fiscal year end on a GncPeriodSelect widget.
Dialog for handling user preferences.
All type declarations for the whole Gnucash engine.
gchar * widgetname
The name of the widget within the glade data file that should be added to the preferences dialog...
Generic api to store and retrieve preferences.
void gnc_preferences_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused)
Handle a user click on one of the buttons at the bottom of the preference dialog. ...
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gchar * filename
The relative name of the file where the glade data for this addition can be found.
GtkWidget * gnc_currency_edit_new(void)
Create a new GNCCurrencyEdit widget which can be used to provide an easy way to enter ISO currency co...
This data structure holds the information for a single addition to the preferences dialog...
#define LEAVE(format, args...)
Print a function exit debugging message.
time64 gnc_time(time64 *tbuf)
get the current time
GtkWidget * gnc_period_select_new(gboolean starting_labels)
Create a new GncPeriodSelect widget which is used to select a accounting period like "previous month"...
void gnc_prefs_block_all(void)
Block all preference callbacks.
Take from locale information.
void gnc_prefs_unblock_all(void)
Unblock all preferences callbacks.
A custom widget for selecting accounting periods.
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.
void gnc_account_separator_pref_changed_cb(GtkEntry *entry, GtkWidget *dialog)
This function is called whenever the account separator is changed in the preferences dialog...