aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-messages.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/indicator-messages.c')
-rw-r--r--src/indicator-messages.c64
1 files changed, 27 insertions, 37 deletions
diff --git a/src/indicator-messages.c b/src/indicator-messages.c
index a289127..3713204 100644
--- a/src/indicator-messages.c
+++ b/src/indicator-messages.c
@@ -32,6 +32,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libindicator/indicator.h>
#include <libindicator/indicator-object.h>
#include <libindicator/indicator-image-helper.h>
+#include <libindicator/indicator-service-manager.h>
#include "dbus-data.h"
#include "messages-service-client.h"
@@ -52,6 +53,7 @@ struct _IndicatorMessagesClass {
struct _IndicatorMessages {
IndicatorObject parent;
+ IndicatorServiceManager * service;
};
GType indicator_messages_get_type (void);
@@ -72,6 +74,9 @@ static void indicator_messages_dispose (GObject *object);
static void indicator_messages_finalize (GObject *object);
static GtkImage * get_icon (IndicatorObject * io);
static GtkMenu * get_menu (IndicatorObject * io);
+static void connection_change (IndicatorServiceManager * sm,
+ gboolean connected,
+ gpointer user_data);
G_DEFINE_TYPE (IndicatorMessages, indicator_messages, INDICATOR_OBJECT_TYPE);
@@ -96,6 +101,12 @@ indicator_messages_class_init (IndicatorMessagesClass *klass)
static void
indicator_messages_init (IndicatorMessages *self)
{
+ /* Default values */
+ self->service = NULL;
+
+ /* Complex stuff */
+ self->service = indicator_service_manager_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1);
+ g_signal_connect(self->service, INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_change), self);
return;
}
@@ -104,6 +115,13 @@ indicator_messages_init (IndicatorMessages *self)
static void
indicator_messages_dispose (GObject *object)
{
+ IndicatorMessages * self = INDICATOR_MESSAGES(object);
+ g_return_if_fail(self != NULL);
+
+ if (self->service != NULL) {
+ g_object_unref(self->service);
+ self->service = NULL;
+ }
G_OBJECT_CLASS (indicator_messages_parent_class)->dispose (object);
return;
@@ -146,17 +164,6 @@ icon_changed_cb (DBusGProxy * proxy, gboolean hidden, gpointer userdata)
return;
}
-/* Whether we can send the watch signal to the service */
-static void
-watch_cb (DBusGProxy * proxy, GError * error, gpointer userdata)
-{
- if (error != NULL) {
- g_warning("Watch failed! %s", error->message);
- g_error_free(error);
- }
- return;
-}
-
/* Callback from getting the attention status from the service. */
static void
attention_cb (DBusGProxy * proxy, gboolean dot, GError * error, gpointer userdata)
@@ -184,13 +191,17 @@ icon_cb (DBusGProxy * proxy, gboolean hidden, GError * error, gpointer userdata)
}
/* Sets up all the icon information in the proxy. */
-static gboolean
-setup_icon_proxy (gpointer userdata)
+static void
+connection_change (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
{
+ if (!connected) {
+ return;
+ }
+
DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
if (connection == NULL) {
g_warning("Unable to get session bus");
- return FALSE; /* TRUE? */
+ return;
}
icon_proxy = dbus_g_proxy_new_for_name(connection,
@@ -199,11 +210,9 @@ setup_icon_proxy (gpointer userdata)
INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE);
if (icon_proxy == NULL) {
g_warning("Unable to get messages service interface.");
- return FALSE;
+ return;
}
- org_ayatana_indicator_messages_service_watch_async(icon_proxy, watch_cb, NULL);
-
dbus_g_proxy_add_signal(icon_proxy, "AttentionChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(icon_proxy,
"AttentionChanged",
@@ -221,7 +230,7 @@ setup_icon_proxy (gpointer userdata)
org_ayatana_indicator_messages_service_attention_requested_async(icon_proxy, attention_cb, NULL);
org_ayatana_indicator_messages_service_icon_shown_async(icon_proxy, icon_cb, NULL);
- return FALSE;
+ return;
}
/* Sets the icon when it changes. */
@@ -453,27 +462,8 @@ get_icon (IndicatorObject * io)
static GtkMenu *
get_menu (IndicatorObject * io)
{
- guint returnval = 0;
- GError * error = NULL;
-
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- DBusGProxy * proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
-
- if (!org_freedesktop_DBus_start_service_by_name (proxy, INDICATOR_MESSAGES_DBUS_NAME, 0, &returnval, &error)) {
- g_error("Unable to send message to DBus to start service: %s", error != NULL ? error->message : "(NULL error)" );
- g_error_free(error);
- return NULL;
- }
-
- if (returnval != DBUS_START_REPLY_SUCCESS && returnval != DBUS_START_REPLY_ALREADY_RUNNING) {
- g_error("Return value isn't indicative of success: %d", returnval);
- return NULL;
- }
-
indicator_right_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
- g_idle_add(setup_icon_proxy, NULL);
-
DbusmenuGtkMenu * menu = dbusmenu_gtkmenu_new(INDICATOR_MESSAGES_DBUS_NAME, INDICATOR_MESSAGES_DBUS_OBJECT);
DbusmenuGtkClient * client = dbusmenu_gtkmenu_get_client(menu);