Flexible dbus-wrapper interface
[mdictionary] / src / gui / src / ws_gui.c
1 /*******************************************************************************
2 This file is part of WhiteStork.
3
4 WhiteStork is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 WhiteStork is distributed in the hope that it will be useful, 
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License 
15 along with WhiteStork; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 Copyright 2006 ComArch S.A.
19 *******************************************************************************/
20 #include <ws_gui.h>
21 #include <ws_gui_callbacks.h>
22 #include <ws_gui_layout.h>
23
24 #include <pc-instances.h>
25
26 //int ws_gui_init(int argc, char *argv[])
27 int main(int argc, char *argv[])
28 {
29         if (is_already_running_this_application() > 1)
30         {
31         //       if YES - do not start another one - terminate
32                 g_debug("Another instance of application curently is running\n");
33                 //return 1;
34         }
35         else
36         {
37                 g_debug("OK\n");
38         }
39         
40         
41         gtk_init(&argc, &argv);
42
43         //localization
44         setlocale(LC_ALL, "");
45         bindtextdomain("whitestork", "/usr/share/locale");
46         bind_textdomain_codeset("whitestork", "UTF-8");
47         textdomain("whitestork");
48
49         if (strcmp(_("ws_check"), "ws_check") == 0)
50         {
51                 setlocale(LC_ALL, "en_GB");
52                 bindtextdomain("whitestork", "/usr/share/locale");
53                 bind_textdomain_codeset("whitestork", "UTF-8");
54                 textdomain("whitestork");
55         }
56
57
58         WSGuiApp *ws_gui_app;
59         ws_gui_app = (WSGuiApp*)g_malloc(sizeof(WSGuiApp)); 
60
61         //memory allocation
62         ws_gui_app->ws_gui_w_list = 
63                 (struct WSGuiList*)g_malloc(sizeof(struct WSGuiList));
64         ws_gui_app->ws_gui_menu = 
65                 (struct WSGuiMenu*)g_malloc(sizeof(struct WSGuiMenu));
66
67         //gonf
68         ws_gui_app->client = gconf_client_get_default();
69
70         ws_gui_create_window(ws_gui_app);
71         ws_gui_read_adjustment(ws_gui_app);
72
73
74         //dbus wrapper
75         ws_gui_app->dbus_data = ws_dbus_create ("WhiteStorkGui", "v1.0");
76
77         ws_dbus_config (ws_gui_app->dbus_data, 
78                         WS_DBUS_CONFIG_SERVICE,
79                         "org.maemo.WhiteStorkGui");
80         ws_dbus_config (ws_gui_app->dbus_data,
81                         WS_DBUS_CONFIG_OBJECT,
82                         "/org/maemo/WhiteStorkGui");
83         ws_dbus_config (ws_gui_app->dbus_data,
84                         WS_DBUS_CONFIG_IFACE,
85                         "org.maemo.WhiteStorkGui");
86         ws_dbus_config (ws_gui_app->dbus_data,
87                         WS_DBUS_CONFIG_REMOTE_SERVICE,
88                         "org.maemo.WhiteStorkManager");
89         ws_dbus_config (ws_gui_app->dbus_data,
90                         WS_DBUS_CONFIG_REMOTE_OBJECT,
91                         "/org/maemo/WhiteStorkManager");
92         ws_dbus_config (ws_gui_app->dbus_data,
93                         WS_DBUS_CONFIG_REMOTE_IFACE,
94                         "org.maemo.WhiteStorkManager");
95
96         ws_dbus_add_method (ws_gui_app->dbus_data,
97                         "return_words",
98                         WS_DBUS_TYPE_GARRAY,
99                         WS_DBUS_TYPE_INVALID);
100                         
101         ws_dbus_add_method (ws_gui_app->dbus_data,
102                         "return_translations",
103                         WS_DBUS_TYPE_STRING,
104                         WS_DBUS_TYPE_INVALID);
105
106         ws_dbus_add_method (ws_gui_app->dbus_data,
107                         "return_extracted_dict",
108                         WS_DBUS_TYPE_STRING,
109                         WS_DBUS_TYPE_INVALID);
110
111         ws_dbus_add_method (ws_gui_app->dbus_data,
112                         "update_progressbar",
113                         WS_DBUS_TYPE_DOUBLE,
114                         WS_DBUS_TYPE_INVALID);
115
116         ws_dbus_add_method (ws_gui_app->dbus_data,
117                         "signal",
118                         WS_DBUS_TYPE_SIGNAL,
119                         WS_DBUS_TYPE_INVALID);
120
121         ws_dbus_add_method (ws_gui_app->dbus_data,
122                         "search_home_applet",
123                         WS_DBUS_TYPE_STRING,
124                         WS_DBUS_TYPE_INVALID);
125
126         ws_dbus_set_cb (ws_gui_app->dbus_data,
127                         "return_words",
128                         ws_gui_dbus_return_words,
129                         ws_gui_app);
130
131         ws_dbus_set_cb (ws_gui_app->dbus_data,
132                         "return_translations",
133                         ws_gui_dbus_return_translation,
134                         ws_gui_app);
135          ws_dbus_set_cb (ws_gui_app->dbus_data,
136                         "return_extracted_dict",
137                         ws_dbus_server_return_extracted_bzip,
138                         ws_gui_app);
139         ws_dbus_set_cb (ws_gui_app->dbus_data,
140                         "update_progressbar",
141                         ws_dbus_progress_bar,
142                         ws_gui_app);
143         ws_dbus_set_cb (ws_gui_app->dbus_data,
144                         "signal",
145                         ws_gui_signal_hander,
146                         ws_gui_app);
147         /* added by Dariusz Wiechecki - HISA */
148         ws_dbus_set_cb (ws_gui_app->dbus_data,
149                         "search_home_applet",
150                         ws_gui_search_home_handler,
151                         ws_gui_app);
152
153         ws_dbus_connect (ws_gui_app->dbus_data);
154
155         //setting the clipboard
156         ws_gui_app->ws_gui_clipboard = 
157                 gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html),
158                                           GDK_SELECTION_CLIPBOARD);
159
160         //connecting the signals
161         g_signal_connect(G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_view),
162                          "cursor-changed",
163                          G_CALLBACK (ws_gui_view_cursor_changed), 
164                          ws_gui_app);
165
166
167         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window),
168                         "key-press-event",
169                          G_CALLBACK(hildon_key_press_listener),
170                          ws_gui_app);
171         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html),
172                          "button-press-event",
173                          G_CALLBACK(ws_gui_button_press),
174                          ws_gui_app);
175         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html),
176                          "button-release-event",
177                          G_CALLBACK(ws_gui_button_release),
178                          ws_gui_app);
179         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window),
180                          "delete-event",
181                          G_CALLBACK(ws_gui_on_exit),
182                          ws_gui_app);
183
184         ws_dbus_notify(ws_gui_app->dbus_data,
185                        WS_DBUS_ERROR_UNKNOWN);
186
187         gtk_main();
188         
189         return 0;
190 }
191