summaryrefslogtreecommitdiff
path: root/applets/wncklet/workspace-switcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/wncklet/workspace-switcher.c')
-rw-r--r--applets/wncklet/workspace-switcher.c160
1 files changed, 52 insertions, 108 deletions
diff --git a/applets/wncklet/workspace-switcher.c b/applets/wncklet/workspace-switcher.c
index 3fcd5085..4d24663f 100644
--- a/applets/wncklet/workspace-switcher.c
+++ b/applets/wncklet/workspace-switcher.c
@@ -15,14 +15,14 @@
#include <string.h>
#include <mate-panel-applet.h>
-#include <mate-panel-applet-mateconf.h>
+#include <mate-panel-applet-gsettings.h>
#include <stdlib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libmatewnck/libmatewnck.h>
-#include <mateconf/mateconf-client.h>
+#include <gio/gio.h>
#include "workspace-switcher.h"
@@ -32,9 +32,13 @@
#define MAX_REASONABLE_ROWS 16
#define DEFAULT_ROWS 1
+#define WORKSPACE_SWITCHER_SCHEMA "org.mate.panel.applet.workspace-switcher"
+
#define NEVER_SENSITIVE "never_sensitive"
-#define NUM_WORKSPACES "/apps/marco/general/num_workspaces"
-#define WORKSPACE_NAME "/apps/marco/workspace_names/name_1"
+#define MARCO_GENERAL_SCHEMA "org.mate.Marco.general"
+#define NUM_WORKSPACES "num-workspaces"
+#define MARCO_WORSKACES_SCHEMA "org.mate.Marco.workspace-names"
+#define WORKSPACE_NAME "name-1"
#define WORKSPACE_SWITCHER_ICON "mate-panel-workspace-switcher"
@@ -71,8 +75,7 @@ typedef struct {
MatewnckPagerDisplayMode display_mode;
gboolean display_all;
- /* mateconf listeners id */
- guint listeners[3];
+ GSettings* settings;
} PagerData;
static void display_properties_dialog(GtkAction* action, PagerData* pager);
@@ -289,17 +292,7 @@ static gboolean applet_scroll(MatePanelApplet* applet, GdkEventScroll* event, Pa
static void destroy_pager(GtkWidget* widget, PagerData* pager)
{
- MateConfClient* client = mateconf_client_get_default();
-
- mateconf_client_notify_remove(client, pager->listeners[0]);
- mateconf_client_notify_remove(client, pager->listeners[1]);
- mateconf_client_notify_remove(client, pager->listeners[2]);
-
- g_object_unref(G_OBJECT(client));
-
- pager->listeners[0] = 0;
- pager->listeners[1] = 0;
- pager->listeners[2] = 0;
+ g_object_unref (pager->settings);
if (pager->properties_dialog)
gtk_widget_destroy(pager->properties_dialog);
@@ -334,14 +327,11 @@ static const GtkActionEntry pager_menu_actions[] = {
}
};
-static void num_rows_changed(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, PagerData* pager)
+static void num_rows_changed(GSettings* settings, gchar* key, PagerData* pager)
{
int n_rows = DEFAULT_ROWS;
- if (entry->value != NULL && entry->value->type == MATECONF_VALUE_INT)
- {
- n_rows = mateconf_value_get_int(entry->value);
- }
+ n_rows = g_settings_get_int (settings, key);
n_rows = CLAMP(n_rows, 1, MAX_REASONABLE_ROWS);
@@ -352,14 +342,11 @@ static void num_rows_changed(MateConfClient* client, guint cnxn_id, MateConfEntr
gtk_spin_button_set_value(GTK_SPIN_BUTTON(pager->num_rows_spin), pager->n_rows);
}
-static void display_workspace_names_changed(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, PagerData* pager)
+static void display_workspace_names_changed(GSettings* settings, gchar* key, PagerData* pager)
{
gboolean value = FALSE; /* Default value */
- if (entry->value != NULL && entry->value->type == MATECONF_VALUE_BOOL)
- {
- value = mateconf_value_get_bool(entry->value);
- }
+ value = g_settings_get_boolean (settings, key);
if (value)
{
@@ -379,14 +366,11 @@ static void display_workspace_names_changed(MateConfClient* client, guint cnxn_i
}
-static void all_workspaces_changed(MateConfClient* client, guint cnxn_id, MateConfEntry* entry, PagerData* pager)
+static void all_workspaces_changed(GSettings* settings, gchar* key, PagerData* pager)
{
gboolean value = TRUE; /* Default value */
- if (entry->value != NULL && entry->value->type == MATECONF_VALUE_BOOL)
- {
- value = mateconf_value_get_bool(entry->value);
- }
+ value = g_settings_get_boolean (settings, key);
pager->display_all = value;
pager_update(pager);
@@ -410,30 +394,22 @@ static void all_workspaces_changed(MateConfClient* client, guint cnxn_id, MateCo
}
}
-static void setup_mateconf(PagerData* pager)
+static void setup_gsettings(PagerData* pager)
{
- MateConfClient* client;
- char* key;
-
- client = mateconf_client_get_default();
-
- key = mate_panel_applet_mateconf_get_full_key(MATE_PANEL_APPLET(pager->applet), "num_rows");
- pager->listeners[0] = mateconf_client_notify_add(client, key, (MateConfClientNotifyFunc) num_rows_changed, pager, NULL, NULL);
-
- g_free(key);
-
-
- key = mate_panel_applet_mateconf_get_full_key(MATE_PANEL_APPLET(pager->applet), "display_workspace_names");
- pager->listeners[1] = mateconf_client_notify_add(client, key, (MateConfClientNotifyFunc) display_workspace_names_changed, pager, NULL, NULL);
-
- g_free(key);
-
- key = mate_panel_applet_mateconf_get_full_key(MATE_PANEL_APPLET(pager->applet), "display_all_workspaces");
- pager->listeners[2] = mateconf_client_notify_add(client, key, (MateConfClientNotifyFunc) all_workspaces_changed, pager, NULL, NULL);
+ pager->settings = mate_panel_applet_settings_new (MATE_PANEL_APPLET (pager->applet), WORKSPACE_SWITCHER_SCHEMA);
- g_free(key);
-
- g_object_unref(G_OBJECT(client));
+ g_signal_connect (pager->settings,
+ "changed::num-rows",
+ G_CALLBACK (num_rows_changed),
+ pager);
+ g_signal_connect (pager->settings,
+ "changed::display-workspace-names",
+ G_CALLBACK (display_workspace_names_changed),
+ pager);
+ g_signal_connect (pager->settings,
+ "changed::display-all-workspaces",
+ G_CALLBACK (all_workspaces_changed),
+ pager);
}
gboolean workspace_switcher_applet_fill(MatePanelApplet* applet)
@@ -441,40 +417,21 @@ gboolean workspace_switcher_applet_fill(MatePanelApplet* applet)
PagerData* pager;
GtkActionGroup* action_group;
gchar* ui_path;
- GError* error;
gboolean display_names;
- mate_panel_applet_add_preferences(applet, "/schemas/apps/workspace_switcher_applet/prefs", NULL);
-
pager = g_new0(PagerData, 1);
pager->applet = GTK_WIDGET(applet);
mate_panel_applet_set_flags(MATE_PANEL_APPLET(pager->applet), MATE_PANEL_APPLET_EXPAND_MINOR);
- setup_mateconf(pager);
+ setup_gsettings(pager);
- error = NULL;
- pager->n_rows = mate_panel_applet_mateconf_get_int(applet, "num_rows", &error);
-
- if (error)
- {
- g_printerr(_("Error loading num_rows value for Workspace Switcher: %s\n"), error->message);
- g_error_free(error);
- /* leave current value */
- }
+ pager->n_rows = g_settings_get_int(pager->settings, "num-rows");
pager->n_rows = CLAMP(pager->n_rows, 1, MAX_REASONABLE_ROWS);
- error = NULL;
- display_names = mate_panel_applet_mateconf_get_bool(applet, "display_workspace_names", &error);
-
- if (error)
- {
- g_printerr(_("Error loading display_workspace_names value for Workspace Switcher: %s\n"), error->message);
- g_error_free(error);
- /* leave current value */
- }
+ display_names = g_settings_get_boolean(pager->settings, "display-workspace-names");
if (display_names)
{
@@ -485,15 +442,7 @@ gboolean workspace_switcher_applet_fill(MatePanelApplet* applet)
pager->display_mode = MATEWNCK_PAGER_DISPLAY_CONTENT;
}
- error = NULL;
- pager->display_all = mate_panel_applet_mateconf_get_bool(applet, "display_all_workspaces", &error);
-
- if (error)
- {
- g_printerr(_("Error loading display_all_workspaces value for Workspace Switcher: %s\n"), error->message);
- g_error_free(error);
- /* leave current value */
- }
+ pager->display_all = g_settings_get_boolean(pager->settings, "display-all-workspaces");
switch (mate_panel_applet_get_orient(applet))
{
@@ -591,17 +540,17 @@ static void display_about_dialog(GtkAction* action, PagerData* pager)
static void display_workspace_names_toggled(GtkToggleButton*button, PagerData* pager)
{
- mate_panel_applet_mateconf_set_bool(MATE_PANEL_APPLET(pager->applet), "display_workspace_names", gtk_toggle_button_get_active(button), NULL);
+ g_settings_set_boolean(pager->settings, "display-workspace-names", gtk_toggle_button_get_active(button));
}
static void all_workspaces_toggled(GtkToggleButton* button, PagerData* pager)
{
- mate_panel_applet_mateconf_set_bool(MATE_PANEL_APPLET(pager->applet), "display_all_workspaces", gtk_toggle_button_get_active(button), NULL);
+ g_settings_set_boolean(pager->settings, "display-all-workspaces", gtk_toggle_button_get_active(button));
}
static void num_rows_value_changed(GtkSpinButton* button, PagerData* pager)
{
- mate_panel_applet_mateconf_set_int(MATE_PANEL_APPLET(pager->applet), "num_rows", gtk_spin_button_get_value_as_int(button), NULL);
+ g_settings_set_int(pager->settings, "num-rows", gtk_spin_button_get_value_as_int(button));
}
static void update_workspaces_model(PagerData* pager)
@@ -752,28 +701,15 @@ static void close_dialog(GtkWidget* button, gpointer data)
#define WID(s) GTK_WIDGET(gtk_builder_get_object(builder, s))
static void
-setup_sensitivity(PagerData* pager, GtkBuilder* builder, const char* wid1, const char* wid2, const char* wid3, const char* key)
+setup_sensitivity(PagerData* pager, GtkBuilder* builder, const char* wid1, const char* wid2, const char* wid3, GSettings* settings, const char* key)
{
- MatePanelApplet* applet = MATE_PANEL_APPLET(pager->applet);
- MateConfClient* client = mateconf_client_get_default();
- char* fullkey;
GtkWidget* w;
- if (key[0] == '/')
- fullkey = g_strdup(key);
- else
- fullkey = mate_panel_applet_mateconf_get_full_key(applet, key);
-
- if (mateconf_client_key_is_writable(client, fullkey, NULL))
+ if (g_settings_is_writable(settings, key))
{
- g_object_unref(G_OBJECT(client));
- g_free(fullkey);
return;
}
- g_object_unref(G_OBJECT(client));
- g_free(fullkey);
-
w = WID(wid1);
g_assert(w != NULL);
g_object_set_data(G_OBJECT(w), NEVER_SENSITIVE, GINT_TO_POINTER(1));
@@ -802,27 +738,35 @@ static void setup_dialog(GtkBuilder* builder, PagerData* pager)
GtkTreeViewColumn* column;
GtkCellRenderer* cell;
int nr_ws, i;
+ GSettings *marco_general_settings;
+ GSettings *marco_workspaces_settings;
+
+ marco_general_settings = g_settings_new (MARCO_GENERAL_SCHEMA);
+ marco_workspaces_settings = g_settings_new (MARCO_WORSKACES_SCHEMA);
pager->workspaces_frame = WID("workspaces_frame");
pager->workspace_names_label = WID("workspace_names_label");
pager->workspace_names_scroll = WID("workspace_names_scroll");
pager->display_workspaces_toggle = WID("workspace_name_toggle");
- setup_sensitivity(pager, builder, "workspace_name_toggle", NULL, NULL, "display_workspace_names" /* key */);
+ setup_sensitivity(pager, builder, "workspace_name_toggle", NULL, NULL, pager->settings, "display-workspace-names" /* key */);
pager->all_workspaces_radio = WID("all_workspaces_radio");
pager->current_only_radio = WID("current_only_radio");
- setup_sensitivity(pager, builder, "all_workspaces_radio", "current_only_radio", "label_row_col", "display_all_workspaces" /* key */);
+ setup_sensitivity(pager, builder, "all_workspaces_radio", "current_only_radio", "label_row_col", pager->settings, "display-all-workspaces" /* key */);
pager->num_rows_spin = WID("num_rows_spin");
pager->label_row_col = WID("label_row_col");
- setup_sensitivity(pager, builder, "num_rows_spin", NULL, NULL, "num_rows" /* key */);
+ setup_sensitivity(pager, builder, "num_rows_spin", NULL, NULL, pager->settings, "num-rows" /* key */);
pager->num_workspaces_spin = WID("num_workspaces_spin");
- setup_sensitivity(pager, builder, "num_workspaces_spin", NULL, NULL, NUM_WORKSPACES /* key */);
+ setup_sensitivity(pager, builder, "num_workspaces_spin", NULL, NULL, marco_general_settings, NUM_WORKSPACES /* key */);
pager->workspaces_tree = WID("workspaces_tree_view");
- setup_sensitivity(pager, builder, "workspaces_tree_view", NULL, NULL, WORKSPACE_NAME /* key */);
+ setup_sensitivity(pager, builder, "workspaces_tree_view", NULL, NULL, marco_workspaces_settings, WORKSPACE_NAME /* key */);
+
+ g_object_unref (marco_general_settings);
+ g_object_unref (marco_workspaces_settings);
/* Display workspace names: */