Commit 2d0cb1b17ecc87459918b3f8067a223e883e14be
1 parent
2fae538c
Exists in
master
and in
4 other branches
Adding option to switch the user interface.
Showing
3 changed files
with
109 additions
and
37 deletions
Show diff stats
branding/launcher.desktop.in
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | X-SuSE-translate=true |
3 | 3 | GenericName=@PRODUCT_NAME@ |
4 | 4 | Name=3270 Terminal |
5 | +Name[pt_BR]=Terminal 3270 | |
5 | 6 | Comment=@PACKAGE_DESCRIPTION@ |
6 | 7 | Exec=@PRODUCT_NAME@ |
7 | 8 | Icon=@PRODUCT_NAME@ |
... | ... | @@ -9,6 +10,20 @@ Terminal=false |
9 | 10 | Type=Application |
10 | 11 | StartupNotify=true |
11 | 12 | |
13 | +Actions=gnomeui;classicalui | |
14 | + | |
12 | 15 | # https://specifications.freedesktop.org/menu-spec/menu-spec-1.0.html |
13 | 16 | Categories=System;TerminalEmulator; |
14 | 17 | |
18 | +[Desktop Action gnomeui] | |
19 | +Name=New window using modern user interface | |
20 | +Name[pt_BR]=Nova janela usando a interface de usuário atualizada | |
21 | + | |
22 | +Exec=@PRODUCT_NAME@ --user-interface=gnome | |
23 | + | |
24 | +[Desktop Action classicalui] | |
25 | +Name=New window using classical user interface | |
26 | +Name[pt_BR]=Nova janela usando a interface de usuário clássica | |
27 | + | |
28 | +Exec=@PRODUCT_NAME@ --user-interface=classic | |
29 | + | ... | ... |
src/objects/application/application.c
... | ... | @@ -171,48 +171,70 @@ |
171 | 171 | |
172 | 172 | } |
173 | 173 | |
174 | - static void pw3270Application_init(pw3270Application *app) { | |
175 | 174 | |
176 | -#ifdef _WIN32 | |
177 | - app->ui_style = PW3270_UI_STYLE_CLASSICAL; | |
178 | -#else | |
179 | - app->ui_style = PW3270_UI_STYLE_AUTOMATIC; | |
180 | -#endif // _WIN32 | |
175 | + static gboolean on_user_interface(const gchar G_GNUC_UNUSED(*option), const gchar *value, gpointer G_GNUC_UNUSED(dunno), GError **error) { | |
181 | 176 | |
182 | - // Get settings | |
183 | - { | |
184 | - g_autofree gchar * path = g_strconcat("/apps/" PACKAGE_NAME "/", g_get_application_name(),"/",NULL); | |
185 | - debug("path=%s",path); | |
177 | + GApplication * app = g_application_get_default(); | |
186 | 178 | |
187 | -#ifdef DEBUG | |
188 | - GError * error = NULL; | |
189 | - GSettingsSchemaSource * source = | |
190 | - g_settings_schema_source_new_from_directory( | |
191 | - ".", | |
192 | - NULL, | |
193 | - TRUE, | |
194 | - &error | |
195 | - ); | |
179 | + debug("********************* %p",app); | |
180 | + | |
181 | + g_autoptr(GSettings) app_settings = pw3270_application_settings_new(); | |
182 | + g_autoptr(GSettings) win_settings = pw3270_application_window_settings_new(); | |
183 | + | |
184 | + if(!g_ascii_strcasecmp(value,"gnome")) { | |
185 | + | |
186 | + g_settings_set_uint(app_settings,"ui-style",PW3270_UI_STYLE_GNOME); | |
187 | + g_settings_set_boolean(win_settings,"toolbar-visible",TRUE); | |
188 | + g_settings_set_boolean(win_settings,"menubar-visible",FALSE); | |
189 | + | |
190 | + } else if(!g_ascii_strcasecmp(value,"classic")) { | |
191 | + | |
192 | + g_settings_set_uint(app_settings,"ui-style",PW3270_UI_STYLE_CLASSICAL); | |
193 | + g_settings_set_boolean(win_settings,"toolbar-visible",TRUE); | |
194 | + g_settings_set_boolean(win_settings,"menubar-visible",TRUE); | |
195 | + | |
196 | + } else if(!g_ascii_strcasecmp(value,"default")) { | |
196 | 197 | |
197 | - g_assert_no_error(error); | |
198 | + g_settings_set_uint(app_settings,"ui-style",PW3270_UI_STYLE_AUTOMATIC); | |
198 | 199 | |
199 | - GSettingsSchema * schema = | |
200 | - g_settings_schema_source_lookup( | |
201 | - source, | |
202 | - "br.com.bb." PACKAGE_NAME, | |
203 | - TRUE); | |
200 | + } else { | |
204 | 201 | |
205 | - debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema); | |
202 | + g_set_error( | |
203 | + error, | |
204 | + g_quark_from_static_string(G_STRINGIFY(PRODUCT_NAME)), | |
205 | + EINVAL, | |
206 | + _( "\"%s\" is not a valid user interface name" ), value | |
207 | + ); | |
208 | + | |
209 | + } | |
210 | + | |
211 | + return TRUE; | |
212 | + | |
213 | + } | |
214 | + | |
215 | + static void pw3270Application_init(pw3270Application *app) { | |
206 | 216 | |
207 | - app->settings = g_settings_new_full(schema, NULL, path); | |
217 | + static GOptionEntry cmd_options[] = { | |
208 | 218 | |
209 | - g_settings_schema_source_unref(source); | |
219 | + { "user-interface", 'U', 0, G_OPTION_ARG_CALLBACK, &on_user_interface, N_( "Set the user-interface type" ), NULL }, | |
220 | + { NULL } | |
210 | 221 | |
222 | + }; | |
223 | + | |
224 | + g_application_add_main_option_entries(G_APPLICATION(app), cmd_options); | |
225 | + | |
226 | +#ifdef _WIN32 | |
227 | + app->ui_style = PW3270_UI_STYLE_CLASSICAL; | |
211 | 228 | #else |
229 | + app->ui_style = PW3270_UI_STYLE_AUTOMATIC; | |
230 | +#endif // _WIN32 | |
212 | 231 | |
213 | - app->settings = g_settings_new_with_path("br.com.bb." PACKAGE_NAME, path); | |
232 | + // Get settings | |
233 | + app->settings = pw3270_application_settings_new(); | |
214 | 234 | |
215 | -#endif // DEBUG | |
235 | + // Bind properties | |
236 | + if(app->settings) { | |
237 | + g_object_ref_sink(G_OBJECT(app->settings)); | |
216 | 238 | |
217 | 239 | #ifdef _WIN32 |
218 | 240 | { |
... | ... | @@ -225,13 +247,6 @@ |
225 | 247 | } |
226 | 248 | #endif // _WIN32 |
227 | 249 | |
228 | - debug("app->settings=%p",app->settings); | |
229 | - | |
230 | - } | |
231 | - | |
232 | - // Bind properties | |
233 | - if(app->settings) { | |
234 | - g_object_ref_sink(G_OBJECT(app->settings)); | |
235 | 250 | g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); |
236 | 251 | } |
237 | 252 | |
... | ... | @@ -420,6 +435,47 @@ |
420 | 435 | |
421 | 436 | } |
422 | 437 | |
438 | + GSettings * pw3270_application_settings_new() { | |
439 | + | |
440 | + GSettings *settings = NULL; | |
441 | + | |
442 | + g_autofree gchar * path = g_strconcat("/apps/" PACKAGE_NAME "/", g_get_application_name(),"/",NULL); | |
443 | + debug("path=%s",path); | |
444 | + | |
445 | +#ifdef DEBUG | |
446 | + GError * error = NULL; | |
447 | + GSettingsSchemaSource * source = | |
448 | + g_settings_schema_source_new_from_directory( | |
449 | + ".", | |
450 | + NULL, | |
451 | + TRUE, | |
452 | + &error | |
453 | + ); | |
454 | + | |
455 | + g_assert_no_error(error); | |
456 | + | |
457 | + GSettingsSchema * schema = | |
458 | + g_settings_schema_source_lookup( | |
459 | + source, | |
460 | + "br.com.bb." PACKAGE_NAME, | |
461 | + TRUE); | |
462 | + | |
463 | + debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema); | |
464 | + | |
465 | + settings = g_settings_new_full(schema, NULL, path); | |
466 | + | |
467 | + g_settings_schema_source_unref(source); | |
468 | + | |
469 | +#else | |
470 | + | |
471 | + settings = g_settings_new_with_path("br.com.bb." PACKAGE_NAME, path); | |
472 | + | |
473 | +#endif // DEBUG | |
474 | + | |
475 | + return settings; | |
476 | + } | |
477 | + | |
478 | + | |
423 | 479 | /* |
424 | 480 | void pw3270_application_plugin_foreach(GApplication *app, GFunc func, gpointer user_data) { |
425 | 481 | ... | ... |
src/objects/application/private.h
... | ... | @@ -48,6 +48,7 @@ |
48 | 48 | |
49 | 49 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); |
50 | 50 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); |
51 | + G_GNUC_INTERNAL GSettings * pw3270_application_settings_new(); | |
51 | 52 | |
52 | 53 | // Actions |
53 | 54 | G_GNUC_INTERNAL GAction * pw3270_about_action_new(); | ... | ... |