Commit 535fbfae65fb918e3c63df47b3383c30aca41f59
1 parent
40fbc881
Exists in
master
and in
4 other branches
Implementing application settings.
Showing
4 changed files
with
120 additions
and
3 deletions
Show diff stats
src/include/pw3270.h
| @@ -54,6 +54,14 @@ | @@ -54,6 +54,14 @@ | ||
| 54 | 54 | ||
| 55 | void pw3270_load_placeholders(GtkBuilder * builder); | 55 | void pw3270_load_placeholders(GtkBuilder * builder); |
| 56 | 56 | ||
| 57 | + // Application settings widget | ||
| 58 | + typedef struct _Pw3270SettingWidget Pw3270SettingsWidget; | ||
| 59 | + | ||
| 60 | + struct _Pw3270SettingWidget { | ||
| 61 | + GtkWidget * widget; | ||
| 62 | + void (*apply)(Pw3270SettingsWidget *, GtkApplication *, GSettings *); | ||
| 63 | + void (*revert)(Pw3270SettingsWidget *, GtkApplication *, GSettings *); | ||
| 64 | + }; | ||
| 57 | 65 | ||
| 58 | G_END_DECLS | 66 | G_END_DECLS |
| 59 | 67 |
src/objects/application/actions/preferences.c
| @@ -28,11 +28,120 @@ | @@ -28,11 +28,120 @@ | ||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include "../private.h" | 30 | #include "../private.h" |
| 31 | + #include <pw3270.h> | ||
| 31 | #include <pw3270/application.h> | 32 | #include <pw3270/application.h> |
| 32 | 33 | ||
| 33 | - void pw3270_application_preferences_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) { | 34 | + typedef struct _Pw3270SettingsDialog { |
| 35 | + GtkApplication * application; | ||
| 36 | + GSimpleAction * action; | ||
| 37 | + GSList * pages; | ||
| 38 | + } Pw3270SettingsDialog; | ||
| 39 | + | ||
| 40 | + static void on_destroy(GtkWidget *dialog, Pw3270SettingsDialog *settings) { | ||
| 41 | + g_slist_free_full(settings->pages,g_free); | ||
| 42 | + g_free(settings); | ||
| 43 | + g_simple_action_set_enabled(settings->action,TRUE); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + void on_response(GtkDialog *dialog, gint response_id, Pw3270SettingsDialog * settings) { | ||
| 47 | + | ||
| 48 | + GSList * page; | ||
| 49 | + GSettings *hSettings = pw3270_application_get_settings(settings->application); | ||
| 50 | + | ||
| 51 | + switch(response_id) { | ||
| 52 | + case GTK_RESPONSE_CANCEL: | ||
| 53 | + g_message("Reverting application settings"); | ||
| 54 | + for(page = settings->pages;page;page = page->next) { | ||
| 55 | + Pw3270SettingsWidget * widget = (Pw3270SettingsWidget *) page->data; | ||
| 56 | + widget->revert(widget,settings->application,hSettings); | ||
| 57 | + } | ||
| 58 | + break; | ||
| 59 | + | ||
| 60 | + case GTK_RESPONSE_APPLY: | ||
| 61 | + g_message("Aplying application settings"); | ||
| 62 | + for(page = settings->pages;page;page = page->next) { | ||
| 63 | + Pw3270SettingsWidget * widget = (Pw3270SettingsWidget *) page->data; | ||
| 64 | + widget->apply(widget,settings->application,hSettings); | ||
| 65 | + } | ||
| 66 | + break; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + gtk_widget_destroy(dialog); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + static void on_page_added(GtkNotebook *notebook, GtkWidget *widget, guint page_num, Pw3270SettingsDialog * settings) { | ||
| 73 | + | ||
| 74 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | ||
| 75 | + | ||
| 76 | + if(GTK_IS_GRID(widget)) { | ||
| 77 | + gtk_grid_set_row_spacing(GTK_GRID(widget),6); | ||
| 78 | + gtk_grid_set_column_spacing(GTK_GRID(widget),12); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + if(GTK_IS_CONTAINER(widget)) { | ||
| 82 | + gtk_container_set_border_width(GTK_CONTAINER(widget),18); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + void pw3270_application_preferences_activated(GSimpleAction *action, GVariant G_GNUC_UNUSED(*parameter), gpointer application) { | ||
| 34 | 88 | ||
| 35 | debug("%s",__FUNCTION__); | 89 | debug("%s",__FUNCTION__); |
| 36 | 90 | ||
| 91 | + // Create dialog. | ||
| 92 | + gboolean use_header; | ||
| 93 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | ||
| 94 | + | ||
| 95 | + GtkWidget * dialog = | ||
| 96 | + GTK_WIDGET(g_object_new( | ||
| 97 | + GTK_TYPE_DIALOG, | ||
| 98 | + "use-header-bar", (use_header ? 1 : 0), | ||
| 99 | + NULL | ||
| 100 | + )); | ||
| 101 | + | ||
| 102 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Application preferences")); | ||
| 103 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
| 104 | + gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | ||
| 105 | + | ||
| 106 | + gtk_window_set_transient_for(GTK_WINDOW(dialog),gtk_application_get_active_window(GTK_APPLICATION(application))); | ||
| 107 | + gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog),TRUE); | ||
| 108 | + | ||
| 109 | + gtk_dialog_add_buttons( | ||
| 110 | + GTK_DIALOG(dialog), | ||
| 111 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | ||
| 112 | + _("_Apply"), GTK_RESPONSE_APPLY, | ||
| 113 | + NULL | ||
| 114 | + ); | ||
| 115 | + | ||
| 116 | + // Create setttings data. | ||
| 117 | + Pw3270SettingsDialog * settings = g_new0(Pw3270SettingsDialog,1); | ||
| 118 | + settings->action = action; | ||
| 119 | + settings->application = GTK_APPLICATION(application); | ||
| 120 | + | ||
| 121 | + g_simple_action_set_enabled(action,FALSE); | ||
| 122 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
| 123 | + | ||
| 124 | + // Create settings notebook. | ||
| 125 | + | ||
| 126 | + GtkNotebook *notebook = GTK_NOTEBOOK(gtk_notebook_new()); | ||
| 127 | + | ||
| 128 | + gtk_notebook_set_scrollable(notebook,TRUE); | ||
| 129 | + gtk_notebook_set_show_tabs(notebook,TRUE); | ||
| 130 | + gtk_notebook_set_show_border(notebook, FALSE); | ||
| 131 | + | ||
| 132 | + g_signal_connect(G_OBJECT(notebook), "page-added", G_CALLBACK(on_page_added), dialog); | ||
| 133 | +// g_signal_connect(G_OBJECT(notebook), "page-removed", G_CALLBACK(on_page_changed), dialog); | ||
| 134 | +// g_signal_connect(G_OBJECT(notebook), "switch-page", G_CALLBACK(on_switch_page), dialog); | ||
| 135 | + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(notebook),TRUE,TRUE,0); | ||
| 136 | + | ||
| 137 | + // Connection signals. | ||
| 138 | + g_signal_connect(dialog,"destroy",G_CALLBACK(on_destroy),settings); | ||
| 139 | + g_signal_connect(dialog,"response",G_CALLBACK(on_response),settings); | ||
| 140 | + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | ||
| 141 | + | ||
| 142 | + // Show dialog. | ||
| 143 | + gtk_widget_show_all(dialog); | ||
| 144 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
| 145 | + | ||
| 37 | } | 146 | } |
| 38 | 147 |
ui/application.xml
| @@ -64,7 +64,7 @@ | @@ -64,7 +64,7 @@ | ||
| 64 | 64 | ||
| 65 | <item> | 65 | <item> |
| 66 | <attribute name="label" translatable="yes">Preferences</attribute> | 66 | <attribute name="label" translatable="yes">Preferences</attribute> |
| 67 | - <attribute name="action">win.preferences</attribute> | 67 | + <attribute name="action">app.preferences</attribute> |
| 68 | </item> | 68 | </item> |
| 69 | 69 | ||
| 70 | <item> | 70 | <item> |
ui/window.xml
| @@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
| 50 | 50 | ||
| 51 | <item> | 51 | <item> |
| 52 | <attribute name="label" translatable="yes">Preferences</attribute> | 52 | <attribute name="label" translatable="yes">Preferences</attribute> |
| 53 | - <attribute name="action">win.preferences</attribute> | 53 | + <attribute name="action">app.preferences</attribute> |
| 54 | </item> | 54 | </item> |
| 55 | 55 | ||
| 56 | </menu> | 56 | </menu> |