aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-04-27 10:42:39 -0500
committerTed Gould <ted@canonical.com>2009-04-27 10:42:39 -0500
commitd2d0c7aac15b44ca5bc876be3a402e63284512b6 (patch)
tree06294e6bfe4a1e4c2f69653302599aea70e83e3f /examples
parentc292100a3d95aac71c7cb943cbd3df9a204c0a70 (diff)
parent5899a3f246b8eeac2c820013a27cde0301ad69ee (diff)
downloadlibayatana-indicator-d2d0c7aac15b44ca5bc876be3a402e63284512b6.tar.gz
libayatana-indicator-d2d0c7aac15b44ca5bc876be3a402e63284512b6.tar.bz2
libayatana-indicator-d2d0c7aac15b44ca5bc876be3a402e63284512b6.zip
Merging in the testing branch to get some tests for this guy
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am72
-rw-r--r--examples/im-client.c111
-rw-r--r--examples/indicate-alot.c45
-rw-r--r--examples/indicate-and-crash.c41
-rw-r--r--examples/listen-and-print.c143
-rw-r--r--examples/show-hide-server.c44
-rwxr-xr-xexamples/test.js6
7 files changed, 462 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..862046e
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,72 @@
+
+libexec_PROGRAMS = \
+ indicate-and-crash \
+ indicate-alot \
+ listen-and-print \
+ im-client \
+ show-hide-server
+
+indicate_and_crash_SOURCES = \
+ indicate-and-crash.c
+
+indicate_and_crash_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(LIBINDICATE_CFLAGS)
+
+indicate_and_crash_LDADD = \
+ ../libindicate/libindicate.la \
+ $(LIBINDICATE_LIBS)
+
+indicate_alot_SOURCES = \
+ indicate-alot.c
+
+indicate_alot_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(LIBINDICATE_CFLAGS)
+
+indicate_alot_LDADD = \
+ ../libindicate/libindicate.la \
+ $(LIBINDICATE_LIBS)
+
+listen_and_print_SOURCES = \
+ listen-and-print.c
+
+listen_and_print_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(LIBINDICATE_CFLAGS)
+
+listen_and_print_LDADD = \
+ ../libindicate/libindicate.la \
+ $(LIBINDICATE_LIBS)
+
+im_client_SOURCES = \
+ im-client.c
+
+im_client_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(LIBINDICATE_CFLAGS)
+
+im_client_LDADD = \
+ ../libindicate/libindicate.la \
+ $(LIBINDICATE_LIBS)
+
+show_hide_server_SOURCES = \
+ show-hide-server.c
+
+show_hide_server_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(LIBINDICATE_CFLAGS)
+
+show_hide_server_LDADD = \
+ ../libindicate/libindicate.la \
+ $(LIBINDICATE_LIBS)
+
+examplesdir = $(docdir)/examples/
+
+examples_DATA = \
+ $(indicate_and_crash_SOURCES) \
+ $(indicate_alot_SOURCES) \
+ $(listen_and_print_SOURCES) \
+ $(im_client_SOURCES)
+
+EXTRA_DIST = $(examples_DATA)
diff --git a/examples/im-client.c b/examples/im-client.c
new file mode 100644
index 0000000..bf2fbb2
--- /dev/null
+++ b/examples/im-client.c
@@ -0,0 +1,111 @@
+/*
+A test for libindicate to ensure its quality.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+#include "libindicate/server.h"
+#include "libindicate/indicator-message.h"
+
+gchar * patha = "/usr/share/icons/hicolor/16x16/apps/empathy.png";
+gchar * pathb = "/usr/share/icons/hicolor/22x22/apps/empathy.png";
+gchar * lastpath = NULL;
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ g_debug("Modifying properties");
+
+ IndicateIndicator * indicator = INDICATE_INDICATOR(data);
+
+ GTimeVal time;
+ g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
+
+ if (lastpath == patha) {
+ lastpath = pathb;
+ } else {
+ lastpath = patha;
+ }
+
+ GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(lastpath, NULL);
+ g_return_val_if_fail(pixbuf != NULL, TRUE);
+
+ indicate_indicator_set_property_icon(INDICATE_INDICATOR(indicator), "icon", pixbuf);
+ g_object_unref(G_OBJECT(pixbuf));
+
+ return TRUE;
+}
+
+static void
+display (IndicateIndicator * indicator, gpointer data)
+{
+ g_debug("Ah, my indicator has been displayed");
+}
+
+static void
+server_display (IndicateServer * server, gpointer data)
+{
+ g_debug("Ah, my server has been displayed");
+}
+
+static void
+interest_added (IndicateServer * server, IndicateInterests interest)
+{
+ g_debug("Oh, someone is interested in my for: %d", interest);
+}
+
+void
+interest_removed (IndicateServer * server, IndicateInterests interest)
+{
+ g_debug("Someone is no longer interested in my for: %d", interest);
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ IndicateServer * server = indicate_server_ref_default();
+ indicate_server_set_type(server, "message.im");
+ indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop");
+ g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_SERVER_DISPLAY, G_CALLBACK(server_display), NULL);
+ g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL);
+ g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_REMOVED, G_CALLBACK(interest_removed), NULL);
+
+ IndicateIndicatorMessage * indicator;
+
+ indicator = indicate_indicator_message_new();
+ indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "subtype", "im");
+ indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "IM Client Test");
+ GTimeVal time; g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
+ indicate_indicator_show(INDICATE_INDICATOR(indicator));
+
+ g_get_current_time(&time);
+ indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time);
+
+ g_signal_connect(G_OBJECT(indicator), INDICATE_INDICATOR_SIGNAL_DISPLAY, G_CALLBACK(display), NULL);
+
+ g_timeout_add_seconds(180, timeout_cb, indicator);
+
+ g_main_loop_run(g_main_loop_new(NULL, FALSE));
+
+ return 0;
+}
diff --git a/examples/indicate-alot.c b/examples/indicate-alot.c
new file mode 100644
index 0000000..479040b
--- /dev/null
+++ b/examples/indicate-alot.c
@@ -0,0 +1,45 @@
+/*
+A test for libindicate to ensure its quality.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <glib.h>
+#include "libindicate/indicator.h"
+
+#define ALOT 30
+
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ IndicateIndicator * indicators[ALOT];
+ int i;
+
+ for (i = 0; i < ALOT; i++) {
+ indicators[i] = indicate_indicator_new();
+ indicate_indicator_show(indicators[i]);
+ }
+
+ g_main_loop_run(g_main_loop_new(NULL, FALSE));
+
+ return 0;
+}
diff --git a/examples/indicate-and-crash.c b/examples/indicate-and-crash.c
new file mode 100644
index 0000000..c002a54
--- /dev/null
+++ b/examples/indicate-and-crash.c
@@ -0,0 +1,41 @@
+/*
+A test for libindicate to ensure its quality.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <glib.h>
+#include "libindicate/indicator.h"
+
+gboolean crashfunc (gpointer data) { *(int *)data = 5; return FALSE;}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ IndicateIndicator * indicator = indicate_indicator_new();
+ indicate_indicator_show(indicator);
+
+ g_timeout_add_seconds(15, crashfunc, NULL);
+
+ g_main_loop_run(g_main_loop_new(NULL, FALSE));
+
+ return 0;
+}
diff --git a/examples/listen-and-print.c b/examples/listen-and-print.c
new file mode 100644
index 0000000..dcad92b
--- /dev/null
+++ b/examples/listen-and-print.c
@@ -0,0 +1,143 @@
+/*
+A test for libindicate to ensure its quality.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+#include "libindicate/listener.h"
+
+static void
+show_property_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
+{
+ g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, propertydata);
+ return;
+}
+
+static void
+show_property_time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data)
+{
+ time_t timet;
+ struct tm * structtm;
+
+ timet = propertydata->tv_sec;
+ structtm = localtime(&timet);
+
+ gchar timestring[80];
+ strftime(timestring, 80, "%I:%M", structtm);
+
+ g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, timestring);
+ return;
+}
+
+static void
+show_property_icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data)
+{
+ g_debug("Indicator Property: %s %d %s %dx%d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, gdk_pixbuf_get_width(propertydata), gdk_pixbuf_get_height(propertydata));
+ g_object_unref(G_OBJECT(propertydata));
+ return;
+}
+
+static void
+show_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property)
+{
+ if (!strcmp(property, "icon")) {
+ indicate_listener_get_property_icon(listener, server, indicator, property, show_property_icon_cb, NULL);
+ } else if (!strcmp(property, "time")) {
+ indicate_listener_get_property_time(listener, server, indicator, property, show_property_time_cb, NULL);
+ } else {
+ indicate_listener_get_property(listener, server, indicator, property, show_property_cb, NULL);
+ }
+
+ return;
+}
+
+static void
+get_properties (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator)
+{
+ //TODO: Not in API yet.
+}
+
+static void
+indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data)
+{
+ g_debug("Indicator Added: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type);
+ get_properties(listener, server, indicator);
+}
+
+static void
+indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data)
+{
+ g_debug("Indicator Removed: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type);
+}
+
+static void
+indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data)
+{
+ g_debug("Indicator Modified: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type, property);
+ show_property(listener, server, indicator, property);
+}
+
+static void
+type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data)
+{
+ g_debug("Indicator Server Type: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value);
+}
+
+static void
+desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data)
+{
+ g_debug("Indicator Server Desktop: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value);
+}
+
+static void
+server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
+{
+ g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
+ indicate_listener_server_get_type(listener, server, type_cb, NULL);
+ indicate_listener_server_get_desktop(listener, server, desktop_cb, NULL);
+
+ indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY);
+ indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY);
+
+ return;
+}
+
+static void
+server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
+{
+ g_debug("Indicator Server Removed: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ IndicateListener * listener = indicate_listener_ref_default();
+
+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL);
+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), NULL);
+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, G_CALLBACK(indicator_modified), NULL);
+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL);
+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), NULL);
+
+ g_main_loop_run(g_main_loop_new(NULL, FALSE));
+
+ return 0;
+}
diff --git a/examples/show-hide-server.c b/examples/show-hide-server.c
new file mode 100644
index 0000000..23c1ea1
--- /dev/null
+++ b/examples/show-hide-server.c
@@ -0,0 +1,44 @@
+/* From LP: #351537 */
+
+#include <glib.h>
+#include "libindicate/server.h"
+#include "libindicate/indicator-message.h"
+
+gboolean hidden = TRUE;
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ IndicateServer * server = INDICATE_SERVER(data);
+
+ if (hidden) {
+ printf("showing... ");
+ indicate_server_show(server);
+ printf("ok\n");
+ hidden = FALSE;
+ } else {
+ printf("hiding... ");
+ indicate_server_hide(server);
+ printf("ok\n");
+ hidden = TRUE;
+ }
+
+ return TRUE;
+}
+
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ IndicateServer * server = indicate_server_ref_default();
+ indicate_server_set_type(server, "message.im");
+ indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop");
+ g_timeout_add_seconds(1, timeout_cb, server);
+
+ g_main_loop_run(g_main_loop_new(NULL, FALSE));
+
+ return 0;
+}
+
diff --git a/examples/test.js b/examples/test.js
new file mode 100755
index 0000000..45b0d05
--- /dev/null
+++ b/examples/test.js
@@ -0,0 +1,6 @@
+#!/usr/local/bin/seed
+Seed.import_namespace("Indicate");
+
+var indicator = new Indicate.Indicator();
+
+indicator.show();