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 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);
  72 +// gboolean pw3270_settings_set_int(const gchar *key, gint value);
73 73  
74 74  
75 75 // Tools
... ...
src/include/pw3270/toolbar.h
... ... @@ -66,6 +66,9 @@
66 66 void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
67 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 72 G_END_DECLS
70 73  
71 74 #endif // PW3270_TOOLBAR_H_INCLUDED
... ...
src/objects/toolbar/toolbar.c
... ... @@ -34,7 +34,6 @@
34 34  
35 35 static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number);
36 36 static void finalize(GObject *object);
37   - static void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
38 37 static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
39 38 static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
40 39  
... ... @@ -89,10 +88,13 @@
89 88 enum {
90 89 PROP_NONE,
91 90 PROP_ACTION_NAMES,
  91 + PROP_ICON_SIZE,
  92 + PROP_STYLE
92 93 };
93 94  
94 95 struct _pw3270ToolBar {
95 96 GtkToolbar parent;
  97 + GtkToolbarStyle style;
96 98  
97 99 /// @brief Popup Menu
98 100 struct {
... ... @@ -127,13 +129,39 @@
127 129 g_object_class_install_property(
128 130 object_class,
129 131 PROP_ACTION_NAMES,
130   - g_param_spec_string ("action-names",
  132 + g_param_spec_string (
  133 + "action-names",
131 134 N_("Action Names"),
132 135 N_("The name of the actions in the toolbar"),
133 136 NULL,
134 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 172 g_value_take_string(value,pw3270_toolbar_get_actions(GTK_WIDGET(object)));
145 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 183 default:
148 184 g_assert_not_reached ();
149 185 }
... ... @@ -158,6 +194,14 @@
158 194 pw3270_toolbar_set_actions(GTK_WIDGET(object), g_value_get_string(value));
159 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 205 default:
162 206 g_assert_not_reached ();
163 207 }
... ... @@ -185,7 +229,7 @@
185 229  
186 230 if(gtk_check_menu_item_get_active(menuitem)) {
187 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 291 gtk_widget_show_all(widget->popup.menu);
248 292 gtk_menu_attach_to_widget(GTK_MENU(widget->popup.menu),GTK_WIDGET(widget),detacher);
249 293  
  294 + /*
250 295 // Bind settings
251 296 GSettings *settings = pw3270_application_get_settings(g_application_get_default());
252 297  
253 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 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 335 debug("%s(%d)",__FUNCTION__,(int) style);
290 336  
  337 + PW3270_TOOLBAR(toolbar)->style = style;
  338 +
291 339 if(style == GTK_TOOLBAR_DEFAULT_STYLE)
292 340 gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar));
293 341 else
294 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 344 // Update menu
300 345 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar);
301 346 if(tb && tb->popup.menu) {
... ... @@ -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 368 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) {
... ... @@ -320,9 +374,6 @@
320 374 else
321 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 377 // Update menu
327 378 pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar);
328 379 if(tb && tb->popup.menu) {
... ... @@ -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 412 void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names) {
... ...
src/objects/window/tools.c
... ... @@ -44,6 +44,7 @@
44 44 }
45 45 */
46 46  
  47 +/*
47 48 gboolean pw3270_settings_set_int(const gchar *key, gint value) {
48 49  
49 50 GSettings * settings = pw3270_application_get_settings(g_application_get_default());
... ... @@ -51,4 +52,4 @@
51 52 return g_settings_set_int(settings,key,value);
52 53 return FALSE;
53 54 }
54   -
  55 +*/
... ...
src/objects/window/window.c
... ... @@ -298,6 +298,22 @@
298 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 317 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
302 318 gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
303 319  
... ...