Commit 5d4e07d6 authored by Jasper St. Pierre's avatar Jasper St. Pierre
Browse files

shell-extensions: Don't show toggle switches for extensions

The UI for extension toggle switches was never really thought out
that well, and it looks awful. Remove it and replace it with code
that simply disables all extensions.

https://bugzilla.gnome.org/show_bug.cgi?id=671693
parent c84706e9
......@@ -42,9 +42,7 @@ struct _GsmFailWhaleDialogPrivate
gboolean debug_mode;
gboolean allow_logout;
GdkRectangle geometry;
gboolean show_extensions;
GsmShellExtensions *extensions;
GtkWidget *extensions_box;
};
G_DEFINE_TYPE (GsmFailWhaleDialog, gsm_fail_whale_dialog, GTK_TYPE_WINDOW);
......@@ -275,61 +273,6 @@ on_logout_clicked (GtkWidget *button,
}
}
static void
on_extension_switched (GObject *object,
GParamSpec *spec,
GsmFailWhaleDialog *fail_dialog)
{
gchar *uuid;
gboolean enabled;
uuid = g_object_get_data (object, "uuid");
g_object_get (object, "active", &enabled, NULL);
gsm_shell_extensions_set_enabled (fail_dialog->priv->extensions,
uuid,
enabled);
}
static void
build_extension_toggle (GsmShellExtensions *extensions,
GsmShellExtension *extension,
gpointer data)
{
GsmFailWhaleDialog *fail_dialog = GSM_FAIL_WHALE_DIALOG (data);
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *sw;
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_set_size_request (hbox, 600, -1);
gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (fail_dialog->priv->extensions_box),
hbox, FALSE, FALSE, 0);
label = gtk_label_new (gsm_shell_extension_get_name (extension));
gtk_widget_show (label);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
sw = gtk_switch_new ();
gtk_switch_set_active (GTK_SWITCH (sw),
gsm_shell_extension_get_is_enabled (extension));
g_object_set_data (G_OBJECT (sw),
"uuid",
gsm_shell_extension_get_uuid (extension));
g_signal_connect (G_OBJECT (sw),
"notify::active",
G_CALLBACK (on_extension_switched),
fail_dialog);
gtk_widget_set_halign (label, GTK_ALIGN_END);
gtk_widget_show (sw);
gtk_box_pack_end (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
}
static void
setup_window (GsmFailWhaleDialog *fail_dialog)
{
......@@ -341,8 +284,6 @@ setup_window (GsmFailWhaleDialog *fail_dialog)
GtkWidget *message_label;
GtkWidget *button_box;
GtkWidget *button;
GtkWidget *extensions_scroll;
GtkWidget *extensions_vbox;
char *markup;
priv = fail_dialog->priv;
......@@ -382,8 +323,8 @@ setup_window (GsmFailWhaleDialog *fail_dialog)
if (!priv->allow_logout)
message_label = gtk_label_new (_("A problem has occurred and the system can't recover. Please contact a system administrator"));
else if (priv->show_extensions && gsm_shell_extensions_n_extensions (priv->extensions) > 0)
message_label = gtk_label_new (_("A problem has occurred and the system can't recover. Some of the extensions below may have caused this.\nPlease try disabling some of these, and then log out and try again."));
else if (priv->extensions != NULL && gsm_shell_extensions_n_extensions (priv->extensions) > 0)
message_label = gtk_label_new (_("A problem has occurred and the system can't recover. All extensions have been disabled as a precaution."));
else
message_label = gtk_label_new (_("A problem has occurred and the system can't recover.\nPlease log out and try again."));
......@@ -393,25 +334,6 @@ setup_window (GsmFailWhaleDialog *fail_dialog)
gtk_box_pack_start (GTK_BOX (box),
message_label, FALSE, FALSE, 0);
if (priv->allow_logout && priv->show_extensions) {
extensions_vbox = gtk_vbox_new (TRUE, 6);
gtk_widget_show (extensions_vbox);
fail_dialog->priv->extensions_box = extensions_vbox;
extensions_scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (extensions_scroll);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (extensions_scroll),
extensions_vbox);
gtk_box_pack_start (GTK_BOX (box),
extensions_scroll, FALSE, FALSE, 0);
gsm_shell_extensions_foreach (priv->extensions,
build_extension_toggle,
(gpointer) fail_dialog);
}
button_box = gtk_hbutton_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (button_box), 20);
gtk_widget_show (button_box);
......@@ -432,13 +354,12 @@ static void
gsm_fail_whale_dialog_init (GsmFailWhaleDialog *fail_dialog)
{
fail_dialog->priv = GSM_FAIL_WHALE_DIALOG_GET_PRIVATE (fail_dialog);
fail_dialog->priv->extensions = g_object_new (GSM_TYPE_SHELL_EXTENSIONS, NULL);
}
void
gsm_fail_whale_dialog_we_failed (gboolean debug_mode,
gboolean allow_logout,
gboolean show_extensions)
gsm_fail_whale_dialog_we_failed (gboolean debug_mode,
gboolean allow_logout,
GsmShellExtensions *extensions)
{
static GsmFailWhaleDialog *current_dialog = NULL;
......@@ -451,7 +372,8 @@ gsm_fail_whale_dialog_we_failed (gboolean debug_mode,
fail_dialog = g_object_new (GSM_TYPE_FAIL_WHALE_DIALOG, NULL);
fail_dialog->priv->debug_mode = debug_mode;
fail_dialog->priv->allow_logout = allow_logout;
fail_dialog->priv->show_extensions = show_extensions;
fail_dialog->priv->extensions = extensions;
setup_window (fail_dialog);
current_dialog = fail_dialog;
......
......@@ -26,6 +26,8 @@
#include <gtk/gtk.h>
#include "gsm-shell-extensions.h"
G_BEGIN_DECLS
#define GSM_TYPE_FAIL_WHALE_DIALOG (gsm_fail_whale_dialog_get_type ())
......@@ -53,9 +55,9 @@ struct _GsmFailWhaleDialogClass
GType gsm_fail_whale_dialog_get_type (void) G_GNUC_CONST;
void gsm_fail_whale_dialog_we_failed (gboolean debug_mode,
gboolean allow_logout,
gboolean show_extensions);
void gsm_fail_whale_dialog_we_failed (gboolean debug_mode,
gboolean allow_logout,
GsmShellExtensions *extensions);
G_END_DECLS
......
......@@ -63,6 +63,7 @@
#include "gsm-inhibit-dialog.h"
#include "gsm-system.h"
#include "gsm-session-save.h"
#include "gsm-shell-extensions.h"
#define GSM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_MANAGER, GsmManagerPrivate))
......@@ -274,12 +275,18 @@ on_required_app_failure (GsmManager *manager,
GsmApp *app)
{
const gchar *app_id;
gboolean want_extensions_ui;
gboolean allow_logout;
GsmSystem *system;
GsmShellExtensions *extensions;
app_id = gsm_app_peek_app_id (app);
want_extensions_ui = g_str_equal (app_id, "gnome-shell.desktop");
if (g_str_equal (app_id, "gnome-shell.desktop")) {
extensions = g_object_new (GSM_TYPE_SHELL_EXTENSIONS, NULL);
gsm_shell_extensions_disable_all (extensions);
} else {
extensions = NULL;
}
system = gsm_get_system ();
if (gsm_system_is_login_session (system)) {
......@@ -291,7 +298,7 @@ on_required_app_failure (GsmManager *manager,
gsm_fail_whale_dialog_we_failed (FALSE,
allow_logout,
want_extensions_ui);
extensions);
}
static gboolean
......
......@@ -29,50 +29,6 @@
#include "gsm-shell-extensions.h"
struct _GsmShellExtension
{
gchar *uuid;
gchar *name;
gchar *description;
gboolean enabled;
};
static void
gsm_shell_extension_free (gpointer data)
{
GsmShellExtension *extension = (GsmShellExtension *)data;
g_free (extension->uuid);
g_free (extension->name);
g_free (extension->description);
}
gchar *
gsm_shell_extension_get_uuid (GsmShellExtension *extension)
{
return extension->uuid;
}
gchar *
gsm_shell_extension_get_name (GsmShellExtension *extension)
{
return extension->name;
}
gchar *
gsm_shell_extension_get_description (GsmShellExtension *extension)
{
return extension->description;
}
gboolean
gsm_shell_extension_get_is_enabled (GsmShellExtension *extension)
{
return extension->enabled;
}
#define SHELL_SCHEMA "org.gnome.shell"
#define ENABLED_EXTENSIONS_KEY "enabled-extensions"
......@@ -81,9 +37,7 @@ gsm_shell_extension_get_is_enabled (GsmShellExtension *extension)
struct _GsmShellExtensionsPrivate
{
GSettings *settings;
/* uuid => GsmShellExtension */
GHashTable *uuid_to_extension;
guint num_extensions;
};
G_DEFINE_TYPE (GsmShellExtensions, gsm_shell_extensions, G_TYPE_OBJECT);
......@@ -107,12 +61,6 @@ gsm_shell_extensions_finalize (GObject *object)
priv->settings = NULL;
}
if (priv->uuid_to_extension != NULL)
{
g_hash_table_unref (priv->uuid_to_extension);
priv->uuid_to_extension = NULL;
}
G_OBJECT_CLASS (gsm_shell_extensions_parent_class)->finalize (object);
}
......@@ -132,28 +80,6 @@ gsm_shell_extensions_class_init (GsmShellExtensionsClass *klass)
g_type_class_add_private (object_class, sizeof (GsmShellExtensionsPrivate));
}
static void
gsm_shell_extensions_fetch_enabled (GsmShellExtensions *self)
{
gchar **enabled_uuids;
gchar **uuids;
enabled_uuids = g_settings_get_strv (self->priv->settings, ENABLED_EXTENSIONS_KEY);
uuids = enabled_uuids;
while (*uuids != '\0')
{
GsmShellExtension *extension;
extension = g_hash_table_lookup (self->priv->uuid_to_extension, *uuids);
if (extension != NULL)
extension->enabled = TRUE;
uuids ++;
}
g_strfreev (enabled_uuids);
}
static void
gsm_shell_extensions_scan_dir (GsmShellExtensions *self,
GFile *dir)
......@@ -175,15 +101,15 @@ gsm_shell_extensions_scan_dir (GsmShellExtensions *self,
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
GsmShellExtension *extension = g_slice_new (GsmShellExtension);
gchar *metadata_filename;
gchar *metadata_uuid;
const gchar *metadata_uuid;
gchar *dir_uuid;
JsonObject *metadata_root;
extension->uuid = (char *) g_file_info_get_name (info);
dir_uuid = (char *) g_file_info_get_name (info);
metadata_filename = g_build_filename (g_file_get_path (dir),
extension->uuid,
dir_uuid,
"metadata.json",
NULL);
......@@ -195,20 +121,14 @@ gsm_shell_extensions_scan_dir (GsmShellExtensions *self,
metadata_root = json_node_get_object (json_parser_get_root (metadata_parser));
metadata_uuid = json_object_get_string_member (metadata_root, "uuid");
if (!g_str_equal (metadata_uuid, extension->uuid))
if (!g_str_equal (metadata_uuid, dir_uuid))
{
g_warning ("Extension with dirname '%s' does not match metadata's UUID of '%s'. Skipping.",
extension->uuid,
metadata_uuid);
dir_uuid, metadata_uuid);
continue;
}
extension->enabled = FALSE;
extension->name = g_strdup (json_object_get_string_member (metadata_root, "name"));
extension->description = g_strdup (json_object_get_string_member (metadata_root, "description"));
g_hash_table_insert (self->priv->uuid_to_extension,
g_strdup (extension->uuid), extension);
self->priv->num_extensions++;
}
}
......@@ -267,104 +187,16 @@ gsm_shell_extensions_init (GsmShellExtensions *self)
schemas ++;
}
if (self->priv->settings)
{
self->priv->uuid_to_extension = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
gsm_shell_extension_free);
gsm_shell_extensions_scan (self);
gsm_shell_extensions_fetch_enabled (self);
}
if (self->priv->settings != NULL)
gsm_shell_extensions_scan (self);
}
gboolean
gsm_shell_extensions_set_enabled (GsmShellExtensions *self,
gchar *uuid,
gboolean enabled)
{
gsize i, length;
gchar **uuids;
const gchar **new_uuids;
GsmShellExtension *extension;
if (self->priv->settings == NULL)
return FALSE;
extension = g_hash_table_lookup (self->priv->uuid_to_extension,
uuid);
if (extension == NULL)
return FALSE;
if (extension->enabled == enabled)
return TRUE;
uuids = g_settings_get_strv (self->priv->settings, ENABLED_EXTENSIONS_KEY);
length = g_strv_length (uuids);
if (enabled)
{
new_uuids = g_new (const gchar *, length + 2); /* New key, NULL */
for (i = 0; i < length; i ++)
new_uuids[i] = g_strdup (uuids[i]);
new_uuids[i++] = g_strdup (uuid);
new_uuids[i] = NULL;
}
else
{
gsize j = 0;
new_uuids = g_new (const gchar *, length);
for (i = 0; i < length; i ++)
{
if (g_str_equal (uuids[i], uuid))
continue;
new_uuids[j] = g_strdup (uuids[i]);
j ++;
}
new_uuids[j] = NULL;
}
g_strfreev (uuids);
if (g_settings_set_strv (self->priv->settings,
ENABLED_EXTENSIONS_KEY,
new_uuids))
{
extension->enabled = enabled;
return TRUE;
}
return FALSE;
}
void
gsm_shell_extensions_foreach (GsmShellExtensions *self,
GsmShellExtensionFunc func,
gpointer user_data)
gsm_shell_extensions_disable_all (GsmShellExtensions *self)
{
GHashTableIter iter;
GsmShellExtension *extension;
if (self->priv->settings == NULL)
return;
g_hash_table_iter_init (&iter, self->priv->uuid_to_extension);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &extension))
(*func) (self, extension, user_data);
}
GsmShellExtension *
gsm_shell_extensions_get_for_uuid (GsmShellExtensions *self,
gchar *uuid)
{
if (self->priv->settings == NULL)
return NULL;
return g_hash_table_lookup (self->priv->uuid_to_extension, uuid);
return g_settings_set_strv (self->priv->settings,
ENABLED_EXTENSIONS_KEY,
NULL);
}
guint
......@@ -373,5 +205,5 @@ gsm_shell_extensions_n_extensions (GsmShellExtensions *self)
if (self->priv->settings == NULL)
return 0;
return g_hash_table_size (self->priv->uuid_to_extension);
return self->priv->num_extensions;
}
......@@ -28,14 +28,6 @@
G_BEGIN_DECLS
/* Opaque struct to represent one shell extension. */
typedef struct _GsmShellExtension GsmShellExtension;
gchar * gsm_shell_extension_get_uuid (GsmShellExtension *extension);
gchar * gsm_shell_extension_get_name (GsmShellExtension *extension);
gchar * gsm_shell_extension_get_description (GsmShellExtension *extension);
gboolean gsm_shell_extension_get_is_enabled (GsmShellExtension *extension);
#define GSM_TYPE_SHELL_EXTENSIONS (gsm_shell_extensions_get_type ())
#define GSM_SHELL_EXTENSIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSM_TYPE_SHELL_EXTENSIONS, GsmShellExtensions))
#define GSM_SHELL_EXTENSIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSM_TYPE_SHELL_EXTENSIONS, GsmShellExtensionsClass))
......@@ -47,10 +39,6 @@ typedef struct _GsmShellExtensions GsmShellExtensions;
typedef struct _GsmShellExtensionsClass GsmShellExtensionsClass;
typedef struct _GsmShellExtensionsPrivate GsmShellExtensionsPrivate;
typedef void (* GsmShellExtensionFunc) (GsmShellExtensions *extensions,
GsmShellExtension *extension,
gpointer user_data);
struct _GsmShellExtensions
{
GObject parent;
......@@ -66,19 +54,10 @@ struct _GsmShellExtensionsClass
GType gsm_shell_extensions_get_type (void) G_GNUC_CONST;
gboolean gsm_shell_extensions_set_enabled (GsmShellExtensions *self,
gchar *uuid,
gboolean value);
void gsm_shell_extensions_foreach (GsmShellExtensions *self,
GsmShellExtensionFunc func,
gpointer user_data);
gboolean gsm_shell_extensions_disable_all (GsmShellExtensions *self);
guint gsm_shell_extensions_n_extensions (GsmShellExtensions *self);
GsmShellExtension * gsm_shell_extensions_get_for_uuid (GsmShellExtensions *self,
gchar *uuid);
G_END_DECLS
#endif /* __GSM_SHELL_EXTENSIONS_H */
......@@ -314,7 +314,7 @@ main (int argc, char **argv)
}
if (please_fail) {
gsm_fail_whale_dialog_we_failed (TRUE, TRUE, TRUE);
gsm_fail_whale_dialog_we_failed (TRUE, TRUE, NULL);
gtk_main ();
exit (1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment