diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | data/ui/epiphany-ui.xml | 1 | ||||
-rw-r--r-- | embed/ephy-embed-single.c | 30 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 44 | ||||
-rw-r--r-- | embed/mozilla/EphySingle.cpp | 35 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 41 | ||||
-rw-r--r-- | src/ephy-window.c | 37 | ||||
-rw-r--r-- | src/window-commands.c | 15 | ||||
-rw-r--r-- | src/window-commands.h | 3 |
9 files changed, 191 insertions, 33 deletions
@@ -1,3 +1,21 @@ +2004-06-26 Christian Persch <chpe@cvs.gnome.org> + + * data/ui/epiphany-ui.xml: + * embed/ephy-embed-single.c: (ephy_embed_single_iface_init), + (ephy_embed_single_set_offline_mode), + (ephy_embed_single_get_offline_mode): + * embed/ephy-embed-single.h: + * embed/mozilla/EphySingle.cpp: + * embed/mozilla/mozilla-embed-single.cpp: + * src/ephy-window.c: (network_status_changed), (ephy_window_init), + (ephy_window_finalize): + * src/window-commands.c: (window_cmd_file_save_as), + (window_cmd_file_work_offline): + * src/window-commands.h: + + Implement File->Work Off-Line command and backend. + No DBUS/HAL/whatever integration yet. + 2004-06-26 Marco Pesenti Gritti <marco@gnome.org> * src/bookmarks/ephy-bookmarks-import.c: (ephy_bookmarks_import), diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml index 6da7f0f16..73a740796 100644 --- a/data/ui/epiphany-ui.xml +++ b/data/ui/epiphany-ui.xml @@ -11,6 +11,7 @@ <menuitem name="FilePrintPreviewMenu" action="FilePrintPreview"/> <menuitem name="FilePrintMenu" action="FilePrint"/> <menuitem name="FileSendToMenu" action="FileSendTo"/> + <menuitem name="FileWorkOfflineItem" action="FileWorkOffline"/> <separator name="FileSep3"/> <menuitem name="FileCloseWindowMenu" action="FileCloseWindow"/> </menu> diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index 9581883e4..c609d3efc 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -81,6 +81,23 @@ ephy_embed_single_iface_init (gpointer g_class) G_TYPE_STRING, G_TYPE_STRING); +/** + * EphyEmbedSingle::network-status: + * @single: + * @offline: the network status + * + * The ::network-status signal is emitted when the network status changes. + **/ + g_signal_new ("network-status", + EPHY_TYPE_EMBED_SINGLE, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyEmbedSingleIface, network_status), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, + 1, + G_TYPE_BOOLEAN); + initialised = TRUE; } } @@ -135,6 +152,19 @@ ephy_embed_single_set_offline_mode (EphyEmbedSingle *single, } /** + * ephy_embed_single_get_offline_mode: + * @single: the #EphyEmbedSingle + * + * Gets the state of the network connection. + **/ +gboolean +ephy_embed_single_get_offline_mode (EphyEmbedSingle *single) +{ + EphyEmbedSingleIface *iface = EPHY_EMBED_SINGLE_GET_IFACE (single); + return iface->get_offline_mode (single); +} + +/** * ephy_embed_single_load_proxy_autoconf: * @single: the #EphyEmbedSingle * @url: a URL to a PAC file diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index 3893a4aa8..b7b66d13b 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -45,40 +45,46 @@ struct _EphyEmbedSingleIface char *mime_type, char *uri); + void (* network_status) (EphyEmbedSingle *single, + gboolean offline); + /* Methods */ - void (* open_window) (EphyEmbedSingle *single, - EphyEmbed *parent, - const char *address, - const char *features); - void (* clear_cache) (EphyEmbedSingle *shell); - void (* clear_auth_cache) (EphyEmbedSingle *shell); - void (* set_offline_mode) (EphyEmbedSingle *shell, - gboolean offline); - void (* load_proxy_autoconf) (EphyEmbedSingle *shell, - const char* url); - GList * (* get_font_list) (EphyEmbedSingle *shell, - const char *langGroup); + void (* open_window) (EphyEmbedSingle *single, + EphyEmbed *parent, + const char *address, + const char *features); + void (* clear_cache) (EphyEmbedSingle *shell); + void (* clear_auth_cache) (EphyEmbedSingle *shell); + void (* set_offline_mode) (EphyEmbedSingle *shell, + gboolean offline); + gboolean (* get_offline_mode) (EphyEmbedSingle *single); + void (* load_proxy_autoconf) (EphyEmbedSingle *shell, + const char* url); + GList * (* get_font_list) (EphyEmbedSingle *shell, + const char *langGroup); }; -GType ephy_embed_single_get_type (void); +GType ephy_embed_single_get_type (void); -void ephy_embed_single_open_window (EphyEmbedSingle *single, +void ephy_embed_single_open_window (EphyEmbedSingle *single, EphyEmbed *parent, const char *address, const char *features); -void ephy_embed_single_clear_cache (EphyEmbedSingle *single); +void ephy_embed_single_clear_cache (EphyEmbedSingle *single); -void ephy_embed_single_clear_auth_cache (EphyEmbedSingle *single); +void ephy_embed_single_clear_auth_cache (EphyEmbedSingle *single); -void ephy_embed_single_set_offline_mode (EphyEmbedSingle *single, +void ephy_embed_single_set_offline_mode (EphyEmbedSingle *single, gboolean offline); -void ephy_embed_single_load_proxy_autoconf (EphyEmbedSingle *single, +gboolean ephy_embed_single_get_offline_mode (EphyEmbedSingle *single); + +void ephy_embed_single_load_proxy_autoconf (EphyEmbedSingle *single, const char* url); -GList *ephy_embed_single_get_font_list (EphyEmbedSingle *single, +GList *ephy_embed_single_get_font_list (EphyEmbedSingle *single, const char *lang_group); G_END_DECLS diff --git a/embed/mozilla/EphySingle.cpp b/embed/mozilla/EphySingle.cpp index b667c16d1..e059b5344 100644 --- a/embed/mozilla/EphySingle.cpp +++ b/embed/mozilla/EphySingle.cpp @@ -37,10 +37,9 @@ NS_IMPL_ISUPPORTS1(EphySingle, nsIObserver) EphySingle::EphySingle() +: mOwner(nsnull) { - LOG ("EphySingle constructor") - - mOwner = nsnull; + LOG ("EphySingle ctor") } nsresult @@ -48,14 +47,17 @@ EphySingle::Init (EphyEmbedSingle *aOwner) { LOG ("EphySingle::Init") - mOwner = aOwner; - mObserverService = do_GetService ("@mozilla.org/observer-service;1"); NS_ENSURE_TRUE (mObserverService, NS_ERROR_FAILURE); - mObserverService->AddObserver (this, "cookie-changed", PR_FALSE); - mObserverService->AddObserver (this, "cookie-rejected", PR_FALSE); - mObserverService->AddObserver (this, "perm-changed", PR_FALSE); + nsresult rv; + rv = mObserverService->AddObserver (this, "cookie-changed", PR_TRUE); + rv |= mObserverService->AddObserver (this, "cookie-rejected", PR_TRUE); + rv |= mObserverService->AddObserver (this, "perm-changed", PR_TRUE); + rv |= mObserverService->AddObserver (this, "network:offline-status-changed", PR_TRUE); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + mOwner = aOwner; return NS_OK; } @@ -63,11 +65,14 @@ EphySingle::Init (EphyEmbedSingle *aOwner) nsresult EphySingle::Detach () { + LOG ("EphySingle::Detach") + if (mObserverService) { mObserverService->RemoveObserver (this, "cookie-changed"); mObserverService->RemoveObserver (this, "cookie-rejected"); mObserverService->RemoveObserver (this, "perm-changed"); + mObserverService->RemoveObserver (this, "network:offline-status-changed"); } return NS_OK; @@ -75,9 +80,8 @@ EphySingle::Detach () EphySingle::~EphySingle() { - LOG ("EphySingle destructor") + LOG ("EphySingle dtor") - Detach(); mOwner = nsnull; } @@ -202,9 +206,18 @@ NS_IMETHODIMP EphySingle::Observe(nsISupports *aSubject, rv = NS_ERROR_FAILURE; } } + else if (strcmp (aTopic, "network:offline-status-changed") == 0) + { + /* aData is either (PRUnichar[]) "offline" or "online" */ + gboolean offline; + + offline = (aData[1] == 'f'); + + g_signal_emit_by_name (mOwner, "network-status", offline); + } else { - g_warning ("EphySingle observed unknown topic!\n"); + g_warning ("EphySingle observed unknown topic '%s'!\n", aTopic); rv = NS_ERROR_FAILURE; } diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 62efe62de..33f14737e 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -414,11 +414,17 @@ mozilla_init_chrome (void) static void mozilla_init_observer (MozillaEmbedSingle *single) { - single->priv->mSingleObserver = new EphySingle (); + EphySingle *observer; - if (single->priv->mSingleObserver) + observer = new EphySingle (); + + if (observer) { - single->priv->mSingleObserver->Init (EPHY_EMBED_SINGLE (single)); + nsresult rv; + rv = observer->Init (EPHY_EMBED_SINGLE (single)); + if (NS_FAILED (rv)) return; + + NS_ADDREF (single->priv->mSingleObserver = observer); } } @@ -492,6 +498,19 @@ mozilla_embed_single_init (MozillaEmbedSingle *mes) } static void +mozilla_embed_single_dispose (GObject *object) +{ + MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (object); + + if (single->priv->mSingleObserver) + { + single->priv->mSingleObserver->Detach (); + NS_RELEASE (single->priv->mSingleObserver); + single->priv->mSingleObserver = nsnull; + } +} + +static void mozilla_embed_single_finalize (GObject *object) { MozillaEmbedSingle *mes = MOZILLA_EMBED_SINGLE (object); @@ -542,6 +561,20 @@ impl_set_offline_mode (EphyEmbedSingle *shell, io->SetOffline(offline); } +static gboolean +impl_get_offline_mode (EphyEmbedSingle *shell) +{ + nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID); + if (!io) return FALSE; /* no way to check the state, assume offline */ + + PRBool isOffline; + nsresult rv; + rv = io->GetOffline(&isOffline); + NS_ENSURE_SUCCESS (rv, FALSE); + + return isOffline; +} + static void impl_load_proxy_autoconf (EphyEmbedSingle *shell, const char* url) @@ -868,6 +901,7 @@ mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass) parent_class = (GObjectClass *) g_type_class_peek_parent (klass); + object_class->dispose = mozilla_embed_single_dispose; object_class->finalize = mozilla_embed_single_finalize; g_type_class_add_private (object_class, sizeof (MozillaEmbedSinglePrivate)); @@ -879,6 +913,7 @@ ephy_embed_single_iface_init (EphyEmbedSingleIface *iface) iface->clear_cache = impl_clear_cache; iface->clear_auth_cache = impl_clear_auth_cache; iface->set_offline_mode = impl_set_offline_mode; + iface->get_offline_mode = impl_get_offline_mode; iface->load_proxy_autoconf = impl_load_proxy_autoconf; iface->get_font_list = impl_get_font_list; iface->open_window = impl_open_window; diff --git a/src/ephy-window.c b/src/ephy-window.c index 0482af01a..f003a1961 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -33,6 +33,8 @@ #include "window-commands.h" #include "find-dialog.h" #include "print-dialog.h" +#include "ephy-embed-shell.h" +#include "ephy-embed-single.h" #include "ephy-shell.h" #include "eel-gconf-extensions.h" #include "ephy-prefs.h" @@ -243,6 +245,11 @@ static guint ephy_menu_n_entries = G_N_ELEMENTS (ephy_menu_entries); static GtkToggleActionEntry ephy_menu_toggle_entries [] = { + /* File Menu */ + { "FileWorkOffline", NULL, N_("_Work Off-Line"), NULL, + N_("Toggle network status"), + G_CALLBACK (window_cmd_file_work_offline), FALSE }, + /* View Menu */ { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T", N_("Show or hide toolbar"), @@ -1368,6 +1375,22 @@ sync_tab_zoom (EphyTab *tab, GParamSpec *pspec, EphyWindow *window) } static void +network_status_changed (EphyEmbedSingle *single, + gboolean offline, + EphyWindow *window) +{ + GtkAction *action; + + action = gtk_action_group_get_action (window->priv->action_group, + "FileWorkOffline"); + g_signal_handlers_block_by_func + (action, G_CALLBACK (window_cmd_file_work_offline), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), offline); + g_signal_handlers_unblock_by_func + (action, G_CALLBACK (window_cmd_file_work_offline), window); +} + +static void popup_menu_at_coords (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) { @@ -1935,6 +1958,7 @@ static void ephy_window_init (EphyWindow *window) { EphyExtension *manager; + EphyEmbedSingle *single; LOG ("EphyWindow initialising %p", window) @@ -2057,6 +2081,14 @@ ephy_window_init (EphyWindow *window) (CONF_BROWSE_WITH_CARET, (GConfClientNotifyFunc)browse_with_caret_notifier, window); + /* network status */ + single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); + network_status_changed (single, + ephy_embed_single_get_offline_mode (single), + window); + g_signal_connect (single, "network-status", + G_CALLBACK (network_status_changed), window); + /* ensure the UI is updated */ gtk_ui_manager_ensure_update (GTK_UI_MANAGER (window->ui_merge)); @@ -2067,6 +2099,11 @@ static void ephy_window_finalize (GObject *object) { EphyWindow *window = EPHY_WINDOW (object); + GObject *single; + + single = ephy_embed_shell_get_embed_single (embed_shell); + g_signal_handlers_disconnect_by_func + (single, G_CALLBACK (network_status_changed), window); eel_gconf_notification_remove (window->priv->disable_arbitrary_url_notifier_id); eel_gconf_notification_remove (window->priv->disable_bookmark_editing_notifier_id); diff --git a/src/window-commands.c b/src/window-commands.c index 4139b6932..38724702f 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -22,6 +22,8 @@ #include "config.h" #endif +#include "ephy-embed-shell.h" +#include "ephy-embed-single.h" #include "ephy-shell.h" #include "ephy-embed-factory.h" #include "ephy-embed-persist.h" @@ -430,6 +432,19 @@ window_cmd_file_save_as (GtkAction *action, g_object_unref (G_OBJECT(persist)); } + +void +window_cmd_file_work_offline (GtkAction *action, + EphyWindow *window) +{ + EphyEmbedSingle *single; + gboolean offline; + + single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); + offline = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + ephy_embed_single_set_offline_mode (single, offline); +} + void window_cmd_file_close_window (GtkAction *action, EphyWindow *window) diff --git a/src/window-commands.h b/src/window-commands.h index 59238d257..6284108c8 100644 --- a/src/window-commands.h +++ b/src/window-commands.h @@ -85,6 +85,9 @@ void window_cmd_file_print (GtkAction *action, void window_cmd_file_send_to (GtkAction *action, EphyWindow *window); +void window_cmd_file_work_offline (GtkAction *action, + EphyWindow *window); + void window_cmd_file_close_window (GtkAction *action, EphyWindow *window); |