gnome-panel r11369 - in trunk: gnome-panel idl



Author: vuntz
Date: Mon Dec  8 17:30:54 2008
New Revision: 11369
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11369&view=rev

Log:
2008-12-08  Vincent Untz  <vuntz gnome org>

	Use dbus-based uniquification instead of bonobo-based, and makes it
	possible to replace a currently running panel.
	Based on patch by Colin Walters <walters verbum org>
	Fix bug #558534.

	* GNOME_Panel.server.in: kill
	* Makefile.am: updated for file removal
	* main.c: (main): add a --replace option to replace the current panel
	* panel-session.c: (panel_session_handle_die_request): just call
	panel_shell_quit()
	* panel-shell.[ch]: this is pretty much rewritten

2008-12-08  Vincent Untz  <vuntz gnome org>

	* GNOME_Panel.idl: remove PanelShell stuff


Removed:
   trunk/gnome-panel/GNOME_Panel.server.in
Modified:
   trunk/gnome-panel/ChangeLog
   trunk/gnome-panel/Makefile.am
   trunk/gnome-panel/main.c
   trunk/gnome-panel/panel-session.c
   trunk/gnome-panel/panel-shell.c
   trunk/gnome-panel/panel-shell.h
   trunk/idl/ChangeLog
   trunk/idl/GNOME_Panel.idl

Modified: trunk/gnome-panel/Makefile.am
==============================================================================
--- trunk/gnome-panel/Makefile.am	(original)
+++ trunk/gnome-panel/Makefile.am	Mon Dec  8 17:30:54 2008
@@ -180,7 +180,6 @@
 	panel-run-dialog.glade
 
 EXTRA_DIST =					\
-	GNOME_Panel.server.in			\
 	$(glade_DATA)				\
 	nothing.cP				\
 	nothing.h				\
@@ -235,15 +234,9 @@
 uidir   = $(datadir)/gnome-2.0/ui
 ui_DATA = GNOME_Panel_Popup.xml
 
-serverdir       = $(libdir)/bonobo/servers
-server_in_files = GNOME_Panel.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
-
 rcdir = $(datadir)
 rc_DATA = gnome-panelrc
 
- INTLTOOL_SERVER_RULE@
-
 entriesdir       = $(GCONF_SCHEMA_FILE_DIR)
 entries_DATA     = panel-default-setup.entries
 
@@ -278,7 +271,6 @@
 CLEANFILES = \
 	$(BUILT_SOURCES) \
 	$(schemas_in_files:.schemas.in=.schemas) \
-	$(server_DATA) \
 	$(sys_DATA) \
 	$(desktop_DATA)
 

Modified: trunk/gnome-panel/main.c
==============================================================================
--- trunk/gnome-panel/main.c	(original)
+++ trunk/gnome-panel/main.c	Mon Dec  8 17:30:54 2008
@@ -36,9 +36,11 @@
 GSList *panels = NULL;
 GSList *panel_list = NULL;
 
-static char *deprecated_profile;
+static char     *deprecated_profile;
+static gboolean  replace = FALSE;
 
 static const GOptionEntry options[] = {
+  { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, N_("Replace a currently running panel"), NULL },
   /* keep this for compatibilty with old GNOME < 2.10 */
   { "profile", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &deprecated_profile, NULL, NULL },
   { NULL }
@@ -68,7 +70,7 @@
 
 	gtk_window_set_default_icon_name (PANEL_ICON_PANEL);
 
-	if (!panel_shell_register ()) {
+	if (!panel_shell_register (replace)) {
 		panel_cleanup_do ();
 		return -1;
 	}

Modified: trunk/gnome-panel/panel-session.c
==============================================================================
--- trunk/gnome-panel/panel-session.c	(original)
+++ trunk/gnome-panel/panel-session.c	Mon Dec  8 17:30:54 2008
@@ -25,28 +25,19 @@
 #include <config.h>
 
 #include <libgnomeui/gnome-client.h>
-#include "panel-session.h"
 
 #include <stdlib.h>
 
-#include "panel-profile.h"
 #include "panel-shell.h"
 
+#include "panel-session.h"
+
 static void
 panel_session_handle_die_request (GnomeClient *client)
 {
-	GSList *toplevels_to_destroy, *l;
-
 	g_return_if_fail (GNOME_IS_CLIENT (client));
 
-        toplevels_to_destroy = g_slist_copy (panel_toplevel_list_toplevels ());
-        for (l = toplevels_to_destroy; l; l = l->next)
-		gtk_widget_destroy (l->data);
-        g_slist_free (toplevels_to_destroy);
-
-	panel_shell_unregister ();
-
-	gtk_main_quit ();
+	panel_shell_quit ();
 }
 
 void

Modified: trunk/gnome-panel/panel-shell.c
==============================================================================
--- trunk/gnome-panel/panel-shell.c	(original)
+++ trunk/gnome-panel/panel-shell.c	Mon Dec  8 17:30:54 2008
@@ -2,6 +2,8 @@
  * panel-shell.c: panel shell interface implementation
  *
  * Copyright (C) 2001 Ximian, Inc.
+ * Copyright (C) 2008 Red Hat, Inc.
+ * Copyright (C) 2008 Novell, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -20,147 +22,154 @@
  *
  * Authors:
  *      Jacob Berkman <jacob ximian com>
+ *      Colin Walters <walters verbum org>
+ *      Vincent Untz <vuntz gnome org>
  */
 
 #include <config.h>
 #include <glib/gi18n.h>
 
-#include <string.h>
-#include <gtk/gtk.h>
+#include <dbus/dbus-glib.h>
 
-#include <libpanel-util/panel-error.h>
+#include <libpanel-util/panel-cleanup.h>
 
-#include "panel-shell.h"
+#include "panel-profile.h"
 #include "panel-session.h"
-#include "panel-util.h"
 
-/*
- * PanelShell is a singleton.
- */
-static PanelShell *panel_shell = NULL;
+#include "panel-shell.h"
 
-static Bonobo_RegistrationResult
-panel_shell_bonobo_activation_register_for_display (const char    *iid,
-						    Bonobo_Unknown ref)
-{
-	const char *display_name;
-	GSList     *reg_env ;
-	Bonobo_RegistrationResult result;
-	
-	display_name = gdk_display_get_name (gdk_display_get_default ());
-	reg_env = bonobo_activation_registration_env_set (NULL,
-							  "DISPLAY",
-							  display_name);
-	result = bonobo_activation_register_active_server (iid, ref, reg_env);
-	bonobo_activation_registration_env_free (reg_env);
-	return result;
-}
+#define PANEL_DBUS_SERVICE "org.gnome.Panel"
+
+static DBusGConnection *dbus_connection = NULL;
+static DBusGProxy      *session_bus = NULL;
 
 static void
-panel_shell_register_error_dialog (int reg_res)
-{
-	GtkWidget *dlg;
-	GtkWidget *checkbox;
-	char      *secondary;
-
-	secondary = g_strdup_printf (_("The panel could not register with the "
-				       "bonobo-activation server (error code: "
-				       "%d) and will exit.\n"
-				       "It may be automatically restarted."),
-				       reg_res);
-
-	dlg = panel_error_dialog (NULL,
-				  gdk_screen_get_default (),
-				  "panel_shell_register_error",
-				  FALSE,
-				  _("The panel has encountered a fatal error"),
-				  secondary);
-
-	g_free (secondary);
-
-	//FIXME: the checkbox is not correctly aligned in the dialog...
-	checkbox = gtk_check_button_new_with_mnemonic (_("Force the panel to "
-							 "not be automatically "
-							 "restarted"));
-	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
-			    checkbox, FALSE, FALSE, 0);
-	gtk_widget_show (checkbox);
+panel_shell_on_name_lost (DBusGProxy *proxy,
+			  const char *name,
+			  gpointer   user_data)
+{
+	if (strcmp (name, PANEL_DBUS_SERVICE) != 0)
+		return;
+
+	/* We lost our DBus name, and there is something replacing us.
+	 * Tell the SM not to restart us automatically, then exit. */
+	g_printerr ("Panel leaving: a new panel shell is starting.\n");
 
-	gtk_dialog_run (GTK_DIALOG (dlg));
+	panel_session_do_not_restart ();
+	panel_shell_quit ();
+}
 
-	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)))
-		panel_session_do_not_restart ();
+static void
+panel_shell_cleanup (gpointer data)
+{
+	if (dbus_connection != NULL) {
+		dbus_g_connection_unref (dbus_connection);
+		dbus_connection = NULL;
+	}
 
-	gtk_widget_destroy (dlg);
+	if (session_bus != NULL) {
+		g_object_unref (session_bus);
+		session_bus = NULL;
+	}
 }
 
 gboolean
-panel_shell_register (void)
+panel_shell_register (gboolean replace)
 {
-	gboolean retval;
+	GError   *error;
+	guint     request_name_reply;
+	guint32   flags;
+	gboolean  retval;
 
-	retval = TRUE;
+	if (session_bus != NULL)
+		return TRUE;
 
-        if (!panel_shell) {
-		Bonobo_RegistrationResult  reg_res;
+	retval = FALSE;
 
-		panel_shell = g_object_new (PANEL_SHELL_TYPE, NULL);
-		bonobo_object_set_immortal (BONOBO_OBJECT (panel_shell), TRUE);
-
-		reg_res = panel_shell_bonobo_activation_register_for_display
-				("OAFIID:GNOME_PanelShell",
-				 BONOBO_OBJREF (panel_shell));
-
-		switch (reg_res) {
-		case Bonobo_ACTIVATION_REG_SUCCESS:
-			break;
-		case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
-			retval = FALSE;
-			g_printerr ("A panel is already running.\n");
-			panel_session_do_not_restart ();
-			break;
-		default:
-			retval = FALSE;
-			panel_shell_register_error_dialog (reg_res);
-			break;
-		}
+	panel_cleanup_register (PANEL_CLEAN_FUNC (panel_shell_cleanup), NULL);
+
+	dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+	if (dbus_connection == NULL) {
+		g_warning ("Cannot register the panel shell: cannot connect "
+			   "to the session bus.");
+		goto register_out;
 	}
 
-	return retval;
-}
+	session_bus = dbus_g_proxy_new_for_name (dbus_connection,
+						 "org.freedesktop.DBus",
+						 "/org/freedesktop/DBus",
+						 "org.freedesktop.DBus");
+	if (session_bus == NULL) {
+		g_warning ("Cannot register the panel shell: cannot connect "
+			   "to the session bus.");
+		goto register_out;
+	}
 
-void
-panel_shell_unregister (void)
-{
-	bonobo_activation_unregister_active_server ("OAFIID:GNOME_PanelShell",
-						    BONOBO_OBJREF (panel_shell));
-}
+	dbus_g_proxy_add_signal (session_bus,
+				 "NameLost",
+				 G_TYPE_STRING,
+				 G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal (session_bus,
+				     "NameLost",
+				     G_CALLBACK (panel_shell_on_name_lost),
+				     NULL,
+				     NULL);
+
+	flags = DBUS_NAME_FLAG_DO_NOT_QUEUE|DBUS_NAME_FLAG_ALLOW_REPLACEMENT;
+	if (replace)
+		flags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
+	error = NULL;
+
+	if (!dbus_g_proxy_call (session_bus,
+				"RequestName",
+				&error,
+				G_TYPE_STRING, PANEL_DBUS_SERVICE,
+				G_TYPE_UINT, flags,
+				G_TYPE_INVALID,
+				G_TYPE_UINT, &request_name_reply,
+				G_TYPE_INVALID)) {
+		g_warning ("Cannot register the panel shell: %s",
+			   error->message);
+		g_error_free (error);
 
-static void
-impl_displayRunDialog (PortableServer_Servant  servant,
-		       const CORBA_char       *initial_string,
-		       CORBA_Environment      *ev)
-{
-	PanelShell *shell;
+		goto register_out;
+	}
 
-	shell = PANEL_SHELL (bonobo_object (servant));
+	if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ||
+	    request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
+		retval = TRUE;
+	else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS)
+		g_printerr ("Cannot register the panel shell: there is "
+			    "already one running.\n");
+	else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
+		/* This should never happen since we don't want to be queued. */
+		g_warning ("Cannot register the panel shell: it was queued "
+			   "after the running one, but this should not "
+			   "happen.");
+	else
+		g_warning ("Cannot register the panel shell: unhandled "
+			   "reply %u from RequestName", request_name_reply);
 
-	g_message ("displayRunDialog: %s\n", initial_string);
-}
+register_out:
 
-static void
-panel_shell_class_init (PanelShellClass *klass)
-{
-	klass->epv.displayRunDialog = impl_displayRunDialog;
+	if (!retval) {
+		panel_session_do_not_restart ();
+		panel_shell_cleanup (NULL);
+	}
+
+	return retval;
 }
 
-static void
-panel_shell_init (PanelShell *shell)
+void
+panel_shell_quit (void)
 {
-}
+	GSList *toplevels_to_destroy, *l;
 
-BONOBO_TYPE_FUNC_FULL (PanelShell,
-		       GNOME_Vertigo_PanelShell,
-		       BONOBO_OBJECT_TYPE,
-		       panel_shell)
+        toplevels_to_destroy = g_slist_copy (panel_toplevel_list_toplevels ());
+        for (l = toplevels_to_destroy; l; l = l->next)
+		gtk_widget_destroy (l->data);
+        g_slist_free (toplevels_to_destroy);
 
+	gtk_main_quit ();
+}

Modified: trunk/gnome-panel/panel-shell.h
==============================================================================
--- trunk/gnome-panel/panel-shell.h	(original)
+++ trunk/gnome-panel/panel-shell.h	Mon Dec  8 17:30:54 2008
@@ -2,6 +2,8 @@
  * panel-shell.h: panel shell interface implementation
  *
  * Copyright (C) 2001 Ximian, Inc.
+ * Copyright (C) 2008 Red Hat, Inc.
+ * Copyright (C) 2008 Novell, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -20,32 +22,16 @@
  *
  * Authors:
  *      Jacob Berkman <jacob ximian com>
+ *      Colin Walters <walters verbum org>
+ *      Vincent Untz <vuntz gnome org>
  */
 
 #ifndef __PANEL_SHELL_H__
 #define __PANEL_SHELL_H__
 
-#include "GNOME_Panel.h"
+#include <glib.h>
 
-#include <bonobo/bonobo-object.h>
-
-#define PANEL_SHELL_TYPE        (panel_shell_get_type ())
-#define PANEL_SHELL(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_SHELL_TYPE, PanelShell))
-#define PANEL_SHELL_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST    ((k), PANEL_SHELL_TYPE, PanelShellClass))
-#define PANEL_IS_SHELL(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_SHELL_TYPE))
-#define PANEL_IS_SHELL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE    ((k), PANEL_SHELL_TYPE))
-
-typedef BonoboObject PanelShell;
-
-typedef struct {
-	BonoboObjectClass                 parent_class;
-
-	POA_GNOME_Vertigo_PanelShell__epv epv;
-} PanelShellClass;
-
-GType     panel_shell_get_type (void) G_GNUC_CONST;
-
-gboolean  panel_shell_register   (void);
-void      panel_shell_unregister (void);
+gboolean panel_shell_register (gboolean replace);
+void     panel_shell_quit     (void);
 
 #endif /* __PANEL_SHELL_H__ */

Modified: trunk/idl/GNOME_Panel.idl
==============================================================================
--- trunk/idl/GNOME_Panel.idl	(original)
+++ trunk/idl/GNOME_Panel.idl	Mon Dec  8 17:30:54 2008
@@ -42,18 +42,6 @@
 	 */
 	typedef string PanelBackground;
 
-	interface PanelShell : Bonobo::Unknown {
-
-		/*
-		 * GNOME::PanelShell::displayRunDialog
-		 * @initialString: string to display in dialog.
-		 *
-		 * Instructs the Panel to display the GNOME 'run'
-		 * dialog box.
-		 */
-		void displayRunDialog (in string initialString);
-	};
-
 	interface PanelAppletShell : Bonobo::Unknown {
 		oneway void popup_menu (in long button, in long time);
 	};



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