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