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