[gnome-control-center/single-window-shell: 3/9] Add a new experimental shell that uses GtkSocket to capture capplets



commit be6fa081f1f3dd0929f1f8ce21f4cdb3e9d24d02
Author: Thomas Wood <thomas wood intel com>
Date:   Tue Nov 24 16:19:12 2009 +0000

    Add a new experimental shell that uses GtkSocket to capture capplets

 shell/Makefile.am      |    4 +-
 shell/control-center.c |  318 ++++++++++++++++++++++--------------------------
 shell/shell.ui         |  154 +++++++++++++++++++++++
 3 files changed, 300 insertions(+), 176 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 915d75a..e8b44a1 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -11,7 +11,7 @@ INCLUDES =					\
 	$(REAL_LIBSLAB_CFLAGS)			\
 	$(GNOMECC_SHELL_CFLAGS)
 
-bin_PROGRAMS = gnome-control-center 
+noinst_PROGRAMS = gnome-control-center 
 
 gnome_control_center_SOURCES =		\
 	control-center.c
@@ -49,7 +49,7 @@ endif
 menudir = $(sysconfdir)/xdg/menus
 menu_DATA = gnomecc.menu
 
-EXTRA_DIST = gnomecc.desktop.in.in gnomecc.directory.in gnomecc.menu $(schemas_DATA).in
+EXTRA_DIST = shell.ui gnomecc.desktop.in.in gnomecc.directory.in gnomecc.menu $(schemas_DATA).in
 
 DISTCLEANFILES = gnomecc.desktop gnomecc.desktop.in gnomecc.directory $(schemas_DATA)
 
diff --git a/shell/control-center.c b/shell/control-center.c
index c4c154d..a1ce296 100644
--- a/shell/control-center.c
+++ b/shell/control-center.c
@@ -1,197 +1,167 @@
 /*
- * This file is part of the Control Center.
+ * Copyright (c) 2009 Intel, Inc.
  *
- * Copyright (c) 2006 Novell, Inc.
+ * The Control Center is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
  *
- * The Control Center is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
+ * The Control Center is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
  *
- * The Control Center is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * the Control Center; if not, write to the Free Software Foundation, Inc., 51
- * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * You should have received a copy of the GNU General Public License along
+ * with the Control Center; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "config.h"
-
-#include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libgnome/gnome-desktop-item.h>
-#include <unique/unique.h>
+#define GMENU_I_KNOW_THIS_IS_UNSTABLE
+#include <gnome-menus/gmenu-tree.h>
 
-#include <libslab/slab.h>
+#define W(b,x) GTK_WIDGET (gtk_builder_get_object (b, x))
 
-void handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data);
-static GSList *get_actions_list ();
 
-#define CONTROL_CENTER_PREFIX             "/apps/control-center/cc_"
-#define CONTROL_CENTER_ACTIONS_LIST_KEY   (CONTROL_CENTER_PREFIX  "actions_list")
-#define CONTROL_CENTER_ACTIONS_SEPARATOR  ";"
-#define EXIT_SHELL_ON_STATIC_ACTION       "exit_shell_on_static_action"
+void
+fill_model (GtkListStore *store)
+{
+  GSList *list, *l;
+  GMenuTreeDirectory *d;
+  GMenuTree *t;
+
+  t = gmenu_tree_lookup ("/etc/xdg/menus/gnomecc.menu", 0);
+
+  d = gmenu_tree_get_root_directory (t);
+
+  list = gmenu_tree_directory_get_contents (d);
+
+  for (l = list; l; l = l->next)
+    {
+      GMenuTreeItemType type;
+      type = gmenu_tree_item_get_type (l->data);
+      if (type == GMENU_TREE_ITEM_DIRECTORY)
+        {
+          GSList *foo, *f;
+          foo = gmenu_tree_directory_get_contents (l->data);
+          for (f = foo; f; f = f->next)
+            {
+              if (gmenu_tree_item_get_type (f->data)
+                  == GMENU_TREE_ITEM_ENTRY)
+                {
+                  const gchar *icon = gmenu_tree_entry_get_icon (f->data);
+                  const gchar *name = gmenu_tree_entry_get_name (f->data);
+                  const gchar *exec = gmenu_tree_entry_get_exec (f->data);
+
+                  gtk_list_store_insert_with_values (store, NULL, 0, 
+                                                     0, name,
+                                                     1, exec,
+                                                     2, icon,
+                                                     -1);
+                }
+            }
+        }
+    }
 
-static GSList *
-get_actions_list (void)
+}
+
+void
+plug_added_cb (GtkSocket *socket,
+               GtkBuilder *builder)
 {
-	GSList *l;
-	GSList *key_list;
-	GSList *actions_list = NULL;
-	AppAction *action;
-
-	key_list = get_slab_gconf_slist (CONTROL_CENTER_ACTIONS_LIST_KEY);
-	if (!key_list)
-	{
-		g_warning (_("key not found [%s]\n"), CONTROL_CENTER_ACTIONS_LIST_KEY);
-		return NULL;
-	}
-
-	for (l = key_list; l != NULL; l = l->next)
-	{
-		gchar *entry = (gchar *) l->data;
-		gchar **temp;
-
-		action = g_new (AppAction, 1);
-		temp = g_strsplit (entry, CONTROL_CENTER_ACTIONS_SEPARATOR, 2);
-		action->name = g_strdup (temp[0]);
-		if ((action->item = load_desktop_item_from_unknown (temp[1])) == NULL)
-		{
-			g_warning ("get_actions_list() - PROBLEM - Can't load %s\n", temp[1]);
-		}
-		else
-		{
-			actions_list = g_slist_prepend (actions_list, action);
-		}
-		g_strfreev (temp);
-		g_free (entry);
-	}
-
-	g_slist_free (key_list);
-
-	return g_slist_reverse (actions_list);
+  GtkWidget *notebook;
+
+  notebook = W (builder, "notebook");
+
+  gtk_notebook_set_page (GTK_NOTEBOOK (notebook), 1);
 }
 
 void
-handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data)
+item_activated_cb (GtkIconView *icon_view,
+                   GtkTreePath *path,
+                   GtkBuilder *builder)
 {
-	gchar *temp;
-	AppShellData *app_data = (AppShellData *) data;
-	GnomeDesktopItem *item =
-		(GnomeDesktopItem *) g_object_get_data (G_OBJECT (tile), APP_ACTION_KEY);
-
-	if (event->type == TILE_EVENT_ACTIVATED_DOUBLE_CLICK)
-		return;
-	open_desktop_item_exec (item);
-
-	temp = g_strdup_printf("%s%s", app_data->gconf_prefix, EXIT_SHELL_ON_STATIC_ACTION);
-	if (get_slab_gconf_bool(temp))
-	{
-		if (app_data->exit_on_close)
-			gtk_main_quit ();
-		else
-			hide_shell (app_data);
-	}
-	g_free (temp);
+  GtkTreeModel *model;
+  GtkTreeIter iter = {0,};
+  gchar *name, *exec, *command;
+  GtkWidget *socket, *notebook;
+  guint socket_id = 0;
+  static gint index = -1;
+
+  /* create new socket */
+  socket = gtk_socket_new ();
+
+  g_signal_connect (socket, "plug-added", G_CALLBACK (plug_added_cb), builder);
+
+  notebook = W (builder, "notebook");
+  if (index >= 0)
+    gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), index);
+  index = gtk_notebook_append_page (GTK_NOTEBOOK (notebook), socket, NULL);
+
+  gtk_widget_show (socket);
+
+  socket_id = gtk_socket_get_id (GTK_SOCKET (socket));
+
+  /* get exec */
+  model = gtk_icon_view_get_model (icon_view);
+
+  gtk_tree_model_get_iter (model, &iter, path);
+
+  gtk_tree_model_get (model, &iter, 0, &name, 1, &exec, -1);
+
+  gtk_label_set_text (GTK_LABEL (W (builder, "applet-label")),
+                      name);
+  gtk_widget_show (W (builder, "applet-label"));
+  gtk_widget_show (W (builder, "arrow"));
+
+  /* start app */
+  command = g_strdup_printf ("%s --socket=%u", exec, socket_id);
+  g_spawn_command_line_async (command, NULL);
+  g_free (command);
+
+  g_free (name);
+  g_free (exec);
 }
 
-static UniqueResponse
-message_received_cb (UniqueApp         *app,
-		     UniqueCommand      command,
-		     UniqueMessageData *message,
-		     guint              time,
-		     gpointer           user_data)
+void
+home_button_clicked_cb (GtkButton *button, GtkBuilder *builder)
 {
-	UniqueResponse  res;
-	AppShellData   *app_data = user_data;
-
-	switch (command) {
-	case UNIQUE_ACTIVATE:
-		/* move the main window to the screen that sent us the command */
-		gtk_window_set_screen (GTK_WINDOW (app_data->main_app),
-				       unique_message_data_get_screen (message));
-		if (!app_data->main_app_window_shown_once)
-			show_shell (app_data);
-
-		gtk_window_present_with_time (GTK_WINDOW (app_data->main_app),
-					      time);
-
-		gtk_widget_grab_focus (SLAB_SECTION (app_data->filter_section)->contents);
-
-		res = UNIQUE_RESPONSE_OK;
-		break;
-	default:
-		res = UNIQUE_RESPONSE_PASSTHROUGH;
-		break;
-	}
-
-	return res;
+  gtk_notebook_set_page (GTK_NOTEBOOK (W (builder, "notebook")), 0);
+  gtk_widget_hide (W (builder, "applet-label"));
+  gtk_widget_hide (W (builder, "arrow"));
 }
 
 int
-main (int argc, char *argv[])
+main (int argc, char **argv)
 {
-	gboolean hidden = FALSE;
-	UniqueApp *unique_app;
-	AppShellData *app_data;
-	GSList *actions;
-	GError *error;
-	GOptionEntry options[] = {
-	  { "hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL },
-	  { NULL }
-	};
-
-#ifdef ENABLE_NLS
-	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-	textdomain (GETTEXT_PACKAGE);
-#endif
-
-	error = NULL;
-	if (!gtk_init_with_args (&argc, &argv,
-				 NULL, options, GETTEXT_PACKAGE, &error)) {
-		g_printerr ("%s\n", error->message);
-		g_error_free (error);
-		return 1;
-	}
-
-	unique_app = unique_app_new ("org.opensuse.yast-control-center-gnome", NULL);
-	if (unique_app_is_running (unique_app)) {
-		int retval = 0;
-
-		if (!hidden) {
-			UniqueResponse response;
-			response = unique_app_send_message (unique_app,
-							    UNIQUE_ACTIVATE,
-							    NULL);
-			retval = (response != UNIQUE_RESPONSE_OK);
-		}
-
-		g_object_unref (unique_app);
-		return retval;
-	}
-
-	app_data = appshelldata_new ("gnomecc.menu", NULL, CONTROL_CENTER_PREFIX,
-				     GTK_ICON_SIZE_DND, FALSE, TRUE);
-	generate_categories (app_data);
-
-	actions = get_actions_list ();
-	layout_shell (app_data, _("Filter"), _("Groups"), _("Common Tasks"), actions,
-		handle_static_action_clicked);
-
-	create_main_window (app_data, "MyControlCenter", _("Control Center"),
-		"gnome-control-center", 975, 600, hidden);
-
-	unique_app_watch_window (unique_app, GTK_WINDOW (app_data->main_app));
-	g_signal_connect (unique_app, "message-received",
-			  G_CALLBACK (message_received_cb), app_data);
-
-	gtk_main ();
-
-	g_object_unref (unique_app);
-
-	return 0;
-};
+  GtkBuilder *b;
+  GtkWidget *window, *notebook;
+  GdkColor color = {0, 32767, 32767, 32767};
+
+  gtk_init (&argc, &argv);
+
+  b = gtk_builder_new ();
+
+  gtk_builder_add_from_file (b, "shell.ui", NULL);
+
+  window = W (b, "main-window");
+  g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
+
+  fill_model (GTK_LIST_STORE (gtk_builder_get_object (b, "liststore")));
+
+  notebook = W (b, "notebook");
+
+  gtk_widget_modify_text (W (b,"search-entry"), GTK_STATE_NORMAL, &color);
+
+
+  g_signal_connect (gtk_builder_get_object (b, "iconview"), "item-activated",
+                    G_CALLBACK (item_activated_cb), b);
+  g_signal_connect (gtk_builder_get_object (b, "home-button"), "clicked",
+                    G_CALLBACK (home_button_clicked_cb), b);
+
+  gtk_widget_show_all (window);
+
+  gtk_main ();
+
+  return 0;
+}
diff --git a/shell/shell.ui b/shell/shell.ui
new file mode 100644
index 0000000..b4bcbf9
--- /dev/null
+++ b/shell/shell.ui
@@ -0,0 +1,154 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="main-window">
+    <property name="default_width">1024</property>
+    <property name="default_height">500</property>
+    <child>
+      <object class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkToolbar" id="toolbar1">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkToolItem" id="home-button1">
+                <property name="visible">True</property>
+                <property name="is_important">True</property>
+                <child>
+                  <object class="GtkButton" id="home-button">
+                    <property name="label" translatable="yes">Settings</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolItem" id="toolbutton3">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkArrow" id="arrow">
+                    <property name="no_show_all">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolItem" id="toolbutton2">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel" id="applet-label">
+                    <property name="no_show_all">True</property>
+                    <property name="label" translatable="yes">Applet</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolItem" id="toolbutton1">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xscale">0</property>
+                    <child>
+                      <object class="GtkEntry" id="search-entry">
+                        <property name="width_request">210</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="is_focus">True</property>
+                        <property name="invisible_char">&#x25CF;</property>
+                        <property name="text" translatable="yes">Type to search your settings</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkNotebook" id="notebook">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="show_tabs">False</property>
+            <property name="show_border">False</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkIconView" id="iconview">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">liststore</property>
+                    <child>
+                      <object class="GtkCellRendererPixbuf" id="cellrendererpixbuf">
+                        <property name="stock_size">5</property>
+                      </object>
+                      <attributes>
+                        <attribute name="icon-name">2</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="cellrenderertext">
+                        <property name="width">100</property>
+                        <property name="yalign">0</property>
+                        <property name="alignment">center</property>
+                        <property name="wrap_mode">word</property>
+                        <property name="wrap_width">100</property>
+                      </object>
+                      <attributes>
+                        <attribute name="text">0</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="tab">
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkListStore" id="liststore">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name exec -->
+      <column type="gchararray"/>
+      <!-- column-name icon -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+</interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]