Code review of GUI module
[mdictionary] / src / gui / include / ws_gui.h
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.h
24  * \brief Definitions of structures used by ws_gui.c
25  *
26  * \author Anna Gadomska \<anna.gadomska\@comarch.com\>
27  * \date 05-11-2007
28  * \version 1.0.0
29  */
30 #ifndef _WS_GUI
31 #define _WS_GUI 
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37
38 #ifdef CHINOOK
39 #include <hildon/hildon-program.h>
40 #include <hildon/hildon-window.h>
41 #include <hildon/hildon-banner.h>
42 #include <hildon/hildon-find-toolbar.h>
43 #include <hildon/hildon-file-chooser-dialog.h>
44 #include <hildon/hildon-caption.h>
45 #else
46 #include <hildon-widgets/hildon-program.h>
47 #include <hildon-widgets/hildon-window.h>
48 #include <hildon-widgets/hildon-banner.h>
49 #include <hildon-widgets/hildon-find-toolbar.h>
50 #include <hildon-fm/hildon-widgets/hildon-file-chooser-dialog.h>
51 #include <hildon-widgets/hildon-caption.h>
52 #endif
53
54 #include <gtk/gtkfilechooser.h>
55 #include <gtk/gtkdialog.h>
56 #include <gdk/gdkkeysyms.h>
57
58 //#include <hildon-widgets/gtk-infoprint.h>
59 #include <gdk/gdkkeysyms.h>
60 #include <gtk/gtk.h>
61 #include <gtkhtml/gtkhtml.h>
62 #include <glib.h>
63 #include <glib/gprintf.h>
64 #include <string.h>
65 #include <stdlib.h>
66 #include <signal.h>
67 #include <sys/time.h>
68
69 #include <ws_services.h>
70 #include <ws_dbus.h>
71
72 #include <gtkhtml/gtkhtml-stream.h>
73 #include <gconf/gconf.h>
74 #include <gconf/gconf-client.h>
75
76 #define ZOOM_MIN 1.000000
77 #define ZOOM_MAX 2.000000
78 #define ZOOM_STEP 0.100000
79 #define ZOOM_DEFAULT 1.300000
80 #define PRESS_TIME 1.0
81 #define HISTORY_LEN 5
82 #define SCROLL_STEP_H 50
83 #define SCROLL_STEP_V 20
84 #define GCONF_PATH "/apps/maemo/mdictionary/dictionaries"
85 #define GCONF_CONF "/apps/maemo/mdictionary/configuration"
86
87
88 #include <libintl.h>
89 #include <locale.h>
90
91 #define _(String) gettext (String)
92 #define WS_GUI_ABS(x) (((x)<0.0)?((-1)*(x)):(x))
93
94 void html_engine_unselect_all(HTMLEngine   *e);
95 void html_engine_block_selection (HTMLEngine   *e);
96 gboolean html_engine_is_selection_active (HTMLEngine *e);
97
98 typedef struct WSGuiAppData WSGuiApp;
99
100 enum
101 {
102   COL_WORD = 0,
103   NUM_COLS
104 };
105
106
107 /** \brief struct which manage layout of html (translation) area
108  *
109  * here are placed all components of application menu and popup menu
110  */
111 struct HtmlLayout {
112 gchar *bg_color;
113 gchar *bg_image;
114 gchar *bg_font_color;
115
116 gchar *th_color;
117 gchar *th_image;
118 gchar *th_font_color;
119
120 gchar *td_color;
121 gchar *td_image;
122 gchar *td_font_color;
123 };
124
125 /** \brief struct which contains components of menu
126  *
127  * here are placed all components of application menu and popup menu
128  */
129 struct WSGuiMenu {
130         /*application menu*/
131         GtkWidget *ws_gui_main_menu; ///< application submenu
132         GtkWidget *ws_gui_menu_dictionaries; ///< dictionaries submenu (managing with the dictionary files)
133         GtkWidget *ws_gui_menu_load_dict; ///<menuitem in dictionaries submenu; load new dictionary file into application
134         GtkWidget *ws_gui_menu_select_dict; ///<menuitem in dictionaries submenu; allow to select which dictionaries are used
135         GtkWidget *ws_gui_menu_remove_dict; ///<menuitem in dictionaries submenu; remove dictionary files which are no longer used
136         GtkWidget *ws_gui_menu_optimize_dict; ///< menuitem used for optimizing dictionaries
137         
138         GtkWidget *ws_gui_menu_bookmarks; ///bookmarks submenu 
139         GtkWidget *ws_gui_menu_open_bookmark; ///menuitem, opens bookmark window
140         GtkWidget *ws_gui_menu_close_bookmark; ///menuitem, closes bookmark window
141         GtkWidget *ws_gui_menu_add_bookmark; ///menuitem used fot adding bookmarks
142         GtkWidget *ws_gui_menu_remove_bookmark; ///menuitem, allows for removing bookmarks
143         
144         GtkWidget *ws_gui_menu_edit; ///< edit submenu(connected with text editing)
145         GtkWidget *ws_gui_menu_copy; ///< menuitem in edit submenu; copy selected text to the clipboard
146         GtkWidget *ws_gui_menu_paste; ///< menuitem in edit submenu; paste content of the clipboard into find toolbar entry
147         GtkWidget *ws_gui_menu_select_all; ///< menuitem in edit submenu; select whole text in the translation (html) area 
148         GtkWidget *ws_gui_menu_view; ///< view submenu
149         GtkWidget *ws_gui_menu_hide_list; ///< menuitem which allows to hide/show words list
150         GtkWidget *ws_gui_menu_zoom_in; ///< menuitem which allows to zoom in text in the translation area
151         GtkWidget *ws_gui_menu_zoom_out; ///< menuitem which allows to zoom out text in the translation area
152         GtkWidget *ws_gui_menu_full_screen; ///< menuitem which allows to switch between fullscreen and normal mode
153         GtkWidget *ws_gui_menu_search; ///< search submenu (connected with searching)
154         GtkWidget *ws_gui_menu_find_word; ///< menuitem which allows to start searching
155         GtkWidget *ws_gui_menu_find_prev; ///< menuitem which allows to find previous word from the history
156         GtkWidget *ws_gui_menu_find_next; ///< menuitem which allows to find next word in the history 
157         GtkWidget *ws_gui_menu_stop; ///< menuitem which stops search
158         GtkWidget *ws_gui_menu_about; ///< menuitem which opens 'about application' dialog window
159         GtkWidget *ws_gui_menu_close; ///< menuitem which closes the application
160         
161         GtkWidget *ws_gui_submenu_0; ///< submenu which is necessaty to build dictionaries submenu
162         GtkWidget *ws_gui_submenu_1; ///< submenu which is necessary to build edit submenu
163         GtkWidget *ws_gui_submenu_2; ///< submenu which is necessary to build view submenu
164         GtkWidget *ws_gui_submenu_3; ///< submenu which is necessary to build search submenu
165         GtkWidget *ws_gui_submenu_4; ///< submenu which is necessary to build search submenu
166         GtkWidget *ws_gui_separator; ///< separator, it is used to provide nice layout
167         
168         /*ws_gui_menu popup*/
169         GtkWidget *ws_gui_popup_menu;  ///< popup menu
170         GtkWidget *ws_gui_popup_search;///< search option, allow to search selected text
171         GtkWidget *ws_gui_popup_bookmark;///< search option, allow to search selected text
172         GtkWidget *ws_gui_popup_edit; ///< edit submenu
173         GtkWidget *ws_gui_popup_submenu; ///< submenu (necessary to create edit submenu)
174         GtkWidget *ws_gui_popup_copy; ///< menuitem which allows to copy selected to the clipboard
175         GtkWidget *ws_gui_popup_paste; ///< menuitem which allows to paste content of the clipboard into find toolbar entry
176         GtkWidget *ws_gui_popup_select_all; ///<menuitem which allows to select whole text in translation area
177         GtkWidget *ws_gui_popup_zoom_in; ///< menuitem which allows to zoom in text in translation area
178         GtkWidget *ws_gui_popup_zoom_out; ///< menuitem which allows to zoom in text in translation area
179         
180         GtkWidget *ws_gui_separator1; ///< separator, it is used to provide nice layout
181         GtkWidget *ws_gui_separator2; ///< separator, it is used to provide nice layout
182 };
183
184 /** \brief struct which contains components of words list
185  *
186  * here are placed all components of words list (inside left scrollwindow)
187  */
188 struct WSGuiList {
189         GtkWidget* ws_gui_list; ///< list which contains words
190         GtkWidget* ws_gui_list_item; ///< item in words list (each word)
191         GtkWidget* ws_gui_list_label; ///< label, necessary to place word in words list
192         
193         GtkObject* ws_gui_list_item_object; ///< object which stores data of selected item (from words list)
194         //gchar* ws_gui_list_item_data_string; ///< variable which stores translation of word (html content)
195
196         GtkListStore* ws_gui_store; ///< list necessary to present words list
197         GtkTreeIter ws_gui_iter; ///< variable necessary to present words list
198         GtkCellRenderer* ws_gui_renderer; ///< variable necessary to draw GtkTree 
199         GtkTreeModel* ws_gui_model; ///< model of GtkTree
200         GtkWidget* ws_gui_view; ///< variable responsible for view of GtkTree
201         GtkTreeSelection* ws_gui_selection; ///< variable necessary to read selection (from words list)
202 };
203
204 /** \brief struct which contains all components of application
205  *
206  * here are placed all components of main window, toolbar, structures responsible for menus and variables responsible for adjustments, words history, banners, message dialogs and everything what user can see and use
207  */
208 struct WSGuiAppData {
209         HildonProgram *ws_gui_hildon_program; ///< handle to hildon program
210         HildonWindow *ws_gui_hildon_window; ///< handle to hildon window
211         gchar *welcome_note; ///< welcome note
212         GtkWidget *ws_gui_html; ///< translation (html) area 
213         GtkWidget *ws_gui_hpane; ///< pane; it allows to divide window into two separate panels
214         HildonFindToolbar *ws_gui_hildon_find_toolbar; ///< find toolbar (placed at the bottom of the window)
215         GtkToolItem *ws_gui_toobar_button_close; ///< close button at the find toolbar
216         GtkToolItem *ws_gui_toobar_button_back; ///< back button at the find toolbar (history navigator)
217         GtkToolItem *ws_gui_toobar_button_forward; ///< next button at the find toolbar (history navigator)
218         GtkToolItem *ws_gui_toobar_button_stop; ///< stop butoon at the find toolbar (allows to stop searching)
219         GtkToolItem *ws_gui_toobar_button_start; ///< stop butoon at the find toolbar (allows to stop searching)
220         GtkWidget *ws_gui_banner_list_searching; ///< banner, displays message that searching is in progress
221         GtkWidget *ws_gui_banner_caching; ///< banner, displays message that caching is in progress
222         GtkWidget *ws_gui_banner_translation_loading; ///< banner, displays message that translation is loading
223         gboolean caching_flag; ///< flag; used when caching is being performed
224         gboolean loading; 
225         gboolean stop_clicked; 
226         GtkWidget *ws_gui_banner_extracting;
227         GtkToolItem *ws_gui_toobar_button_hide; ///< button hide, allows to hide/show words list with button placed at find toolbar
228         GtkWidget *ws_gui_scrolledwindow_right; ///< right scrolledwindow (placed in right pane), necessary to provide scrollbars)
229         GtkWidget *ws_gui_scrolledwindow_left; ///< scrollwindow (placed in left pane), necessary to provide scrollbars)
230
231         GtkWidget *ws_gui_list_vbox;
232         GtkWidget *ws_gui_list_hbox;
233         GtkWidget *ws_gui_list_label;
234         GtkWidget *ws_gui_list_eventbox;
235         GtkWidget *ws_gui_list_image;
236
237         gchar *ws_gui_html_source; ///< string which contains html content (translation of word)
238         
239         GtkAdjustment* ws_gui_vadj; ///< vertical adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
240         GtkAdjustment* ws_gui_hadj; ///< horizontal adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
241         gdouble v_delta; ///< variable used for moving vertical scrollbar in words list
242         gdouble v_new_value; ///< variable used for moving vertical scrollbar in words list
243         gdouble h_delta; ///< variable used for moving horizontal scrollbar in words list
244         gdouble h_new_value; ///< variable used for moving horizontal scrollbar in words list
245         gdouble cur_vadj; ///< current vertical adjustment of vertical scrollbar in words list
246         gdouble prev_vadj; ///< previous vertical adjustment of vertical scrollbar in words list
247         gdouble cur_hadj; ///< current vertical adjustment of horizontal scrollbar in words list
248         gdouble prev_hadj; ///< previous vertical adjustment of horizontal scrollbar in words list
249         
250         GArray *ws_gui_history; ///< words history
251         GArray *ws_gui_history_list;
252         GArray *ws_gui_history_iter;
253         GArray *ws_gui_history_bookmarks;
254         gboolean history_flag;
255         gint ws_gui_history_cur_pos; ///< current position in words history array 
256         
257
258         struct WSGuiMenu *ws_gui_menu; ///< structure responsible for menus
259         struct WSGuiList *ws_gui_w_list; ///< structure responsible for words list
260         
261         gboolean ws_gui_banner_flag; ///< flag; used for notifing if searching is in progress and banner has to be displaying
262         gboolean ws_gui_full_screen_flag; ///< flag; used for informing if fullscreen mode is active
263         gboolean ws_gui_double_click; ///< flag; necessary to recognize double click
264         gboolean ws_gui_sel_flag; ///< flag; used to identify selected text
265         
266         WSDBusData *dbus_data; ///< DBUS declaration
267         
268         GtkWidget* ws_message_dialog; ///< message dialogs; used for informing user about errors
269         
270         GSList *directories; ///< list consist of directories previously read from gconf
271         GSList *directories_last; ///< list consist of directories previously read from gconf
272         GConfClient *client; ///< variable necessary to read from gconf
273         GtkClipboard *ws_gui_clipboard; ///< application clipboard (available outside the application as well)
274         GtkClipboard *ws_gui_clipboard_primary;
275         PangoFontDescription* p; ///< schema, which allows to format text on widgets
276         GtkWidget *licence_dialog; ///< variable necessary to create license dialog
277         GTimer *timer; ///< timer, counts how long user press button (stylus)
278         GArray *bookmarks_list; ///< array wchich contains bookmarked words
279         gboolean bookmark_on; ///< flag which switch beetween bookmark and normal mode
280         gchar *word_book; ///< word added to the bookmarks
281         gchar *translation_book; ///< translation of the word added to bookmarks
282         
283         gboolean bookmark_avail; ///< flag, denpends on availablity of bookmarks module
284         gboolean bookmark_mode; ///< flag, shows either bookmarks mode is on or off
285         gchar *last_word; ///< stores last choosen word on the words list (necessary for bookmarks)
286         GString *raw_translation; ///< stores current translation, if user wants to add it to bookmarks
287         gchar *last_searched;
288         gchar *last_searched_in_book;
289         gdouble zoom;
290         gboolean html_flag;
291         gboolean no_words_found;
292         
293         gboolean first_run;
294
295 };
296
297 #ifdef __cplusplus
298 }
299 #endif
300
301 #endif