1 /*******************************************************************************
2 This file is part of mdictionary.
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.
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.
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
18 Copyright 2006 ComArch S.A.
19 *******************************************************************************/
29 #include <hildon/hildon-program.h>
30 #include <hildon/hildon-window.h>
31 #include <hildon/hildon-banner.h>
32 #include <hildon/hildon-find-toolbar.h>
33 #include <hildon/hildon-file-chooser-dialog.h>
34 #include <hildon/hildon-caption.h>
36 #include <hildon-widgets/hildon-program.h>
37 #include <hildon-widgets/hildon-window.h>
38 #include <hildon-widgets/hildon-banner.h>
39 #include <hildon-widgets/hildon-find-toolbar.h>
40 #include <hildon-fm/hildon-widgets/hildon-file-chooser-dialog.h>
41 #include <hildon-widgets/hildon-caption.h>
44 #include <gtk/gtkfilechooser.h>
45 #include <gtk/gtkdialog.h>
46 #include <gdk/gdkkeysyms.h>
48 //#include <hildon-widgets/gtk-infoprint.h>
49 #include <gdk/gdkkeysyms.h>
51 #include <gtkhtml/gtkhtml.h>
53 #include <glib/gprintf.h>
59 #include <ws_services.h>
62 #include <gtkhtml/gtkhtml-stream.h>
63 #include <gconf/gconf.h>
64 #include <gconf/gconf-client.h>
66 #define ZOOM_MIN 1.000000
67 #define ZOOM_MAX 2.000000
68 #define ZOOM_STEP 0.100000
69 #define ZOOM_DEFAULT 1.300000
70 #define PRESS_TIME 1.0
72 #define SCROLL_STEP_H 50
73 #define SCROLL_STEP_V 20
74 #define GCONF_PATH "/apps/maemo/mdictionary/dictionaries"
75 #define GCONF_CONF "/apps/maemo/mdictionary/configuration"
81 #define _(String) gettext (String)
82 #define WS_GUI_ABS(x) (((x)<0.0)?((-1)*(x)):(x))
84 void html_engine_unselect_all(HTMLEngine *e);
85 void html_engine_block_selection (HTMLEngine *e);
86 gboolean html_engine_is_selection_active (HTMLEngine *e);
88 typedef struct WSGuiAppData WSGuiApp;
97 /** \brief struct which manage layout of html (translation) area
99 * here are placed all components of application menu and popup menu
104 gchar *bg_font_color;
108 gchar *th_font_color;
112 gchar *td_font_color;
115 /** \brief struct which contains components of menu
117 * here are placed all components of application menu and popup menu
121 GtkWidget *ws_gui_main_menu; ///< application submenu
122 GtkWidget *ws_gui_menu_dictionaries; ///< dictionaries submenu (managing with the dictionary files)
123 GtkWidget *ws_gui_menu_load_dict; ///<menuitem in dictionaries submenu; load new dictionary file into application
124 GtkWidget *ws_gui_menu_select_dict; ///<menuitem in dictionaries submenu; allow to select which dictionaries are used
125 GtkWidget *ws_gui_menu_remove_dict; ///<menuitem in dictionaries submenu; remove dictionary files which are no longer used
126 GtkWidget *ws_gui_menu_optimize_dict; ///< menuitem used for optimizing dictionaries
128 GtkWidget *ws_gui_menu_bookmarks; ///bookmarks submenu
129 GtkWidget *ws_gui_menu_open_bookmark; ///menuitem, opens bookmark window
130 GtkWidget *ws_gui_menu_close_bookmark; ///menuitem, closes bookmark window
131 GtkWidget *ws_gui_menu_add_bookmark; ///menuitem used fot adding bookmarks
132 GtkWidget *ws_gui_menu_remove_bookmark; ///menuitem, allows for removing bookmarks
134 GtkWidget *ws_gui_menu_edit; ///< edit submenu(connected with text editing)
135 GtkWidget *ws_gui_menu_copy; ///< menuitem in edit submenu; copy selected text to the clipboard
136 GtkWidget *ws_gui_menu_paste; ///< menuitem in edit submenu; paste content of the clipboard into find toolbar entry
137 GtkWidget *ws_gui_menu_select_all; ///< menuitem in edit submenu; select whole text in the translation (html) area
138 GtkWidget *ws_gui_menu_view; ///< view submenu
139 GtkWidget *ws_gui_menu_hide_list; ///< menuitem which allows to hide/show words list
140 GtkWidget *ws_gui_menu_zoom_in; ///< menuitem which allows to zoom in text in the translation area
141 GtkWidget *ws_gui_menu_zoom_out; ///< menuitem which allows to zoom out text in the translation area
142 GtkWidget *ws_gui_menu_full_screen; ///< menuitem which allows to switch between fullscreen and normal mode
143 GtkWidget *ws_gui_menu_search; ///< search submenu (connected with searching)
144 GtkWidget *ws_gui_menu_find_word; ///< menuitem which allows to start searching
145 GtkWidget *ws_gui_menu_find_prev; ///< menuitem which allows to find previous word from the history
146 GtkWidget *ws_gui_menu_find_next; ///< menuitem which allows to find next word in the history
147 GtkWidget *ws_gui_menu_stop; ///< menuitem which stops search
148 GtkWidget *ws_gui_menu_about; ///< menuitem which opens 'about application' dialog window
149 GtkWidget *ws_gui_menu_close; ///< menuitem which closes the application
151 GtkWidget *ws_gui_submenu_0; ///< submenu which is necessaty to build dictionaries submenu
152 GtkWidget *ws_gui_submenu_1; ///< submenu which is necessary to build edit submenu
153 GtkWidget *ws_gui_submenu_2; ///< submenu which is necessary to build view submenu
154 GtkWidget *ws_gui_submenu_3; ///< submenu which is necessary to build search submenu
155 GtkWidget *ws_gui_submenu_4; ///< submenu which is necessary to build search submenu
156 GtkWidget *ws_gui_separator; ///< separator, it is used to provide nice layout
158 /*ws_gui_menu popup*/
159 GtkWidget *ws_gui_popup_menu; ///< popup menu
160 GtkWidget *ws_gui_popup_search;///< search option, allow to search selected text
161 GtkWidget *ws_gui_popup_bookmark;///< search option, allow to search selected text
162 GtkWidget *ws_gui_popup_edit; ///< edit submenu
163 GtkWidget *ws_gui_popup_submenu; ///< submenu (necessary to create edit submenu)
164 GtkWidget *ws_gui_popup_copy; ///< menuitem which allows to copy selected to the clipboard
165 GtkWidget *ws_gui_popup_paste; ///< menuitem which allows to paste content of the clipboard into find toolbar entry
166 GtkWidget *ws_gui_popup_select_all; ///<menuitem which allows to select whole text in translation area
167 GtkWidget *ws_gui_popup_zoom_in; ///< menuitem which allows to zoom in text in translation area
168 GtkWidget *ws_gui_popup_zoom_out; ///< menuitem which allows to zoom in text in translation area
170 GtkWidget *ws_gui_separator1; ///< separator, it is used to provide nice layout
171 GtkWidget *ws_gui_separator2; ///< separator, it is used to provide nice layout
174 /** \brief struct which contains components of words list
176 * here are placed all components of words list (inside left scrollwindow)
179 GtkWidget* ws_gui_list; ///< list which contains words
180 GtkWidget* ws_gui_list_item; ///< item in words list (each word)
181 GtkWidget* ws_gui_list_label; ///< label, necessary to place word in words list
183 GtkObject* ws_gui_list_item_object; ///< object which stores data of selected item (from words list)
184 //gchar* ws_gui_list_item_data_string; ///< variable which stores translation of word (html content)
186 GtkListStore* ws_gui_store; ///< list necessary to present words list
187 GtkTreeIter ws_gui_iter; ///< variable necessary to present words list
188 GtkCellRenderer* ws_gui_renderer; ///< variable necessary to draw GtkTree
189 GtkTreeModel* ws_gui_model; ///< model of GtkTree
190 GtkWidget* ws_gui_view; ///< variable responsible for view of GtkTree
191 GtkTreeSelection* ws_gui_selection; ///< variable necessary to read selection (from words list)
194 /** \brief struct which contains all components of application
196 * 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
198 struct WSGuiAppData {
199 HildonProgram *ws_gui_hildon_program; ///< handle to hildon program
200 HildonWindow *ws_gui_hildon_window; ///< handle to hildon window
201 gchar *welcome_note; ///< welcome note
202 GtkWidget *ws_gui_html; ///< translation (html) area
203 GtkWidget *ws_gui_hpane; ///< pane; it allows to divide window into two separate panels
204 HildonFindToolbar *ws_gui_hildon_find_toolbar; ///< find toolbar (placed at the bottom of the window)
205 GtkToolItem *ws_gui_toobar_button_close; ///< close button at the find toolbar
206 GtkToolItem *ws_gui_toobar_button_back; ///< back button at the find toolbar (history navigator)
207 GtkToolItem *ws_gui_toobar_button_forward; ///< next button at the find toolbar (history navigator)
208 GtkToolItem *ws_gui_toobar_button_stop; ///< stop butoon at the find toolbar (allows to stop searching)
209 GtkToolItem *ws_gui_toobar_button_start; ///< stop butoon at the find toolbar (allows to stop searching)
210 GtkWidget *ws_gui_banner_list_searching; ///< banner, displays message that searching is in progress
211 GtkWidget *ws_gui_banner_caching; ///< banner, displays message that caching is in progress
212 GtkWidget *ws_gui_banner_translation_loading; ///< banner, displays message that translation is loading
213 gboolean caching_flag; ///< flag; used when caching is being performed
215 gboolean stop_clicked;
216 GtkWidget *ws_gui_banner_extracting;
217 GtkToolItem *ws_gui_toobar_button_hide; ///< button hide, allows to hide/show words list with button placed at find toolbar
218 GtkWidget *ws_gui_scrolledwindow_right; ///< right scrolledwindow (placed in right pane), necessary to provide scrollbars)
219 GtkWidget *ws_gui_scrolledwindow_left; ///< scrollwindow (placed in left pane), necessary to provide scrollbars)
221 GtkWidget *ws_gui_list_vbox;
222 GtkWidget *ws_gui_list_hbox;
223 GtkWidget *ws_gui_list_label;
224 GtkWidget *ws_gui_list_eventbox;
225 GtkWidget *ws_gui_list_image;
227 gchar *ws_gui_html_source; ///< string which contains html content (translation of word)
229 GtkAdjustment* ws_gui_vadj; ///< vertical adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
230 GtkAdjustment* ws_gui_hadj; ///< horizontal adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
231 gdouble v_delta; ///< variable used for moving vertical scrollbar in words list
232 gdouble v_new_value; ///< variable used for moving vertical scrollbar in words list
233 gdouble h_delta; ///< variable used for moving horizontal scrollbar in words list
234 gdouble h_new_value; ///< variable used for moving horizontal scrollbar in words list
235 gdouble cur_vadj; ///< current vertical adjustment of vertical scrollbar in words list
236 gdouble prev_vadj; ///< previous vertical adjustment of vertical scrollbar in words list
237 gdouble cur_hadj; ///< current vertical adjustment of horizontal scrollbar in words list
238 gdouble prev_hadj; ///< previous vertical adjustment of horizontal scrollbar in words list
240 GArray *ws_gui_history; ///< words history
241 GArray *ws_gui_history_list;
242 GArray *ws_gui_history_iter;
243 GArray *ws_gui_history_bookmarks;
244 gboolean history_flag;
245 gint ws_gui_history_cur_pos; ///< current position in words history array
248 struct WSGuiMenu *ws_gui_menu; ///< structure responsible for menus
249 struct WSGuiList *ws_gui_w_list; ///< structure responsible for words list
251 gboolean ws_gui_banner_flag; ///< flag; used for notifing if searching is in progress and banner has to be displaying
252 gboolean ws_gui_full_screen_flag; ///< flag; used for informing if fullscreen mode is active
253 gboolean ws_gui_double_click; ///< flag; necessary to recognize double click
254 gboolean ws_gui_sel_flag; ///< flag; used to identify selected text
256 WSDBusData *dbus_data; ///< DBUS declaration
258 GtkWidget* ws_message_dialog; ///< message dialogs; used for informing user about errors
260 GSList *directories; ///< list consist of directories previously read from gconf
261 GSList *directories_last; ///< list consist of directories previously read from gconf
262 GConfClient *client; ///< variable necessary to read from gconf
263 GtkClipboard *ws_gui_clipboard; ///< application clipboard (available outside the application as well)
264 GtkClipboard *ws_gui_clipboard_primary;
265 PangoFontDescription* p; ///< schema, which allows to format text on widgets
266 GtkWidget *licence_dialog; ///< variable necessary to create license dialog
267 GTimer *timer; ///< timer, counts how long user press button (stylus)
268 GArray *bookmarks_list; ///< array wchich contains bookmarked words
269 gboolean bookmark_on; ///< flag which switch beetween bookmark and normal mode
270 gchar *word_book; ///< word added to the bookmarks
271 gchar *translation_book; ///< translation of the word added to bookmarks
273 gboolean bookmark_avail; ///< flag, denpends on availablity of bookmarks module
274 gboolean bookmark_mode; ///< flag, shows either bookmarks mode is on or off
275 gchar *last_word; ///< stores last choosen word on the words list (necessary for bookmarks)
276 GString *raw_translation; ///< stores current translation, if user wants to add it to bookmarks
277 gchar *last_searched;
278 gchar *last_searched_in_book;
281 gboolean no_words_found;