From 5c43eaf3ddb344cc14f7a30dd73330f027794620 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 20 Mar 2010 00:00:28 -0400 Subject: Make EShell extensible. --- shell/e-shell.c | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) (limited to 'shell') diff --git a/shell/e-shell.c b/shell/e-shell.c index 00c1e4a7a7..8bbcde784d 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -24,9 +24,10 @@ #include #include +#include "e-util/e-module.h" +#include "e-util/e-extensible.h" #include "e-util/e-util-private.h" #include "e-util/e-util.h" -#include "e-util/e-module.h" #include "smclient/eggsmclient.h" #include "widgets/misc/e-preferences-window.h" @@ -94,7 +95,6 @@ static GDebugKey debug_keys[] = { { "settings", DEBUG_KEY_SETTINGS } }; -static gpointer parent_class; static gpointer default_shell; static guint signals[LAST_SIGNAL]; @@ -102,6 +102,10 @@ static guint signals[LAST_SIGNAL]; gboolean e_shell_dbus_initialize (EShell *shell); #endif +G_DEFINE_TYPE_WITH_CODE ( + EShell, e_shell, UNIQUE_TYPE_APP, + G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL)) + static void shell_parse_debug_string (EShell *shell) { @@ -606,7 +610,7 @@ shell_dispose (GObject *object) } /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); + G_OBJECT_CLASS (e_shell_parent_class)->dispose (object); } static void @@ -627,7 +631,7 @@ shell_finalize (GObject *object) g_free (priv->module_directory); /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (e_shell_parent_class)->finalize (object); } static void @@ -656,6 +660,8 @@ shell_constructed (GObject *object) e_type_traverse ( E_TYPE_SHELL_BACKEND, (ETypeFunc) shell_add_backend, object); + + e_extensible_load_extensions (E_EXTENSIBLE (object)); } static UniqueResponse @@ -740,7 +746,7 @@ shell_message_received (UniqueApp *app, } /* Chain up to parent's message_received() method. */ - return UNIQUE_APP_CLASS (parent_class)-> + return UNIQUE_APP_CLASS (e_shell_parent_class)-> message_received (app, command, data, time_); } @@ -752,12 +758,11 @@ shell_window_destroyed (EShell *shell) } static void -shell_class_init (EShellClass *class) +e_shell_class_init (EShellClass *class) { GObjectClass *object_class; UniqueAppClass *unique_app_class; - parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EShellPrivate)); object_class = G_OBJECT_CLASS (class); @@ -1061,7 +1066,7 @@ shell_class_init (EShellClass *class) } static void -shell_init (EShell *shell) +e_shell_init (EShell *shell) { GHashTable *backends_by_name; GHashTable *backends_by_scheme; @@ -1150,32 +1155,6 @@ shell_init (EShell *shell) G_CALLBACK (shell_sm_quit_cb), shell); } -GType -e_shell_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - const GTypeInfo type_info = { - sizeof (EShellClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) shell_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EShell), - 0, /* n_preallocs */ - (GInstanceInitFunc) shell_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - UNIQUE_TYPE_APP, "EShell", &type_info, 0); - } - - return type; -} - /** * e_shell_get_default: * -- cgit From cd7fadfcdbbf983dbee379d55bd8a6e44351e8fa Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 20 Mar 2010 11:38:33 -0400 Subject: Convert NetworkManager integration to an EShell extension. This demonstrates how to extend EShell without having to modify and recompile e-shell.c. If NetworkManager integration is enabled, the extension is loaded automatically when the EShell is created. The same pattern can be applied to integrate other network monitoring software like ConnMan or Microsoft's Wireless Zero Configuration. --- shell/Makefile.am | 12 ---- shell/e-shell-nm.c | 177 ----------------------------------------------------- shell/e-shell.c | 8 --- 3 files changed, 197 deletions(-) delete mode 100644 shell/e-shell-nm.c (limited to 'shell') diff --git a/shell/Makefile.am b/shell/Makefile.am index 8afc886d46..0a93912680 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -2,13 +2,6 @@ if ENABLE_TEST_COMPONENT SUBDIRS = . test endif -if NM_SUPPORT -NM_CPPFLAGS = \ - $(DBUS_GLIB_CFLAGS) \ - $(NM_CFLAGS) -NM_SUPPORT_FILES = e-shell-nm.c -endif - # Executable bin_PROGRAMS = evolution @@ -61,7 +54,6 @@ libeshell_la_CPPFLAGS = \ $(SHELL_CFLAGS) libeshell_la_SOURCES = \ - $(NM_SUPPORT_FILES) \ $(eshellinclude_HEADERS) \ e-shell.c \ e-shell-backend.c \ @@ -92,10 +84,6 @@ libeshell_la_LIBADD = \ $(GNOME_PLATFORM_LIBS) \ $(SHELL_LIBS) -if NM_SUPPORT -libeshell_la_LIBADD += $(DBUS_GLIB_LIBS) -endif - # Evolution executable if HAVE_WINDRES diff --git a/shell/e-shell-nm.c b/shell/e-shell-nm.c deleted file mode 100644 index 7f17d9716f..0000000000 --- a/shell/e-shell-nm.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Shreyas Srinivasan - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#define DBUS_API_SUBJECT_TO_CHANGE 1 - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -static DBusConnection *dbus_connection; - -/* Forward Declaration */ -gboolean e_shell_dbus_initialize (EShell *shell); - -static gboolean -reinit_dbus (EShell *shell) -{ - return !e_shell_dbus_initialize (shell); -} - -static DBusHandlerResult -e_shell_network_monitor (DBusConnection *connection G_GNUC_UNUSED, - DBusMessage *message, - gpointer user_data) -{ - DBusError error = DBUS_ERROR_INIT; - EShell *shell = user_data; - const gchar *path; - guint32 state; - - path = dbus_message_get_path (message); - - if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") && - path != NULL && strcmp (path, DBUS_PATH_LOCAL) == 0) { - dbus_connection_unref (dbus_connection); - dbus_connection = NULL; - - g_timeout_add_seconds (3, (GSourceFunc) reinit_dbus, shell); - - return DBUS_HANDLER_RESULT_HANDLED; - } - - if (!dbus_message_is_signal (message, NM_DBUS_INTERFACE, "StateChanged")) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_message_get_args ( - message, &error, - DBUS_TYPE_UINT32, &state, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set (&error)) { - g_warning ("%s", error.message); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - switch (state) { - case NM_STATE_CONNECTED: - e_shell_set_network_available (shell, TRUE); - break; - case NM_STATE_ASLEEP: - case NM_STATE_DISCONNECTED: - e_shell_set_network_available (shell, FALSE); - break; - default: - break; - } - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static void -check_initial_state (EShell *shell) -{ - DBusMessage *message = NULL, *response = NULL; - guint32 state = -1; - DBusError error = DBUS_ERROR_INIT; - - message = dbus_message_new_method_call ( - NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"); - - /* assuming this should be safe to call syncronously */ - response = dbus_connection_send_with_reply_and_block ( - dbus_connection, message, 100, &error); - - if (response) - dbus_message_get_args ( - response, &error, DBUS_TYPE_UINT32, - &state, DBUS_TYPE_INVALID); - else { - g_warning ("%s", error.message); - dbus_error_free (&error); - return; - } - - /* Update the state only in the absence of a network connection, - * otherwise let the old state prevail. */ - if (state == NM_STATE_DISCONNECTED) - e_shell_set_network_available (shell, FALSE); - - dbus_message_unref (message); - dbus_message_unref (response); -} - -gboolean -e_shell_dbus_initialize (EShell *shell) -{ - DBusError error = DBUS_ERROR_INIT; - - g_return_val_if_fail (E_IS_SHELL (shell), FALSE); - - if (dbus_connection != NULL) - return TRUE; - - dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (dbus_connection == NULL) { - g_warning ("%s", error.message); - dbus_error_free (&error); - return FALSE; - } - - dbus_connection_setup_with_g_main (dbus_connection, NULL); - dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); - - if (!dbus_connection_add_filter ( - dbus_connection, e_shell_network_monitor, shell, NULL)) - goto exception; - - check_initial_state (shell); - - dbus_bus_add_match (dbus_connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE "'," - "sender='" NM_DBUS_SERVICE "'," - "path='" NM_DBUS_PATH "'", &error); - if (dbus_error_is_set (&error)) { - g_warning ("%s", error.message); - dbus_error_free (&error); - goto exception; - } - - return TRUE; - -exception: - - dbus_connection_unref (dbus_connection); - dbus_connection = NULL; - - return FALSE; -} diff --git a/shell/e-shell.c b/shell/e-shell.c index 8bbcde784d..459ebdc64a 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -98,10 +98,6 @@ static GDebugKey debug_keys[] = { static gpointer default_shell; static guint signals[LAST_SIGNAL]; -#if defined(NM_SUPPORT) && NM_SUPPORT -gboolean e_shell_dbus_initialize (EShell *shell); -#endif - G_DEFINE_TYPE_WITH_CODE ( EShell, e_shell, UNIQUE_TYPE_APP, G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL)) @@ -1087,10 +1083,6 @@ e_shell_init (EShell *shell) g_object_ref_sink (shell->priv->preferences_window); -#if defined(NM_SUPPORT) && NM_SUPPORT - e_shell_dbus_initialize (shell); -#endif - /* Add our icon directory to the theme's search path * here instead of in main() so Anjal picks it up. */ icon_theme = gtk_icon_theme_get_default (); -- cgit From 3dfd9aa7c4b24f8971382dcc5278714956066ff8 Mon Sep 17 00:00:00 2001 From: Fridrich Strba Date: Sun, 21 Mar 2010 00:12:01 +0100 Subject: [win32] Be consistent in disabling the lockdown options. --- shell/e-shell-utils.c | 2 ++ shell/e-shell-window-private.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'shell') diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c index a584289d20..c7b296931c 100644 --- a/shell/e-shell-utils.c +++ b/shell/e-shell-utils.c @@ -70,6 +70,7 @@ e_shell_configure_web_view (EShell *shell, shell_settings = e_shell_get_shell_settings (shell); +#ifndef G_OS_WIN32 e_binding_new ( shell_settings, "disable-printing", web_view, "disable-printing"); @@ -77,6 +78,7 @@ e_shell_configure_web_view (EShell *shell, e_binding_new ( shell_settings, "disable-save-to-disk", web_view, "disable-save-to-disk"); +#endif } /** diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index c4389ab3bc..faccac8052 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -359,6 +359,7 @@ e_shell_window_private_constructed (EShellWindow *shell_window) shell_window, "notify::active-view", G_CALLBACK (e_shell_window_update_search_menu), NULL); +#ifndef G_OS_WIN32 /* Support lockdown. */ action_group = ACTION_GROUP (LOCKDOWN_PRINTING); @@ -378,6 +379,7 @@ e_shell_window_private_constructed (EShellWindow *shell_window) e_binding_new_with_negation ( shell_settings, "disable-save-to-disk", action_group, "visible"); +#endif /* Bind GObject properties to GObject properties. */ -- cgit