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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtk/gtk.h>
#include "im-menu-item.h"
typedef struct _ImMenuItemPrivate ImMenuItemPrivate;
struct _ImMenuItemPrivate
{
IndicateListener * listener;
IndicateListenerServer * server;
IndicateListenerIndicator * indicator;
GtkHBox * hbox;
GtkLabel * user;
GtkLabel * time;
GtkImage * icon;
};
#define IM_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IM_MENU_ITEM_TYPE, ImMenuItemPrivate))
/* Prototypes */
static void im_menu_item_class_init (ImMenuItemClass *klass);
static void im_menu_item_init (ImMenuItem *self);
static void im_menu_item_dispose (GObject *object);
static void im_menu_item_finalize (GObject *object);
static void sender_cb (IndicateListener * listener,
IndicateListenerServer * server,
IndicateListenerIndicator * indicator,
gchar * property,
gchar * propertydata,
gpointer data);
static void time_cb (IndicateListener * listener,
IndicateListenerServer * server,
IndicateListenerIndicator * indicator,
gchar * property,
gchar * propertydata,
gpointer data);
static void icon_cb (IndicateListener * listener,
IndicateListenerServer * server,
IndicateListenerIndicator * indicator,
gchar * property,
gchar * propertydata,
gpointer data);
static GtkSizeGroup * icon_group = NULL;
static GtkSizeGroup * user_group = NULL;
static GtkSizeGroup * time_group = NULL;
G_DEFINE_TYPE (ImMenuItem, im_menu_item, GTK_TYPE_MENU_ITEM);
static void
im_menu_item_class_init (ImMenuItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (ImMenuItemPrivate));
object_class->dispose = im_menu_item_dispose;
object_class->finalize = im_menu_item_finalize;
}
static void
im_menu_item_init (ImMenuItem *self)
{
ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
priv->listener = NULL;
priv->server = NULL;
priv->indicator = NULL;
/* build widgets first */
priv->icon = GTK_IMAGE(gtk_image_new());
priv->user = GTK_LABEL(gtk_label_new(""));
priv->time = GTK_LABEL(gtk_label_new(""));
if (icon_group == NULL) {
icon_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
}
if (user_group == NULL) {
user_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
}
if (time_group == NULL) {
time_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
}
gtk_size_group_add_widget(icon_group, priv->icon);
gtk_size_group_add_widget(user_group, priv->user);
gtk_size_group_add_widget(time_group, priv->time);
priv->hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(priv->hbox), GTK_WIDGET(priv->time), FALSE, TRUE, 3);
gtk_box_pack_start(GTK_BOX(priv->hbox), GTK_WIDGET(priv->user), TRUE, TRUE, 3);
gtk_box_pack_start(GTK_BOX(priv->hbox), GTK_WIDGET(priv->icon), FALSE, TRUE, 3);
gtk_container_add(GTK_CONTAINER(self), priv->hbox);
return;
}
static void
im_menu_item_dispose (GObject *object)
{
G_OBJECT_CLASS (im_menu_item_parent_class)->dispose (object);
}
static void
im_menu_item_finalize (GObject *object)
{
G_OBJECT_CLASS (im_menu_item_parent_class)->finalize (object);
}
static void
icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
{
}
static void
time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
{
ImMenuItem * self = IM_MENU_ITEM(data);
if (self == NULL) {
g_error("Menu Item callback called without a menu item");
return;
}
if (property == NULL || strcmp(property, "sender")) {
g_warning("Sender callback called without being send the sender.");
return;
}
ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
gtk_label_set_label(priv->time, propertydata);
gtk_widget_show(priv->time);
return;
}
static void
sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
{
ImMenuItem * self = IM_MENU_ITEM(data);
if (self == NULL) {
g_error("Menu Item callback called without a menu item");
return;
}
if (property == NULL || strcmp(property, "sender")) {
g_warning("Sender callback called without being send the sender.");
return;
}
ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
gtk_label_set_label(priv->user, propertydata);
gtk_widget_show(priv->user);
/* Once we have the user we'll show the menu item */
gtk_widget_show(self);
return;
}
ImMenuItem *
im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator)
{
ImMenuItem * self = g_object_new(IM_MENU_ITEM_TYPE, NULL);
ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
priv->listener = listener;
priv->server = server;
priv->indicator = indicator;
indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self);
indicate_listener_get_property(listener, server, indicator, "time", time_cb, self);
indicate_listener_get_property(listener, server, indicator, "icon", icon_cb, self);
return;
}
|