Commit da55a19272553330ad44867454add795cba20930

Authored by Perry Werneck
1 parent 79a7ba35

Storing toolbar settings.

schemas/application.gschema.xml.in
... ... @@ -44,6 +44,18 @@
44 44 <description>If TRUE, reserve space for a subtitle, even if none is currently set.</description>
45 45 </key>
46 46  
  47 + <key name="toolbar-style" type="i">
  48 + <default>-1</default>
  49 + <summary>How to draw the toolbar.</summary>
  50 + <description></description>
  51 + </key>
  52 +
  53 + <key name="toolbar-icon-size" type="i">
  54 + <default>0</default>
  55 + <summary>The size of the icons in a toolbar</summary>
  56 + <description></description>
  57 + </key>
  58 +
47 59 </schema>
48 60  
49 61 </schemalist>
... ...
src/include/pw3270/application.h
... ... @@ -69,6 +69,8 @@
69 69 void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type);
70 70 PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app);
71 71  
  72 + gboolean pw3270_settings_set_int(const gchar *key, gint value);
  73 +
72 74 G_END_DECLS
73 75  
74 76  
... ...
src/include/pw3270/toolbar.h
... ... @@ -60,6 +60,8 @@
60 60 GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, GAction *action, gint pos);
61 61 GtkWidget * pw3270_toolbar_insert_action_by_name(GtkWidget *toolbar, const gchar *name, gint pos);
62 62  
  63 + void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
  64 + void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size);
63 65  
64 66 G_END_DECLS
65 67  
... ...
src/main/tools.c
... ... @@ -38,3 +38,4 @@
38 38  
39 39 /*---[ Implement ]----------------------------------------------------------------------------------*/
40 40  
  41 +
... ...
src/objects/actions/lib3270/action.c
... ... @@ -110,13 +110,13 @@
110 110 }
111 111  
112 112 void Lib3270Action_init(Lib3270Action *action) {
113   - debug("%s",__FUNCTION__);
  113 +// debug("%s",__FUNCTION__);
114 114 PW3270_ACTION(action)->activate = activate;
115 115 }
116 116  
117 117 GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) {
118 118  
119   - Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL);
  119 + Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL);
120 120  
121 121 // Setup hooks.
122 122 action->definition = definition;
... ...
src/objects/toolbar/toolbar.c
... ... @@ -28,10 +28,62 @@
28 28 */
29 29  
30 30 #include "private.h"
  31 + #include <pw3270/application.h>
  32 +
  33 + #define GTK_TOOLBAR_DEFAULT_STYLE ((GtkToolbarStyle) -1)
31 34  
32 35 static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number);
33 36 static void finalize(GObject *object);
34 37  
  38 + static const struct icon_size {
  39 + const gchar * label;
  40 + GtkIconSize icon_size;
  41 + } icon_sizes[] = {
  42 +
  43 + {
  44 + .label = N_( "System default" ),
  45 + .icon_size = GTK_ICON_SIZE_INVALID
  46 +
  47 + },
  48 +
  49 + {
  50 + .label = N_( "Small" ),
  51 + .icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR
  52 + },
  53 +
  54 + {
  55 + .label = N_( "Large" ),
  56 + .icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR
  57 + },
  58 + };
  59 +
  60 + static const struct toolbar_style {
  61 + const gchar * label;
  62 + GtkToolbarStyle style;
  63 + } styles[] = {
  64 +
  65 + {
  66 + .label = N_( "System default" ),
  67 + .style = GTK_TOOLBAR_DEFAULT_STYLE
  68 + },
  69 +
  70 + {
  71 + .label = N_( "Icons only" ),
  72 + .style = GTK_TOOLBAR_ICONS
  73 + },
  74 +
  75 + {
  76 + .label = N_( "Text only" ),
  77 + .style = GTK_TOOLBAR_TEXT
  78 + },
  79 +
  80 + {
  81 + .label = N_( "Icons & text" ),
  82 + .style = GTK_TOOLBAR_BOTH
  83 + },
  84 +};
  85 +
  86 +
35 87  
36 88 struct _pw3270ToolBar {
37 89 GtkToolbar parent;
... ... @@ -60,7 +112,7 @@
60 112  
61 113 }
62 114  
63   - static void detacher(GtkWidget *attach_widget, GtkMenu *menu) {
  115 + static void detacher(GtkWidget *attach_widget, GtkMenu G_GNUC_UNUSED(*menu)) {
64 116  
65 117 pw3270ToolBar * toolbar = PW3270_TOOLBAR(attach_widget);
66 118 toolbar->popup_menu = NULL;
... ... @@ -69,23 +121,18 @@
69 121  
70 122 static void set_icon_size(GtkMenuItem *menuitem, GtkWidget *toolbar) {
71 123  
72   - GtkIconSize * icon_size = g_object_get_data(G_OBJECT(menuitem),"icon_size");
  124 + const struct icon_size * size = g_object_get_data(G_OBJECT(menuitem),"icon_size");
73 125  
74   - if(icon_size)
75   - gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),*icon_size);
76   - else
77   - gtk_toolbar_unset_icon_size(GTK_TOOLBAR(toolbar));
  126 + debug("%s(%d,%s)",__FUNCTION__,(int) size->icon_size, size->label);
  127 + pw3270_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), size->icon_size);
78 128  
79 129 }
80 130  
81 131 static void set_style(GtkMenuItem *menuitem, GtkWidget *toolbar) {
  132 + struct toolbar_style * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style");
82 133  
83   - GtkToolbarStyle * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style");
84   -
85   - if(style)
86   - gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),*style);
87   - else
88   - gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar));
  134 + debug("%s(%d,%s)",__FUNCTION__,(int) style->style, style->label);
  135 + pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(toolbar), style->style);
89 136  
90 137 }
91 138  
... ... @@ -95,27 +142,6 @@
95 142  
96 143 // Size options
97 144 {
98   - static const struct {
99   - const gchar * label;
100   - GtkIconSize icon_size;
101   - } itens[] = {
102   -
103   - {
104   - .label = N_( "System default" )
105   -
106   - },
107   -
108   - {
109   - .label = N_( "Small" ),
110   - .icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR
111   - },
112   -
113   - {
114   - .label = N_( "Large" ),
115   - .icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR
116   - },
117   - };
118   -
119 145 size_t ix;
120 146  
121 147 GtkWidget * item = gtk_menu_item_new_with_mnemonic( _("Icon _size") );
... ... @@ -124,13 +150,11 @@
124 150 GtkWidget * submenu = gtk_menu_new();
125 151 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu);
126 152  
127   - for(ix = 0; ix < G_N_ELEMENTS(itens); ix++) {
  153 + for(ix = 0; ix < G_N_ELEMENTS(icon_sizes); ix++) {
128 154  
129   - item = gtk_menu_item_new_with_mnemonic(gettext(itens[ix].label));
130   -
131   - if(ix > 0)
132   - g_object_set_data(G_OBJECT(item),"icon_size", (gpointer) &itens[ix].icon_size);
  155 + item = gtk_menu_item_new_with_mnemonic(gettext(icon_sizes[ix].label));
133 156  
  157 + g_object_set_data(G_OBJECT(item),"icon_size", (gpointer) &icon_sizes[ix]);
134 158 g_signal_connect(item, "activate", G_CALLBACK(set_icon_size), widget);
135 159  
136 160 gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item);
... ... @@ -141,31 +165,6 @@
141 165  
142 166 // Style option
143 167 {
144   - static const struct {
145   - const gchar * label;
146   - GtkToolbarStyle style;
147   - } itens[] = {
148   -
149   - {
150   - .label = N_( "System default" )
151   - },
152   -
153   - {
154   - .label = N_( "Icons only" ),
155   - .style = GTK_TOOLBAR_ICONS
156   - },
157   -
158   - {
159   - .label = N_( "Text only" ),
160   - .style = GTK_TOOLBAR_TEXT
161   - },
162   -
163   - {
164   - .label = N_( "Icons & text" ),
165   - .style = GTK_TOOLBAR_BOTH
166   - },
167   - };
168   -
169 168 size_t ix;
170 169  
171 170 GtkWidget * item = gtk_menu_item_new_with_mnemonic( _("S_tyle") );
... ... @@ -174,13 +173,11 @@
174 173 GtkWidget * submenu = gtk_menu_new();
175 174 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu);
176 175  
177   - for(ix = 0; ix < G_N_ELEMENTS(itens); ix++) {
178   -
179   - item = gtk_menu_item_new_with_mnemonic(gettext(itens[ix].label));
  176 + for(ix = 0; ix < G_N_ELEMENTS(styles); ix++) {
180 177  
181   - if(ix > 0)
182   - g_object_set_data(G_OBJECT(item),"toolbar_style", (gpointer) &itens[ix].style);
  178 + item = gtk_menu_item_new_with_mnemonic(gettext(styles[ix].label));
183 179  
  180 + g_object_set_data(G_OBJECT(item),"toolbar_style", (gpointer) &styles[ix]);
184 181 g_signal_connect(item, "activate", G_CALLBACK(set_style), widget);
185 182  
186 183 gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item);
... ... @@ -193,6 +190,14 @@
193 190 gtk_widget_show_all(widget->popup_menu);
194 191 gtk_menu_attach_to_widget(GTK_MENU(widget->popup_menu),GTK_WIDGET(widget),detacher);
195 192  
  193 + // Bind settings
  194 + GSettings *settings = pw3270_application_get_settings(g_application_get_default());
  195 +
  196 + if(settings) {
  197 + pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-style"));
  198 + pw3270_toolbar_set_icon_size(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-icon-size"));
  199 + }
  200 +
196 201 }
197 202  
198 203 static void finalize(GObject *object) {
... ... @@ -242,7 +247,7 @@
242 247 return GTK_WIDGET(item);
243 248 }
244 249  
245   - gboolean popup_context_menu(GtkToolbar *widget, gint x, gint y, gint button_number) {
  250 + gboolean popup_context_menu(GtkToolbar *widget, gint G_GNUC_UNUSED(x), gint G_GNUC_UNUSED(y), gint button_number) {
246 251  
247 252 pw3270ToolBar * toolbar = PW3270_TOOLBAR(widget);
248 253  
... ... @@ -252,8 +257,32 @@
252 257 gtk_menu_popup_at_pointer(GTK_MENU(toolbar->popup_menu),NULL);
253 258 }
254 259  
255   -
256 260 return TRUE;
257 261  
258 262 }
259 263  
  264 + void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style) {
  265 +
  266 + debug("%s(%d)",__FUNCTION__,(int) style);
  267 +
  268 + if(style == GTK_TOOLBAR_DEFAULT_STYLE)
  269 + gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar));
  270 + else
  271 + gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),style);
  272 +
  273 + pw3270_settings_set_int("toolbar-style",(int) style);
  274 +
  275 + }
  276 +
  277 + void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) {
  278 +
  279 + debug("%s(%d)",__FUNCTION__,(int) icon_size);
  280 +
  281 + if(icon_size == GTK_ICON_SIZE_INVALID)
  282 + gtk_toolbar_unset_icon_size(GTK_TOOLBAR(toolbar));
  283 + else
  284 + gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),icon_size);
  285 +
  286 + pw3270_settings_set_int("toolbar-icon-size", (gint) icon_size);
  287 +
  288 + }
... ...
src/objects/window/tools.c
... ... @@ -41,4 +41,11 @@
41 41  
42 42 }
43 43  
  44 + gboolean pw3270_settings_set_int(const gchar *key, gint value) {
  45 +
  46 + GSettings * settings = pw3270_application_get_settings(g_application_get_default());
  47 + if(settings)
  48 + return g_settings_set_int(settings,key,value);
  49 + return FALSE;
  50 + }
44 51  
... ...