Commit 3e708c90d36f2b064363af0155fb4205b3ca356b
1 parent
726bfb70
Exists in
master
and in
4 other branches
Setting UI type as an application property.
Showing
4 changed files
with
90 additions
and
19 deletions
Show diff stats
src/include/pw3270/application.h
| @@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
| 50 | #define PW3270_IS_APPLICATION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ | 50 | #define PW3270_IS_APPLICATION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ |
| 51 | PW3270_TYPE_APPLICATION)) | 51 | PW3270_TYPE_APPLICATION)) |
| 52 | #define PW3270_APPLICATION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \ | 52 | #define PW3270_APPLICATION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \ |
| 53 | - GTK_TYPE_APPLICATION, pw3270ApplicationClass)) | 53 | + GTK_TYPE_APPLICATION, pw3270ApplicationClass)) |
| 54 | 54 | ||
| 55 | typedef enum _pw3270_ui_type { | 55 | typedef enum _pw3270_ui_type { |
| 56 | PW3270_UI_STYLE_CLASSICAL, ///< @brief Interface "classica", com menu e toolbar. | 56 | PW3270_UI_STYLE_CLASSICAL, ///< @brief Interface "classica", com menu e toolbar. |
| @@ -63,6 +63,8 @@ | @@ -63,6 +63,8 @@ | ||
| 63 | 63 | ||
| 64 | GType pw3270Application_get_type(); | 64 | GType pw3270Application_get_type(); |
| 65 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags); | 65 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags); |
| 66 | + | ||
| 67 | + void pw3270_application_set_ui_type(GApplication *app, PW3270_UI_TYPE type); | ||
| 66 | PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app); | 68 | PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app); |
| 67 | 69 | ||
| 68 | G_END_DECLS | 70 | G_END_DECLS |
src/objects/window/application.c
| @@ -34,12 +34,24 @@ | @@ -34,12 +34,24 @@ | ||
| 34 | #include "private.h" | 34 | #include "private.h" |
| 35 | #include <pw3270/application.h> | 35 | #include <pw3270/application.h> |
| 36 | 36 | ||
| 37 | + enum { | ||
| 38 | + PROP_ZERO, | ||
| 39 | + PROP_UI_TYPE, | ||
| 40 | + | ||
| 41 | + NUM_PROPERTIES | ||
| 42 | + }; | ||
| 43 | + | ||
| 44 | + static GParamSpec * props[NUM_PROPERTIES]; | ||
| 45 | + | ||
| 37 | struct _pw3270ApplicationClass { | 46 | struct _pw3270ApplicationClass { |
| 38 | GtkApplicationClass parent_class; | 47 | GtkApplicationClass parent_class; |
| 39 | }; | 48 | }; |
| 40 | 49 | ||
| 41 | struct _pw3270Application { | 50 | struct _pw3270Application { |
| 42 | GtkApplication parent; | 51 | GtkApplication parent; |
| 52 | + | ||
| 53 | + PW3270_UI_TYPE ui_type; | ||
| 54 | + | ||
| 43 | }; | 55 | }; |
| 44 | 56 | ||
| 45 | static void startup(GApplication * application); | 57 | static void startup(GApplication * application); |
| @@ -48,18 +60,71 @@ | @@ -48,18 +60,71 @@ | ||
| 48 | 60 | ||
| 49 | G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); | 61 | G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); |
| 50 | 62 | ||
| 63 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { | ||
| 64 | + | ||
| 65 | + switch (prop_id) { | ||
| 66 | + case PROP_UI_TYPE: | ||
| 67 | + g_value_set_uint(value,pw3270_application_get_ui_type(G_APPLICATION(object))); | ||
| 68 | + break; | ||
| 69 | + | ||
| 70 | + default: | ||
| 71 | + g_assert_not_reached (); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { | ||
| 77 | + | ||
| 78 | + switch (prop_id) { | ||
| 79 | + case PROP_UI_TYPE: | ||
| 80 | + pw3270_application_set_ui_type(G_APPLICATION(object),g_value_get_uint(value)); | ||
| 81 | + break; | ||
| 82 | + | ||
| 83 | + default: | ||
| 84 | + g_assert_not_reached (); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + } | ||
| 88 | + | ||
| 51 | static void pw3270Application_class_init(pw3270ApplicationClass *klass) { | 89 | static void pw3270Application_class_init(pw3270ApplicationClass *klass) { |
| 52 | 90 | ||
| 53 | GApplicationClass *application_class = G_APPLICATION_CLASS(klass); | 91 | GApplicationClass *application_class = G_APPLICATION_CLASS(klass); |
| 92 | + GObjectClass *object_class = G_OBJECT_CLASS(klass); | ||
| 93 | + | ||
| 94 | + object_class->get_property = get_property; | ||
| 95 | + object_class->set_property = set_property; | ||
| 54 | 96 | ||
| 55 | application_class->startup = startup; | 97 | application_class->startup = startup; |
| 56 | application_class->activate = activate; | 98 | application_class->activate = activate; |
| 57 | application_class->open = open; | 99 | application_class->open = open; |
| 58 | 100 | ||
| 101 | + props[PROP_UI_TYPE] = | ||
| 102 | + g_param_spec_uint( | ||
| 103 | + "ui_type", | ||
| 104 | + _("UI Type"), | ||
| 105 | + _("The code of the User interface type"), | ||
| 106 | + PW3270_UI_STYLE_CLASSICAL, | ||
| 107 | + PW3270_UI_STYLE_GNOME, | ||
| 108 | +#ifdef _WIN32 | ||
| 109 | + PW3270_UI_STYLE_CLASSICAL, | ||
| 110 | +#else | ||
| 111 | + PW3270_UI_STYLE_GNOME, | ||
| 112 | +#endif // _WIN32 | ||
| 113 | + G_PARAM_READABLE|G_PARAM_WRITABLE | ||
| 114 | + ); | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + g_object_class_install_properties(object_class, NUM_PROPERTIES, props); | ||
| 118 | + | ||
| 59 | } | 119 | } |
| 60 | 120 | ||
| 61 | static void pw3270Application_init(pw3270Application *app) { | 121 | static void pw3270Application_init(pw3270Application *app) { |
| 62 | 122 | ||
| 123 | +#ifdef _WIN32 | ||
| 124 | + app->ui_type = PW3270_UI_STYLE_CLASSICAL; | ||
| 125 | +#else | ||
| 126 | + app->ui_type = PW3270_UI_STYLE_GNOME; | ||
| 127 | +#endif // _WIN32 | ||
| 63 | 128 | ||
| 64 | } | 129 | } |
| 65 | 130 | ||
| @@ -179,3 +244,24 @@ | @@ -179,3 +244,24 @@ | ||
| 179 | 244 | ||
| 180 | } | 245 | } |
| 181 | 246 | ||
| 247 | + void pw3270_application_set_ui_type(GApplication *app, PW3270_UI_TYPE type) { | ||
| 248 | + | ||
| 249 | + g_return_if_fail(PW3270_IS_APPLICATION(app)); | ||
| 250 | + | ||
| 251 | + pw3270Application * application = PW3270_APPLICATION(app); | ||
| 252 | + | ||
| 253 | + if(application->ui_type == type) | ||
| 254 | + return; | ||
| 255 | + | ||
| 256 | + application->ui_type = type; | ||
| 257 | + g_object_notify_by_pspec(G_OBJECT(app), props[PROP_UI_TYPE]); | ||
| 258 | + | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app) { | ||
| 262 | + | ||
| 263 | + g_return_val_if_fail(PW3270_IS_APPLICATION(app),PW3270_UI_STYLE_CLASSICAL); | ||
| 264 | + return PW3270_APPLICATION(app)->ui_type; | ||
| 265 | + | ||
| 266 | + } | ||
| 267 | + |
src/objects/window/testprogram/testprogram.c
src/objects/window/window.c
| @@ -35,20 +35,6 @@ | @@ -35,20 +35,6 @@ | ||
| 35 | 35 | ||
| 36 | static void pw3270ApplicationWindow_class_init(pw3270ApplicationWindowClass *klass) { | 36 | static void pw3270ApplicationWindow_class_init(pw3270ApplicationWindowClass *klass) { |
| 37 | 37 | ||
| 38 | - /* | ||
| 39 | - window_props[PROP_UI_STYLE] = | ||
| 40 | - g_param_spec_uint ( | ||
| 41 | - "ui_style", // P_() | ||
| 42 | - "ui_style", // P_() | ||
| 43 | - _( "The application interface style" ), | ||
| 44 | - PW3270_UI_STYLE_CLASSICAL, | ||
| 45 | - PW3270_UI_STYLE_GNOME, | ||
| 46 | - PW3270_UI_STYLE_GNOME, | ||
| 47 | - G_PARAM_READABLE | ||
| 48 | - ); | ||
| 49 | - */ | ||
| 50 | - | ||
| 51 | - | ||
| 52 | } | 38 | } |
| 53 | 39 | ||
| 54 | static void pw3270ApplicationWindow_init(pw3270ApplicationWindow *widget) { | 40 | static void pw3270ApplicationWindow_init(pw3270ApplicationWindow *widget) { |
| @@ -141,7 +127,7 @@ | @@ -141,7 +127,7 @@ | ||
| 141 | 127 | ||
| 142 | // Create "new tab" bar | 128 | // Create "new tab" bar |
| 143 | GtkWidget * new_tab_button = pw3270_setup_image_button(gtk_button_new(),"tab-new-symbolic"); | 129 | GtkWidget * new_tab_button = pw3270_setup_image_button(gtk_button_new(),"tab-new-symbolic"); |
| 144 | - gtk_actionable_set_action_name(GTK_ACTIONABLE(new_tab_button),"app.new_tab"); | 130 | + gtk_actionable_set_action_name(GTK_ACTIONABLE(new_tab_button),"app.new.tab"); |
| 145 | gtk_header_bar_pack_start(header, new_tab_button); | 131 | gtk_header_bar_pack_start(header, new_tab_button); |
| 146 | 132 | ||
| 147 | // Show the new header | 133 | // Show the new header |