history still need some improovements.
[mdictionary] / src / gui / src / ws_gui_callbacks.c
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 #include <ws_gui_callbacks.h>
21 #include <ws_gui.h>
22 #include <ws_gui_layout.h>
23 #include <ws_dbus.h>
24
25 /** \brief show how much time did take a callback of another function
26  *
27  */
28 static double timer(gboolean start, gchar* message)
29 {
30         static GArray* stack = NULL;
31         static gboolean first_run = TRUE;
32         static struct timeval actual_time;
33         static struct timeval last_time;
34         static struct timeval result;
35         static double seconds = 0.0;
36         if(first_run)
37         {
38                 first_run = FALSE;
39                 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
40         };
41         // things to do on the beggining of function's work
42         if (start)
43         {
44                 g_debug("XDXF->%s() start counting time for function '%s()'.\n",
45                         __FUNCTION__,message);
46                 g_array_prepend_val(stack, actual_time);
47                 gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
48                 return -1.0;
49         }
50         // we just want to end some timer - print some information 
51         //about working time;
52         else {
53                 gettimeofday(&actual_time,NULL);
54                 last_time = g_array_index(stack, struct timeval, 0);
55                 g_array_remove_index(stack, 0);
56
57                 if (actual_time.tv_usec < last_time.tv_usec) {
58                         int nsec = (last_time.tv_usec - 
59                                              actual_time.tv_usec) / 1000000 + 1;
60                         last_time.tv_usec -= 1000000 * nsec;
61                         last_time.tv_sec += nsec;
62                 }
63                 if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
64                         int nsec = (last_time.tv_usec -
65                                                  actual_time.tv_usec) / 1000000;
66                         last_time.tv_usec += 1000000 * nsec;
67                         last_time.tv_sec -= nsec;
68                 }
69                 result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
70                 result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
71                 seconds = (((double)(result.tv_usec)) / 1e6) + 
72                                                       ((double)(result.tv_sec));
73
74                 g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] "
75                         "or %ld [us].\n",
76                         __FUNCTION__,
77                         message,seconds,
78                         ((long)(result.tv_sec*1e6)+(result.tv_usec)));
79                // stack is empty so we delete everything
80                if(stack->len == 0) 
81                {
82                         g_array_free(stack, TRUE);
83                         first_run = TRUE;
84                }
85                return seconds;
86         }
87         return -2.0;
88 }
89
90
91 /**  this function handles signals from dbus; it is called 
92 when there are any messages from other modules
93  *
94  * @param error - error message recived from DBUS
95  * @param words - array with recived data structure
96  * @param user_data - pointer to data structure
97  * @return
98  */
99 void ws_gui_signal_hander (GError *error, GArray *words, gpointer user_data)
100 {
101         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
102         osso_rpc_t osss_data;
103         osss_data = g_array_index (words, osso_rpc_t, 0);
104         switch(osss_data.value.i)
105         {
106                 case WS_DBUS_ERROR_ENGINE_NOT_FOUND:
107                 {
108                         ws_gui_app->ws_message_dialog = 
109                         gtk_message_dialog_new(
110                                    GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
111                                    GTK_DIALOG_DESTROY_WITH_PARENT,
112                                    GTK_MESSAGE_ERROR,
113                                    GTK_BUTTONS_OK,
114                                    _("ws_ni_error_occured"));
115                         gtk_widget_show_all(ws_gui_app->ws_message_dialog);
116
117                         g_signal_connect_swapped(
118                                      GTK_OBJECT (ws_gui_app->ws_message_dialog),
119                                      "response",
120                                      G_CALLBACK (gtk_main_quit),
121                                      ws_gui_app);
122                         break;
123                 }
124
125                 case WS_DBUS_ERROR_FILE_NOT_FOUND:
126                 {
127                         ws_gui_app->ws_message_dialog = 
128                                 gtk_message_dialog_new(
129                                    GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
130                                    GTK_DIALOG_DESTROY_WITH_PARENT,
131                                    GTK_MESSAGE_ERROR,
132                                    GTK_BUTTONS_OK,
133                                    _("ws_ni_no_dictionary_available"));
134
135                         gtk_widget_show_all(ws_gui_app->ws_message_dialog);
136
137                         GArray *tmp;
138                         tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
139                         gtk_list_store_clear(
140                                        ws_gui_app->ws_gui_w_list->ws_gui_store);
141                         ws_gui_app->ws_gui_w_list->ws_gui_model = 
142                                 create_and_fill_model(tmp, ws_gui_app);
143                         ws_gui_fill_html(" ", ws_gui_app);
144                         ws_gui_app->html_flag = FALSE;
145
146                         gtk_widget_set_sensitive(
147                              GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
148                              FALSE);
149                         gtk_widget_set_sensitive(
150                         GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
151                         FALSE);
152
153                         if (gtk_dialog_run(
154                                 GTK_DIALOG(ws_gui_app->ws_message_dialog)) 
155                                                              == GTK_RESPONSE_OK)
156                         {
157                                 gtk_widget_destroy(
158                                                  ws_gui_app->ws_message_dialog);
159                         }
160                         break;
161                 }
162
163                 case WS_DBUS_INFO_CACHING:
164                 {
165                         ws_gui_app->ws_gui_banner_caching =
166                                 hildon_banner_show_progress(
167                                    GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
168                                    NULL,
169                                    _("ws_pb_caching"));
170                        ws_gui_app->caching_flag = TRUE;
171                        hildon_banner_set_fraction(
172                                HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
173                                0.0);
174                        gtk_widget_set_sensitive(
175                              GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
176                              FALSE);
177                        gtk_widget_set_sensitive(
178                         GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
179                         FALSE);
180
181                        break;
182                 }
183
184                 case WS_DBUS_INFO_CACHING_FINISHED:
185                 {
186                         gtk_widget_destroy(
187                                  GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
188                         ws_gui_app->caching_flag = FALSE;
189                         gtk_widget_set_sensitive(
190                              GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
191                              TRUE);
192                         gtk_widget_set_sensitive(
193                        GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
194                        TRUE);
195
196                         break;
197                 }
198
199                 case WS_DBUS_ERROR_DICTIONARY_NOT_LOAD:
200                 {
201                         if (ws_gui_app->ws_gui_history_cur_pos >= 0 &&
202                                ws_gui_app->ws_gui_history_cur_pos <=HISTORY_LEN)
203                         { 
204                                 g_array_remove_index(ws_gui_app->ws_gui_history,
205                                             ws_gui_app->ws_gui_history_cur_pos);
206                         }
207
208                         ws_gui_app->ws_message_dialog = gtk_message_dialog_new(
209                                    GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
210                                    GTK_DIALOG_DESTROY_WITH_PARENT,
211                                    GTK_MESSAGE_ERROR,
212                                    GTK_BUTTONS_OK,
213                                   _("ws_ni_dictionary_unavailable"));
214                        gtk_widget_show_all(ws_gui_app->ws_message_dialog);
215                        if (gtk_dialog_run(
216                        GTK_DIALOG(ws_gui_app->ws_message_dialog)) 
217                                                              == GTK_RESPONSE_OK)
218                        {
219                               gtk_widget_destroy(ws_gui_app->ws_message_dialog);
220                        }
221                        break;
222                 }
223                 
224                 case  WS_DBUS_BOOKMARKS_ADDED_OK:
225                 {
226                         gtk_infoprint(GTK_WINDOW(
227                                         ws_gui_app->ws_gui_hildon_window),
228                                         _("ws_ni_bookmark_added"));
229                 break;
230                 }
231
232                 case WS_DBUS_BOOKMARKS_REMOVED_OK:
233                 {
234                         gtk_infoprint(GTK_WINDOW(
235                                         ws_gui_app->ws_gui_hildon_window),
236                                         _("ws_ni_bookmark_removed"));
237                 break;
238                 }
239         
240                 case WS_DBUS_BOOKMARKS_ADDED_FAIL:
241                 {
242                         gtk_infoprint(GTK_WINDOW(
243                                         ws_gui_app->ws_gui_hildon_window),
244                                         _("ws_ni_bookmark_not_added"));
245                 break;
246                 }
247         
248                 case WS_DBUS_BOOKMARKS_REMOVED_FAIL:
249                 {
250                         gtk_infoprint(GTK_WINDOW(
251                                         ws_gui_app->ws_gui_hildon_window),
252                                         _("ws_ni_bookmark_not_removed"));
253                 break;
254                 }
255
256                 case WS_DBUS_LOAD_BOOKMARK_FAILED:
257                 {
258                      gtk_widget_set_sensitive(
259                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
260                      FALSE);
261                      ws_gui_app->bookmark_avail = FALSE;
262                                 
263                         ws_gui_app->ws_message_dialog = 
264                         gtk_message_dialog_new(
265                                    GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
266                                    GTK_DIALOG_DESTROY_WITH_PARENT,
267                                    GTK_MESSAGE_ERROR,
268                                    GTK_BUTTONS_OK,
269                                    _("ws_ni_bookmarks_unavailable"));
270
271                         if (gtk_dialog_run(
272                                 GTK_DIALOG(ws_gui_app->ws_message_dialog)) 
273                                                              == GTK_RESPONSE_OK)
274                         {
275                                 gtk_widget_destroy(
276                                                  ws_gui_app->ws_message_dialog);
277                         }
278
279                         
280                         break;  
281                 }
282         }
283 }
284 /**  this function handles signals from dbus; it is called when progress bar
285  status has been changed
286  *
287  * @param error - error message recived from DBUS
288  * @param words - array with recived data structure
289  * @param user_data - pointer to data structure
290  * @return
291  */
292 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
293 {
294         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
295         osso_rpc_t osss_data;
296         osss_data = g_array_index (words, osso_rpc_t, 0);
297         double progress = osss_data.value.d;
298         if (ws_gui_app->caching_flag == TRUE)
299         {
300                 hildon_banner_set_fraction(
301                                HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
302                                progress);
303         }
304 }
305
306 /** this function handles signal from dbus and transfer recived 
307 (found in a dictionary) words to the words list
308  *
309  * @param error - error message recived from DBUS
310  * @param words - array with recived data structure
311  * @param user_data - pointer to data structure
312  * @return
313  */
314 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
315 {
316         timer(TIMER_START, (gchar*)__FUNCTION__);
317         guint i;
318         osso_rpc_t data;
319
320         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
321         
322         GArray *tmp;
323         tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
324         gchar *tmp_word;
325
326         for (i=0;i<words->len;++i)
327         {
328                 data = g_array_index (words, osso_rpc_t, i);
329                 tmp_word = g_strconcat(data.value.s,NULL);
330                 g_array_append_val(tmp, tmp_word);
331         }
332         
333         g_assert(ws_gui_app->ws_gui_banner);
334         gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
335         //g_signal_handler_unblock(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263); 
336  
337         ws_gui_app->ws_gui_banner_flag = FALSE;
338         gtk_widget_set_sensitive(
339                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
340                               FALSE);
341         gtk_widget_set_sensitive(
342                           GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
343                           FALSE);
344         gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
345
346         ws_gui_app->ws_gui_w_list->ws_gui_model = 
347                                         create_and_fill_model(tmp, ws_gui_app);
348         
349         if (ws_gui_app->history_flag == TRUE)
350         {
351         if (gtk_tree_model_get_iter_from_string
352                                   (GTK_TREE_MODEL(
353                                   ws_gui_app->ws_gui_w_list->ws_gui_model),
354                                   &ws_gui_app->ws_gui_w_list->ws_gui_iter,
355                                   g_array_index(ws_gui_app->ws_gui_history_iter,
356                                   gchar*, 
357                                   ws_gui_app->ws_gui_history_cur_pos)) == TRUE);
358         {
359         
360         g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n\nString from iter: %s", gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(
361                                 ws_gui_app->ws_gui_w_list->ws_gui_model), &ws_gui_app->ws_gui_w_list->ws_gui_iter));
362         g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "GUI-TrePath: %s\n\n", gtk_tree_path_to_string(ws_gui_app->ws_gui_w_list->path));
363
364                 gtk_tree_selection_select_iter(
365                                 ws_gui_app->ws_gui_w_list->ws_gui_selection,
366                                 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
367         
368                 ws_gui_app->history_flag = FALSE;
369                 ws_gui_fill_html(format_html(data.value.s, ws_gui_app), 
370                                              ws_gui_app);
371                 ws_gui_app->html_flag = TRUE;
372         }
373         }
374         
375         if (tmp->len == 0)
376         {
377                 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
378                               _("ws_ni_no_words_found"));
379                 
380                 ws_gui_app->history_mode = 0;
381
382                 ws_gui_fill_html(" ", ws_gui_app);
383                 ws_gui_app->html_flag = FALSE;
384                 g_free(ws_gui_app->last_word);
385                 ws_gui_app->last_word = NULL;
386         }
387
388         
389         timer(TIMER_STOP, (gchar*)__FUNCTION__);
390 }
391
392 /** this function handles signal from dbus and send recived data to 
393 the translation area
394  *
395  * @param error - error message recived from DBUS
396  * @param words - array with recived data structure
397  * @param user_data - pointer to data structure
398  * @return
399  */
400 void ws_gui_dbus_return_translation (GError *error,
401                                      GArray *words,
402                                      gpointer user_data)
403 {
404         //timer(TIMER_START, (gchar*)__FUNCTION__);
405         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
406
407         osso_rpc_t data;
408
409         data = g_array_index (words, osso_rpc_t, 0);
410        //gtk_html_zoom_reset(GTK_HTML(ws_gui_app->ws_gui_html));
411         ws_gui_fill_html(format_html(data.value.s, ws_gui_app), ws_gui_app);
412         ws_gui_app->html_flag = TRUE;
413         //timer(TIMER_STOP, (gchar*)__FUNCTION__);
414
415 }
416
417 /**
418 * this function allows to free allocated memory
419 *
420 * @param user_data - pointer to data structure
421 */
422 void ws_gui_free_memory(gpointer user_data)
423 {
424         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
425         g_array_free(ws_gui_app->ws_gui_history, TRUE);
426         pango_font_description_free(ws_gui_app->p);
427         g_free(ws_gui_app->last_word);
428         g_free(ws_gui_app->ws_gui_w_list);
429         g_free(ws_gui_app->ws_gui_menu);
430         g_free(ws_gui_app);
431 }
432
433 /** this function handle press signals (keyboard)
434  * 
435  * @param widget
436  * @param keyevent
437  * @param user_data - ponter to data structure
438  * @return TRUE to stop other handlers from being invoked for the event. 
439  FALSE to propagate the event further.
440  */
441 gboolean hildon_key_press_listener (GtkWidget * widget,
442                                     GdkEventKey * keyevent,
443                                     gpointer user_data)
444 {
445         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
446
447         switch ((guint)(keyevent->keyval)) {
448                 case HILDON_HARDKEY_UP: 
449                 {
450                         gtk_container_set_focus_vadjustment(
451                           GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
452                           gtk_scrolled_window_get_vadjustment(
453                           GTK_SCROLLED_WINDOW(
454                                       ws_gui_app->ws_gui_scrolledwindow_left)));
455                       ws_gui_app->v_new_value =
456                          gtk_adjustment_get_value(
457                            GTK_ADJUSTMENT(
458                                 ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
459                       if (ws_gui_app->v_new_value > 
460                           ws_gui_app->ws_gui_vadj->lower) 
461                       {
462                               gtk_adjustment_set_value(
463                                         GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
464                                         ws_gui_app->v_new_value);
465                       }
466                         
467                         break;
468                 }
469
470                 case HILDON_HARDKEY_DOWN: 
471                 {
472                       gtk_container_set_focus_vadjustment(
473                           GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
474                           gtk_scrolled_window_get_vadjustment(
475                           GTK_SCROLLED_WINDOW(
476                                       ws_gui_app->ws_gui_scrolledwindow_left)));
477                       ws_gui_app->v_new_value = gtk_adjustment_get_value(
478                                         GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj))
479                                         + ws_gui_app->v_delta;
480
481                       if (ws_gui_app->v_new_value < 
482                                      (ws_gui_app->ws_gui_vadj->upper - 
483                                             ws_gui_app->ws_gui_vadj->page_size)) 
484                       {
485                                 gtk_adjustment_set_value(
486                                         GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
487                                         ws_gui_app->v_new_value);
488                       }
489                         /*if (gtk_tree_model_iter_next(
490                                 ws_gui_app->ws_gui_w_list->ws_gui_model, &ws_gui_app->ws_gui_w_list->ws_gui_iter) == TRUE)
491                         {
492                         gtk_tree_selection_select_iter(
493                                 ws_gui_app->ws_gui_w_list->ws_gui_selection,
494                                 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
495                         }*/
496                       break;
497                 }
498
499                 case HILDON_HARDKEY_LEFT:
500                 {
501                       gtk_container_set_focus_hadjustment(
502                       GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
503                       gtk_scrolled_window_get_hadjustment(
504                       GTK_SCROLLED_WINDOW(
505                                       ws_gui_app->ws_gui_scrolledwindow_left)));
506
507                       ws_gui_app->h_new_value = gtk_adjustment_get_value(
508                       GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) 
509                       - ws_gui_app->h_delta;
510
511                       if (ws_gui_app->h_new_value > 
512                           ws_gui_app->ws_gui_hadj->lower) 
513                       {
514                                 gtk_adjustment_set_value(
515                                         GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
516                                         ws_gui_app->h_new_value);
517                       }
518                 }
519                 break;
520
521                 case HILDON_HARDKEY_RIGHT: 
522                 {
523                       gtk_container_set_focus_hadjustment(
524                        GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
525                        gtk_scrolled_window_get_hadjustment(
526                        GTK_SCROLLED_WINDOW(
527                        ws_gui_app->ws_gui_scrolledwindow_left)));
528
529                       ws_gui_app->h_new_value = gtk_adjustment_get_value(
530                       GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) 
531                       + ws_gui_app->h_delta;
532
533                       if (ws_gui_app->h_new_value < 
534                                 (ws_gui_app->ws_gui_hadj->upper - 
535                                         ws_gui_app->ws_gui_hadj->page_size)) 
536                       {
537                       gtk_adjustment_set_value(
538                                         GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
539                                         ws_gui_app->h_new_value);
540                       }
541                  }
542                  break;
543
544                  case HILDON_HARDKEY_SELECT: 
545                         ws_gui_search(NULL, ws_gui_app);
546                  break;
547
548                  case HILDON_HARDKEY_FULLSCREEN: 
549                       ws_gui_full_screen(NULL, ws_gui_app);
550                  break;
551
552                  case HILDON_HARDKEY_INCREASE: 
553                       ws_gui_html_zoom_in(NULL, ws_gui_app);
554                  break;
555
556                  case HILDON_HARDKEY_DECREASE:
557                       ws_gui_html_zoom_out(NULL, ws_gui_app);
558                  break;
559
560                  case HILDON_HARDKEY_ESC: 
561                       ws_gui_search_stop(NULL, ws_gui_app);
562                  break;
563
564                  default:
565                       return FALSE;
566                  break;
567         }
568         return TRUE;
569 }
570
571 /** this function allow to hide words list using menu item from application menu
572  *
573  * @param checkmenuitem - the object which received the signal
574  * @param user_data - user data set when the signal handler was connected
575  * @return
576  */
577 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
578                                       gpointer user_data)
579 {
580         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
581         if (gtk_check_menu_item_get_active(
582            GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
583         {
584                 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
585                 gtk_toggle_tool_button_set_active(
586                   GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide),
587                   TRUE);
588                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
589                                 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
590                                 TRUE);
591         }
592         else 
593         {
594                 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
595                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
596                                          ws_gui_app->ws_gui_toobar_button_hide),
597                                          FALSE);
598                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
599                                 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
600                                 FALSE);
601         }
602 }
603
604 /** this function allow to hide words list using toggle button placed in 
605 the find toolbar
606  *
607  * @param toolbar - the object which received the signal
608  * @param user_data - user data set when the signal handler was connected
609  * @return
610  */
611 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
612 {
613         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
614
615         if (gtk_toggle_tool_button_get_active(
616                  GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
617         {
618                 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
619                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
620                                          ws_gui_app->ws_gui_toobar_button_hide),
621                                          TRUE);
622                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
623                                 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
624                                 TRUE);
625         }
626         else 
627         {
628                 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
629                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
630                                          ws_gui_app->ws_gui_toobar_button_hide),
631                                          FALSE);
632                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
633                                 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
634                                 FALSE);
635         }
636 }
637
638 /** add word to the history
639  *
640  * @param new_word - word which is going to be append to the history array
641  * @param user_data - user data set when the signal handler was connected
642  * @return
643  */
644 void ws_gui_history_add(char *new_word, gpointer user_data)
645 {
646         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
647
648         if (ws_gui_app->history_mode == 0)
649         {
650
651                 guint i;
652                 gchar *tmp_word;
653                 gchar *tmp_last_searched;
654                 gchar *tmp_iter = NULL;
655                 gchar *previous_word = " ";
656         
657                 if (ws_gui_app->ws_gui_history_cur_pos > -1 &&
658                     g_array_index(ws_gui_app->ws_gui_history, 
659                                   gchar*, 
660                                   ws_gui_app->ws_gui_history_cur_pos) != NULL)
661                 {
662                         previous_word = NULL;
663                         previous_word = g_array_index(
664                                         ws_gui_app->ws_gui_history, 
665                                         gchar*, 
666                                         ws_gui_app->ws_gui_history_cur_pos);
667                 }
668         
669                 i = ws_gui_app->ws_gui_history_cur_pos + 1;
670                 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, 
671                                            gchar*, 
672                                            i);
673                 tmp_iter = gtk_tree_model_get_string_from_iter (GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_model), &ws_gui_app->ws_gui_w_list->ws_gui_iter);
674         
675                 if (previous_word != NULL && strcmp(previous_word, new_word) != 0)
676                 {
677                         while (tmp != NULL) 
678                         {
679                                 g_array_remove_index(
680                                 ws_gui_app->ws_gui_history_list, 
681                                 i);
682                                 g_array_remove_index(
683                                 ws_gui_app->ws_gui_history_iter, 
684                                 i);
685
686                                 
687                                 g_array_remove_index(
688                                 ws_gui_app->ws_gui_history, 
689                                 i);
690                                 
691                                 tmp = g_array_index(
692                                       ws_gui_app->ws_gui_history, 
693                                       gchar*, 
694                                       i);
695                         }
696         
697                 i = 0;
698                 ws_gui_app->ws_gui_history_cur_pos ++;
699         
700                 
701                 if (ws_gui_app->bookmark_mode == FALSE)
702                 {
703                 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
704                 }
705                 else
706                 {
707                 tmp_last_searched = g_strdup(ws_gui_app->last_searched_in_book);
708                 }
709
710                 g_array_append_val(ws_gui_app->ws_gui_history_list, 
711                                    tmp_last_searched);
712                                 
713                 tmp_word = g_strdup(new_word);
714                 
715                 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
716                 g_array_append_val(ws_gui_app->ws_gui_history_iter, tmp_iter);
717                 
718         
719                 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
720                 {
721                         g_array_remove_index(ws_gui_app->ws_gui_history, 0);
722                         g_array_remove_index(ws_gui_app->ws_gui_history_list, 
723                                         0);
724                         g_array_remove_index(ws_gui_app->ws_gui_history_iter, 
725                                         0);
726                         
727                         ws_gui_app->ws_gui_history_cur_pos--;
728                 }
729         
730                 i = 0;
731                 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
732                 }
733                 
734         }
735                 
736         ws_gui_app->ws_gui_w_list->path = gtk_tree_model_get_path(GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_model), &ws_gui_app->ws_gui_w_list->ws_gui_iter);
737         ws_gui_check_history(ws_gui_app);
738 }
739
740 /** display previously choosen word (previous from the history array)
741      if avaible, sets current position in the history array
742  *
743  * @param button - button which recived a signal
744  * @param user_data - user data set when the signal handler was connected
745  * @return 
746  */
747 void ws_gui_history_back(GtkButton *button, gpointer user_data) 
748 {
749         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
750         
751         ws_gui_app->history_flag = TRUE;
752
753         if (ws_gui_app->ws_gui_history_cur_pos > 0) 
754         {
755                 ws_gui_app->ws_gui_history_cur_pos = 
756                                         ws_gui_app->ws_gui_history_cur_pos - 1;
757
758                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
759                              "prefix",
760                              (g_array_index(ws_gui_app->ws_gui_history_list,
761                              gchar*, 
762                              ws_gui_app->ws_gui_history_cur_pos)),
763                              NULL);
764         
765                 
766                 ws_dbus_client_find_word (ws_gui_app->dbus_data, 
767                                         g_array_index(ws_gui_app->ws_gui_history_list,
768                                         gchar*, 
769                                         ws_gui_app->ws_gui_history_cur_pos)
770                                         );
771                 
772         }
773         else 
774         {
775                 gtk_widget_set_sensitive (
776                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
777                               FALSE);
778                 gtk_widget_set_sensitive(
779                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
780                      FALSE);
781         }
782
783         ws_gui_check_history(ws_gui_app);
784
785 }
786
787 /** display choosen word, next in the history array (if avaible), 
788 sets current position in the history array
789  *
790  * @param button - button which recived a signal
791  * @param user_data - user data set when the signal handler was connected
792  * @return 
793  */
794 void ws_gui_history_next(GtkButton *button, gpointer user_data) 
795 {
796         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
797         
798         ws_gui_app->history_flag = TRUE;
799
800         gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
801                                    gchar*,
802                                    ws_gui_app->ws_gui_history_cur_pos+1);
803
804         if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1) 
805              && (tmp != NULL)) 
806         {
807                 ws_gui_app->ws_gui_history_cur_pos =
808                          ws_gui_app->ws_gui_history_cur_pos + 1;
809
810                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
811                                "prefix",
812                                (g_array_index(ws_gui_app->ws_gui_history_list,
813                                gchar*, 
814                                ws_gui_app->ws_gui_history_cur_pos)),
815                                NULL);
816         
817                 ws_dbus_client_find_word(ws_gui_app->dbus_data, 
818                                         g_array_index(ws_gui_app->ws_gui_history_list,
819                                         gchar*, 
820                                         ws_gui_app->ws_gui_history_cur_pos)
821                                         );
822         }
823         else 
824         {
825                 gtk_widget_set_sensitive(
826                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
827                            FALSE);
828                 gtk_widget_set_sensitive(
829                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
830                      FALSE);
831         }
832
833         ws_gui_check_history(ws_gui_app);
834 }
835
836 /** check current position in the history array and sets sensitivity of buttons 
837 / menu items, depends on availablity of words in the history
838  *
839  * @param user_data - user data set when the signal handler was connected
840  * @return 
841  */
842 void ws_gui_check_history(gpointer user_data) 
843 {
844         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
845
846         gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
847                                    gchar*,
848                                    ws_gui_app->ws_gui_history_cur_pos+1);
849
850         if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN) 
851              && (tmp != NULL))
852         {
853                 gtk_widget_set_sensitive(
854                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
855                            TRUE);
856                 gtk_widget_set_sensitive(
857                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
858                      TRUE);
859         }
860         else 
861         {
862                 gtk_widget_set_sensitive(
863                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
864                            FALSE);
865                 gtk_widget_set_sensitive(
866                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
867                      FALSE);
868         }
869
870         tmp = g_array_index(ws_gui_app->ws_gui_history,
871                             gchar*,
872                             ws_gui_app->ws_gui_history_cur_pos-1);
873         if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
874         {
875                 gtk_widget_set_sensitive(
876                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
877                               TRUE);
878                 gtk_widget_set_sensitive(
879                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
880                      TRUE);
881        }
882        else
883        {
884                 gtk_widget_set_sensitive (
885                         GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
886                         FALSE);
887                 gtk_widget_set_sensitive(
888                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
889                      FALSE);
890        }
891 }
892
893 /** create TreeView Model, which allows to display words list
894  *
895  * @param words_list - array with words(found in a dictionary), recived from 
896  * DBUS;
897  * @param user_data - user data set when the signal handler was connected
898  * @return 
899  */
900 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
901 {
902         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
903         guint i = 0;
904         gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
905
906          gboolean valid;
907         valid = gtk_tree_model_get_iter_first(
908                         GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
909                         &ws_gui_app->ws_gui_w_list->ws_gui_iter);
910
911         /* Append a row and fill in some data */
912         while (tmp != NULL)
913         {
914                 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
915                                        &ws_gui_app->ws_gui_w_list->ws_gui_iter);
916
917                 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
918                               &ws_gui_app->ws_gui_w_list->ws_gui_iter, 
919                               COL_WORD, tmp,
920                               -1);
921                 i=i+1;
922                 tmp = g_strdup(g_array_index(words_list, gchar*, i));
923         };
924
925         tmp = g_strdup(g_array_index(words_list, gchar*, 0));
926
927         if (tmp != NULL && ws_gui_app->history_flag == FALSE)
928         {
929                 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
930                 ws_gui_history_add(tmp, ws_gui_app);
931                 g_free(ws_gui_app->last_word);
932                 ws_gui_app->last_word = NULL;
933                 ws_gui_app->last_word = g_strdup (tmp);
934         }
935          
936         return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
937 }
938
939 /** create TreeView and TreeModel using create_and_fill_model() function;
940  it is necessary to display found words in a words list;
941  *
942  * @param words_list - array with words(found in a dictionary), 
943  * recived from DBUS;
944  * @param user_data - user data set when the signal handler was connected
945  * @return 
946  */
947 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
948 {
949         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
950
951         ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
952
953         ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
954         gtk_tree_view_insert_column_with_attributes(
955                          GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
956                          -1,
957                          "Name",
958                          ws_gui_app->ws_gui_w_list->ws_gui_renderer,
959                          "text",
960                          COL_WORD,
961                          NULL);
962         ws_gui_app->ws_gui_w_list->ws_gui_model = 
963                                 create_and_fill_model(words_list, ws_gui_app);
964
965         gtk_tree_view_set_model(
966                          GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
967                          ws_gui_app->ws_gui_w_list->ws_gui_model);
968         g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
969         
970         return ws_gui_app->ws_gui_w_list->ws_gui_view;
971 }
972
973 /** handle signal from words list, get selected word and calls 
974 'find translation' function
975  *
976  * @param selection - the object which received the signal
977  * @param user_data - user data set when the signal handler was connected
978  * @return 
979  */
980 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
981                                    gpointer user_data)
982 {
983         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
984         gchar *string;
985         ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
986
987         if (gtk_tree_selection_get_selected(selection,
988                                        &ws_gui_app->ws_gui_w_list->ws_gui_model,
989                                        &ws_gui_app->ws_gui_w_list->ws_gui_iter))
990         {
991                 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
992                                    &ws_gui_app->ws_gui_w_list->ws_gui_iter,
993                                    COL_WORD,
994                                    &string,
995                                    -1);
996
997                 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
998                 
999                 g_free(ws_gui_app->last_word);
1000                 ws_gui_app->last_word = NULL;
1001                 ws_gui_app->last_word = g_strdup (string);
1002                 
1003                 
1004                 if (string != NULL && ws_gui_app->history_flag == FALSE)
1005                 {
1006                         ws_gui_history_add(string, ws_gui_app);
1007                 }
1008                 g_free (string);
1009         }
1010 }
1011
1012 /** switch application between fun screen and normal mode
1013  *
1014  * @param menuitem - object which recived the signal
1015  * @param user_data - user data set when the signal handler was connected 
1016  * @return
1017  */
1018 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
1019 {
1020
1021         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1022         if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
1023
1024                 gtk_window_fullscreen(
1025                                   GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1026                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1027                               ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1028                               TRUE);
1029                 ws_gui_app->ws_gui_full_screen_flag = TRUE;
1030                 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1031                                  _("ws_ib_fullscreen_on"));
1032         }
1033         else 
1034         {
1035                 gtk_window_unfullscreen(
1036                                   GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1037                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1038                               ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1039                               FALSE);
1040                 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1041                 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1042                                  _("ws_ib_fullscreen_off"));
1043         }
1044 }
1045
1046 /** search for selected text in a dictionary
1047  *
1048  * @param menuitem - object which recived the signal
1049  * @param user_data - user data set when the signal handler was connected 
1050  * @return
1051  */
1052 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1053 {
1054         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1055         gchar *temp;
1056         ws_gui_app->ws_gui_clipboard_primary = 
1057                 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1058                                          GDK_SELECTION_PRIMARY);
1059         temp = gtk_clipboard_wait_for_text(
1060                                           ws_gui_app->ws_gui_clipboard_primary);
1061
1062         g_strstrip(temp);
1063         if (temp != NULL || strcmp(temp, " "))
1064         {
1065                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1066                                       "prefix",
1067                                       temp,
1068                                       NULL);
1069                 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1070         }
1071         else
1072         {
1073                 hildon_banner_show_information(
1074                                    GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1075                                    NULL,
1076                                    _("ws_ni_no_text_selected"));
1077         }
1078 }
1079
1080 /** select whole text in the translation (html) area
1081  *
1082  * @param menuitem - object which recived the signal
1083  * @param user_data - user data set when the signal handler was connected 
1084  * @return
1085  */
1086 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data) 
1087 {
1088         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1089         gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1090 }
1091
1092 /** copy selected text to the clipoard from context popup menu
1093  *
1094  * @param menuitem - object which recived the signal
1095  * @param user_data - user data set when the signal handler was connected 
1096  * @return
1097  */
1098 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data) 
1099 {
1100         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1101         gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1102         gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1103                                  _("ws_ib_copied"));
1104 }
1105
1106 /** paste copied text into toolbar entry
1107  *
1108  * @param menuitem - object which recived the signal
1109  * @param user_data - user data set when the signal handler was connected 
1110  * @return
1111  */
1112 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1113 {
1114         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1115
1116         gchar *temp;
1117         gchar *temp2;
1118         temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1119         g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1120                      "prefix",
1121                      &temp2,
1122                      NULL);
1123         temp = g_strconcat(temp2, temp, NULL);
1124         temp = g_strdelimit(temp, "\n", ' ');
1125         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1126                      "prefix",
1127                      temp,
1128                      NULL);
1129         gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1130                                  _("ws_ib_pasted"));
1131 }
1132
1133 /** zoom in text in translation (html) area
1134  *
1135  * @param menuitem - object which recived the signal
1136  * @param user_data - user data set when the signal handler was connected 
1137  * @return
1138  */
1139 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1140 {
1141         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1142         ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1143         if (ws_gui_app->zoom > ZOOM_MAX)
1144         {
1145                 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1146                 gtk_infoprint(GTK_WINDOW(
1147                                       ws_gui_app->ws_gui_hildon_window),
1148                                       _("ws_ib_max_zoom"));
1149         }
1150         else
1151         {
1152                 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html), 
1153                                                 ws_gui_app->zoom);
1154
1155                 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1156                 {
1157                         gtk_infoprint(GTK_WINDOW(
1158                                         ws_gui_app->ws_gui_hildon_window),
1159                                         _("ws_ib_zoom_default"));
1160                 }
1161                 else
1162                 {
1163                         gtk_infoprint(GTK_WINDOW(
1164                                         ws_gui_app->ws_gui_hildon_window),
1165                                         _("ws_ib_zoom_in"));
1166                 }
1167         }
1168 }
1169
1170 /** zoom out text in translation (html) area
1171  *
1172  * @param menuitem - object which recived the signal
1173  * @param user_data - user data set when the signal handler was connected 
1174  * @return
1175  */
1176 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1177 {
1178         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1179         ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1180         if (ws_gui_app->zoom < ZOOM_MIN)
1181         {
1182                 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1183                 gtk_infoprint(GTK_WINDOW(
1184                                       ws_gui_app->ws_gui_hildon_window),
1185                                       _("ws_ib_min_zoom"));
1186         }
1187         else
1188         {
1189                 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html), 
1190                                                 ws_gui_app->zoom);
1191                 
1192                 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1193                 {
1194                         gtk_infoprint(GTK_WINDOW(
1195                                         ws_gui_app->ws_gui_hildon_window),
1196                                         _("ws_ib_zoom_default"));
1197                 }
1198                 else
1199                 {
1200                         gtk_infoprint(GTK_WINDOW(
1201                                         ws_gui_app->ws_gui_hildon_window),
1202                                         _("ws_ib_zoom_out"));
1203                 }
1204         }
1205 }
1206
1207 /** start searching, send typed word to DBUS and query for words
1208  *
1209  * @param widget - object which recived the signal
1210  * @param user_data - user data set when the signal handler was connected 
1211  * @return
1212  */
1213 void ws_gui_search(GtkWidget * widget, gpointer user_data) 
1214 {
1215         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1216
1217         if (ws_gui_app->ws_gui_banner_flag == FALSE) 
1218         {
1219         gchar* ws_gui_text = NULL;
1220         g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1221                      "prefix",
1222                      &ws_gui_text,
1223                      NULL);
1224
1225         if (ws_gui_app->bookmark_mode == FALSE) 
1226         {
1227                 g_free(ws_gui_app->last_searched);
1228                 ws_gui_app->last_searched = NULL;
1229                 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1230         }
1231         else
1232         {
1233                 g_free(ws_gui_app->last_searched_in_book);
1234                 ws_gui_app->last_searched_in_book = NULL;
1235                 ws_gui_app->last_searched_in_book = g_strdup(ws_gui_text);
1236         }
1237         
1238         g_strstrip(ws_gui_text);
1239         if (strlen(ws_gui_text) != 0) 
1240         {
1241                 gtk_widget_show(ws_gui_app->ws_gui_banner);
1242                 
1243                 gtk_widget_set_sensitive(
1244                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1245                               TRUE);
1246                 gtk_widget_set_sensitive(
1247                           GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1248                           TRUE);
1249
1250                 ws_gui_app->ws_gui_banner_flag = TRUE;
1251                 ws_gui_fill_html(" ", ws_gui_app);
1252                 ws_gui_app->html_flag = FALSE;
1253                 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1254
1255         }
1256         else 
1257         {
1258                 gtk_infoprint(
1259                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1260                               _("ws_ni_no_word_typed"));
1261         }
1262         g_free(ws_gui_app->last_word);
1263         ws_gui_app->last_word=NULL;
1264         }
1265 }
1266
1267 /** stop search process
1268  *
1269  * @param button - object which recived the signal
1270  * @param user_data - user data set when the signal handler was connected 
1271  * @return
1272  */
1273 void ws_gui_search_stop(GtkButton *button, gpointer user_data) 
1274 {
1275         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1276         if (ws_gui_app->ws_gui_banner_flag == TRUE) 
1277         {
1278                 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1279                 ws_gui_app->ws_gui_banner_flag = FALSE;
1280                 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1281                 gtk_infoprint(
1282                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1283                               _("ws_ni_search_aborted"));
1284         }
1285 }
1286
1287 /** this function is called just before closing application; 
1288 it sends signal to DBUS and destroys it; 
1289  *
1290  * @param widget - object which recived the signal
1291  * @param event - 
1292  * @param user_data - user data set when the signal handler was connected 
1293  * @return
1294  */
1295 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data) 
1296 {
1297         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1298         ws_gui_app->bookmark_mode = FALSE;
1299         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1300         g_timer_destroy(ws_gui_app->timer);
1301         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1302         ws_dbus_destroy (ws_gui_app->dbus_data);
1303         ws_gui_free_memory(ws_gui_app);
1304         gtk_main_quit();
1305         exit (0);
1306 }
1307
1308 /** this function is called just before closing application, 
1309 from application menu; it sends signal to DBUS and destroys it;
1310  *
1311  * @param menuitem - object which recived the signal
1312  * @param user_data - user data set when the signal handler was connected 
1313  * @return
1314  */
1315 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1316 {
1317         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1318         ws_gui_app->bookmark_mode = FALSE;
1319         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1320         g_timer_destroy(ws_gui_app->timer);
1321         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1322         ws_dbus_destroy (ws_gui_app->dbus_data);
1323         ws_gui_free_memory(ws_gui_app);
1324         gtk_main_quit();
1325         exit (0);
1326 }
1327
1328 /** fill translation area with text (html) recived from DBUS
1329  *
1330  * @param html_context - text which is going to be displayed; it should be html
1331  * @param user_data - user data set when the function was called
1332  * @return
1333  */
1334 void ws_gui_fill_html(char *html_context, gpointer user_data) 
1335 {
1336         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1337         gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1338
1339         gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1340                                   html_context,
1341                                   -1);
1342 }
1343
1344 /** read adjustment of left scrollwindow, which is necessary to navigate with 
1345 arrow keys inside words list
1346  *
1347  * @param user_data - user data set when the signal handler was connected 
1348  * @return
1349  */
1350 void ws_gui_read_adjustment(gpointer user_data)
1351 {
1352         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1353
1354         ws_gui_app->ws_gui_hadj = 
1355                 gtk_scrolled_window_get_hadjustment(
1356                 GTK_SCROLLED_WINDOW(
1357                 ws_gui_app->ws_gui_scrolledwindow_left));
1358
1359         ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1360                                   ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1361
1362         ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1363         GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1364
1365         ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1366                                   ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1367         ws_gui_app->v_new_value =
1368            gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1369                                                             ws_gui_app->v_delta;
1370
1371         gtk_container_set_focus_vadjustment(
1372                GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), 
1373                gtk_scrolled_window_get_vadjustment(
1374                   GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1375
1376 }
1377
1378 /** allows to display image in html area
1379  *
1380  * @param html - object which received a signal 
1381  * @param url - url to the image
1382  * @param stream - html stream 
1383  * @return
1384  */
1385 void ws_gui_url_requested (
1386                           GtkHTML *html, 
1387                           const char *url, 
1388                           GtkHTMLStream *stream)
1389 {
1390         int fd;
1391
1392         if (url && !strncmp (url, "file:", 5)) {
1393                 url += 5;
1394                 fd = open (url, O_RDONLY);
1395                 if (fd != -1) {
1396                         gchar *buf;
1397                         size_t size;
1398                         buf = alloca (8192);
1399                         while ((size = read (fd, buf, 8192)) > 0) {
1400                                 gtk_html_stream_write (stream, buf, size);
1401                         }
1402                        gtk_html_stream_close(stream, size == -1
1403                                          ? GTK_HTML_STREAM_ERROR
1404                                          : GTK_HTML_STREAM_OK);
1405                        close (fd);
1406
1407                       return;
1408                 }
1409         }
1410
1411         gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1412 }
1413
1414 /** handles button press event and examines what kind of event was it 
1415         suppose to be
1416  *
1417  * @param widget - object which received a signal
1418  * @param event - type of event which has been performed
1419  * @param user_data - user data set when the signal handler was connected 
1420  * @return TRUE to stop other handlers from being invoked for the event. 
1421  FALSE to propagate the event further
1422  */
1423 gboolean ws_gui_button_press(GtkWidget *widget,
1424                              GdkEventButton *event,
1425                              gpointer user_data)
1426 {
1427         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1428         if (ws_gui_app->ws_gui_sel_flag == FALSE)
1429         {
1430                 if (event->type == GDK_2BUTTON_PRESS) 
1431                 {
1432                         ws_gui_app->ws_gui_double_click = TRUE;
1433                         g_timer_stop(ws_gui_app->timer);
1434                         g_timer_reset(ws_gui_app->timer);
1435                         return FALSE;
1436                 }
1437
1438                 g_signal_stop_emission_by_name(G_OBJECT(
1439                                                 ws_gui_app->ws_gui_html),
1440                                                "button-press-event");
1441                 g_timer_start(ws_gui_app->timer);
1442                 gtk_timeout_add((guint)(PRESS_TIME*1000),
1443                                 (GtkFunction)(ws_gui_show_popup),
1444                                 ws_gui_app);
1445                 return FALSE;
1446         }
1447         else
1448         {
1449                 ws_gui_app->ws_gui_sel_flag = FALSE;
1450                 return FALSE;
1451         }
1452
1453 }
1454
1455 /** handles button release event and examines whether 'click' or 'tap and hold' 
1456 event it supposed to be
1457  *
1458  * @param widget - object which received a signal
1459  * @param event - type of event which has been performed
1460  * @param user_data - user data set when the signal handler was connected 
1461  * @return TRUE to stop other handlers from being invoked for the event. 
1462  FALSE to propagate the event further
1463  */
1464 gboolean ws_gui_button_release (GtkWidget *widget,
1465                                 GdkEventButton *event,
1466                                 gpointer user_data)
1467 {
1468         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1469         gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1470         g_timer_stop(ws_gui_app->timer);
1471         g_timer_reset(ws_gui_app->timer);
1472         if (ws_gui_app->ws_gui_double_click == TRUE)
1473         {
1474                 ws_gui_app->ws_gui_double_click = FALSE;
1475                 return FALSE;
1476         }
1477         else if (tmp < PRESS_TIME)
1478         {
1479                 struct _GtkHTML *tmp = (struct _GtkHTML *)
1480                                         (ws_gui_app->ws_gui_html);
1481                 html_engine_unselect_all(tmp->engine);
1482                 return TRUE;
1483         }
1484                 return FALSE;
1485 }
1486
1487 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1488  *
1489  * @param user_data - user data set when the signal handler was connected 
1490  * @return 
1491  */
1492 guint ws_gui_show_popup (gpointer user_data)
1493 {
1494         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1495         gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1496         if (tmp > PRESS_TIME)
1497         {
1498                 ws_gui_create_popup_menu(ws_gui_app);
1499         }
1500         return (guint)(FALSE);
1501
1502 }
1503
1504 /** checks clipboard content and sets sensitivity of widgets 
1505  *
1506  * @param widget - object which recived a signal
1507  * @param user_data - user data set when the signal handler was connected 
1508  * @return 
1509  */
1510 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data) 
1511 {
1512         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1513         if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1514         {
1515                 gtk_widget_set_sensitive(
1516                          GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1517                          TRUE);
1518         }
1519         else
1520         {
1521                 gtk_widget_set_sensitive(
1522                          GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1523                          FALSE);
1524         }
1525
1526         struct _GtkHTML *tmp = (struct _GtkHTML *)(ws_gui_app->ws_gui_html);
1527
1528         if (html_engine_is_selection_active(tmp->engine) == TRUE)
1529         {
1530                 gtk_widget_set_sensitive(GTK_WIDGET
1531                                 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1532                                 TRUE);
1533         }
1534         else 
1535         {
1536                 gtk_widget_set_sensitive(GTK_WIDGET
1537                                 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1538                                 FALSE);
1539         }
1540
1541         if (ws_gui_app->html_flag == FALSE)
1542         {
1543                 gtk_widget_set_sensitive(GTK_WIDGET
1544                         (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1545                         FALSE);
1546         }
1547         else
1548         {
1549                 gtk_widget_set_sensitive(GTK_WIDGET
1550                         (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1551                         TRUE);
1552         }       
1553
1554 }
1555
1556 /** gets received string (with translation), formats it and sends it to be 
1557  * displayed
1558  *
1559  * @param received_string - content received from Manager
1560  * @param user_data - user data set when the function has been called
1561  * @return 
1562  */
1563 gchar * format_html (gchar * received_string, gpointer user_data)
1564 {
1565         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1566         GString *str_final;
1567         GString *str_tmp;
1568         str_final = g_string_new(received_string);
1569         str_tmp = g_string_new(received_string);
1570         gchar * tmp;
1571         gchar * tmp2;
1572         
1573         ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation, 
1574                                                    0, 
1575                                                   -1);
1576
1577         while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1578         {
1579                 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1580                 str_final =  g_string_erase(str_final,
1581                                            (long)(tmp - str_final->str),
1582                                            14);
1583                 str_final =  g_string_insert(str_final,
1584                  (long)(tmp - str_final->str),
1585                  "<html><head></head><body><center><table width=\"400px\"><tr>"
1586                  "<td><table border=1 width=100%><tr>"
1587                  "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1588                  "<img align=left src=\"file:/usr/share/pixmaps/"
1589                  "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1590                 
1591                 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1592                 if (ws_gui_app->last_word != NULL)
1593                 {
1594                         str_tmp =  g_string_erase(str_tmp,
1595                                            (long)(tmp2 - str_tmp->str),
1596                                            14 + strlen(ws_gui_app->last_word));
1597                 }
1598         }
1599
1600         while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1601         {
1602                 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1603                 str_final =  g_string_erase(str_final,
1604                                             (long)(tmp - str_final->str),
1605                                             16);
1606                 str_final =  g_string_insert(str_final,
1607                                             (long)(tmp - str_final->str),
1608                                             "</font></th></tr></table>");
1609
1610                 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1611                 str_tmp =  g_string_erase(str_tmp,
1612                                           (long)(tmp2 - str_tmp->str),
1613                                           16);
1614         }
1615
1616         while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1617         {
1618                 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1619                 str_final =  g_string_erase (str_final,
1620                                              (long)(tmp - str_final->str),
1621                                              18);
1622                 str_final =  g_string_insert (str_final,
1623                 (long)(tmp - str_final->str),
1624                 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1625                 "share/pixmaps/ws_tra.png\">");
1626
1627                 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1628                 str_tmp =  g_string_erase(str_tmp,
1629                                            (long)(tmp2 - str_tmp->str),
1630                                            18);
1631         }
1632
1633         while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1634         {
1635                 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1636                 str_final =  g_string_erase(str_final,
1637                                             (long)(tmp - str_final->str),
1638                                             20);
1639                 str_final =  g_string_insert(str_final,
1640                                              (long)(tmp - str_final->str),
1641                                              "</td></tr></table></center>");
1642
1643                 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1644                 str_tmp =  g_string_erase(str_tmp,
1645                                           (long)(tmp2 - str_tmp->str),
1646                                           20);
1647         }
1648
1649         str_final = g_string_append(str_final,
1650                                     "</td></tr></table></body></html>");
1651
1652         ws_gui_app->raw_translation = g_string_insert(
1653                                                 ws_gui_app->raw_translation,
1654                                                 0,
1655                                                 str_tmp->str);
1656         
1657         return str_final->str;
1658 }
1659
1660 /** open bookmarks database 
1661  *
1662  * @param menuitem - object which recived the signal
1663  * @param user_data - user data set when the signal handler was connected 
1664  * @return
1665  */
1666 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1667 {
1668         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1669
1670         ws_gui_read_active_dictionaries(ws_gui_app);
1671         
1672         g_free(ws_gui_app->last_word);
1673         ws_gui_app->last_word = NULL;
1674
1675         ws_gui_app->bookmark_mode = TRUE;
1676         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1677         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1678                                      "prefix",
1679                                       "*",
1680                                       NULL);
1681         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1682         
1683         if(ws_gui_app->ws_gui_history->len >= 0)
1684         {
1685         ws_gui_clear_array(ws_gui_app->ws_gui_history);
1686         ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1687         ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1688         ws_gui_app->ws_gui_history_cur_pos = -1;
1689         }
1690         ws_gui_check_history(ws_gui_app);
1691         
1692         ws_gui_fill_html(" ", ws_gui_app);
1693         ws_gui_app->html_flag = FALSE;
1694         //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1695         ws_gui_search(NULL, ws_gui_app);
1696         
1697 }
1698
1699 /** closes bookmarks database 
1700  *
1701  * @param menuitem - object which recived the signal
1702  * @param user_data - user data set when the signal handler was connected 
1703  * @return
1704  */
1705 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1706 {
1707         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1708
1709         ws_gui_read_active_dictionaries(ws_gui_app);
1710         
1711         g_free(ws_gui_app->last_word);
1712         ws_gui_app->last_word = NULL;
1713
1714         ws_gui_app->bookmark_mode = FALSE;
1715         ws_gui_set_bookmarks_sensitivity(ws_gui_app);   
1716         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1717
1718         if(ws_gui_app->ws_gui_history->len >= 0)
1719         {
1720         ws_gui_clear_array(ws_gui_app->ws_gui_history);
1721         ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1722         ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1723         ws_gui_app->ws_gui_history_cur_pos = -1;
1724         }
1725         ws_gui_check_history(ws_gui_app);
1726
1727         ws_gui_fill_html(" ", ws_gui_app);
1728         ws_gui_app->html_flag = FALSE;
1729         g_strstrip(ws_gui_app->last_searched);
1730         if (ws_gui_app->last_searched != NULL) 
1731         {
1732         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1733                                      "prefix",
1734                                       ws_gui_app->last_searched,
1735                                       NULL);
1736         //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1737         ws_gui_search(NULL, ws_gui_app);
1738         }
1739         else
1740         {
1741                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1742                                      "prefix",
1743                                       "\0",
1744                                       NULL);
1745                 GArray *tmp;
1746                 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
1747                 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
1748                 ws_gui_app->ws_gui_w_list->ws_gui_model = 
1749                                         create_and_fill_model(tmp, ws_gui_app);
1750                 
1751                 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1752                 ws_gui_search(NULL, ws_gui_app);        
1753         }
1754 }
1755
1756 /** adds bookmark to bookmarks database 
1757  *
1758  * @param menuitem - object which recived the signal
1759  * @param user_data - user data set when the signal handler was connected 
1760  * @return
1761  */
1762 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1763 {
1764         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1765
1766         if (ws_gui_app->last_word != NULL)
1767         {
1768                 ws_gui_add_bookmark_dialog(ws_gui_app);
1769         }
1770         else
1771         {
1772                 gtk_infoprint(
1773                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1774                               _("ws_ni_select_word_to_add"));
1775         }
1776 }
1777
1778 /** removes bookmark from bookmarks database 
1779  *
1780  * @param menuitem - object which recived the signal
1781  * @param user_data - user data set when the signal handler was connected 
1782  * @return
1783  */
1784 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem, 
1785                                        gpointer user_data)
1786 {
1787         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1788
1789         if (ws_gui_app->last_word != NULL)
1790         {
1791                 ws_gui_remove_bookmark_dialog(ws_gui_app);
1792
1793                 gchar *temp;
1794                 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1795                                       "prefix",
1796                                       &temp,
1797                                       NULL);
1798                 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1799                 
1800         }
1801         else
1802         {
1803                 gtk_infoprint(
1804                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1805                               _("ws_ni_select_word_to_remove"));
1806         }
1807         
1808         
1809 }
1810
1811 /** checks wheather dictionaries are available or not; according to the result
1812  * dimmes proper menuitem 
1813  *
1814  * @param menuitem - object which recived the signal
1815  * @param user_data - user data set when the signal handler was connected 
1816  * @return
1817  */
1818 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1819 {
1820         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1821         if (gconf_client_dir_exists(ws_gui_app->client, 
1822                                     GCONF_PATH, NULL) == TRUE)
1823         {
1824                 ws_gui_app->directories = gconf_client_all_dirs(
1825                                                         ws_gui_app->client,
1826                                                         GCONF_PATH,
1827                                                         NULL
1828                                                         );
1829                 
1830         
1831                 if(g_slist_length(ws_gui_app->directories) != 0)
1832                 {
1833                         gtk_widget_set_sensitive(GTK_WIDGET
1834                         (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1835                         TRUE);
1836                         gtk_widget_set_sensitive(GTK_WIDGET
1837                         (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1838                         TRUE);
1839                         gtk_widget_set_sensitive(GTK_WIDGET
1840                         (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1841                         TRUE);
1842                 }
1843
1844         }
1845         else 
1846         {
1847         gtk_widget_set_sensitive(GTK_WIDGET
1848                              (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1849                              FALSE);
1850         gtk_widget_set_sensitive(GTK_WIDGET
1851                              (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1852                              FALSE);
1853         gtk_widget_set_sensitive(GTK_WIDGET
1854                            (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1855                            FALSE);
1856         }
1857
1858 }
1859
1860 /** sets sensitivity of menu items due to bookmark's mode
1861  *
1862  * @param user_data - user data set when the function was called 
1863  * @return
1864  */
1865 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1866 {
1867         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1868         int i;
1869         gchar *string;
1870         gchar *name;
1871
1872         if (ws_gui_app->bookmark_mode == TRUE)
1873         {
1874                 g_slist_free(ws_gui_app->directories_last);
1875                 ws_gui_app->directories_last = NULL;
1876                 ws_gui_app->directories_last = g_slist_alloc();
1877                 g_slist_free(ws_gui_app->directories);
1878                 ws_gui_app->directories = g_slist_alloc();
1879
1880                 ws_gui_app->directories = gconf_client_all_dirs(
1881                                                         ws_gui_app->client, 
1882                                                         GCONF_PATH, NULL);
1883                 
1884         for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
1885         {
1886                 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
1887                 name = g_path_get_basename(string);
1888                 string = g_strconcat(string, "/active", NULL);
1889                 
1890                 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE) 
1891                 {
1892                         ws_gui_app->directories_last = 
1893                                 g_slist_append(ws_gui_app->directories_last, 
1894                                                string);
1895                 }
1896
1897                 if (strcmp(name, "bookmarks") == 0)
1898                 {
1899                         gconf_client_set_bool(ws_gui_app->client, 
1900                                               string, 
1901                                               TRUE, 
1902                                               NULL);
1903                 }
1904                 else
1905                 {
1906                         gconf_client_set_bool(ws_gui_app->client, 
1907                                               string, 
1908                                               FALSE, 
1909                                               NULL);
1910                 }
1911         }
1912
1913         //setting sensitivity of components
1914         gtk_widget_set_sensitive(
1915                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1916                 FALSE);
1917         gtk_widget_set_sensitive(
1918                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1919                 TRUE);
1920         gtk_widget_set_sensitive(
1921                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1922                TRUE);
1923         gtk_widget_set_sensitive(
1924                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1925                 FALSE);
1926         gtk_widget_set_sensitive(
1927                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1928                 FALSE);
1929         }
1930         else 
1931         {
1932         gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1933         if (g_slist_length(ws_gui_app->directories_last) > 0)
1934         {
1935         gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1936         }
1937         
1938         for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1939         {
1940                 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last, 
1941                                                   i);
1942                 
1943                 //string = g_strconcat(string, "/active", NULL);
1944                 if (string != NULL)
1945                 {
1946                 gconf_client_set_bool(ws_gui_app->client, 
1947                                 string, 
1948                                 TRUE, 
1949                                 NULL);
1950                 }
1951         }
1952
1953         //setting sensitivity of components
1954         gtk_widget_set_sensitive(
1955                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1956                 TRUE);
1957         gtk_widget_set_sensitive(
1958                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1959                 FALSE);
1960         gtk_widget_set_sensitive(
1961                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1962                FALSE);
1963         gtk_widget_set_sensitive(
1964                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1965                 TRUE);
1966         gtk_widget_set_sensitive(
1967                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1968                 TRUE);
1969         }
1970 }
1971
1972 /** sets sensitivity of menu items due to user selection made
1973  *
1974  * @param user_data - user data set when the function was called 
1975  * @return
1976  */
1977 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
1978 {
1979         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1980         if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
1981         {
1982                gtk_widget_set_sensitive(
1983                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1984                TRUE);
1985         }
1986         else
1987         {
1988                gtk_widget_set_sensitive(
1989                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1990                FALSE);
1991         }
1992
1993         if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
1994         {
1995                gtk_widget_set_sensitive(
1996                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1997                FALSE);
1998         }
1999         else
2000         {
2001                gtk_widget_set_sensitive(
2002                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2003                TRUE);
2004         }
2005 }
2006 /** reads gconf entries and sets variables with a proper data; it is necessary
2007  * for changing the bookmarks mode
2008  *
2009  * @param user_data - user data set when the function was called
2010  * @return
2011  */
2012 void ws_gui_read_active_dictionaries(gpointer user_data)
2013 {
2014         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2015
2016         
2017         ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
2018                                              GCONF_PATH,
2019                                              NULL);
2020 }
2021
2022 void ws_gui_clear_array(GArray *history)
2023 {
2024         if(history->len >= 0)
2025         {
2026         history = g_array_remove_range(history, 0, history->len);
2027         }
2028 }