diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/dbus-shared-names.h | 9 | ||||
-rw-r--r-- | src/indicator-sus.c | 59 | ||||
-rw-r--r-- | src/status-provider-pidgin.c | 7 | ||||
-rw-r--r-- | src/status-provider.c | 2 | ||||
-rw-r--r-- | src/status-provider.h | 3 | ||||
-rw-r--r-- | src/status-service-dbus.c | 41 | ||||
-rw-r--r-- | src/status-service-dbus.h | 1 | ||||
-rw-r--r-- | src/status-service.c | 33 | ||||
-rw-r--r-- | src/status-service.xml | 6 | ||||
-rw-r--r-- | src/users-service.c | 1 |
11 files changed, 153 insertions, 22 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ab79f0f..bc3c9d9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,17 +29,17 @@ indicator_status_service_SOURCES = \ status-provider.c \ status-provider-pidgin.h \ status-provider-pidgin.c -indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) +indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror indicator_status_service_LDADD = $(STATUSSERVICE_LIBS) -status-service-client.h: status-service.xml +status-service-client.h: $(srcdir)/status-service.xml dbus-binding-tool \ --prefix=_status_service_client \ --mode=glib-client \ --output=status-service-client.h \ $(srcdir)/status-service.xml -status-service-server.h: status-service.xml +status-service-server.h: $(srcdir)/status-service.xml dbus-binding-tool \ --prefix=_status_service_server \ --mode=glib-server \ @@ -51,7 +51,7 @@ status-service-server.h: status-service.xml ############### indicator_users_service_SOURCES = users-service.c -indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) +indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror indicator_users_service_LDADD = $(USERSSERVICE_LIBS) ################# @@ -59,7 +59,7 @@ indicator_users_service_LDADD = $(USERSSERVICE_LIBS) ################# indicator_session_service_SOURCES = session-service.c -indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" +indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) ############### @@ -72,3 +72,6 @@ BUILT_SOURCES = \ EXTRA_DIST = \ status-service.xml + +CLEANFILES = \ + $(BUILT_SOURCES) diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 3ba21f8..a645830 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -25,13 +25,14 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define __DBUS_SHARED_NAMES_H__ 1 #define INDICATOR_STATUS_DBUS_NAME "org.ayatana.indicator.status" -#define INDICATOR_STATUS_DBUS_OBJECT "/org/ayatana/indicator/status" -#define INDICATOR_STATUS_SERVICE_DBUS_OBJECT "/org/ayatana/indicator/status-service" +#define INDICATOR_STATUS_DBUS_OBJECT "/org/ayatana/indicator/status/menu" +#define INDICATOR_STATUS_SERVICE_DBUS_OBJECT "/org/ayatana/indicator/status/service" +#define INDICATOR_STATUS_SERVICE_DBUS_INTERFACE "org.ayatana.indicator.status.service" #define INDICATOR_USERS_DBUS_NAME "org.ayatana.indicator.users" -#define INDICATOR_USERS_DBUS_OBJECT "/org/ayatana/indicator/users" +#define INDICATOR_USERS_DBUS_OBJECT "/org/ayatana/indicator/users/menu" #define INDICATOR_SESSION_DBUS_NAME "org.ayatana.indicator.session" -#define INDICATOR_SESSION_DBUS_OBJECT "/org/ayatana/indicator/session" +#define INDICATOR_SESSION_DBUS_OBJECT "/org/ayatana/indicator/session/menu" #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-sus.c b/src/indicator-sus.c index e248e68..07efc86 100644 --- a/src/indicator-sus.c +++ b/src/indicator-sus.c @@ -39,6 +39,7 @@ static DbusmenuGtkClient * users_client = NULL; static DbusmenuGtkClient * session_client = NULL; static GtkMenu * main_menu = NULL; +static GtkImage * status_image = NULL; static GtkWidget * status_separator = NULL; static GtkWidget * users_separator = NULL; @@ -47,6 +48,7 @@ static GtkWidget * loading_item = NULL; static DBusGConnection * connection = NULL; static DBusGProxy * proxy = NULL; +static DBusGProxy * status_proxy = NULL; typedef enum { STATUS_SECTION, @@ -71,8 +73,10 @@ get_label (void) GtkImage * get_icon (void) { - GtkImage * image = GTK_IMAGE(gtk_image_new_from_icon_name("user-offline", GTK_ICON_SIZE_MENU)); - return image; + g_debug("Changing status icon: '%s'", "user-offline"); + status_image = GTK_IMAGE(gtk_image_new_from_icon_name("user-offline", GTK_ICON_SIZE_MENU)); + gtk_widget_show(GTK_WIDGET(status_image)); + return status_image; } static void @@ -178,6 +182,55 @@ status_menu_root_changed(DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, return; } +void +status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata) +{ + g_return_if_fail(status_image != NULL); + g_return_if_fail(icons != NULL); + g_return_if_fail(icons[0] != '\0'); + + g_debug("Changing status icon: '%s'", icons); + gtk_image_set_from_icon_name(status_image, icons, GTK_ICON_SIZE_MENU); + + return; +} + +void +status_icon_changed (DBusGProxy * proxy, gchar * icon, gpointer userdata) +{ + return status_icon_cb(proxy, icon, NULL, NULL); +} + + +static gboolean +connect_to_status (gpointer userdata) +{ + if (status_proxy == NULL) { + GError * error = NULL; + + DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + + status_proxy = dbus_g_proxy_new_for_name_owner(sbus, + INDICATOR_STATUS_DBUS_NAME, + INDICATOR_STATUS_SERVICE_DBUS_OBJECT, + INDICATOR_STATUS_SERVICE_DBUS_INTERFACE, + &error); + + if (error != NULL) { + g_warning("Unable to get status proxy: %s", error->message); + g_error_free(error); + return FALSE; + } + + dbus_g_proxy_add_signal(status_proxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(status_proxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), NULL, NULL); + } + + org_ayatana_indicator_status_service_status_icons_async(status_proxy, status_icon_cb, NULL); + + return FALSE; +} + static gboolean build_status_menu (gpointer userdata) { @@ -208,6 +261,8 @@ build_status_menu (gpointer userdata) gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), status_separator); gtk_widget_hide(status_separator); /* Should be default, I'm just being explicit. $(%*#$ hide already! */ + g_idle_add(connect_to_status, NULL); + return FALSE; } diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index 6a3f7a5..aaa8732 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -129,6 +129,12 @@ status_provider_pidgin_init (StatusProviderPidgin *self) static void status_provider_pidgin_dispose (GObject *object) { + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(object); + + if (priv->proxy != NULL) { + g_object_unref(priv->proxy); + priv->proxy = NULL; + } G_OBJECT_CLASS (status_provider_pidgin_parent_class)->dispose (object); return; @@ -166,6 +172,7 @@ set_status (StatusProvider * sp, StatusProviderStatus status) StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(sp); pg_status_t pg_status = sp_to_pg_map[status]; priv->pg_status = pg_status; + g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); return; } diff --git a/src/status-provider.c b/src/status-provider.c index 1c9561b..83d44ac 100644 --- a/src/status-provider.c +++ b/src/status-provider.c @@ -43,7 +43,7 @@ G_DEFINE_TYPE (StatusProvider, status_provider, G_TYPE_OBJECT); static void status_provider_class_init (StatusProviderClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + // GObjectClass *object_class = G_OBJECT_CLASS (klass); klass->status_changed = NULL; diff --git a/src/status-provider.h b/src/status-provider.h index f01a90e..9cc9885 100644 --- a/src/status-provider.h +++ b/src/status-provider.h @@ -47,7 +47,8 @@ typedef enum } StatusProviderStatus; -#define STATUS_PROVIDER_SIGNAL_STATUS_CHANGED "status-changed" +#define STATUS_PROVIDER_SIGNAL_STATUS_CHANGED "status-changed" +#define STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID (g_signal_lookup(STATUS_PROVIDER_SIGNAL_STATUS_CHANGED, STATUS_PROVIDER_TYPE)) typedef struct _StatusProvider StatusProvider; struct _StatusProvider { diff --git a/src/status-service-dbus.c b/src/status-service-dbus.c index a8e031c..65de499 100644 --- a/src/status-service-dbus.c +++ b/src/status-service-dbus.c @@ -34,7 +34,7 @@ static void status_service_dbus_init (StatusServiceDbus *self); static void status_service_dbus_dispose (GObject *object); static void status_service_dbus_finalize (GObject *object); static gboolean _status_service_server_watch (StatusServiceDbus * service, GError ** error); -static gboolean _status_service_server_status_icons (StatusServiceDbus * service, GArray * array, GError ** error); +static gboolean _status_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error); static gboolean _status_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error); #include "status-service-server.h" @@ -44,6 +44,7 @@ typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate; struct _StatusServiceDbusPrivate { gchar * name; + gchar * icon; }; #define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \ @@ -102,8 +103,8 @@ status_service_dbus_class_init (StatusServiceDbusClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(StatusServiceDbusClass, status_icons_changed), NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); dbus_g_object_type_install_info(STATUS_SERVICE_DBUS_TYPE, &dbus_glib__status_service_server_object_info); @@ -120,7 +121,8 @@ status_service_dbus_init (StatusServiceDbus *self) G_OBJECT(self)); StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); - priv->name = "test"; + priv->name = NULL; + priv->icon = NULL; return; } @@ -149,8 +151,19 @@ _status_service_server_watch (StatusServiceDbus * service, GError ** error) } static gboolean -_status_service_server_status_icons (StatusServiceDbus * service, GArray * array, GError ** error) +_status_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error) { + if (!IS_STATUS_SERVICE_DBUS(service)) { + g_warning("NO BAD EVIL!"); + return FALSE; + } + + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); + if (priv->icon == NULL) { + *icon = g_strdup(""); + } else { + *icon = g_strdup(priv->icon); + } return TRUE; } @@ -172,3 +185,21 @@ _status_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** u return TRUE; } + +void +status_service_dbus_set_status (StatusServiceDbus * self, const gchar * icon) +{ + g_return_if_fail(IS_STATUS_SERVICE_DBUS(self)); + + g_debug("Setting icon to: %s", icon); + + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); + + if (priv->icon != NULL) { + g_free(priv->icon); + } + priv->icon = g_strdup(icon); + + g_signal_emit(G_OBJECT(self), signals[STATUS_ICONS_CHANGED], 0, priv->icon, TRUE); + return; +} diff --git a/src/status-service-dbus.h b/src/status-service-dbus.h index 66c9206..34a9c3c 100644 --- a/src/status-service-dbus.h +++ b/src/status-service-dbus.h @@ -52,6 +52,7 @@ struct _StatusServiceDbus { }; GType status_service_dbus_get_type (void); +void status_service_dbus_set_status (StatusServiceDbus * self, const gchar * icon); G_END_DECLS diff --git a/src/status-service.c b/src/status-service.c index 4c48c72..5a9d9b5 100644 --- a/src/status-service.c +++ b/src/status-service.c @@ -23,6 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <sys/types.h> #include <pwd.h> +#include <unistd.h> #include <glib/gi18n.h> @@ -67,6 +68,30 @@ static DbusmenuMenuitem * root_menuitem = NULL; static DbusmenuMenuitem * status_menuitem = NULL; static GMainLoop * mainloop = NULL; static StatusServiceDbus * dbus_interface = NULL; +static StatusProviderStatus global_status = STATUS_PROVIDER_STATUS_OFFLINE; + +static void +status_update (void) { + StatusProviderStatus oldglobal = global_status; + global_status = STATUS_PROVIDER_STATUS_ONLINE; + + int i; + for (i = 0; i < STATUS_PROVIDER_CNT; i++) { + StatusProviderStatus localstatus = status_provider_get_status(status_providers[i]); + if (localstatus > global_status) { + global_status = localstatus; + } + } + + if (global_status != oldglobal) { + g_debug("Global status changed to: %s", _(status_strings[global_status])); + + dbusmenu_menuitem_property_set(status_menuitem, "label", _(status_strings[global_status])); + status_service_dbus_set_status(dbus_interface, status_icons[global_status]); + } + + return; +} /* A fun little function to actually lock the screen. If, that's what you want, let's do it! */ @@ -114,8 +139,14 @@ build_providers (gpointer data) int i; for (i = 0; i < STATUS_PROVIDER_CNT; i++) { status_providers[i] = status_provider_newfuncs[i](); + + if (status_providers[i] != NULL) { + g_signal_connect(G_OBJECT(status_providers[i]), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED, G_CALLBACK(status_update), NULL); + } } + status_update(); + return FALSE; } @@ -154,7 +185,7 @@ build_menu (gpointer data) build_user_item(root); status_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(status_menuitem, "label", "Status"); + dbusmenu_menuitem_property_set(status_menuitem, "label", _(status_strings[global_status])); dbusmenu_menuitem_child_append(root, status_menuitem); StatusProviderStatus i; diff --git a/src/status-service.xml b/src/status-service.xml index 3807158..977b338 100644 --- a/src/status-service.xml +++ b/src/status-service.xml @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <node name="/"> - <interface name="org.ayatana.indicator.status"> + <interface name="org.ayatana.indicator.status.service"> <!-- Methods --> <method name="Watch"> <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> </method> <method name="StatusIcons"> - <arg type="a(s)" name="icons" direction="out" /> + <arg type="s" name="icons" direction="out" /> </method> <method name="PrettyUserName"> <arg type="s" name="name" direction="out" /> @@ -18,7 +18,7 @@ <arg type="s" name="name" direction="out" /> </signal> <signal name="StatusIconsChanged"> - <arg type="a(s)" name="icons" direction="out" /> + <arg type="s" name="icons" direction="out" /> </signal> </interface> diff --git a/src/users-service.c b/src/users-service.c index a8a9c67..9ada91f 100644 --- a/src/users-service.c +++ b/src/users-service.c @@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <unistd.h> #include <glib/gi18n.h> |