Commit 6cf2c5ddc1f3ce8cbf27e35b9dee15c17be72fa4

Authored by Perry Werneck
1 parent 60bd7fdd

Delaying 'gsettings' change on application preferences dialog.

src/include/pw3270/settings.h
... ... @@ -51,19 +51,19 @@
51 51  
52 52 GType PW3270Settings_get_type(void);
53 53  
54   - typedef struct _PW3270SettingsPrivate PW3270SettingsPrivate;
  54 + typedef struct _PW3270SettingsPage PW3270SettingsPage;
55 55  
56 56 typedef struct _PW3270Settings {
57 57  
58 58 GtkGrid parent;
59 59  
60   - PW3270SettingsPrivate * settings; ///< @brief Private Data.
61   - const gchar * label; ///< @brief Page lagel.
62   - const gchar * title; ///< @brief Page title.
  60 + PW3270SettingsPage * settings; ///< @brief Page Data.
  61 + const gchar * label; ///< @brief Page lagel.
  62 + const gchar * title; ///< @brief Page title.
63 63  
64   - void (*load)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method to load the properties from terminal widget
65   - void (*apply)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method for GTK_RESPONSE_APPLY
66   - void (*revert)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method for GTK_RESPONSE_CANCEL
  64 + void (*load)(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page); ///< @brief Method to load the properties from terminal widget
  65 + void (*apply)(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page); ///< @brief Method for GTK_RESPONSE_APPLY
  66 + void (*revert)(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page); ///< @brief Method for GTK_RESPONSE_CANCEL
67 67  
68 68 } PW3270Settings;
69 69  
... ... @@ -73,8 +73,10 @@
73 73  
74 74 } PW3270SettingsClass;
75 75  
  76 + /// @brief Create a new pw3270 settings.
76 77 PW3270Settings * pw3270_settings_new();
77 78  
  79 +
78 80 /*--[ PW3270 Settings Dialog ]-----------------------------------------------------------------------*/
79 81  
80 82 #define GTK_TYPE_PW3270_SETTINGS_DIALOG (PW3270SettingsDialog_get_type())
... ...
src/objects/actions/view.c
... ... @@ -409,7 +409,7 @@
409 409 return g_string_free(str,FALSE);
410 410 }
411 411  
412   - static void check_4_sensitive(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gboolean *sensitive) {
  412 + static void check_4_sensitive(GtkTreeModel *model, GtkTreePath G_GNUC_UNUSED(*path), GtkTreeIter *iter, gboolean *sensitive) {
413 413  
414 414 GValue value = { 0, };
415 415 gtk_tree_model_get_value(model,iter,COLUMN_FLAGS,&value);
... ...
src/objects/application/application.c
... ... @@ -417,20 +417,20 @@
417 417 // Load keypad models
418 418 //
419 419 {
420   -#ifdef DEBUG
421   - const gchar * keypad_path = "keypad";
422   -#else
423 420 lib3270_autoptr(char) keypad_path = lib3270_build_data_filename("keypad",NULL);
424   -#endif // DEBUG
425 421  
426 422 g_autoptr(GError) error = NULL;
427 423 g_autoptr(GDir) dir = g_dir_open(keypad_path,0,&error);
428 424  
429   - const gchar *name = g_dir_read_name(dir);
430   - while(!error && name) {
431   - g_autofree gchar * path = g_build_filename(keypad_path,name,NULL);
432   - app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path);
433   - name = g_dir_read_name(dir);
  425 + if(dir) {
  426 +
  427 + const gchar *name = g_dir_read_name(dir);
  428 + while(!error && name) {
  429 + g_autofree gchar * path = g_build_filename(keypad_path,name,NULL);
  430 + app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path);
  431 + name = g_dir_read_name(dir);
  432 + }
  433 +
434 434 }
435 435  
436 436 if(error) {
... ...
src/objects/settings/dialog.c
... ... @@ -35,6 +35,7 @@
35 35 #include <pw3270.h>
36 36 #include <pw3270/settings.h>
37 37 #include <pw3270/actions.h>
  38 + #include <pw3270/window.h>
38 39 #include <lib3270.h>
39 40 #include <lib3270/log.h>
40 41  
... ... @@ -144,18 +145,18 @@ void dialog_close(GtkDialog *dialog) {
144 145 gtk_widget_destroy(GTK_WIDGET(dialog));
145 146 }
146 147  
147   -static void apply(GtkWidget *widget, GtkWidget G_GNUC_UNUSED(*dialog)) {
  148 +static void apply(GtkWidget *widget, GSettings *settings) {
148 149  
149 150 if(GTK_IS_PW3270_SETTINGS(widget)) {
150   - GTK_PW3270_SETTINGS(widget)->apply(widget,GTK_PW3270_SETTINGS(widget)->settings);
  151 + GTK_PW3270_SETTINGS(widget)->apply(widget,settings,GTK_PW3270_SETTINGS(widget)->settings);
151 152 }
152 153  
153 154 }
154 155  
155   -static void revert(GtkWidget *widget, GtkWidget G_GNUC_UNUSED(*dialog)) {
  156 +static void revert(GtkWidget *widget, GSettings *settings, GtkWidget G_GNUC_UNUSED(*dialog)) {
156 157  
157 158 if(GTK_IS_PW3270_SETTINGS(widget)) {
158   - GTK_PW3270_SETTINGS(widget)->revert(widget,GTK_PW3270_SETTINGS(widget)->settings);
  159 + GTK_PW3270_SETTINGS(widget)->revert(widget,settings,GTK_PW3270_SETTINGS(widget)->settings);
159 160 }
160 161  
161 162 }
... ... @@ -164,12 +165,15 @@ void response(GtkDialog *dialog, gint response_id) {
164 165  
165 166 debug("%s(%d)",__FUNCTION__,response_id);
166 167  
  168 + g_autoptr(GSettings) settings = pw3270_application_window_settings_new();
  169 + g_settings_delay(settings);
  170 +
167 171 switch(response_id) {
168 172 case GTK_RESPONSE_APPLY:
169 173 gtk_container_foreach(
170 174 GTK_CONTAINER(GTK_PW3270_SETTINGS_DIALOG(dialog)->tabs),
171 175 (GtkCallback) apply,
172   - dialog
  176 + settings
173 177 );
174 178 break;
175 179  
... ... @@ -177,13 +181,15 @@ void response(GtkDialog *dialog, gint response_id) {
177 181 gtk_container_foreach(
178 182 GTK_CONTAINER(GTK_PW3270_SETTINGS_DIALOG(dialog)->tabs),
179 183 (GtkCallback) revert,
180   - dialog
  184 + settings
181 185 );
182 186 break;
183 187  
184 188 }
185 189  
  190 + g_settings_apply(settings);
186 191 gtk_widget_destroy(GTK_WIDGET(dialog));
  192 +
187 193 }
188 194  
189 195 void add(GtkContainer *container, GtkWidget *widget) {
... ... @@ -196,7 +202,9 @@ void add(GtkContainer *container, GtkWidget *widget) {
196 202 if(GTK_IS_PW3270_SETTINGS(widget)) {
197 203 PW3270Settings * settings = GTK_PW3270_SETTINGS(widget);
198 204 label = gtk_label_new(settings->label);
199   - settings->load(widget,settings->settings);
  205 +
  206 + g_autoptr(GSettings) gs = pw3270_application_window_settings_new();
  207 + settings->load(widget,gs,settings->settings);
200 208 }
201 209  
202 210 gtk_widget_show(widget);
... ... @@ -212,7 +220,7 @@ void page_changed(GtkNotebook *notebook, GtkWidget G_GNUC_UNUSED(*child), guint
212 220 gtk_notebook_set_show_tabs(notebook,gtk_notebook_get_n_pages(notebook) > 1);
213 221 }
214 222  
215   -void switch_page(GtkNotebook *notebook, PW3270Settings *page, guint G_GNUC_UNUSED(page_num), PW3270SettingsDialog *dialog) {
  223 +void switch_page(GtkNotebook G_GNUC_UNUSED(*notebook), PW3270Settings *page, guint G_GNUC_UNUSED(page_num), PW3270SettingsDialog *dialog) {
216 224  
217 225 GtkWidget * header_bar = gtk_dialog_get_header_bar(GTK_DIALOG(dialog));
218 226  
... ...
src/objects/settings/widget.c
... ... @@ -39,9 +39,9 @@
39 39  
40 40 G_DEFINE_TYPE(PW3270Settings, PW3270Settings, GTK_TYPE_GRID);
41 41  
42   - static void load(GtkWidget *widget, PW3270SettingsPrivate *settings);
43   - static void apply(GtkWidget *widget, PW3270SettingsPrivate *settings);
44   - static void revert(GtkWidget *widget, PW3270SettingsPrivate *settings);
  42 + static void load(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
  43 + static void apply(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
  44 + static void revert(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
45 45 static void finalize(GObject *object);
46 46  
47 47 /*--[ Implement ]------------------------------------------------------------------------------------*/
... ... @@ -78,12 +78,12 @@
78 78  
79 79 }
80 80  
81   - void load(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) {
  81 + void load(GtkWidget G_GNUC_UNUSED(*widget), GSettings G_GNUC_UNUSED(*settings), PW3270SettingsPage G_GNUC_UNUSED(*page)) {
82 82 }
83 83  
84   - void apply(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) {
  84 + void apply(GtkWidget G_GNUC_UNUSED(*widget), GSettings G_GNUC_UNUSED(*settings), PW3270SettingsPage G_GNUC_UNUSED(*page)) {
85 85 }
86 86  
87   - void revert(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) {
  87 + void revert(GtkWidget G_GNUC_UNUSED(*widget), GSettings G_GNUC_UNUSED(*settings), PW3270SettingsPage G_GNUC_UNUSED(*page)) {
88 88 }
89 89  
... ...
src/objects/toolbar/settings.c
... ... @@ -35,8 +35,8 @@
35 35 #include <pw3270/window.h>
36 36 #include <v3270/dialogs.h>
37 37  
38   - static void load(GtkWidget *widget, PW3270SettingsPrivate *settings);
39   - static void apply(GtkWidget *widget, PW3270SettingsPrivate *settings);
  38 + static void load(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
  39 + static void apply(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
40 40  
41 41 /*--[ Constants ]------------------------------------------------------------------------------------*/
42 42  
... ... @@ -77,7 +77,7 @@
77 77  
78 78 };
79 79  
80   - struct _PW3270SettingsPrivate {
  80 + struct _PW3270SettingsPage {
81 81 GtkWidget * views[2];
82 82 // GtkTreeModel * models[G_N_ELEMENTS(comboboxes)];
83 83 GtkWidget * combos[G_N_ELEMENTS(comboboxes)];
... ... @@ -97,7 +97,7 @@
97 97 settings->load = load;
98 98  
99 99 // Create private data.
100   - PW3270SettingsPrivate * page = settings->settings = g_new0(PW3270SettingsPrivate,1);
  100 + PW3270SettingsPage * page = settings->settings = g_new0(PW3270SettingsPage,1);
101 101  
102 102 //
103 103 // Create views
... ... @@ -222,10 +222,9 @@
222 222 return GTK_WIDGET(settings);
223 223 }
224 224  
225   - void load(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) {
  225 + void load(GtkWidget G_GNUC_UNUSED(*widget), GSettings *settings, PW3270SettingsPage *page) {
226 226  
227 227 size_t ix;
228   - g_autoptr(GSettings) settings = pw3270_application_window_settings_new();
229 228  
230 229 // Populate views
231 230 Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default()));
... ... @@ -274,10 +273,9 @@
274 273  
275 274 }
276 275  
277   - void apply(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) {
  276 + void apply(GtkWidget G_GNUC_UNUSED(*widget), GSettings *settings, PW3270SettingsPage *page) {
278 277  
279 278 size_t ix;
280   - g_autoptr(GSettings) settings = pw3270_application_window_settings_new();
281 279  
282 280 g_autofree gchar * action_names = pw3270_action_view_get_action_names(page->views[0]);
283 281 g_settings_set_string(settings,"toolbar-action-names",action_names);
... ...
src/objects/window/header-settings.c
... ... @@ -34,12 +34,12 @@
34 34 #include <pw3270/application.h>
35 35 #include <v3270/dialogs.h>
36 36  
37   - static void load(GtkWidget *widget, PW3270SettingsPrivate *settings);
38   - static void apply(GtkWidget *widget, PW3270SettingsPrivate *settings);
  37 + static void load(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
  38 + static void apply(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
39 39  
40 40 /*--[ Constants ]------------------------------------------------------------------------------------*/
41 41  
42   - struct _PW3270SettingsPrivate {
  42 + struct _PW3270SettingsPage {
43 43 GtkWidget * editor;
44 44 /*
45 45 GtkWidget * views[3];
... ... @@ -87,7 +87,7 @@
87 87 settings->load = load;
88 88  
89 89 // Create private data.
90   - PW3270SettingsPrivate * page = settings->settings = g_new0(PW3270SettingsPrivate,1);
  90 + PW3270SettingsPage * page = settings->settings = g_new0(PW3270SettingsPage,1);
91 91  
92 92 page->editor = pw3270_settings_actions_new();
93 93  
... ... @@ -102,9 +102,7 @@
102 102 return GTK_WIDGET(settings);
103 103 }
104 104  
105   - void load(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) {
106   -
107   - g_autoptr(GSettings) settings = pw3270_application_window_settings_new();
  105 + void load(GtkWidget G_GNUC_UNUSED(*widget), GSettings *settings, PW3270SettingsPage *page) {
108 106  
109 107 // Get avaliable actions.
110 108 Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default()));
... ... @@ -162,10 +160,9 @@
162 160 pw3270_action_list_free(action_list);
163 161 }
164 162  
165   - void apply(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) {
  163 + void apply(GtkWidget G_GNUC_UNUSED(*widget), GSettings *settings, PW3270SettingsPage *page) {
166 164  
167 165 g_autofree gchar * action_names = pw3270_settings_action_get(page->editor);
168   - g_autoptr(GSettings) settings = pw3270_application_window_settings_new();
169 166 g_settings_set_string(settings,"header-action-names",action_names);
170 167  
171 168 }
... ...