[nautilus/gtk3-breakage: 6/7] application: go back to libunique for now
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk3-breakage: 6/7] application: go back to libunique for now
- Date: Fri, 22 Oct 2010 15:45:51 +0000 (UTC)
commit 6e8fafa8176c1e920ce195714c7160685591c357
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Oct 22 17:17:58 2010 +0200
application: go back to libunique for now
While GApplication API settles. Also, porting to the new GApplication
would require quite some refactoring.
configure.in | 3 +-
src/nautilus-application.c | 280 ++++++++++++++++++++++----------------------
src/nautilus-application.h | 3 +-
src/nautilus-main.c | 2 +-
4 files changed, 145 insertions(+), 143 deletions(-)
---
diff --git a/configure.in b/configure.in
index 3d28030..4dc798a 100644
--- a/configure.in
+++ b/configure.in
@@ -68,6 +68,7 @@ PKG_CHECK_MODULES(ALL, [
libxml-2.0 >= xml_minver
gail-3.0 >= gtk_minver
gsettings-desktop-schemas
+ unique-3.0
])
dnl ==========================================================================
@@ -337,7 +338,7 @@ LIBNAUTILUS_EXTENSION_LIBS="`$PKG_CONFIG --libs $LIBNAUTILUS_EXTENSION_MODULES`"
AC_SUBST(LIBNAUTILUS_EXTENSION_LIBS)
dnl core nautilus
-CORE_MODULES="glib-2.0 gnome-desktop-3.0 gtk+-3.0 gthread-2.0 gio-2.0 gio-unix-2.0 gail-3.0 gconf-2.0 libxml-2.0 gsettings-desktop-schemas $EXTRA_CORE_MODULES"
+CORE_MODULES="glib-2.0 gnome-desktop-3.0 gtk+-3.0 gthread-2.0 gio-2.0 gio-unix-2.0 gail-3.0 gconf-2.0 libxml-2.0 gsettings-desktop-schemas unique-3.0 $EXTRA_CORE_MODULES"
CORE_CFLAGS="`$PKG_CONFIG --cflags $CORE_MODULES` $x_cflags"
AC_SUBST(CORE_CFLAGS)
CORE_LIBS="`$PKG_CONFIG --libs $CORE_MODULES` $x_libs"
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 2d5f476..22da591 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -75,10 +75,14 @@
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-private/nautilus-autorun.h>
-#define COMMAND_OPEN "open"
-#define COMMAND_START_DESKTOP "start_desktop"
-#define COMMAND_STOP_DESKTOP "stop_desktop"
-#define COMMAND_CLOSE "close"
+enum
+{
+ COMMAND_0, /* unused: 0 is an invalid command */
+
+ COMMAND_START_DESKTOP,
+ COMMAND_STOP_DESKTOP,
+ COMMAND_OPEN_BROWSER,
+};
/* Keep window from shrinking down ridiculously small; numbers are somewhat arbitrary */
#define APPLICATION_WINDOW_MIN_WIDTH 300
@@ -121,6 +125,73 @@ static char * nautilus_application_get_session_data (void);
G_DEFINE_TYPE (NautilusApplication, nautilus_application, G_TYPE_OBJECT);
+static gboolean
+_unique_message_data_set_geometry_and_uris (UniqueMessageData *message_data,
+ const char *geometry,
+ char **uris)
+{
+ GString *list;
+ gint i;
+ gchar *result;
+ gsize length;
+
+ list = g_string_new (NULL);
+ if (geometry != NULL) {
+ g_string_append (list, geometry);
+ }
+ g_string_append (list, "\r\n");
+
+ for (i = 0; uris != NULL && uris[i]; i++) {
+ g_string_append (list, uris[i]);
+ g_string_append (list, "\r\n");
+ }
+
+ result = g_convert (list->str, list->len,
+ "ASCII", "UTF-8",
+ NULL, &length, NULL);
+ g_string_free (list, TRUE);
+
+ if (result) {
+ unique_message_data_set (message_data, (guchar *) result, length);
+ g_free (result);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gchar **
+_unique_message_data_get_geometry_and_uris (UniqueMessageData *message_data,
+ char **geometry)
+{
+ gchar **result = NULL;
+
+ *geometry = NULL;
+
+ gchar *text, *newline, *uris;
+ text = unique_message_data_get_text (message_data);
+ if (text) {
+ newline = strchr (text, '\n');
+ if (newline) {
+ *geometry = g_strndup (text, newline-text);
+ uris = newline+1;
+ } else {
+ uris = text;
+ }
+
+ result = g_uri_list_extract_uris (uris);
+ g_free (text);
+ }
+
+ /* if the string is empty, make it NULL */
+ if (*geometry && strlen (*geometry) == 0) {
+ g_free (*geometry);
+ *geometry = NULL;
+ }
+
+ return result;
+}
+
GList *
nautilus_application_get_window_list (void)
{
@@ -210,6 +281,13 @@ nautilus_application_init (NautilusApplication *application)
/* Create an undo manager */
application->undo_manager = nautilus_undo_manager_new ();
+ application->unique_app = unique_app_new_with_commands ("org.gnome.Nautilus", NULL,
+ "start_desktop", COMMAND_START_DESKTOP,
+ "stop_desktop", COMMAND_STOP_DESKTOP,
+ "open_browser", COMMAND_OPEN_BROWSER,
+ NULL);
+
+
application->smclient = egg_sm_client_get ();
g_signal_connect (application->smclient, "save_state",
G_CALLBACK (smclient_save_state_cb),
@@ -758,65 +836,53 @@ open_windows (NautilusApplication *application,
}
}
-static void
-message_received_cb (GApplication *unique_app,
- gchar *name,
- GVariant *platform_data,
- gpointer user_data)
+static UniqueResponse
+message_received_cb (UniqueApp *unique_app,
+ guint command,
+ UniqueMessageData *message,
+ guint time_,
+ gpointer user_data)
{
NautilusApplication *application;
-
+ UniqueResponse res;
+ char **uris;
+ char *geometry;
+ GdkScreen *screen;
+
application = user_data;
-
- if (g_strcmp0 (name, COMMAND_CLOSE) == 0) {
+ res = UNIQUE_RESPONSE_OK;
+
+ switch (command) {
+ case UNIQUE_CLOSE:
+ res = UNIQUE_RESPONSE_OK;
nautilus_main_event_loop_quit (TRUE);
- return;
- }
-
- if (g_strcmp0 (name, COMMAND_OPEN) == 0) {
- GVariantIter iter;
- gboolean use_browser;
- gchar *key;
- GVariant *value;
- gchar *startup_id = NULL, *geometry = NULL;
- char **uris = NULL;
-
- g_variant_iter_init (&iter, platform_data);
-
- while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) {
- if (g_strcmp0 (key, "urls") == 0) {
- g_variant_get (value, "^as", &uris);
- } else if (g_strcmp0 (key, "geometry") == 0) {
- g_variant_get (value, "&s", &geometry);
- } else if (g_strcmp0 (key, "use_browser") == 0) {
- g_variant_get (value, "b", &use_browser);
- } else if (g_strcmp0 (key, "startup_id") == 0) {
- g_variant_get (value, "&s", &startup_id);
- }
-
- g_variant_unref (value);
- }
-
+
+ break;
+ case UNIQUE_OPEN:
+ case COMMAND_OPEN_BROWSER:
+ uris = _unique_message_data_get_geometry_and_uris (message, &geometry);
+ screen = unique_message_data_get_screen (message);
open_windows (application,
- startup_id,
+ unique_message_data_get_startup_id (message),
uris,
- gdk_screen_get_default (),
+ screen,
geometry,
- use_browser);
+ command == COMMAND_OPEN_BROWSER);
g_strfreev (uris);
-
- return;
- }
-
- if (g_strcmp0 (name, COMMAND_START_DESKTOP) == 0) {
+ g_free (geometry);
+ break;
+ case COMMAND_START_DESKTOP:
nautilus_application_open_desktop (application);
- return;
- }
-
- if (g_strcmp0 (name, COMMAND_STOP_DESKTOP) == 0) {
+ break;
+ case COMMAND_STOP_DESKTOP:
nautilus_application_close_desktop ();
- return;
+ break;
+ default:
+ res = UNIQUE_RESPONSE_PASSTHROUGH;
+ break;
}
+
+ return res;
}
gboolean
@@ -848,34 +914,6 @@ queue_accel_map_save_callback (GtkAccelMap *object, gchar *accel_path,
}
}
-static GVariant *
-get_startup_id (void)
-{
- gchar *id = NULL;
- GVariant *retval;
- GTimeVal timeval = { 0, };
-
- id = g_strdup (gdk_x11_display_get_startup_notification_id (gdk_display_get_default ()));
-
- if (id == NULL) {
- id = g_strdup (g_getenv ("DESKTOP_STARTUP_ID"));
- }
-
- if (id == NULL) {
- guint32 timestamp;
-
- g_get_current_time (&timeval);
-
- timestamp = timeval.tv_sec;
- id = g_strdup_printf ("_TIME%lu", (unsigned long) timestamp);
- }
-
- retval = g_variant_new ("s", id);
- g_free (id);
-
- return retval;
-}
-
void
nautilus_application_startup (NautilusApplication *application,
gboolean kill_shell,
@@ -885,9 +923,8 @@ nautilus_application_startup (NautilusApplication *application,
const char *geometry,
char **urls)
{
- gboolean is_remote;
- GError *error = NULL;
-
+ UniqueMessageData *message;
+
/* Check the user's ~/.nautilus directories and post warnings
* if there are problems.
*/
@@ -895,32 +932,11 @@ nautilus_application_startup (NautilusApplication *application,
return;
}
- application->unique_app = g_initable_new (G_TYPE_APPLICATION,
- NULL,
- &error,
- "application-id", "org.gnome.Nautilus",
- "default-quit", FALSE,
- "argv", g_variant_new_bytestring_array (NULL, 0),
- NULL);
- g_assert (error == NULL);
- is_remote = g_application_is_remote (application->unique_app);
-
- if (!is_remote) {
- /* set application properties */
- g_application_add_action (application->unique_app,
- "open", "Open a nautilus window");
- g_application_add_action (application->unique_app,
- "close", "Close the application");
- g_application_add_action (application->unique_app,
- COMMAND_START_DESKTOP, "Starts the desktop");
- g_application_add_action (application->unique_app,
- COMMAND_STOP_DESKTOP, "Stops the desktop");
- }
-
if (kill_shell) {
- if (is_remote) {
- g_application_invoke_action (application->unique_app,
- COMMAND_CLOSE, NULL);
+ if (unique_app_is_running (application->unique_app)) {
+ unique_app_send_message (application->unique_app,
+ UNIQUE_CLOSE, NULL);
+
}
} else {
char *accel_map_filename;
@@ -931,21 +947,19 @@ nautilus_application_startup (NautilusApplication *application,
}
if (!no_desktop) {
- if (is_remote) {
- g_application_invoke_action (application->unique_app,
- COMMAND_START_DESKTOP, NULL);
+ if (unique_app_is_running (application->unique_app)) {
+ unique_app_send_message (application->unique_app,
+ COMMAND_START_DESKTOP, NULL);
} else {
nautilus_application_open_desktop (application);
}
}
- if (!is_remote) {
+ if (!unique_app_is_running (application->unique_app)) {
finish_startup (application, no_desktop);
- g_signal_connect (application->unique_app,
- "action-with-data",
- G_CALLBACK (message_received_cb), application);
+ g_signal_connect (application->unique_app, "message-received", G_CALLBACK (message_received_cb), application);
}
-
+
/* Monitor the preference to show or hide the desktop */
g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
G_CALLBACK(desktop_changed_callback),
@@ -959,31 +973,17 @@ nautilus_application_startup (NautilusApplication *application,
/* Create the other windows. */
if (urls != NULL || !no_default_window) {
- if (is_remote) {
- GVariant *variant;
- GVariantBuilder builder;
-
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
-
- if (geometry != NULL) {
- g_variant_builder_add (&builder, "{sv}",
- "geometry", g_variant_new ("s", geometry));
- }
-
- if (urls != NULL) {
- g_variant_builder_add (&builder, "{sv}",
- "urls", g_variant_new ("^as", urls));
+ if (unique_app_is_running (application->unique_app)) {
+ message = unique_message_data_new ();
+ _unique_message_data_set_geometry_and_uris (message, geometry, urls);
+ if (browser_window) {
+ unique_app_send_message (application->unique_app,
+ COMMAND_OPEN_BROWSER, message);
+ } else {
+ unique_app_send_message (application->unique_app,
+ UNIQUE_OPEN, message);
}
-
- g_variant_builder_add (&builder, "{sv}",
- "use_browser", g_variant_new ("b", browser_window));
- g_variant_builder_add (&builder, "{sv}",
- "startup_id", get_startup_id ());
- variant = g_variant_builder_end (&builder);
-
- g_application_invoke_action (application->unique_app,
- COMMAND_OPEN, variant);
- g_variant_unref (variant);
+ unique_message_data_free (message);
} else {
open_windows (application, NULL,
urls,
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index f57d6e2..adcd5c2 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -29,6 +29,7 @@
#include <gdk/gdk.h>
#include <gio/gio.h>
+#include <unique/unique.h>
#include <libegg/eggsmclient.h>
#include <libnautilus-private/nautilus-undo-manager.h>
@@ -60,7 +61,7 @@ typedef struct NautilusShell NautilusShell;
typedef struct {
GObject parent;
- GApplication *unique_app;
+ UniqueApp *unique_app;
EggSMClient *smclient;
NautilusUndoManager *undo_manager;
GVolumeMonitor *volume_monitor;
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index 3212918..34145f0 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -527,7 +527,7 @@ main (int argc, char *argv[])
uris);
g_strfreev (uris);
- if (g_application_is_remote (application->unique_app) ||
+ if (unique_app_is_running (application->unique_app) ||
kill_shell) {
exit_with_last_window = TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]