From 873cedbc95777e7b74960a66883c48945fcecd4c Mon Sep 17 00:00:00 2001 From: monsta Date: Tue, 5 Jan 2016 17:38:52 +0300 Subject: rename mate-panel-*.{c|h} -> panel-*.{c|h} for consistency (libmate-panel-applet files are left alone since there are public header files used by all panel applets) --- mate-panel/Makefile.am | 16 +- mate-panel/applet.c | 2 +- .../libmate-panel-applet-private/Makefile.am | 22 +- .../mate-panel-applet-container.c | 798 ------------- .../mate-panel-applet-container.h | 119 -- .../mate-panel-applet-frame-dbus.c | 470 -------- .../mate-panel-applet-frame-dbus.h | 65 -- .../mate-panel-applet-mini.c | 5 - .../mate-panel-applets-manager-dbus.c | 604 ---------- .../mate-panel-applets-manager-dbus.h | 60 - .../panel-applet-container.c | 798 +++++++++++++ .../panel-applet-container.h | 119 ++ .../panel-applet-frame-dbus.c | 469 ++++++++ .../panel-applet-frame-dbus.h | 65 ++ .../panel-applet-mini.c | 5 + .../panel-applets-manager-dbus.c | 603 ++++++++++ .../panel-applets-manager-dbus.h | 60 + mate-panel/mate-panel-applet-frame.c | 1193 -------------------- mate-panel/mate-panel-applet-frame.h | 147 --- mate-panel/mate-panel-applet-info.c | 113 -- mate-panel/mate-panel-applet-info.h | 51 - mate-panel/mate-panel-applets-manager.c | 201 ---- mate-panel/mate-panel-applets-manager.h | 94 -- mate-panel/panel-addto.c | 4 +- mate-panel/panel-applet-frame.c | 1193 ++++++++++++++++++++ mate-panel/panel-applet-frame.h | 147 +++ mate-panel/panel-applet-info.c | 113 ++ mate-panel/panel-applet-info.h | 51 + mate-panel/panel-applets-manager.c | 201 ++++ mate-panel/panel-applets-manager.h | 94 ++ mate-panel/panel-modules.c | 6 +- mate-panel/panel-test-applets.c | 4 +- mate-panel/panel-widget.c | 2 +- mate-panel/panel.c | 2 +- po/POTFILES.in | 2 +- 35 files changed, 3947 insertions(+), 3951 deletions(-) delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applet-container.c delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applet-container.h delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.c delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.h delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applet-mini.c delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.c delete mode 100644 mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.h create mode 100644 mate-panel/libmate-panel-applet-private/panel-applet-container.c create mode 100644 mate-panel/libmate-panel-applet-private/panel-applet-container.h create mode 100644 mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.c create mode 100644 mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.h create mode 100644 mate-panel/libmate-panel-applet-private/panel-applet-mini.c create mode 100644 mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c create mode 100644 mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.h delete mode 100644 mate-panel/mate-panel-applet-frame.c delete mode 100644 mate-panel/mate-panel-applet-frame.h delete mode 100644 mate-panel/mate-panel-applet-info.c delete mode 100644 mate-panel/mate-panel-applet-info.h delete mode 100644 mate-panel/mate-panel-applets-manager.c delete mode 100644 mate-panel/mate-panel-applets-manager.h create mode 100644 mate-panel/panel-applet-frame.c create mode 100644 mate-panel/panel-applet-frame.h create mode 100644 mate-panel/panel-applet-info.c create mode 100644 mate-panel/panel-applet-info.h create mode 100644 mate-panel/panel-applets-manager.c create mode 100644 mate-panel/panel-applets-manager.h diff --git a/mate-panel/Makefile.am b/mate-panel/Makefile.am index 879dc07a..a7ea3944 100644 --- a/mate-panel/Makefile.am +++ b/mate-panel/Makefile.am @@ -40,8 +40,8 @@ panel_sources = \ menu.c \ panel-context-menu.c \ launcher.c \ - mate-panel-applet-frame.c \ - mate-panel-applets-manager.c \ + panel-applet-frame.c \ + panel-applets-manager.c \ panel-shell.c \ panel-background.c \ panel-background-monitor.c \ @@ -67,7 +67,7 @@ panel_sources = \ panel-addto.c \ panel-ditem-editor.c \ panel-modules.c \ - mate-panel-applet-info.c \ + panel-applet-info.c \ panel-reset.c panel_headers = \ @@ -87,8 +87,8 @@ panel_headers = \ menu.h \ panel-context-menu.h \ launcher.h \ - mate-panel-applet-frame.h \ - mate-panel-applets-manager.h \ + panel-applet-frame.h \ + panel-applets-manager.h \ panel-shell.h \ panel-background.h \ panel-background-monitor.h \ @@ -117,7 +117,7 @@ panel_headers = \ panel-ditem-editor.h \ panel-icon-names.h \ panel-modules.h \ - mate-panel-applet-info.h \ + panel-applet-info.h \ panel-reset.h \ panel-schemas.h @@ -158,8 +158,8 @@ mate_desktop_item_edit_LDADD = \ mate_panel_test_applets_SOURCES = \ panel-modules.c \ - mate-panel-applet-info.c \ - mate-panel-applets-manager.c \ + panel-applet-info.c \ + panel-applets-manager.c \ panel-marshal.c \ panel-test-applets.c diff --git a/mate-panel/applet.c b/mate-panel/applet.c index 9fdadf53..c7115379 100644 --- a/mate-panel/applet.c +++ b/mate-panel/applet.c @@ -22,7 +22,7 @@ #include "launcher.h" #include "panel-addto.h" #include "panel-config-global.h" -#include "mate-panel-applet-frame.h" +#include "panel-applet-frame.h" #include "panel-action-button.h" #include "panel-menu-bar.h" #include "panel-separator.h" diff --git a/mate-panel/libmate-panel-applet-private/Makefile.am b/mate-panel/libmate-panel-applet-private/Makefile.am index 9dd4b631..76d122d0 100644 --- a/mate-panel/libmate-panel-applet-private/Makefile.am +++ b/mate-panel/libmate-panel-applet-private/Makefile.am @@ -17,18 +17,18 @@ AM_CPPFLAGS = \ AM_CFLAGS = $(WARN_CFLAGS) libmate_panel_applet_private_la_SOURCES = \ - mate-panel-applets-manager-dbus.c \ - mate-panel-applets-manager-dbus.h \ - mate-panel-applet-container.c \ - mate-panel-applet-container.h \ - mate-panel-applet-frame-dbus.c \ - mate-panel-applet-frame-dbus.h + panel-applets-manager-dbus.c \ + panel-applets-manager-dbus.h \ + panel-applet-container.c \ + panel-applet-container.h \ + panel-applet-frame-dbus.c \ + panel-applet-frame-dbus.h libmate_panel_applet_private_mini_la_SOURCES =\ - mate-panel-applet-mini.c \ - mate-panel-applets-manager-dbus.c \ - mate-panel-applets-manager-dbus.h \ - mate-panel-applet-container.c \ - mate-panel-applet-container.h + panel-applet-mini.c \ + panel-applets-manager-dbus.c \ + panel-applets-manager-dbus.h \ + panel-applet-container.c \ + panel-applet-container.h -include $(top_srcdir)/git.mk diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.c b/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.c deleted file mode 100644 index 3b6a1102..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.c +++ /dev/null @@ -1,798 +0,0 @@ -/* - * mate-panel-applet-container.c: a container for applets. - * - * Copyright (C) 2010 Carlos Garcia Campos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include -#include -#if GTK_CHECK_VERSION (3, 0, 0) -#include -#endif -#include "mate-panel-applet-container.h" -#include "panel-marshal.h" - -struct _MatePanelAppletContainerPrivate { - GDBusProxy *applet_proxy; - - guint name_watcher_id; - gchar *bus_name; - - guint32 xid; - GtkWidget *socket; - - GHashTable *pending_ops; -}; - -enum { - APPLET_BROKEN, - APPLET_MOVE, - APPLET_REMOVE, - APPLET_LOCK, - CHILD_PROPERTY_CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -typedef struct { - const gchar *name; - const gchar *dbus_name; -} AppletPropertyInfo; - -static const AppletPropertyInfo applet_properties [] = { - { "prefs-path", "PrefsPath" }, - { "orient", "Orient" }, - { "size", "Size" }, - { "size-hints", "SizeHints" }, - { "background", "Background" }, - { "flags", "Flags" }, - { "locked", "Locked" }, - { "locked-down", "LockedDown" } -}; - -#define MATE_PANEL_APPLET_CONTAINER_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerPrivate)) - -#define MATE_PANEL_APPLET_BUS_NAME "org.mate.panel.applet.%s" -#define MATE_PANEL_APPLET_FACTORY_INTERFACE "org.mate.panel.applet.AppletFactory" -#define MATE_PANEL_APPLET_FACTORY_OBJECT_PATH "/org/mate/panel/applet/%s" -#define MATE_PANEL_APPLET_INTERFACE "org.mate.panel.applet.Applet" - -static gboolean mate_panel_applet_container_plug_removed (MatePanelAppletContainer *container); - -G_DEFINE_TYPE (MatePanelAppletContainer, mate_panel_applet_container, GTK_TYPE_EVENT_BOX); - -GQuark mate_panel_applet_container_error_quark (void) -{ - return g_quark_from_static_string ("mate-panel-applet-container-error-quark"); -} - -static void mate_panel_applet_container_init(MatePanelAppletContainer* container) -{ - container->priv = MATE_PANEL_APPLET_CONTAINER_GET_PRIVATE (container); - - container->priv->socket = gtk_socket_new (); - g_signal_connect_swapped (container->priv->socket, "plug-removed", G_CALLBACK (mate_panel_applet_container_plug_removed), container); - - container->priv->pending_ops = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - (GDestroyNotify) g_object_unref); - - gtk_container_add (GTK_CONTAINER (container), - container->priv->socket); - gtk_widget_show (container->priv->socket); -} - -static void -mate_panel_applet_container_cancel_pending_operations (MatePanelAppletContainer *container) -{ - GList *keys, *l; - - if (!container->priv->pending_ops) - return; - - keys = g_hash_table_get_keys (container->priv->pending_ops); - for (l = keys; l; l = g_list_next (l)) { - GCancellable *cancellable; - - cancellable = G_CANCELLABLE (g_hash_table_lookup (container->priv->pending_ops, l->data)); - g_cancellable_cancel (cancellable); - } - g_list_free (keys); -} - -static void -mate_panel_applet_container_dispose (GObject *object) -{ - MatePanelAppletContainer *container = MATE_PANEL_APPLET_CONTAINER (object); - - if (container->priv->pending_ops) { - mate_panel_applet_container_cancel_pending_operations (container); - g_hash_table_destroy (container->priv->pending_ops); - container->priv->pending_ops = NULL; - } - - if (container->priv->bus_name) { - g_free (container->priv->bus_name); - container->priv->bus_name = NULL; - } - - if (container->priv->name_watcher_id > 0) { - g_bus_unwatch_name (container->priv->name_watcher_id); - container->priv->name_watcher_id = 0; - } - - if (container->priv->applet_proxy) { - g_object_unref (container->priv->applet_proxy); - container->priv->applet_proxy = NULL; - } - - G_OBJECT_CLASS (mate_panel_applet_container_parent_class)->dispose (object); -} - -static void -mate_panel_applet_container_class_init (MatePanelAppletContainerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (MatePanelAppletContainerPrivate)); - - gobject_class->dispose = mate_panel_applet_container_dispose; - - signals[APPLET_BROKEN] = - g_signal_new ("applet-broken", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_broken), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - signals[APPLET_MOVE] = - g_signal_new ("applet-move", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_move), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - signals[APPLET_REMOVE] = - g_signal_new ("applet-remove", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_remove), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - signals[APPLET_LOCK] = - g_signal_new ("applet-lock", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_lock), - NULL, - NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, - 1, G_TYPE_BOOLEAN); - signals[CHILD_PROPERTY_CHANGED] = - g_signal_new ("child-property-changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | - G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS, - G_STRUCT_OFFSET (MatePanelAppletContainerClass, child_property_changed), - NULL, - NULL, - panel_marshal_VOID__STRING_POINTER, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_POINTER); -} - -static const AppletPropertyInfo * -mate_panel_applet_container_child_property_get_info (const gchar *property_name) -{ - gint i; - - g_assert (property_name != NULL); - - for (i = 0; i < G_N_ELEMENTS (applet_properties); i++) { - if (g_ascii_strcasecmp (applet_properties[i].name, property_name) == 0) - return &applet_properties[i]; - } - - return NULL; -} - -GtkWidget * -mate_panel_applet_container_new (void) -{ - GtkWidget *container; - - container = GTK_WIDGET (g_object_new (PANEL_TYPE_APPLET_CONTAINER, NULL)); - - return container; -} - -static gboolean -mate_panel_applet_container_plug_removed (MatePanelAppletContainer *container) -{ - if (!container->priv->applet_proxy) - return FALSE; - - mate_panel_applet_container_cancel_pending_operations (container); - - if (container->priv->name_watcher_id > 0) { - g_bus_unwatch_name (container->priv->name_watcher_id); - container->priv->name_watcher_id = 0; - } - - g_object_unref (container->priv->applet_proxy); - container->priv->applet_proxy = NULL; - - g_signal_emit (container, signals[APPLET_BROKEN], 0); - - /* Continue destroying, in case of reloading - * a new frame widget is created - */ - return FALSE; -} - -static void -mate_panel_applet_container_child_signal (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - MatePanelAppletContainer *container) -{ - if (g_strcmp0 (signal_name, "Move") == 0) { - g_signal_emit (container, signals[APPLET_MOVE], 0); - } else if (g_strcmp0 (signal_name, "RemoveFromPanel") == 0) { - g_signal_emit (container, signals[APPLET_REMOVE], 0); - } else if (g_strcmp0 (signal_name, "Lock") == 0) { - g_signal_emit (container, signals[APPLET_LOCK], 0, TRUE); - } else if (g_strcmp0 (signal_name, "Unlock") == 0) { - g_signal_emit (container, signals[APPLET_LOCK], 0, FALSE); - } -} - -static void -on_property_changed (GDBusConnection *connection, - const gchar *sender_name, - const gchar *object_path, - const gchar *interface_name, - const gchar *signal_name, - GVariant *parameters, - MatePanelAppletContainer *container) -{ - GVariant *props; - GVariantIter iter; - GVariant *value; - gchar *key; - - g_variant_get (parameters, "(s@a{sv}*)", NULL, &props, NULL); - - g_variant_iter_init (&iter, props); - while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) { - if (g_strcmp0 (key, "Flags") == 0) { - g_signal_emit (container, signals[CHILD_PROPERTY_CHANGED], - g_quark_from_string ("flags"), - "flags", value); - } else if (g_strcmp0 (key, "SizeHints") == 0) { - g_signal_emit (container, signals[CHILD_PROPERTY_CHANGED], - g_quark_from_string ("size-hints"), - "size-hints", value); - } - } - - g_variant_unref (props); -} - -static void -on_proxy_appeared (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - MatePanelAppletContainer *container; - GDBusProxy *proxy; - GError *error = NULL; - - proxy = g_dbus_proxy_new_finish (res, &error); - if (!proxy) { - g_simple_async_result_set_from_error (result, error); - g_error_free (error); - g_simple_async_result_complete (result); - g_object_unref (result); - - return; - } - - container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); - - container->priv->applet_proxy = proxy; - g_signal_connect (container->priv->applet_proxy, "g-signal", - G_CALLBACK (mate_panel_applet_container_child_signal), - container); - g_dbus_connection_signal_subscribe (g_dbus_proxy_get_connection (proxy), - g_dbus_proxy_get_name (proxy), - "org.freedesktop.DBus.Properties", - "PropertiesChanged", - g_dbus_proxy_get_object_path (proxy), - MATE_PANEL_APPLET_INTERFACE, - G_DBUS_SIGNAL_FLAGS_NONE, - (GDBusSignalCallback) on_property_changed, - container, NULL); - - g_simple_async_result_complete (result); - g_object_unref (result); - - if (container->priv->xid > 0) { - gtk_socket_add_id (GTK_SOCKET (container->priv->socket), - container->priv->xid); - } - - /* g_async_result_get_source_object returns new ref */ - g_object_unref (container); -} - -static void -get_applet_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusConnection *connection = G_DBUS_CONNECTION (source_object); - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - MatePanelAppletContainer *container; - GVariant *retvals; - const gchar *applet_path; - GError *error = NULL; - - retvals = g_dbus_connection_call_finish (connection, res, &error); - if (!retvals) { - g_simple_async_result_set_from_error (result, error); - g_error_free (error); - g_simple_async_result_complete (result); - g_object_unref (result); - - return; - } - - container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); - g_variant_get (retvals, "(&ou)", &applet_path, &container->priv->xid); - - g_dbus_proxy_new (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, - container->priv->bus_name, - applet_path, - MATE_PANEL_APPLET_INTERFACE, - NULL, - (GAsyncReadyCallback) on_proxy_appeared, - result); - - g_variant_unref (retvals); - - /* g_async_result_get_source_object returns new ref */ - g_object_unref (container); -} - -typedef struct { - GSimpleAsyncResult *result; - gchar *factory_id; - GVariant *parameters; - GCancellable *cancellable; -} AppletFactoryData; - -static void -applet_factory_data_free (AppletFactoryData *data) -{ - g_free (data->factory_id); - if (data->cancellable) - g_object_unref (data->cancellable); - - g_free (data); -} - -static void -on_factory_appeared (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - AppletFactoryData *data) -{ - MatePanelAppletContainer *container; - gchar *object_path; - - container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (data->result))); - container->priv->bus_name = g_strdup (name_owner); - object_path = g_strdup_printf (MATE_PANEL_APPLET_FACTORY_OBJECT_PATH, data->factory_id); - g_dbus_connection_call (connection, - name_owner, - object_path, - MATE_PANEL_APPLET_FACTORY_INTERFACE, - "GetApplet", - data->parameters, - G_VARIANT_TYPE ("(ou)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - data->cancellable, - get_applet_cb, - data->result); - g_free (object_path); -} - -static void -mate_panel_applet_container_get_applet (MatePanelAppletContainer *container, - GdkScreen *screen, - const gchar *iid, - GVariant *props, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - AppletFactoryData *data; - gint screen_number; - gchar *bus_name; - gchar *factory_id; - gchar *applet_id; - - result = g_simple_async_result_new (G_OBJECT (container), - callback, - user_data, - mate_panel_applet_container_get_applet); - - applet_id = g_strrstr (iid, "::"); - if (!applet_id) { - g_simple_async_result_set_error (result, - MATE_PANEL_APPLET_CONTAINER_ERROR, - MATE_PANEL_APPLET_CONTAINER_INVALID_APPLET, - "Invalid applet iid: %s", iid); - g_simple_async_result_complete (result); - g_object_unref (result); - - return; - } - - factory_id = g_strndup (iid, strlen (iid) - strlen (applet_id)); - applet_id += 2; - - /* we can't use the screen of the container widget since it's not in a - * widget hierarchy yet */ - screen_number = gdk_screen_get_number (screen); - - data = g_new (AppletFactoryData, 1); - data->result = result; - data->factory_id = factory_id; - data->parameters = g_variant_new ("(si*)", applet_id, screen_number, props); - data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - - bus_name = g_strdup_printf (MATE_PANEL_APPLET_BUS_NAME, factory_id); - - container->priv->name_watcher_id = - g_bus_watch_name (G_BUS_TYPE_SESSION, - bus_name, - G_BUS_NAME_WATCHER_FLAGS_AUTO_START, - (GBusNameAppearedCallback) on_factory_appeared, - NULL, - data, - (GDestroyNotify) applet_factory_data_free); - - g_free (bus_name); -} - -void -mate_panel_applet_container_add (MatePanelAppletContainer *container, - GdkScreen *screen, - const gchar *iid, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data, - GVariant *properties) -{ - g_return_if_fail (PANEL_IS_APPLET_CONTAINER (container)); - g_return_if_fail (iid != NULL); - - mate_panel_applet_container_cancel_pending_operations (container); - - mate_panel_applet_container_get_applet (container, screen, iid, properties, - cancellable, callback, user_data); -} - -gboolean -mate_panel_applet_container_add_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_get_applet); - - return !g_simple_async_result_propagate_error (simple, error); -} - -/* Child Properties */ -static void -set_applet_property_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusConnection *connection = G_DBUS_CONNECTION (source_object); - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - MatePanelAppletContainer *container; - GVariant *retvals; - GError *error = NULL; - - retvals = g_dbus_connection_call_finish (connection, res, &error); - if (!retvals) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Error setting property: %s\n", error->message); - g_simple_async_result_set_from_error (result, error); - g_error_free (error); - } else { - g_variant_unref (retvals); - } - - container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); - g_hash_table_remove (container->priv->pending_ops, result); - g_simple_async_result_complete (result); - g_object_unref (result); - - /* g_async_result_get_source_object returns new ref */ - g_object_unref (container); -} - -void -mate_panel_applet_container_child_set (MatePanelAppletContainer *container, - const gchar *property_name, - const GVariant *value, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GDBusProxy *proxy = container->priv->applet_proxy; - const AppletPropertyInfo *info; - GSimpleAsyncResult *result; - - if (!proxy) - return; - - info = mate_panel_applet_container_child_property_get_info (property_name); - if (!info) { - g_simple_async_report_error_in_idle (G_OBJECT (container), - callback, user_data, - MATE_PANEL_APPLET_CONTAINER_ERROR, - MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY, - "%s: Applet has no child property named `%s'", - G_STRLOC, property_name); - return; - } - - result = g_simple_async_result_new (G_OBJECT (container), - callback, - user_data, - mate_panel_applet_container_child_set); - - if (cancellable) - g_object_ref (cancellable); - else - cancellable = g_cancellable_new (); - g_hash_table_insert (container->priv->pending_ops, result, cancellable); - - g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), - g_dbus_proxy_get_name (proxy), - g_dbus_proxy_get_object_path (proxy), - "org.freedesktop.DBus.Properties", - "Set", - g_variant_new ("(ssv)", - g_dbus_proxy_get_interface_name (proxy), - info->dbus_name, - value), - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, cancellable, - set_applet_property_cb, - result); -} - -gboolean -mate_panel_applet_container_child_set_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_set); - - return !g_simple_async_result_propagate_error (simple, error); -} - -static void -get_applet_property_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusConnection *connection = G_DBUS_CONNECTION (source_object); - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - MatePanelAppletContainer *container; - GVariant *retvals; - GError *error = NULL; - - retvals = g_dbus_connection_call_finish (connection, res, &error); - if (!retvals) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Error getting property: %s\n", error->message); - g_simple_async_result_set_from_error (result, error); - g_error_free (error); - } else { - GVariant *value, *item; - - item = g_variant_get_child_value (retvals, 0); - value = g_variant_get_variant (item); - g_variant_unref (item); - g_simple_async_result_set_op_res_gpointer (result, value, - (GDestroyNotify) g_variant_unref); - g_variant_unref (retvals); - } - - container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); - g_hash_table_remove (container->priv->pending_ops, result); - g_simple_async_result_complete (result); - g_object_unref (result); - - /* g_async_result_get_source_object returns new ref */ - g_object_unref (container); -} - -void -mate_panel_applet_container_child_get (MatePanelAppletContainer *container, - const gchar *property_name, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GDBusProxy *proxy = container->priv->applet_proxy; - const AppletPropertyInfo *info; - GSimpleAsyncResult *result; - - if (!proxy) - return; - - info = mate_panel_applet_container_child_property_get_info (property_name); - if (!info) { - g_simple_async_report_error_in_idle (G_OBJECT (container), - callback, user_data, - MATE_PANEL_APPLET_CONTAINER_ERROR, - MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY, - "%s: Applet has no child property named `%s'", - G_STRLOC, property_name); - return; - } - - result = g_simple_async_result_new (G_OBJECT (container), - callback, - user_data, - mate_panel_applet_container_child_get); - if (cancellable) - g_object_ref (cancellable); - else - cancellable = g_cancellable_new (); - g_hash_table_insert (container->priv->pending_ops, result, cancellable); - - g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), - g_dbus_proxy_get_name (proxy), - g_dbus_proxy_get_object_path (proxy), - "org.freedesktop.DBus.Properties", - "Get", - g_variant_new ("(ss)", - g_dbus_proxy_get_interface_name (proxy), - info->dbus_name), - G_VARIANT_TYPE ("(v)"), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, cancellable, - get_applet_property_cb, - result); -} - -GVariant * -mate_panel_applet_container_child_get_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_get); - - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - - return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -static void -child_popup_menu_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusConnection *connection = G_DBUS_CONNECTION (source_object); - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - GVariant *retvals; - GError *error = NULL; - - retvals = g_dbus_connection_call_finish (connection, res, &error); - if (!retvals) { - g_simple_async_result_set_from_error (result, error); - g_error_free (error); - } else { - g_variant_unref (retvals); - } - - g_simple_async_result_complete (result); - g_object_unref (result); -} - -void -mate_panel_applet_container_child_popup_menu (MatePanelAppletContainer *container, - guint button, - guint32 timestamp, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *result; - GDBusProxy *proxy = container->priv->applet_proxy; - - if (!proxy) - return; - - result = g_simple_async_result_new (G_OBJECT (container), - callback, - user_data, - mate_panel_applet_container_child_popup_menu); - - g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), - g_dbus_proxy_get_name (proxy), - g_dbus_proxy_get_object_path (proxy), - MATE_PANEL_APPLET_INTERFACE, - "PopupMenu", - g_variant_new ("(uu)", button, timestamp), - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, cancellable, - child_popup_menu_cb, - result); -} - -gboolean -mate_panel_applet_container_child_popup_menu_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_popup_menu); - - return !g_simple_async_result_propagate_error (simple, error); -} diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.h b/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.h deleted file mode 100644 index 8f01db80..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applet-container.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * mate-panel-applet-container.c: a container for applets. - * - * Copyright (C) 2010 Carlos Garcia Campos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef __MATE_PANEL_APPLET_CONTAINER_H__ -#define __MATE_PANEL_APPLET_CONTAINER_H__ - -#include -#include -#include "panel.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_APPLET_CONTAINER (mate_panel_applet_container_get_type ()) -#define MATE_PANEL_APPLET_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainer)) -#define MATE_PANEL_APPLET_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerClass)) -#define PANEL_IS_APPLET_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLET_CONTAINER)) -#define PANEL_IS_APPLET_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLET_CONTAINER)) -#define MATE_PANEL_APPLET_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerClass)) - -#define MATE_PANEL_APPLET_CONTAINER_ERROR (mate_panel_applet_container_error_quark()) - -typedef enum { - MATE_PANEL_APPLET_CONTAINER_INVALID_APPLET, - MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY -} MatePanelAppletContainerError; - -typedef struct _MatePanelAppletContainer MatePanelAppletContainer; -typedef struct _MatePanelAppletContainerClass MatePanelAppletContainerClass; -typedef struct _MatePanelAppletContainerPrivate MatePanelAppletContainerPrivate; - -struct _MatePanelAppletContainer { - GtkEventBox parent; - - MatePanelAppletContainerPrivate *priv; -}; - -struct _MatePanelAppletContainerClass { - GtkEventBoxClass parent_class; - - /* Signals */ - void (*applet_broken) (MatePanelAppletContainer *container); - void (*applet_move) (MatePanelAppletContainer *container); - void (*applet_remove) (MatePanelAppletContainer *container); - void (*applet_lock) (MatePanelAppletContainer *container, - gboolean locked); - void (*child_property_changed) (MatePanelAppletContainer *container, - const gchar *property_name, - GVariant *value); -}; - -GType mate_panel_applet_container_get_type (void) G_GNUC_CONST; -GQuark mate_panel_applet_container_error_quark (void) G_GNUC_CONST; -GtkWidget *mate_panel_applet_container_new (void); - - -void mate_panel_applet_container_add (MatePanelAppletContainer *container, - GdkScreen *screen, - const gchar *iid, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data, - GVariant *properties); -gboolean mate_panel_applet_container_add_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error); -void mate_panel_applet_container_child_popup_menu (MatePanelAppletContainer *container, - guint button, - guint32 timestamp, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean mate_panel_applet_container_child_popup_menu_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error); - -void mate_panel_applet_container_child_set (MatePanelAppletContainer *container, - const gchar *property_name, - const GVariant *value, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean mate_panel_applet_container_child_set_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error); -void mate_panel_applet_container_child_get (MatePanelAppletContainer *container, - const gchar *property_name, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GVariant *mate_panel_applet_container_child_get_finish (MatePanelAppletContainer *container, - GAsyncResult *result, - GError **error); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLET_CONTAINER_H__ */ diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.c b/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.c deleted file mode 100644 index ca70915e..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.c +++ /dev/null @@ -1,470 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * mate-panel-applet-frame-dbus.c: panel side container for applets - * - * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * Authors: - * Mark McLoughlin - */ - -#include - -#include - -#include -#include - -#include "mate-panel-applet-container.h" - -#include "mate-panel-applet-frame-dbus.h" - -G_DEFINE_TYPE (MatePanelAppletFrameDBus, - mate_panel_applet_frame_dbus, - PANEL_TYPE_APPLET_FRAME) - -struct _MatePanelAppletFrameDBusPrivate -{ - MatePanelAppletContainer *container; - GCancellable *bg_cancellable; -}; - -/* Keep in sync with mate-panel-applet.h. Uggh. */ -typedef enum { - APPLET_FLAGS_NONE = 0, - APPLET_EXPAND_MAJOR = 1 << 0, - APPLET_EXPAND_MINOR = 1 << 1, - APPLET_HAS_HANDLE = 1 << 2 -} MatePanelAppletFlags; - - -static guint -get_mate_panel_applet_orient (PanelOrientation orientation) -{ - /* For some reason libmate-panel-applet and panel use a different logic for - * orientation, so we need to convert it. We should fix this. */ - switch (orientation) { - case PANEL_ORIENTATION_TOP: - return 1; - case PANEL_ORIENTATION_BOTTOM: - return 0; - case PANEL_ORIENTATION_LEFT: - return 3; - case PANEL_ORIENTATION_RIGHT: - return 2; - default: - g_assert_not_reached (); - break; - } -} - -static void -mate_panel_applet_frame_dbus_update_flags (MatePanelAppletFrame *frame, - GVariant *value) -{ - guint32 flags; - gboolean major; - gboolean minor; - gboolean has_handle; - - flags = g_variant_get_uint32 (value); - - major = (flags & APPLET_EXPAND_MAJOR) != 0; - minor = (flags & APPLET_EXPAND_MINOR) != 0; - has_handle = (flags & APPLET_HAS_HANDLE) != 0; - - _mate_panel_applet_frame_update_flags (frame, major, minor, has_handle); -} - - -static void -mate_panel_applet_frame_dbus_get_flags_cb (MatePanelAppletContainer *container, - GAsyncResult *res, - MatePanelAppletFrame *frame) -{ - GVariant *value; - GError *error = NULL; - - value = mate_panel_applet_container_child_get_finish (container, res, &error); - if (!value) { - g_warning ("%s\n", error->message); - g_error_free (error); - return; - } - - mate_panel_applet_frame_dbus_update_flags (frame, value); - g_variant_unref (value); -} - -static void -mate_panel_applet_frame_dbus_get_size_hints_cb (MatePanelAppletContainer *container, - GAsyncResult *res, - MatePanelAppletFrame *frame) -{ - GVariant *value; - const gint *sz; - gint *size_hints = NULL; - gsize n_elements; - GError *error = NULL; - - value = mate_panel_applet_container_child_get_finish (container, res, &error); - if (!value) { - g_warning ("%s\n", error->message); - g_error_free (error); - return; - } - - sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); - if (n_elements > 0) { - size_hints = g_new (gint32, n_elements); - memcpy (size_hints, sz, n_elements * sizeof (gint32)); - } - - _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); - g_variant_unref (value); -} - -static void -mate_panel_applet_frame_dbus_init_properties (MatePanelAppletFrame *frame) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - - mate_panel_applet_container_child_get (dbus_frame->priv->container, "flags", NULL, - (GAsyncReadyCallback) mate_panel_applet_frame_dbus_get_flags_cb, - frame); - mate_panel_applet_container_child_get (dbus_frame->priv->container, "size-hints", NULL, - (GAsyncReadyCallback) mate_panel_applet_frame_dbus_get_size_hints_cb, - frame); -} - -static void -mate_panel_applet_frame_dbus_sync_menu_state (MatePanelAppletFrame *frame, - gboolean movable, - gboolean removable, - gboolean lockable, - gboolean locked, - gboolean locked_down) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - - mate_panel_applet_container_child_set (dbus_frame->priv->container, - "locked", g_variant_new_boolean (lockable && locked), - NULL, NULL, NULL); - mate_panel_applet_container_child_set (dbus_frame->priv->container, - "locked-down", g_variant_new_boolean (locked_down), - NULL, NULL, NULL); -} - -static void -mate_panel_applet_frame_dbus_popup_menu (MatePanelAppletFrame *frame, - guint button, - guint32 timestamp) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - - mate_panel_applet_container_child_popup_menu (dbus_frame->priv->container, - button, timestamp, - NULL, NULL, NULL); -} - -static void -change_orientation_cb (MatePanelAppletContainer *container, - GAsyncResult *res, - MatePanelAppletFrame *frame) -{ - GError *error = NULL; - - if (!mate_panel_applet_container_child_set_finish (container, res, &error)) { - g_warning ("%s\n", error->message); - g_error_free (error); - - return; - } - - gtk_widget_queue_resize (GTK_WIDGET (frame)); -} - -static void -mate_panel_applet_frame_dbus_change_orientation (MatePanelAppletFrame *frame, - PanelOrientation orientation) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - - mate_panel_applet_container_child_set (dbus_frame->priv->container, - "orient", - g_variant_new_uint32 (get_mate_panel_applet_orient (orientation)), - NULL, - (GAsyncReadyCallback)change_orientation_cb, - frame); -} - -static void -mate_panel_applet_frame_dbus_change_size (MatePanelAppletFrame *frame, - guint size) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - - mate_panel_applet_container_child_set (dbus_frame->priv->container, - "size", g_variant_new_uint32 (size), - NULL, NULL, NULL); -} - -static void -container_child_background_set (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - MatePanelAppletContainer *container = MATE_PANEL_APPLET_CONTAINER (source_object); - MatePanelAppletFrameDBus *frame = MATE_PANEL_APPLET_FRAME_DBUS (user_data); - - mate_panel_applet_container_child_set_finish (container, res, NULL); - - if (frame->priv->bg_cancellable) - g_clear_object (&frame->priv->bg_cancellable); - - frame->priv->bg_cancellable = NULL; -} - -static void -mate_panel_applet_frame_dbus_change_background (MatePanelAppletFrame *frame, - PanelBackgroundType type) -{ - MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); - char *bg_str; - - bg_str = _mate_panel_applet_frame_get_background_string ( - frame, PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))), type); - - if (bg_str != NULL) { - if (dbus_frame->priv->bg_cancellable) - g_cancellable_cancel (dbus_frame->priv->bg_cancellable); - dbus_frame->priv->bg_cancellable = g_cancellable_new (); - - mate_panel_applet_container_child_set (dbus_frame->priv->container, - "background", - g_variant_new_string (bg_str), - dbus_frame->priv->bg_cancellable, - container_child_background_set, - dbus_frame); - g_free (bg_str); - } -} - -static void -mate_panel_applet_frame_dbus_flags_changed (MatePanelAppletContainer *container, - const gchar *prop_name, - GVariant *value, - MatePanelAppletFrame *frame) -{ - mate_panel_applet_frame_dbus_update_flags (frame, value); -} - -static void -mate_panel_applet_frame_dbus_size_hints_changed (MatePanelAppletContainer *container, - const gchar *prop_name, - GVariant *value, - MatePanelAppletFrame *frame) -{ - const gint *sz; - gint *size_hints = NULL; - gsize n_elements; - - sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); - if (n_elements > 0) { - size_hints = g_new (gint32, n_elements); - memcpy (size_hints, sz, n_elements * sizeof (gint32)); - } - - _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); -} - -static void -mate_panel_applet_frame_dbus_applet_broken (MatePanelAppletContainer *container, - MatePanelAppletFrame *frame) -{ - _mate_panel_applet_frame_applet_broken (frame); -} - -static void -mate_panel_applet_frame_dbus_applet_remove (MatePanelAppletContainer *container, - MatePanelAppletFrame *frame) -{ - _mate_panel_applet_frame_applet_remove (frame); -} - -static void -mate_panel_applet_frame_dbus_applet_move (MatePanelAppletContainer *container, - MatePanelAppletFrame *frame) -{ - _mate_panel_applet_frame_applet_move (frame); -} - -static void -mate_panel_applet_frame_dbus_applet_lock (MatePanelAppletContainer *container, - gboolean locked, - MatePanelAppletFrame *frame) -{ - _mate_panel_applet_frame_applet_lock (frame, locked); -} - -static void -mate_panel_applet_frame_dbus_finalize (GObject *object) -{ - MatePanelAppletFrameDBus *frame = MATE_PANEL_APPLET_FRAME_DBUS (object); - - if (frame->priv->bg_cancellable) - g_cancellable_cancel (frame->priv->bg_cancellable); - - G_OBJECT_CLASS (mate_panel_applet_frame_dbus_parent_class)->finalize (object); -} - -static void -mate_panel_applet_frame_dbus_init (MatePanelAppletFrameDBus *frame) -{ - GtkWidget *container; - - frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame, - PANEL_TYPE_APPLET_FRAME_DBUS, - MatePanelAppletFrameDBusPrivate); - - container = mate_panel_applet_container_new (); - gtk_widget_show (container); - gtk_container_add (GTK_CONTAINER (frame), container); - frame->priv->container = MATE_PANEL_APPLET_CONTAINER (container); - - g_signal_connect (container, "child-property-changed::flags", - G_CALLBACK (mate_panel_applet_frame_dbus_flags_changed), - frame); - g_signal_connect (container, "child-property-changed::size-hints", - G_CALLBACK (mate_panel_applet_frame_dbus_size_hints_changed), - frame); - g_signal_connect (container, "applet-broken", - G_CALLBACK (mate_panel_applet_frame_dbus_applet_broken), - frame); - g_signal_connect (container, "applet-remove", - G_CALLBACK (mate_panel_applet_frame_dbus_applet_remove), - frame); - g_signal_connect (container, "applet-move", - G_CALLBACK (mate_panel_applet_frame_dbus_applet_move), - frame); - g_signal_connect (container, "applet-lock", - G_CALLBACK (mate_panel_applet_frame_dbus_applet_lock), - frame); -} - -static void -mate_panel_applet_frame_dbus_class_init (MatePanelAppletFrameDBusClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - MatePanelAppletFrameClass *frame_class = MATE_PANEL_APPLET_FRAME_CLASS (class); - - gobject_class->finalize = mate_panel_applet_frame_dbus_finalize; - - frame_class->init_properties = mate_panel_applet_frame_dbus_init_properties; - frame_class->sync_menu_state = mate_panel_applet_frame_dbus_sync_menu_state; - frame_class->popup_menu = mate_panel_applet_frame_dbus_popup_menu; - frame_class->change_orientation = mate_panel_applet_frame_dbus_change_orientation; - frame_class->change_size = mate_panel_applet_frame_dbus_change_size; - frame_class->change_background = mate_panel_applet_frame_dbus_change_background; - - g_type_class_add_private (class, sizeof (MatePanelAppletFrameDBusPrivate)); -} - -static void -mate_panel_applet_frame_dbus_activated (MatePanelAppletContainer *container, - GAsyncResult *res, - MatePanelAppletFrame *frame) -{ - MatePanelAppletFrameActivating *frame_act; - GError *error = NULL; - - if (!mate_panel_applet_container_add_finish (container, res, &error)) - g_assert (error != NULL); - - frame_act = g_object_get_data (G_OBJECT (frame), "mate-panel-applet-frame-activating"); - g_object_set_data (G_OBJECT (frame), "mate-panel-applet-frame-activating", NULL); - - _mate_panel_applet_frame_activated (frame, frame_act, error); -} - -gboolean -mate_panel_applet_frame_dbus_load (const gchar *iid, - MatePanelAppletFrameActivating *frame_act) -{ - MatePanelAppletFrameDBus *dbus_frame; - MatePanelAppletFrame *frame; - GVariantBuilder builder; - GdkScreen *screen; - gchar *conf_path; - gchar *background; - guint orient; - - g_return_val_if_fail (iid != NULL, FALSE); - g_return_val_if_fail (frame_act != NULL, FALSE); - - if (!mate_panel_applets_manager_factory_activate (iid)) - return FALSE; - - dbus_frame = g_object_new (PANEL_TYPE_APPLET_FRAME_DBUS, NULL); - frame = MATE_PANEL_APPLET_FRAME (dbus_frame); - _mate_panel_applet_frame_set_iid (frame, iid); - - screen = panel_applet_frame_activating_get_screen (frame_act); - orient = get_mate_panel_applet_orient (mate_panel_applet_frame_activating_get_orientation (frame_act)); - conf_path = mate_panel_applet_frame_activating_get_conf_path (frame_act); - /* we can't really get a background string at this point since we don't - * know the position of the applet */ - background = NULL; - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - g_variant_builder_add (&builder, "{sv}", - "prefs-path", - g_variant_new_string (conf_path)); - g_variant_builder_add (&builder, "{sv}", - "orient", - g_variant_new_uint32 (orient)); - g_variant_builder_add (&builder, "{sv}", - "size", - g_variant_new_uint32 (mate_panel_applet_frame_activating_get_size (frame_act))); - g_variant_builder_add (&builder, "{sv}", - "locked", - g_variant_new_boolean (mate_panel_applet_frame_activating_get_locked (frame_act))); - g_variant_builder_add (&builder, "{sv}", - "locked-down", - g_variant_new_boolean (mate_panel_applet_frame_activating_get_locked_down (frame_act))); - if (background) { - g_variant_builder_add (&builder, "{sv}", - "background", - g_variant_new_string (background)); - } - - g_object_set_data (G_OBJECT (frame), "mate-panel-applet-frame-activating", frame_act); - - mate_panel_applet_container_add (dbus_frame->priv->container, - screen, iid, NULL, - (GAsyncReadyCallback) mate_panel_applet_frame_dbus_activated, - frame, - g_variant_builder_end (&builder)); - - g_free (conf_path); - g_free (background); - - return TRUE; -} diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.h b/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.h deleted file mode 100644 index 8b9e62a1..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applet-frame-dbus.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * mate-panel-applet-frame-dbus.h: panel side container for applets - * - * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * Authors: - * Mark McLoughlin - */ - -#ifndef __MATE_PANEL_APPLET_FRAME_DBUS_H__ -#define __MATE_PANEL_APPLET_FRAME_DBUS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_APPLET_FRAME_DBUS (mate_panel_applet_frame_dbus_get_type ()) -#define MATE_PANEL_APPLET_FRAME_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBus)) -#define MATE_PANEL_APPLET_FRAME_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBusClass)) -#define PANEL_IS_APPLET_FRAME_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_APPLET_FRAME_DBUS)) -#define PANEL_IS_APPLET_FRAME_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_APPLET_FRAME_DBUS)) -#define MATE_PANEL_APPLET_FRAME_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBusClass)) - -typedef struct _MatePanelAppletFrameDBus MatePanelAppletFrameDBus; -typedef struct _MatePanelAppletFrameDBusClass MatePanelAppletFrameDBusClass; -typedef struct _MatePanelAppletFrameDBusPrivate MatePanelAppletFrameDBusPrivate; - -struct _MatePanelAppletFrameDBusClass { - MatePanelAppletFrameClass parent_class; -}; - -struct _MatePanelAppletFrameDBus{ - MatePanelAppletFrame parent; - - MatePanelAppletFrameDBusPrivate *priv; -}; - -GType mate_panel_applet_frame_dbus_get_type (void) G_GNUC_CONST; - -gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, - MatePanelAppletFrameActivating *frame_act); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLET_FRAME_DBUS_H__ */ diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applet-mini.c b/mate-panel/libmate-panel-applet-private/mate-panel-applet-mini.c deleted file mode 100644 index 13112376..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applet-mini.c +++ /dev/null @@ -1,5 +0,0 @@ -/* Symbols needed for libmate-panel-applet-private-mini, which is used by the test - * program */ -#include -gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, gpointer frame_act); -gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, gpointer frame_act) { return FALSE; } diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.c b/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.c deleted file mode 100644 index fc2f817b..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.c +++ /dev/null @@ -1,604 +0,0 @@ -/* - * mate-panel-applets-manager-dbus.c - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include - -#include -#include -#include - -#include - -#include "mate-panel-applet-frame-dbus.h" - -#include "mate-panel-applets-manager-dbus.h" - -G_DEFINE_TYPE_WITH_CODE (MatePanelAppletsManagerDBus, - mate_panel_applets_manager_dbus, - PANEL_TYPE_APPLETS_MANAGER, - g_io_extension_point_implement (MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME, - g_define_type_id, - "dbus", - 10)) - -struct _MatePanelAppletsManagerDBusPrivate -{ - GHashTable *applet_factories; - GList *monitors; -}; - -typedef gint (* ActivateAppletFunc) (void); - -typedef struct _MatePanelAppletFactoryInfo { - gchar *id; - gchar *location; - gboolean in_process; - GModule *module; - ActivateAppletFunc activate_applet; - guint n_applets; - - gchar *srcdir; - - GList *applet_list; - gboolean has_old_ids; -} MatePanelAppletFactoryInfo; - -#define MATE_PANEL_APPLET_FACTORY_GROUP "Applet Factory" -#define MATE_PANEL_APPLETS_EXTENSION ".mate-panel-applet" - -static void -mate_panel_applet_factory_info_free (MatePanelAppletFactoryInfo *info) -{ - if (!info) - return; - - g_free (info->id); - g_free (info->location); - g_list_foreach (info->applet_list, - (GFunc) mate_panel_applet_info_free, - NULL); - g_list_free (info->applet_list); - info->applet_list = NULL; - g_free (info->srcdir); - - g_slice_free (MatePanelAppletFactoryInfo, info); -} - -static MatePanelAppletInfo * -_mate_panel_applets_manager_get_applet_info (GKeyFile *applet_file, - const gchar *group, - const gchar *factory_id) -{ - MatePanelAppletInfo *info; - char *iid; - char *name; - char *comment; - char *icon; - char **old_ids; - - iid = g_strdup_printf ("%s::%s", factory_id, group); - name = g_key_file_get_locale_string (applet_file, group, - "Name", NULL, NULL); - comment = g_key_file_get_locale_string (applet_file, group, - "Description", NULL, NULL); - icon = g_key_file_get_string (applet_file, group, "Icon", NULL); - /* MateComponent compatibility */ - old_ids = g_key_file_get_string_list (applet_file, group, - "MateComponentId", NULL, NULL); - - info = mate_panel_applet_info_new (iid, name, comment, icon, (const char **) old_ids); - - g_free (iid); - g_free (name); - g_free (comment); - g_free (icon); - g_strfreev (old_ids); - - return info; -} - -static MatePanelAppletFactoryInfo * -mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filename) -{ - MatePanelAppletFactoryInfo *info; - GKeyFile *applet_file; - gchar **groups; - gsize n_groups; - gint i; - GError *error = NULL; - - applet_file = g_key_file_new (); - if (!g_key_file_load_from_file (applet_file, filename, G_KEY_FILE_NONE, &error)) { - g_warning ("Error opening panel applet file %s: %s", - filename, error->message); - g_error_free (error); - g_key_file_free (applet_file); - - return NULL; - } - - info = g_slice_new0 (MatePanelAppletFactoryInfo); - info->id = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, "Id", NULL); - if (!info->id) { - g_warning ("Bad panel applet file %s: Could not find 'Id' in group '%s'", - filename, MATE_PANEL_APPLET_FACTORY_GROUP); - mate_panel_applet_factory_info_free (info); - g_key_file_free (applet_file); - - return NULL; - } - - info->in_process = g_key_file_get_boolean (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, - "InProcess", NULL); - if (info->in_process) { - info->location = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, - "Location", NULL); - if (!info->location) { - g_warning ("Bad panel applet file %s: In-process applet without 'Location'", - filename); - mate_panel_applet_factory_info_free (info); - g_key_file_free (applet_file); - - return NULL; - } - } - - info->has_old_ids = FALSE; - - groups = g_key_file_get_groups (applet_file, &n_groups); - for (i = 0; i < n_groups; i++) { - MatePanelAppletInfo *ainfo; - - if (g_strcmp0 (groups[i], MATE_PANEL_APPLET_FACTORY_GROUP) == 0) - continue; - - ainfo = _mate_panel_applets_manager_get_applet_info (applet_file, - groups[i], info->id); - if (mate_panel_applet_info_get_old_ids (ainfo) != NULL) - info->has_old_ids = TRUE; - - info->applet_list = g_list_prepend (info->applet_list, ainfo); - } - g_strfreev (groups); - - g_key_file_free (applet_file); - - if (!info->applet_list) { - mate_panel_applet_factory_info_free (info); - return NULL; - } - - info->srcdir = g_path_get_dirname (filename); - - return info; -} - -static GSList * -mate_panel_applets_manager_get_applets_dirs (void) -{ - const gchar *dir = NULL; - gchar **paths; - guint i; - GSList *retval = NULL; - - dir = g_getenv ("MATE_PANEL_APPLETS_DIR"); - if (!dir || g_strcmp0 (dir, "") == 0) { - return g_slist_prepend (NULL, g_strdup (MATE_PANEL_APPLETS_DIR)); - } - - paths = g_strsplit (dir, ":", 0); - for (i = 0; paths[i]; i++) { - if (g_slist_find_custom (retval, paths[i], (GCompareFunc) g_strcmp0)) - continue; - retval = g_slist_prepend (retval, g_strdup (paths[i])); - } - g_strfreev (paths); - - return g_slist_reverse (retval); -} - -static void -applets_directory_changed (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event_type, - gpointer user_data) -{ - MatePanelAppletsManagerDBus *manager = MATE_PANEL_APPLETS_MANAGER_DBUS (user_data); - - switch (event_type) { - case G_FILE_MONITOR_EVENT_CHANGED: - case G_FILE_MONITOR_EVENT_CREATED: { - MatePanelAppletFactoryInfo *info; - MatePanelAppletFactoryInfo *old_info; - gchar *filename; - GSList *dirs, *d; - - filename = g_file_get_path (file); - if (!g_str_has_suffix (filename, MATE_PANEL_APPLETS_EXTENSION)) { - g_free (filename); - return; - } - - info = mate_panel_applets_manager_get_applet_factory_info_from_file (filename); - g_free (filename); - - if (!info) - return; - - old_info = g_hash_table_lookup (manager->priv->applet_factories, info->id); - if (!old_info) { - /* New applet, just insert it */ - g_hash_table_insert (manager->priv->applet_factories, g_strdup (info->id), info); - return; - } - - /* Make sure we don't update an applet that has changed in - * another source dir unless it takes precedence over the - * current one */ - if (g_strcmp0 (info->srcdir, old_info->srcdir) == 0) { - g_hash_table_replace (manager->priv->applet_factories, g_strdup (info->id), info); - return; - } - - dirs = mate_panel_applets_manager_get_applets_dirs (); - - for (d = dirs; d; d = g_slist_next (d)) { - gchar *path = (gchar *) d->data; - - if (g_strcmp0 (path, old_info->srcdir) == 0) { - mate_panel_applet_factory_info_free (info); - break; - } else if (g_strcmp0 (path, info->srcdir) == 0) { - g_hash_table_replace (manager->priv->applet_factories, g_strdup (info->id), info); - break; - } - } - - g_slist_foreach (dirs, (GFunc) g_free, NULL); - g_slist_free (dirs); - } - break; - default: - /* Ignore any other change */ - break; - } -} - -static void -mate_panel_applets_manager_dbus_load_applet_infos (MatePanelAppletsManagerDBus *manager) -{ - GSList *dirs, *d; - GDir *dir; - const gchar *dirent; - GError *error = NULL; - - dirs = mate_panel_applets_manager_get_applets_dirs (); - for (d = dirs; d; d = g_slist_next (d)) { - GFileMonitor *monitor; - GFile *dir_file; - gchar *path = (gchar *) d->data; - - dir = g_dir_open (path, 0, &error); - if (!dir) { - g_warning ("%s", error->message); - g_error_free (error); - g_free (path); - - continue; - } - - /* Monitor dir */ - dir_file = g_file_new_for_path (path); - monitor = g_file_monitor_directory (dir_file, - G_FILE_MONITOR_NONE, - NULL, NULL); - if (monitor) { - g_signal_connect (monitor, "changed", - G_CALLBACK (applets_directory_changed), - manager); - manager->priv->monitors = g_list_prepend (manager->priv->monitors, monitor); - } - g_object_unref (dir_file); - - while ((dirent = g_dir_read_name (dir))) { - MatePanelAppletFactoryInfo *info; - gchar *file; - - if (!g_str_has_suffix (dirent, MATE_PANEL_APPLETS_EXTENSION)) - continue; - - file = g_build_filename (path, dirent, NULL); - info = mate_panel_applets_manager_get_applet_factory_info_from_file (file); - g_free (file); - - if (!info) - continue; - - if (g_hash_table_lookup (manager->priv->applet_factories, info->id)) { - mate_panel_applet_factory_info_free (info); - continue; - } - - g_hash_table_insert (manager->priv->applet_factories, g_strdup (info->id), info); - } - - g_dir_close (dir); - g_free (path); - } - - g_slist_free (dirs); -} - -static GList * -mate_panel_applets_manager_dbus_get_applets (MatePanelAppletsManager *manager) -{ - MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); - - GHashTableIter iter; - gpointer key, value; - GList *retval = NULL; - - g_hash_table_iter_init (&iter, dbus_manager->priv->applet_factories); - while (g_hash_table_iter_next (&iter, &key, &value)) { - MatePanelAppletFactoryInfo *info; - - info = (MatePanelAppletFactoryInfo *) value; - retval = g_list_concat (retval, g_list_copy (info->applet_list)); - } - - return retval; -} - -static MatePanelAppletFactoryInfo * -get_applet_factory_info (MatePanelAppletsManager *manager, - const gchar *iid) -{ - MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); - - MatePanelAppletFactoryInfo *info; - const gchar *sp; - gchar *factory_id; - - sp = g_strrstr (iid, "::"); - if (!sp) - return NULL; - - factory_id = g_strndup (iid, strlen (iid) - strlen (sp)); - info = g_hash_table_lookup (dbus_manager->priv->applet_factories, factory_id); - g_free (factory_id); - - return info; -} - -static gboolean -mate_panel_applets_manager_dbus_factory_activate (MatePanelAppletsManager *manager, - const gchar *iid) -{ - MatePanelAppletFactoryInfo *info; - ActivateAppletFunc activate_applet; - - info = get_applet_factory_info (manager, iid); - if (!info) - return FALSE; - - /* Out-of-process applets are activated by the session bus */ - if (!info->in_process) - return TRUE; - - if (info->module) { - if (info->n_applets == 0) { - if (info->activate_applet () != 0) { - g_warning ("Failed to reactivate factory %s\n", iid); - return FALSE; - } - } - info->n_applets++; - - return TRUE; - } - - info->module = g_module_open (info->location, G_MODULE_BIND_LAZY); - if (!info->module) { - /* FIXME: use a GError? */ - g_warning ("Failed to load applet %s: %s\n", - iid, g_module_error ()); - return FALSE; - } - - if (!g_module_symbol (info->module, "_mate_panel_applet_shlib_factory", (gpointer *) &activate_applet)) { - /* FIXME: use a GError? */ - g_warning ("Failed to load applet %s: %s\n", - iid, g_module_error ()); - g_module_close (info->module); - info->module = NULL; - - return FALSE; - } - - /* Activate the applet */ - if (activate_applet () != 0) { - /* FIXME: use a GError? */ - g_warning ("Failed to load applet %s\n", iid); - g_module_close (info->module); - info->module = NULL; - - return FALSE; - } - info->activate_applet = activate_applet; - - info->n_applets = 1; - - return TRUE; -} - -static gboolean -mate_panel_applets_manager_dbus_factory_deactivate (MatePanelAppletsManager *manager, - const gchar *iid) -{ - MatePanelAppletFactoryInfo *info; - - info = get_applet_factory_info (manager, iid); - if (!info) - return FALSE; - - /* Out-of-process applets are deactivated by the session bus */ - if (!info->in_process) - return TRUE; - - if (!info->module) - return TRUE; - - info->n_applets--; - if (info->n_applets == 0) { - /* FIXME: we should close the module here, however applet types - * are registered static */ -#if 0 - g_module_close (info->module); - info->module = NULL; -#endif - } - - return TRUE; -} - -static MatePanelAppletInfo * -mate_panel_applets_manager_dbus_get_applet_info (MatePanelAppletsManager *manager, - const gchar *iid) -{ - MatePanelAppletFactoryInfo *info; - GList *l; - - info = get_applet_factory_info (manager, iid); - if (!info) - return NULL; - - for (l = info->applet_list; l; l = g_list_next (l)) { - MatePanelAppletInfo *ainfo = (MatePanelAppletInfo *) l->data; - - if (g_strcmp0 (mate_panel_applet_info_get_iid (ainfo), iid) == 0) - return ainfo; - } - - return NULL; -} - -static MatePanelAppletInfo * -mate_panel_applets_manager_dbus_get_applet_info_from_old_id (MatePanelAppletsManager *manager, - const gchar *iid) -{ - MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); - - GHashTableIter iter; - gpointer key, value; - - g_hash_table_iter_init (&iter, dbus_manager->priv->applet_factories); - while (g_hash_table_iter_next (&iter, &key, &value)) { - MatePanelAppletFactoryInfo *info; - GList *l; - - info = (MatePanelAppletFactoryInfo *) value; - if (!info->has_old_ids) - continue; - - for (l = info->applet_list; l; l = g_list_next (l)) { - MatePanelAppletInfo *ainfo; - gint i = 0; - const gchar * const *old_ids; - - ainfo = (MatePanelAppletInfo *) l->data; - - old_ids = mate_panel_applet_info_get_old_ids (ainfo); - - if (old_ids == NULL) - continue; - - while (old_ids[i]) { - if (g_strcmp0 (old_ids[i], iid) == 0) - return ainfo; - i++; - } - } - } - - return NULL; -} - -static gboolean -mate_panel_applets_manager_dbus_load_applet (MatePanelAppletsManager *manager, - const gchar *iid, - MatePanelAppletFrameActivating *frame_act) -{ - return mate_panel_applet_frame_dbus_load (iid, frame_act); -} - -static void -mate_panel_applets_manager_dbus_finalize (GObject *object) -{ - MatePanelAppletsManagerDBus *manager = MATE_PANEL_APPLETS_MANAGER_DBUS (object); - - if (manager->priv->monitors) { - g_list_foreach (manager->priv->monitors, (GFunc) g_object_unref, NULL); - g_list_free (manager->priv->monitors); - manager->priv->monitors = NULL; - } - - if (manager->priv->applet_factories) { - g_hash_table_destroy (manager->priv->applet_factories); - manager->priv->applet_factories = NULL; - } - - G_OBJECT_CLASS (mate_panel_applets_manager_dbus_parent_class)->finalize (object); -} - -static void -mate_panel_applets_manager_dbus_init (MatePanelAppletsManagerDBus *manager) -{ - manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, - PANEL_TYPE_APPLETS_MANAGER_DBUS, - MatePanelAppletsManagerDBusPrivate); - - manager->priv->applet_factories = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) mate_panel_applet_factory_info_free); - - mate_panel_applets_manager_dbus_load_applet_infos (manager); -} - -static void -mate_panel_applets_manager_dbus_class_init (MatePanelAppletsManagerDBusClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - MatePanelAppletsManagerClass *manager_class = MATE_PANEL_APPLETS_MANAGER_CLASS (class); - - gobject_class->finalize = mate_panel_applets_manager_dbus_finalize; - - manager_class->get_applets = mate_panel_applets_manager_dbus_get_applets; - manager_class->factory_activate = mate_panel_applets_manager_dbus_factory_activate; - manager_class->factory_deactivate = mate_panel_applets_manager_dbus_factory_deactivate; - manager_class->get_applet_info = mate_panel_applets_manager_dbus_get_applet_info; - manager_class->get_applet_info_from_old_id = mate_panel_applets_manager_dbus_get_applet_info_from_old_id; - manager_class->load_applet = mate_panel_applets_manager_dbus_load_applet; - - g_type_class_add_private (class, sizeof (MatePanelAppletsManagerDBusPrivate)); -} diff --git a/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.h b/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.h deleted file mode 100644 index 0250ce54..00000000 --- a/mate-panel/libmate-panel-applet-private/mate-panel-applets-manager-dbus.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * mate-panel-applets-manager-dbus.h - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __MATE_PANEL_APPLETS_MANAGER_DBUS_H__ -#define __MATE_PANEL_APPLETS_MANAGER_DBUS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_APPLETS_MANAGER_DBUS (mate_panel_applets_manager_dbus_get_type ()) -#define MATE_PANEL_APPLETS_MANAGER_DBUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBus)) -#define MATE_PANEL_APPLETS_MANAGER_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBusClass)) -#define PANEL_IS_APPLETS_MANAGER_DBUS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS)) -#define PANEL_IS_APPLETS_MANAGER_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLETS_MANAGER_DBUS)) -#define MATE_PANEL_APPLETS_MANAGER_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBusClass)) - -typedef struct _MatePanelAppletsManagerDBus MatePanelAppletsManagerDBus; -typedef struct _MatePanelAppletsManagerDBusClass MatePanelAppletsManagerDBusClass; -typedef struct _MatePanelAppletsManagerDBusPrivate MatePanelAppletsManagerDBusPrivate; - -struct _MatePanelAppletsManagerDBusClass { - MatePanelAppletsManagerClass parent_class; -}; - -struct _MatePanelAppletsManagerDBus { - MatePanelAppletsManager parent; - - /*< private > */ - MatePanelAppletsManagerDBusPrivate *priv; -}; - -GType mate_panel_applets_manager_dbus_get_type (void); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLETS_MANAGER_DBUS_H__ */ diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-container.c b/mate-panel/libmate-panel-applet-private/panel-applet-container.c new file mode 100644 index 00000000..7aa34d6a --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applet-container.c @@ -0,0 +1,798 @@ +/* + * panel-applet-container.c: a container for applets. + * + * Copyright (C) 2010 Carlos Garcia Campos + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#if GTK_CHECK_VERSION (3, 0, 0) +#include +#endif +#include "panel-applet-container.h" +#include "panel-marshal.h" + +struct _MatePanelAppletContainerPrivate { + GDBusProxy *applet_proxy; + + guint name_watcher_id; + gchar *bus_name; + + guint32 xid; + GtkWidget *socket; + + GHashTable *pending_ops; +}; + +enum { + APPLET_BROKEN, + APPLET_MOVE, + APPLET_REMOVE, + APPLET_LOCK, + CHILD_PROPERTY_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +typedef struct { + const gchar *name; + const gchar *dbus_name; +} AppletPropertyInfo; + +static const AppletPropertyInfo applet_properties [] = { + { "prefs-path", "PrefsPath" }, + { "orient", "Orient" }, + { "size", "Size" }, + { "size-hints", "SizeHints" }, + { "background", "Background" }, + { "flags", "Flags" }, + { "locked", "Locked" }, + { "locked-down", "LockedDown" } +}; + +#define MATE_PANEL_APPLET_CONTAINER_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerPrivate)) + +#define MATE_PANEL_APPLET_BUS_NAME "org.mate.panel.applet.%s" +#define MATE_PANEL_APPLET_FACTORY_INTERFACE "org.mate.panel.applet.AppletFactory" +#define MATE_PANEL_APPLET_FACTORY_OBJECT_PATH "/org/mate/panel/applet/%s" +#define MATE_PANEL_APPLET_INTERFACE "org.mate.panel.applet.Applet" + +static gboolean mate_panel_applet_container_plug_removed (MatePanelAppletContainer *container); + +G_DEFINE_TYPE (MatePanelAppletContainer, mate_panel_applet_container, GTK_TYPE_EVENT_BOX); + +GQuark mate_panel_applet_container_error_quark (void) +{ + return g_quark_from_static_string ("mate-panel-applet-container-error-quark"); +} + +static void mate_panel_applet_container_init(MatePanelAppletContainer* container) +{ + container->priv = MATE_PANEL_APPLET_CONTAINER_GET_PRIVATE (container); + + container->priv->socket = gtk_socket_new (); + g_signal_connect_swapped (container->priv->socket, "plug-removed", G_CALLBACK (mate_panel_applet_container_plug_removed), container); + + container->priv->pending_ops = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, + (GDestroyNotify) g_object_unref); + + gtk_container_add (GTK_CONTAINER (container), + container->priv->socket); + gtk_widget_show (container->priv->socket); +} + +static void +mate_panel_applet_container_cancel_pending_operations (MatePanelAppletContainer *container) +{ + GList *keys, *l; + + if (!container->priv->pending_ops) + return; + + keys = g_hash_table_get_keys (container->priv->pending_ops); + for (l = keys; l; l = g_list_next (l)) { + GCancellable *cancellable; + + cancellable = G_CANCELLABLE (g_hash_table_lookup (container->priv->pending_ops, l->data)); + g_cancellable_cancel (cancellable); + } + g_list_free (keys); +} + +static void +mate_panel_applet_container_dispose (GObject *object) +{ + MatePanelAppletContainer *container = MATE_PANEL_APPLET_CONTAINER (object); + + if (container->priv->pending_ops) { + mate_panel_applet_container_cancel_pending_operations (container); + g_hash_table_destroy (container->priv->pending_ops); + container->priv->pending_ops = NULL; + } + + if (container->priv->bus_name) { + g_free (container->priv->bus_name); + container->priv->bus_name = NULL; + } + + if (container->priv->name_watcher_id > 0) { + g_bus_unwatch_name (container->priv->name_watcher_id); + container->priv->name_watcher_id = 0; + } + + if (container->priv->applet_proxy) { + g_object_unref (container->priv->applet_proxy); + container->priv->applet_proxy = NULL; + } + + G_OBJECT_CLASS (mate_panel_applet_container_parent_class)->dispose (object); +} + +static void +mate_panel_applet_container_class_init (MatePanelAppletContainerClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (MatePanelAppletContainerPrivate)); + + gobject_class->dispose = mate_panel_applet_container_dispose; + + signals[APPLET_BROKEN] = + g_signal_new ("applet-broken", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_broken), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + signals[APPLET_MOVE] = + g_signal_new ("applet-move", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_move), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + signals[APPLET_REMOVE] = + g_signal_new ("applet-remove", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_remove), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + signals[APPLET_LOCK] = + g_signal_new ("applet-lock", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MatePanelAppletContainerClass, applet_lock), + NULL, + NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, + 1, G_TYPE_BOOLEAN); + signals[CHILD_PROPERTY_CHANGED] = + g_signal_new ("child-property-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | + G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET (MatePanelAppletContainerClass, child_property_changed), + NULL, + NULL, + panel_marshal_VOID__STRING_POINTER, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_POINTER); +} + +static const AppletPropertyInfo * +mate_panel_applet_container_child_property_get_info (const gchar *property_name) +{ + gint i; + + g_assert (property_name != NULL); + + for (i = 0; i < G_N_ELEMENTS (applet_properties); i++) { + if (g_ascii_strcasecmp (applet_properties[i].name, property_name) == 0) + return &applet_properties[i]; + } + + return NULL; +} + +GtkWidget * +mate_panel_applet_container_new (void) +{ + GtkWidget *container; + + container = GTK_WIDGET (g_object_new (PANEL_TYPE_APPLET_CONTAINER, NULL)); + + return container; +} + +static gboolean +mate_panel_applet_container_plug_removed (MatePanelAppletContainer *container) +{ + if (!container->priv->applet_proxy) + return FALSE; + + mate_panel_applet_container_cancel_pending_operations (container); + + if (container->priv->name_watcher_id > 0) { + g_bus_unwatch_name (container->priv->name_watcher_id); + container->priv->name_watcher_id = 0; + } + + g_object_unref (container->priv->applet_proxy); + container->priv->applet_proxy = NULL; + + g_signal_emit (container, signals[APPLET_BROKEN], 0); + + /* Continue destroying, in case of reloading + * a new frame widget is created + */ + return FALSE; +} + +static void +mate_panel_applet_container_child_signal (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + MatePanelAppletContainer *container) +{ + if (g_strcmp0 (signal_name, "Move") == 0) { + g_signal_emit (container, signals[APPLET_MOVE], 0); + } else if (g_strcmp0 (signal_name, "RemoveFromPanel") == 0) { + g_signal_emit (container, signals[APPLET_REMOVE], 0); + } else if (g_strcmp0 (signal_name, "Lock") == 0) { + g_signal_emit (container, signals[APPLET_LOCK], 0, TRUE); + } else if (g_strcmp0 (signal_name, "Unlock") == 0) { + g_signal_emit (container, signals[APPLET_LOCK], 0, FALSE); + } +} + +static void +on_property_changed (GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + MatePanelAppletContainer *container) +{ + GVariant *props; + GVariantIter iter; + GVariant *value; + gchar *key; + + g_variant_get (parameters, "(s@a{sv}*)", NULL, &props, NULL); + + g_variant_iter_init (&iter, props); + while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) { + if (g_strcmp0 (key, "Flags") == 0) { + g_signal_emit (container, signals[CHILD_PROPERTY_CHANGED], + g_quark_from_string ("flags"), + "flags", value); + } else if (g_strcmp0 (key, "SizeHints") == 0) { + g_signal_emit (container, signals[CHILD_PROPERTY_CHANGED], + g_quark_from_string ("size-hints"), + "size-hints", value); + } + } + + g_variant_unref (props); +} + +static void +on_proxy_appeared (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + MatePanelAppletContainer *container; + GDBusProxy *proxy; + GError *error = NULL; + + proxy = g_dbus_proxy_new_finish (res, &error); + if (!proxy) { + g_simple_async_result_set_from_error (result, error); + g_error_free (error); + g_simple_async_result_complete (result); + g_object_unref (result); + + return; + } + + container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); + + container->priv->applet_proxy = proxy; + g_signal_connect (container->priv->applet_proxy, "g-signal", + G_CALLBACK (mate_panel_applet_container_child_signal), + container); + g_dbus_connection_signal_subscribe (g_dbus_proxy_get_connection (proxy), + g_dbus_proxy_get_name (proxy), + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + g_dbus_proxy_get_object_path (proxy), + MATE_PANEL_APPLET_INTERFACE, + G_DBUS_SIGNAL_FLAGS_NONE, + (GDBusSignalCallback) on_property_changed, + container, NULL); + + g_simple_async_result_complete (result); + g_object_unref (result); + + if (container->priv->xid > 0) { + gtk_socket_add_id (GTK_SOCKET (container->priv->socket), + container->priv->xid); + } + + /* g_async_result_get_source_object returns new ref */ + g_object_unref (container); +} + +static void +get_applet_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source_object); + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + MatePanelAppletContainer *container; + GVariant *retvals; + const gchar *applet_path; + GError *error = NULL; + + retvals = g_dbus_connection_call_finish (connection, res, &error); + if (!retvals) { + g_simple_async_result_set_from_error (result, error); + g_error_free (error); + g_simple_async_result_complete (result); + g_object_unref (result); + + return; + } + + container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); + g_variant_get (retvals, "(&ou)", &applet_path, &container->priv->xid); + + g_dbus_proxy_new (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + container->priv->bus_name, + applet_path, + MATE_PANEL_APPLET_INTERFACE, + NULL, + (GAsyncReadyCallback) on_proxy_appeared, + result); + + g_variant_unref (retvals); + + /* g_async_result_get_source_object returns new ref */ + g_object_unref (container); +} + +typedef struct { + GSimpleAsyncResult *result; + gchar *factory_id; + GVariant *parameters; + GCancellable *cancellable; +} AppletFactoryData; + +static void +applet_factory_data_free (AppletFactoryData *data) +{ + g_free (data->factory_id); + if (data->cancellable) + g_object_unref (data->cancellable); + + g_free (data); +} + +static void +on_factory_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + AppletFactoryData *data) +{ + MatePanelAppletContainer *container; + gchar *object_path; + + container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (data->result))); + container->priv->bus_name = g_strdup (name_owner); + object_path = g_strdup_printf (MATE_PANEL_APPLET_FACTORY_OBJECT_PATH, data->factory_id); + g_dbus_connection_call (connection, + name_owner, + object_path, + MATE_PANEL_APPLET_FACTORY_INTERFACE, + "GetApplet", + data->parameters, + G_VARIANT_TYPE ("(ou)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + data->cancellable, + get_applet_cb, + data->result); + g_free (object_path); +} + +static void +mate_panel_applet_container_get_applet (MatePanelAppletContainer *container, + GdkScreen *screen, + const gchar *iid, + GVariant *props, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + AppletFactoryData *data; + gint screen_number; + gchar *bus_name; + gchar *factory_id; + gchar *applet_id; + + result = g_simple_async_result_new (G_OBJECT (container), + callback, + user_data, + mate_panel_applet_container_get_applet); + + applet_id = g_strrstr (iid, "::"); + if (!applet_id) { + g_simple_async_result_set_error (result, + MATE_PANEL_APPLET_CONTAINER_ERROR, + MATE_PANEL_APPLET_CONTAINER_INVALID_APPLET, + "Invalid applet iid: %s", iid); + g_simple_async_result_complete (result); + g_object_unref (result); + + return; + } + + factory_id = g_strndup (iid, strlen (iid) - strlen (applet_id)); + applet_id += 2; + + /* we can't use the screen of the container widget since it's not in a + * widget hierarchy yet */ + screen_number = gdk_screen_get_number (screen); + + data = g_new (AppletFactoryData, 1); + data->result = result; + data->factory_id = factory_id; + data->parameters = g_variant_new ("(si*)", applet_id, screen_number, props); + data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + + bus_name = g_strdup_printf (MATE_PANEL_APPLET_BUS_NAME, factory_id); + + container->priv->name_watcher_id = + g_bus_watch_name (G_BUS_TYPE_SESSION, + bus_name, + G_BUS_NAME_WATCHER_FLAGS_AUTO_START, + (GBusNameAppearedCallback) on_factory_appeared, + NULL, + data, + (GDestroyNotify) applet_factory_data_free); + + g_free (bus_name); +} + +void +mate_panel_applet_container_add (MatePanelAppletContainer *container, + GdkScreen *screen, + const gchar *iid, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data, + GVariant *properties) +{ + g_return_if_fail (PANEL_IS_APPLET_CONTAINER (container)); + g_return_if_fail (iid != NULL); + + mate_panel_applet_container_cancel_pending_operations (container); + + mate_panel_applet_container_get_applet (container, screen, iid, properties, + cancellable, callback, user_data); +} + +gboolean +mate_panel_applet_container_add_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_get_applet); + + return !g_simple_async_result_propagate_error (simple, error); +} + +/* Child Properties */ +static void +set_applet_property_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source_object); + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + MatePanelAppletContainer *container; + GVariant *retvals; + GError *error = NULL; + + retvals = g_dbus_connection_call_finish (connection, res, &error); + if (!retvals) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Error setting property: %s\n", error->message); + g_simple_async_result_set_from_error (result, error); + g_error_free (error); + } else { + g_variant_unref (retvals); + } + + container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); + g_hash_table_remove (container->priv->pending_ops, result); + g_simple_async_result_complete (result); + g_object_unref (result); + + /* g_async_result_get_source_object returns new ref */ + g_object_unref (container); +} + +void +mate_panel_applet_container_child_set (MatePanelAppletContainer *container, + const gchar *property_name, + const GVariant *value, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GDBusProxy *proxy = container->priv->applet_proxy; + const AppletPropertyInfo *info; + GSimpleAsyncResult *result; + + if (!proxy) + return; + + info = mate_panel_applet_container_child_property_get_info (property_name); + if (!info) { + g_simple_async_report_error_in_idle (G_OBJECT (container), + callback, user_data, + MATE_PANEL_APPLET_CONTAINER_ERROR, + MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY, + "%s: Applet has no child property named `%s'", + G_STRLOC, property_name); + return; + } + + result = g_simple_async_result_new (G_OBJECT (container), + callback, + user_data, + mate_panel_applet_container_child_set); + + if (cancellable) + g_object_ref (cancellable); + else + cancellable = g_cancellable_new (); + g_hash_table_insert (container->priv->pending_ops, result, cancellable); + + g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), + g_dbus_proxy_get_name (proxy), + g_dbus_proxy_get_object_path (proxy), + "org.freedesktop.DBus.Properties", + "Set", + g_variant_new ("(ssv)", + g_dbus_proxy_get_interface_name (proxy), + info->dbus_name, + value), + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, cancellable, + set_applet_property_cb, + result); +} + +gboolean +mate_panel_applet_container_child_set_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_set); + + return !g_simple_async_result_propagate_error (simple, error); +} + +static void +get_applet_property_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source_object); + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + MatePanelAppletContainer *container; + GVariant *retvals; + GError *error = NULL; + + retvals = g_dbus_connection_call_finish (connection, res, &error); + if (!retvals) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Error getting property: %s\n", error->message); + g_simple_async_result_set_from_error (result, error); + g_error_free (error); + } else { + GVariant *value, *item; + + item = g_variant_get_child_value (retvals, 0); + value = g_variant_get_variant (item); + g_variant_unref (item); + g_simple_async_result_set_op_res_gpointer (result, value, + (GDestroyNotify) g_variant_unref); + g_variant_unref (retvals); + } + + container = MATE_PANEL_APPLET_CONTAINER (g_async_result_get_source_object (G_ASYNC_RESULT (result))); + g_hash_table_remove (container->priv->pending_ops, result); + g_simple_async_result_complete (result); + g_object_unref (result); + + /* g_async_result_get_source_object returns new ref */ + g_object_unref (container); +} + +void +mate_panel_applet_container_child_get (MatePanelAppletContainer *container, + const gchar *property_name, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GDBusProxy *proxy = container->priv->applet_proxy; + const AppletPropertyInfo *info; + GSimpleAsyncResult *result; + + if (!proxy) + return; + + info = mate_panel_applet_container_child_property_get_info (property_name); + if (!info) { + g_simple_async_report_error_in_idle (G_OBJECT (container), + callback, user_data, + MATE_PANEL_APPLET_CONTAINER_ERROR, + MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY, + "%s: Applet has no child property named `%s'", + G_STRLOC, property_name); + return; + } + + result = g_simple_async_result_new (G_OBJECT (container), + callback, + user_data, + mate_panel_applet_container_child_get); + if (cancellable) + g_object_ref (cancellable); + else + cancellable = g_cancellable_new (); + g_hash_table_insert (container->priv->pending_ops, result, cancellable); + + g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), + g_dbus_proxy_get_name (proxy), + g_dbus_proxy_get_object_path (proxy), + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + g_dbus_proxy_get_interface_name (proxy), + info->dbus_name), + G_VARIANT_TYPE ("(v)"), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, cancellable, + get_applet_property_cb, + result); +} + +GVariant * +mate_panel_applet_container_child_get_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_get); + + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + + return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple)); +} + +static void +child_popup_menu_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source_object); + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + GVariant *retvals; + GError *error = NULL; + + retvals = g_dbus_connection_call_finish (connection, res, &error); + if (!retvals) { + g_simple_async_result_set_from_error (result, error); + g_error_free (error); + } else { + g_variant_unref (retvals); + } + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +mate_panel_applet_container_child_popup_menu (MatePanelAppletContainer *container, + guint button, + guint32 timestamp, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + GDBusProxy *proxy = container->priv->applet_proxy; + + if (!proxy) + return; + + result = g_simple_async_result_new (G_OBJECT (container), + callback, + user_data, + mate_panel_applet_container_child_popup_menu); + + g_dbus_connection_call (g_dbus_proxy_get_connection (proxy), + g_dbus_proxy_get_name (proxy), + g_dbus_proxy_get_object_path (proxy), + MATE_PANEL_APPLET_INTERFACE, + "PopupMenu", + g_variant_new ("(uu)", button, timestamp), + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, cancellable, + child_popup_menu_cb, + result); +} + +gboolean +mate_panel_applet_container_child_popup_menu_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == mate_panel_applet_container_child_popup_menu); + + return !g_simple_async_result_propagate_error (simple, error); +} diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-container.h b/mate-panel/libmate-panel-applet-private/panel-applet-container.h new file mode 100644 index 00000000..108a38c9 --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applet-container.h @@ -0,0 +1,119 @@ +/* + * panel-applet-container.h: a container for applets. + * + * Copyright (C) 2010 Carlos Garcia Campos + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __PANEL_APPLET_CONTAINER_H__ +#define __PANEL_APPLET_CONTAINER_H__ + +#include +#include +#include "panel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PANEL_TYPE_APPLET_CONTAINER (mate_panel_applet_container_get_type ()) +#define MATE_PANEL_APPLET_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainer)) +#define MATE_PANEL_APPLET_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerClass)) +#define PANEL_IS_APPLET_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLET_CONTAINER)) +#define PANEL_IS_APPLET_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLET_CONTAINER)) +#define MATE_PANEL_APPLET_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANEL_TYPE_APPLET_CONTAINER, MatePanelAppletContainerClass)) + +#define MATE_PANEL_APPLET_CONTAINER_ERROR (mate_panel_applet_container_error_quark()) + +typedef enum { + MATE_PANEL_APPLET_CONTAINER_INVALID_APPLET, + MATE_PANEL_APPLET_CONTAINER_INVALID_CHILD_PROPERTY +} MatePanelAppletContainerError; + +typedef struct _MatePanelAppletContainer MatePanelAppletContainer; +typedef struct _MatePanelAppletContainerClass MatePanelAppletContainerClass; +typedef struct _MatePanelAppletContainerPrivate MatePanelAppletContainerPrivate; + +struct _MatePanelAppletContainer { + GtkEventBox parent; + + MatePanelAppletContainerPrivate *priv; +}; + +struct _MatePanelAppletContainerClass { + GtkEventBoxClass parent_class; + + /* Signals */ + void (*applet_broken) (MatePanelAppletContainer *container); + void (*applet_move) (MatePanelAppletContainer *container); + void (*applet_remove) (MatePanelAppletContainer *container); + void (*applet_lock) (MatePanelAppletContainer *container, + gboolean locked); + void (*child_property_changed) (MatePanelAppletContainer *container, + const gchar *property_name, + GVariant *value); +}; + +GType mate_panel_applet_container_get_type (void) G_GNUC_CONST; +GQuark mate_panel_applet_container_error_quark (void) G_GNUC_CONST; +GtkWidget *mate_panel_applet_container_new (void); + + +void mate_panel_applet_container_add (MatePanelAppletContainer *container, + GdkScreen *screen, + const gchar *iid, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data, + GVariant *properties); +gboolean mate_panel_applet_container_add_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error); +void mate_panel_applet_container_child_popup_menu (MatePanelAppletContainer *container, + guint button, + guint32 timestamp, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mate_panel_applet_container_child_popup_menu_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error); + +void mate_panel_applet_container_child_set (MatePanelAppletContainer *container, + const gchar *property_name, + const GVariant *value, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mate_panel_applet_container_child_set_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error); +void mate_panel_applet_container_child_get (MatePanelAppletContainer *container, + const gchar *property_name, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GVariant *mate_panel_applet_container_child_get_finish (MatePanelAppletContainer *container, + GAsyncResult *result, + GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLET_CONTAINER_H__ */ diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.c b/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.c new file mode 100644 index 00000000..9330db0d --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.c @@ -0,0 +1,469 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * panel-applet-frame-dbus.c: panel side container for applets + * + * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Authors: + * Mark McLoughlin + */ + +#include + +#include + +#include +#include + +#include "panel-applet-container.h" +#include "panel-applet-frame-dbus.h" + +G_DEFINE_TYPE (MatePanelAppletFrameDBus, + mate_panel_applet_frame_dbus, + PANEL_TYPE_APPLET_FRAME) + +struct _MatePanelAppletFrameDBusPrivate +{ + MatePanelAppletContainer *container; + GCancellable *bg_cancellable; +}; + +/* Keep in sync with mate-panel-applet.h. Uggh. */ +typedef enum { + APPLET_FLAGS_NONE = 0, + APPLET_EXPAND_MAJOR = 1 << 0, + APPLET_EXPAND_MINOR = 1 << 1, + APPLET_HAS_HANDLE = 1 << 2 +} MatePanelAppletFlags; + + +static guint +get_mate_panel_applet_orient (PanelOrientation orientation) +{ + /* For some reason libmate-panel-applet and panel use a different logic for + * orientation, so we need to convert it. We should fix this. */ + switch (orientation) { + case PANEL_ORIENTATION_TOP: + return 1; + case PANEL_ORIENTATION_BOTTOM: + return 0; + case PANEL_ORIENTATION_LEFT: + return 3; + case PANEL_ORIENTATION_RIGHT: + return 2; + default: + g_assert_not_reached (); + break; + } +} + +static void +mate_panel_applet_frame_dbus_update_flags (MatePanelAppletFrame *frame, + GVariant *value) +{ + guint32 flags; + gboolean major; + gboolean minor; + gboolean has_handle; + + flags = g_variant_get_uint32 (value); + + major = (flags & APPLET_EXPAND_MAJOR) != 0; + minor = (flags & APPLET_EXPAND_MINOR) != 0; + has_handle = (flags & APPLET_HAS_HANDLE) != 0; + + _mate_panel_applet_frame_update_flags (frame, major, minor, has_handle); +} + + +static void +mate_panel_applet_frame_dbus_get_flags_cb (MatePanelAppletContainer *container, + GAsyncResult *res, + MatePanelAppletFrame *frame) +{ + GVariant *value; + GError *error = NULL; + + value = mate_panel_applet_container_child_get_finish (container, res, &error); + if (!value) { + g_warning ("%s\n", error->message); + g_error_free (error); + return; + } + + mate_panel_applet_frame_dbus_update_flags (frame, value); + g_variant_unref (value); +} + +static void +mate_panel_applet_frame_dbus_get_size_hints_cb (MatePanelAppletContainer *container, + GAsyncResult *res, + MatePanelAppletFrame *frame) +{ + GVariant *value; + const gint *sz; + gint *size_hints = NULL; + gsize n_elements; + GError *error = NULL; + + value = mate_panel_applet_container_child_get_finish (container, res, &error); + if (!value) { + g_warning ("%s\n", error->message); + g_error_free (error); + return; + } + + sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); + if (n_elements > 0) { + size_hints = g_new (gint32, n_elements); + memcpy (size_hints, sz, n_elements * sizeof (gint32)); + } + + _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); + g_variant_unref (value); +} + +static void +mate_panel_applet_frame_dbus_init_properties (MatePanelAppletFrame *frame) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + + mate_panel_applet_container_child_get (dbus_frame->priv->container, "flags", NULL, + (GAsyncReadyCallback) mate_panel_applet_frame_dbus_get_flags_cb, + frame); + mate_panel_applet_container_child_get (dbus_frame->priv->container, "size-hints", NULL, + (GAsyncReadyCallback) mate_panel_applet_frame_dbus_get_size_hints_cb, + frame); +} + +static void +mate_panel_applet_frame_dbus_sync_menu_state (MatePanelAppletFrame *frame, + gboolean movable, + gboolean removable, + gboolean lockable, + gboolean locked, + gboolean locked_down) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + + mate_panel_applet_container_child_set (dbus_frame->priv->container, + "locked", g_variant_new_boolean (lockable && locked), + NULL, NULL, NULL); + mate_panel_applet_container_child_set (dbus_frame->priv->container, + "locked-down", g_variant_new_boolean (locked_down), + NULL, NULL, NULL); +} + +static void +mate_panel_applet_frame_dbus_popup_menu (MatePanelAppletFrame *frame, + guint button, + guint32 timestamp) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + + mate_panel_applet_container_child_popup_menu (dbus_frame->priv->container, + button, timestamp, + NULL, NULL, NULL); +} + +static void +change_orientation_cb (MatePanelAppletContainer *container, + GAsyncResult *res, + MatePanelAppletFrame *frame) +{ + GError *error = NULL; + + if (!mate_panel_applet_container_child_set_finish (container, res, &error)) { + g_warning ("%s\n", error->message); + g_error_free (error); + + return; + } + + gtk_widget_queue_resize (GTK_WIDGET (frame)); +} + +static void +mate_panel_applet_frame_dbus_change_orientation (MatePanelAppletFrame *frame, + PanelOrientation orientation) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + + mate_panel_applet_container_child_set (dbus_frame->priv->container, + "orient", + g_variant_new_uint32 (get_mate_panel_applet_orient (orientation)), + NULL, + (GAsyncReadyCallback)change_orientation_cb, + frame); +} + +static void +mate_panel_applet_frame_dbus_change_size (MatePanelAppletFrame *frame, + guint size) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + + mate_panel_applet_container_child_set (dbus_frame->priv->container, + "size", g_variant_new_uint32 (size), + NULL, NULL, NULL); +} + +static void +container_child_background_set (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + MatePanelAppletContainer *container = MATE_PANEL_APPLET_CONTAINER (source_object); + MatePanelAppletFrameDBus *frame = MATE_PANEL_APPLET_FRAME_DBUS (user_data); + + mate_panel_applet_container_child_set_finish (container, res, NULL); + + if (frame->priv->bg_cancellable) + g_clear_object (&frame->priv->bg_cancellable); + + frame->priv->bg_cancellable = NULL; +} + +static void +mate_panel_applet_frame_dbus_change_background (MatePanelAppletFrame *frame, + PanelBackgroundType type) +{ + MatePanelAppletFrameDBus *dbus_frame = MATE_PANEL_APPLET_FRAME_DBUS (frame); + char *bg_str; + + bg_str = _mate_panel_applet_frame_get_background_string ( + frame, PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))), type); + + if (bg_str != NULL) { + if (dbus_frame->priv->bg_cancellable) + g_cancellable_cancel (dbus_frame->priv->bg_cancellable); + dbus_frame->priv->bg_cancellable = g_cancellable_new (); + + mate_panel_applet_container_child_set (dbus_frame->priv->container, + "background", + g_variant_new_string (bg_str), + dbus_frame->priv->bg_cancellable, + container_child_background_set, + dbus_frame); + g_free (bg_str); + } +} + +static void +mate_panel_applet_frame_dbus_flags_changed (MatePanelAppletContainer *container, + const gchar *prop_name, + GVariant *value, + MatePanelAppletFrame *frame) +{ + mate_panel_applet_frame_dbus_update_flags (frame, value); +} + +static void +mate_panel_applet_frame_dbus_size_hints_changed (MatePanelAppletContainer *container, + const gchar *prop_name, + GVariant *value, + MatePanelAppletFrame *frame) +{ + const gint *sz; + gint *size_hints = NULL; + gsize n_elements; + + sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); + if (n_elements > 0) { + size_hints = g_new (gint32, n_elements); + memcpy (size_hints, sz, n_elements * sizeof (gint32)); + } + + _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); +} + +static void +mate_panel_applet_frame_dbus_applet_broken (MatePanelAppletContainer *container, + MatePanelAppletFrame *frame) +{ + _mate_panel_applet_frame_applet_broken (frame); +} + +static void +mate_panel_applet_frame_dbus_applet_remove (MatePanelAppletContainer *container, + MatePanelAppletFrame *frame) +{ + _mate_panel_applet_frame_applet_remove (frame); +} + +static void +mate_panel_applet_frame_dbus_applet_move (MatePanelAppletContainer *container, + MatePanelAppletFrame *frame) +{ + _mate_panel_applet_frame_applet_move (frame); +} + +static void +mate_panel_applet_frame_dbus_applet_lock (MatePanelAppletContainer *container, + gboolean locked, + MatePanelAppletFrame *frame) +{ + _mate_panel_applet_frame_applet_lock (frame, locked); +} + +static void +mate_panel_applet_frame_dbus_finalize (GObject *object) +{ + MatePanelAppletFrameDBus *frame = MATE_PANEL_APPLET_FRAME_DBUS (object); + + if (frame->priv->bg_cancellable) + g_cancellable_cancel (frame->priv->bg_cancellable); + + G_OBJECT_CLASS (mate_panel_applet_frame_dbus_parent_class)->finalize (object); +} + +static void +mate_panel_applet_frame_dbus_init (MatePanelAppletFrameDBus *frame) +{ + GtkWidget *container; + + frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame, + PANEL_TYPE_APPLET_FRAME_DBUS, + MatePanelAppletFrameDBusPrivate); + + container = mate_panel_applet_container_new (); + gtk_widget_show (container); + gtk_container_add (GTK_CONTAINER (frame), container); + frame->priv->container = MATE_PANEL_APPLET_CONTAINER (container); + + g_signal_connect (container, "child-property-changed::flags", + G_CALLBACK (mate_panel_applet_frame_dbus_flags_changed), + frame); + g_signal_connect (container, "child-property-changed::size-hints", + G_CALLBACK (mate_panel_applet_frame_dbus_size_hints_changed), + frame); + g_signal_connect (container, "applet-broken", + G_CALLBACK (mate_panel_applet_frame_dbus_applet_broken), + frame); + g_signal_connect (container, "applet-remove", + G_CALLBACK (mate_panel_applet_frame_dbus_applet_remove), + frame); + g_signal_connect (container, "applet-move", + G_CALLBACK (mate_panel_applet_frame_dbus_applet_move), + frame); + g_signal_connect (container, "applet-lock", + G_CALLBACK (mate_panel_applet_frame_dbus_applet_lock), + frame); +} + +static void +mate_panel_applet_frame_dbus_class_init (MatePanelAppletFrameDBusClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + MatePanelAppletFrameClass *frame_class = MATE_PANEL_APPLET_FRAME_CLASS (class); + + gobject_class->finalize = mate_panel_applet_frame_dbus_finalize; + + frame_class->init_properties = mate_panel_applet_frame_dbus_init_properties; + frame_class->sync_menu_state = mate_panel_applet_frame_dbus_sync_menu_state; + frame_class->popup_menu = mate_panel_applet_frame_dbus_popup_menu; + frame_class->change_orientation = mate_panel_applet_frame_dbus_change_orientation; + frame_class->change_size = mate_panel_applet_frame_dbus_change_size; + frame_class->change_background = mate_panel_applet_frame_dbus_change_background; + + g_type_class_add_private (class, sizeof (MatePanelAppletFrameDBusPrivate)); +} + +static void +mate_panel_applet_frame_dbus_activated (MatePanelAppletContainer *container, + GAsyncResult *res, + MatePanelAppletFrame *frame) +{ + MatePanelAppletFrameActivating *frame_act; + GError *error = NULL; + + if (!mate_panel_applet_container_add_finish (container, res, &error)) + g_assert (error != NULL); + + frame_act = g_object_get_data (G_OBJECT (frame), "mate-panel-applet-frame-activating"); + g_object_set_data (G_OBJECT (frame), "mate-panel-applet-frame-activating", NULL); + + _mate_panel_applet_frame_activated (frame, frame_act, error); +} + +gboolean +mate_panel_applet_frame_dbus_load (const gchar *iid, + MatePanelAppletFrameActivating *frame_act) +{ + MatePanelAppletFrameDBus *dbus_frame; + MatePanelAppletFrame *frame; + GVariantBuilder builder; + GdkScreen *screen; + gchar *conf_path; + gchar *background; + guint orient; + + g_return_val_if_fail (iid != NULL, FALSE); + g_return_val_if_fail (frame_act != NULL, FALSE); + + if (!mate_panel_applets_manager_factory_activate (iid)) + return FALSE; + + dbus_frame = g_object_new (PANEL_TYPE_APPLET_FRAME_DBUS, NULL); + frame = MATE_PANEL_APPLET_FRAME (dbus_frame); + _mate_panel_applet_frame_set_iid (frame, iid); + + screen = panel_applet_frame_activating_get_screen (frame_act); + orient = get_mate_panel_applet_orient (mate_panel_applet_frame_activating_get_orientation (frame_act)); + conf_path = mate_panel_applet_frame_activating_get_conf_path (frame_act); + /* we can't really get a background string at this point since we don't + * know the position of the applet */ + background = NULL; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&builder, "{sv}", + "prefs-path", + g_variant_new_string (conf_path)); + g_variant_builder_add (&builder, "{sv}", + "orient", + g_variant_new_uint32 (orient)); + g_variant_builder_add (&builder, "{sv}", + "size", + g_variant_new_uint32 (mate_panel_applet_frame_activating_get_size (frame_act))); + g_variant_builder_add (&builder, "{sv}", + "locked", + g_variant_new_boolean (mate_panel_applet_frame_activating_get_locked (frame_act))); + g_variant_builder_add (&builder, "{sv}", + "locked-down", + g_variant_new_boolean (mate_panel_applet_frame_activating_get_locked_down (frame_act))); + if (background) { + g_variant_builder_add (&builder, "{sv}", + "background", + g_variant_new_string (background)); + } + + g_object_set_data (G_OBJECT (frame), "mate-panel-applet-frame-activating", frame_act); + + mate_panel_applet_container_add (dbus_frame->priv->container, + screen, iid, NULL, + (GAsyncReadyCallback) mate_panel_applet_frame_dbus_activated, + frame, + g_variant_builder_end (&builder)); + + g_free (conf_path); + g_free (background); + + return TRUE; +} diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.h b/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.h new file mode 100644 index 00000000..73da38f2 --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applet-frame-dbus.h @@ -0,0 +1,65 @@ +/* + * panel-applet-frame-dbus.h: panel side container for applets + * + * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Authors: + * Mark McLoughlin + */ + +#ifndef __PANEL_APPLET_FRAME_DBUS_H__ +#define __PANEL_APPLET_FRAME_DBUS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PANEL_TYPE_APPLET_FRAME_DBUS (mate_panel_applet_frame_dbus_get_type ()) +#define MATE_PANEL_APPLET_FRAME_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBus)) +#define MATE_PANEL_APPLET_FRAME_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBusClass)) +#define PANEL_IS_APPLET_FRAME_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_APPLET_FRAME_DBUS)) +#define PANEL_IS_APPLET_FRAME_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_APPLET_FRAME_DBUS)) +#define MATE_PANEL_APPLET_FRAME_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_APPLET_FRAME_DBUS, MatePanelAppletFrameDBusClass)) + +typedef struct _MatePanelAppletFrameDBus MatePanelAppletFrameDBus; +typedef struct _MatePanelAppletFrameDBusClass MatePanelAppletFrameDBusClass; +typedef struct _MatePanelAppletFrameDBusPrivate MatePanelAppletFrameDBusPrivate; + +struct _MatePanelAppletFrameDBusClass { + MatePanelAppletFrameClass parent_class; +}; + +struct _MatePanelAppletFrameDBus{ + MatePanelAppletFrame parent; + + MatePanelAppletFrameDBusPrivate *priv; +}; + +GType mate_panel_applet_frame_dbus_get_type (void) G_GNUC_CONST; + +gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, + MatePanelAppletFrameActivating *frame_act); + +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLET_FRAME_DBUS_H__ */ diff --git a/mate-panel/libmate-panel-applet-private/panel-applet-mini.c b/mate-panel/libmate-panel-applet-private/panel-applet-mini.c new file mode 100644 index 00000000..13112376 --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applet-mini.c @@ -0,0 +1,5 @@ +/* Symbols needed for libmate-panel-applet-private-mini, which is used by the test + * program */ +#include +gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, gpointer frame_act); +gboolean mate_panel_applet_frame_dbus_load (const gchar *iid, gpointer frame_act) { return FALSE; } diff --git a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c new file mode 100644 index 00000000..695f66fb --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c @@ -0,0 +1,603 @@ +/* + * panel-applets-manager-dbus.c + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include +#include +#include + +#include + +#include "panel-applet-frame-dbus.h" +#include "panel-applets-manager-dbus.h" + +G_DEFINE_TYPE_WITH_CODE (MatePanelAppletsManagerDBus, + mate_panel_applets_manager_dbus, + PANEL_TYPE_APPLETS_MANAGER, + g_io_extension_point_implement (MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME, + g_define_type_id, + "dbus", + 10)) + +struct _MatePanelAppletsManagerDBusPrivate +{ + GHashTable *applet_factories; + GList *monitors; +}; + +typedef gint (* ActivateAppletFunc) (void); + +typedef struct _MatePanelAppletFactoryInfo { + gchar *id; + gchar *location; + gboolean in_process; + GModule *module; + ActivateAppletFunc activate_applet; + guint n_applets; + + gchar *srcdir; + + GList *applet_list; + gboolean has_old_ids; +} MatePanelAppletFactoryInfo; + +#define MATE_PANEL_APPLET_FACTORY_GROUP "Applet Factory" +#define MATE_PANEL_APPLETS_EXTENSION ".mate-panel-applet" + +static void +mate_panel_applet_factory_info_free (MatePanelAppletFactoryInfo *info) +{ + if (!info) + return; + + g_free (info->id); + g_free (info->location); + g_list_foreach (info->applet_list, + (GFunc) mate_panel_applet_info_free, + NULL); + g_list_free (info->applet_list); + info->applet_list = NULL; + g_free (info->srcdir); + + g_slice_free (MatePanelAppletFactoryInfo, info); +} + +static MatePanelAppletInfo * +_mate_panel_applets_manager_get_applet_info (GKeyFile *applet_file, + const gchar *group, + const gchar *factory_id) +{ + MatePanelAppletInfo *info; + char *iid; + char *name; + char *comment; + char *icon; + char **old_ids; + + iid = g_strdup_printf ("%s::%s", factory_id, group); + name = g_key_file_get_locale_string (applet_file, group, + "Name", NULL, NULL); + comment = g_key_file_get_locale_string (applet_file, group, + "Description", NULL, NULL); + icon = g_key_file_get_string (applet_file, group, "Icon", NULL); + /* MateComponent compatibility */ + old_ids = g_key_file_get_string_list (applet_file, group, + "MateComponentId", NULL, NULL); + + info = mate_panel_applet_info_new (iid, name, comment, icon, (const char **) old_ids); + + g_free (iid); + g_free (name); + g_free (comment); + g_free (icon); + g_strfreev (old_ids); + + return info; +} + +static MatePanelAppletFactoryInfo * +mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filename) +{ + MatePanelAppletFactoryInfo *info; + GKeyFile *applet_file; + gchar **groups; + gsize n_groups; + gint i; + GError *error = NULL; + + applet_file = g_key_file_new (); + if (!g_key_file_load_from_file (applet_file, filename, G_KEY_FILE_NONE, &error)) { + g_warning ("Error opening panel applet file %s: %s", + filename, error->message); + g_error_free (error); + g_key_file_free (applet_file); + + return NULL; + } + + info = g_slice_new0 (MatePanelAppletFactoryInfo); + info->id = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, "Id", NULL); + if (!info->id) { + g_warning ("Bad panel applet file %s: Could not find 'Id' in group '%s'", + filename, MATE_PANEL_APPLET_FACTORY_GROUP); + mate_panel_applet_factory_info_free (info); + g_key_file_free (applet_file); + + return NULL; + } + + info->in_process = g_key_file_get_boolean (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, + "InProcess", NULL); + if (info->in_process) { + info->location = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, + "Location", NULL); + if (!info->location) { + g_warning ("Bad panel applet file %s: In-process applet without 'Location'", + filename); + mate_panel_applet_factory_info_free (info); + g_key_file_free (applet_file); + + return NULL; + } + } + + info->has_old_ids = FALSE; + + groups = g_key_file_get_groups (applet_file, &n_groups); + for (i = 0; i < n_groups; i++) { + MatePanelAppletInfo *ainfo; + + if (g_strcmp0 (groups[i], MATE_PANEL_APPLET_FACTORY_GROUP) == 0) + continue; + + ainfo = _mate_panel_applets_manager_get_applet_info (applet_file, + groups[i], info->id); + if (mate_panel_applet_info_get_old_ids (ainfo) != NULL) + info->has_old_ids = TRUE; + + info->applet_list = g_list_prepend (info->applet_list, ainfo); + } + g_strfreev (groups); + + g_key_file_free (applet_file); + + if (!info->applet_list) { + mate_panel_applet_factory_info_free (info); + return NULL; + } + + info->srcdir = g_path_get_dirname (filename); + + return info; +} + +static GSList * +mate_panel_applets_manager_get_applets_dirs (void) +{ + const gchar *dir = NULL; + gchar **paths; + guint i; + GSList *retval = NULL; + + dir = g_getenv ("MATE_PANEL_APPLETS_DIR"); + if (!dir || g_strcmp0 (dir, "") == 0) { + return g_slist_prepend (NULL, g_strdup (MATE_PANEL_APPLETS_DIR)); + } + + paths = g_strsplit (dir, ":", 0); + for (i = 0; paths[i]; i++) { + if (g_slist_find_custom (retval, paths[i], (GCompareFunc) g_strcmp0)) + continue; + retval = g_slist_prepend (retval, g_strdup (paths[i])); + } + g_strfreev (paths); + + return g_slist_reverse (retval); +} + +static void +applets_directory_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + MatePanelAppletsManagerDBus *manager = MATE_PANEL_APPLETS_MANAGER_DBUS (user_data); + + switch (event_type) { + case G_FILE_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_CREATED: { + MatePanelAppletFactoryInfo *info; + MatePanelAppletFactoryInfo *old_info; + gchar *filename; + GSList *dirs, *d; + + filename = g_file_get_path (file); + if (!g_str_has_suffix (filename, MATE_PANEL_APPLETS_EXTENSION)) { + g_free (filename); + return; + } + + info = mate_panel_applets_manager_get_applet_factory_info_from_file (filename); + g_free (filename); + + if (!info) + return; + + old_info = g_hash_table_lookup (manager->priv->applet_factories, info->id); + if (!old_info) { + /* New applet, just insert it */ + g_hash_table_insert (manager->priv->applet_factories, g_strdup (info->id), info); + return; + } + + /* Make sure we don't update an applet that has changed in + * another source dir unless it takes precedence over the + * current one */ + if (g_strcmp0 (info->srcdir, old_info->srcdir) == 0) { + g_hash_table_replace (manager->priv->applet_factories, g_strdup (info->id), info); + return; + } + + dirs = mate_panel_applets_manager_get_applets_dirs (); + + for (d = dirs; d; d = g_slist_next (d)) { + gchar *path = (gchar *) d->data; + + if (g_strcmp0 (path, old_info->srcdir) == 0) { + mate_panel_applet_factory_info_free (info); + break; + } else if (g_strcmp0 (path, info->srcdir) == 0) { + g_hash_table_replace (manager->priv->applet_factories, g_strdup (info->id), info); + break; + } + } + + g_slist_foreach (dirs, (GFunc) g_free, NULL); + g_slist_free (dirs); + } + break; + default: + /* Ignore any other change */ + break; + } +} + +static void +mate_panel_applets_manager_dbus_load_applet_infos (MatePanelAppletsManagerDBus *manager) +{ + GSList *dirs, *d; + GDir *dir; + const gchar *dirent; + GError *error = NULL; + + dirs = mate_panel_applets_manager_get_applets_dirs (); + for (d = dirs; d; d = g_slist_next (d)) { + GFileMonitor *monitor; + GFile *dir_file; + gchar *path = (gchar *) d->data; + + dir = g_dir_open (path, 0, &error); + if (!dir) { + g_warning ("%s", error->message); + g_error_free (error); + g_free (path); + + continue; + } + + /* Monitor dir */ + dir_file = g_file_new_for_path (path); + monitor = g_file_monitor_directory (dir_file, + G_FILE_MONITOR_NONE, + NULL, NULL); + if (monitor) { + g_signal_connect (monitor, "changed", + G_CALLBACK (applets_directory_changed), + manager); + manager->priv->monitors = g_list_prepend (manager->priv->monitors, monitor); + } + g_object_unref (dir_file); + + while ((dirent = g_dir_read_name (dir))) { + MatePanelAppletFactoryInfo *info; + gchar *file; + + if (!g_str_has_suffix (dirent, MATE_PANEL_APPLETS_EXTENSION)) + continue; + + file = g_build_filename (path, dirent, NULL); + info = mate_panel_applets_manager_get_applet_factory_info_from_file (file); + g_free (file); + + if (!info) + continue; + + if (g_hash_table_lookup (manager->priv->applet_factories, info->id)) { + mate_panel_applet_factory_info_free (info); + continue; + } + + g_hash_table_insert (manager->priv->applet_factories, g_strdup (info->id), info); + } + + g_dir_close (dir); + g_free (path); + } + + g_slist_free (dirs); +} + +static GList * +mate_panel_applets_manager_dbus_get_applets (MatePanelAppletsManager *manager) +{ + MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); + + GHashTableIter iter; + gpointer key, value; + GList *retval = NULL; + + g_hash_table_iter_init (&iter, dbus_manager->priv->applet_factories); + while (g_hash_table_iter_next (&iter, &key, &value)) { + MatePanelAppletFactoryInfo *info; + + info = (MatePanelAppletFactoryInfo *) value; + retval = g_list_concat (retval, g_list_copy (info->applet_list)); + } + + return retval; +} + +static MatePanelAppletFactoryInfo * +get_applet_factory_info (MatePanelAppletsManager *manager, + const gchar *iid) +{ + MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); + + MatePanelAppletFactoryInfo *info; + const gchar *sp; + gchar *factory_id; + + sp = g_strrstr (iid, "::"); + if (!sp) + return NULL; + + factory_id = g_strndup (iid, strlen (iid) - strlen (sp)); + info = g_hash_table_lookup (dbus_manager->priv->applet_factories, factory_id); + g_free (factory_id); + + return info; +} + +static gboolean +mate_panel_applets_manager_dbus_factory_activate (MatePanelAppletsManager *manager, + const gchar *iid) +{ + MatePanelAppletFactoryInfo *info; + ActivateAppletFunc activate_applet; + + info = get_applet_factory_info (manager, iid); + if (!info) + return FALSE; + + /* Out-of-process applets are activated by the session bus */ + if (!info->in_process) + return TRUE; + + if (info->module) { + if (info->n_applets == 0) { + if (info->activate_applet () != 0) { + g_warning ("Failed to reactivate factory %s\n", iid); + return FALSE; + } + } + info->n_applets++; + + return TRUE; + } + + info->module = g_module_open (info->location, G_MODULE_BIND_LAZY); + if (!info->module) { + /* FIXME: use a GError? */ + g_warning ("Failed to load applet %s: %s\n", + iid, g_module_error ()); + return FALSE; + } + + if (!g_module_symbol (info->module, "_mate_panel_applet_shlib_factory", (gpointer *) &activate_applet)) { + /* FIXME: use a GError? */ + g_warning ("Failed to load applet %s: %s\n", + iid, g_module_error ()); + g_module_close (info->module); + info->module = NULL; + + return FALSE; + } + + /* Activate the applet */ + if (activate_applet () != 0) { + /* FIXME: use a GError? */ + g_warning ("Failed to load applet %s\n", iid); + g_module_close (info->module); + info->module = NULL; + + return FALSE; + } + info->activate_applet = activate_applet; + + info->n_applets = 1; + + return TRUE; +} + +static gboolean +mate_panel_applets_manager_dbus_factory_deactivate (MatePanelAppletsManager *manager, + const gchar *iid) +{ + MatePanelAppletFactoryInfo *info; + + info = get_applet_factory_info (manager, iid); + if (!info) + return FALSE; + + /* Out-of-process applets are deactivated by the session bus */ + if (!info->in_process) + return TRUE; + + if (!info->module) + return TRUE; + + info->n_applets--; + if (info->n_applets == 0) { + /* FIXME: we should close the module here, however applet types + * are registered static */ +#if 0 + g_module_close (info->module); + info->module = NULL; +#endif + } + + return TRUE; +} + +static MatePanelAppletInfo * +mate_panel_applets_manager_dbus_get_applet_info (MatePanelAppletsManager *manager, + const gchar *iid) +{ + MatePanelAppletFactoryInfo *info; + GList *l; + + info = get_applet_factory_info (manager, iid); + if (!info) + return NULL; + + for (l = info->applet_list; l; l = g_list_next (l)) { + MatePanelAppletInfo *ainfo = (MatePanelAppletInfo *) l->data; + + if (g_strcmp0 (mate_panel_applet_info_get_iid (ainfo), iid) == 0) + return ainfo; + } + + return NULL; +} + +static MatePanelAppletInfo * +mate_panel_applets_manager_dbus_get_applet_info_from_old_id (MatePanelAppletsManager *manager, + const gchar *iid) +{ + MatePanelAppletsManagerDBus *dbus_manager = MATE_PANEL_APPLETS_MANAGER_DBUS (manager); + + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, dbus_manager->priv->applet_factories); + while (g_hash_table_iter_next (&iter, &key, &value)) { + MatePanelAppletFactoryInfo *info; + GList *l; + + info = (MatePanelAppletFactoryInfo *) value; + if (!info->has_old_ids) + continue; + + for (l = info->applet_list; l; l = g_list_next (l)) { + MatePanelAppletInfo *ainfo; + gint i = 0; + const gchar * const *old_ids; + + ainfo = (MatePanelAppletInfo *) l->data; + + old_ids = mate_panel_applet_info_get_old_ids (ainfo); + + if (old_ids == NULL) + continue; + + while (old_ids[i]) { + if (g_strcmp0 (old_ids[i], iid) == 0) + return ainfo; + i++; + } + } + } + + return NULL; +} + +static gboolean +mate_panel_applets_manager_dbus_load_applet (MatePanelAppletsManager *manager, + const gchar *iid, + MatePanelAppletFrameActivating *frame_act) +{ + return mate_panel_applet_frame_dbus_load (iid, frame_act); +} + +static void +mate_panel_applets_manager_dbus_finalize (GObject *object) +{ + MatePanelAppletsManagerDBus *manager = MATE_PANEL_APPLETS_MANAGER_DBUS (object); + + if (manager->priv->monitors) { + g_list_foreach (manager->priv->monitors, (GFunc) g_object_unref, NULL); + g_list_free (manager->priv->monitors); + manager->priv->monitors = NULL; + } + + if (manager->priv->applet_factories) { + g_hash_table_destroy (manager->priv->applet_factories); + manager->priv->applet_factories = NULL; + } + + G_OBJECT_CLASS (mate_panel_applets_manager_dbus_parent_class)->finalize (object); +} + +static void +mate_panel_applets_manager_dbus_init (MatePanelAppletsManagerDBus *manager) +{ + manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, + PANEL_TYPE_APPLETS_MANAGER_DBUS, + MatePanelAppletsManagerDBusPrivate); + + manager->priv->applet_factories = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) mate_panel_applet_factory_info_free); + + mate_panel_applets_manager_dbus_load_applet_infos (manager); +} + +static void +mate_panel_applets_manager_dbus_class_init (MatePanelAppletsManagerDBusClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + MatePanelAppletsManagerClass *manager_class = MATE_PANEL_APPLETS_MANAGER_CLASS (class); + + gobject_class->finalize = mate_panel_applets_manager_dbus_finalize; + + manager_class->get_applets = mate_panel_applets_manager_dbus_get_applets; + manager_class->factory_activate = mate_panel_applets_manager_dbus_factory_activate; + manager_class->factory_deactivate = mate_panel_applets_manager_dbus_factory_deactivate; + manager_class->get_applet_info = mate_panel_applets_manager_dbus_get_applet_info; + manager_class->get_applet_info_from_old_id = mate_panel_applets_manager_dbus_get_applet_info_from_old_id; + manager_class->load_applet = mate_panel_applets_manager_dbus_load_applet; + + g_type_class_add_private (class, sizeof (MatePanelAppletsManagerDBusPrivate)); +} diff --git a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.h b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.h new file mode 100644 index 00000000..85ab5c53 --- /dev/null +++ b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.h @@ -0,0 +1,60 @@ +/* + * panel-applets-manager-dbus.h + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __PANEL_APPLETS_MANAGER_DBUS_H__ +#define __PANEL_APPLETS_MANAGER_DBUS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PANEL_TYPE_APPLETS_MANAGER_DBUS (mate_panel_applets_manager_dbus_get_type ()) +#define MATE_PANEL_APPLETS_MANAGER_DBUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBus)) +#define MATE_PANEL_APPLETS_MANAGER_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBusClass)) +#define PANEL_IS_APPLETS_MANAGER_DBUS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS)) +#define PANEL_IS_APPLETS_MANAGER_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLETS_MANAGER_DBUS)) +#define MATE_PANEL_APPLETS_MANAGER_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_APPLETS_MANAGER_DBUS, MatePanelAppletsManagerDBusClass)) + +typedef struct _MatePanelAppletsManagerDBus MatePanelAppletsManagerDBus; +typedef struct _MatePanelAppletsManagerDBusClass MatePanelAppletsManagerDBusClass; +typedef struct _MatePanelAppletsManagerDBusPrivate MatePanelAppletsManagerDBusPrivate; + +struct _MatePanelAppletsManagerDBusClass { + MatePanelAppletsManagerClass parent_class; +}; + +struct _MatePanelAppletsManagerDBus { + MatePanelAppletsManager parent; + + /*< private > */ + MatePanelAppletsManagerDBusPrivate *priv; +}; + +GType mate_panel_applets_manager_dbus_get_type (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLETS_MANAGER_DBUS_H__ */ diff --git a/mate-panel/mate-panel-applet-frame.c b/mate-panel/mate-panel-applet-frame.c deleted file mode 100644 index e1115435..00000000 --- a/mate-panel/mate-panel-applet-frame.c +++ /dev/null @@ -1,1193 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * mate-panel-applet-frame.c: panel side container for applets - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * Authors: - * Mark McLoughlin - */ - -#include -#include - -#include - -#include -#include -#include - -#include "mate-panel-applets-manager.h" -#include "panel-profile.h" -#include "panel.h" -#include "applet.h" -#include "panel-marshal.h" -#include "panel-background.h" -#include "panel-lockdown.h" -#include "panel-stock-icons.h" -#include "xstuff.h" -#include "panel-schemas.h" - -#include "mate-panel-applet-frame.h" - -#define PANEL_RESPONSE_DELETE 0 -#define PANEL_RESPONSE_DONT_RELOAD 1 -#define PANEL_RESPONSE_RELOAD 2 - -static void mate_panel_applet_frame_activating_free (MatePanelAppletFrameActivating *frame_act); - -static void mate_panel_applet_frame_loading_failed (const char *iid, - PanelWidget *panel, - const char *id); - -static void mate_panel_applet_frame_load (const gchar *iid, - PanelWidget *panel, - gboolean locked, - int position, - gboolean exactpos, - const char *id); - -struct _MatePanelAppletFrameActivating { - gboolean locked; - PanelWidget *panel; - int position; - gboolean exactpos; - char *id; -}; - -/* MatePanelAppletFrame implementation */ - -G_DEFINE_TYPE (MatePanelAppletFrame, mate_panel_applet_frame, GTK_TYPE_EVENT_BOX) - -#define MATE_PANEL_APPLET_FRAME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFramePrivate)) - -#define HANDLE_SIZE 10 -#define MATE_PANEL_APPLET_PREFS_PATH "/org/mate/panel/objects/%s/prefs/" - -struct _MatePanelAppletFramePrivate { - PanelWidget *panel; - AppletInfo *applet_info; - - PanelOrientation orientation; - - gchar *iid; - - GtkAllocation child_allocation; - GdkRectangle handle_rect; - - guint has_handle : 1; -}; - -#if GTK_CHECK_VERSION (3, 0, 0) -static gboolean -mate_panel_applet_frame_draw (GtkWidget *widget, - cairo_t *cr) -{ - MatePanelAppletFrame *frame = MATE_PANEL_APPLET_FRAME (widget); - GtkStyleContext *context; - GtkStateFlags state; - cairo_pattern_t *bg_pattern; - PanelBackground *background; - - if (GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->draw) - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->draw (widget, cr); - - if (!frame->priv->has_handle) - return FALSE; - - context = gtk_widget_get_style_context (widget); - state = gtk_widget_get_state_flags (widget); - gtk_style_context_save (context); - gtk_style_context_set_state (context, state); - - cairo_save (cr); - - /* Set the pattern transform so as to correctly render a patterned - * background with the handle */ - gtk_style_context_get (context, state, - "background-image", &bg_pattern, - NULL); - background = &frame->priv->panel->background; - - if (bg_pattern && (background->type == PANEL_BACK_IMAGE || - (background->type == PANEL_BACK_COLOR && background->has_alpha))) { - cairo_matrix_t ptm; - - cairo_matrix_init_translate (&ptm, - frame->priv->handle_rect.x, - frame->priv->handle_rect.y); - cairo_matrix_scale (&ptm, - frame->priv->handle_rect.width, - frame->priv->handle_rect.height); - cairo_pattern_set_matrix (bg_pattern, &ptm); - cairo_pattern_destroy (bg_pattern); - } - - cairo_rectangle (cr, - frame->priv->handle_rect.x, - frame->priv->handle_rect.y, - frame->priv->handle_rect.width, - frame->priv->handle_rect.height); - cairo_clip (cr); - gtk_render_handle (context, cr, - 0, 0, - gtk_widget_get_allocated_width (widget), - gtk_widget_get_allocated_height (widget)); - - cairo_restore (cr); - - gtk_style_context_restore (context); - - return FALSE; -} -#else -static void -mate_panel_applet_frame_paint (GtkWidget *widget, - GdkRectangle *area) -{ - MatePanelAppletFrame *frame; - - frame = MATE_PANEL_APPLET_FRAME (widget); - - if (!frame->priv->has_handle) - return; - - if (gtk_widget_is_drawable (widget)) { - GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; - - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - orientation = GTK_ORIENTATION_VERTICAL; - break; - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - orientation = GTK_ORIENTATION_HORIZONTAL; - break; - default: - g_assert_not_reached (); - break; - } - - gtk_paint_handle ( - gtk_widget_get_style (widget), gtk_widget_get_window (widget), - gtk_widget_get_state (widget), - GTK_SHADOW_OUT, - area, widget, "handlebox", - frame->priv->handle_rect.x, - frame->priv->handle_rect.y, - frame->priv->handle_rect.width, - frame->priv->handle_rect.height, - orientation); - } -} - -static gboolean mate_panel_applet_frame_expose(GtkWidget* widget, GdkEventExpose* event) -{ - if (gtk_widget_is_drawable (widget)) - { - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->expose_event (widget, event); - - mate_panel_applet_frame_paint (widget, &event->area); - } - - return FALSE; -} -#endif - -static void -mate_panel_applet_frame_update_background_size (MatePanelAppletFrame *frame, - GtkAllocation *old_allocation, - GtkAllocation *new_allocation) -{ - PanelBackground *background; - - if (old_allocation->x == new_allocation->x && - old_allocation->y == new_allocation->y && - old_allocation->width == new_allocation->width && - old_allocation->height == new_allocation->height) - return; - - background = &frame->priv->panel->background; - - if (background->type == PANEL_BACK_NONE || - (background->type == PANEL_BACK_COLOR && !background->has_alpha)) - return; - - mate_panel_applet_frame_change_background (frame, background->type); -} - -#if GTK_CHECK_VERSION (3, 0, 0) -static void -mate_panel_applet_frame_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) -{ - MatePanelAppletFrame *frame; - GtkBin *bin; - GtkWidget *child; - guint border_width; - - frame = MATE_PANEL_APPLET_FRAME (widget); - bin = GTK_BIN (widget); - - if (!frame->priv->has_handle) { - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->get_preferred_width (widget, minimal_width, natural_width); - return; - } - - child = gtk_bin_get_child (bin); - if (child && gtk_widget_get_visible (child)) - gtk_widget_get_preferred_width (child, minimal_width, natural_width); - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - *minimal_width += border_width; - *natural_width += border_width; - - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - *minimal_width += HANDLE_SIZE; - *natural_width += HANDLE_SIZE; - break; - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -mate_panel_applet_frame_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height) -{ - MatePanelAppletFrame *frame; - GtkBin *bin; - GtkWidget *child; - guint border_width; - - frame = MATE_PANEL_APPLET_FRAME (widget); - bin = GTK_BIN (widget); - - if (!frame->priv->has_handle) { - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->get_preferred_height (widget, minimal_height, natural_height); - return; - } - - child = gtk_bin_get_child (bin); - if (child && gtk_widget_get_visible (child)) - gtk_widget_get_preferred_height (child, minimal_height, natural_height); - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - *minimal_height += border_width; - *natural_height += border_width; - - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - *minimal_height += HANDLE_SIZE; - *natural_height += HANDLE_SIZE; - break; - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - break; - default: - g_assert_not_reached (); - break; - } -} -#else -static void -mate_panel_applet_frame_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - MatePanelAppletFrame *frame; - GtkBin *bin; - GtkWidget *child; - GtkRequisition child_requisition; - guint border_width; - - frame = MATE_PANEL_APPLET_FRAME (widget); - bin = GTK_BIN (widget); - - if (!frame->priv->has_handle) { - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->size_request (widget, requisition); - return; - } - - child = gtk_bin_get_child (bin); - if (child && gtk_widget_get_visible (child)) { - gtk_widget_size_request (child, &child_requisition); - - requisition->width = child_requisition.width; - requisition->height = child_requisition.height; - } - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - requisition->width += border_width; - requisition->height += border_width; - - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - requisition->width += HANDLE_SIZE; - break; - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - requisition->height += HANDLE_SIZE; - break; - default: - g_assert_not_reached (); - break; - } -} -#endif - -static void -mate_panel_applet_frame_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - MatePanelAppletFrame *frame; - GtkBin *bin; - GtkWidget *child; - GdkWindow *window; - GtkAllocation new_allocation; - GtkAllocation old_allocation; - GtkAllocation widget_allocation; - - gtk_widget_get_allocation (widget, &widget_allocation); - - old_allocation.x = widget_allocation.x; - old_allocation.y = widget_allocation.y; - old_allocation.width = widget_allocation.width; - old_allocation.height = widget_allocation.height; - - frame = MATE_PANEL_APPLET_FRAME (widget); - bin = GTK_BIN (widget); - - if (!frame->priv->has_handle) { - GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->size_allocate (widget, allocation); - mate_panel_applet_frame_update_background_size (frame, &old_allocation, allocation); - return; - } - - window = gtk_widget_get_window (widget); - child = gtk_bin_get_child (bin); - gtk_widget_set_allocation (widget, allocation); - - frame->priv->handle_rect.x = 0; - frame->priv->handle_rect.y = 0; - - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - frame->priv->handle_rect.width = HANDLE_SIZE; - frame->priv->handle_rect.height = allocation->height; - - if (gtk_widget_get_direction (GTK_WIDGET (frame)) != - GTK_TEXT_DIR_RTL) { - frame->priv->handle_rect.x = 0; - new_allocation.x = HANDLE_SIZE; - } else { - frame->priv->handle_rect.x = allocation->width - HANDLE_SIZE; - new_allocation.x = 0; - } - - new_allocation.y = 0; - new_allocation.width = allocation->width - HANDLE_SIZE; - new_allocation.height = allocation->height; - break; - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - frame->priv->handle_rect.width = allocation->width; - frame->priv->handle_rect.height = HANDLE_SIZE; - - new_allocation.x = 0; - new_allocation.y = HANDLE_SIZE; - new_allocation.width = allocation->width; - new_allocation.height = allocation->height - HANDLE_SIZE; - break; - default: - g_assert_not_reached (); - break; - } - - new_allocation.width = MAX (1, new_allocation.width); - new_allocation.height = MAX (1, new_allocation.height); - - /* If the child allocation changed, that means that the frame is drawn - * in a new place, so we must redraw the entire widget. - */ - if (gtk_widget_get_mapped (widget) && - (new_allocation.x != frame->priv->child_allocation.x || - new_allocation.y != frame->priv->child_allocation.y || - new_allocation.width != frame->priv->child_allocation.width || - new_allocation.height != frame->priv->child_allocation.height)) - gdk_window_invalidate_rect (window, &widget_allocation, FALSE); - - if (gtk_widget_get_realized (widget)) { - guint border_width; - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - gdk_window_move_resize (window, - allocation->x + border_width, - allocation->y + border_width, - MAX (allocation->width - border_width * 2, 0), - MAX (allocation->height - border_width * 2, 0)); - } - - if (child && gtk_widget_get_visible (child)) - gtk_widget_size_allocate (child, &new_allocation); - - frame->priv->child_allocation = new_allocation; - - mate_panel_applet_frame_update_background_size (frame, - &old_allocation, - allocation); -} - -static inline gboolean -button_event_in_rect (GdkEventButton *event, - GdkRectangle *rect) -{ - if (event->x >= rect->x && - event->x <= (rect->x + rect->width) && - event->y >= rect->y && - event->y <= (rect->y + rect->height)) - return TRUE; - - return FALSE; -} - -static gboolean -mate_panel_applet_frame_button_changed (GtkWidget *widget, - GdkEventButton *event) -{ - MatePanelAppletFrame *frame; - gboolean handled = FALSE; -#if GTK_CHECK_VERSION (3, 0, 0) - GdkDisplay *display; - GdkDevice *pointer; - GdkDeviceManager *device_manager; -#endif - - frame = MATE_PANEL_APPLET_FRAME (widget); - - if (!frame->priv->has_handle) - return handled; - - if (event->window != gtk_widget_get_window (widget)) - return FALSE; - - switch (event->button) { - case 1: - case 2: - if (button_event_in_rect (event, &frame->priv->handle_rect)) { - if (event->type == GDK_BUTTON_PRESS || - event->type == GDK_2BUTTON_PRESS) { - panel_widget_applet_drag_start ( - frame->priv->panel, GTK_WIDGET (frame), - PW_DRAG_OFF_CURSOR, event->time); - handled = TRUE; - } else if (event->type == GDK_BUTTON_RELEASE) { - panel_widget_applet_drag_end (frame->priv->panel); - handled = TRUE; - } - } - break; - case 3: - if (event->type == GDK_BUTTON_PRESS || - event->type == GDK_2BUTTON_PRESS) { -#if GTK_CHECK_VERSION (3, 0, 0) - display = gtk_widget_get_display (widget); - device_manager = gdk_display_get_device_manager (display); - pointer = gdk_device_manager_get_client_pointer (device_manager); - gdk_device_ungrab (pointer, GDK_CURRENT_TIME); -#endif - gdk_pointer_ungrab (GDK_CURRENT_TIME); - - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_menu (frame, - event->button, - event->time); - - handled = TRUE; - } else if (event->type == GDK_BUTTON_RELEASE) - handled = TRUE; - break; - default: - break; - } - - return handled; -} - -static void -mate_panel_applet_frame_finalize (GObject *object) -{ - MatePanelAppletFrame *frame = MATE_PANEL_APPLET_FRAME (object); - - mate_panel_applets_manager_factory_deactivate (frame->priv->iid); - - panel_lockdown_notify_remove (G_CALLBACK (mate_panel_applet_frame_sync_menu_state), - frame); - - g_free (frame->priv->iid); - frame->priv->iid = NULL; - - G_OBJECT_CLASS (mate_panel_applet_frame_parent_class)->finalize (object); -} - -static void -mate_panel_applet_frame_class_init (MatePanelAppletFrameClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; - - gobject_class->finalize = mate_panel_applet_frame_finalize; - -#if GTK_CHECK_VERSION (3, 0, 0) - widget_class->draw = mate_panel_applet_frame_draw; - widget_class->get_preferred_width = mate_panel_applet_frame_get_preferred_width; - widget_class->get_preferred_height = mate_panel_applet_frame_get_preferred_height; -#else - widget_class->expose_event = mate_panel_applet_frame_expose; - widget_class->size_request = mate_panel_applet_frame_size_request; -#endif - widget_class->size_allocate = mate_panel_applet_frame_size_allocate; - widget_class->button_press_event = mate_panel_applet_frame_button_changed; - widget_class->button_release_event = mate_panel_applet_frame_button_changed; - - g_type_class_add_private (klass, sizeof (MatePanelAppletFramePrivate)); -} - -static void -mate_panel_applet_frame_init (MatePanelAppletFrame *frame) -{ - frame->priv = MATE_PANEL_APPLET_FRAME_GET_PRIVATE (frame); - - frame->priv->panel = NULL; - frame->priv->orientation = PANEL_ORIENTATION_TOP; - frame->priv->applet_info = NULL; - frame->priv->has_handle = FALSE; -} - -static void -mate_panel_applet_frame_init_properties (MatePanelAppletFrame *frame) -{ - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->init_properties (frame); -} - -void -mate_panel_applet_frame_sync_menu_state (MatePanelAppletFrame *frame) -{ - PanelWidget *panel_widget; - gboolean locked_down; - gboolean locked; - gboolean lockable; - gboolean movable; - gboolean removable; - - panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))); - - movable = mate_panel_applet_can_freely_move (frame->priv->applet_info); - removable = panel_profile_id_lists_are_writable (); - lockable = mate_panel_applet_lockable (frame->priv->applet_info); - - locked = panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame)); - locked_down = panel_lockdown_get_locked_down (); - - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->sync_menu_state (frame, movable, removable, lockable, locked, locked_down); -} - -void -mate_panel_applet_frame_change_orientation (MatePanelAppletFrame *frame, - PanelOrientation orientation) -{ - if (orientation == frame->priv->orientation) - return; - - frame->priv->orientation = orientation; - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_orientation (frame, orientation); -} - -void -mate_panel_applet_frame_change_size (MatePanelAppletFrame *frame, - guint size) -{ - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_size (frame, size); -} - -void -mate_panel_applet_frame_change_background (MatePanelAppletFrame *frame, - PanelBackgroundType type) -{ - GtkWidget *parent; - - g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); - - parent = gtk_widget_get_parent (GTK_WIDGET (frame)); - - g_return_if_fail (PANEL_IS_WIDGET (parent)); - - if (frame->priv->has_handle) { - PanelBackground *background; - - background = &PANEL_WIDGET (parent)->background; -#if GTK_CHECK_VERSION (3, 0, 0) - panel_background_apply_css (background, GTK_WIDGET (frame)); -#else - panel_background_change_background_on_widget (background, - GTK_WIDGET (frame)); -#endif - } - - MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_background (frame, type); -} - -void -mate_panel_applet_frame_set_panel (MatePanelAppletFrame *frame, - PanelWidget *panel) -{ - g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); - g_return_if_fail (PANEL_IS_WIDGET (panel)); - - frame->priv->panel = panel; -} - -void -_mate_panel_applet_frame_set_iid (MatePanelAppletFrame *frame, - const gchar *iid) -{ - if (frame->priv->iid) - g_free (frame->priv->iid); - frame->priv->iid = g_strdup (iid); -} - -void -_mate_panel_applet_frame_activated (MatePanelAppletFrame *frame, - MatePanelAppletFrameActivating *frame_act, - GError *error) -{ - AppletInfo *info; - - g_assert (frame->priv->iid != NULL); - - if (error != NULL) { - g_warning ("Failed to load applet %s:\n%s", - frame->priv->iid, error->message); - g_error_free (error); - - mate_panel_applet_frame_loading_failed (frame->priv->iid, - frame_act->panel, - frame_act->id); - mate_panel_applet_frame_activating_free (frame_act); - gtk_widget_destroy (GTK_WIDGET (frame)); - - return; - } - - frame->priv->panel = frame_act->panel; - gtk_widget_show_all (GTK_WIDGET (frame)); - - info = mate_panel_applet_register (GTK_WIDGET (frame), GTK_WIDGET (frame), - NULL, frame->priv->panel, - frame_act->locked, frame_act->position, - frame_act->exactpos, PANEL_OBJECT_APPLET, - frame_act->id); - frame->priv->applet_info = info; - - panel_widget_set_applet_size_constrained (frame->priv->panel, - GTK_WIDGET (frame), TRUE); - - mate_panel_applet_frame_sync_menu_state (frame); - mate_panel_applet_frame_init_properties (frame); - - panel_lockdown_notify_add (G_CALLBACK (mate_panel_applet_frame_sync_menu_state), - frame); - - mate_panel_applet_stop_loading (frame_act->id); - mate_panel_applet_frame_activating_free (frame_act); -} - -void -_mate_panel_applet_frame_update_flags (MatePanelAppletFrame *frame, - gboolean major, - gboolean minor, - gboolean has_handle) -{ - gboolean old_has_handle; - - panel_widget_set_applet_expandable ( - frame->priv->panel, GTK_WIDGET (frame), major, minor); - - old_has_handle = frame->priv->has_handle; - frame->priv->has_handle = has_handle; - - if (!old_has_handle && frame->priv->has_handle) { - /* we've added an handle, so we need to get the background for - * it */ - PanelBackground *background; - - background = &frame->priv->panel->background; - mate_panel_applet_frame_change_background (frame, background->type); - } -} - -void -_mate_panel_applet_frame_update_size_hints (MatePanelAppletFrame *frame, - gint *size_hints, - guint n_elements) -{ - if (frame->priv->has_handle) { - gint extra_size = HANDLE_SIZE + 1; - gint i; - - for (i = 0; i < n_elements; i++) - size_hints[i] += extra_size; - } - - /* It takes the ownership of size-hints array */ - panel_widget_set_applet_size_hints (frame->priv->panel, - GTK_WIDGET (frame), - size_hints, - n_elements); -} - -char * -_mate_panel_applet_frame_get_background_string (MatePanelAppletFrame *frame, - PanelWidget *panel, - PanelBackgroundType type) -{ - GtkAllocation allocation; - int x; - int y; - - gtk_widget_get_allocation (GTK_WIDGET (frame), &allocation); - - x = allocation.x; - y = allocation.y; - - if (frame->priv->has_handle) { - switch (frame->priv->orientation) { - case PANEL_ORIENTATION_TOP: - case PANEL_ORIENTATION_BOTTOM: - if (gtk_widget_get_direction (GTK_WIDGET (frame)) != - GTK_TEXT_DIR_RTL) - x += frame->priv->handle_rect.width; - break; - case PANEL_ORIENTATION_LEFT: - case PANEL_ORIENTATION_RIGHT: - y += frame->priv->handle_rect.height; - break; - default: - g_assert_not_reached (); - break; - } - } - - return panel_background_make_string (&panel->background, x, y); -} - -static void -mate_panel_applet_frame_reload_response (GtkWidget *dialog, - int response, - MatePanelAppletFrame *frame) -{ - AppletInfo *info; - - g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); - - if (!frame->priv->iid || !frame->priv->panel) { - g_object_unref (frame); - gtk_widget_destroy (dialog); - return; - } - - info = frame->priv->applet_info; - - if (response == PANEL_RESPONSE_RELOAD) { - PanelWidget *panel; - char *iid; - char *id = NULL; - int position = -1; - gboolean locked = FALSE; - - panel = frame->priv->panel; - iid = g_strdup (frame->priv->iid); - - if (info) { - id = g_strdup (info->id); - position = mate_panel_applet_get_position (info); - locked = panel_widget_get_applet_locked (panel, info->widget); - mate_panel_applet_clean (info); - } - - mate_panel_applet_frame_load (iid, panel, locked, - position, TRUE, id); - - g_free (iid); - g_free (id); - - } else if (response == PANEL_RESPONSE_DELETE) { - /* if we can't write to applets list we can't really delete - it, so we'll just ignore this. FIXME: handle this - more correctly I suppose. */ - if (panel_profile_id_lists_are_writable () && info) - panel_profile_delete_object (info); - } - - g_object_unref (frame); - gtk_widget_destroy (dialog); -} - -void -_mate_panel_applet_frame_applet_broken (MatePanelAppletFrame *frame) -{ - GtkWidget *dialog; - GdkScreen *screen; - const char *applet_name = NULL; - char *dialog_txt; - - screen = gtk_widget_get_screen (GTK_WIDGET (frame)); - - if (xstuff_is_display_dead ()) - return; - - if (frame->priv->iid) { - MatePanelAppletInfo *info; - - info = (MatePanelAppletInfo *)mate_panel_applets_manager_get_applet_info (frame->priv->iid); - applet_name = mate_panel_applet_info_get_name (info); - } - - if (applet_name) - dialog_txt = g_strdup_printf (_("\"%s\" has quit unexpectedly"), applet_name); - else - dialog_txt = g_strdup (_("Panel object has quit unexpectedly")); - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, - dialog_txt, applet_name ? applet_name : NULL); - - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("If you reload a panel object, it will automatically " - "be added back to the panel.")); - - gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); - - if (panel_profile_id_lists_are_writable ()) { - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - _("D_elete"), PANEL_RESPONSE_DELETE, - _("_Don't Reload"), PANEL_RESPONSE_DONT_RELOAD, - _("_Reload"), PANEL_RESPONSE_RELOAD, - NULL); - } else { - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - _("_Don't Reload"), PANEL_RESPONSE_DONT_RELOAD, - _("_Reload"), PANEL_RESPONSE_RELOAD, - NULL); - } - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), - PANEL_RESPONSE_RELOAD); - - gtk_window_set_screen (GTK_WINDOW (dialog), screen); - - g_signal_connect (dialog, "response", - G_CALLBACK (mate_panel_applet_frame_reload_response), - g_object_ref (frame)); - - panel_widget_register_open_dialog (frame->priv->panel, dialog); - gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); - /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */ - gtk_window_set_title (GTK_WINDOW (dialog), _("Error")); - - gtk_widget_show (dialog); - g_free (dialog_txt); -} - -void -_mate_panel_applet_frame_applet_remove (MatePanelAppletFrame *frame) -{ - AppletInfo *info; - - if (!frame->priv->applet_info) - return; - - info = frame->priv->applet_info; - frame->priv->applet_info = NULL; - - panel_profile_delete_object (info); -} - -void -_mate_panel_applet_frame_applet_move (MatePanelAppletFrame *frame) -{ - GtkWidget *widget = GTK_WIDGET (frame); - GtkWidget *parent = gtk_widget_get_parent (widget); - - if (!PANEL_IS_WIDGET (parent)) - return; - - panel_widget_applet_drag_start (PANEL_WIDGET (parent), - widget, - PW_DRAG_OFF_CENTER, - GDK_CURRENT_TIME); -} - -void -_mate_panel_applet_frame_applet_lock (MatePanelAppletFrame *frame, - gboolean locked) -{ - PanelWidget *panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))); - - if (panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame)) == locked) - return; - - mate_panel_applet_toggle_locked (frame->priv->applet_info); -} - -/* Generic methods */ - -static GSList *no_reload_applets = NULL; - -enum { - LOADING_FAILED_RESPONSE_DONT_DELETE, - LOADING_FAILED_RESPONSE_DELETE -}; - -static void -mate_panel_applet_frame_activating_free (MatePanelAppletFrameActivating *frame_act) -{ - g_free (frame_act->id); - g_slice_free (MatePanelAppletFrameActivating, frame_act); -} - -GdkScreen * -panel_applet_frame_activating_get_screen (MatePanelAppletFrameActivating *frame_act) -{ - return gtk_widget_get_screen (GTK_WIDGET(frame_act->panel)); -} - -PanelOrientation -mate_panel_applet_frame_activating_get_orientation(MatePanelAppletFrameActivating *frame_act) -{ - return panel_widget_get_applet_orientation(frame_act->panel); -} - -guint32 -mate_panel_applet_frame_activating_get_size (MatePanelAppletFrameActivating *frame_act) -{ - return frame_act->panel->sz; -} - -gboolean -mate_panel_applet_frame_activating_get_locked (MatePanelAppletFrameActivating *frame_act) -{ - return frame_act->locked; -} - -gboolean -mate_panel_applet_frame_activating_get_locked_down (MatePanelAppletFrameActivating *frame_act) -{ - return panel_lockdown_get_locked_down (); -} - -gchar * -mate_panel_applet_frame_activating_get_conf_path (MatePanelAppletFrameActivating *frame_act) -{ - return g_strdup_printf (MATE_PANEL_APPLET_PREFS_PATH, frame_act->id); -} - -static void -mate_panel_applet_frame_loading_failed_response (GtkWidget *dialog, - guint response, - char *id) -{ - gtk_widget_destroy (dialog); - - if (response == LOADING_FAILED_RESPONSE_DELETE && - !panel_lockdown_get_locked_down () && - panel_profile_id_lists_are_writable ()) { - GSList *item; - - item = g_slist_find_custom (no_reload_applets, id, - (GCompareFunc) strcmp); - if (item) { - g_free (item->data); - no_reload_applets = g_slist_delete_link (no_reload_applets, - item); - } - - panel_profile_remove_from_list (PANEL_GSETTINGS_OBJECTS, id); - } - - g_free (id); -} - -static void -mate_panel_applet_frame_loading_failed (const char *iid, - PanelWidget *panel, - const char *id) -{ - GtkWidget *dialog; - char *problem_txt; - gboolean locked_down; - - no_reload_applets = g_slist_prepend (no_reload_applets, - g_strdup (id)); - - locked_down = panel_lockdown_get_locked_down (); - - problem_txt = g_strdup_printf (_("The panel encountered a problem " - "while loading \"%s\"."), - iid); - - dialog = gtk_message_dialog_new (NULL, 0, - locked_down ? GTK_MESSAGE_INFO : GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - "%s", problem_txt); - g_free (problem_txt); - - if (locked_down) { - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - GTK_STOCK_OK, LOADING_FAILED_RESPONSE_DONT_DELETE, - NULL); - } else { - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Do you want to delete the applet " - "from your configuration?")); - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - PANEL_STOCK_DONT_DELETE, LOADING_FAILED_RESPONSE_DONT_DELETE, - GTK_STOCK_DELETE, LOADING_FAILED_RESPONSE_DELETE, - NULL); - } - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), - LOADING_FAILED_RESPONSE_DONT_DELETE); - - gtk_window_set_screen (GTK_WINDOW (dialog), - gtk_window_get_screen (GTK_WINDOW (panel->toplevel))); - - g_signal_connect (dialog, "response", - G_CALLBACK (mate_panel_applet_frame_loading_failed_response), - g_strdup (id)); - - panel_widget_register_open_dialog (panel, dialog); - gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); - /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */ - gtk_window_set_title (GTK_WINDOW (dialog), _("Error")); - - gtk_widget_show_all (dialog); - - /* Note: this call will free the memory for id, so the variable should - * not get accessed afterwards. */ - mate_panel_applet_stop_loading (id); -} - -static void -mate_panel_applet_frame_load (const gchar *iid, - PanelWidget *panel, - gboolean locked, - int position, - gboolean exactpos, - const char *id) -{ - MatePanelAppletFrameActivating *frame_act; - - g_return_if_fail (iid != NULL); - g_return_if_fail (panel != NULL); - g_return_if_fail (id != NULL); - - if (g_slist_find_custom (no_reload_applets, id, - (GCompareFunc) strcmp)) { - mate_panel_applet_stop_loading (id); - return; - } - - if (panel_lockdown_is_applet_disabled (iid)) { - mate_panel_applet_stop_loading (id); - return; - } - - frame_act = g_slice_new0 (MatePanelAppletFrameActivating); - frame_act->locked = locked; - frame_act->panel = panel; - frame_act->position = position; - frame_act->exactpos = exactpos; - frame_act->id = g_strdup (id); - - if (!mate_panel_applets_manager_load_applet (iid, frame_act)) { - mate_panel_applet_frame_loading_failed (iid, panel, id); - mate_panel_applet_frame_activating_free (frame_act); - } -} - -void -mate_panel_applet_frame_load_from_gsettings (PanelWidget *panel_widget, - gboolean locked, - int position, - const char *id) -{ - GSettings *settings; - gchar *path; - gchar *applet_iid; - - g_return_if_fail (panel_widget != NULL); - g_return_if_fail (id != NULL); - - path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id); - settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path); - applet_iid = g_settings_get_string (settings, PANEL_OBJECT_APPLET_IID_KEY); - g_object_unref (settings); - g_free (path); - - if (!applet_iid) { - mate_panel_applet_stop_loading (id); - return; - } - - mate_panel_applet_frame_load (applet_iid, panel_widget, - locked, position, TRUE, id); - - g_free (applet_iid); -} - -void -mate_panel_applet_frame_create (PanelToplevel *toplevel, - int position, - const char *iid) -{ - GSettings *settings; - gchar *path; - char *id; - - g_return_if_fail (iid != NULL); - - id = panel_profile_prepare_object (PANEL_OBJECT_APPLET, toplevel, position, FALSE); - - path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id); - settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path); - g_settings_set_string (settings, PANEL_OBJECT_APPLET_IID_KEY, iid); - - panel_profile_add_to_list (PANEL_GSETTINGS_OBJECTS, id); - - g_free (id); - g_free (path); - g_object_unref (settings); -} diff --git a/mate-panel/mate-panel-applet-frame.h b/mate-panel/mate-panel-applet-frame.h deleted file mode 100644 index ad5fbc75..00000000 --- a/mate-panel/mate-panel-applet-frame.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * mate-panel-applet-frame.h: panel side container for applets - * - * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301, USA. - * Authors: - * Mark McLoughlin - */ - -#ifndef __MATE_PANEL_APPLET_FRAME_H__ -#define __MATE_PANEL_APPLET_FRAME_H__ - -#include - -#include "panel-widget.h" -#include "applet.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_APPLET_FRAME (mate_panel_applet_frame_get_type ()) -#define MATE_PANEL_APPLET_FRAME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrame)) -#define MATE_PANEL_APPLET_FRAME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrameClass)) -#define PANEL_IS_APPLET_FRAME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_APPLET_FRAME)) -#define PANEL_IS_APPLET_FRAME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_APPLET_FRAME)) -#define MATE_PANEL_APPLET_FRAME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrameClass)) - -typedef struct _MatePanelAppletFrame MatePanelAppletFrame; -typedef struct _MatePanelAppletFrameClass MatePanelAppletFrameClass; -typedef struct _MatePanelAppletFramePrivate MatePanelAppletFramePrivate; - -struct _MatePanelAppletFrameClass { - GtkEventBoxClass parent_class; - - void (*init_properties) (MatePanelAppletFrame *frame); - - void (*sync_menu_state) (MatePanelAppletFrame *frame, - gboolean movable, - gboolean removable, - gboolean lockable, - gboolean locked, - gboolean locked_down); - - void (*popup_menu) (MatePanelAppletFrame *frame, - guint button, - guint32 timestamp); - - void (*change_orientation) (MatePanelAppletFrame *frame, - PanelOrientation orientation); - - void (*change_size) (MatePanelAppletFrame *frame, - guint size); - - void (*change_background) (MatePanelAppletFrame *frame, - PanelBackgroundType type); -}; - -struct _MatePanelAppletFrame { - GtkEventBox parent; - - MatePanelAppletFramePrivate *priv; -}; - -GType mate_panel_applet_frame_get_type (void) G_GNUC_CONST; - -void mate_panel_applet_frame_create (PanelToplevel *toplevel, - int position, - const char *iid); - -void mate_panel_applet_frame_load_from_gsettings (PanelWidget *panel_widget, - gboolean locked, - int position, - const char *id); - -void mate_panel_applet_frame_sync_menu_state (MatePanelAppletFrame *frame); - -void mate_panel_applet_frame_change_orientation (MatePanelAppletFrame *frame, - PanelOrientation orientation); - -void mate_panel_applet_frame_change_size (MatePanelAppletFrame *frame, - guint size); - -void mate_panel_applet_frame_change_background (MatePanelAppletFrame *frame, - PanelBackgroundType type); - -void mate_panel_applet_frame_set_panel (MatePanelAppletFrame *frame, - PanelWidget *panel); - - -/* For module implementations only */ - -typedef struct _MatePanelAppletFrameActivating MatePanelAppletFrameActivating; - -GdkScreen *panel_applet_frame_activating_get_screen (MatePanelAppletFrameActivating *frame_act); -PanelOrientation mate_panel_applet_frame_activating_get_orientation (MatePanelAppletFrameActivating *frame_act); -guint32 mate_panel_applet_frame_activating_get_size (MatePanelAppletFrameActivating *frame_act); -gboolean mate_panel_applet_frame_activating_get_locked (MatePanelAppletFrameActivating *frame_act); -gboolean mate_panel_applet_frame_activating_get_locked_down (MatePanelAppletFrameActivating *frame_act); -gchar *mate_panel_applet_frame_activating_get_conf_path (MatePanelAppletFrameActivating *frame_act); - -void _mate_panel_applet_frame_set_iid (MatePanelAppletFrame *frame, - const gchar *iid); - -void _mate_panel_applet_frame_activated (MatePanelAppletFrame *frame, - MatePanelAppletFrameActivating *frame_act, - GError *error); - -void _mate_panel_applet_frame_update_flags (MatePanelAppletFrame *frame, - gboolean major, - gboolean minor, - gboolean has_handle); - -void _mate_panel_applet_frame_update_size_hints (MatePanelAppletFrame *frame, - gint *size_hints, - guint n_elements); - -char *_mate_panel_applet_frame_get_background_string (MatePanelAppletFrame *frame, - PanelWidget *panel, - PanelBackgroundType type); - -void _mate_panel_applet_frame_applet_broken (MatePanelAppletFrame *frame); - -void _mate_panel_applet_frame_applet_remove (MatePanelAppletFrame *frame); -void _mate_panel_applet_frame_applet_move (MatePanelAppletFrame *frame); -void _mate_panel_applet_frame_applet_lock (MatePanelAppletFrame *frame, - gboolean locked); -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLET_FRAME_H__ */ - diff --git a/mate-panel/mate-panel-applet-info.c b/mate-panel/mate-panel-applet-info.c deleted file mode 100644 index 9f6dfc0a..00000000 --- a/mate-panel/mate-panel-applet-info.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * mate-panel-applet-info.c - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include - -#include "mate-panel-applet-info.h" - -struct _MatePanelAppletInfo { - gchar *iid; - - gchar *name; - gchar *comment; - gchar *icon; - - gchar **old_ids; -}; - -MatePanelAppletInfo * -mate_panel_applet_info_new (const gchar *iid, - const gchar *name, - const gchar *comment, - const gchar *icon, - const gchar **old_ids) -{ - MatePanelAppletInfo *info; - int len; - - info = g_slice_new0 (MatePanelAppletInfo); - - info->iid = g_strdup (iid); - info->name = g_strdup (name); - info->comment = g_strdup (comment); - info->icon = g_strdup (icon); - - /* MateComponent compatibility */ - if (old_ids != NULL) { - len = g_strv_length ((gchar **) old_ids); - if (len > 0) { - int i; - - info->old_ids = g_new0 (gchar *, len + 1); - - for (i = 0; i < len; i++) - info->old_ids[i] = g_strdup (old_ids[i]); - } - } - - return info; -} - -void -mate_panel_applet_info_free (MatePanelAppletInfo *info) -{ - if (!info) - return; - - g_free (info->iid); - g_free (info->name); - g_free (info->comment); - g_free (info->icon); - g_strfreev (info->old_ids); - - g_slice_free (MatePanelAppletInfo, info); -} - -const gchar * -mate_panel_applet_info_get_iid (MatePanelAppletInfo *info) -{ - return info->iid; -} - -const gchar * -mate_panel_applet_info_get_name (MatePanelAppletInfo *info) -{ - return info->name; -} - -const gchar * -mate_panel_applet_info_get_description (MatePanelAppletInfo *info) -{ - return info->comment; -} - -const gchar * -mate_panel_applet_info_get_icon (MatePanelAppletInfo *info) -{ - return info->icon; -} - -const gchar * const * -mate_panel_applet_info_get_old_ids (MatePanelAppletInfo *info) -{ - return (const gchar * const *) info->old_ids; -} diff --git a/mate-panel/mate-panel-applet-info.h b/mate-panel/mate-panel-applet-info.h deleted file mode 100644 index b18ff5cc..00000000 --- a/mate-panel/mate-panel-applet-info.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * mate-panel-applet-info.h - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#ifndef __MATE_PANEL_APPLET_INFO_H__ -#define __MATE_PANEL_APPLET_INFO_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _MatePanelAppletInfo MatePanelAppletInfo; - -MatePanelAppletInfo *mate_panel_applet_info_new (const gchar *iid, - const gchar *name, - const gchar *comment, - const gchar *icon, - const gchar **old_ids); -void mate_panel_applet_info_free (MatePanelAppletInfo *info); - -const gchar *mate_panel_applet_info_get_iid (MatePanelAppletInfo *info); -const gchar *mate_panel_applet_info_get_name (MatePanelAppletInfo *info); -const gchar *mate_panel_applet_info_get_description (MatePanelAppletInfo *info); -const gchar *mate_panel_applet_info_get_icon (MatePanelAppletInfo *info); -const gchar * const *mate_panel_applet_info_get_old_ids (MatePanelAppletInfo *info); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLET_INFO_H__ */ diff --git a/mate-panel/mate-panel-applets-manager.c b/mate-panel/mate-panel-applets-manager.c deleted file mode 100644 index d4c53fbd..00000000 --- a/mate-panel/mate-panel-applets-manager.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * mate-panel-applets-manager.c - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include - -#include - -#include - -#include "panel-modules.h" - -#include "mate-panel-applets-manager.h" - -G_DEFINE_ABSTRACT_TYPE (MatePanelAppletsManager, mate_panel_applets_manager, G_TYPE_OBJECT) - -static void -mate_panel_applets_manager_init (MatePanelAppletsManager *manager) -{ -} - -static void -mate_panel_applets_manager_class_init (MatePanelAppletsManagerClass *class) -{ -} - -/* Generic methods */ - -static GSList *mate_panel_applets_managers = NULL; - -static void -_mate_panel_applets_manager_cleanup (gpointer data) -{ - g_slist_foreach (mate_panel_applets_managers, (GFunc) g_object_unref, NULL); - g_slist_free (mate_panel_applets_managers); - mate_panel_applets_managers = NULL; -} - -static void -_mate_panel_applets_managers_ensure_loaded (void) -{ - GIOExtensionPoint *point; - GList *extensions, *l; - - if (mate_panel_applets_managers != NULL) - return; - - panel_cleanup_register (PANEL_CLEAN_FUNC (_mate_panel_applets_manager_cleanup), NULL); - - panel_modules_ensure_loaded (); - - point = g_io_extension_point_lookup (MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME); - - extensions = g_io_extension_point_get_extensions (point); - - if (extensions == NULL) - g_error ("No MatePanelAppletsManager implementations exist."); - - for (l = extensions; l != NULL; l = l->next) { - GIOExtension *extension; - GType type; - GObject *object; - - extension = l->data; - type = g_io_extension_get_type (extension); - object = g_object_new (type, NULL); - mate_panel_applets_managers = g_slist_prepend (mate_panel_applets_managers, object); - } - - mate_panel_applets_managers = g_slist_reverse (mate_panel_applets_managers); -} - -GList * -mate_panel_applets_manager_get_applets (void) -{ - GSList *l; - GList *retval = NULL; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - GList *applets; - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - applets = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applets (manager); - if (applets) - retval = g_list_concat (retval, applets); - } - - return retval; -} - -gboolean -mate_panel_applets_manager_factory_activate (const gchar *iid) -{ - GSList *l; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - if (MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->factory_activate (manager, iid)) - return TRUE; - } - - return FALSE; -} - -void -mate_panel_applets_manager_factory_deactivate (const gchar *iid) -{ - GSList *l; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - if (MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->factory_deactivate (manager, iid)) - return; - } -} - -MatePanelAppletInfo * -mate_panel_applets_manager_get_applet_info (const gchar *iid) -{ - GSList *l; - MatePanelAppletInfo *retval = NULL; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - retval = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info (manager, iid); - - if (retval != NULL) - return retval; - } - - return NULL; -} - -MatePanelAppletInfo * -mate_panel_applets_manager_get_applet_info_from_old_id (const gchar *iid) -{ - GSList *l; - MatePanelAppletInfo *retval = NULL; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - retval = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info_from_old_id (manager, iid); - - if (retval != NULL) - return retval; - } - - return NULL; -} - -gboolean -mate_panel_applets_manager_load_applet (const gchar *iid, - MatePanelAppletFrameActivating *frame_act) -{ - GSList *l; - - _mate_panel_applets_managers_ensure_loaded (); - - for (l = mate_panel_applets_managers; l != NULL; l = l->next) { - MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); - - if (!MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info (manager, iid)) - continue; - - return MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->load_applet (manager, iid, frame_act); - } - - return FALSE; -} diff --git a/mate-panel/mate-panel-applets-manager.h b/mate-panel/mate-panel-applets-manager.h deleted file mode 100644 index 19132329..00000000 --- a/mate-panel/mate-panel-applets-manager.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * mate-panel-applets-manager.h - * - * Copyright (C) 2010 Carlos Garcia Campos - * Copyright (C) 2010 Vincent Untz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __MATE_PANEL_APPLETS_MANAGER_H__ -#define __MATE_PANEL_APPLETS_MANAGER_H__ - -#include - -#include "mate-panel-applet-frame.h" -#include "mate-panel-applet-info.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_APPLETS_MANAGER (mate_panel_applets_manager_get_type ()) -#define MATE_PANEL_APPLETS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManager)) -#define MATE_PANEL_APPLETS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManagerClass)) -#define PANEL_IS_APPLETS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLETS_MANAGER)) -#define PANEL_IS_APPLETS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLETS_MANAGER)) -#define MATE_PANEL_APPLETS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManagerClass)) - -/** - * MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME: - * - * Extension point for #MatePanelAppletsManager functionality. - **/ -#define MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME "mate-panel-applets-manager" - -typedef struct _MatePanelAppletsManager MatePanelAppletsManager; -typedef struct _MatePanelAppletsManagerClass MatePanelAppletsManagerClass; - -struct _MatePanelAppletsManagerClass { - GObjectClass parent_class; - - GList * (*get_applets) (MatePanelAppletsManager *manager); - - gboolean (*factory_activate) (MatePanelAppletsManager *manager, - const gchar *iid); - gboolean (*factory_deactivate) (MatePanelAppletsManager *manager, - const gchar *iid); - - MatePanelAppletInfo * (*get_applet_info) (MatePanelAppletsManager *manager, - const gchar *iid); - - MatePanelAppletInfo * (*get_applet_info_from_old_id) (MatePanelAppletsManager *manager, - const gchar *iid); - - gboolean (*load_applet) (MatePanelAppletsManager *manager, - const gchar *iid, - MatePanelAppletFrameActivating *frame_act); -}; - -struct _MatePanelAppletsManager { - GObject parent; -}; - -GType mate_panel_applets_manager_get_type (void); - -GList *mate_panel_applets_manager_get_applets (void); - -gboolean mate_panel_applets_manager_factory_activate (const gchar *iid); -void mate_panel_applets_manager_factory_deactivate (const gchar *iid); - -MatePanelAppletInfo *mate_panel_applets_manager_get_applet_info (const gchar *iid); -MatePanelAppletInfo *mate_panel_applets_manager_get_applet_info_from_old_id (const gchar *iid); - -gboolean mate_panel_applets_manager_load_applet (const gchar *iid, - MatePanelAppletFrameActivating *frame_act); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_PANEL_APPLETS_MANAGER_H__ */ diff --git a/mate-panel/panel-addto.c b/mate-panel/panel-addto.c index 401fd9ed..09d4bcd9 100644 --- a/mate-panel/panel-addto.c +++ b/mate-panel/panel-addto.c @@ -36,8 +36,8 @@ #include "launcher.h" #include "panel.h" #include "drawer.h" -#include "mate-panel-applets-manager.h" -#include "mate-panel-applet-frame.h" +#include "panel-applets-manager.h" +#include "panel-applet-frame.h" #include "panel-action-button.h" #include "panel-menu-bar.h" #include "panel-separator.h" diff --git a/mate-panel/panel-applet-frame.c b/mate-panel/panel-applet-frame.c new file mode 100644 index 00000000..3610882e --- /dev/null +++ b/mate-panel/panel-applet-frame.c @@ -0,0 +1,1193 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * panel-applet-frame.c: panel side container for applets + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Authors: + * Mark McLoughlin + */ + +#include +#include + +#include + +#include +#include +#include + +#include "panel-applets-manager.h" +#include "panel-profile.h" +#include "panel.h" +#include "applet.h" +#include "panel-marshal.h" +#include "panel-background.h" +#include "panel-lockdown.h" +#include "panel-stock-icons.h" +#include "xstuff.h" +#include "panel-schemas.h" + +#include "panel-applet-frame.h" + +#define PANEL_RESPONSE_DELETE 0 +#define PANEL_RESPONSE_DONT_RELOAD 1 +#define PANEL_RESPONSE_RELOAD 2 + +static void mate_panel_applet_frame_activating_free (MatePanelAppletFrameActivating *frame_act); + +static void mate_panel_applet_frame_loading_failed (const char *iid, + PanelWidget *panel, + const char *id); + +static void mate_panel_applet_frame_load (const gchar *iid, + PanelWidget *panel, + gboolean locked, + int position, + gboolean exactpos, + const char *id); + +struct _MatePanelAppletFrameActivating { + gboolean locked; + PanelWidget *panel; + int position; + gboolean exactpos; + char *id; +}; + +/* MatePanelAppletFrame implementation */ + +G_DEFINE_TYPE (MatePanelAppletFrame, mate_panel_applet_frame, GTK_TYPE_EVENT_BOX) + +#define MATE_PANEL_APPLET_FRAME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFramePrivate)) + +#define HANDLE_SIZE 10 +#define MATE_PANEL_APPLET_PREFS_PATH "/org/mate/panel/objects/%s/prefs/" + +struct _MatePanelAppletFramePrivate { + PanelWidget *panel; + AppletInfo *applet_info; + + PanelOrientation orientation; + + gchar *iid; + + GtkAllocation child_allocation; + GdkRectangle handle_rect; + + guint has_handle : 1; +}; + +#if GTK_CHECK_VERSION (3, 0, 0) +static gboolean +mate_panel_applet_frame_draw (GtkWidget *widget, + cairo_t *cr) +{ + MatePanelAppletFrame *frame = MATE_PANEL_APPLET_FRAME (widget); + GtkStyleContext *context; + GtkStateFlags state; + cairo_pattern_t *bg_pattern; + PanelBackground *background; + + if (GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->draw) + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->draw (widget, cr); + + if (!frame->priv->has_handle) + return FALSE; + + context = gtk_widget_get_style_context (widget); + state = gtk_widget_get_state_flags (widget); + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + + cairo_save (cr); + + /* Set the pattern transform so as to correctly render a patterned + * background with the handle */ + gtk_style_context_get (context, state, + "background-image", &bg_pattern, + NULL); + background = &frame->priv->panel->background; + + if (bg_pattern && (background->type == PANEL_BACK_IMAGE || + (background->type == PANEL_BACK_COLOR && background->has_alpha))) { + cairo_matrix_t ptm; + + cairo_matrix_init_translate (&ptm, + frame->priv->handle_rect.x, + frame->priv->handle_rect.y); + cairo_matrix_scale (&ptm, + frame->priv->handle_rect.width, + frame->priv->handle_rect.height); + cairo_pattern_set_matrix (bg_pattern, &ptm); + cairo_pattern_destroy (bg_pattern); + } + + cairo_rectangle (cr, + frame->priv->handle_rect.x, + frame->priv->handle_rect.y, + frame->priv->handle_rect.width, + frame->priv->handle_rect.height); + cairo_clip (cr); + gtk_render_handle (context, cr, + 0, 0, + gtk_widget_get_allocated_width (widget), + gtk_widget_get_allocated_height (widget)); + + cairo_restore (cr); + + gtk_style_context_restore (context); + + return FALSE; +} +#else +static void +mate_panel_applet_frame_paint (GtkWidget *widget, + GdkRectangle *area) +{ + MatePanelAppletFrame *frame; + + frame = MATE_PANEL_APPLET_FRAME (widget); + + if (!frame->priv->has_handle) + return; + + if (gtk_widget_is_drawable (widget)) { + GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; + + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + orientation = GTK_ORIENTATION_VERTICAL; + break; + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + orientation = GTK_ORIENTATION_HORIZONTAL; + break; + default: + g_assert_not_reached (); + break; + } + + gtk_paint_handle ( + gtk_widget_get_style (widget), gtk_widget_get_window (widget), + gtk_widget_get_state (widget), + GTK_SHADOW_OUT, + area, widget, "handlebox", + frame->priv->handle_rect.x, + frame->priv->handle_rect.y, + frame->priv->handle_rect.width, + frame->priv->handle_rect.height, + orientation); + } +} + +static gboolean mate_panel_applet_frame_expose(GtkWidget* widget, GdkEventExpose* event) +{ + if (gtk_widget_is_drawable (widget)) + { + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->expose_event (widget, event); + + mate_panel_applet_frame_paint (widget, &event->area); + } + + return FALSE; +} +#endif + +static void +mate_panel_applet_frame_update_background_size (MatePanelAppletFrame *frame, + GtkAllocation *old_allocation, + GtkAllocation *new_allocation) +{ + PanelBackground *background; + + if (old_allocation->x == new_allocation->x && + old_allocation->y == new_allocation->y && + old_allocation->width == new_allocation->width && + old_allocation->height == new_allocation->height) + return; + + background = &frame->priv->panel->background; + + if (background->type == PANEL_BACK_NONE || + (background->type == PANEL_BACK_COLOR && !background->has_alpha)) + return; + + mate_panel_applet_frame_change_background (frame, background->type); +} + +#if GTK_CHECK_VERSION (3, 0, 0) +static void +mate_panel_applet_frame_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) +{ + MatePanelAppletFrame *frame; + GtkBin *bin; + GtkWidget *child; + guint border_width; + + frame = MATE_PANEL_APPLET_FRAME (widget); + bin = GTK_BIN (widget); + + if (!frame->priv->has_handle) { + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->get_preferred_width (widget, minimal_width, natural_width); + return; + } + + child = gtk_bin_get_child (bin); + if (child && gtk_widget_get_visible (child)) + gtk_widget_get_preferred_width (child, minimal_width, natural_width); + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + *minimal_width += border_width; + *natural_width += border_width; + + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + *minimal_width += HANDLE_SIZE; + *natural_width += HANDLE_SIZE; + break; + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + break; + default: + g_assert_not_reached (); + break; + } +} + +static void +mate_panel_applet_frame_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height) +{ + MatePanelAppletFrame *frame; + GtkBin *bin; + GtkWidget *child; + guint border_width; + + frame = MATE_PANEL_APPLET_FRAME (widget); + bin = GTK_BIN (widget); + + if (!frame->priv->has_handle) { + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->get_preferred_height (widget, minimal_height, natural_height); + return; + } + + child = gtk_bin_get_child (bin); + if (child && gtk_widget_get_visible (child)) + gtk_widget_get_preferred_height (child, minimal_height, natural_height); + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + *minimal_height += border_width; + *natural_height += border_width; + + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + *minimal_height += HANDLE_SIZE; + *natural_height += HANDLE_SIZE; + break; + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + break; + default: + g_assert_not_reached (); + break; + } +} +#else +static void +mate_panel_applet_frame_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + MatePanelAppletFrame *frame; + GtkBin *bin; + GtkWidget *child; + GtkRequisition child_requisition; + guint border_width; + + frame = MATE_PANEL_APPLET_FRAME (widget); + bin = GTK_BIN (widget); + + if (!frame->priv->has_handle) { + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->size_request (widget, requisition); + return; + } + + child = gtk_bin_get_child (bin); + if (child && gtk_widget_get_visible (child)) { + gtk_widget_size_request (child, &child_requisition); + + requisition->width = child_requisition.width; + requisition->height = child_requisition.height; + } + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + requisition->width += border_width; + requisition->height += border_width; + + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + requisition->width += HANDLE_SIZE; + break; + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + requisition->height += HANDLE_SIZE; + break; + default: + g_assert_not_reached (); + break; + } +} +#endif + +static void +mate_panel_applet_frame_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + MatePanelAppletFrame *frame; + GtkBin *bin; + GtkWidget *child; + GdkWindow *window; + GtkAllocation new_allocation; + GtkAllocation old_allocation; + GtkAllocation widget_allocation; + + gtk_widget_get_allocation (widget, &widget_allocation); + + old_allocation.x = widget_allocation.x; + old_allocation.y = widget_allocation.y; + old_allocation.width = widget_allocation.width; + old_allocation.height = widget_allocation.height; + + frame = MATE_PANEL_APPLET_FRAME (widget); + bin = GTK_BIN (widget); + + if (!frame->priv->has_handle) { + GTK_WIDGET_CLASS (mate_panel_applet_frame_parent_class)->size_allocate (widget, allocation); + mate_panel_applet_frame_update_background_size (frame, &old_allocation, allocation); + return; + } + + window = gtk_widget_get_window (widget); + child = gtk_bin_get_child (bin); + gtk_widget_set_allocation (widget, allocation); + + frame->priv->handle_rect.x = 0; + frame->priv->handle_rect.y = 0; + + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + frame->priv->handle_rect.width = HANDLE_SIZE; + frame->priv->handle_rect.height = allocation->height; + + if (gtk_widget_get_direction (GTK_WIDGET (frame)) != + GTK_TEXT_DIR_RTL) { + frame->priv->handle_rect.x = 0; + new_allocation.x = HANDLE_SIZE; + } else { + frame->priv->handle_rect.x = allocation->width - HANDLE_SIZE; + new_allocation.x = 0; + } + + new_allocation.y = 0; + new_allocation.width = allocation->width - HANDLE_SIZE; + new_allocation.height = allocation->height; + break; + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + frame->priv->handle_rect.width = allocation->width; + frame->priv->handle_rect.height = HANDLE_SIZE; + + new_allocation.x = 0; + new_allocation.y = HANDLE_SIZE; + new_allocation.width = allocation->width; + new_allocation.height = allocation->height - HANDLE_SIZE; + break; + default: + g_assert_not_reached (); + break; + } + + new_allocation.width = MAX (1, new_allocation.width); + new_allocation.height = MAX (1, new_allocation.height); + + /* If the child allocation changed, that means that the frame is drawn + * in a new place, so we must redraw the entire widget. + */ + if (gtk_widget_get_mapped (widget) && + (new_allocation.x != frame->priv->child_allocation.x || + new_allocation.y != frame->priv->child_allocation.y || + new_allocation.width != frame->priv->child_allocation.width || + new_allocation.height != frame->priv->child_allocation.height)) + gdk_window_invalidate_rect (window, &widget_allocation, FALSE); + + if (gtk_widget_get_realized (widget)) { + guint border_width; + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + gdk_window_move_resize (window, + allocation->x + border_width, + allocation->y + border_width, + MAX (allocation->width - border_width * 2, 0), + MAX (allocation->height - border_width * 2, 0)); + } + + if (child && gtk_widget_get_visible (child)) + gtk_widget_size_allocate (child, &new_allocation); + + frame->priv->child_allocation = new_allocation; + + mate_panel_applet_frame_update_background_size (frame, + &old_allocation, + allocation); +} + +static inline gboolean +button_event_in_rect (GdkEventButton *event, + GdkRectangle *rect) +{ + if (event->x >= rect->x && + event->x <= (rect->x + rect->width) && + event->y >= rect->y && + event->y <= (rect->y + rect->height)) + return TRUE; + + return FALSE; +} + +static gboolean +mate_panel_applet_frame_button_changed (GtkWidget *widget, + GdkEventButton *event) +{ + MatePanelAppletFrame *frame; + gboolean handled = FALSE; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkDisplay *display; + GdkDevice *pointer; + GdkDeviceManager *device_manager; +#endif + + frame = MATE_PANEL_APPLET_FRAME (widget); + + if (!frame->priv->has_handle) + return handled; + + if (event->window != gtk_widget_get_window (widget)) + return FALSE; + + switch (event->button) { + case 1: + case 2: + if (button_event_in_rect (event, &frame->priv->handle_rect)) { + if (event->type == GDK_BUTTON_PRESS || + event->type == GDK_2BUTTON_PRESS) { + panel_widget_applet_drag_start ( + frame->priv->panel, GTK_WIDGET (frame), + PW_DRAG_OFF_CURSOR, event->time); + handled = TRUE; + } else if (event->type == GDK_BUTTON_RELEASE) { + panel_widget_applet_drag_end (frame->priv->panel); + handled = TRUE; + } + } + break; + case 3: + if (event->type == GDK_BUTTON_PRESS || + event->type == GDK_2BUTTON_PRESS) { +#if GTK_CHECK_VERSION (3, 0, 0) + display = gtk_widget_get_display (widget); + device_manager = gdk_display_get_device_manager (display); + pointer = gdk_device_manager_get_client_pointer (device_manager); + gdk_device_ungrab (pointer, GDK_CURRENT_TIME); +#endif + gdk_pointer_ungrab (GDK_CURRENT_TIME); + + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_menu (frame, + event->button, + event->time); + + handled = TRUE; + } else if (event->type == GDK_BUTTON_RELEASE) + handled = TRUE; + break; + default: + break; + } + + return handled; +} + +static void +mate_panel_applet_frame_finalize (GObject *object) +{ + MatePanelAppletFrame *frame = MATE_PANEL_APPLET_FRAME (object); + + mate_panel_applets_manager_factory_deactivate (frame->priv->iid); + + panel_lockdown_notify_remove (G_CALLBACK (mate_panel_applet_frame_sync_menu_state), + frame); + + g_free (frame->priv->iid); + frame->priv->iid = NULL; + + G_OBJECT_CLASS (mate_panel_applet_frame_parent_class)->finalize (object); +} + +static void +mate_panel_applet_frame_class_init (MatePanelAppletFrameClass *klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; + + gobject_class->finalize = mate_panel_applet_frame_finalize; + +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->draw = mate_panel_applet_frame_draw; + widget_class->get_preferred_width = mate_panel_applet_frame_get_preferred_width; + widget_class->get_preferred_height = mate_panel_applet_frame_get_preferred_height; +#else + widget_class->expose_event = mate_panel_applet_frame_expose; + widget_class->size_request = mate_panel_applet_frame_size_request; +#endif + widget_class->size_allocate = mate_panel_applet_frame_size_allocate; + widget_class->button_press_event = mate_panel_applet_frame_button_changed; + widget_class->button_release_event = mate_panel_applet_frame_button_changed; + + g_type_class_add_private (klass, sizeof (MatePanelAppletFramePrivate)); +} + +static void +mate_panel_applet_frame_init (MatePanelAppletFrame *frame) +{ + frame->priv = MATE_PANEL_APPLET_FRAME_GET_PRIVATE (frame); + + frame->priv->panel = NULL; + frame->priv->orientation = PANEL_ORIENTATION_TOP; + frame->priv->applet_info = NULL; + frame->priv->has_handle = FALSE; +} + +static void +mate_panel_applet_frame_init_properties (MatePanelAppletFrame *frame) +{ + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->init_properties (frame); +} + +void +mate_panel_applet_frame_sync_menu_state (MatePanelAppletFrame *frame) +{ + PanelWidget *panel_widget; + gboolean locked_down; + gboolean locked; + gboolean lockable; + gboolean movable; + gboolean removable; + + panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))); + + movable = mate_panel_applet_can_freely_move (frame->priv->applet_info); + removable = panel_profile_id_lists_are_writable (); + lockable = mate_panel_applet_lockable (frame->priv->applet_info); + + locked = panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame)); + locked_down = panel_lockdown_get_locked_down (); + + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->sync_menu_state (frame, movable, removable, lockable, locked, locked_down); +} + +void +mate_panel_applet_frame_change_orientation (MatePanelAppletFrame *frame, + PanelOrientation orientation) +{ + if (orientation == frame->priv->orientation) + return; + + frame->priv->orientation = orientation; + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_orientation (frame, orientation); +} + +void +mate_panel_applet_frame_change_size (MatePanelAppletFrame *frame, + guint size) +{ + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_size (frame, size); +} + +void +mate_panel_applet_frame_change_background (MatePanelAppletFrame *frame, + PanelBackgroundType type) +{ + GtkWidget *parent; + + g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); + + parent = gtk_widget_get_parent (GTK_WIDGET (frame)); + + g_return_if_fail (PANEL_IS_WIDGET (parent)); + + if (frame->priv->has_handle) { + PanelBackground *background; + + background = &PANEL_WIDGET (parent)->background; +#if GTK_CHECK_VERSION (3, 0, 0) + panel_background_apply_css (background, GTK_WIDGET (frame)); +#else + panel_background_change_background_on_widget (background, + GTK_WIDGET (frame)); +#endif + } + + MATE_PANEL_APPLET_FRAME_GET_CLASS (frame)->change_background (frame, type); +} + +void +mate_panel_applet_frame_set_panel (MatePanelAppletFrame *frame, + PanelWidget *panel) +{ + g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); + g_return_if_fail (PANEL_IS_WIDGET (panel)); + + frame->priv->panel = panel; +} + +void +_mate_panel_applet_frame_set_iid (MatePanelAppletFrame *frame, + const gchar *iid) +{ + if (frame->priv->iid) + g_free (frame->priv->iid); + frame->priv->iid = g_strdup (iid); +} + +void +_mate_panel_applet_frame_activated (MatePanelAppletFrame *frame, + MatePanelAppletFrameActivating *frame_act, + GError *error) +{ + AppletInfo *info; + + g_assert (frame->priv->iid != NULL); + + if (error != NULL) { + g_warning ("Failed to load applet %s:\n%s", + frame->priv->iid, error->message); + g_error_free (error); + + mate_panel_applet_frame_loading_failed (frame->priv->iid, + frame_act->panel, + frame_act->id); + mate_panel_applet_frame_activating_free (frame_act); + gtk_widget_destroy (GTK_WIDGET (frame)); + + return; + } + + frame->priv->panel = frame_act->panel; + gtk_widget_show_all (GTK_WIDGET (frame)); + + info = mate_panel_applet_register (GTK_WIDGET (frame), GTK_WIDGET (frame), + NULL, frame->priv->panel, + frame_act->locked, frame_act->position, + frame_act->exactpos, PANEL_OBJECT_APPLET, + frame_act->id); + frame->priv->applet_info = info; + + panel_widget_set_applet_size_constrained (frame->priv->panel, + GTK_WIDGET (frame), TRUE); + + mate_panel_applet_frame_sync_menu_state (frame); + mate_panel_applet_frame_init_properties (frame); + + panel_lockdown_notify_add (G_CALLBACK (mate_panel_applet_frame_sync_menu_state), + frame); + + mate_panel_applet_stop_loading (frame_act->id); + mate_panel_applet_frame_activating_free (frame_act); +} + +void +_mate_panel_applet_frame_update_flags (MatePanelAppletFrame *frame, + gboolean major, + gboolean minor, + gboolean has_handle) +{ + gboolean old_has_handle; + + panel_widget_set_applet_expandable ( + frame->priv->panel, GTK_WIDGET (frame), major, minor); + + old_has_handle = frame->priv->has_handle; + frame->priv->has_handle = has_handle; + + if (!old_has_handle && frame->priv->has_handle) { + /* we've added an handle, so we need to get the background for + * it */ + PanelBackground *background; + + background = &frame->priv->panel->background; + mate_panel_applet_frame_change_background (frame, background->type); + } +} + +void +_mate_panel_applet_frame_update_size_hints (MatePanelAppletFrame *frame, + gint *size_hints, + guint n_elements) +{ + if (frame->priv->has_handle) { + gint extra_size = HANDLE_SIZE + 1; + gint i; + + for (i = 0; i < n_elements; i++) + size_hints[i] += extra_size; + } + + /* It takes the ownership of size-hints array */ + panel_widget_set_applet_size_hints (frame->priv->panel, + GTK_WIDGET (frame), + size_hints, + n_elements); +} + +char * +_mate_panel_applet_frame_get_background_string (MatePanelAppletFrame *frame, + PanelWidget *panel, + PanelBackgroundType type) +{ + GtkAllocation allocation; + int x; + int y; + + gtk_widget_get_allocation (GTK_WIDGET (frame), &allocation); + + x = allocation.x; + y = allocation.y; + + if (frame->priv->has_handle) { + switch (frame->priv->orientation) { + case PANEL_ORIENTATION_TOP: + case PANEL_ORIENTATION_BOTTOM: + if (gtk_widget_get_direction (GTK_WIDGET (frame)) != + GTK_TEXT_DIR_RTL) + x += frame->priv->handle_rect.width; + break; + case PANEL_ORIENTATION_LEFT: + case PANEL_ORIENTATION_RIGHT: + y += frame->priv->handle_rect.height; + break; + default: + g_assert_not_reached (); + break; + } + } + + return panel_background_make_string (&panel->background, x, y); +} + +static void +mate_panel_applet_frame_reload_response (GtkWidget *dialog, + int response, + MatePanelAppletFrame *frame) +{ + AppletInfo *info; + + g_return_if_fail (PANEL_IS_APPLET_FRAME (frame)); + + if (!frame->priv->iid || !frame->priv->panel) { + g_object_unref (frame); + gtk_widget_destroy (dialog); + return; + } + + info = frame->priv->applet_info; + + if (response == PANEL_RESPONSE_RELOAD) { + PanelWidget *panel; + char *iid; + char *id = NULL; + int position = -1; + gboolean locked = FALSE; + + panel = frame->priv->panel; + iid = g_strdup (frame->priv->iid); + + if (info) { + id = g_strdup (info->id); + position = mate_panel_applet_get_position (info); + locked = panel_widget_get_applet_locked (panel, info->widget); + mate_panel_applet_clean (info); + } + + mate_panel_applet_frame_load (iid, panel, locked, + position, TRUE, id); + + g_free (iid); + g_free (id); + + } else if (response == PANEL_RESPONSE_DELETE) { + /* if we can't write to applets list we can't really delete + it, so we'll just ignore this. FIXME: handle this + more correctly I suppose. */ + if (panel_profile_id_lists_are_writable () && info) + panel_profile_delete_object (info); + } + + g_object_unref (frame); + gtk_widget_destroy (dialog); +} + +void +_mate_panel_applet_frame_applet_broken (MatePanelAppletFrame *frame) +{ + GtkWidget *dialog; + GdkScreen *screen; + const char *applet_name = NULL; + char *dialog_txt; + + screen = gtk_widget_get_screen (GTK_WIDGET (frame)); + + if (xstuff_is_display_dead ()) + return; + + if (frame->priv->iid) { + MatePanelAppletInfo *info; + + info = (MatePanelAppletInfo *)mate_panel_applets_manager_get_applet_info (frame->priv->iid); + applet_name = mate_panel_applet_info_get_name (info); + } + + if (applet_name) + dialog_txt = g_strdup_printf (_("\"%s\" has quit unexpectedly"), applet_name); + else + dialog_txt = g_strdup (_("Panel object has quit unexpectedly")); + + dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, + dialog_txt, applet_name ? applet_name : NULL); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("If you reload a panel object, it will automatically " + "be added back to the panel.")); + + gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); + + if (panel_profile_id_lists_are_writable ()) { + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + _("D_elete"), PANEL_RESPONSE_DELETE, + _("_Don't Reload"), PANEL_RESPONSE_DONT_RELOAD, + _("_Reload"), PANEL_RESPONSE_RELOAD, + NULL); + } else { + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + _("_Don't Reload"), PANEL_RESPONSE_DONT_RELOAD, + _("_Reload"), PANEL_RESPONSE_RELOAD, + NULL); + } + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + PANEL_RESPONSE_RELOAD); + + gtk_window_set_screen (GTK_WINDOW (dialog), screen); + + g_signal_connect (dialog, "response", + G_CALLBACK (mate_panel_applet_frame_reload_response), + g_object_ref (frame)); + + panel_widget_register_open_dialog (frame->priv->panel, dialog); + gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); + /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */ + gtk_window_set_title (GTK_WINDOW (dialog), _("Error")); + + gtk_widget_show (dialog); + g_free (dialog_txt); +} + +void +_mate_panel_applet_frame_applet_remove (MatePanelAppletFrame *frame) +{ + AppletInfo *info; + + if (!frame->priv->applet_info) + return; + + info = frame->priv->applet_info; + frame->priv->applet_info = NULL; + + panel_profile_delete_object (info); +} + +void +_mate_panel_applet_frame_applet_move (MatePanelAppletFrame *frame) +{ + GtkWidget *widget = GTK_WIDGET (frame); + GtkWidget *parent = gtk_widget_get_parent (widget); + + if (!PANEL_IS_WIDGET (parent)) + return; + + panel_widget_applet_drag_start (PANEL_WIDGET (parent), + widget, + PW_DRAG_OFF_CENTER, + GDK_CURRENT_TIME); +} + +void +_mate_panel_applet_frame_applet_lock (MatePanelAppletFrame *frame, + gboolean locked) +{ + PanelWidget *panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame))); + + if (panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame)) == locked) + return; + + mate_panel_applet_toggle_locked (frame->priv->applet_info); +} + +/* Generic methods */ + +static GSList *no_reload_applets = NULL; + +enum { + LOADING_FAILED_RESPONSE_DONT_DELETE, + LOADING_FAILED_RESPONSE_DELETE +}; + +static void +mate_panel_applet_frame_activating_free (MatePanelAppletFrameActivating *frame_act) +{ + g_free (frame_act->id); + g_slice_free (MatePanelAppletFrameActivating, frame_act); +} + +GdkScreen * +panel_applet_frame_activating_get_screen (MatePanelAppletFrameActivating *frame_act) +{ + return gtk_widget_get_screen (GTK_WIDGET(frame_act->panel)); +} + +PanelOrientation +mate_panel_applet_frame_activating_get_orientation(MatePanelAppletFrameActivating *frame_act) +{ + return panel_widget_get_applet_orientation(frame_act->panel); +} + +guint32 +mate_panel_applet_frame_activating_get_size (MatePanelAppletFrameActivating *frame_act) +{ + return frame_act->panel->sz; +} + +gboolean +mate_panel_applet_frame_activating_get_locked (MatePanelAppletFrameActivating *frame_act) +{ + return frame_act->locked; +} + +gboolean +mate_panel_applet_frame_activating_get_locked_down (MatePanelAppletFrameActivating *frame_act) +{ + return panel_lockdown_get_locked_down (); +} + +gchar * +mate_panel_applet_frame_activating_get_conf_path (MatePanelAppletFrameActivating *frame_act) +{ + return g_strdup_printf (MATE_PANEL_APPLET_PREFS_PATH, frame_act->id); +} + +static void +mate_panel_applet_frame_loading_failed_response (GtkWidget *dialog, + guint response, + char *id) +{ + gtk_widget_destroy (dialog); + + if (response == LOADING_FAILED_RESPONSE_DELETE && + !panel_lockdown_get_locked_down () && + panel_profile_id_lists_are_writable ()) { + GSList *item; + + item = g_slist_find_custom (no_reload_applets, id, + (GCompareFunc) strcmp); + if (item) { + g_free (item->data); + no_reload_applets = g_slist_delete_link (no_reload_applets, + item); + } + + panel_profile_remove_from_list (PANEL_GSETTINGS_OBJECTS, id); + } + + g_free (id); +} + +static void +mate_panel_applet_frame_loading_failed (const char *iid, + PanelWidget *panel, + const char *id) +{ + GtkWidget *dialog; + char *problem_txt; + gboolean locked_down; + + no_reload_applets = g_slist_prepend (no_reload_applets, + g_strdup (id)); + + locked_down = panel_lockdown_get_locked_down (); + + problem_txt = g_strdup_printf (_("The panel encountered a problem " + "while loading \"%s\"."), + iid); + + dialog = gtk_message_dialog_new (NULL, 0, + locked_down ? GTK_MESSAGE_INFO : GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + "%s", problem_txt); + g_free (problem_txt); + + if (locked_down) { + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_OK, LOADING_FAILED_RESPONSE_DONT_DELETE, + NULL); + } else { + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("Do you want to delete the applet " + "from your configuration?")); + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + PANEL_STOCK_DONT_DELETE, LOADING_FAILED_RESPONSE_DONT_DELETE, + GTK_STOCK_DELETE, LOADING_FAILED_RESPONSE_DELETE, + NULL); + } + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + LOADING_FAILED_RESPONSE_DONT_DELETE); + + gtk_window_set_screen (GTK_WINDOW (dialog), + gtk_window_get_screen (GTK_WINDOW (panel->toplevel))); + + g_signal_connect (dialog, "response", + G_CALLBACK (mate_panel_applet_frame_loading_failed_response), + g_strdup (id)); + + panel_widget_register_open_dialog (panel, dialog); + gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); + /* FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=165132 */ + gtk_window_set_title (GTK_WINDOW (dialog), _("Error")); + + gtk_widget_show_all (dialog); + + /* Note: this call will free the memory for id, so the variable should + * not get accessed afterwards. */ + mate_panel_applet_stop_loading (id); +} + +static void +mate_panel_applet_frame_load (const gchar *iid, + PanelWidget *panel, + gboolean locked, + int position, + gboolean exactpos, + const char *id) +{ + MatePanelAppletFrameActivating *frame_act; + + g_return_if_fail (iid != NULL); + g_return_if_fail (panel != NULL); + g_return_if_fail (id != NULL); + + if (g_slist_find_custom (no_reload_applets, id, + (GCompareFunc) strcmp)) { + mate_panel_applet_stop_loading (id); + return; + } + + if (panel_lockdown_is_applet_disabled (iid)) { + mate_panel_applet_stop_loading (id); + return; + } + + frame_act = g_slice_new0 (MatePanelAppletFrameActivating); + frame_act->locked = locked; + frame_act->panel = panel; + frame_act->position = position; + frame_act->exactpos = exactpos; + frame_act->id = g_strdup (id); + + if (!mate_panel_applets_manager_load_applet (iid, frame_act)) { + mate_panel_applet_frame_loading_failed (iid, panel, id); + mate_panel_applet_frame_activating_free (frame_act); + } +} + +void +mate_panel_applet_frame_load_from_gsettings (PanelWidget *panel_widget, + gboolean locked, + int position, + const char *id) +{ + GSettings *settings; + gchar *path; + gchar *applet_iid; + + g_return_if_fail (panel_widget != NULL); + g_return_if_fail (id != NULL); + + path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id); + settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path); + applet_iid = g_settings_get_string (settings, PANEL_OBJECT_APPLET_IID_KEY); + g_object_unref (settings); + g_free (path); + + if (!applet_iid) { + mate_panel_applet_stop_loading (id); + return; + } + + mate_panel_applet_frame_load (applet_iid, panel_widget, + locked, position, TRUE, id); + + g_free (applet_iid); +} + +void +mate_panel_applet_frame_create (PanelToplevel *toplevel, + int position, + const char *iid) +{ + GSettings *settings; + gchar *path; + char *id; + + g_return_if_fail (iid != NULL); + + id = panel_profile_prepare_object (PANEL_OBJECT_APPLET, toplevel, position, FALSE); + + path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id); + settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path); + g_settings_set_string (settings, PANEL_OBJECT_APPLET_IID_KEY, iid); + + panel_profile_add_to_list (PANEL_GSETTINGS_OBJECTS, id); + + g_free (id); + g_free (path); + g_object_unref (settings); +} diff --git a/mate-panel/panel-applet-frame.h b/mate-panel/panel-applet-frame.h new file mode 100644 index 00000000..50b700b4 --- /dev/null +++ b/mate-panel/panel-applet-frame.h @@ -0,0 +1,147 @@ +/* + * panel-applet-frame.h: panel side container for applets + * + * Copyright (C) 2001 - 2003 Sun Microsystems, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301, USA. + * Authors: + * Mark McLoughlin + */ + +#ifndef __PANEL_APPLET_FRAME_H__ +#define __PANEL_APPLET_FRAME_H__ + +#include + +#include "panel-widget.h" +#include "applet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PANEL_TYPE_APPLET_FRAME (mate_panel_applet_frame_get_type ()) +#define MATE_PANEL_APPLET_FRAME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrame)) +#define MATE_PANEL_APPLET_FRAME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrameClass)) +#define PANEL_IS_APPLET_FRAME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_APPLET_FRAME)) +#define PANEL_IS_APPLET_FRAME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_APPLET_FRAME)) +#define MATE_PANEL_APPLET_FRAME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_APPLET_FRAME, MatePanelAppletFrameClass)) + +typedef struct _MatePanelAppletFrame MatePanelAppletFrame; +typedef struct _MatePanelAppletFrameClass MatePanelAppletFrameClass; +typedef struct _MatePanelAppletFramePrivate MatePanelAppletFramePrivate; + +struct _MatePanelAppletFrameClass { + GtkEventBoxClass parent_class; + + void (*init_properties) (MatePanelAppletFrame *frame); + + void (*sync_menu_state) (MatePanelAppletFrame *frame, + gboolean movable, + gboolean removable, + gboolean lockable, + gboolean locked, + gboolean locked_down); + + void (*popup_menu) (MatePanelAppletFrame *frame, + guint button, + guint32 timestamp); + + void (*change_orientation) (MatePanelAppletFrame *frame, + PanelOrientation orientation); + + void (*change_size) (MatePanelAppletFrame *frame, + guint size); + + void (*change_background) (MatePanelAppletFrame *frame, + PanelBackgroundType type); +}; + +struct _MatePanelAppletFrame { + GtkEventBox parent; + + MatePanelAppletFramePrivate *priv; +}; + +GType mate_panel_applet_frame_get_type (void) G_GNUC_CONST; + +void mate_panel_applet_frame_create (PanelToplevel *toplevel, + int position, + const char *iid); + +void mate_panel_applet_frame_load_from_gsettings (PanelWidget *panel_widget, + gboolean locked, + int position, + const char *id); + +void mate_panel_applet_frame_sync_menu_state (MatePanelAppletFrame *frame); + +void mate_panel_applet_frame_change_orientation (MatePanelAppletFrame *frame, + PanelOrientation orientation); + +void mate_panel_applet_frame_change_size (MatePanelAppletFrame *frame, + guint size); + +void mate_panel_applet_frame_change_background (MatePanelAppletFrame *frame, + PanelBackgroundType type); + +void mate_panel_applet_frame_set_panel (MatePanelAppletFrame *frame, + PanelWidget *panel); + + +/* For module implementations only */ + +typedef struct _MatePanelAppletFrameActivating MatePanelAppletFrameActivating; + +GdkScreen *panel_applet_frame_activating_get_screen (MatePanelAppletFrameActivating *frame_act); +PanelOrientation mate_panel_applet_frame_activating_get_orientation (MatePanelAppletFrameActivating *frame_act); +guint32 mate_panel_applet_frame_activating_get_size (MatePanelAppletFrameActivating *frame_act); +gboolean mate_panel_applet_frame_activating_get_locked (MatePanelAppletFrameActivating *frame_act); +gboolean mate_panel_applet_frame_activating_get_locked_down (MatePanelAppletFrameActivating *frame_act); +gchar *mate_panel_applet_frame_activating_get_conf_path (MatePanelAppletFrameActivating *frame_act); + +void _mate_panel_applet_frame_set_iid (MatePanelAppletFrame *frame, + const gchar *iid); + +void _mate_panel_applet_frame_activated (MatePanelAppletFrame *frame, + MatePanelAppletFrameActivating *frame_act, + GError *error); + +void _mate_panel_applet_frame_update_flags (MatePanelAppletFrame *frame, + gboolean major, + gboolean minor, + gboolean has_handle); + +void _mate_panel_applet_frame_update_size_hints (MatePanelAppletFrame *frame, + gint *size_hints, + guint n_elements); + +char *_mate_panel_applet_frame_get_background_string (MatePanelAppletFrame *frame, + PanelWidget *panel, + PanelBackgroundType type); + +void _mate_panel_applet_frame_applet_broken (MatePanelAppletFrame *frame); + +void _mate_panel_applet_frame_applet_remove (MatePanelAppletFrame *frame); +void _mate_panel_applet_frame_applet_move (MatePanelAppletFrame *frame); +void _mate_panel_applet_frame_applet_lock (MatePanelAppletFrame *frame, + gboolean locked); +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLET_FRAME_H__ */ + diff --git a/mate-panel/panel-applet-info.c b/mate-panel/panel-applet-info.c new file mode 100644 index 00000000..10023ea5 --- /dev/null +++ b/mate-panel/panel-applet-info.c @@ -0,0 +1,113 @@ +/* + * panel-applet-info.c + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include "panel-applet-info.h" + +struct _MatePanelAppletInfo { + gchar *iid; + + gchar *name; + gchar *comment; + gchar *icon; + + gchar **old_ids; +}; + +MatePanelAppletInfo * +mate_panel_applet_info_new (const gchar *iid, + const gchar *name, + const gchar *comment, + const gchar *icon, + const gchar **old_ids) +{ + MatePanelAppletInfo *info; + int len; + + info = g_slice_new0 (MatePanelAppletInfo); + + info->iid = g_strdup (iid); + info->name = g_strdup (name); + info->comment = g_strdup (comment); + info->icon = g_strdup (icon); + + /* MateComponent compatibility */ + if (old_ids != NULL) { + len = g_strv_length ((gchar **) old_ids); + if (len > 0) { + int i; + + info->old_ids = g_new0 (gchar *, len + 1); + + for (i = 0; i < len; i++) + info->old_ids[i] = g_strdup (old_ids[i]); + } + } + + return info; +} + +void +mate_panel_applet_info_free (MatePanelAppletInfo *info) +{ + if (!info) + return; + + g_free (info->iid); + g_free (info->name); + g_free (info->comment); + g_free (info->icon); + g_strfreev (info->old_ids); + + g_slice_free (MatePanelAppletInfo, info); +} + +const gchar * +mate_panel_applet_info_get_iid (MatePanelAppletInfo *info) +{ + return info->iid; +} + +const gchar * +mate_panel_applet_info_get_name (MatePanelAppletInfo *info) +{ + return info->name; +} + +const gchar * +mate_panel_applet_info_get_description (MatePanelAppletInfo *info) +{ + return info->comment; +} + +const gchar * +mate_panel_applet_info_get_icon (MatePanelAppletInfo *info) +{ + return info->icon; +} + +const gchar * const * +mate_panel_applet_info_get_old_ids (MatePanelAppletInfo *info) +{ + return (const gchar * const *) info->old_ids; +} diff --git a/mate-panel/panel-applet-info.h b/mate-panel/panel-applet-info.h new file mode 100644 index 00000000..fafef8b5 --- /dev/null +++ b/mate-panel/panel-applet-info.h @@ -0,0 +1,51 @@ +/* + * panel-applet-info.h + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef __PANEL_APPLET_INFO_H__ +#define __PANEL_APPLET_INFO_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _MatePanelAppletInfo MatePanelAppletInfo; + +MatePanelAppletInfo *mate_panel_applet_info_new (const gchar *iid, + const gchar *name, + const gchar *comment, + const gchar *icon, + const gchar **old_ids); +void mate_panel_applet_info_free (MatePanelAppletInfo *info); + +const gchar *mate_panel_applet_info_get_iid (MatePanelAppletInfo *info); +const gchar *mate_panel_applet_info_get_name (MatePanelAppletInfo *info); +const gchar *mate_panel_applet_info_get_description (MatePanelAppletInfo *info); +const gchar *mate_panel_applet_info_get_icon (MatePanelAppletInfo *info); +const gchar * const *mate_panel_applet_info_get_old_ids (MatePanelAppletInfo *info); + +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLET_INFO_H__ */ diff --git a/mate-panel/panel-applets-manager.c b/mate-panel/panel-applets-manager.c new file mode 100644 index 00000000..9568327e --- /dev/null +++ b/mate-panel/panel-applets-manager.c @@ -0,0 +1,201 @@ +/* + * panel-applets-manager.c + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include + +#include + +#include "panel-modules.h" + +#include "panel-applets-manager.h" + +G_DEFINE_ABSTRACT_TYPE (MatePanelAppletsManager, mate_panel_applets_manager, G_TYPE_OBJECT) + +static void +mate_panel_applets_manager_init (MatePanelAppletsManager *manager) +{ +} + +static void +mate_panel_applets_manager_class_init (MatePanelAppletsManagerClass *class) +{ +} + +/* Generic methods */ + +static GSList *mate_panel_applets_managers = NULL; + +static void +_mate_panel_applets_manager_cleanup (gpointer data) +{ + g_slist_foreach (mate_panel_applets_managers, (GFunc) g_object_unref, NULL); + g_slist_free (mate_panel_applets_managers); + mate_panel_applets_managers = NULL; +} + +static void +_mate_panel_applets_managers_ensure_loaded (void) +{ + GIOExtensionPoint *point; + GList *extensions, *l; + + if (mate_panel_applets_managers != NULL) + return; + + panel_cleanup_register (PANEL_CLEAN_FUNC (_mate_panel_applets_manager_cleanup), NULL); + + panel_modules_ensure_loaded (); + + point = g_io_extension_point_lookup (MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME); + + extensions = g_io_extension_point_get_extensions (point); + + if (extensions == NULL) + g_error ("No MatePanelAppletsManager implementations exist."); + + for (l = extensions; l != NULL; l = l->next) { + GIOExtension *extension; + GType type; + GObject *object; + + extension = l->data; + type = g_io_extension_get_type (extension); + object = g_object_new (type, NULL); + mate_panel_applets_managers = g_slist_prepend (mate_panel_applets_managers, object); + } + + mate_panel_applets_managers = g_slist_reverse (mate_panel_applets_managers); +} + +GList * +mate_panel_applets_manager_get_applets (void) +{ + GSList *l; + GList *retval = NULL; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + GList *applets; + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + applets = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applets (manager); + if (applets) + retval = g_list_concat (retval, applets); + } + + return retval; +} + +gboolean +mate_panel_applets_manager_factory_activate (const gchar *iid) +{ + GSList *l; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + if (MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->factory_activate (manager, iid)) + return TRUE; + } + + return FALSE; +} + +void +mate_panel_applets_manager_factory_deactivate (const gchar *iid) +{ + GSList *l; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + if (MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->factory_deactivate (manager, iid)) + return; + } +} + +MatePanelAppletInfo * +mate_panel_applets_manager_get_applet_info (const gchar *iid) +{ + GSList *l; + MatePanelAppletInfo *retval = NULL; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + retval = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info (manager, iid); + + if (retval != NULL) + return retval; + } + + return NULL; +} + +MatePanelAppletInfo * +mate_panel_applets_manager_get_applet_info_from_old_id (const gchar *iid) +{ + GSList *l; + MatePanelAppletInfo *retval = NULL; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + retval = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info_from_old_id (manager, iid); + + if (retval != NULL) + return retval; + } + + return NULL; +} + +gboolean +mate_panel_applets_manager_load_applet (const gchar *iid, + MatePanelAppletFrameActivating *frame_act) +{ + GSList *l; + + _mate_panel_applets_managers_ensure_loaded (); + + for (l = mate_panel_applets_managers; l != NULL; l = l->next) { + MatePanelAppletsManager *manager = MATE_PANEL_APPLETS_MANAGER (l->data); + + if (!MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applet_info (manager, iid)) + continue; + + return MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->load_applet (manager, iid, frame_act); + } + + return FALSE; +} diff --git a/mate-panel/panel-applets-manager.h b/mate-panel/panel-applets-manager.h new file mode 100644 index 00000000..5ea82bf8 --- /dev/null +++ b/mate-panel/panel-applets-manager.h @@ -0,0 +1,94 @@ +/* + * panel-applets-manager.h + * + * Copyright (C) 2010 Carlos Garcia Campos + * Copyright (C) 2010 Vincent Untz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __PANEL_APPLETS_MANAGER_H__ +#define __PANEL_APPLETS_MANAGER_H__ + +#include + +#include "panel-applet-frame.h" +#include "panel-applet-info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PANEL_TYPE_APPLETS_MANAGER (mate_panel_applets_manager_get_type ()) +#define MATE_PANEL_APPLETS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManager)) +#define MATE_PANEL_APPLETS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManagerClass)) +#define PANEL_IS_APPLETS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_APPLETS_MANAGER)) +#define PANEL_IS_APPLETS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_APPLETS_MANAGER)) +#define MATE_PANEL_APPLETS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_APPLETS_MANAGER, MatePanelAppletsManagerClass)) + +/** + * MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME: + * + * Extension point for #MatePanelAppletsManager functionality. + **/ +#define MATE_PANEL_APPLETS_MANAGER_EXTENSION_POINT_NAME "mate-panel-applets-manager" + +typedef struct _MatePanelAppletsManager MatePanelAppletsManager; +typedef struct _MatePanelAppletsManagerClass MatePanelAppletsManagerClass; + +struct _MatePanelAppletsManagerClass { + GObjectClass parent_class; + + GList * (*get_applets) (MatePanelAppletsManager *manager); + + gboolean (*factory_activate) (MatePanelAppletsManager *manager, + const gchar *iid); + gboolean (*factory_deactivate) (MatePanelAppletsManager *manager, + const gchar *iid); + + MatePanelAppletInfo * (*get_applet_info) (MatePanelAppletsManager *manager, + const gchar *iid); + + MatePanelAppletInfo * (*get_applet_info_from_old_id) (MatePanelAppletsManager *manager, + const gchar *iid); + + gboolean (*load_applet) (MatePanelAppletsManager *manager, + const gchar *iid, + MatePanelAppletFrameActivating *frame_act); +}; + +struct _MatePanelAppletsManager { + GObject parent; +}; + +GType mate_panel_applets_manager_get_type (void); + +GList *mate_panel_applets_manager_get_applets (void); + +gboolean mate_panel_applets_manager_factory_activate (const gchar *iid); +void mate_panel_applets_manager_factory_deactivate (const gchar *iid); + +MatePanelAppletInfo *mate_panel_applets_manager_get_applet_info (const gchar *iid); +MatePanelAppletInfo *mate_panel_applets_manager_get_applet_info_from_old_id (const gchar *iid); + +gboolean mate_panel_applets_manager_load_applet (const gchar *iid, + MatePanelAppletFrameActivating *frame_act); + +#ifdef __cplusplus +} +#endif + +#endif /* __PANEL_APPLETS_MANAGER_H__ */ diff --git a/mate-panel/panel-modules.c b/mate-panel/panel-modules.c index a4182241..af26d634 100644 --- a/mate-panel/panel-modules.c +++ b/mate-panel/panel-modules.c @@ -23,13 +23,11 @@ */ #include - #include -#include - -#include "mate-panel-applets-manager.h" +#include +#include "panel-applets-manager.h" #include "panel-modules.h" static void diff --git a/mate-panel/panel-test-applets.c b/mate-panel/panel-test-applets.c index aa83bbbe..ecdd784a 100644 --- a/mate-panel/panel-test-applets.c +++ b/mate-panel/panel-test-applets.c @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include #include "panel-modules.h" diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c index c8e82442..79591ca5 100644 --- a/mate-panel/panel-widget.c +++ b/mate-panel/panel-widget.c @@ -24,7 +24,7 @@ #include "panel-util.h" #include "panel-marshal.h" #include "panel-typebuiltins.h" -#include "mate-panel-applet-frame.h" +#include "panel-applet-frame.h" #include "panel-globals.h" #include "panel-profile.h" #include "panel-lockdown.h" diff --git a/mate-panel/panel.c b/mate-panel/panel.c index f0893774..6c29eda2 100644 --- a/mate-panel/panel.c +++ b/mate-panel/panel.c @@ -35,7 +35,7 @@ #include "panel-util.h" #include "panel-config-global.h" #include "panel-profile.h" -#include "mate-panel-applet-frame.h" +#include "panel-applet-frame.h" #include "panel-action-button.h" #include "panel-menu-bar.h" #include "panel-separator.h" diff --git a/po/POTFILES.in b/po/POTFILES.in index 653d481b..dc79a790 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -47,7 +47,7 @@ mate-panel/menu.c mate-panel/nothing.cP mate-panel/panel-action-button.c mate-panel/panel-addto.c -mate-panel/mate-panel-applet-frame.c +mate-panel/panel-applet-frame.c mate-panel/panel-bindings.c mate-panel/panel-context-menu.c mate-panel/panel-ditem-editor.c -- cgit v1.2.1