1 /*******************************************************************************
2 This file is part of WhiteStork.
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.
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.
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
18 Copyright 2006 ComArch S.A.
19 *******************************************************************************/
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>
38 #include <hildon-widgets/gtk-infoprint.h>
39 #include <gdk/gdkkeysyms.h>
41 #include <gtkhtml/gtkhtml.h>
43 #include <glib/gprintf.h>
51 #include <gtkhtml/gtkhtml-stream.h>
52 #include <gconf/gconf.h>
53 #include <gconf/gconf-client.h>
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
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"
70 #define _(String) gettext (String)
71 #define WS_GUI_ABS(x) (((x)<0.0)?((-1)*(x)):(x))
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);
77 typedef struct WSGuiAppData WSGuiApp;
86 /** \brief struct which manage layout of html (translation) area
88 * here are placed all components of application menu and popup menu
101 gchar *td_font_color;
104 /** \brief struct which contains components of menu
106 * here are placed all components of application menu and popup 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
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
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
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
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
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
163 /** \brief struct which contains components of words list
165 * here are placed all components of words list (inside left scrollwindow)
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
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)
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)
186 /** \brief struct which contains all components of application
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
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 GtkWidget *ws_gui_banner_extracting;
205 GtkToolItem *ws_gui_toobar_button_hide; ///< button hide, allows to hide/show words list with button placed at find toolbar
206 GtkWidget *ws_gui_scrolledwindow_right; ///< right scrolledwindow (placed in right pane), necessary to provide scrollbars)
207 GtkWidget *ws_gui_scrolledwindow_left; ///< scrollwindow (placed in left pane), necessary to provide scrollbars)
208 gchar *ws_gui_html_source; ///< string which contains html content (translation of word)
210 GtkAdjustment* ws_gui_vadj; ///< vertical adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
211 GtkAdjustment* ws_gui_hadj; ///< horizontal adjustment of left scrolledwindow (necessary to provide navigation (kardware keys) inside words list)
212 gdouble v_delta; ///< variable used for moving vertical scrollbar in words list
213 gdouble v_new_value; ///< variable used for moving vertical scrollbar in words list
214 gdouble h_delta; ///< variable used for moving horizontal scrollbar in words list
215 gdouble h_new_value; ///< variable used for moving horizontal scrollbar in words list
216 gdouble cur_vadj; ///< current vertical adjustment of vertical scrollbar in words list
217 gdouble prev_vadj; ///< previous vertical adjustment of vertical scrollbar in words list
218 gdouble cur_hadj; ///< current vertical adjustment of horizontal scrollbar in words list
219 gdouble prev_hadj; ///< previous vertical adjustment of horizontal scrollbar in words list
221 GArray *ws_gui_history; ///< words history
222 GArray *ws_gui_history_list;
223 GArray *ws_gui_history_iter;
224 GArray *ws_gui_history_bookmarks;
225 gboolean history_flag;
226 gint ws_gui_history_cur_pos; ///< current position in words history array
229 struct WSGuiMenu *ws_gui_menu; ///< structure responsible for menus
230 struct WSGuiList *ws_gui_w_list; ///< structure responsible for words list
232 gboolean ws_gui_banner_flag; ///< flag; used for notifing if searching is in progress and banner has to be displaying
233 gboolean ws_gui_full_screen_flag; ///< flag; used for informing if fullscreen mode is active
234 gboolean ws_gui_double_click; ///< flag; necessary to recognize double click
235 gboolean ws_gui_sel_flag; ///< flag; used to identify selected text
237 WSDBusData *dbus_data; ///< DBUS declaration
239 GtkWidget* ws_message_dialog; ///< message dialogs; used for informing user about errors
241 GSList *directories; ///< list consist of directories previously read from gconf
242 GSList *directories_last; ///< list consist of directories previously read from gconf
243 GConfClient *client; ///< variable necessary to read from gconf
244 GtkClipboard *ws_gui_clipboard; ///< application clipboard (available outside the application as well)
245 GtkClipboard *ws_gui_clipboard_primary;
246 PangoFontDescription* p; ///< schema, which allows to format text on widgets
247 GtkWidget *licence_dialog; ///< variable necessary to create license dialog
248 GTimer *timer; ///< timer, counts how long user press button (stylus)
249 GArray *bookmarks_list; ///< array wchich contains bookmarked words
250 gboolean bookmark_on; ///< flag which switch beetween bookmark and normal mode
251 gchar *word_book; ///< word added to the bookmarks
252 gchar *translation_book; ///< translation of the word added to bookmarks
254 gboolean bookmark_avail; ///< flag, denpends on availablity of bookmarks module
255 gboolean bookmark_mode; ///< flag, shows either bookmarks mode is on or off
256 gchar *last_word; ///< stores last choosen word on the words list (necessary for bookmarks)
257 GString *raw_translation; ///< stores current translation, if user wants to add it to bookmarks
258 gchar *last_searched;
259 gchar *last_searched_in_book;