Commit 061296898e15d7ae4ecc1e7b17b9071f72ee154b
1 parent
af9b20f5
Exists in
master
and in
4 other branches
Implementing gsettings support.
Showing
7 changed files
with
89 additions
and
42 deletions
Show diff stats
configure.ac
| ... | ... | @@ -194,6 +194,7 @@ dnl --------------------------------------------------------------------------- |
| 194 | 194 | AC_SUBST(INSTALL_PACKAGES) |
| 195 | 195 | |
| 196 | 196 | AC_CONFIG_FILES(Makefile) |
| 197 | +AC_CONFIG_FILES(schemas/application.gschema.xml) | |
| 197 | 198 | |
| 198 | 199 | dnl --------------------------------------------------------------------------- |
| 199 | 200 | dnl Output the generated config.status script. | ... | ... |
schemas/application.gschema.xml
| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<!-- | |
| 3 | - | |
| 4 | - | |
| 5 | ---> | |
| 6 | - | |
| 7 | -<schemalist> | |
| 8 | - | |
| 9 | - <schema path="/br/com/bb/pw3270/application/" id="br.com.bb.pw3270"> | |
| 10 | - | |
| 11 | - <key name="ui-style" type="u"> | |
| 12 | - <default>1</default> | |
| 13 | - <summary>UI Style</summary> | |
| 14 | - <description>The ID of the current user interface style</description> | |
| 15 | - </key> | |
| 16 | - | |
| 17 | - </schema> | |
| 18 | - | |
| 19 | -</schemalist> |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!-- | |
| 3 | + | |
| 4 | + | |
| 5 | +--> | |
| 6 | + | |
| 7 | +<schemalist> | |
| 8 | + | |
| 9 | + <schema path="/br/com/bb/pw3270/application/" id="br.com.bb.pw3270"> | |
| 10 | + | |
| 11 | + <key name="ui-style" type="u"> | |
| 12 | + <default>1</default> | |
| 13 | + <summary>UI Style</summary> | |
| 14 | + <description>The ID of the current user interface style</description> | |
| 15 | + </key> | |
| 16 | + | |
| 17 | + </schema> | |
| 18 | + | |
| 19 | +</schemalist> | ... | ... |
src/include/pw3270/application.h
| ... | ... | @@ -52,10 +52,10 @@ |
| 52 | 52 | #define PW3270_APPLICATION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \ |
| 53 | 53 | GTK_TYPE_APPLICATION, pw3270ApplicationClass)) |
| 54 | 54 | |
| 55 | - typedef enum _pw3270_ui_type { | |
| 55 | + typedef enum _pw3270_ui_style { | |
| 56 | 56 | PW3270_UI_STYLE_CLASSICAL, ///< @brief Interface "classica", com menu e toolbar. |
| 57 | 57 | PW3270_UI_STYLE_GNOME, ///< @brief Interface padrão gnome. |
| 58 | - } PW3270_UI_TYPE; | |
| 58 | + } PW3270_UI_STYLE; | |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | typedef struct _pw3270ApplicationClass pw3270ApplicationClass; |
| ... | ... | @@ -64,8 +64,8 @@ |
| 64 | 64 | GType pw3270Application_get_type(); |
| 65 | 65 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags); |
| 66 | 66 | |
| 67 | - void pw3270_application_set_ui_type(GApplication *app, PW3270_UI_TYPE type); | |
| 68 | - PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app); | |
| 67 | + void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type); | |
| 68 | + PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app); | |
| 69 | 69 | |
| 70 | 70 | G_END_DECLS |
| 71 | 71 | ... | ... |
src/main/main.c
| ... | ... | @@ -45,6 +45,7 @@ int main (int argc, char **argv) { |
| 45 | 45 | GtkApplication *app; |
| 46 | 46 | int status; |
| 47 | 47 | |
| 48 | +/* | |
| 48 | 49 | #ifdef DEBUG |
| 49 | 50 | { |
| 50 | 51 | GError * error = NULL; |
| ... | ... | @@ -73,8 +74,11 @@ int main (int argc, char **argv) { |
| 73 | 74 | g_object_unref(settings); |
| 74 | 75 | } |
| 75 | 76 | #endif // DEBUG |
| 77 | +*/ | |
| 78 | + | |
| 79 | +// app = pw3270_application_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME),G_APPLICATION_HANDLES_OPEN); | |
| 80 | + app = pw3270_application_new("br.com.bb.pw3270",G_APPLICATION_HANDLES_OPEN); | |
| 76 | 81 | |
| 77 | - app = pw3270_application_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME),G_APPLICATION_HANDLES_OPEN); | |
| 78 | 82 | status = g_application_run(G_APPLICATION (app), argc, argv); |
| 79 | 83 | g_object_unref (app); |
| 80 | 84 | ... | ... |
src/objects/window/application.c
| ... | ... | @@ -36,7 +36,7 @@ |
| 36 | 36 | |
| 37 | 37 | enum { |
| 38 | 38 | PROP_ZERO, |
| 39 | - PROP_UI_TYPE, | |
| 39 | + PROP_UI_STYLE, | |
| 40 | 40 | |
| 41 | 41 | NUM_PROPERTIES |
| 42 | 42 | }; |
| ... | ... | @@ -50,7 +50,7 @@ |
| 50 | 50 | struct _pw3270Application { |
| 51 | 51 | GtkApplication parent; |
| 52 | 52 | |
| 53 | - PW3270_UI_TYPE ui_type; | |
| 53 | + PW3270_UI_STYLE ui_style; | |
| 54 | 54 | |
| 55 | 55 | }; |
| 56 | 56 | |
| ... | ... | @@ -63,8 +63,8 @@ |
| 63 | 63 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { |
| 64 | 64 | |
| 65 | 65 | switch (prop_id) { |
| 66 | - case PROP_UI_TYPE: | |
| 67 | - g_value_set_uint(value,pw3270_application_get_ui_type(G_APPLICATION(object))); | |
| 66 | + case PROP_UI_STYLE: | |
| 67 | + g_value_set_uint(value,pw3270_application_get_ui_style(G_APPLICATION(object))); | |
| 68 | 68 | break; |
| 69 | 69 | |
| 70 | 70 | default: |
| ... | ... | @@ -76,8 +76,8 @@ |
| 76 | 76 | static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { |
| 77 | 77 | |
| 78 | 78 | switch (prop_id) { |
| 79 | - case PROP_UI_TYPE: | |
| 80 | - pw3270_application_set_ui_type(G_APPLICATION(object),g_value_get_uint(value)); | |
| 79 | + case PROP_UI_STYLE: | |
| 80 | + pw3270_application_set_ui_style(G_APPLICATION(object),g_value_get_uint(value)); | |
| 81 | 81 | break; |
| 82 | 82 | |
| 83 | 83 | default: |
| ... | ... | @@ -98,9 +98,9 @@ |
| 98 | 98 | application_class->activate = activate; |
| 99 | 99 | application_class->open = open; |
| 100 | 100 | |
| 101 | - props[PROP_UI_TYPE] = | |
| 101 | + props[PROP_UI_STYLE] = | |
| 102 | 102 | g_param_spec_uint( |
| 103 | - "ui_type", | |
| 103 | + "ui-style", | |
| 104 | 104 | _("UI Type"), |
| 105 | 105 | _("The code of the User interface type"), |
| 106 | 106 | PW3270_UI_STYLE_CLASSICAL, |
| ... | ... | @@ -121,11 +121,53 @@ |
| 121 | 121 | static void pw3270Application_init(pw3270Application *app) { |
| 122 | 122 | |
| 123 | 123 | #ifdef _WIN32 |
| 124 | - app->ui_type = PW3270_UI_STYLE_CLASSICAL; | |
| 124 | + app->ui_style = PW3270_UI_STYLE_CLASSICAL; | |
| 125 | 125 | #else |
| 126 | - app->ui_type = PW3270_UI_STYLE_GNOME; | |
| 126 | + app->ui_style = PW3270_UI_STYLE_GNOME; | |
| 127 | 127 | #endif // _WIN32 |
| 128 | 128 | |
| 129 | + // Bind properties | |
| 130 | + GSettings * settings = NULL; | |
| 131 | + | |
| 132 | +#ifdef DEBUG | |
| 133 | + { | |
| 134 | + GError * error = NULL; | |
| 135 | + GSettingsSchemaSource * source = | |
| 136 | + g_settings_schema_source_new_from_directory( | |
| 137 | + ".", | |
| 138 | + NULL, | |
| 139 | + TRUE, | |
| 140 | + &error | |
| 141 | + ); | |
| 142 | + | |
| 143 | + g_assert_no_error(error); | |
| 144 | + | |
| 145 | + GSettingsSchema * schema = | |
| 146 | + g_settings_schema_source_lookup( | |
| 147 | + source, | |
| 148 | + "br.com.bb.pw3270", | |
| 149 | + TRUE); | |
| 150 | + | |
| 151 | + g_settings_schema_source_unref(source); | |
| 152 | + | |
| 153 | + settings = g_settings_new_full(schema, NULL, "/br/com/bb/pw3270/application/"); | |
| 154 | + | |
| 155 | + } | |
| 156 | +#else | |
| 157 | + | |
| 158 | + #error TODO! | |
| 159 | + | |
| 160 | +#endif // DEBUG | |
| 161 | + | |
| 162 | + if(settings) { | |
| 163 | + | |
| 164 | + g_settings_bind(settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); | |
| 165 | + | |
| 166 | + | |
| 167 | + g_object_unref(settings); | |
| 168 | + | |
| 169 | + } | |
| 170 | + | |
| 129 | 171 | } |
| 130 | 172 | |
| 131 | 173 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags) { |
| ... | ... | @@ -200,7 +242,7 @@ |
| 200 | 242 | GtkBuilder * builder = gtk_builder_new_from_file("ui/application.xml"); |
| 201 | 243 | gtk_application_set_app_menu(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "app-menu"))); |
| 202 | 244 | |
| 203 | - if(pw3270_application_get_ui_type(application) == PW3270_UI_STYLE_CLASSICAL) | |
| 245 | + if(pw3270_application_get_ui_style(application) == PW3270_UI_STYLE_CLASSICAL) | |
| 204 | 246 | gtk_application_set_menubar(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "menubar"))); |
| 205 | 247 | |
| 206 | 248 | g_object_unref(builder); |
| ... | ... | @@ -244,24 +286,24 @@ |
| 244 | 286 | |
| 245 | 287 | } |
| 246 | 288 | |
| 247 | - void pw3270_application_set_ui_type(GApplication *app, PW3270_UI_TYPE type) { | |
| 289 | + void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type) { | |
| 248 | 290 | |
| 249 | 291 | g_return_if_fail(PW3270_IS_APPLICATION(app)); |
| 250 | 292 | |
| 251 | 293 | pw3270Application * application = PW3270_APPLICATION(app); |
| 252 | 294 | |
| 253 | - if(application->ui_type == type) | |
| 295 | + if(application->ui_style == type) | |
| 254 | 296 | return; |
| 255 | 297 | |
| 256 | - application->ui_type = type; | |
| 257 | - g_object_notify_by_pspec(G_OBJECT(app), props[PROP_UI_TYPE]); | |
| 298 | + application->ui_style = type; | |
| 299 | + g_object_notify_by_pspec(G_OBJECT(app), props[PROP_UI_STYLE]); | |
| 258 | 300 | |
| 259 | 301 | } |
| 260 | 302 | |
| 261 | - PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app) { | |
| 303 | + PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app) { | |
| 262 | 304 | |
| 263 | 305 | g_return_val_if_fail(PW3270_IS_APPLICATION(app),PW3270_UI_STYLE_CLASSICAL); |
| 264 | - return PW3270_APPLICATION(app)->ui_type; | |
| 306 | + return PW3270_APPLICATION(app)->ui_style; | |
| 265 | 307 | |
| 266 | 308 | } |
| 267 | 309 | ... | ... |
src/objects/window/window.c
| ... | ... | @@ -108,7 +108,7 @@ |
| 108 | 108 | |
| 109 | 109 | GtkBuilder * builder = gtk_builder_new_from_file("ui/window.xml"); |
| 110 | 110 | |
| 111 | - switch(pw3270_application_get_ui_type(G_APPLICATION(application))) { | |
| 111 | + switch(pw3270_application_get_ui_style(G_APPLICATION(application))) { | |
| 112 | 112 | case PW3270_UI_STYLE_CLASSICAL: |
| 113 | 113 | { |
| 114 | 114 | gtk_window_set_title(GTK_WINDOW(window), title); | ... | ... |