2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* based on indicator-messages.c written by :
6
* Ted Gould <ted@canonical.com>
7
* Cody Russell <cody.russell@canonical.com>
8
* E-mail : see the 'copyright' file.
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU General Public License
12
* as published by the Free Software Foundation; either version 3
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <libdbusmenu-gtk/menuitem.h>
28
#include <libdbusmenu-gtk/menu.h>
30
#include "applet-struct.h"
31
#include "dbus-data.h"
32
#include "applet-menu.h"
34
//////////////////////
35
// APPLICATION ITEM //
36
//////////////////////
38
/* Sets the icon when it changes.
40
application_icon_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, gpointer user_data)
42
g_print("Me-Messaging: (app_icon_change_cb)\n");
43
if (!g_strcmp0(prop, APPLICATION_MENUITEM_PROP_ICON)) {
45
if (GTK_IS_IMAGE(user_data)) {
46
gtk_image_set_from_icon_name(GTK_IMAGE(user_data), g_value_get_string(value), GTK_ICON_SIZE_MENU);
53
/* Sets the label when it changes.
55
application_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, gpointer user_data)
57
g_print("Me-Messaging: (app_prop_change_cb)\n");
58
if (!g_strcmp0(prop, APPLICATION_MENUITEM_PROP_NAME)) {
59
if (GTK_IS_LABEL(user_data)) {
60
gtk_label_set_text(GTK_LABEL(user_data), g_value_get_string(value));
67
void menu_item_set_icon_from_dmi
68
(DbusmenuMenuitem * mi, menu_item_t * mmi)
70
GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(mi, DBUSMENU_MENUITEM_PROP_ICON_DATA);
71
const char* icon_name;
72
if(icon_name = dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_ICON_NAME)) {
74
gtk_image_set_from_icon_name(mmi->icon, (gchar*)icon_name, GTK_ICON_SIZE_MENU);
75
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mmi->gmi), GTK_WIDGET(mmi->icon));
79
/* If we've got a pixbuf we need to make sure it's of a reasonable
80
size to fit in the menu. If not, rescale it. */
81
GdkPixbuf * resized_pixbuf;
83
gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
84
if (gdk_pixbuf_get_width(pixbuf) > width ||
85
gdk_pixbuf_get_height(pixbuf) > height) {
86
g_debug("Resizing icon from %dx%d to %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), width, height);
87
resized_pixbuf = gdk_pixbuf_scale_simple(pixbuf,
92
g_debug("Happy with icon sized %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
93
resized_pixbuf = pixbuf;
96
gtk_image_set_from_pixbuf(GTK_IMAGE(mmi->icon), resized_pixbuf);
98
/* The other pixbuf should be free'd by the dbusmenu. */
99
if (resized_pixbuf != pixbuf) {
100
g_object_unref(resized_pixbuf);
105
/* Whenever we have a property change on a DbusmenuMenuitem
106
we need to be responsive to that. */
108
indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, menu_item_t * mmi)
110
if(GTK_IS_LABEL(mmi->label)) {
111
g_print ("Me-Messaging: (PropChange) %s (%s) [%s] '%s'\n",
112
gtk_label_get_text(GTK_LABEL(mmi->label)),
114
dbusmenu_menuitem_property_get(mi, "type"),
115
g_value_get_string(value)
118
g_print("Me-Messaging: (PropChange) %s\n", prop);
121
if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_LABEL)) {
122
if(GTK_IS_LABEL(mmi->label)) {
123
gtk_label_set_text(GTK_LABEL(mmi->label), g_value_get_string(value));
125
} else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_RIGHT)) {
126
if(GTK_IS_LABEL(mmi->right)) {
127
gtk_label_set_text(GTK_LABEL(mmi->right), g_value_get_string(value));
129
} else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) {
130
g_print("Setting Visible\n");
131
if(g_value_get_boolean(value))
133
gtk_widget_set_child_visible(mmi->gmi,TRUE);
134
gtk_widget_set_visible(GTK_WIDGET(mmi->gmi),TRUE);
136
gtk_widget_set_child_visible(mmi->gmi,FALSE);
137
gtk_widget_set_visible(GTK_WIDGET(mmi->gmi),FALSE);
139
} else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ICON_NAME)) {
140
/* We don't use the value here, which is probably less efficient,
141
but it's easier to use the easy function. And since th value
142
is already cached, shouldn't be a big deal really. */
144
gtk_image_set_from_icon_name(mmi->icon, g_value_get_string(value), GTK_ICON_SIZE_MENU);
145
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mmi->gmi), GTK_WIDGET(mmi->icon));
147
// menu_item_set_icon_from_dmi(mi,mmi);
154
void menu_item_set_label_from_dmi(menu_item_t* mmi, DbusmenuMenuitem * dbus_mi)
156
g_print("Creating Label\n");
157
const char* label_text = "<Unknown>";
159
if(!GTK_IS_LABEL(mmi->label)) {
160
mmi->label = gtk_label_new(NULL);
161
gtk_misc_set_alignment(GTK_MISC(mmi->label), 0.0, 0.0);
162
gtk_box_pack_start(GTK_BOX(mmi->hbox), mmi->label, TRUE, TRUE, 0.0);
164
label_text = gtk_label_get_text(GTK_LABEL(mmi->label));
167
if(dbusmenu_menuitem_property_get(dbus_mi, INDICATOR_MENUITEM_PROP_LABEL)) {
168
label_text = dbusmenu_menuitem_property_get(dbus_mi, INDICATOR_MENUITEM_PROP_LABEL);
169
} else if(dbusmenu_menuitem_property_get(dbus_mi, DBUSMENU_MENUITEM_PROP_LABEL)) {
170
label_text = dbusmenu_menuitem_property_get(dbus_mi, DBUSMENU_MENUITEM_PROP_LABEL);
171
} else if(dbusmenu_menuitem_property_get(dbus_mi, APPLICATION_MENUITEM_PROP_NAME)) {
172
label_text = dbusmenu_menuitem_property_get(dbus_mi, APPLICATION_MENUITEM_PROP_NAME);
175
gtk_label_set_text(GTK_LABEL(mmi->label),label_text);
181
menu_item_new(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
183
g_print("Me-Messaging: Entering creation of item\n");
185
GtkWidget * running_icon;
187
gint icon_width, icon_height;
189
//Note: not checking parent, it's reasonable for it to be NULL
190
menu_item_t * ret = g_new0(menu_item_t, 1);
191
ret->hbox = gtk_hbox_new(FALSE, 0);
194
if(!g_strcmp0(dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_TYPE), APPLICATION_MENUITEM_TYPE)) {
195
ret->gmi = gtk_image_menu_item_new();
197
ret->icon = gtk_image_new_from_icon_name((gchar*)dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME), GTK_ICON_SIZE_MENU);
198
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(ret->gmi), GTK_WIDGET(ret->icon));
199
gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(ret->gmi), TRUE);
200
if(dbusmenu_menuitem_property_get_image(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA) != NULL)
202
g_print("Loading Icon Data!\n");
203
menu_item_set_icon_from_dmi(newitem, ret);
205
g_print("No data to load!\n");
208
// gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
209
// gtk_widget_set_size_request(icon, icon_width, icon_height);
210
// gtk_misc_set_alignment(GTK_MISC(icon), 0.0, 0.0);
211
// gtk_box_pack_start(GTK_BOX(ret->hbox), icon, FALSE, FALSE, padding);
212
// g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), ret);
214
ret->gmi = gtk_menu_item_new();
216
gtk_widget_style_get(ret->gmi, "horizontal-padding", &padding, NULL);
219
menu_item_set_label_from_dmi(ret, newitem);
222
ret->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT));
223
gtk_size_group_add_widget(myData.indicator_right_group, ret->right);
224
gtk_misc_set_alignment(GTK_MISC(ret->right), 1.0, 0.5);
225
gtk_box_pack_start(GTK_BOX(ret->hbox), ret->right, FALSE, FALSE, padding);
228
gtk_container_add(GTK_CONTAINER(ret->gmi), ret->hbox);
231
if(!dbusmenu_menuitem_property_get_bool(newitem, DBUSMENU_MENUITEM_PROP_VISIBLE)) {
232
gtk_widget_set_child_visible(ret->gmi,FALSE);
233
gtk_widget_set_visible(GTK_WIDGET(ret->gmi),FALSE);
235
gtk_widget_show_all(ret->gmi);
236
gtk_widget_set_child_visible(ret->gmi,TRUE);
237
gtk_widget_set_visible(GTK_WIDGET(ret->gmi),TRUE);
240
gtk_widget_show_all(ret->gmi);
242
g_print("Messaging-Menu: (App) New Menu Item %s %s\n",
243
gtk_label_get_text(GTK_LABEL(ret->label)),
244
dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_TYPE)
247
g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), ret);
248
dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ret->gmi), parent);
253
/* We have a small little menuitem type that handles all
254
of the fun stuff for indicators. Mostly this is the
255
shifting over and putting the icon in with some right
256
side text that'll be determined by the service. */
258
new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
261
return menu_item_new(newitem,parent,client);
264
/* Builds a menu item representing a running application in the
267
new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
269
return menu_item_new(newitem,parent,client);
277
void cd_messaging_add_menu_handler (DbusmenuGtkClient * client)
279
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), INDICATOR_MENUITEM_TYPE, new_indicator_item);
280
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), APPLICATION_MENUITEM_TYPE, new_application_item);