comparison src/statusicon/si_ui.c @ 433:38fe08dff5cd trunk

[svn] - added status icon plugin (written from scratch, with code from gtk 2.10)
author giacomo
date Mon, 15 Jan 2007 11:54:32 -0800
parents
children 84029a5250c1
comparison
equal deleted inserted replaced
432:1716423d29fe 433:38fe08dff5cd
1 /*
2 *
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "si_ui.h"
22 #include "si_audacious.h"
23 #include "si_common.h"
24 #include "gtktrayicon.h"
25 #include "si.xpm"
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29
30
31 static GtkWidget * si_evbox = NULL;
32
33
34 static GtkTrayIcon *
35 si_ui_statusicon_create ( void )
36 {
37 GtkTrayIcon *si_applet = NULL;
38
39 si_applet = _gtk_tray_icon_new( "audacious" );
40
41 gtk_widget_show( GTK_WIDGET(si_applet) );
42
43 return si_applet;
44 }
45
46
47 static GtkWidget *
48 si_ui_rmenu_create ( GtkWidget * evbox )
49 {
50 GtkWidget *menu;
51 GtkWidget *menuitem;
52
53 menu = gtk_menu_new();
54
55 /* gtk_widget_show_all( GTK_WIDGET(menu) ); */
56 return menu;
57 }
58
59
60 static gboolean
61 si_ui_statusicon_cb_btpress ( GtkWidget * evbox , GdkEventButton * event )
62 {
63 switch ( event->button )
64 {
65 case 1:
66 {
67 si_audacious_toggle_visibility();
68 break;
69 }
70
71 /*
72 case 3:
73 {
74 GtkWidget *si_rmenu = GTK_WIDGET(g_object_get_data( G_OBJECT(evbox) , "rmenu" ));
75 gtk_menu_popup( GTK_MENU(si_rmenu) , NULL , NULL ,
76 NULL , NULL , event->button , event->time );
77 break;
78 }
79 */
80 }
81
82 return FALSE;
83 }
84
85
86 void
87 si_ui_statusicon_show ( void )
88 {
89 GtkWidget *si_image;
90 GtkWidget *si_rmenu;
91 GdkPixbuf *si_pixbuf;
92 GtkTrayIcon *si_applet;
93
94 si_applet = si_ui_statusicon_create();
95 if ( si_applet == NULL )
96 {
97 g_warning( "StatusIcon plugin: unable to create a status icon.\n" );
98 return;
99 }
100
101 si_pixbuf = gdk_pixbuf_new_from_xpm_data( (const char**)si_xpm );
102 si_image = gtk_image_new_from_pixbuf( si_pixbuf );
103 g_object_unref( si_pixbuf );
104
105 si_evbox = gtk_event_box_new();
106 si_rmenu = si_ui_rmenu_create( si_evbox );
107
108 g_object_set_data( G_OBJECT(si_evbox) , "rmenu" , si_rmenu );
109 g_object_set_data( G_OBJECT(si_evbox) , "applet" , si_applet );
110 g_signal_connect( G_OBJECT(si_evbox) , "button-press-event" ,
111 G_CALLBACK(si_ui_statusicon_cb_btpress) , NULL );
112
113 gtk_container_add( GTK_CONTAINER(si_evbox), si_image );
114 gtk_container_add( GTK_CONTAINER(si_applet), si_evbox );
115
116 gtk_widget_show_all( GTK_WIDGET(si_applet) );
117 return;
118 }
119
120
121 void
122 si_ui_statusicon_hide ( void )
123 {
124 if ( si_evbox != NULL )
125 {
126 GtkTrayIcon *si_applet = g_object_get_data( G_OBJECT(si_evbox) , "applet" );
127 GtkWidget *si_rmenu = g_object_get_data( G_OBJECT(si_evbox) , "rmenu" );
128 gtk_widget_destroy( GTK_WIDGET(si_evbox) );
129 gtk_widget_destroy( GTK_WIDGET(si_rmenu) );
130 gtk_widget_destroy( GTK_WIDGET(si_applet) );
131 }
132 return;
133 }
134
135
136 void
137 si_ui_about_show ( void )
138 {
139 GtkWidget *about_dlg = gtk_message_dialog_new(
140 NULL , 0 , GTK_MESSAGE_INFO , GTK_BUTTONS_CLOSE ,
141 _( "Status Icon Plugin " SI_VERSION_PLUGIN "\n"
142 "written by Giacomo Lozito < james@develia.org >\n\n"
143 "This plugin provides a status icon, placed in\n"
144 "the system tray area of the window manager.\n" ) );
145 gtk_dialog_run( GTK_DIALOG(about_dlg) );
146 gtk_widget_destroy( about_dlg );
147 return;
148 }