summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--capplets/theme-switcher/theme-properties.glade71
-rw-r--r--capplets/theme-switcher/theme-switcher.c228
2 files changed, 210 insertions, 89 deletions
diff --git a/capplets/theme-switcher/theme-properties.glade b/capplets/theme-switcher/theme-properties.glade
index c8bc14425..8690310c0 100644
--- a/capplets/theme-switcher/theme-properties.glade
+++ b/capplets/theme-switcher/theme-properties.glade
@@ -21,10 +21,8 @@
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
- <property name="border_width">5</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
- <property name="spacing">10</property>
<child>
<widget class="GtkButton" id="helpbutton1">
@@ -178,6 +176,7 @@
<child>
<widget class="GtkHBox" id="hbox5">
+ <property name="border_width">8</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">8</property>
@@ -222,7 +221,7 @@
</widget>
<packing>
<property name="padding">0</property>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
@@ -299,6 +298,21 @@
<property name="spacing">8</property>
<child>
+ <widget class="GtkButton" id="window_install_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">_Install New Theme...</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
<widget class="GtkButton" id="window_manage_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -326,6 +340,57 @@
<property name="fill">True</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkHBox" id="hbox8">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">8</property>
+
+ <child>
+ <widget class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="stock">gtk-dialog-info</property>
+ <property name="icon_size">6</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label13">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">New themes can also be installed by dragging them into the window.</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">True</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="tab_expand">False</property>
diff --git a/capplets/theme-switcher/theme-switcher.c b/capplets/theme-switcher/theme-switcher.c
index 338ff264a..937a8e0ef 100644
--- a/capplets/theme-switcher/theme-switcher.c
+++ b/capplets/theme-switcher/theme-switcher.c
@@ -19,11 +19,19 @@
#include "gconf-property-editor.h"
#include "file-transfer-dialog.h"
+/* FIXME: This shouldn't be hardcoded
+ */
+#define METACITY_THEME_LOCATION "/usr/share/themes"
+
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
#define WINDOW_THEME_KEY "/desktop/gnome/applications/window_manager/theme"
+#define METACITY_THEME_DIR "/apps/metacity/general"
+#define METACITY_THEME_KEY METACITY_THEME_DIR "/theme"
#define MAX_ELEMENTS_BEFORE_SCROLLING 8
+static void read_themes (GladeXML *dialog);
+
enum
{
THEME_NAME_COLUMN,
@@ -48,6 +56,7 @@ static gboolean setting_model = FALSE;
static gboolean initial_scroll = TRUE;
static gboolean window_setting_model = FALSE;
static gboolean window_initial_scroll = TRUE;
+static gboolean running_theme_install = FALSE;
static GladeXML *
create_dialog (void)
@@ -61,7 +70,7 @@ create_dialog (void)
static void
theme_selection_changed (GtkTreeSelection *selection,
- gpointer data)
+ const gchar *gconf_key)
{
GtkTreeModel *model;
gchar *new_key;
@@ -89,107 +98,68 @@ theme_selection_changed (GtkTreeSelection *selection,
{
gchar *old_key;
- old_key = gconf_client_get_string (client, GTK_THEME_KEY, NULL);
+ old_key = gconf_client_get_string (client, gconf_key, NULL);
if (old_key && strcmp (old_key, new_key))
{
- gconf_client_set_string (client, GTK_THEME_KEY, new_key, NULL);
+ gconf_client_set_string (client, gconf_key, new_key, NULL);
}
g_free (old_key);
}
else
{
- gconf_client_unset (client, GTK_THEME_KEY, NULL);
+ gconf_client_unset (client, gconf_key, NULL);
}
g_free (new_key);
+ g_object_unref (client);
+}
+
+static void
+gtk_theme_selection_changed (GtkTreeSelection *selection,
+ gpointer data)
+{
+ theme_selection_changed (selection, GTK_THEME_KEY);
}
static void
window_theme_selection_changed (GtkTreeSelection *selection,
gpointer data)
{
- GtkTreeModel *model;
- gchar *new_key;
- GConfClient *client;
- GtkTreeIter iter;
-
- if (window_setting_model)
- return;
-
- client = gconf_client_get_default ();
-
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- {
- gtk_tree_model_get (model, &iter,
- THEME_NAME_COLUMN, &new_key,
- -1);
- }
- else
- /* This shouldn't happen */
- {
- new_key = NULL;
- }
-
- if (new_key != NULL)
- {
- gchar *old_key;
-
- old_key = gconf_client_get_string (client, WINDOW_THEME_KEY, NULL);
- if (old_key && strcmp (old_key, new_key))
- {
- gconf_client_set_string (client, WINDOW_THEME_KEY, new_key, NULL);
- }
- g_free (old_key);
- }
- else
- {
- gconf_client_unset (client, WINDOW_THEME_KEY, NULL);
- }
- g_free (new_key);
+ theme_selection_changed (selection, METACITY_THEME_KEY);
}
static void
-read_themes (GladeXML *dialog)
+load_theme_names (GtkTreeView *tree_view,
+ GList *theme_list,
+ char *current_theme)
{
- GConfClient *client;
- GList *gtk_theme_list;
GList *list;
GtkTreeModel *model;
- GtkTreeView *tree_view;
- gchar *current_theme;
+ GtkWidget *swindow;
gint i = 0;
gboolean current_theme_found = FALSE;
GtkTreeRowReference *row_ref = NULL;
- client = gconf_client_get_default ();
-
- gtk_theme_list = theme_common_get_list ();
- tree_view = GTK_TREE_VIEW (WID ("theme_treeview"));
+ swindow = GTK_WIDGET (tree_view)->parent;
model = gtk_tree_view_get_model (tree_view);
setting_model = TRUE;
gtk_list_store_clear (GTK_LIST_STORE (model));
-
- current_theme = gconf_client_get_string (client, GTK_THEME_KEY, NULL);
- if (current_theme == NULL)
- current_theme = g_strdup ("Default");
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("theme_swindow")),
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
- gtk_widget_set_usize (WID ("theme_swindow"), -1, -1);
+ gtk_widget_set_usize (swindow, -1, -1);
- for (list = gtk_theme_list; list; list = list->next)
+ for (list = theme_list; list; list = list->next)
{
- ThemeInfo *info = list->data;
+ const char *name = list->data;
GtkTreeIter iter;
- if (! info->has_gtk)
- continue;
-
gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- THEME_NAME_COLUMN, info->name,
+ THEME_NAME_COLUMN, name,
-1);
- if (strcmp (current_theme, info->name) == 0)
+ if (strcmp (current_theme, name) == 0)
{
GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
row_ref = gtk_tree_row_reference_new (model, path);
@@ -201,8 +171,8 @@ read_themes (GladeXML *dialog)
{
GtkRequisition rectangle;
gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle);
- gtk_widget_set_usize (WID ("theme_swindow"), -1, rectangle.height);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("theme_swindow")),
+ gtk_widget_set_usize (swindow, -1, rectangle.height);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
}
i++;
@@ -245,6 +215,49 @@ read_themes (GladeXML *dialog)
}
static void
+read_themes (GladeXML *dialog)
+{
+ GList *theme_list, *gtk_theme_list, *metacity_theme_list;
+ GList *list;
+ GConfClient *client;
+ char *current_theme;
+
+ client = gconf_client_get_default ();
+
+ /* Read in themes
+ */
+ theme_list = theme_common_get_list ();
+
+ gtk_theme_list = NULL;
+ metacity_theme_list = NULL;
+ for (list = theme_list; list; list = list->next)
+ {
+ ThemeInfo *info = list->data;
+
+ if (info->has_gtk)
+ gtk_theme_list = g_list_prepend (gtk_theme_list, info->name);
+ if (info->has_metacity){
+ metacity_theme_list = g_list_prepend (metacity_theme_list, info->name);
+ }
+ }
+
+ current_theme = gconf_client_get_string (client, GTK_THEME_KEY, NULL);
+ if (current_theme == NULL)
+ current_theme = g_strdup ("Default");
+
+ load_theme_names (GTK_TREE_VIEW (WID ("theme_treeview")), gtk_theme_list, current_theme);
+
+ current_theme = gconf_client_get_string (client, METACITY_THEME_KEY, NULL);
+ if (current_theme == NULL)
+ current_theme = g_strdup ("Default");
+
+ load_theme_names (GTK_TREE_VIEW (WID ("window_theme_treeview")), metacity_theme_list, current_theme);
+
+ g_list_free (gtk_theme_list);
+ g_list_free (metacity_theme_list);
+}
+
+static void
window_read_themes (GladeXML *dialog)
{
GConfClient *client;
@@ -366,6 +379,18 @@ theme_key_changed (GConfClient *client,
}
static void
+metacity_key_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
+{
+ if (strcmp (entry->key, METACITY_THEME_KEY))
+ return;
+
+ read_themes ((GladeXML *)user_data);
+}
+
+static void
window_theme_key_changed (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
@@ -536,23 +561,40 @@ install_dialog_response (GtkWidget *widget, int response_id, gpointer data)
}
static void
-show_install_dialog (GtkWidget *button, gpointer parent)
+real_show_install_dialog (gpointer parent, gchar *filename)
{
- GladeXML *dialog = glade_xml_new (GLADEDIR "/theme-install.glade", NULL, NULL);
- GtkWidget *widget = WID ("install_dialog");
+ GladeXML *dialog;
+ GtkWidget *widget;
+
+ if (running_theme_install)
+ return;
+
+ running_theme_install = TRUE;
+ dialog = glade_xml_new (GLADEDIR "/theme-install.glade", NULL, NULL);
+ widget = WID ("install_dialog");
+
g_signal_connect (G_OBJECT (widget), "response",
G_CALLBACK (install_dialog_response), dialog);
gtk_window_set_transient_for (GTK_WINDOW (widget), parent);
gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ON_PARENT);
+ if (filename)
+ gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("install_theme_picker")), filename);
while (gtk_dialog_run (GTK_DIALOG (widget)) == GTK_RESPONSE_HELP)
;
gtk_widget_destroy (widget);
g_object_unref (G_OBJECT (dialog));
+
+ running_theme_install = FALSE;
}
+static void
+show_install_dialog (GtkWidget *button, gpointer parent)
+{
+ real_show_install_dialog (parent, NULL);
+}
/* Callback issued during drag movements */
static gboolean
@@ -579,7 +621,6 @@ drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
guint info, guint time, gpointer data)
{
GList *uris;
- GladeXML *dialog = data;
gchar *filename;
if (!(info == TARGET_URI_LIST || info == TARGET_NS_URL))
@@ -593,11 +634,10 @@ drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
g_free (filename);
filename = gnome_vfs_uri_to_string (uris->data, GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD);
}
- gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("install_theme_picker")), filename);
- g_free (filename);
gnome_vfs_uri_list_unref (uris);
- show_install_dialog (NULL, widget);
+ real_show_install_dialog (widget, filename);
+ g_free (filename);
}
static void
@@ -633,17 +673,18 @@ cb_dialog_response (GtkDialog *dialog, gint response_id)
gtk_main_quit ();
}
-void
-setup_theme_tree (GtkTreeView *tree_view, GCallback theme_selection_changed_cb)
+static void
+setup_tree_view (GtkTreeView *tree_view,
+ GCallback changed_callback)
{
GtkTreeModel *model;
GtkTreeSelection *selection;
-
+
gtk_tree_view_insert_column_with_attributes (tree_view,
- -1, NULL,
- gtk_cell_renderer_text_new (),
- "text", THEME_NAME_COLUMN,
- NULL);
+ -1, NULL,
+ gtk_cell_renderer_text_new (),
+ "text", THEME_NAME_COLUMN,
+ NULL);
model = (GtkTreeModel *) gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model), 0, sort_func, NULL, NULL);
@@ -651,24 +692,28 @@ setup_theme_tree (GtkTreeView *tree_view, GCallback theme_selection_changed_cb)
gtk_tree_view_set_model (tree_view, model);
selection = gtk_tree_view_get_selection (tree_view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
- g_signal_connect (G_OBJECT (selection), "changed", (GCallback) theme_selection_changed_cb, NULL);}
-
+ g_signal_connect (G_OBJECT (selection), "changed", changed_callback, NULL);
+}
static void
setup_dialog (GladeXML *dialog)
{
GConfClient *client;
- GtkWidget *widget, *parent;
+ GtkWidget *parent, *widget;
client = gconf_client_get_default ();
parent = WID ("theme_dialog");
- setup_theme_tree (GTK_TREE_VIEW (WID ("theme_treeview")), (GCallback)theme_selection_changed);
- setup_theme_tree (GTK_TREE_VIEW (WID ("window_theme_treeview")), (GCallback)window_theme_selection_changed);
+ setup_tree_view (GTK_TREE_VIEW (WID ("theme_treeview")),
+ (GCallback)gtk_theme_selection_changed);
+ setup_tree_view (GTK_TREE_VIEW (WID ("window_theme_treeview")),
+ (GCallback)window_theme_selection_changed);
gconf_client_add_dir (client, "/desktop/gnome/interface", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
gconf_client_add_dir (client, "/desktop/gnome/applications/window_manager",
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ gconf_client_add_dir (client, METACITY_THEME_DIR,
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
gconf_client_notify_add (client,
GTK_THEME_KEY,
@@ -678,19 +723,30 @@ setup_dialog (GladeXML *dialog)
WINDOW_THEME_KEY,
(GConfClientNotifyFunc) &window_theme_key_changed,
dialog, NULL, NULL);
+ gconf_client_notify_add (client,
+ METACITY_THEME_KEY,
+ (GConfClientNotifyFunc) &metacity_key_changed,
+ dialog, NULL, NULL);
read_themes (dialog);
window_read_themes (dialog);
theme_common_register_theme_change (theme_changed_func, dialog);
+ /* app themes */
widget = WID ("install_button");
g_signal_connect (G_OBJECT (widget), "clicked",
G_CALLBACK (show_install_dialog), parent);
widget = WID ("manage_button");
g_signal_connect (G_OBJECT (widget), "clicked",
G_CALLBACK (show_manage_themes), dialog);
- g_signal_connect (G_OBJECT (WID ("window_manage_button")), "clicked",
+
+ /* window manager themes */
+ widget = WID ("window_install_button");
+ g_signal_connect (G_OBJECT (widget), "clicked",
+ G_CALLBACK (show_install_dialog), parent);
+ widget = WID ("window_manage_button");
+ g_signal_connect (G_OBJECT (widget), "clicked",
G_CALLBACK (window_show_manage_themes), dialog);
/*