diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-05-11 22:45:51 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-05-14 18:24:03 -0300 |
commit | 50094b45a67b4266532f34433001ca110b7a95ce (patch) | |
tree | 082bee414824e8ce0edfb67f9e1d5232e353f5c2 | |
parent | 7322cdc45bc5b23b99e1ccaced8c554554f98af3 (diff) | |
download | gnome-control-center-50094b45a67b4266532f34433001ca110b7a95ce.tar.gz |
window: Warn about development builds
With this commit, a message dialog pops up whenever a
development build runs. This is meant to actually annoy,
so that we're always reminded that things may not work
as expected.
Since the dialog can be dismissed with a single button
press, it is not the end of the world. But people still
should be aware that Settings is ~not~ meant to run with
Flatpak, and that this is a development tool only.
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | meson_options.txt | 2 | ||||
-rw-r--r-- | shell/cc-window.c | 74 | ||||
-rw-r--r-- | shell/org.gnome.ControlCenter.gschema.xml | 7 | ||||
-rw-r--r-- | shell/window.ui | 13 |
5 files changed, 96 insertions, 2 deletions
diff --git a/meson.build b/meson.build index 340e2004e..a61acc9c4 100644 --- a/meson.build +++ b/meson.build @@ -282,4 +282,4 @@ output += ' NetworkManager (Network panel) ............. ' + host_is_linux.t output += ' Wacom (Wacom tablet panel) ................. ' + host_is_linux_not_s390.to_string() + '\n' output += ' Wayland .................................... ' + enable_wayland.to_string() + '\n' -message(output) +message(output)
\ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt index a01c11553..a347168b7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,4 +3,4 @@ option('documentation', type: 'boolean', value: false, description: 'build docum option('gnome_session_libexecdir', type: 'string', value: '', description: 'Directory for gnome-session\'s libexecdir') option('ibus', type: 'boolean', value: true, description: 'build with IBus support') option('tracing', type: 'boolean', value: false, description: 'add extra debugging information') -option('wayland', type: 'boolean', value: true, description: 'build with Wayland support') +option('wayland', type: 'boolean', value: true, description: 'build with Wayland support')
\ No newline at end of file diff --git a/shell/cc-window.c b/shell/cc-window.c index f8dbc0ffb..50d3995d7 100644 --- a/shell/cc-window.c +++ b/shell/cc-window.c @@ -65,6 +65,7 @@ struct _CcWindow GtkWidget *search_entry; GtkWidget *lock_button; GtkWidget *current_panel_box; + GtkWidget *development_warning_dialog; GtkWidget *current_panel; char *current_panel_id; GQueue *previous_panels; @@ -91,6 +92,47 @@ enum }; /* Auxiliary methods */ +static gboolean +in_flatpak_sandbox (void) +{ + return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS); +} + +static void +add_development_build_css (CcWindow *self) +{ + g_autoptr(GtkCssProvider) provider = NULL; + g_autoptr(GError) error = NULL; + + /* This CSS snipped is added on development builds of GNOME Settings. It is + * not meant to be beautiful (althout it is) and is only supposed to integrate + * with Adwaita light (although it integrates well with dark too). + */ + + const gchar *development_build_css = + "window.development-version headerbar {\n" + " background: @theme_bg_color linear-gradient(to top,\n" + " alpha(@theme_selected_bg_color, 0.34),\n" + " alpha(@theme_selected_bg_color, 0.27) 2px,\n" + " alpha(@theme_selected_bg_color, 0.20) 3px);\n" + "}"; + + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "development-version"); + + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, development_build_css, -1, &error); + + if (error) + { + g_error ("Failed to load CSS: %s", error->message); + return; + } + + gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (self)), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); +} + static gchar * get_symbolic_icon_name_from_g_icon (GIcon *gicon) { @@ -580,6 +622,17 @@ split_decorations_cb (GtkSettings *settings, gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (self->panel_headerbar), layout_end); } +static void +on_development_warning_dialog_responded_cb (GtkWidget *dialog, + gint response, + CcWindow *self) +{ + g_debug ("Disabling development build warning dialog"); + g_settings_set_boolean (self->settings, "show-development-warning", FALSE); + + gtk_widget_hide (dialog); +} + /* CcShell implementation */ static gboolean cc_window_set_active_panel_from_id (CcShell *shell, @@ -618,6 +671,19 @@ cc_shell_iface_init (CcShellInterface *iface) iface->get_toplevel = cc_window_get_toplevel; } +/* GtkWidget overrides */ +static void +cc_window_map (GtkWidget *widget) +{ + CcWindow *self = (CcWindow *) widget; + + GTK_WIDGET_CLASS (cc_window_parent_class)->map (widget); + + /* Show a warning for Flatpak builds */ + if (in_flatpak_sandbox () && g_settings_get_boolean (self->settings, "show-development-warning")) + gtk_window_present (GTK_WINDOW (self->development_warning_dialog)); +} + /* GObject Implementation */ static void cc_window_get_property (GObject *object, @@ -695,10 +761,13 @@ cc_window_class_init (CcWindowClass *klass) object_class->dispose = cc_window_dispose; object_class->finalize = cc_window_finalize; + widget_class->map = cc_window_map; + g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel"); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/gtk/window.ui"); + gtk_widget_class_bind_template_child (widget_class, CcWindow, development_warning_dialog); gtk_widget_class_bind_template_child (widget_class, CcWindow, header); gtk_widget_class_bind_template_child (widget_class, CcWindow, header_box); gtk_widget_class_bind_template_child (widget_class, CcWindow, header_sizegroup); @@ -714,6 +783,7 @@ cc_window_class_init (CcWindowClass *klass) gtk_widget_class_bind_template_child (widget_class, CcWindow, top_right_box); gtk_widget_class_bind_template_callback (widget_class, gdk_window_set_cb); + gtk_widget_class_bind_template_callback (widget_class, on_development_warning_dialog_responded_cb); gtk_widget_class_bind_template_callback (widget_class, panel_list_view_changed_cb); gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb); @@ -760,6 +830,10 @@ cc_window_init (CcWindow *self) cc_panel_list_set_active_panel (CC_PANEL_LIST (self->panel_list), id); else cc_panel_list_activate (CC_PANEL_LIST (self->panel_list)); + + /* Add a custom CSS class on development builds */ + if (in_flatpak_sandbox ()) + add_development_build_css (self); } CcWindow * diff --git a/shell/org.gnome.ControlCenter.gschema.xml b/shell/org.gnome.ControlCenter.gschema.xml index a40b9b08c..40350bca4 100644 --- a/shell/org.gnome.ControlCenter.gschema.xml +++ b/shell/org.gnome.ControlCenter.gschema.xml @@ -8,5 +8,12 @@ will be ignored and the first panel in the list selected. </description> </key> + <key name="show-development-warning" type="b"> + <default>true</default> + <summary>Show warning when running a development build of Settings</summary> + <description> + Whether Settings should show a warning when running a development build. + </description> + </key> </schema> </schemalist> diff --git a/shell/window.ui b/shell/window.ui index 92ff197ce..c34ce60bc 100644 --- a/shell/window.ui +++ b/shell/window.ui @@ -224,4 +224,17 @@ <widget name="sidebar_box"/> </widgets> </object> + + <!-- Warning dialog for development builds --> + <object class="GtkMessageDialog" id="development_warning_dialog"> + <property name="message-type">warning</property> + <property name="transient-for">CcWindow</property> + <property name="resizable">false</property> + <property name="modal">true</property> + <property name="buttons">ok</property> + <property name="text" translatable="yes">Warning: Development Version</property> + <property name="secondary-text" translatable="yes">This version of Settings should only be used for development purposes. You may experience incorrect system behavior, data loss, and other unexpected issues. </property> + <signal name="response" handler="on_development_warning_dialog_responded_cb" object="CcWindow" swapped="no" /> + </object> + </interface> |