aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-11-23 14:55:06 -0600
committerTed Gould <ted@canonical.com>2009-11-23 14:55:06 -0600
commit59b0398609ef5ce6ee991c633eb84c3b55a42ac3 (patch)
treeb81beec36b41653eb49717110b3655515a5637c3
parent97388871ba0a4669792bead5878ec1eec24a2118 (diff)
parent2c04418795e644efafc0204656dd575844ba0976 (diff)
downloadlibayatana-appindicator-59b0398609ef5ce6ee991c633eb84c3b55a42ac3.tar.gz
libayatana-appindicator-59b0398609ef5ce6ee991c633eb84c3b55a42ac3.tar.bz2
libayatana-appindicator-59b0398609ef5ce6ee991c633eb84c3b55a42ac3.zip
Adding more fun. Now we're cookin'!
-rw-r--r--.bzrignore1
-rw-r--r--debian/changelog6
-rw-r--r--src/custom-service-appstore.c15
-rw-r--r--src/custom-service-watcher.c2
-rw-r--r--src/custom-service.c30
-rw-r--r--src/indicator-custom.c33
-rw-r--r--src/libcustomindicator/custom-indicator.c27
-rw-r--r--tests/Makefile.am19
-rw-r--r--tests/test-simple-app.c32
9 files changed, 158 insertions, 7 deletions
diff --git a/.bzrignore b/.bzrignore
index 4d5f1b0..b582d67 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -31,3 +31,4 @@ src/custom-service-marshal.h
src/stamp-marshal
src/dbus-properties-client.h
src/dbus-properties-server.h
+tests/test-simple-app
diff --git a/debian/changelog b/debian/changelog
index 833baae..92fbfb8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+indicator-custom (0.0.1-0ubuntu3~ppa1~service3) UNRELEASED; urgency=low
+
+ * Adding more fun. Now we're cookin'!
+
+ -- Ted Gould <ted@ubuntu.com> Mon, 23 Nov 2009 14:54:43 -0600
+
indicator-custom (0.0.1-0ubuntu3~ppa1~service2) karmic; urgency=low
* Building the service and getting things in better shape.
diff --git a/src/custom-service-appstore.c b/src/custom-service-appstore.c
index a69bde6..6cb2dd9 100644
--- a/src/custom-service-appstore.c
+++ b/src/custom-service-appstore.c
@@ -152,6 +152,10 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err
CustomServiceAppstorePrivate * priv = CUSTOM_SERVICE_APPSTORE_GET_PRIVATE(app->appstore);
priv->applications = g_list_prepend(priv->applications, app);
+
+ /* TODO: We need to have the position determined better. This
+ would involve looking at the name and category and sorting
+ it with the other entries. */
g_signal_emit(G_OBJECT(app->appstore),
signals[APPLICATION_ADDED], 0,
@@ -164,20 +168,27 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err
return;
}
+/* Adding a new NotificationItem object from DBus in to the
+ appstore. First, we need to get the information on it
+ though. */
void
custom_service_appstore_application_add (CustomServiceAppstore * appstore, const gchar * dbus_name, const gchar * dbus_object)
{
+ /* Make sure we got a sensible request */
g_return_if_fail(IS_CUSTOM_SERVICE_APPSTORE(appstore));
g_return_if_fail(dbus_name != NULL && dbus_name[0] != '\0');
g_return_if_fail(dbus_object != NULL && dbus_object[0] != '\0');
CustomServiceAppstorePrivate * priv = CUSTOM_SERVICE_APPSTORE_GET_PRIVATE(appstore);
+ /* Build the application entry. This will be carried
+ along until we're sure we've got everything. */
Application * app = g_new(Application, 1);
app->dbus_name = g_strdup(dbus_name);
app->dbus_object = g_strdup(dbus_object);
app->appstore = appstore;
+ /* Get the DBus proxy for the NotificationItem interface */
GError * error = NULL;
app->dbus_proxy = dbus_g_proxy_new_for_name_owner(priv->bus,
app->dbus_name,
@@ -192,6 +203,7 @@ custom_service_appstore_application_add (CustomServiceAppstore * appstore, const
return;
}
+ /* Grab the property proxy interface */
app->prop_proxy = dbus_g_proxy_new_for_name_owner(priv->bus,
app->dbus_name,
app->dbus_object,
@@ -206,11 +218,14 @@ custom_service_appstore_application_add (CustomServiceAppstore * appstore, const
return;
}
+ /* Get all the propertiees */
org_freedesktop_DBus_Properties_get_all_async(app->prop_proxy,
NOTIFICATION_ITEM_DBUS_IFACE,
get_all_properties_cb,
app);
+ /* We're returning, nothing is yet added until the properties
+ come back and give us more info. */
return;
}
diff --git a/src/custom-service-watcher.c b/src/custom-service-watcher.c
index a0a1b27..7cc15ee 100644
--- a/src/custom-service-watcher.c
+++ b/src/custom-service-watcher.c
@@ -104,7 +104,7 @@ custom_service_watcher_init (CustomServiceWatcher *self)
}
dbus_g_connection_register_g_object(session_bus,
- INDICATOR_CUSTOM_DBUS_OBJ "/more",
+ NOTIFICATION_WATCHER_DBUS_OBJ,
G_OBJECT(self));
return;
diff --git a/src/custom-service.c b/src/custom-service.c
index 3205bc2..5bd9b96 100644
--- a/src/custom-service.c
+++ b/src/custom-service.c
@@ -5,22 +5,52 @@
#include "custom-service-watcher.h"
#include "dbus-shared.h"
+/* The base main loop */
static GMainLoop * mainloop = NULL;
+/* Where the application registry lives */
static CustomServiceAppstore * appstore = NULL;
+/* Interface for applications */
static CustomServiceWatcher * watcher = NULL;
+/* The service management interface */
static IndicatorService * service = NULL;
+
+/* Recieves the disonnection signal from the service
+ object and closes the mainloop. */
+static void
+service_disconnected (IndicatorService * service, gpointer data)
+{
+ g_debug("Service disconnected");
+ if (mainloop != NULL) {
+ g_main_loop_quit(mainloop);
+ }
+ return;
+}
+/* Builds up the core objects and puts us spinning into
+ a main loop. */
int
main (int argc, char ** argv)
{
g_type_init();
+ /* Bring us up as a basic indicator service */
service = indicator_service_new(INDICATOR_CUSTOM_DBUS_ADDR);
+ g_signal_connect(G_OBJECT(service), "disconnected", G_CALLBACK(service_disconnected), NULL);
+
+ /* Building our app store */
appstore = CUSTOM_SERVICE_APPSTORE(g_object_new(CUSTOM_SERVICE_APPSTORE_TYPE, NULL));
+
+ /* Adding a watcher for the Apps coming up */
watcher = custom_service_watcher_new(appstore);
+ /* Building and executing our main loop */
mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);
+ /* Unref'ing all the objects */
+ g_object_unref(G_OBJECT(watcher));
+ g_object_unref(G_OBJECT(appstore));
+ g_object_unref(G_OBJECT(service));
+
return 0;
}
diff --git a/src/indicator-custom.c b/src/indicator-custom.c
index 7cb9142..3bd2aa9 100644
--- a/src/indicator-custom.c
+++ b/src/indicator-custom.c
@@ -55,7 +55,6 @@ struct _IndicatorCustomPrivate {
typedef struct _ApplicationEntry ApplicationEntry;
struct _ApplicationEntry {
- guint position;
IndicatorObjectEntry entry;
};
@@ -115,7 +114,7 @@ indicator_custom_dispose (GObject *object)
while (priv->applications != NULL) {
application_removed(priv->service_proxy,
- ((ApplicationEntry *)priv->applications->data)->position,
+ 0,
INDICATOR_CUSTOM(object));
}
@@ -237,20 +236,44 @@ application_added (DBusGProxy * proxy, const gchar * iconname, gint position, co
IndicatorCustomPrivate * priv = INDICATOR_CUSTOM_GET_PRIVATE(custom);
ApplicationEntry * app = g_new(ApplicationEntry, 1);
- app->position = position;
app->entry.image = GTK_IMAGE(gtk_image_new_from_icon_name(iconname, GTK_ICON_SIZE_MENU));
app->entry.label = NULL;
app->entry.menu = GTK_MENU(dbusmenu_gtkmenu_new((gchar *)dbusaddress, (gchar *)dbusobject));
- priv->applications = g_list_prepend(priv->applications, app);
+ priv->applications = g_list_insert(priv->applications, app, position);
+ /* TODO: Need to deal with position here somehow */
g_signal_emit(G_OBJECT(custom), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, &(app->entry), TRUE);
return;
}
+/* This removes the application from the list and free's all
+ of the memory associated with it. */
static void
-application_removed (DBusGProxy * proxy, gint position , IndicatorCustom * custom)
+application_removed (DBusGProxy * proxy, gint position, IndicatorCustom * custom)
{
+ IndicatorCustomPrivate * priv = INDICATOR_CUSTOM_GET_PRIVATE(custom);
+ ApplicationEntry * app = (ApplicationEntry *)g_list_nth_data(priv->applications, position);
+
+ if (app == NULL) {
+ g_warning("Unable to find application at position: %d", position);
+ return;
+ }
+
+ priv->applications = g_list_remove(priv->applications, app);
+ g_signal_emit(G_OBJECT(custom), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, &(app->entry), TRUE);
+
+ if (app->entry.image != NULL) {
+ g_object_unref(G_OBJECT(app->entry.image));
+ }
+ if (app->entry.label != NULL) {
+ g_warning("Odd, an application indicator with a label?");
+ g_object_unref(G_OBJECT(app->entry.label));
+ }
+ if (app->entry.menu != NULL) {
+ g_object_unref(G_OBJECT(app->entry.menu));
+ }
+ g_free(app);
return;
}
diff --git a/src/libcustomindicator/custom-indicator.c b/src/libcustomindicator/custom-indicator.c
index a4835cc..b2d1384 100644
--- a/src/libcustomindicator/custom-indicator.c
+++ b/src/libcustomindicator/custom-indicator.c
@@ -11,6 +11,8 @@
#include "notification-item-server.h"
#include "notification-watcher-client.h"
+#include "dbus-shared.h"
+
/**
CustomIndicatorPrivate:
@id: The ID of the indicator. Maps to CustomIndicator::id.
@@ -91,6 +93,7 @@ static void custom_indicator_set_property (GObject * object, guint prop_id, cons
static void custom_indicator_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
/* Other stuff */
static void check_connect (CustomIndicator * self);
+static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data);
/* GObject type */
G_DEFINE_TYPE (CustomIndicator, custom_indicator, G_TYPE_OBJECT);
@@ -277,10 +280,25 @@ custom_indicator_init (CustomIndicator *self)
g_error_free(error);
return;
}
+
dbus_g_connection_register_g_object(connection,
"/need/a/path",
G_OBJECT(self));
+ priv->watcher_proxy = dbus_g_proxy_new_for_name_owner(connection,
+ INDICATOR_CUSTOM_DBUS_ADDR,
+ NOTIFICATION_WATCHER_DBUS_OBJ,
+ NOTIFICATION_WATCHER_DBUS_IFACE,
+ &error);
+ if (error != NULL) {
+ g_warning("Unable to create Ayatana Watcher proxy! %s", error->message);
+ /* TODO: This is where we should start looking at fallbacks */
+ g_error_free(error);
+ return;
+ }
+
+ org_ayatana_indicator_custom_NotificationWatcher_register_service_async(priv->watcher_proxy, "/need/a/path", register_service_cb, self);
+
return;
}
@@ -598,6 +616,15 @@ check_connect (CustomIndicator * self)
}
+static void
+register_service_cb (DBusGProxy * proxy, GError * error, gpointer data)
+{
+ if (error != NULL) {
+ g_warning("Unable to connect to the Notification Watcher: %s", error->message);
+ }
+ return;
+}
+
/* ************************* */
/* Public Functions */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f6a0525..39cd3a6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,8 @@
check_PROGRAMS = \
test-libcustomindicator \
test-libcustomindicator-dbus-client \
- test-libcustomindicator-dbus-server
+ test-libcustomindicator-dbus-server \
+ test-simple-app
TESTS =
DISTCLEANFILES = $(TESTS)
@@ -82,3 +83,19 @@ test-libcustomindicator-dbus: test-libcustomindicator-dbus-client test-libcustom
TESTS += test-libcustomindicator-dbus
+#########################################
+## test-simple-app
+#########################################
+
+test_simple_app_SOURCES = \
+ test-simple-app.c
+
+test_simple_app_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_simple_app_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libcustomindicator.la
+
diff --git a/tests/test-simple-app.c b/tests/test-simple-app.c
new file mode 100644
index 0000000..9e779ec
--- /dev/null
+++ b/tests/test-simple-app.c
@@ -0,0 +1,32 @@
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <glib.h>
+#include <libcustomindicator/custom-indicator.h>
+
+static GMainLoop * mainloop = NULL;
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ DbusmenuServer * dms = dbusmenu_server_new("/menu");
+ DbusmenuMenuitem * dmi = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set(dmi, "label", "Bob");
+
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE,
+ "id", "test-application",
+ "status-enum", CUSTOM_INDICATOR_STATUS_ACTIVE,
+ "icon-name", "system-shutdown",
+ "menu-object", dms,
+ NULL));
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(ci));
+ g_debug("Quiting");
+
+ return 0;
+}