aboutsummaryrefslogtreecommitdiff
path: root/tests/dummy-indicator-signaler.c
blob: a4206d0a40fd5fe78f6dd58fa96703ce1cbf557c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Test for libindicator

Copyright 2009 Canonical Ltd.

Authors:
    Ted Gould <ted@canonical.com>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 3.0 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License version 3.0 for more details.

You should have received a copy of the GNU General Public
License along with this library. If not, see
<http://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <glib-object.h>

#include "libindicator/indicator.h"
#include "libindicator/indicator-object.h"

#define DUMMY_INDICATOR_SIGNALER_TYPE            (dummy_indicator_signaler_get_type ())
#define DUMMY_INDICATOR_SIGNALER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignaler))
#define DUMMY_INDICATOR_SIGNALER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass))
#define IS_DUMMY_INDICATOR_SIGNALER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIGNALER_TYPE))
#define IS_DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIGNALER_TYPE))
#define DUMMY_INDICATOR_SIGNALER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass))

typedef struct _DummyIndicatorSignaler      DummyIndicatorSignaler;
typedef struct _DummyIndicatorSignalerClass DummyIndicatorSignalerClass;

struct _DummyIndicatorSignalerClass {
	IndicatorObjectClass parent_class;
};

struct _DummyIndicatorSignaler {
	IndicatorObject parent;
	IndicatorObjectEntry *entries;
};

GType dummy_indicator_signaler_get_type (void);

INDICATOR_SET_VERSION
INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIGNALER_TYPE)

GtkLabel *
get_label (IndicatorObject * io)
{
	return GTK_LABEL(gtk_label_new("Signaler Item"));
}

GtkImage *
get_icon (IndicatorObject * io)
{
	return GTK_IMAGE(gtk_image_new());
}

GtkMenu *
get_menu (IndicatorObject * io)
{
	GtkMenu * main_menu = GTK_MENU(gtk_menu_new());
	GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading...");
	gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item);
	gtk_widget_show(GTK_WIDGET(loading_item));

	return main_menu;
}

const gchar *
get_accessible_desc (IndicatorObject * io)
{
	return "Signaler Item";
}

static void dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass);
static void dummy_indicator_signaler_init       (DummyIndicatorSignaler *self);
static void dummy_indicator_signaler_dispose    (GObject *object);
static void dummy_indicator_signaler_finalize   (GObject *object);

G_DEFINE_TYPE (DummyIndicatorSignaler, dummy_indicator_signaler, INDICATOR_OBJECT_TYPE);

static void
dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->dispose = dummy_indicator_signaler_dispose;
	object_class->finalize = dummy_indicator_signaler_finalize;

	IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);

	io_class->get_label = get_label;
	io_class->get_image = get_icon;
	io_class->get_menu = get_menu;
	io_class->get_accessible_desc = get_accessible_desc;
	io_class->entry_being_removed  = NULL;
	io_class->entry_was_added  = NULL;

	return;
}

static gboolean
idle_signal (gpointer data)
{
	DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data);

	IndicatorObjectEntry *added_entry, *removed_entry, *moved_entry;

	added_entry = &self->entries[0];
	moved_entry = &self->entries[1];
	removed_entry = &self->entries[2];

	added_entry->name_hint = "added";
	moved_entry->name_hint = "moved";
	removed_entry->name_hint = "removed";

	g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, added_entry);
	g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED_ID, 0, moved_entry, 0, 1);
	g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, removed_entry);

	return FALSE; /* Don't queue again */
}

static void
dummy_indicator_signaler_init (DummyIndicatorSignaler *self)
{
	self->entries = g_new0(IndicatorObjectEntry, 3);
	g_idle_add(idle_signal, self);
	return;
}

static void
dummy_indicator_signaler_dispose (GObject *object)
{

	G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->dispose (object);
	return;
}

static void
dummy_indicator_signaler_finalize (GObject *object)
{
	DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(object);
	g_free (self->entries);
	G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->finalize (object);
	return;
}