Commit 8e3e419c89f621ee53b52b425d9124eb8b924b37

Authored by Perry Werneck
1 parent c9c4eb5b

Adding toolbar options in the settings dialog.

src/include/pw3270/application.h
@@ -69,7 +69,7 @@ @@ -69,7 +69,7 @@
69 void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type); 69 void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type);
70 PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app); 70 PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app);
71 71
72 - gboolean pw3270_settings_set_int(const gchar *key, gint value); 72 +// gboolean pw3270_settings_set_int(const gchar *key, gint value);
73 73
74 74
75 // Tools 75 // Tools
src/include/pw3270/toolbar.h
@@ -66,6 +66,9 @@ @@ -66,6 +66,9 @@
66 void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); 66 void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
67 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size); 67 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size);
68 68
  69 + GtkToolbarStyle pw3270_toolbar_get_style(GtkToolbar *toolbar);
  70 + GtkIconSize pw3270_toolbar_get_icon_size(GtkToolbar *toolbar);
  71 +
69 G_END_DECLS 72 G_END_DECLS
70 73
71 #endif // PW3270_TOOLBAR_H_INCLUDED 74 #endif // PW3270_TOOLBAR_H_INCLUDED
src/objects/toolbar/toolbar.c
@@ -34,7 +34,6 @@ @@ -34,7 +34,6 @@
34 34
35 static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number); 35 static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number);
36 static void finalize(GObject *object); 36 static void finalize(GObject *object);
37 - static void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);  
38 static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); 37 static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
39 static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); 38 static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
40 39
@@ -89,10 +88,13 @@ @@ -89,10 +88,13 @@
89 enum { 88 enum {
90 PROP_NONE, 89 PROP_NONE,
91 PROP_ACTION_NAMES, 90 PROP_ACTION_NAMES,
  91 + PROP_ICON_SIZE,
  92 + PROP_STYLE
92 }; 93 };
93 94
94 struct _pw3270ToolBar { 95 struct _pw3270ToolBar {
95 GtkToolbar parent; 96 GtkToolbar parent;
  97 + GtkToolbarStyle style;
96 98
97 /// @brief Popup Menu 99 /// @brief Popup Menu
98 struct { 100 struct {
@@ -127,13 +129,39 @@ @@ -127,13 +129,39 @@
127 g_object_class_install_property( 129 g_object_class_install_property(
128 object_class, 130 object_class,
129 PROP_ACTION_NAMES, 131 PROP_ACTION_NAMES,
130 - g_param_spec_string ("action-names", 132 + g_param_spec_string (
  133 + "action-names",
131 N_("Action Names"), 134 N_("Action Names"),
132 N_("The name of the actions in the toolbar"), 135 N_("The name of the actions in the toolbar"),
133 NULL, 136 NULL,
134 G_PARAM_READABLE|G_PARAM_WRITABLE) 137 G_PARAM_READABLE|G_PARAM_WRITABLE)
135 ); 138 );
136 139
  140 + g_object_class_install_property(
  141 + object_class,
  142 + PROP_ICON_SIZE,
  143 + g_param_spec_int(
  144 + "icon-size",
  145 + "icon-size",
  146 + _("The toolbar icon size"),
  147 + INT_MIN,
  148 + INT_MAX,
  149 + 0,
  150 + G_PARAM_READABLE|G_PARAM_WRITABLE)
  151 + );
  152 +
  153 + g_object_class_install_property(
  154 + object_class,
  155 + PROP_STYLE,
  156 + g_param_spec_int(
  157 + "style",
  158 + "style",
  159 + _("The toolbar style"),
  160 + INT_MIN,
  161 + INT_MAX,
  162 + 0,
  163 + G_PARAM_READABLE|G_PARAM_WRITABLE)
  164 + );
137 165
138 } 166 }
139 167
@@ -144,6 +172,14 @@ @@ -144,6 +172,14 @@
144 g_value_take_string(value,pw3270_toolbar_get_actions(GTK_WIDGET(object))); 172 g_value_take_string(value,pw3270_toolbar_get_actions(GTK_WIDGET(object)));
145 break; 173 break;
146 174
  175 + case PROP_ICON_SIZE:
  176 + g_value_set_int(value,pw3270_toolbar_get_icon_size(GTK_TOOLBAR(object)));
  177 + break;
  178 +
  179 + case PROP_STYLE:
  180 + g_value_set_int(value,pw3270_toolbar_get_style(GTK_TOOLBAR(object)));
  181 + break;
  182 +
147 default: 183 default:
148 g_assert_not_reached (); 184 g_assert_not_reached ();
149 } 185 }
@@ -158,6 +194,14 @@ @@ -158,6 +194,14 @@
158 pw3270_toolbar_set_actions(GTK_WIDGET(object), g_value_get_string(value)); 194 pw3270_toolbar_set_actions(GTK_WIDGET(object), g_value_get_string(value));
159 break; 195 break;
160 196
  197 + case PROP_ICON_SIZE:
  198 + pw3270_toolbar_set_icon_size(GTK_TOOLBAR(object),(GtkIconSize) g_value_get_int(value));
  199 + break;
  200 +
  201 + case PROP_STYLE:
  202 + pw3270_toolbar_set_style(GTK_TOOLBAR(object),(GtkToolbarStyle) g_value_get_int(value));
  203 + break;
  204 +
161 default: 205 default:
162 g_assert_not_reached (); 206 g_assert_not_reached ();
163 } 207 }
@@ -185,7 +229,7 @@ @@ -185,7 +229,7 @@
185 229
186 if(gtk_check_menu_item_get_active(menuitem)) { 230 if(gtk_check_menu_item_get_active(menuitem)) {
187 struct style * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style"); 231 struct style * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style");
188 - pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(toolbar), style->style); 232 + pw3270_toolbar_set_style(GTK_TOOLBAR(toolbar), style->style);
189 } 233 }
190 234
191 } 235 }
@@ -247,13 +291,15 @@ @@ -247,13 +291,15 @@
247 gtk_widget_show_all(widget->popup.menu); 291 gtk_widget_show_all(widget->popup.menu);
248 gtk_menu_attach_to_widget(GTK_MENU(widget->popup.menu),GTK_WIDGET(widget),detacher); 292 gtk_menu_attach_to_widget(GTK_MENU(widget->popup.menu),GTK_WIDGET(widget),detacher);
249 293
  294 + /*
250 // Bind settings 295 // Bind settings
251 GSettings *settings = pw3270_application_get_settings(g_application_get_default()); 296 GSettings *settings = pw3270_application_get_settings(g_application_get_default());
252 297
253 if(settings) { 298 if(settings) {
254 - pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-style"));  
255 - pw3270_toolbar_set_icon_size(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-icon-size")); 299 +// pw3270_toolbar_set_style(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-style"));
  300 +// pw3270_toolbar_set_icon_size(GTK_TOOLBAR(widget),g_settings_get_int(settings,"toolbar-icon-size"));
256 } 301 }
  302 + */
257 303
258 } 304 }
259 305
@@ -284,18 +330,17 @@ @@ -284,18 +330,17 @@
284 330
285 } 331 }
286 332
287 - void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style) { 333 + void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style) {
288 334
289 debug("%s(%d)",__FUNCTION__,(int) style); 335 debug("%s(%d)",__FUNCTION__,(int) style);
290 336
  337 + PW3270_TOOLBAR(toolbar)->style = style;
  338 +
291 if(style == GTK_TOOLBAR_DEFAULT_STYLE) 339 if(style == GTK_TOOLBAR_DEFAULT_STYLE)
292 gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar)); 340 gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar));
293 else 341 else
294 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),style); 342 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),style);
295 343
296 - // Store value  
297 - pw3270_settings_set_int("toolbar-style",(int) style);  
298 -  
299 // Update menu 344 // Update menu
300 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar); 345 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar);
301 if(tb && tb->popup.menu) { 346 if(tb && tb->popup.menu) {
@@ -309,6 +354,15 @@ @@ -309,6 +354,15 @@
309 } 354 }
310 } 355 }
311 356
  357 + // Store value
  358 +// pw3270_settings_set_int("toolbar-style",(int) style);
  359 +
  360 + g_object_notify(G_OBJECT(toolbar), "style");
  361 +
  362 + }
  363 +
  364 + GtkToolbarStyle pw3270_toolbar_get_style(GtkToolbar *toolbar) {
  365 + return PW3270_TOOLBAR(toolbar)->style;
312 } 366 }
313 367
314 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) { 368 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) {
@@ -320,9 +374,6 @@ @@ -320,9 +374,6 @@
320 else 374 else
321 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),icon_size); 375 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),icon_size);
322 376
323 - // Store value  
324 - pw3270_settings_set_int("toolbar-icon-size", (gint) icon_size);  
325 -  
326 // Update menu 377 // Update menu
327 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar); 378 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar);
328 if(tb && tb->popup.menu) { 379 if(tb && tb->popup.menu) {
@@ -336,8 +387,26 @@ @@ -336,8 +387,26 @@
336 } 387 }
337 } 388 }
338 389
339 - // gtk_container_foreach(GTK_CONTAINER(toolbar),(GtkCallback) update_child, toolbar); 390 + // Store value
  391 +// pw3270_settings_set_int("toolbar-icon-size", (gint) icon_size);
  392 + g_object_notify(G_OBJECT(toolbar), "icon-size");
  393 +
  394 + }
  395 +
  396 + GtkIconSize pw3270_toolbar_get_icon_size(GtkToolbar *toolbar) {
  397 +
  398 + GValue value = G_VALUE_INIT;
  399 + g_value_init(&value, G_TYPE_BOOLEAN);
  400 + g_object_get_property(G_OBJECT(toolbar),"icon-size-set",&value);
  401 +
  402 + gboolean is_set = g_value_get_boolean(&value);
  403 +
  404 + g_value_unset(&value);
  405 +
  406 + if(is_set)
  407 + return gtk_toolbar_get_icon_size(GTK_TOOLBAR(toolbar));
340 408
  409 + return GTK_ICON_SIZE_INVALID;
341 } 410 }
342 411
343 void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names) { 412 void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names) {
src/objects/window/tools.c
@@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
44 } 44 }
45 */ 45 */
46 46
  47 +/*
47 gboolean pw3270_settings_set_int(const gchar *key, gint value) { 48 gboolean pw3270_settings_set_int(const gchar *key, gint value) {
48 49
49 GSettings * settings = pw3270_application_get_settings(g_application_get_default()); 50 GSettings * settings = pw3270_application_get_settings(g_application_get_default());
@@ -51,4 +52,4 @@ @@ -51,4 +52,4 @@
51 return g_settings_set_int(settings,key,value); 52 return g_settings_set_int(settings,key,value);
52 return FALSE; 53 return FALSE;
53 } 54 }
54 - 55 +*/
src/objects/window/window.c
@@ -298,6 +298,22 @@ @@ -298,6 +298,22 @@
298 G_SETTINGS_BIND_DEFAULT 298 G_SETTINGS_BIND_DEFAULT
299 ); 299 );
300 300
  301 + g_settings_bind(
  302 + settings,
  303 + "toolbar-style",
  304 + window->toolbar,
  305 + "style",
  306 + G_SETTINGS_BIND_DEFAULT
  307 + );
  308 +
  309 + g_settings_bind(
  310 + settings,
  311 + "toolbar-icon-size",
  312 + window->toolbar,
  313 + "icon-size",
  314 + G_SETTINGS_BIND_DEFAULT
  315 + );
  316 +
301 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); 317 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
302 gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); 318 gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
303 319