Back to index

libappindicator  12.10.0
test-libappindicator-status-server.c
Go to the documentation of this file.
00001 /*
00002 Tests for the libappindicator library that are over DBus.  This is
00003 the server side of those tests.
00004 
00005 Copyright 2009 Canonical Ltd.
00006 
00007 Authors:
00008     Ted Gould <ted@canonical.com>
00009 
00010 This program is free software: you can redistribute it and/or modify it
00011 under the terms of the GNU General Public License version 3, as published
00012 by the Free Software Foundation.
00013 
00014 This program is distributed in the hope that it will be useful, but
00015 WITHOUT ANY WARRANTY; without even the implied warranties of
00016 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
00017 PURPOSE.  See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License along
00020 with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 
00024 #include <stdlib.h>
00025 #include <dbus/dbus-glib.h>
00026 #include <dbus/dbus-glib-lowlevel.h>
00027 #include <glib.h>
00028 #include <app-indicator.h>
00029 
00030 static GMainLoop * mainloop = NULL;
00031 static gboolean active = FALSE;
00032 static guint toggle_count = 0;
00033 
00034 gboolean
00035 toggle (gpointer userdata)
00036 {
00037        if (active) {
00038               app_indicator_set_status (APP_INDICATOR(userdata), APP_INDICATOR_STATUS_ATTENTION);
00039               active = FALSE;
00040        } else {
00041               app_indicator_set_status (APP_INDICATOR(userdata), APP_INDICATOR_STATUS_ACTIVE);
00042               active = TRUE;
00043        }
00044 
00045        toggle_count++;
00046 
00047        if (toggle_count == 100) {
00048               g_main_loop_quit(mainloop);
00049               return FALSE;
00050        }
00051 
00052        return TRUE;
00053 }
00054 
00055 gint
00056 main (gint argc, gchar * argv[])
00057 {
00058        gtk_init(&argc, &argv);
00059 
00060        g_usleep(100000);
00061 
00062        g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
00063 
00064        AppIndicator * ci = app_indicator_new ("my-id", "my-icon-name", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
00065        app_indicator_set_attention_icon (ci, "my-attention-icon");
00066 
00067        GtkMenu * menu = GTK_MENU(gtk_menu_new());
00068        GtkMenuItem * item = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Label"));
00069        gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(item));
00070 
00071        app_indicator_set_menu(ci, menu);
00072 
00073        g_timeout_add(50, toggle, ci);
00074 
00075        mainloop = g_main_loop_new(NULL, FALSE);
00076        g_main_loop_run(mainloop);
00077 
00078        g_object_unref(G_OBJECT(ci));
00079        g_debug("Quiting");
00080 
00081        return 0;
00082 }