[gnome-panel] panel: Port creation of new toplevels to GSettings
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] panel: Port creation of new toplevels to GSettings
- Date: Mon, 28 Mar 2011 21:14:41 +0000 (UTC)
commit 20dd1a7ccc8d5040110f8bc8fd4f9d7be570c30a
Author: Vincent Untz <vuntz gnome org>
Date: Fri Mar 25 18:50:58 2011 +0100
panel: Port creation of new toplevels to GSettings
gnome-panel/panel-context-menu.c | 3 +-
gnome-panel/panel-layout.c | 52 +++++++++++++++++-
gnome-panel/panel-layout.h | 1 +
gnome-panel/panel-profile.c | 109 --------------------------------------
gnome-panel/panel-toplevel.c | 57 ++++++++++++++++++++
gnome-panel/panel-toplevel.h | 3 +
6 files changed, 113 insertions(+), 112 deletions(-)
---
diff --git a/gnome-panel/panel-context-menu.c b/gnome-panel/panel-context-menu.c
index 9d12bc4..bf36c66 100644
--- a/gnome-panel/panel-context-menu.c
+++ b/gnome-panel/panel-context-menu.c
@@ -43,6 +43,7 @@
#include "menu.h"
#include "panel-profile.h"
#include "panel-properties-dialog.h"
+#include "panel-layout.h"
#include "panel-lockdown.h"
#include "panel-addto.h"
#include "panel-icon-names.h"
@@ -50,7 +51,7 @@
static void
panel_context_menu_create_new_panel (GtkWidget *menuitem)
{
- panel_profile_create_toplevel (gtk_widget_get_screen (menuitem));
+ panel_layout_toplevel_create (gtk_widget_get_screen (menuitem));
}
static void
diff --git a/gnome-panel/panel-layout.c b/gnome-panel/panel-layout.c
index 0d9ad78..0ae0304 100644
--- a/gnome-panel/panel-layout.c
+++ b/gnome-panel/panel-layout.c
@@ -549,6 +549,52 @@ panel_layout_append_from_file (const char *layout_file,
}
+/***********************\
+ * New toplevel/object *
+\***********************/
+
+
+void
+panel_layout_toplevel_create (GdkScreen *screen)
+{
+ char *unique_id;
+ char *path;
+ GSettings *settings;
+ PanelOrientation orientation;
+ int monitor;
+
+ unique_id = panel_layout_find_free_id (PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY,
+ PANEL_TOPLEVEL_SCHEMA,
+ PANEL_LAYOUT_TOPLEVEL_PATH,
+ NULL, -1);
+
+ path = g_strdup_printf ("%s%s/", PANEL_LAYOUT_TOPLEVEL_PATH, unique_id);
+ settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, path);
+ g_free (path);
+
+ g_settings_set_int (settings,
+ PANEL_TOPLEVEL_SCREEN_KEY,
+ gdk_screen_get_number (screen));
+
+ if (panel_toplevel_find_empty_spot (screen, &orientation, &monitor)) {
+ g_settings_set_enum (settings,
+ PANEL_TOPLEVEL_ORIENTATION_KEY,
+ orientation);
+ g_settings_set_int (settings,
+ PANEL_TOPLEVEL_MONITOR_KEY,
+ monitor);
+ }
+
+ g_object_unref (settings);
+
+ panel_gsettings_append_strv (layout_settings,
+ PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY,
+ unique_id);
+
+ g_free (unique_id);
+}
+
+
/*******************\
* Changing layout *
\*******************/
@@ -766,8 +812,10 @@ panel_layout_changed_object (void)
g_strfreev (ids);
- if (loading)
- panel_object_loader_do_load (FALSE);
+ /* Always do this, even if loading is FALSE: if a panel has been
+ * created, we want a do_load() to unhide it, even if there is no
+ * object to load */
+ panel_object_loader_do_load (FALSE);
}
static void
diff --git a/gnome-panel/panel-layout.h b/gnome-panel/panel-layout.h
index c8b73d6..4f81c6a 100644
--- a/gnome-panel/panel-layout.h
+++ b/gnome-panel/panel-layout.h
@@ -34,6 +34,7 @@ void panel_layout_append_from_file (const char *layout_file,
gboolean panel_layout_load (void);
+void panel_layout_toplevel_create (GdkScreen *screen);
void panel_layout_delete_toplevel (const char *toplevel_id);
void panel_layout_delete_object (const char *object_id);
diff --git a/gnome-panel/panel-profile.c b/gnome-panel/panel-profile.c
index aa67825..417edff 100644
--- a/gnome-panel/panel-profile.c
+++ b/gnome-panel/panel-profile.c
@@ -41,14 +41,6 @@
#include "panel-toplevel.h"
#include "panel-lockdown.h"
-static GConfEnumStringPair panel_orientation_map [] = {
- { PANEL_ORIENTATION_TOP, "top" },
- { PANEL_ORIENTATION_BOTTOM, "bottom" },
- { PANEL_ORIENTATION_LEFT, "left" },
- { PANEL_ORIENTATION_RIGHT, "right" },
- { 0, NULL }
-};
-
static GConfEnumStringPair panel_object_type_map [] = {
{ PANEL_OBJECT_MENU, "menu-object" },
{ PANEL_OBJECT_LAUNCHER, "launcher-object" },
@@ -61,12 +53,6 @@ static GConfEnumStringPair panel_object_type_map [] = {
{ 0, NULL }
};
-const char *
-panel_profile_map_orientation (PanelOrientation orientation)
-{
- return gconf_enum_to_string (panel_orientation_map, orientation);
-}
-
char *
panel_profile_find_new_id (PanelGConfKeyType type)
{
@@ -202,101 +188,6 @@ panel_profile_id_lists_are_writable (void)
panel_profile_id_list_is_writable (PANEL_GCONF_OBJECTS);
}
-static gboolean
-panel_profile_find_empty_spot (GdkScreen *screen,
- PanelOrientation *orientation,
- int *monitor)
-{
- GSList *li;
- int i;
- int *filled_spots;
- gboolean found_a_spot = FALSE;
-
- *monitor = 0;
- *orientation = PANEL_ORIENTATION_TOP;
-
- filled_spots = g_new0 (int, panel_multiscreen_monitors (screen));
-
- for (li = panel_toplevel_list_toplevels (); li != NULL; li = li->next) {
- PanelToplevel *toplevel = li->data;
- GdkScreen *toplevel_screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
- int toplevel_monitor = panel_toplevel_get_monitor (toplevel);
-
- if (toplevel_screen != screen ||
- toplevel_monitor < 0)
- continue;
-
- filled_spots[toplevel_monitor] |= panel_toplevel_get_orientation (toplevel);
- }
-
- for (i = 0; i < panel_multiscreen_monitors (screen); i++) {
- /* These are ordered based on "priority" of the
- orientation when picking it */
- if ( ! (filled_spots[i] & PANEL_ORIENTATION_TOP)) {
- *orientation = PANEL_ORIENTATION_TOP;
- *monitor = i;
- found_a_spot = TRUE;
- break;
- } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_BOTTOM)) {
- *orientation = PANEL_ORIENTATION_BOTTOM;
- *monitor = i;
- found_a_spot = TRUE;
- break;
- } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_RIGHT)) {
- *orientation = PANEL_ORIENTATION_RIGHT;
- *monitor = i;
- found_a_spot = TRUE;
- break;
- } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_LEFT)) {
- *orientation = PANEL_ORIENTATION_LEFT;
- *monitor = i;
- found_a_spot = TRUE;
- break;
- }
- }
-
- g_free (filled_spots);
-
- return found_a_spot;
-}
-
-void
-panel_profile_create_toplevel (GdkScreen *screen)
-{
- GConfClient *client;
- const char *key;
- char *id;
- char *dir;
- PanelOrientation orientation;
- int monitor;
-
- g_return_if_fail (screen != NULL);
-
- client = panel_gconf_get_client ();
-
- id = panel_profile_find_new_id (PANEL_GCONF_TOPLEVELS);
-
- dir = g_strdup_printf (PANEL_CONFIG_DIR "/toplevels/%s", id);
- panel_gconf_associate_schemas_in_dir (client, dir, PANEL_SCHEMAS_DIR "/toplevels");
- g_free (dir);
-
- key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "screen");
- gconf_client_set_int (client, key, gdk_screen_get_number (screen), NULL);
-
- if (panel_profile_find_empty_spot (screen, &orientation, &monitor)) {
- key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "monitor");
- gconf_client_set_int (client, key, monitor, NULL);
-
- key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, id, "orientation");
- gconf_client_set_string (client, key, panel_profile_map_orientation (orientation), NULL);
- }
-
- panel_profile_add_to_list (PANEL_GCONF_TOPLEVELS, id);
-
- g_free (id);
-}
-
-
char *
panel_profile_prepare_object_with_id (PanelObjectType object_type,
const char *toplevel_id,
diff --git a/gnome-panel/panel-toplevel.c b/gnome-panel/panel-toplevel.c
index df94030..f8a051f 100644
--- a/gnome-panel/panel-toplevel.c
+++ b/gnome-panel/panel-toplevel.c
@@ -289,6 +289,63 @@ panel_toplevel_is_last (PanelToplevel *toplevel)
return TRUE;
}
+gboolean
+panel_toplevel_find_empty_spot (GdkScreen *screen,
+ PanelOrientation *orientation,
+ int *monitor)
+{
+ int *filled_spots;
+ GSList *li;
+ int i;
+ gboolean found_a_spot = FALSE;
+
+ *monitor = 0;
+ *orientation = PANEL_ORIENTATION_TOP;
+
+ filled_spots = g_new0 (int, panel_multiscreen_monitors (screen));
+
+ for (li = panel_toplevel_list_toplevels (); li != NULL; li = li->next) {
+ PanelToplevel *toplevel = li->data;
+ GdkScreen *toplevel_screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
+ int toplevel_monitor = panel_toplevel_get_monitor (toplevel);
+
+ if (toplevel_screen != screen ||
+ toplevel_monitor < 0)
+ continue;
+
+ filled_spots[toplevel_monitor] |= panel_toplevel_get_orientation (toplevel);
+ }
+
+ for (i = 0; i < panel_multiscreen_monitors (screen); i++) {
+ /* These are ordered based on "priority" of the
+ orientation when picking it */
+ if ( ! (filled_spots[i] & PANEL_ORIENTATION_TOP)) {
+ *orientation = PANEL_ORIENTATION_TOP;
+ *monitor = i;
+ found_a_spot = TRUE;
+ break;
+ } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_BOTTOM)) {
+ *orientation = PANEL_ORIENTATION_BOTTOM;
+ *monitor = i;
+ found_a_spot = TRUE;
+ break;
+ } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_RIGHT)) {
+ *orientation = PANEL_ORIENTATION_RIGHT;
+ *monitor = i;
+ found_a_spot = TRUE;
+ break;
+ } else if ( ! (filled_spots[i] & PANEL_ORIENTATION_LEFT)) {
+ *orientation = PANEL_ORIENTATION_LEFT;
+ *monitor = i;
+ found_a_spot = TRUE;
+ break;
+ }
+ }
+
+ g_free (filled_spots);
+
+ return found_a_spot;
+}
static GdkScreen *
panel_toplevel_get_screen_geometry (PanelToplevel *toplevel,
diff --git a/gnome-panel/panel-toplevel.h b/gnome-panel/panel-toplevel.h
index 27f8bff..76e0faf 100644
--- a/gnome-panel/panel-toplevel.h
+++ b/gnome-panel/panel-toplevel.h
@@ -162,6 +162,9 @@ int panel_toplevel_get_maximum_size (PanelToplevel *tople
GSList *panel_toplevel_list_toplevels (void);
PanelToplevel *panel_toplevel_get_by_id (const char *toplevel_id);
+gboolean panel_toplevel_find_empty_spot (GdkScreen *screen,
+ PanelOrientation *orientation,
+ int *monitor);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]