/[sido]/sido.c
ViewVC logotype

Contents of /sido.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (show annotations)
Sat Oct 17 00:31:21 2009 UTC (8 years, 1 month ago) by ben
File MIME type: text/plain
File size: 4133 byte(s)
only one instance of volume control
1 /* sido.c
2 *
3 * Copyright 2009 Benoit Rouits <brouits@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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, Boston,
18 * MA 02110-1301, USA.
19 */
20
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <gtk/gtk.h>
24 #include <libintl.h>
25 #include <locale.h>
26 #include "callbacks.h"
27 #include "controller.h"
28 #include "menu.h"
29 #include "version.h"
30 #define _(string) gettext (string)
31
32 int main(int argc, char** argv)
33 {
34 GtkStatusIcon* status_icon = NULL;
35 GtkMenu* right_menu = NULL;
36 const gchar* const * data_dirs;
37 gchar* icon_path = NULL;
38 AppData* app_data = NULL;
39 int i;
40
41 app_data = (AppData*) malloc (sizeof(AppData));
42 app_data->config_path = NULL;
43 app_data->ip = g_strdup("127.0.0.1");
44 app_data->port = 6600;
45 app_data->sock = -1;
46 app_data->right_menu = NULL;
47 app_data->status_icon = NULL;
48 app_data->pref_window = NULL;
49 app_data->ip_entry = NULL;
50 app_data->port_spin = NULL;
51 app_data->pref_item = NULL;
52 app_data->volume = NULL;
53 app_data->vol_window = NULL;
54
55 /* internationalization */
56 setlocale ( LC_ALL, "" );
57 bindtextdomain ("sido", LOCALEDIR);
58 textdomain ( "sido" );
59
60 /* set $HOME/.sido as config file */
61 app_data->config_path = g_build_path ("/", g_get_home_dir(), ".sido", NULL);
62 read_config(app_data);
63
64 gtk_init(&argc, &argv);
65
66 /* search for status icon */
67 data_dirs = g_get_system_data_dirs();
68 for (i = 0; data_dirs[i]; ++i) {
69 icon_path = g_strconcat (data_dirs[i],"/icons/sido.png", NULL);
70 if (g_file_test (icon_path, G_FILE_TEST_EXISTS)) {
71 break;
72 }
73 g_free(icon_path);
74 icon_path = NULL;
75 }
76 if (!icon_path) {
77 g_error("no icon found");
78 return 1;
79 }
80
81 /* create right-click menu */
82 right_menu = menu_new();
83 app_data->right_menu = right_menu;
84
85 status_icon = gtk_status_icon_new();
86 app_data->status_icon = status_icon;
87 gtk_status_icon_set_from_file(status_icon, icon_path);
88 gtk_window_set_default_icon_from_file(icon_path, NULL);
89 g_free(icon_path);
90 gtk_status_icon_set_tooltip(status_icon, "Sido");
91 gtk_status_icon_set_visible(status_icon, TRUE);
92
93 g_signal_connect(G_OBJECT(status_icon), "activate",
94 G_CALLBACK(status_icon_on_left_click), app_data);
95 g_signal_connect(G_OBJECT(status_icon), "popup-menu",
96 G_CALLBACK(status_icon_on_right_click), app_data);
97
98 /* right menu items callbacks */
99 menu_append_image_item(right_menu, GTK_STOCK_MEDIA_PLAY, G_CALLBACK(menu_item_on_play), app_data);
100 menu_append_image_item(right_menu, GTK_STOCK_MEDIA_PAUSE, G_CALLBACK(menu_item_on_pause), app_data);
101 menu_append_image_item(right_menu, GTK_STOCK_MEDIA_NEXT, G_CALLBACK(menu_item_on_next), app_data);
102 menu_append_image_item(right_menu, GTK_STOCK_MEDIA_PREVIOUS, G_CALLBACK(menu_item_on_prev), app_data);
103 menu_append_image_item(right_menu, GTK_STOCK_MEDIA_STOP, G_CALLBACK(menu_item_on_stop), app_data);
104 menu_append_item(right_menu, _("Shuffle"), G_CALLBACK(menu_item_on_shuffle), app_data);
105 app_data->pref_item = menu_append_image_item(right_menu, GTK_STOCK_PREFERENCES, G_CALLBACK(menu_item_on_pref), app_data);
106 menu_append_image_item(right_menu, GTK_STOCK_ABOUT, G_CALLBACK(menu_item_on_about), app_data);
107 menu_append_image_item(right_menu, GTK_STOCK_QUIT, G_CALLBACK(menu_item_on_quit), app_data);
108
109 app_data->sock = mpd_connect(app_data->ip, app_data->port);
110 g_timeout_add_seconds(3, tooltip_display, (gpointer)app_data);
111
112 gtk_main();
113
114 mpd_disconnect(app_data->sock);
115 free (app_data);
116 return 0;
117 }

  ViewVC Help
Powered by ViewVC 1.1.26