1 /* gtkstatusicon-x11.c:
3 * Copyright (C) 2003 Sun Microsystems, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 * Mark McLoughlin <mark@skynet.ie>
32 static TestStatus status = TEST_STATUS_FILE;
33 static gint timeout = 0;
36 update_icon (GtkStatusIcon *status_icon)
41 if (status == TEST_STATUS_FILE)
43 icon_name = "gnome-fs-regular";
44 tooltip = "Regular File";
48 icon_name = "gnome-fs-directory";
49 tooltip = "Directory";
52 gtk_status_icon_set_from_icon_name (status_icon, icon_name);
53 gtk_status_icon_set_tooltip (status_icon, tooltip);
57 timeout_handler (gpointer data)
59 GtkStatusIcon *icon = GTK_STATUS_ICON (data);
61 if (status == TEST_STATUS_FILE)
62 status = TEST_STATUS_DIRECTORY;
64 status = TEST_STATUS_FILE;
72 blink_toggle_toggled (GtkToggleButton *toggle,
75 gtk_status_icon_set_blinking (icon,
76 gtk_toggle_button_get_active (toggle));
80 visible_toggle_toggled (GtkToggleButton *toggle,
83 gtk_status_icon_set_visible (icon,
84 gtk_toggle_button_get_active (toggle));
88 timeout_toggle_toggled (GtkToggleButton *toggle,
93 g_source_remove (timeout);
98 timeout = g_timeout_add (2000, timeout_handler, icon);
103 icon_activated (GtkStatusIcon *icon)
108 dialog = g_object_get_data (G_OBJECT (icon), "test-status-icon-dialog");
111 dialog = gtk_message_dialog_new (NULL, 0,
112 GTK_MESSAGE_QUESTION,
114 "You wanna test the status icon ?");
116 g_object_set_data_full (G_OBJECT (icon), "test-status-icon-dialog",
117 dialog, (GDestroyNotify) gtk_widget_destroy);
119 g_signal_connect (dialog, "response",
120 G_CALLBACK (gtk_widget_hide), NULL);
121 g_signal_connect (dialog, "delete_event",
122 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
124 toggle = gtk_toggle_button_new_with_mnemonic ("_Show the icon");
125 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
126 gtk_widget_show (toggle);
128 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
129 gtk_status_icon_get_visible (icon));
130 g_signal_connect (toggle, "toggled",
131 G_CALLBACK (visible_toggle_toggled), icon);
133 toggle = gtk_toggle_button_new_with_mnemonic ("_Blink the icon");
134 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
135 gtk_widget_show (toggle);
137 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
138 gtk_status_icon_get_blinking (icon));
139 g_signal_connect (toggle, "toggled",
140 G_CALLBACK (blink_toggle_toggled), icon);
142 toggle = gtk_toggle_button_new_with_mnemonic ("_Change images");
143 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
144 gtk_widget_show (toggle);
146 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
148 g_signal_connect (toggle, "toggled",
149 G_CALLBACK (timeout_toggle_toggled), icon);
152 gtk_window_present (GTK_WINDOW (dialog));
156 check_activated (GtkCheckMenuItem *item,
159 gtk_status_icon_set_blinking (icon,
160 gtk_check_menu_item_get_active (item));
164 popup_menu (GtkStatusIcon *icon,
166 guint32 activate_time)
168 GtkWidget *menu, *menuitem;
170 menu = gtk_menu_new ();
172 menuitem = gtk_check_menu_item_new_with_label ("Blink");
173 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem),
174 gtk_status_icon_get_blinking (icon));
175 g_signal_connect (menuitem, "activate", G_CALLBACK (check_activated), icon);
177 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
179 gtk_widget_show (menuitem);
181 gtk_menu_popup (GTK_MENU (menu),
182 NULL, NULL, NULL, NULL,
183 button, activate_time);
187 main (int argc, char **argv)
191 gtk_init (&argc, &argv);
193 icon = gtk_status_icon_new ();
196 gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), TRUE);
198 g_signal_connect (icon, "activate",
199 G_CALLBACK (icon_activated), NULL);
201 g_signal_connect (icon, "popup-menu",
202 G_CALLBACK (popup_menu), NULL);
204 timeout = g_timeout_add (2000, timeout_handler, icon);