shell: Allow panels to register custom widgets in the shell header

This allows us to add the kill switch in the various different panels to match
the mockups, and also allows us to connect up any custom functionality the
designers want.

For example, in the bluetooth panel we might want to allow the GtkLabel to be
edited to change the bluetooth device name.
This commit is contained in:
Richard Hughes
2012-01-09 15:19:13 +00:00
parent f4bcd50240
commit dcb88a861d
3 changed files with 72 additions and 0 deletions

View File

@@ -236,3 +236,24 @@ cc_shell_get_toplevel (CcShell *shell)
return NULL;
}
void
cc_shell_embed_widget_in_header (CcShell *shell, GtkWidget *widget)
{
CcShellClass *class;
g_return_if_fail (CC_IS_SHELL (shell));
class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
if (!class->embed_widget_in_header)
{
g_warning ("Object of type \"%s\" does not implement required virtual"
" function \"embed_widget_in_header\",",
G_OBJECT_TYPE_NAME (shell));
return FALSE;
}
else
{
return class->embed_widget_in_header (shell, widget);
}
}

View File

@@ -89,6 +89,8 @@ struct _CcShellClass
const gchar **argv,
GError **error);
GtkWidget * (*get_toplevel) (CcShell *shell);
void (*embed_widget_in_header) (CcShell *shell,
GtkWidget *widget);
};
GType cc_shell_get_type (void) G_GNUC_CONST;
@@ -102,6 +104,9 @@ gboolean cc_shell_set_active_panel_from_id (CcShell *shell,
GError **error);
GtkWidget * cc_shell_get_toplevel (CcShell *shell);
void cc_shell_embed_widget_in_header (CcShell *shell,
GtkWidget *widget);
G_END_DECLS
#endif /* _CC_SHELL_H */

View File

@@ -69,6 +69,7 @@ struct _GnomeControlCenterPrivate
GtkWidget *window;
GtkWidget *search_entry;
GtkWidget *lock_button;
GPtrArray *custom_widgets;
GMenuTree *menu_tree;
GtkListStore *store;
@@ -200,6 +201,23 @@ activate_panel (GnomeControlCenter *shell,
}
}
static void
_shell_remove_all_custom_widgets (GnomeControlCenterPrivate *priv)
{
GtkBox *box;
GtkWidget *widget;
guint i;
/* remove from the header */
box = GTK_BOX (W (priv->builder, "topright"));
for (i = 0; i < priv->custom_widgets->len; i++)
{
widget = g_ptr_array_index (priv->custom_widgets, i);
gtk_container_remove (GTK_CONTAINER (box), widget);
}
g_ptr_array_set_size (priv->custom_widgets, 0);
}
static void
shell_show_overview_page (GnomeControlCenterPrivate *priv)
{
@@ -220,6 +238,9 @@ shell_show_overview_page (GnomeControlCenterPrivate *priv)
gtk_window_set_default_icon_name (priv->default_window_icon);
gtk_window_set_icon_name (GTK_WINDOW (priv->window),
priv->default_window_icon);
/* clear any custom widgets */
_shell_remove_all_custom_widgets (priv);
}
void
@@ -809,6 +830,20 @@ notebook_switch_page_cb (GtkNotebook *book,
}
}
/* CcShell implementation */
static void
_shell_embed_widget_in_header (CcShell *shell,
GtkWidget *widget)
{
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (shell)->priv;
GtkBox *box;
/* add to header */
box = GTK_BOX (W (priv->builder, "topright"));
gtk_box_pack_end (box, widget, FALSE, FALSE, 0);
g_ptr_array_add (priv->custom_widgets, g_object_ref (widget));
}
/* CcShell implementation */
static gboolean
_shell_set_active_panel_from_id (CcShell *shell,
@@ -823,6 +858,8 @@ _shell_set_active_panel_from_id (CcShell *shell,
GIcon *gicon;
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (shell)->priv;
/* clear any custom widgets */
_shell_remove_all_custom_widgets (priv);
iter_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
&iter);
@@ -919,6 +956,11 @@ gnome_control_center_dispose (GObject *object)
{
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
if (priv->custom_widgets)
{
g_ptr_array_unref (priv->custom_widgets);
priv->custom_widgets = NULL;
}
if (priv->window)
{
gtk_widget_destroy (priv->window);
@@ -1005,6 +1047,7 @@ gnome_control_center_class_init (GnomeControlCenterClass *klass)
object_class->finalize = gnome_control_center_finalize;
shell_class->set_active_panel_from_id = _shell_set_active_panel_from_id;
shell_class->embed_widget_in_header = _shell_embed_widget_in_header;
shell_class->get_toplevel = _shell_get_toplevel;
}
@@ -1083,6 +1126,9 @@ gnome_control_center_init (GnomeControlCenter *self)
g_signal_connect (gtk_builder_get_object (priv->builder, "home-button"),
"clicked", G_CALLBACK (home_button_clicked_cb), self);
/* keep a list of custom widgets to unload on panel change */
priv->custom_widgets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
/* load the available settings panels */
setup_model (self);