Code review of GUI module
[mdictionary] / src / gui / src / ws_gui.c
1 /*******************************************************************************
2 This file is part of mdictionary.
3
4 mdictionary 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 mdictionary 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 mdictionary; 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 /** \addtogroup GUI
21  */
22 /*@{*/
23 /** \file ws_gui.c
24  * \brief Main GUI file.
25  *
26  * GUI main loop and basic configuration of gui modules.
27  * \author Anna Gadomska \<anna.gadomska\@comarch.com\>
28  * \date 05-11-2007
29  * \version 1.0.0
30  */
31
32 #include <ws_gui.h>
33 #include <ws_gui_callbacks.h>
34 #include <ws_gui_layout.h>
35
36 //int ws_gui_init(int argc, char *argv[])
37 int main(int argc, char *argv[])
38 {
39         
40         
41         gtk_init(&argc, &argv);
42
43         //localization
44         setlocale(LC_ALL, "");
45         bindtextdomain(PACKAGE, LOCALEDIR);
46         bind_textdomain_codeset(PACKAGE, "UTF-8");
47         textdomain(PACKAGE);
48
49         if (strcmp(_("ws_check"), "ws_check") == 0)
50         {
51                 setlocale(LC_ALL, "en_GB");
52                 bindtextdomain(PACKAGE, LOCALEDIR);
53                 bind_textdomain_codeset(PACKAGE, "UTF-8");
54                 textdomain(PACKAGE);
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         /*gconf*/
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 ("mdictionaryGui", "v1.0");
76
77         /*dbus wrapper configuration*/
78         ws_dbus_config (ws_gui_app->dbus_data, 
79                         WS_DBUS_CONFIG_SERVICE,
80                         GUI_SERVICE);
81         ws_dbus_config (ws_gui_app->dbus_data,
82                         WS_DBUS_CONFIG_OBJECT,
83                         GUI_OBJECT);
84         ws_dbus_config (ws_gui_app->dbus_data,
85                         WS_DBUS_CONFIG_IFACE,
86                         GUI_IFACE);
87         ws_dbus_config (ws_gui_app->dbus_data,
88                         WS_DBUS_CONFIG_REMOTE_SERVICE,
89                         MANAGER_SERVICE);
90         ws_dbus_config (ws_gui_app->dbus_data,
91                         WS_DBUS_CONFIG_REMOTE_OBJECT,
92                         MANAGER_OBJECT);
93         ws_dbus_config (ws_gui_app->dbus_data,
94                         WS_DBUS_CONFIG_REMOTE_IFACE,
95                         MANAGER_IFACE);
96
97         //Add a list of remote methods available
98         ws_dbus_add_method (ws_gui_app->dbus_data,
99                         "return_words",
100                         WS_DBUS_TYPE_GARRAY,
101                         WS_DBUS_TYPE_INVALID);
102                         
103         ws_dbus_add_method (ws_gui_app->dbus_data,
104                         "return_translations",
105                         WS_DBUS_TYPE_STRING,
106                         WS_DBUS_TYPE_INVALID);
107
108         ws_dbus_add_method (ws_gui_app->dbus_data,
109                         "return_extracted_dict",
110                         WS_DBUS_TYPE_STRING,
111                         WS_DBUS_TYPE_INVALID);
112
113         ws_dbus_add_method (ws_gui_app->dbus_data,
114                         "update_progressbar",
115                         WS_DBUS_TYPE_DOUBLE,
116                         WS_DBUS_TYPE_INVALID);
117
118         ws_dbus_add_method (ws_gui_app->dbus_data,
119                         "signal",
120                         WS_DBUS_TYPE_SIGNAL,
121                         WS_DBUS_TYPE_INVALID);
122
123         ws_dbus_add_method (ws_gui_app->dbus_data,
124                         "search_home_applet",
125                         WS_DBUS_TYPE_STRING,
126                         WS_DBUS_TYPE_INVALID);
127
128         //setting callbacks for local methods
129         ws_dbus_set_cb (ws_gui_app->dbus_data,
130                         "return_words",
131                         ws_gui_dbus_return_words,
132                         ws_gui_app);
133
134         ws_dbus_set_cb (ws_gui_app->dbus_data,
135                         "return_translations",
136                         ws_gui_dbus_return_translation,
137                         ws_gui_app);
138         ws_dbus_set_cb (ws_gui_app->dbus_data,
139                         "return_extracted_dict",
140                         ws_dbus_server_return_extracted_bzip,
141                         ws_gui_app);
142         ws_dbus_set_cb (ws_gui_app->dbus_data,
143                         "update_progressbar",
144                         ws_dbus_progress_bar,
145                         ws_gui_app);
146         ws_dbus_set_cb (ws_gui_app->dbus_data,
147                         "signal",
148                         ws_gui_signal_hander,
149                         ws_gui_app);
150         /*hisa*/
151         ws_dbus_set_cb (ws_gui_app->dbus_data,
152                         "search_home_applet",
153                         ws_gui_search_home_handler,
154                         ws_gui_app);
155
156         ws_dbus_connect (ws_gui_app->dbus_data);
157
158         /*setting the clipboard*/
159         ws_gui_app->ws_gui_clipboard = 
160                 gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html),
161                                         GDK_SELECTION_CLIPBOARD);
162
163         /*connecting the signals*/
164         g_signal_connect(G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_view),
165                         "cursor-changed",
166                         G_CALLBACK (ws_gui_view_cursor_changed), 
167                         ws_gui_app);
168
169
170         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window),
171                         "key-press-event",
172                         G_CALLBACK(hildon_key_press_listener),
173                         ws_gui_app);
174         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html),
175                         "button-press-event",
176                         G_CALLBACK(ws_gui_button_press),
177                         ws_gui_app);
178         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html),
179                         "button-release-event",
180                         G_CALLBACK(ws_gui_button_release),
181                         ws_gui_app);
182         
183         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_list_eventbox),
184                         "button-press-event",
185                         G_CALLBACK(ws_gui_list_full_dialog),
186                         ws_gui_app);
187         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window),
188                         "delete-event",
189                         G_CALLBACK(ws_gui_on_exit),
190                         ws_gui_app);
191
192         ws_dbus_notify(ws_gui_app->dbus_data,
193                 WS_DBUS_ERROR_UNKNOWN);
194
195         gtk_main();
196         
197         return 0;
198 }
199