1 |
/* gluid.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 "utils.h" |
27 |
#include "callbacks.h" |
28 |
#include "type.h" |
29 |
#include "menu.h" |
30 |
#include "version.h" |
31 |
#define _(string) gettext (string) |
32 |
|
33 |
int main(int argc, char** argv) |
34 |
{ |
35 |
GtkStatusIcon* status_icon = NULL; |
36 |
GtkMenu* right_menu = NULL; |
37 |
const gchar* const * data_dirs; |
38 |
gchar* icon_path = NULL; |
39 |
AppData* app_data = NULL; |
40 |
int i; |
41 |
|
42 |
app_data = (AppData*) malloc (sizeof(AppData)); |
43 |
app_data->config_path = NULL; |
44 |
app_data->right_menu = NULL; |
45 |
app_data->status_icon = NULL; |
46 |
app_data->pref_window = NULL; |
47 |
app_data->settings = NULL; |
48 |
app_data->synth = NULL; |
49 |
app_data->adriver = NULL; |
50 |
app_data->mdriver = NULL; |
51 |
app_data->router = NULL; |
52 |
app_data->pref_item = NULL; |
53 |
app_data->reverb_btn = NULL; |
54 |
app_data->chorus_btn = NULL; |
55 |
app_data->reverb = NULL; |
56 |
app_data->chorus = NULL; |
57 |
|
58 |
/* internationalization */ |
59 |
setlocale ( LC_ALL, "" ); |
60 |
bindtextdomain ("gluid", LOCALEDIR); |
61 |
textdomain ( "gluid" ); |
62 |
|
63 |
/* set $HOME/.gluid as config file */ |
64 |
app_data->config_path = g_build_path ("/", g_get_home_dir(), ".gluid", NULL); |
65 |
read_config(app_data); |
66 |
|
67 |
gtk_init(&argc, &argv); |
68 |
|
69 |
/* search for status icon */ |
70 |
data_dirs = g_get_system_data_dirs(); |
71 |
for (i = 0; data_dirs[i]; ++i) { |
72 |
icon_path = g_strconcat (data_dirs[i],"/icons/gluid.png", NULL); |
73 |
if (g_file_test (icon_path, G_FILE_TEST_EXISTS)) { |
74 |
break; |
75 |
} |
76 |
g_free(icon_path); |
77 |
icon_path = NULL; |
78 |
} |
79 |
if (!icon_path) { |
80 |
g_error("no icon found"); |
81 |
return 1; |
82 |
} |
83 |
|
84 |
/* create right-click menu */ |
85 |
right_menu = menu_new(); |
86 |
app_data->right_menu = right_menu; |
87 |
|
88 |
status_icon = gtk_status_icon_new(); |
89 |
app_data->status_icon = status_icon; |
90 |
gtk_status_icon_set_from_file(status_icon, icon_path); |
91 |
gtk_window_set_default_icon_from_file(icon_path, NULL); |
92 |
g_free(icon_path); |
93 |
gtk_status_icon_set_tooltip(status_icon, "Gluid"); |
94 |
gtk_status_icon_set_visible(status_icon, TRUE); |
95 |
|
96 |
g_signal_connect(G_OBJECT(status_icon), "activate", |
97 |
G_CALLBACK(status_icon_on_left_click), app_data); |
98 |
g_signal_connect(G_OBJECT(status_icon), "popup-menu", |
99 |
G_CALLBACK(status_icon_on_right_click), app_data); |
100 |
|
101 |
/* right menu items callbacks */ |
102 |
menu_append_item(right_menu, _("Start"), G_CALLBACK(menu_item_on_startstop), app_data); |
103 |
app_data->pref_item = menu_append_image_item(right_menu, GTK_STOCK_PREFERENCES, G_CALLBACK(menu_item_on_pref), app_data); |
104 |
menu_append_image_item(right_menu, GTK_STOCK_ABOUT, G_CALLBACK(menu_item_on_about), app_data); |
105 |
menu_append_image_item(right_menu, GTK_STOCK_QUIT, G_CALLBACK(menu_item_on_quit), app_data); |
106 |
|
107 |
gtk_main(); |
108 |
free (app_data); |
109 |
return 0; |
110 |
} |