Back to index

libindicator  12.10.0
dummy-indicator-signaler.c
Go to the documentation of this file.
00001 /*
00002 Test for libindicator
00003 
00004 Copyright 2009 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 version 3.0 as published by the Free Software Foundation.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License version 3.0 for more details.
00017 
00018 You should have received a copy of the GNU General Public
00019 License along with this library. If not, see
00020 <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #include <glib.h>
00024 #include <glib-object.h>
00025 
00026 #include "libindicator/indicator.h"
00027 #include "libindicator/indicator-object.h"
00028 
00029 #define DUMMY_INDICATOR_SIGNALER_TYPE            (dummy_indicator_signaler_get_type ())
00030 #define DUMMY_INDICATOR_SIGNALER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignaler))
00031 #define DUMMY_INDICATOR_SIGNALER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass))
00032 #define IS_DUMMY_INDICATOR_SIGNALER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIGNALER_TYPE))
00033 #define IS_DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIGNALER_TYPE))
00034 #define DUMMY_INDICATOR_SIGNALER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass))
00035 
00036 typedef struct _DummyIndicatorSignaler      DummyIndicatorSignaler;
00037 typedef struct _DummyIndicatorSignalerClass DummyIndicatorSignalerClass;
00038 
00039 struct _DummyIndicatorSignalerClass {
00040        IndicatorObjectClass parent_class;
00041 };
00042 
00043 struct _DummyIndicatorSignaler {
00044        IndicatorObject parent;
00045        IndicatorObjectEntry *entries;
00046 };
00047 
00048 GType dummy_indicator_signaler_get_type (void);
00049 
00050 INDICATOR_SET_VERSION
00051 INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIGNALER_TYPE)
00052 
00053 GtkLabel *
00054 get_label (IndicatorObject * io)
00055 {
00056        return GTK_LABEL(gtk_label_new("Signaler Item"));
00057 }
00058 
00059 GtkImage *
00060 get_icon (IndicatorObject * io)
00061 {
00062        return GTK_IMAGE(gtk_image_new());
00063 }
00064 
00065 GtkMenu *
00066 get_menu (IndicatorObject * io)
00067 {
00068        GtkMenu * main_menu = GTK_MENU(gtk_menu_new());
00069        GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading...");
00070        gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item);
00071        gtk_widget_show(GTK_WIDGET(loading_item));
00072 
00073        return main_menu;
00074 }
00075 
00076 const gchar *
00077 get_accessible_desc (IndicatorObject * io)
00078 {
00079        return "Signaler Item";
00080 }
00081 
00082 static void dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass);
00083 static void dummy_indicator_signaler_init       (DummyIndicatorSignaler *self);
00084 static void dummy_indicator_signaler_dispose    (GObject *object);
00085 static void dummy_indicator_signaler_finalize   (GObject *object);
00086 
00087 G_DEFINE_TYPE (DummyIndicatorSignaler, dummy_indicator_signaler, INDICATOR_OBJECT_TYPE);
00088 
00089 static void
00090 dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass)
00091 {
00092        GObjectClass *object_class = G_OBJECT_CLASS (klass);
00093 
00094        object_class->dispose = dummy_indicator_signaler_dispose;
00095        object_class->finalize = dummy_indicator_signaler_finalize;
00096 
00097        IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);
00098 
00099        io_class->get_label = get_label;
00100        io_class->get_image = get_icon;
00101        io_class->get_menu = get_menu;
00102        io_class->get_accessible_desc = get_accessible_desc;
00103        io_class->entry_being_removed  = NULL;
00104        io_class->entry_was_added  = NULL;
00105 
00106        return;
00107 }
00108 
00109 static gboolean
00110 idle_signal (gpointer data)
00111 {
00112        DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data);
00113 
00114        IndicatorObjectEntry *added_entry, *removed_entry, *moved_entry;
00115 
00116        added_entry = &self->entries[0];
00117        moved_entry = &self->entries[1];
00118        removed_entry = &self->entries[2];
00119 
00120        added_entry->name_hint = "added";
00121        moved_entry->name_hint = "moved";
00122        removed_entry->name_hint = "removed";
00123 
00124        g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, added_entry);
00125        g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED_ID, 0, moved_entry, 0, 1);
00126        g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, removed_entry);
00127 
00128        return FALSE; /* Don't queue again */
00129 }
00130 
00131 static void
00132 dummy_indicator_signaler_init (DummyIndicatorSignaler *self)
00133 {
00134        self->entries = g_new0(IndicatorObjectEntry, 3);
00135        g_idle_add(idle_signal, self);
00136        return;
00137 }
00138 
00139 static void
00140 dummy_indicator_signaler_dispose (GObject *object)
00141 {
00142 
00143        G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->dispose (object);
00144        return;
00145 }
00146 
00147 static void
00148 dummy_indicator_signaler_finalize (GObject *object)
00149 {
00150        DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(object);
00151        g_free (self->entries);
00152        G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->finalize (object);
00153        return;
00154 }