Commit 5421303d726094d50c7c648035ecaea1f05e541e

Authored by Perry Werneck
1 parent 9306acb3

Toolbar action list is now set from gsettings.

schemas/application.gschema.xml.in
... ... @@ -68,6 +68,12 @@
68 68 <description></description>
69 69 </key>
70 70  
  71 + <key name="toolbar-action-names" type="s">
  72 + <default>'win.copy,win.paste,win.select-all,separator,win.connect,win.disconnect,separator,win.session.properties,win.file.transfer,win.print,app.quit'</default>
  73 + <summary>The toolbar action list</summary>
  74 + <description></description>
  75 + </key>
  76 +
71 77 </schema>
72 78  
73 79 </schemalist>
... ...
src/include/pw3270/toolbar.h
... ... @@ -60,6 +60,8 @@
60 60 GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos);
61 61  
62 62 void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names);
  63 + gchar * pw3270_toolbar_get_actions(GtkWidget *toolbar);
  64 +
63 65  
64 66 void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
65 67 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size);
... ...
src/objects/application/application.c
... ... @@ -155,16 +155,20 @@
155 155 "br.com.bb." PACKAGE_NAME,
156 156 TRUE);
157 157  
158   - g_settings_schema_source_unref(source);
  158 + debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema);
159 159  
160 160 app->settings = g_settings_new_full(schema, NULL, path);
161 161  
  162 + g_settings_schema_source_unref(source);
  163 +
162 164 #else
163 165  
164 166 app->settings = g_settings_new_with_path("br.com.bb." PACKAGE_NAME, path);
165 167  
166 168 #endif // DEBUG
167 169  
  170 + debug("app->settings=%p",app->settings);
  171 +
168 172 }
169 173  
170 174 // Bind properties
... ...
src/objects/toolbar/toolbar.c
... ... @@ -35,6 +35,8 @@
35 35 static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number);
36 36 static void finalize(GObject *object);
37 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);
  39 + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
38 40  
39 41 static const struct icon_size {
40 42 const gchar * label;
... ... @@ -82,8 +84,12 @@
82 84 .label = N_( "Icons & text" ),
83 85 .style = GTK_TOOLBAR_BOTH
84 86 },
85   -};
  87 + };
86 88  
  89 + enum {
  90 + PROP_NONE,
  91 + PROP_ACTION_NAMES,
  92 + };
87 93  
88 94  
89 95 struct _pw3270ToolBar {
... ... @@ -109,14 +115,57 @@
109 115  
110 116 static void pw3270ToolBar_class_init(pw3270ToolBarClass *klass) {
111 117  
  118 + GObjectClass *object_class = G_OBJECT_CLASS(klass);
112 119 GtkToolbarClass * toolbar = GTK_TOOLBAR_CLASS(klass);
113 120  
114 121 toolbar->popup_context_menu = popup_context_menu;
115 122  
116 123 G_OBJECT_CLASS(klass)->finalize = finalize;
117 124  
  125 + object_class->set_property = set_property;
  126 + object_class->get_property = get_property;
  127 +
  128 + g_object_class_install_property(
  129 + object_class,
  130 + PROP_ACTION_NAMES,
  131 + g_param_spec_string ("action-names",
  132 + N_("Action Names"),
  133 + N_("The name of the actions in the toolbar"),
  134 + NULL,
  135 + G_PARAM_READABLE|G_PARAM_WRITABLE)
  136 + );
  137 +
  138 +
118 139 }
119 140  
  141 + void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
  142 +
  143 + switch (prop_id) {
  144 + case PROP_ACTION_NAMES:
  145 + g_value_take_string(value,pw3270_toolbar_get_actions(GTK_WIDGET(object)));
  146 + break;
  147 +
  148 + default:
  149 + g_assert_not_reached ();
  150 + }
  151 +
  152 + }
  153 +
  154 + void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
  155 +
  156 + switch (prop_id)
  157 + {
  158 + case PROP_ACTION_NAMES:
  159 + pw3270_toolbar_set_actions(GTK_WIDGET(object), g_value_get_string(value));
  160 + break;
  161 +
  162 + default:
  163 + g_assert_not_reached ();
  164 + }
  165 +
  166 + }
  167 +
  168 +
120 169 static void detacher(GtkWidget *attach_widget, GtkMenu G_GNUC_UNUSED(*menu)) {
121 170  
122 171 pw3270ToolBar * toolbar = PW3270_TOOLBAR(attach_widget);
... ... @@ -297,17 +346,6 @@
297 346  
298 347 }
299 348  
300   - /*
301   - static void update_child(GtkToolButton *item, GtkWidget *toolbar) {
302   -
303   - if(!GTK_IS_TOOL_BUTTON(item))
304   - return;
305   -
306   - debug("[%s]", gtk_tool_button_get_icon_name(item));
307   -
308   - }
309   - */
310   -
311 349 void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) {
312 350  
313 351 debug("%s(%d)",__FUNCTION__,(int) icon_size);
... ...
src/objects/window/window.c
... ... @@ -154,10 +154,12 @@
154 154  
155 155 {
156 156  
  157 + /*
157 158 pw3270_toolbar_set_actions(
158 159 GTK_WIDGET(widget->toolbar),
159 160 "win.copy,win.paste,win.select-all,separator,win.connect,win.disconnect,separator,win.session.properties,win.file.transfer,win.print,app.quit"
160 161 );
  162 + */
161 163  
162 164 g_action_map_add_action(
163 165 G_ACTION_MAP(widget),
... ... @@ -169,8 +171,8 @@
169 171 G_ACTION(g_property_action_new("menubar", widget, "show-menubar"))
170 172 );
171 173  
172   - g_autofree gchar * action_names = pw3270_toolbar_get_actions(GTK_WIDGET(widget->toolbar));
173   - debug("[%s]",action_names);
  174 + //g_autofree gchar * action_names = pw3270_toolbar_get_actions(GTK_WIDGET(widget->toolbar));
  175 + //debug("[%s]",action_names);
174 176  
175 177 }
176 178  
... ... @@ -183,6 +185,8 @@
183 185  
184 186 g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application));
185 187  
  188 + debug("*************** settings=%p",settings);
  189 +
186 190 g_return_val_if_fail(GTK_IS_APPLICATION(application), NULL);
187 191 pw3270ApplicationWindow * window =
188 192 g_object_new(
... ... @@ -276,6 +280,14 @@
276 280 G_SETTINGS_BIND_DEFAULT
277 281 );
278 282  
  283 + g_settings_bind(
  284 + settings,
  285 + "toolbar-action-names",
  286 + window->toolbar,
  287 + "action-names",
  288 + G_SETTINGS_BIND_DEFAULT
  289 + );
  290 +
279 291 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
280 292 gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
281 293  
... ...