/[sido]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations)
Thu Apr 29 13:50:38 2010 UTC (10 years, 6 months ago) by ben
File MIME type: text/plain
File size: 8100 byte(s)
bugfix for volume window focus out
1 /*
2 * callbacks.c Copyright © 2009 by Benoît Rouits <brouits@free.fr>
3 * Published under the terms of the GNU General Public License v2 (GPLv2).
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 * see the COPYING file included in the jackie package or
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt for the full licence
22 *
23 */
24
25 #include <gtk/gtk.h>
26 #include <libintl.h>
27 #include <locale.h>
28 #include "controller.h"
29 #include "menu.h"
30 #include "about.h"
31 #include "version.h"
32 #define _(string) gettext (string)
33
34 /* refresh the tooltip */
35 gboolean tooltip_display (gpointer app_data) {
36 AppData* d = (AppData*) app_data;
37 gchar* tooltip;
38
39 tooltip = mpd_get_song(d->sock);
40 gtk_status_icon_set_tooltip(d->status_icon, tooltip);
41 g_free(tooltip);
42 return TRUE;
43 }
44
45 /* handler for the volume button drag */
46 void volume_on_change (GtkWidget* instance, gpointer app_data) {
47 gchar* cmd = NULL;
48 gdouble value = 0;
49 AppData* d = (AppData*) app_data;
50
51 value = gtk_range_get_value(GTK_RANGE(d->volume));
52 cmd = g_strdup_printf ("setvol %.0f", value);
53 mpd_control (d->sock, cmd);
54 g_free (cmd);
55 instance = NULL;
56 }
57
58 /* handler for volume slider leaving (close) */
59 gboolean volume_on_leave (GtkWidget* instance, GdkEventFocus* event, gpointer app_data)
60 {
61 AppData* d = (AppData*) app_data;
62
63 gtk_widget_hide (d->vol_window);
64 gtk_widget_destroy (d->vol_window);
65 d->vol_window = NULL;
66 instance = NULL;
67 event = NULL;
68 return FALSE;
69 }
70
71 /* handler for left-button click */
72 void status_icon_on_left_click(GtkStatusIcon* instance, gpointer app_data) {
73 AppData* d = (AppData*) app_data;
74 gdouble curvol;
75
76 if (NULL != d->vol_window) /* already set up */
77 return;
78 d->vol_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
79 gtk_window_set_decorated (GTK_WINDOW(d->vol_window), FALSE);
80 gtk_window_set_default_size(GTK_WINDOW(d->vol_window), 25, 128);
81 gtk_window_set_position(GTK_WINDOW(d->vol_window), GTK_WIN_POS_MOUSE);
82 d->volume = gtk_vscale_new_with_range (0, 100, 1);
83 gtk_range_set_inverted(GTK_RANGE(d->volume), TRUE);
84 curvol = mpd_get_vol(d->sock);
85 gtk_range_set_value(GTK_RANGE(d->volume), curvol);
86 gtk_container_add (GTK_CONTAINER(d->vol_window), d->volume);
87 g_signal_connect(G_OBJECT(d->volume), "value-changed", G_CALLBACK(volume_on_change), app_data);
88 g_signal_connect(G_OBJECT(d->volume), "focus-out-event", G_CALLBACK(volume_on_leave), app_data);
89 gtk_widget_show_all(d->vol_window);
90 instance = NULL;
91 }
92
93 /* handler for right-button click */
94 void status_icon_on_right_click(GtkStatusIcon* instance, guint button, guint activate_time, gpointer app_data) {
95 AppData* d = (AppData*) app_data;
96
97 if (app_data)
98 menu_show (GTK_MENU(d->right_menu), button, activate_time);
99 instance = NULL;
100 }
101
102 /* handler for the "Play" menu item */
103 void menu_item_on_play(GtkMenuItem* instance, gpointer app_data) {
104 AppData* d = (AppData*) app_data;
105
106 mpd_control(d->sock, "play");
107 instance = NULL;
108 }
109
110 /* handler for the "Pause" menu item */
111 void menu_item_on_pause(GtkMenuItem* instance, gpointer app_data) {
112 AppData* d = (AppData*) app_data;
113
114 mpd_control(d->sock, "pause");
115 instance = NULL;
116 }
117
118 void menu_item_on_next(GtkMenuItem* instance, gpointer app_data) {
119 AppData* d = (AppData*) app_data;
120
121 mpd_control(d->sock, "next");
122 instance = NULL;
123 }
124
125 void menu_item_on_prev(GtkMenuItem* instance, gpointer app_data) {
126 AppData* d = (AppData*) app_data;
127
128 mpd_control(d->sock, "previous");
129 instance = NULL;
130 }
131
132 void menu_item_on_stop(GtkMenuItem* instance, gpointer app_data) {
133 AppData* d = (AppData*) app_data;
134
135 mpd_control(d->sock, "stop");
136 instance = NULL;
137 }
138
139 void menu_item_on_shuffle(GtkMenuItem* instance, gpointer app_data) {
140 AppData* d = (AppData*) app_data;
141
142 mpd_control(d->sock, "shuffle");
143 instance = NULL;
144 }
145
146 /* handler for the "About" menu item (see version.h) */
147 void menu_item_on_about(GtkMenuItem* instance, gpointer unused) {
148 GtkAboutDialog* about;
149 const gchar* authors [] = {
150 PROG_AUTHOR0,
151 NULL
152 };
153
154 about = about_create (PROG_NAME, PROG_VERSION, PROG_COPYRIGHT,
155 PROG_COMMENT, PROG_LICENSE, PROG_WEBSITE,
156 authors);
157 about_show (about);
158 unused = NULL; /* avoid compiler warnings */
159 instance = NULL; /* _ */
160 return;
161 }
162
163 /* callback on Preferences window closed */
164 void pref_window_on_close (gpointer app_data) {
165 AppData* d = (AppData*) app_data;
166
167 g_free(d->ip);
168 d->ip = g_strdup (gtk_entry_get_text(d->ip_entry));
169
170 d->port = gtk_spin_button_get_value_as_int (d->port_spin);
171
172 /* write it to $HOME/.fala */
173 write_config (d);
174 gtk_widget_hide (GTK_WIDGET(d->pref_window));
175 gtk_widget_destroy (GTK_WIDGET(d->pref_window));
176 gtk_widget_set_sensitive (GTK_WIDGET(d->pref_item), TRUE);
177 d->pref_window = NULL;
178 mpd_disconnect (d->sock);
179 d->sock = -1;
180 d->sock = mpd_connect (d->ip, d->port);
181 }
182
183 /* handler for the "Preference" menu item */
184 void menu_item_on_pref(GtkMenuItem* instance, gpointer app_data) {
185 AppData* d = (AppData*) app_data;
186 GtkVBox* vbox;
187 GtkHBox* hbox1;
188 GtkHBox* hbox2;
189 GtkHBox* hbox3;
190 GtkLabel* ip_label;
191 GtkLabel* port_label;
192 GtkLabel* empty_label;
193 GtkButton* close_button;
194
195 d->pref_window = GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL));
196 gtk_window_set_title (GTK_WINDOW(d->pref_window), _("Preferences"));
197 gtk_window_set_default_size (GTK_WINDOW(d->pref_window), 300, 200);
198 gtk_window_set_resizable (GTK_WINDOW(d->pref_window), TRUE);
199
200 vbox = GTK_VBOX(gtk_vbox_new (TRUE, 0));
201 gtk_container_add (GTK_CONTAINER(d->pref_window), GTK_WIDGET(vbox));
202
203 hbox1 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
204 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox1), TRUE, FALSE, 10);
205
206 hbox2 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
207 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox2), TRUE, FALSE, 10);
208
209 hbox3 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
210 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox3), TRUE, FALSE, 10);
211
212 ip_label = GTK_LABEL(gtk_label_new (_("MPD IP Address:")));
213 gtk_box_pack_start (GTK_BOX(hbox1), GTK_WIDGET(ip_label), TRUE, FALSE, 10);
214 port_label = GTK_LABEL(gtk_label_new (_("MPD TCP Port:")));
215 gtk_box_pack_start (GTK_BOX(hbox2), GTK_WIDGET(port_label), TRUE, FALSE, 10);
216
217 d->ip_entry = GTK_ENTRY(gtk_entry_new ());
218 gtk_entry_set_max_length (d->ip_entry, 15);
219 gtk_entry_set_width_chars (d->ip_entry, 15);
220 gtk_entry_set_text (d->ip_entry, d->ip); /* MPD ip address */
221 gtk_box_pack_start( GTK_BOX(hbox1), GTK_WIDGET(d->ip_entry), TRUE, FALSE, 10);
222 d->port_spin = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range (1, 65535, 1));
223 gtk_spin_button_set_value (d->port_spin, (gdouble)d->port); /* MPD tcp port */
224 gtk_box_pack_start (GTK_BOX(hbox2), GTK_WIDGET(d->port_spin), TRUE, FALSE, 10);
225
226 empty_label = GTK_LABEL(gtk_label_new (""));
227 gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(empty_label), TRUE, FALSE, 10);
228
229 close_button = GTK_BUTTON(gtk_button_new_from_stock (GTK_STOCK_CLOSE));
230 gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(close_button), FALSE, FALSE, 10);
231
232 g_signal_connect_swapped (G_OBJECT(close_button), "clicked", G_CALLBACK(pref_window_on_close), (gpointer)d);
233 g_signal_connect_swapped (G_OBJECT(d->pref_window), "delete-event", G_CALLBACK(pref_window_on_close), (gpointer)d);
234
235 gtk_widget_show_all (GTK_WIDGET(d->pref_window));
236 gtk_widget_set_sensitive (GTK_WIDGET(instance), FALSE);
237 }
238
239 /* handler for the "Quit" menu item */
240 void menu_item_on_quit(GtkMenuItem* instance, gpointer app_data) {
241 AppData* d = (AppData*) app_data;
242 quit (d);
243 instance = NULL; /* useless but does not warn at compile time */
244 }
245

  ViewVC Help
Powered by ViewVC 1.1.26