diff options
-rw-r--r-- | ChangeLog | 46 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 2 | ||||
-rw-r--r-- | lib/ephy-file-helpers.c | 42 | ||||
-rw-r--r-- | lib/ephy-file-helpers.h | 8 | ||||
-rw-r--r-- | src/.cvsignore | 2 | ||||
-rw-r--r-- | src/ephy-dbus.c | 319 | ||||
-rw-r--r-- | src/ephy-dbus.h | 15 | ||||
-rw-r--r-- | src/ephy-lockdown.c | 10 | ||||
-rw-r--r-- | src/ephy-main.c | 628 | ||||
-rw-r--r-- | src/ephy-shell.c | 256 | ||||
-rw-r--r-- | src/ephy-shell.h | 39 | ||||
-rw-r--r-- | src/epiphany.defs | 64 |
12 files changed, 800 insertions, 631 deletions
@@ -1,5 +1,51 @@ 2006-01-23 Christian Persch <chpe@cvs.gnome.org> + * embed/mozilla/MozDownload.cpp: + * lib/ephy-file-helpers.c: (ephy_file_helpers_init), + (ephy_ensure_dir_exists): + * lib/ephy-file-helpers.h: + + Add a GError** to ephy_file_helpers_init and ephy_ensure_dir_exists, + so we can show the error to the user in main(). + + * src/ephy-dbus.c: (ephy_dbus_connect_to_session_bus_cb), + (ephy_dbus_connect_to_system_bus_cb), (session_filter_func), + (system_filter_func), (ephy_dbus_connect_to_system_bus), + (ephy_dbus_connect_to_session_bus), (ephy_dbus_shutdown), + (ephy_dbus_finalize), (ephy_dbus_get_type), + (ephy_dbus_get_default), (ephy_dbus_get_bus), + (ephy_dbus_get_proxy), (_ephy_dbus_startup), (_ephy_dbus_release), + (_ephy_dbus_is_name_owner): + * src/ephy-dbus.h: + + Refactored. Propagate errors to callers via GError**, and change + lifecycle to the app lifetime. + + * src/ephy-lockdown.c: (ephy_lockdown_init), + (ephy_lockdown_finalize): + + Move gconf notification add/remove for the lockdown key dirs + here from main(). + + * src/ephy-shell.c: (ephy_shell_dispose), + (_ephy_shell_create_instance): + * src/ephy-shell.h: + * src/epiphany.defs: + + Remove ephy_shell_startup and related stuff. + + * src/ephy-main.c: (handle_url), (handle_email), + (shell_weak_notify), (dbus_g_proxy_finalized_cb), + (save_yourself_cb), (die_cb), (gnome_session_init), + (path_from_command_line_arg), (open_urls), (call_dbus_proxy), + (show_error_message), (main): + + Move all startup code to main(), so we can show errors to + the user instead of crashing when things go wrong. + Part of bug #326807. + +2006-01-23 Christian Persch <chpe@cvs.gnome.org> + * embed/mozilla/EphyPromptService.cpp: Invert button order. Bug #327381. diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index cf8a4e3e6..4591b1a90 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -777,7 +777,7 @@ GetFilePath (const char *filename) download_dir = ephy_file_get_downloads_dir (); - if (ephy_ensure_dir_exists (download_dir)) + if (ephy_ensure_dir_exists (download_dir, NULL)) { path = g_build_filename (download_dir, filename, NULL); } diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index b8acb26fb..c9c62d043 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -63,6 +63,8 @@ static char *dot_dir = NULL; static char *tmp_dir = NULL; static GList *del_on_exit = NULL; +GQuark ephy_file_helpers_error_quark; + const char * ephy_file_tmp_dir (void) { @@ -260,8 +262,8 @@ ephy_dot_dir (void) return dot_dir; } -void -ephy_file_helpers_init (void) +gboolean +ephy_file_helpers_init (GError **error) { const char *uuid; @@ -276,10 +278,14 @@ ephy_file_helpers_init (void) /* Put marker in env */ g_setenv (EPHY_UUID_ENVVAR, EPHY_UUID, TRUE); + ephy_file_helpers_error_quark = g_quark_from_static_string ("ephy-file-helpers-error"); + files = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_free); + + return ephy_ensure_dir_exists (ephy_dot_dir (), error); } static void @@ -321,21 +327,29 @@ ephy_file_helpers_shutdown (void) } gboolean -ephy_ensure_dir_exists (const char *dir) +ephy_ensure_dir_exists (const char *dir, + GError **error) { - if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) + if (g_file_test (dir, G_FILE_TEST_EXISTS) && + !g_file_test (dir, G_FILE_TEST_IS_DIR)) { - if (g_file_test (dir, G_FILE_TEST_EXISTS) == TRUE) - { - g_warning (_("\"%s\" exists, please move it out of the way."), dir); - return FALSE; - } + g_set_error (error, + EPHY_FILE_HELPERS_ERROR_QUARK, + 0, + _("ā%sā exists, please move it out of the way."), + dir); + return FALSE; + } - if (mkdir (dir, 488) != 0) - { - g_warning (_("Failed to create directory \"%s\"."), dir); - return FALSE; - } + if (!g_file_test (dir, G_FILE_TEST_EXISTS) && + mkdir (dir, 488) != 0) + { + g_set_error (error, + EPHY_FILE_HELPERS_ERROR_QUARK, + 0, + _("Failed to create directory ā%sā."), + dir); + return FALSE; } return TRUE; diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h index 15a1ff825..189cc17e2 100644 --- a/lib/ephy-file-helpers.h +++ b/lib/ephy-file-helpers.h @@ -27,6 +27,9 @@ #include <libgnomevfs/gnome-vfs-mime-handlers.h> #include <libgnomevfs/gnome-vfs-ops.h> +extern GQuark ephy_file_helpers_error_quark; +#define EPHY_FILE_HELPERS_ERROR_QUARK (ephy_file_helpers_error_quark) + G_BEGIN_DECLS typedef enum @@ -44,7 +47,7 @@ const char *ephy_file (const char *filename); const char *ephy_dot_dir (void); -void ephy_file_helpers_init (void); +gboolean ephy_file_helpers_init (GError **error); void ephy_file_helpers_shutdown (void); @@ -59,7 +62,8 @@ const char *ephy_file_tmp_dir (void); char *ephy_file_tmp_filename (const char *base, const char *extension); -gboolean ephy_ensure_dir_exists (const char *dir); +gboolean ephy_ensure_dir_exists (const char *dir, + GError **); GSList *ephy_file_find (const char *path, const char *fname, diff --git a/src/.cvsignore b/src/.cvsignore index 9278325f3..15ff81294 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,4 +1,6 @@ *.o +*.lo +*.la Makefile Makefile.in .deps diff --git a/src/ephy-dbus.c b/src/ephy-dbus.c index 61367f7a5..d01417837 100644 --- a/src/ephy-dbus.c +++ b/src/ephy-dbus.c @@ -28,13 +28,22 @@ #include <string.h> #include <dbus/dbus-glib-bindings.h> +/* dbus 0.6 API change */ +#ifndef DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT +#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0 +#endif + +#define RECONNECT_DELAY 3000 + #define EPHY_DBUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DBUS, EphyDbusPrivate)) struct _EphyDbusPrivate { DBusGConnection *session_bus; DBusGConnection *system_bus; - guint reconnect_timeout_id; + guint session_reconnect_timeout_id; + guint system_reconnect_timeout_id; + guint is_session_service_owner : 1; }; enum @@ -44,9 +53,11 @@ enum LAST_SIGNAL }; -static guint signals[LAST_SIGNAL] = { 0 }; +static EphyDbus *ephy_dbus_instance; -static GObjectClass *parent_class = NULL; +static guint signals[LAST_SIGNAL]; +static GObjectClass *parent_class; +GQuark ephy_dbus_error_quark; /* Filter signals form session bus */ static DBusHandlerResult session_filter_func (DBusConnection *connection, @@ -63,8 +74,8 @@ static void ephy_dbus_nm_devices_changed_cb (DBusGProxy *proxy, EphyDbus *ephy_dbus); /* Both connect to their respective bus */ -static void ephy_dbus_connect_to_session_bus (EphyDbus *dbus); -static void ephy_dbus_connect_to_system_bus (EphyDbus *dbus); +static gboolean ephy_dbus_connect_to_session_bus (EphyDbus*, GError**); +static gboolean ephy_dbus_connect_to_system_bus (EphyDbus*, GError**); /* implementation of the DBUS helpers */ @@ -72,27 +83,40 @@ static gboolean ephy_dbus_connect_to_session_bus_cb (gpointer user_data) { EphyDbus *dbus = EPHY_DBUS (user_data); - gboolean success; - - ephy_dbus_connect_to_session_bus (dbus); + GError *error = NULL; - success = (dbus->priv->session_bus != NULL); - if (success) + if (!ephy_dbus_connect_to_session_bus (dbus, &error)) { - dbus->priv->reconnect_timeout_id = 0; + g_error_free (error); + + /* try again */ + return TRUE; } - return !success; + dbus->priv->session_reconnect_timeout_id = 0; + + /* we're done */ + return FALSE; } static gboolean ephy_dbus_connect_to_system_bus_cb (gpointer user_data) { EphyDbus *dbus = EPHY_DBUS (user_data); + GError *error = NULL; + + if (!ephy_dbus_connect_to_system_bus (dbus, &error)) + { + g_error_free (error); + + /* try again */ + return TRUE; + } - ephy_dbus_connect_to_system_bus (dbus); + dbus->priv->system_reconnect_timeout_id = 0; - return dbus->priv->system_bus == NULL; + /* we're done */ + return FALSE; } static DBusHandlerResult @@ -114,8 +138,10 @@ session_filter_func (DBusConnection *connection, g_signal_emit (ephy_dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SESSION); /* try to reconnect later ... */ - ephy_dbus->priv->reconnect_timeout_id = - g_timeout_add (3000, (GSourceFunc) ephy_dbus_connect_to_session_bus_cb, ephy_dbus); + ephy_dbus->priv->session_reconnect_timeout_id = + g_timeout_add (RECONNECT_DELAY, + (GSourceFunc) ephy_dbus_connect_to_session_bus_cb, + ephy_dbus); return DBUS_HANDLER_RESULT_HANDLED; } @@ -144,33 +170,40 @@ system_filter_func (DBusConnection *connection, g_signal_emit (ephy_dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SYSTEM); /* try to reconnect later ... */ - g_timeout_add (3000, ephy_dbus_connect_to_system_bus_cb, (gpointer) ephy_dbus); + ephy_dbus->priv->system_reconnect_timeout_id = + g_timeout_add (RECONNECT_DELAY, + (GSourceFunc) ephy_dbus_connect_to_system_bus_cb, + ephy_dbus); return DBUS_HANDLER_RESULT_HANDLED; } + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -static void -ephy_dbus_connect_to_system_bus (EphyDbus *ephy_dbus) +static gboolean +ephy_dbus_connect_to_system_bus (EphyDbus *ephy_dbus, + GError **error) { DBusGProxy *proxy; - GError *error = NULL; LOG ("EphyDbus connecting to system DBUS"); - ephy_dbus->priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + ephy_dbus->priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); if (ephy_dbus->priv->system_bus == NULL) { - g_warning ("Unable to connect to system bus: %s", error->message); - g_error_free (error); - return; + g_warning ("Unable to connect to system bus: %s", error ? (*error)->message : ""); + return FALSE; } if (dbus_g_connection_get_connection (ephy_dbus->priv->system_bus) == NULL) { g_warning ("DBus connection is null"); - return; + g_set_error (error, + EPHY_DBUS_ERROR_QUARK, + 0, + "DBus connection is NULL"); + return FALSE; } dbus_connection_set_exit_on_disconnect @@ -186,13 +219,6 @@ ephy_dbus_connect_to_system_bus (EphyDbus *ephy_dbus) DBUS_NETWORK_MANAGER_PATH, DBUS_NETWORK_MANAGER_INTERFACE); - if (proxy == NULL) - { - g_warning ("Unable to get DBus proxy: %s", error->message); - g_error_free (error); - return; - } - dbus_g_proxy_add_signal (proxy, "DevicesChanged", G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (proxy, "DevicesChanged", @@ -202,24 +228,25 @@ ephy_dbus_connect_to_system_bus (EphyDbus *ephy_dbus) g_object_unref (proxy); g_signal_emit (ephy_dbus, signals[CONNECTED], 0, EPHY_DBUS_SYSTEM); + + return TRUE; } -static void -ephy_dbus_connect_to_session_bus (EphyDbus *ephy_dbus) +static gboolean +ephy_dbus_connect_to_session_bus (EphyDbus *ephy_dbus, + GError **error) { DBusGProxy *proxy; - GError *error = NULL; guint request_ret; LOG ("EphyDbus connecting to session DBUS"); /* Init the DBus connection */ - ephy_dbus->priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + ephy_dbus->priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error); if (ephy_dbus->priv->session_bus == NULL) { - g_warning("Unable to connect to session bus: %s", error->message); - g_error_free (error); - return; + g_warning("Unable to connect to session bus: %s", error ? (*error)->message : ""); + return FALSE; } dbus_connection_set_exit_on_disconnect @@ -244,43 +271,35 @@ ephy_dbus_connect_to_session_bus (EphyDbus *ephy_dbus) DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); -/* dbus 0.6 dependency */ -#ifndef DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT -#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0 -#endif - - org_freedesktop_DBus_request_name (proxy, - DBUS_EPHY_SERVICE, - DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, - &request_ret, &error); + if (!org_freedesktop_DBus_request_name (proxy, + DBUS_EPHY_SERVICE, + DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, + &request_ret, error)) + { + /* We have a BIG problem! */ + g_warning ("RequestName failed: %s\n", error ? (*error)->message : ""); + return FALSE; + } if (request_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - ephy_dbus->is_session_service_owner = TRUE; + ephy_dbus->priv->is_session_service_owner = TRUE; } - else + else if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS) { - /* if the bus replied that an owner already exists, we set the - * owner flag and proceed -- it means there's another epiphany - * instance running and we should simply forward the requests to - * it; however if it's another return code, we should (at least) - * print a warning */ - ephy_dbus->is_session_service_owner = FALSE; - - if ((request_ret != DBUS_REQUEST_NAME_REPLY_EXISTS) && - (error != NULL)) - { - g_warning("Unable to register service: %s", error->message); - } - + ephy_dbus->priv->is_session_service_owner = FALSE; } - if (error != NULL) + else { - g_error_free (error); + /* FIXME can this happen? */ + g_assert_not_reached (); } - LOG ("Instance is %ssession bus owner.", ephy_dbus->is_session_service_owner ? "" : "NOT "); + + LOG ("Instance is %ssession bus owner.", ephy_dbus->priv->is_session_service_owner ? "" : "NOT "); g_object_unref (proxy); + + return TRUE; } static void @@ -325,28 +344,21 @@ ephy_dbus_nm_devices_changed_cb (DBusGProxy *proxy, /* Public methods */ -void -ephy_dbus_startup (EphyDbus *dbus) -{ - g_return_if_fail (EPHY_IS_DBUS (dbus)); - - LOG ("EphyDbus startup"); - - ephy_dbus_connect_to_session_bus (dbus); - ephy_dbus_connect_to_system_bus (dbus); -} - -void +static void ephy_dbus_shutdown (EphyDbus *dbus) { - g_return_if_fail (EPHY_IS_DBUS (dbus)); - LOG ("EphyDbus shutdown"); - if (dbus->priv->reconnect_timeout_id != 0) + if (dbus->priv->session_reconnect_timeout_id != 0) + { + g_source_remove (dbus->priv->session_reconnect_timeout_id); + dbus->priv->session_reconnect_timeout_id = 0; + } + + if (dbus->priv->system_reconnect_timeout_id != 0) { - g_source_remove (dbus->priv->reconnect_timeout_id); - dbus->priv->reconnect_timeout_id = 0; + g_source_remove (dbus->priv->system_reconnect_timeout_id); + dbus->priv->system_reconnect_timeout_id = 0; } if (dbus->priv->session_bus) @@ -368,50 +380,6 @@ ephy_dbus_shutdown (EphyDbus *dbus) } } -DBusGConnection * -ephy_dbus_get_bus (EphyDbus *dbus, - EphyDbusBus kind) -{ - DBusGConnection *bus = NULL; - - g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL); - - switch (kind) - { - case EPHY_DBUS_SYSTEM: - bus = dbus->priv->system_bus; - break; - case EPHY_DBUS_SESSION: - bus = dbus->priv->session_bus; - break; - default: - bus = dbus->priv->session_bus; - } - return bus; -} - -DBusGProxy * -ephy_dbus_get_proxy (EphyDbus *dbus, - EphyDbusBus kind) -{ - DBusGConnection *bus = NULL; - - g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL); - - bus = ephy_dbus_get_bus (dbus, kind); - - if (bus == NULL) - { - g_warning ("Unable to get proxy for DBus's s bus."); - return NULL; - } - - return dbus_g_proxy_new_for_name (bus, - DBUS_EPHY_SERVICE, - DBUS_EPHY_PATH, - DBUS_EPHY_INTERFACE); -} - /* Class implementation */ static void @@ -427,6 +395,9 @@ ephy_dbus_finalize (GObject *object) { EphyDbus *dbus = EPHY_DBUS (object); + /* Have to do this after the object's weak ref notifiers have + * been called, see https://bugs.freedesktop.org/show_bug.cgi?id=5688 + */ ephy_dbus_shutdown (dbus); LOG ("EphyDbus finalised"); @@ -495,3 +466,97 @@ ephy_dbus_get_type (void) return type; } + +EphyDbus * +ephy_dbus_get_default (void) +{ + g_assert (ephy_dbus_instance != NULL); + + return ephy_dbus_instance; +} + +DBusGConnection * +ephy_dbus_get_bus (EphyDbus *dbus, + EphyDbusBus kind) +{ + DBusGConnection *bus = NULL; + + g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL); + + if (kind == EPHY_DBUS_SYSTEM) + { + /* We connect lazily to the system bus */ + if (dbus->priv->system_bus == NULL) + { + ephy_dbus_connect_to_system_bus (dbus, NULL); + } + bus = dbus->priv->system_bus; + } + else if (kind == EPHY_DBUS_SESSION) + { + bus = dbus->priv->session_bus; + } + else + { + g_assert_not_reached (); + } + + g_assert (bus != NULL); + + return bus; +} + +DBusGProxy * +ephy_dbus_get_proxy (EphyDbus *dbus, + EphyDbusBus kind) +{ + DBusGConnection *bus = NULL; + + g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL); + + bus = ephy_dbus_get_bus (dbus, kind); + + if (bus == NULL) + { + g_warning ("Unable to get proxy for the %s bus.\n", + kind == EPHY_DBUS_SESSION ? "session" : "system"); + return NULL; + } + + return dbus_g_proxy_new_for_name (bus, + DBUS_EPHY_SERVICE, + DBUS_EPHY_PATH, + DBUS_EPHY_INTERFACE); +} + +/* private API */ + +gboolean +_ephy_dbus_startup (GError **error) +{ + g_assert (ephy_dbus_instance == NULL); + + ephy_dbus_error_quark = g_quark_from_static_string ("ephy-dbus-error"); + + ephy_dbus_instance = g_object_new (EPHY_TYPE_DBUS, NULL); + + /* We only connect to the session bus on startup*/ + return ephy_dbus_connect_to_session_bus (ephy_dbus_instance, error); +} + +void +_ephy_dbus_release (void) +{ + g_assert (ephy_dbus_instance != NULL); + + g_object_unref (ephy_dbus_instance); + ephy_dbus_instance = NULL; +} + +gboolean +_ephy_dbus_is_name_owner (void) +{ + g_assert (ephy_dbus_instance != NULL); + + return ephy_dbus_instance->priv->is_session_service_owner; +} diff --git a/src/ephy-dbus.h b/src/ephy-dbus.h index eb6b64d83..597109910 100644 --- a/src/ephy-dbus.h +++ b/src/ephy-dbus.h @@ -47,6 +47,9 @@ G_BEGIN_DECLS #define EPHY_IS_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_DBUS)) #define EPHY_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_DBUS, EphyDbusClass)) +extern GQuark ephy_dbus_error_quark; +#define EPHY_DBUS_ERROR_QUARK (ephy_dbus_error_quark) + typedef struct _EphyDbus EphyDbus; typedef struct _EphyDbusPrivate EphyDbusPrivate; typedef struct _EphyDbusClass EphyDbusClass; @@ -60,7 +63,6 @@ typedef enum struct _EphyDbus { GObject parent; - gboolean is_session_service_owner; /*< private >*/ EphyDbusPrivate *priv; @@ -79,9 +81,7 @@ struct _EphyDbusClass GType ephy_dbus_get_type (void); -void ephy_dbus_startup (EphyDbus *dbus); - -void ephy_dbus_shutdown (EphyDbus *dbus); +EphyDbus *ephy_dbus_get_default (void); DBusGConnection *ephy_dbus_get_bus (EphyDbus *dbus, EphyDbusBus kind); @@ -89,6 +89,13 @@ DBusGConnection *ephy_dbus_get_bus (EphyDbus *dbus, DBusGProxy *ephy_dbus_get_proxy (EphyDbus *dbus, EphyDbusBus kind); +/* private */ +gboolean _ephy_dbus_startup (GError **error); + +void _ephy_dbus_release (void); + +gboolean _ephy_dbus_is_name_owner (void); + G_END_DECLS #endif /* !EPHY_DBUS_H */ diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c index 48f6f5e1a..723042320 100644 --- a/src/ephy-lockdown.c +++ b/src/ephy-lockdown.c @@ -233,16 +233,17 @@ ephy_lockdown_init (EphyLockdown *lockdown) LOG ("EphyLockdown initialising"); - /* lockdown pref notifiers */ for (i = 0; i < G_N_ELEMENTS (keys); i++) { priv->notifier_id[i] =eel_gconf_notification_add (keys[i], (GConfClientNotifyFunc) notifier, lockdown); } - /* We know that no windows are open yet, - * so we don't need to do anything else here. + * so we don't need to do notify here. */ + + eel_gconf_monitor_add ("/apps/epiphany/lockdown"); + eel_gconf_monitor_add ("/desktop/gnome/lockdown"); } static void @@ -254,6 +255,9 @@ ephy_lockdown_finalize (GObject *object) LOG ("EphyLockdown finalising"); + eel_gconf_monitor_remove ("/apps/epiphany/lockdown"); + eel_gconf_monitor_remove ("/desktop/gnome/lockdown"); + for (i = 0; i < G_N_ELEMENTS (keys); i++) { eel_gconf_notification_remove (priv->notifier_id[i]); diff --git a/src/ephy-main.c b/src/ephy-main.c index 9eeadfebd..88444dae0 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -20,8 +20,6 @@ #include "config.h" -#undef GNOME_DISABLE_DEPRECATED - #include "ephy-shell.h" #include "ephy-file-helpers.h" #include "ephy-object-helpers.h" @@ -29,54 +27,88 @@ #include "ephy-debug.h" #include "ephy-stock-icons.h" #include "eel-gconf-extensions.h" +#include "ephy-dbus-client-bindings.h" +#include "ephy-activation.h" +#include "ephy-session.h" +#include "ephy-shell.h" +#include "ephy-debug.h" -#include <libgnomeui/gnome-ui-init.h> -#include <libgnomeui/gnome-app-helper.h> +#include <libxml/xmlversion.h> + +#include <glib/gi18n.h> + +#include <gdk/gdkx.h> #include <gtk/gtkaboutdialog.h> #include <gtk/gtkmain.h> #include <gtk/gtkmessagedialog.h> -#include <gdk/gdkx.h> + #include <libgnome/gnome-program.h> -#include <glib/gi18n.h> +#include <libgnomeui/gnome-client.h> + +/* libgnome < 2.13 compat */ +#ifndef GNOME_PARAM_GOPTION_CONTEXT +#include <libgnomeui/gnome-ui-init.h> +#endif + #include <libgnomevfs/gnome-vfs-init.h> #include <libgnomevfs/gnome-vfs-utils.h> -#include <libxml/xmlversion.h> +#include <libgnomeui/gnome-app-helper.h> + #include <errno.h> #include <string.h> -static gboolean open_in_existing = FALSE; +static GQuark startup_error_quark = 0; +#define STARTUP_ERROR_QUARK (startup_error_quark) + static gboolean open_in_new_tab = FALSE; -static gboolean open_fullscreen = FALSE; +static gboolean open_in_new_window = FALSE; static gboolean open_as_bookmarks_editor = FALSE; -static gboolean reload_plugins = FALSE; +//static gboolean reload_plugins = FALSE; static char *session_filename = NULL; static char *bookmark_url = NULL; static char *bookmarks_file = NULL; +static char **remaining_arguments = NULL; + +static const GOptionEntry option_entries[] = +{ + { "new-tab", 'n', 0, G_OPTION_ARG_NONE, &open_in_new_tab, + N_("Open a new tab in an existing Epiphany window"), NULL }, + { "new-window", 0, 0, G_OPTION_ARG_NONE, &open_in_new_window, + N_("Open a new tab in an existing Epiphany window"), NULL }, + { "bookmarks-editor", 'b', 0, G_OPTION_ARG_NONE, &open_as_bookmarks_editor, + N_("Launch the bookmarks editor"), NULL }, + { "import-bookmarks", '\0', 0, G_OPTION_ARG_FILENAME, &bookmarks_file, + N_("Import bookmarks from the given file"), N_("FILE") }, + { "load-session", 'l', 0, G_OPTION_ARG_FILENAME, &session_filename, + N_("Load the given session file"), N_("FILE") }, + { "add-bookmark", 't', 0, G_OPTION_ARG_STRING, &bookmark_url, + N_("Add a bookmark"), N_("URL") }, + { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining_arguments, + "", "" }, + { NULL } +}; -static struct poptOption popt_options[] = +#ifndef GNOME_PARAM_GOPTION_CONTEXT +/* libgnome < 2.13 compat */ +static char *sm_client_id = NULL; +static char *sm_config_prefix = NULL; +static gboolean sm_disable = FALSE; +static gboolean disable_crash_dialog = FALSE; + +static const GOptionEntry libgnome_option_entries[] = { - { "new-tab", 'n', POPT_ARG_NONE, &open_in_new_tab, 0, - N_("Open a new tab in an existing window"), - NULL }, - { "fullscreen", 'f', POPT_ARG_NONE, &open_fullscreen, 0, - N_("Run in full screen mode"), - NULL }, - { "load-session", 'l', POPT_ARG_STRING, &session_filename, 0, - N_("Load the given session file"), - N_("FILE") }, - { "add-bookmark", 't', POPT_ARG_STRING, &bookmark_url, - 0, N_("Add a bookmark (don't open any window)"), - N_("URL")}, - { "import-bookmarks", '\0', POPT_ARG_STRING, &bookmarks_file, - 0, N_("Import bookmarks from the given file"), - N_("FILE") }, - { "bookmarks-editor", 'b', POPT_ARG_NONE, &open_as_bookmarks_editor, 0, - N_("Launch the bookmarks editor"), - NULL }, - { "reload-plugins", '\0', POPT_ARG_NONE, &reload_plugins, 0, NULL, NULL }, - { NULL, 0, 0, NULL, 0, NULL, NULL } + { "sm-client-id", 0, 0, G_OPTION_ARG_STRING, &sm_client_id, + "Specify session management ID", "ID" }, + { "sm-config-prefix", 0, 0, G_OPTION_ARG_STRING, &sm_config_prefix, + "Specify prefix of saved configuration", "PREFIX" }, + { "sm-disable", 0, 0, G_OPTION_ARG_NONE, &sm_disable, + "Disable connection to session manager", NULL }, + { "disable-crash-dialog", 0, 0, G_OPTION_ARG_NONE, &disable_crash_dialog, + "Disable Crash Dialog", NULL }, + { NULL } }; +#endif /* !GNOME_PARAM_GOPTION_CONTEXT */ /* adapted from gtk+/gdk/x11/gdkdisplay-x11.c */ static guint32 @@ -111,34 +143,6 @@ get_startup_id (void) return retval; } -static void -handle_url (GtkAboutDialog *about, - const char *link, - gpointer data) -{ - ephy_shell_new_tab (ephy_shell, NULL, NULL, link, - EPHY_NEW_TAB_OPEN_PAGE); -} - -static void -handle_email (GtkAboutDialog *about, - const char *link, - gpointer data) -{ - char *address; - - address = g_strdup_printf ("mailto:%s\n", link); - gnome_vfs_url_show (address); - g_free (address); -} - -static void -shell_weak_notify (gpointer data, - GObject *where_the_object_was) -{ - gtk_main_quit (); -} - /* Copied from libnautilus/nautilus-program-choosing.c; Needed in case * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp). */ @@ -190,23 +194,284 @@ slowly_and_stupidly_obtain_timestamp (Display *xdisplay) return event.xproperty.time; } +static void +handle_url (GtkAboutDialog *about, + const char *link, + gpointer data) +{ + ephy_shell_new_tab (ephy_shell_get_default (), + NULL, NULL, link, + EPHY_NEW_TAB_OPEN_PAGE); +} + +static void +handle_email (GtkAboutDialog *about, + const char *link, + gpointer data) +{ + char *address; + + address = g_strdup_printf ("mailto:%s", link); + gnome_vfs_url_show (address); + g_free (address); +} + +static void +shell_weak_notify (gpointer data, + GObject *zombie) +{ + if (gtk_main_level ()) + { + gtk_main_quit (); + } +} + +static void +dbus_g_proxy_finalized_cb (EphyShell *shell, + GObject *zombie) +{ + LOG ("dbus_g_proxy_finalized_cb"); + + g_object_unref (shell); +} + +/* Gnome session client */ + +static gboolean +save_yourself_cb (GnomeClient *client, + gint phase, + GnomeSaveStyle save_style, + gboolean shutdown, + GnomeInteractStyle interact_style, + gboolean fast, + gpointer user_data) +{ + EphyShell *shell; + EphySession *session; + char *argv[] = { NULL, "--load-session", NULL }; + char *discard_argv[] = { "rm", "-f", NULL }; + char *tmp, *save_to; + + LOG ("save_yourself_cb"); + + /* FIXME FIXME */ + if (!ephy_shell_get_default ()) return FALSE; + + tmp = g_build_filename (ephy_dot_dir (), + "session_gnome-XXXXXX", + NULL); + save_to = ephy_file_tmp_filename (tmp, "xml"); + g_free (tmp); + + shell = ephy_shell_get_default (); + g_assert (shell != NULL); + + session = EPHY_SESSION (ephy_shell_get_session (shell)); + g_assert (session != NULL); + + argv[0] = g_get_prgname (); + argv[2] = save_to; + gnome_client_set_restart_command + (client, 3, argv); + + discard_argv[2] = save_to; + gnome_client_set_discard_command (client, 3, + discard_argv); + + ephy_session_save (session, save_to); + + g_free (save_to); + + return TRUE; +} + +static void +die_cb (GnomeClient* client, + gpointer user_data) + +{ + EphyShell *shell; + EphySession *session; + + LOG ("die_cb"); + + /* FIXME FIXME */ + if (!ephy_shell_get_default ()) return; + + shell = ephy_shell_get_default (); + g_assert (shell != NULL); + + session = EPHY_SESSION (ephy_shell_get_session (shell)); + g_assert (session != NULL); + + ephy_session_close (session); +} + +static void +gnome_session_init (void) +{ + GnomeClient *client; + + client = gnome_master_client (); + + g_signal_connect (client, "save_yourself", + G_CALLBACK (save_yourself_cb), NULL); + g_signal_connect (client, "die", + G_CALLBACK (die_cb), NULL); +} + +#if 0 +static char * +path_from_command_line_arg (const char *arg) +{ + char path[PATH_MAX]; + + if (realpath (arg, path) != NULL) + { + return g_strdup (path); + } + else + { + return g_strdup (arg); + } +} +#endif + +static gboolean +open_urls (DBusGProxy *proxy, + guint32 user_time, + GError **error) +{ + EphyShell *shell; + int i; + + shell = ephy_shell_get_default (); + + if (remaining_arguments == NULL) + { + /* Homepage or resume */ + org_gnome_Epiphany_load_url_async + (proxy, "", FALSE, !open_in_new_tab, + open_in_new_tab, user_time, + ephy_activation_general_purpose_reply, NULL /* FIXME! */); + } + else + { + for (i = 0; remaining_arguments[i] != NULL; ++i) + { + char *path; + + path = remaining_arguments[i]; + //path = path_from_command_line_arg (args[i]); + + org_gnome_Epiphany_load_url_async + (proxy, path, FALSE, !open_in_new_tab, + open_in_new_tab, user_time, + ephy_activation_general_purpose_reply, NULL /* FIXME */); + + //g_free (path); + } + + g_strfreev (remaining_arguments); + } + + return TRUE; +} + +static gboolean +call_dbus_proxy (DBusGProxy *proxy, + guint32 user_time, + GError **error) +{ + EphyShell *shell; + gboolean retval = TRUE; + + shell = ephy_shell_get_default (); + + if (open_as_bookmarks_editor) + { + org_gnome_Epiphany_open_bookmarks_editor_async + (proxy, user_time, + ephy_activation_general_purpose_reply, shell); + } + else if (session_filename != NULL) + { + org_gnome_Epiphany_load_session_async + (proxy, session_filename, user_time, + ephy_activation_general_purpose_reply, shell); + } +#if 0 + else if (flags & EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS) + { + org_gnome_Epiphany_import_bookmarks_async + (proxy, string_arg, + ephy_activation_general_purpose_reply, shell); + } + else if (flags & EPHY_SHELL_STARTUP_ADD_BOOKMARK) + { + org_gnome_Epiphany_add_bookmark_async + (proxy, string_arg, + ephy_activation_general_purpose_reply, shell); + } +#endif + else + { + /* no need to open the homepage if autoresume returns TRUE; + * we already opened session windows */ + if (!_ephy_dbus_is_name_owner () || + (ephy_session_autoresume + (EPHY_SESSION (ephy_shell_get_session (shell)), + user_time) == FALSE)) + { + retval = open_urls (proxy, user_time, error); + } + } + + /* FIXME why? */ + dbus_g_connection_flush (ephy_dbus_get_bus (ephy_dbus_get_default (), EPHY_DBUS_SESSION)); + + return retval; +} + +static void +show_error_message (GError **error) +{ + GtkWidget *dialog; + + /* FIXME better texts!!! */ + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Could not start GNOME Web Browser")); + gtk_message_dialog_format_secondary_text + (GTK_MESSAGE_DIALOG (dialog), + _("Startup failed because of the following error:\n%s"), + (*error)->message); + + g_clear_error (error); + + gtk_dialog_run (GTK_DIALOG (dialog)); +} + int -main (int argc, char *argv[]) +main (int argc, + char *argv[]) { - poptContext context; - GValue context_as_value = { 0 }; - GnomeProgram *program; - EphyShellStartupFlags startup_flags; - const char **args, *string_arg; + GOptionContext *option_context; + GOptionGroup *option_group; + DBusGProxy *proxy; + GError *error = NULL; guint32 user_time; - gboolean new_instance; - GError *err = NULL; +#ifndef GNOME_PARAM_GOPTION_CONTEXT + GPtrArray *fake_argv_array; +#endif #ifdef ENABLE_NLS /* Initialize the i18n stuff */ - bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); #endif /* check libxml2 API version epiphany was compiled with against the @@ -214,15 +479,82 @@ main (int argc, char *argv[]) */ LIBXML_TEST_VERSION + /* Initialise our debug helpers */ + ephy_debug_init (); + /* get this early, since gdk will unset the env var */ user_time = get_startup_id (); - program = gnome_program_init (PACKAGE, VERSION, - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PARAM_POPT_TABLE, popt_options, - GNOME_PARAM_HUMAN_READABLE_NAME, _("Web Browser"), - GNOME_PARAM_APP_DATADIR, DATADIR, - NULL); + option_context = g_option_context_new (_("GNOME Web Browser")); + option_group = g_option_group_new ("epiphany", + N_("GNOME Web Browser"), + N_("GNOME Web Browser options"), + NULL, NULL); + g_option_group_add_entries (option_group, option_entries); + + g_option_context_set_main_group (option_context, option_group); + +#ifdef GNOME_PARAM_GOPTION_CONTEXT + gnome_program_init (PACKAGE, VERSION, + LIBGNOMEUI_MODULE, argc, argv, + GNOME_PARAM_GOPTION_CONTEXT, option_context, + GNOME_PARAM_HUMAN_READABLE_NAME, _("Web Browser"), + GNOME_PARAM_APP_DATADIR, DATADIR, + NULL); + +#else /* !GNOME_PARAM_GOPTION_CONTEXT */ + + option_group = g_option_group_new ("gnome-compat", "GNOME GUI Library", + "Show GNOME GUI options", NULL, NULL); + g_option_group_set_translation_domain (option_group, "libgnomeui-2.0"); + g_option_group_add_entries (option_group, libgnome_option_entries); + g_option_context_add_group (option_context, option_group); + + /* Add the gtk+ option group, but don't open the default display! */ + option_group = gtk_get_option_group (FALSE); + g_option_context_add_group (option_context, option_group); + + if (!g_option_context_parse (option_context, &argc, &argv, &error)) + { + g_print ("%s\n", error->message); + g_error_free (error); + exit (1); + } + + fake_argv_array = g_ptr_array_new (); + + g_ptr_array_add (fake_argv_array, g_strdup (g_get_prgname ())); + if (sm_disable) + { + g_ptr_array_add (fake_argv_array, g_strdup ("--sm-disable")); + } + if (sm_client_id != NULL) + { + g_ptr_array_add (fake_argv_array, g_strdup ("--sm-client-id")); + g_ptr_array_add (fake_argv_array, sm_client_id); + } + if (sm_config_prefix != NULL) + { + g_ptr_array_add (fake_argv_array, g_strdup ("--sm-config-prefix")); + g_ptr_array_add (fake_argv_array, sm_config_prefix); + } + if (disable_crash_dialog) + { + g_ptr_array_add (fake_argv_array, g_strdup ("--disable-crash-dialog")); + } + + gnome_program_init (PACKAGE, VERSION, + LIBGNOMEUI_MODULE, + fake_argv_array->len, + (char**) fake_argv_array->pdata, + GNOME_PARAM_HUMAN_READABLE_NAME, _("Web Browser"), + GNOME_PARAM_APP_DATADIR, DATADIR, + NULL); + + g_ptr_array_add (fake_argv_array, NULL); + g_strfreev ((char**) g_ptr_array_free (fake_argv_array, FALSE)); + +#endif /* GNOME_PARAM_GOPTION_CONTEXT */ /* Get a timestamp manually if need be */ if (user_time == 0) @@ -236,90 +568,124 @@ main (int argc, char *argv[]) /* Set default window icon */ gtk_window_set_default_icon_name ("web-browser"); - g_object_get_property (G_OBJECT (program), - GNOME_PARAM_POPT_CONTEXT, - g_value_init (&context_as_value, G_TYPE_POINTER)); - context = g_value_get_pointer (&context_as_value); - args = poptGetArgs (context); + startup_error_quark = g_quark_from_static_string ("epiphany-startup-error"); - startup_flags = 0; - string_arg = NULL; - if (open_in_new_tab) - { - startup_flags |= EPHY_SHELL_STARTUP_TABS; - } - else if (open_fullscreen) - { - startup_flags |= EPHY_SHELL_STARTUP_FULLSCREEN; - } - else if (open_in_existing) - { - startup_flags |= EPHY_SHELL_STARTUP_EXISTING_WINDOW; - } - else if (open_as_bookmarks_editor) - { - startup_flags |= EPHY_SHELL_STARTUP_BOOKMARKS_EDITOR; - } - else if (session_filename != NULL) + if (!_ephy_dbus_startup (&error)) { - startup_flags |= EPHY_SHELL_STARTUP_SESSION; - string_arg = session_filename; + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + show_error_message (&error); + + exit (1); } - else if (bookmarks_file != NULL) + + /* If we're remoting, no need to start up any further services, + * just forward the call. + */ + if (!_ephy_dbus_is_name_owner ()) { - startup_flags |= EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS; - string_arg = bookmarks_file; + /* FIXME */ + proxy = ephy_dbus_get_proxy (ephy_dbus_get_default (), EPHY_DBUS_SESSION); + if (proxy == NULL) + { + error = g_error_new (STARTUP_ERROR_QUARK, + 0, + "Unable to get DBus proxy; aborting activation."); /* FIXME i18n */ + } + + if (proxy != NULL && + call_dbus_proxy (proxy, user_time, &error)) + { + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + exit (0); + } + + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + show_error_message (&error); + + exit (1); } - else if (bookmark_url != NULL) + + /* We're not remoting; start our services */ + + if (!ephy_file_helpers_init (&error)) { - startup_flags |= EPHY_SHELL_STARTUP_ADD_BOOKMARK; - string_arg = bookmark_url; + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + show_error_message (&error); + + exit (1); } + /* init the session manager up here so we can quit while the resume dialogue is shown */ + gnome_session_init (); + + eel_gconf_monitor_add ("/apps/epiphany/general"); gnome_vfs_init (); - ephy_debug_init (); - ephy_file_helpers_init (); ephy_stock_icons_init (); - eel_gconf_monitor_add ("/apps/epiphany/general"); - eel_gconf_monitor_add ("/apps/epiphany/lockdown"); - eel_gconf_monitor_add ("/desktop/gnome/lockdown"); /* Extensions may want these, so don't initialize in window-cmds */ gtk_about_dialog_set_url_hook (handle_url, NULL, NULL); gtk_about_dialog_set_email_hook (handle_email, NULL, NULL); - ephy_shell_new (); - g_assert (ephy_shell != NULL); - new_instance = ephy_shell_startup (ephy_shell, startup_flags, - user_time, - args, string_arg, &err); + /* Now create the shell */ + _ephy_shell_create_instance (); - if (err != NULL) + /* Create DBUS proxy */ + proxy = ephy_dbus_get_proxy (ephy_dbus_get_default (), EPHY_DBUS_SESSION); + if (proxy == NULL) { - GtkWidget *dialog; + error = g_error_new (STARTUP_ERROR_QUARK, + 0, + "Unable to get DBus proxy; aborting activation."); /* FIXME i18n */ + + g_object_unref (ephy_shell_get_default ()); + + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + show_error_message (&error); - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_BUTTONS_CLOSE, - GTK_MESSAGE_ERROR, err->message); - gtk_dialog_run (GTK_DIALOG (dialog)); + exit (1); } - else if (new_instance && ephy_shell) + + g_object_weak_ref (G_OBJECT (proxy), + (GWeakNotify) dbus_g_proxy_finalized_cb, + g_object_ref (ephy_shell_get_default ())); + + if (!call_dbus_proxy (proxy, user_time, &error)) { - g_object_weak_ref (G_OBJECT (ephy_shell), shell_weak_notify, NULL); - ephy_object_idle_unref (ephy_shell); + g_object_unref (ephy_shell_get_default ()); + + _ephy_dbus_release (); + + gdk_notify_startup_complete (); + show_error_message (&error); - gtk_main (); + exit (1); } + /* We'll release the initial reference on idle */ + g_object_weak_ref (G_OBJECT (ephy_shell), shell_weak_notify, NULL); + ephy_object_idle_unref (ephy_shell); + + gtk_main (); + + /* Shutdown */ eel_gconf_monitor_remove ("/apps/epiphany/general"); - eel_gconf_monitor_remove ("/apps/epiphany/lockdown"); - eel_gconf_monitor_remove ("/desktop/gnome/lockdown"); gnome_accelerators_sync (); ephy_state_save (); ephy_file_helpers_shutdown (); gnome_vfs_shutdown (); xmlCleanupParser (); - poptFreeContext (context); + + _ephy_dbus_release (); return 0; } diff --git a/src/ephy-shell.c b/src/ephy-shell.c index b89b931c4..62b2788d6 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -47,19 +47,12 @@ #include "print-dialog.h" #include "ephy-prefs.h" #include "ephy-gui.h" -#include "ephy-dbus.h" -#include "ephy-dbus-client-bindings.h" -#include "ephy-activation.h" #include <string.h> #include <glib/gi18n.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkmessagedialog.h> #include <gtk/gtknotebook.h> #include <dirent.h> #include <unistd.h> -#include <libgnomeui/gnome-client.h> #define AUTOMATION_IID "OAFIID:GNOME_Epiphany_Automation" @@ -73,7 +66,6 @@ struct _EphyShellPrivate EggToolbarsModel *toolbars_model; EggToolbarsModel *fs_toolbars_model; EphyExtensionsManager *extensions_manager; - GObject *dbus_service; GtkWidget *bme; GtkWidget *history_window; GObject *pdm_dialog; @@ -93,19 +85,6 @@ static GObject *impl_get_embed_single (EphyEmbedShell *embed_shell); static GObjectClass *parent_class = NULL; -GQuark -ephy_shell_error_quark (void) -{ - static GQuark q = 0; - - if (q == 0) - { - q = g_quark_from_static_string ("ephy-shell-error-quark"); - } - - return q; -} - GType ephy_shell_get_type (void) { @@ -268,213 +247,6 @@ ephy_shell_init (EphyShell *shell) (gpointer *)ptr); } -static char * -path_from_command_line_arg (const char *arg) -{ - char path[PATH_MAX]; - - if (realpath (arg, path) != NULL) - { - return g_strdup (path); - } - else - { - return g_strdup (arg); - } -} - -static void -open_urls (DBusGProxy *proxy, - guint32 user_time, - const char **args, - gboolean new_tab, - gboolean existing_window, - gboolean fullscreen) -{ - int i; - - if (args == NULL) - { - /* Homepage or resume */ - org_gnome_Epiphany_load_url_async - (proxy, "", fullscreen, existing_window, new_tab, - user_time, ephy_activation_general_purpose_reply, - NULL); - } - else - { - for (i = 0; args[i] != NULL; i++) - { - char *path; - - path = path_from_command_line_arg (args[i]); - - org_gnome_Epiphany_load_url_async - (proxy, path, fullscreen, existing_window, - new_tab, user_time, - ephy_activation_general_purpose_reply, NULL); - - g_free (path); - } - } -} - -static gboolean -save_yourself_cb (GnomeClient *client, - gint phase, - GnomeSaveStyle save_style, - gboolean shutdown, - GnomeInteractStyle interact_style, - gboolean fast, - EphyShell *shell) -{ - char *argv[] = { NULL, "--load-session", NULL }; - char *discard_argv[] = { "rm", "-f", NULL }; - EphySession *session; - char *tmp, *save_to; - - LOG ("save_yourself_cb"); - - tmp = g_build_filename (ephy_dot_dir (), - "session_gnome-XXXXXX", - NULL); - save_to = ephy_file_tmp_filename (tmp, "xml"); - g_free (tmp); - - session = EPHY_SESSION (ephy_shell_get_session (shell)); - - argv[0] = g_get_prgname (); - argv[2] = save_to; - gnome_client_set_restart_command - (client, 3, argv); - - discard_argv[2] = save_to; - gnome_client_set_discard_command (client, 3, - discard_argv); - - ephy_session_save (session, save_to); - - g_free (save_to); - - return TRUE; -} - -static void -die_cb (GnomeClient* client, - EphyShell *shell) -{ - EphySession *session; - - LOG ("die_cb"); - - session = EPHY_SESSION (ephy_shell_get_session (shell)); - ephy_session_close (session); -} - -static void -dbus_g_proxy_finalized_cb (EphyShell *ephy_shell, - GObject *where_the_object_was) -{ - g_object_unref (ephy_shell); -} - -static void -gnome_session_init (EphyShell *shell) -{ - GnomeClient *client; - - client = gnome_master_client (); - - g_signal_connect_object (client, "save_yourself", - G_CALLBACK (save_yourself_cb), shell, 0); - /* don't use connect_object here, since that will ref the shell - * while dispatching the callbacks! - */ - g_signal_connect (client, "die", - G_CALLBACK (die_cb), shell); -} - -gboolean -ephy_shell_startup (EphyShell *shell, - EphyShellStartupFlags flags, - guint32 user_time, - const char **args, - const char *string_arg, - GError **error) -{ - EphyDbus *ephy_dbus; - DBusGProxy *proxy; - - ephy_ensure_dir_exists (ephy_dot_dir ()); - - ephy_dbus = EPHY_DBUS (ephy_shell_get_dbus_service (shell)); - g_assert (ephy_dbus != NULL); - - proxy = ephy_dbus_get_proxy (ephy_dbus, EPHY_DBUS_SESSION); - if (proxy == NULL) - { - g_warning ("Unable to get DBus proxy; aborting activation."); - gdk_notify_startup_complete (); - return FALSE; - } - g_object_ref (ephy_shell); - g_object_weak_ref (G_OBJECT (proxy), - (GWeakNotify) dbus_g_proxy_finalized_cb, - ephy_shell); - - if (ephy_dbus->is_session_service_owner == TRUE) - { - LOG ("Instance is session service owner"); - - /* init the session manager up here so we can quit while the resume dialogue is on */ - gnome_session_init (shell); - } - - if (flags & EPHY_SHELL_STARTUP_BOOKMARKS_EDITOR) - { - org_gnome_Epiphany_open_bookmarks_editor_async - (proxy, user_time, - ephy_activation_general_purpose_reply, ephy_shell); - } - else if (flags & EPHY_SHELL_STARTUP_SESSION) - { - org_gnome_Epiphany_load_session_async - (proxy, string_arg, user_time, - ephy_activation_general_purpose_reply, ephy_shell); - } - else if (flags & EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS) - { - org_gnome_Epiphany_import_bookmarks_async - (proxy, string_arg, - ephy_activation_general_purpose_reply, ephy_shell); - } - else if (flags & EPHY_SHELL_STARTUP_ADD_BOOKMARK) - { - org_gnome_Epiphany_add_bookmark_async - (proxy, string_arg, - ephy_activation_general_purpose_reply, ephy_shell); - } - else - { - /* no need to open the homepage if autoresume returns TRUE; - * we already opened session windows */ - if ((ephy_dbus->is_session_service_owner == FALSE) || - (ephy_session_autoresume - (EPHY_SESSION (ephy_shell_get_session (ephy_shell)), - user_time) == FALSE)) - { - open_urls (proxy, user_time, args, - flags & EPHY_SHELL_STARTUP_TABS, - flags & EPHY_SHELL_STARTUP_EXISTING_WINDOW, - flags & EPHY_SHELL_STARTUP_FULLSCREEN); - } - } - - dbus_g_connection_flush (ephy_dbus_get_bus (ephy_dbus, EPHY_DBUS_SESSION)); - gdk_notify_startup_complete (); - return ephy_dbus->is_session_service_owner; -} - static void ephy_shell_dispose (GObject *object) { @@ -491,13 +263,6 @@ ephy_shell_dispose (GObject *object) priv->extensions_manager = NULL; } - if (priv->dbus_service != NULL) - { - LOG ("Shutting down DBUS service"); - g_object_unref (priv->dbus_service); - priv->dbus_service = NULL; - } - if (priv->session != NULL) { LOG ("Unref session manager"); @@ -592,12 +357,6 @@ ephy_shell_get_default (void) return ephy_shell; } -EphyShell * -ephy_shell_new (void) -{ - return EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL, NULL)); -} - static gboolean url_is_empty (const char *location) { @@ -1021,16 +780,13 @@ ephy_shell_get_print_setup_dialog (EphyShell *shell) return shell->priv->print_setup_dialog; } -GObject * -ephy_shell_get_dbus_service (EphyShell *shell) +void +_ephy_shell_create_instance (void) { - g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); + g_assert (ephy_shell == NULL); - if (shell->priv->dbus_service == NULL) - { - shell->priv->dbus_service = g_object_new (EPHY_TYPE_DBUS, NULL); - ephy_dbus_startup (EPHY_DBUS (shell->priv->dbus_service)); - } + ephy_shell = EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL, NULL)); + /* FIXME weak ref */ - return G_OBJECT (shell->priv->dbus_service); + g_assert (ephy_shell != NULL); } diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 17319d79f..2581e48bb 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -45,26 +45,6 @@ typedef struct _EphyShellPrivate EphyShellPrivate; extern EphyShell *ephy_shell; -#define EPHY_SHELL_ERROR ephy_shell_error_quark () - -typedef enum -{ - EPHY_SHELL_ERROR_MISSING_SERVER, - EPHY_SHELL_ERROR_OBJECT_REG_FAILED, - EPHY_SHELL_ERROR_FACTORY_REG_FAILED -} EphyShellError; - -typedef enum -{ - EPHY_SHELL_STARTUP_TABS = 1 << 0, - EPHY_SHELL_STARTUP_EXISTING_WINDOW = 1 << 2, - EPHY_SHELL_STARTUP_FULLSCREEN = 1 << 3, - EPHY_SHELL_STARTUP_BOOKMARKS_EDITOR = 1 << 4, - EPHY_SHELL_STARTUP_SESSION = 1 << 5, - EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS = 1 << 6, - EPHY_SHELL_STARTUP_ADD_BOOKMARK = 1 << 7 -} EphyShellStartupFlags; - typedef enum { /* Page types */ @@ -97,27 +77,12 @@ struct _EphyShellClass EphyEmbedShellClass parent_class; }; -GType ephy_shell_error_get_type (void) G_GNUC_CONST; - -GType ephy_shell_startup_flags_get_type (void) G_GNUC_CONST; - GType ephy_new_tab_flags_get_type (void) G_GNUC_CONST; GType ephy_shell_get_type (void); -GQuark ephy_shell_error_quark (void); - EphyShell *ephy_shell_get_default (void); -EphyShell *ephy_shell_new (void); - -gboolean ephy_shell_startup (EphyShell *shell, - EphyShellStartupFlags flags, - guint32 user_time, - const char **args, - const char *string_arg, - GError **error); - EphyTab *ephy_shell_new_tab (EphyShell *shell, EphyWindow *parent_window, EphyTab *previous_tab, @@ -154,6 +119,10 @@ GObject *ephy_shell_get_print_setup_dialog (EphyShell *shell); GObject *ephy_shell_get_dbus_service (EphyShell *shell); +/* private API */ + +void _ephy_shell_create_instance (void); + G_END_DECLS #endif diff --git a/src/epiphany.defs b/src/epiphany.defs index 76c0e0322..34ce537de 100644 --- a/src/epiphany.defs +++ b/src/epiphany.defs @@ -404,32 +404,6 @@ ) ) -(define-enum ShellError - (in-module "Ephy") - (c-name "EphyShellError") - (gtype-id "EPHY_TYPE_SHELL_ERROR") - (values - '("missing-server" "EPHY_SHELL_ERROR_MISSING_SERVER") - '("object-reg-failed" "EPHY_SHELL_ERROR_OBJECT_REG_FAILED") - '("factory-reg-failed" "EPHY_SHELL_ERROR_FACTORY_REG_FAILED") - ) -) - -(define-flags ShellStartupFlags - (in-module "Ephy") - (c-name "EphyShellStartupFlags") - (gtype-id "EPHY_TYPE_SHELL_STARTUP_FLAGS") - (values - '("tabs" "EPHY_SHELL_STARTUP_TABS") - '("existing-window" "EPHY_SHELL_STARTUP_EXISTING_WINDOW") - '("fullscreen" "EPHY_SHELL_STARTUP_FULLSCREEN") - '("bookmarks-editor" "EPHY_SHELL_STARTUP_BOOKMARKS_EDITOR") - '("session" "EPHY_SHELL_STARTUP_SESSION") - '("import-bookmarks" "EPHY_SHELL_STARTUP_IMPORT_BOOKMARKS") - '("add-bookmark" "EPHY_SHELL_STARTUP_ADD_BOOKMARK") - ) -) - (define-flags NewTabFlags (in-module "Ephy") (c-name "EphyNewTabFlags") @@ -3033,16 +3007,6 @@ ;; From ../../src/ephy-shell.h -(define-function ephy_shell_error_get_type - (c-name "ephy_shell_error_get_type") - (return-type "GType") -) - -(define-function ephy_shell_startup_flags_get_type - (c-name "ephy_shell_startup_flags_get_type") - (return-type "GType") -) - (define-function ephy_new_tab_flags_get_type (c-name "ephy_new_tab_flags_get_type") (return-type "GType") @@ -3053,11 +3017,6 @@ (return-type "GType") ) -(define-function ephy_shell_error_quark - (c-name "ephy_shell_error_quark") - (return-type "GQuark") -) - (define-function ephy_shell_get_default (c-name "ephy_shell_get_default") (return-type "EphyShell*") @@ -3069,19 +3028,6 @@ (return-type "EphyShell*") ) -(define-method startup - (of-object "EphyShell") - (c-name "ephy_shell_startup") - (return-type "gboolean") - (parameters - '("EphyShellStartupFlags" "flags") - '("guint32" "user_time") - '("const-char**" "args") - '("const-char*" "string_arg") - '("GError**" "error") - ) -) - (define-method new_tab (of-object "EphyShell") (c-name "ephy_shell_new_tab") @@ -3518,16 +3464,6 @@ (return-type "GType") ) -(define-function ephy_shell_error_get_type - (c-name "ephy_shell_error_get_type") - (return-type "GType") -) - -(define-function ephy_shell_startup_flags_get_type - (c-name "ephy_shell_startup_flags_get_type") - (return-type "GType") -) - (define-function ephy_new_tab_flags_get_type (c-name "ephy_new_tab_flags_get_type") (return-type "GType") |