close bookmark function has been improved.
[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         }
730         else 
731         {
732                 gtk_widget_set_sensitive (
733                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
734                               FALSE);
735                 gtk_widget_set_sensitive(
736                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
737                      FALSE);
738         }
739
740         ws_gui_check_history(ws_gui_app);
741
742 }
743
744 /** display choosen word, next in the history array (if avaible), 
745 sets current position in the history array
746  *
747  * @param button - button which recived a signal
748  * @param user_data - user data set when the signal handler was connected
749  * @return 
750  */
751 void ws_gui_history_next(GtkButton *button, gpointer user_data) 
752 {
753         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
754         
755         ws_gui_app->history_flag = TRUE;
756
757         gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
758                                    gchar*,
759                                    ws_gui_app->ws_gui_history_cur_pos+1);
760
761         if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1) 
762              && (tmp != NULL)) 
763         {
764                 ws_gui_app->ws_gui_history_cur_pos =
765                          ws_gui_app->ws_gui_history_cur_pos + 1;
766
767                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
768                                "prefix",
769                                (g_array_index(ws_gui_app->ws_gui_history_list,
770                                gchar*, 
771                                ws_gui_app->ws_gui_history_cur_pos)),
772                                NULL);
773         
774         
775                 //ws_gui_search(NULL, ws_gui_app);
776                 
777                 ws_dbus_client_find_word(ws_gui_app->dbus_data, 
778                                         g_array_index(ws_gui_app->ws_gui_history_list,
779                                         gchar*, 
780                                         ws_gui_app->ws_gui_history_cur_pos)
781                                         );
782
783                 //ws_dbus_client_search_in_history(ws_gui_app->dbus_data,
784                 //                (g_array_index(ws_gui_app->ws_gui_history,
785                 //                          gchar*,
786                 //                          ws_gui_app->ws_gui_history_cur_pos)));
787
788         }
789         else 
790         {
791                 gtk_widget_set_sensitive(
792                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
793                            FALSE);
794                 gtk_widget_set_sensitive(
795                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
796                      FALSE);
797         }
798
799         ws_gui_check_history(ws_gui_app);
800 }
801
802 /** check current position in the history array and sets sensitivity of buttons 
803 / menu items, depends on availablity of words in the history
804  *
805  * @param user_data - user data set when the signal handler was connected
806  * @return 
807  */
808 void ws_gui_check_history(gpointer user_data) 
809 {
810         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
811
812         gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
813                                    gchar*,
814                                    ws_gui_app->ws_gui_history_cur_pos+1);
815
816         if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN) 
817              && (tmp != NULL))
818         {
819                 gtk_widget_set_sensitive(
820                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
821                            TRUE);
822                 gtk_widget_set_sensitive(
823                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
824                      TRUE);
825         }
826         else 
827         {
828                 gtk_widget_set_sensitive(
829                            GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
830                            FALSE);
831                 gtk_widget_set_sensitive(
832                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
833                      FALSE);
834         }
835
836         tmp = g_array_index(ws_gui_app->ws_gui_history,
837                             gchar*,
838                             ws_gui_app->ws_gui_history_cur_pos-1);
839         if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
840         {
841                 gtk_widget_set_sensitive(
842                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
843                               TRUE);
844                 gtk_widget_set_sensitive(
845                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
846                      TRUE);
847        }
848        else
849        {
850                 gtk_widget_set_sensitive (
851                         GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
852                         FALSE);
853                 gtk_widget_set_sensitive(
854                      GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
855                      FALSE);
856        }
857 }
858
859 /** create TreeView Model, which allows to display words list
860  *
861  * @param words_list - array with words(found in a dictionary), recived from 
862  * DBUS;
863  * @param user_data - user data set when the signal handler was connected
864  * @return 
865  */
866 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
867 {
868         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
869         guint i = 0;
870         gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
871
872          gboolean valid;
873         valid = gtk_tree_model_get_iter_first(
874                         GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
875                         &ws_gui_app->ws_gui_w_list->ws_gui_iter);
876
877         /* Append a row and fill in some data */
878         while (tmp != NULL)
879         {
880                 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
881                                        &ws_gui_app->ws_gui_w_list->ws_gui_iter);
882
883                 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
884                               &ws_gui_app->ws_gui_w_list->ws_gui_iter, 
885                               COL_WORD, tmp,
886                               -1);
887                 i=i+1;
888                 tmp = g_strdup(g_array_index(words_list, gchar*, i));
889         };
890
891         tmp = g_strdup(g_array_index(words_list, gchar*, 0));
892
893         if (tmp != NULL && ws_gui_app->history_flag == FALSE)
894         {
895                 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
896                 ws_gui_history_add(tmp, ws_gui_app);
897                 g_free(ws_gui_app->last_word);
898                 ws_gui_app->last_word = NULL;
899                 ws_gui_app->last_word = g_strdup (tmp);
900         }
901          
902         return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
903 }
904
905 /** create TreeView and TreeModel using create_and_fill_model() function;
906  it is necessary to display found words in a words list;
907  *
908  * @param words_list - array with words(found in a dictionary), 
909  * recived from DBUS;
910  * @param user_data - user data set when the signal handler was connected
911  * @return 
912  */
913 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
914 {
915         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
916
917         ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
918
919         ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
920         gtk_tree_view_insert_column_with_attributes(
921                          GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
922                          -1,
923                          "Name",
924                          ws_gui_app->ws_gui_w_list->ws_gui_renderer,
925                          "text",
926                          COL_WORD,
927                          NULL);
928         ws_gui_app->ws_gui_w_list->ws_gui_model = 
929                                 create_and_fill_model(words_list, ws_gui_app);
930
931         gtk_tree_view_set_model(
932                          GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
933                          ws_gui_app->ws_gui_w_list->ws_gui_model);
934         g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
935         
936         return ws_gui_app->ws_gui_w_list->ws_gui_view;
937 }
938
939 /** handle signal from words list, get selected word and calls 
940 'find translation' function
941  *
942  * @param selection - the object which received the signal
943  * @param user_data - user data set when the signal handler was connected
944  * @return 
945  */
946 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
947                                    gpointer user_data)
948 {
949         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
950         gchar *string;
951         ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
952
953         if (gtk_tree_selection_get_selected(selection,
954                                        &ws_gui_app->ws_gui_w_list->ws_gui_model,
955                                        &ws_gui_app->ws_gui_w_list->ws_gui_iter))
956         {
957                 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
958                                    &ws_gui_app->ws_gui_w_list->ws_gui_iter,
959                                    COL_WORD,
960                                    &string,
961                                    -1);
962
963                 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
964                 
965                 g_free(ws_gui_app->last_word);
966                 ws_gui_app->last_word = NULL;
967                 ws_gui_app->last_word = g_strdup (string);
968                 
969                 
970                 if (string != NULL && ws_gui_app->history_flag == FALSE)
971                 {
972                         ws_gui_history_add(string, ws_gui_app);
973                 }
974                 g_free (string);
975         }
976 }
977
978 /** switch application between fun screen and normal mode
979  *
980  * @param menuitem - object which recived the signal
981  * @param user_data - user data set when the signal handler was connected 
982  * @return
983  */
984 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
985 {
986
987         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
988         if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
989
990                 gtk_window_fullscreen(
991                                   GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
992                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
993                               ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
994                               TRUE);
995                 ws_gui_app->ws_gui_full_screen_flag = TRUE;
996                 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
997                                  _("ws_ib_fullscreen_on"));
998         }
999         else 
1000         {
1001                 gtk_window_unfullscreen(
1002                                   GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1003                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1004                               ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1005                               FALSE);
1006                 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1007                 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1008                                  _("ws_ib_fullscreen_off"));
1009         }
1010 }
1011
1012 /** search for selected text in a dictionary
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_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1019 {
1020         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1021         gchar *temp;
1022         ws_gui_app->ws_gui_clipboard_primary = 
1023                 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1024                                          GDK_SELECTION_PRIMARY);
1025         temp = gtk_clipboard_wait_for_text(
1026                                           ws_gui_app->ws_gui_clipboard_primary);
1027
1028         g_strstrip(temp);
1029         if (temp != NULL || strcmp(temp, " "))
1030         {
1031                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1032                                       "prefix",
1033                                       temp,
1034                                       NULL);
1035                 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1036         }
1037         else
1038         {
1039                 hildon_banner_show_information(
1040                                    GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1041                                    NULL,
1042                                    _("ws_ni_no_text_selected"));
1043         }
1044 }
1045
1046 /** select whole text in the translation (html) area
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_html_select_all(GtkMenuItem *menuitem, gpointer user_data) 
1053 {
1054         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1055         gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1056 }
1057
1058 /** copy selected text to the clipoard from context popup menu
1059  *
1060  * @param menuitem - object which recived the signal
1061  * @param user_data - user data set when the signal handler was connected 
1062  * @return
1063  */
1064 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data) 
1065 {
1066         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1067         gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1068 }
1069
1070 /** paste copied text into toolbar entry
1071  *
1072  * @param menuitem - object which recived the signal
1073  * @param user_data - user data set when the signal handler was connected 
1074  * @return
1075  */
1076 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1077 {
1078         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1079
1080         gchar *temp;
1081         gchar *temp2;
1082         temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1083         g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1084                      "prefix",
1085                      &temp2,
1086                      NULL);
1087         temp = g_strconcat(temp2, temp, NULL);
1088         temp = g_strdelimit(temp, "\n", ' ');
1089         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1090                      "prefix",
1091                      temp,
1092                      NULL);
1093 }
1094
1095 /** zoom in text in translation (html) area
1096  *
1097  * @param menuitem - object which recived the signal
1098  * @param user_data - user data set when the signal handler was connected 
1099  * @return
1100  */
1101 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1102 {
1103         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1104         //gtk_html_zoom_in(GTK_HTML(ws_gui_app->ws_gui_html));
1105         ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1106         if (ws_gui_app->zoom > ZOOM_MAX)
1107         {
1108                 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1109                 gtk_infoprint(GTK_WINDOW(
1110                                       ws_gui_app->ws_gui_hildon_window),
1111                                       _("ws_ib_max_zoom"));
1112         }
1113         else
1114         {
1115         gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html), 
1116                                             ws_gui_app->zoom);
1117         gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1118                                  _("ws_ib_zoom_in"));
1119         }
1120 }
1121
1122 /** zoom out text in translation (html) area
1123  *
1124  * @param menuitem - object which recived the signal
1125  * @param user_data - user data set when the signal handler was connected 
1126  * @return
1127  */
1128 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1129 {
1130         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1131         //gtk_html_zoom_out(GTK_HTML(ws_gui_app->ws_gui_html));
1132         ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1133         if (ws_gui_app->zoom < ZOOM_MIN)
1134         {
1135                 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1136                 gtk_infoprint(GTK_WINDOW(
1137                                       ws_gui_app->ws_gui_hildon_window),
1138                                       _("ws_ib_min_zoom"));
1139         }
1140         else
1141         {
1142         gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html), 
1143                                             ws_gui_app->zoom);
1144         gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1145                                  _("ws_ib_zoom_out"));
1146         }
1147 }
1148
1149 /** start searching, send typed word to DBUS and query for words
1150  *
1151  * @param widget - object which recived the signal
1152  * @param user_data - user data set when the signal handler was connected 
1153  * @return
1154  */
1155 void ws_gui_search(GtkWidget * widget, gpointer user_data) 
1156 {
1157         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1158         
1159
1160         if (ws_gui_app->ws_gui_banner_flag == FALSE) 
1161         {
1162         gchar* ws_gui_text = NULL;
1163         g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1164                      "prefix",
1165                      &ws_gui_text,
1166                      NULL);
1167
1168         if (ws_gui_app->bookmark_mode == FALSE) 
1169         {
1170                 g_free(ws_gui_app->last_searched);
1171                 ws_gui_app->last_searched = NULL;
1172                 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1173         }
1174         
1175         g_strstrip(ws_gui_text);
1176         if (strlen(ws_gui_text) != 0) 
1177         {
1178                 gtk_widget_show(ws_gui_app->ws_gui_banner);
1179                 //g_signal_handler_block(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);   
1180
1181                 gtk_widget_set_sensitive(
1182                               GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1183                               TRUE);
1184                 gtk_widget_set_sensitive(
1185                           GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1186                           TRUE);
1187
1188                 ws_gui_app->ws_gui_banner_flag = TRUE;
1189                 ws_gui_fill_html(" ", ws_gui_app);
1190                 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1191
1192         }
1193         else 
1194         {
1195                 gtk_infoprint(
1196                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1197                               _("ws_ni_no_word_typed"));
1198         }
1199         g_free(ws_gui_app->last_word);
1200         ws_gui_app->last_word=NULL;
1201         }
1202 }
1203
1204 /** stop search process
1205  *
1206  * @param button - object which recived the signal
1207  * @param user_data - user data set when the signal handler was connected 
1208  * @return
1209  */
1210 void ws_gui_search_stop(GtkButton *button, gpointer user_data) 
1211 {
1212         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1213         if (ws_gui_app->ws_gui_banner_flag == TRUE) 
1214         {
1215                 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1216                 //g_signal_handler_unblock(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263); 
1217                 ws_gui_app->ws_gui_banner_flag = FALSE;
1218                 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1219                 gtk_infoprint(
1220                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1221                               _("ws_ni_search_aborted"));
1222         }
1223 }
1224
1225 /** this function is called just before closing application; 
1226 it sends signal to DBUS and destroys it; 
1227  *
1228  * @param widget - object which recived the signal
1229  * @param event - 
1230  * @param user_data - user data set when the signal handler was connected 
1231  * @return
1232  */
1233 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data) 
1234 {
1235         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1236         ws_gui_app->bookmark_mode = FALSE;
1237         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1238         g_timer_destroy(ws_gui_app->timer);
1239         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1240         ws_dbus_destroy (ws_gui_app->dbus_data);
1241         ws_gui_free_memory(ws_gui_app);
1242         gtk_main_quit();
1243         exit (0);
1244 }
1245
1246 /** this function is called just before closing application, 
1247 from application menu; it sends signal to DBUS and destroys it;
1248  *
1249  * @param menuitem - object which recived the signal
1250  * @param user_data - user data set when the signal handler was connected 
1251  * @return
1252  */
1253 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1254 {
1255         WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1256         ws_gui_app->bookmark_mode = FALSE;
1257         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1258         g_timer_destroy(ws_gui_app->timer);
1259         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1260         ws_dbus_destroy (ws_gui_app->dbus_data);
1261         ws_gui_free_memory(ws_gui_app);
1262         gtk_main_quit();
1263         exit (0);
1264 }
1265
1266 /** fill translation area with text (html) recived from DBUS
1267  *
1268  * @param html_context - text which is going to be displayed; it should be html
1269  * @param user_data - user data set when the function was called
1270  * @return
1271  */
1272 void ws_gui_fill_html(char *html_context, gpointer user_data) 
1273 {
1274         WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1275         gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1276
1277         gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1278                                   html_context,
1279                                   -1);
1280 }
1281
1282 /** read adjustment of left scrollwindow, which is necessary to navigate with 
1283 arrow keys inside words list
1284  *
1285  * @param user_data - user data set when the signal handler was connected 
1286  * @return
1287  */
1288 void ws_gui_read_adjustment(gpointer user_data)
1289 {
1290         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1291
1292         ws_gui_app->ws_gui_hadj = 
1293                 gtk_scrolled_window_get_hadjustment(
1294                 GTK_SCROLLED_WINDOW(
1295                 ws_gui_app->ws_gui_scrolledwindow_left));
1296
1297         ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1298                                   ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1299
1300         ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1301         GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1302
1303         ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1304                                   ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1305         ws_gui_app->v_new_value =
1306            gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1307                                                             ws_gui_app->v_delta;
1308
1309         gtk_container_set_focus_vadjustment(
1310                GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), 
1311                gtk_scrolled_window_get_vadjustment(
1312                   GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1313
1314 }
1315
1316 /** allows to display image in html area
1317  *
1318  * @param html - object which received a signal 
1319  * @param url - url to the image
1320  * @param stream - html stream 
1321  * @return
1322  */
1323 void ws_gui_url_requested (
1324                           GtkHTML *html, 
1325                           const char *url, 
1326                           GtkHTMLStream *stream)
1327 {
1328         int fd;
1329
1330         if (url && !strncmp (url, "file:", 5)) {
1331                 url += 5;
1332                 fd = open (url, O_RDONLY);
1333                 if (fd != -1) {
1334                         gchar *buf;
1335                         size_t size;
1336                         buf = alloca (8192);
1337                         while ((size = read (fd, buf, 8192)) > 0) {
1338                                 gtk_html_stream_write (stream, buf, size);
1339                         }
1340                        gtk_html_stream_close(stream, size == -1
1341                                          ? GTK_HTML_STREAM_ERROR
1342                                          : GTK_HTML_STREAM_OK);
1343                        close (fd);
1344
1345                       return;
1346                 }
1347         }
1348
1349         gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1350 }
1351
1352 /** handles button press event and examines what kind of event was it 
1353         suppose to be
1354  *
1355  * @param widget - object which received a signal
1356  * @param event - type of event which has been performed
1357  * @param user_data - user data set when the signal handler was connected 
1358  * @return TRUE to stop other handlers from being invoked for the event. 
1359  FALSE to propagate the event further
1360  */
1361 gboolean ws_gui_button_press(GtkWidget *widget,
1362                              GdkEventButton *event,
1363                              gpointer user_data)
1364 {
1365         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1366         if (ws_gui_app->ws_gui_sel_flag == FALSE)
1367         {
1368                 if (event->type == GDK_2BUTTON_PRESS) 
1369                 {
1370                         ws_gui_app->ws_gui_double_click = TRUE;
1371                         g_timer_stop(ws_gui_app->timer);
1372                         g_timer_reset(ws_gui_app->timer);
1373                         return FALSE;
1374                 }
1375
1376                 g_signal_stop_emission_by_name(G_OBJECT(
1377                                                 ws_gui_app->ws_gui_html),
1378                                                "button-press-event");
1379                 g_timer_start(ws_gui_app->timer);
1380                 gtk_timeout_add((guint)(PRESS_TIME*1000),
1381                                 (GtkFunction)(ws_gui_show_popup),
1382                                 ws_gui_app);
1383                 return FALSE;
1384         }
1385         else
1386         {
1387                 ws_gui_app->ws_gui_sel_flag = FALSE;
1388                 return FALSE;
1389         }
1390
1391 }
1392
1393 /** handles button release event and examines whether 'click' or 'tap and hold' 
1394 event it supposed to be
1395  *
1396  * @param widget - object which received a signal
1397  * @param event - type of event which has been performed
1398  * @param user_data - user data set when the signal handler was connected 
1399  * @return TRUE to stop other handlers from being invoked for the event. 
1400  FALSE to propagate the event further
1401  */
1402 gboolean ws_gui_button_release (GtkWidget *widget,
1403                                 GdkEventButton *event,
1404                                 gpointer user_data)
1405 {
1406         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1407         gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1408         g_timer_stop(ws_gui_app->timer);
1409         g_timer_reset(ws_gui_app->timer);
1410         if (ws_gui_app->ws_gui_double_click == TRUE)
1411         {
1412                 ws_gui_app->ws_gui_double_click = FALSE;
1413                 return FALSE;
1414         }
1415         else if (tmp < PRESS_TIME)
1416         {
1417                 struct _GtkHTML *tmp = (struct _GtkHTML *)
1418                                         (ws_gui_app->ws_gui_html);
1419                 html_engine_unselect_all(tmp->engine);
1420                 return TRUE;
1421         }
1422                 return FALSE;
1423 }
1424
1425 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1426  *
1427  * @param user_data - user data set when the signal handler was connected 
1428  * @return 
1429  */
1430 guint ws_gui_show_popup (gpointer user_data)
1431 {
1432         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1433         gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1434         if (tmp > PRESS_TIME)
1435         {
1436                 ws_gui_create_popup_menu(ws_gui_app);
1437         }
1438         return (guint)(FALSE);
1439
1440 }
1441
1442 /** checks clipboard content and sets sensitivity of widgets 
1443  *
1444  * @param widget - object which recived a signal
1445  * @param user_data - user data set when the signal handler was connected 
1446  * @return 
1447  */
1448 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data) 
1449 {
1450         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1451         if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1452         {
1453                 gtk_widget_set_sensitive(
1454                          GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1455                          TRUE);
1456         }
1457         else
1458         {
1459                 gtk_widget_set_sensitive(
1460                          GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1461                          FALSE);
1462         }
1463 }
1464
1465 /** gets received string (with translation), formats it and sends it to be 
1466  * displayed
1467  *
1468  * @param received_string - content received from Manager
1469  * @param user_data - user data set when the function has been called
1470  * @return 
1471  */
1472 gchar * format_html (gchar * received_string, gpointer user_data)
1473 {
1474         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1475         GString *str_final;
1476         GString *str_tmp;
1477         str_final = g_string_new(received_string);
1478         str_tmp = g_string_new(received_string);
1479         gchar * tmp;
1480         gchar * tmp2;
1481         
1482         ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation, 
1483                                                    0, 
1484                                                   -1);
1485
1486         while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1487         {
1488                 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1489                 str_final =  g_string_erase(str_final,
1490                                            (long)(tmp - str_final->str),
1491                                            14);
1492                 str_final =  g_string_insert(str_final,
1493                  (long)(tmp - str_final->str),
1494                  "<html><head></head><body><center><table width=\"400px\"><tr>"
1495                  "<td><table border=1 width=100%><tr>"
1496                  "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1497                  "<img align=left src=\"file:/usr/share/pixmaps/"
1498                  "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1499                 
1500                 //g_debug("\n\nws_gui_app->last_word %s", ws_gui_app->last_word);
1501                 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1502                 if (ws_gui_app->last_word != NULL)
1503                 {
1504                         str_tmp =  g_string_erase(str_tmp,
1505                                            (long)(tmp2 - str_tmp->str),
1506                                            14 + strlen(ws_gui_app->last_word));
1507                 }
1508                 //str_tmp = g_string_insert(str_tmp, "<br>", 0);
1509         }
1510
1511         while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1512         {
1513                 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1514                 str_final =  g_string_erase(str_final,
1515                                             (long)(tmp - str_final->str),
1516                                             16);
1517                 str_final =  g_string_insert(str_final,
1518                                             (long)(tmp - str_final->str),
1519                                             "</font></th></tr></table>");
1520
1521                 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1522                 str_tmp =  g_string_erase(str_tmp,
1523                                           (long)(tmp2 - str_tmp->str),
1524                                           16);
1525         }
1526
1527         while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1528         {
1529                 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1530                 str_final =  g_string_erase (str_final,
1531                                              (long)(tmp - str_final->str),
1532                                              18);
1533                 str_final =  g_string_insert (str_final,
1534                 (long)(tmp - str_final->str),
1535                 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1536                 "share/pixmaps/ws_tra.png\">");
1537
1538                 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1539                 str_tmp =  g_string_erase(str_tmp,
1540                                            (long)(tmp2 - str_tmp->str),
1541                                            18);
1542                 /*str_tmp =  g_string_insert(str_tmp,
1543                                              (long)(tmp2 - str_tmp->str),
1544                                              "<p/>");
1545                 */
1546         }
1547
1548         while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1549         {
1550                 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1551                 str_final =  g_string_erase(str_final,
1552                                             (long)(tmp - str_final->str),
1553                                             20);
1554                 str_final =  g_string_insert(str_final,
1555                                              (long)(tmp - str_final->str),
1556                                              "</td></tr></table></center>");
1557
1558                 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1559                 str_tmp =  g_string_erase(str_tmp,
1560                                           (long)(tmp2 - str_tmp->str),
1561                                           20);
1562                                 
1563         }
1564
1565         str_final = g_string_append(str_final,
1566                                     "</td></tr></table></body></html>");
1567
1568         ws_gui_app->raw_translation = g_string_insert(
1569                                                 ws_gui_app->raw_translation,
1570                                                 0,
1571                                                 str_tmp->str);
1572         
1573         
1574         //ws_gui_app->raw_translation = g_string_append(str_final, "<br>");
1575
1576         return str_final->str;
1577 }
1578
1579 /** open bookmarks database 
1580  *
1581  * @param menuitem - object which recived the signal
1582  * @param user_data - user data set when the signal handler was connected 
1583  * @return
1584  */
1585 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1586 {
1587         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1588
1589         ws_gui_read_active_dictionaries(ws_gui_app);
1590         
1591         g_free(ws_gui_app->last_word);
1592         ws_gui_app->last_word = NULL;
1593
1594         ws_gui_app->bookmark_mode = TRUE;
1595         ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1596         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1597                                      "prefix",
1598                                       "*",
1599                                       NULL);
1600         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1601         
1602         ws_gui_fill_html(" ", ws_gui_app);
1603         //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1604         ws_gui_search(NULL, ws_gui_app);
1605         
1606 }
1607
1608 /** closes bookmarks database 
1609  *
1610  * @param menuitem - object which recived the signal
1611  * @param user_data - user data set when the signal handler was connected 
1612  * @return
1613  */
1614 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1615 {
1616         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1617
1618         ws_gui_read_active_dictionaries(ws_gui_app);
1619         
1620         g_free(ws_gui_app->last_word);
1621         ws_gui_app->last_word = NULL;
1622
1623         ws_gui_app->bookmark_mode = FALSE;
1624         ws_gui_set_bookmarks_sensitivity(ws_gui_app);   
1625         ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1626         ws_gui_fill_html(" ", ws_gui_app);
1627         g_strstrip(ws_gui_app->last_searched);
1628         if (ws_gui_app->last_searched != NULL) 
1629         {
1630         g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1631                                      "prefix",
1632                                       ws_gui_app->last_searched,
1633                                       NULL);
1634         //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1635         ws_gui_search(NULL, ws_gui_app);
1636         }
1637         else
1638         {
1639                 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1640                                      "prefix",
1641                                       "\0",
1642                                       NULL);
1643                 GArray *tmp;
1644                 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
1645                 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
1646                 ws_gui_app->ws_gui_w_list->ws_gui_model = 
1647                                         create_and_fill_model(tmp, ws_gui_app);
1648                 
1649                 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1650                 ws_gui_search(NULL, ws_gui_app);        
1651         }
1652 }
1653
1654 /** adds bookmark to bookmarks database 
1655  *
1656  * @param menuitem - object which recived the signal
1657  * @param user_data - user data set when the signal handler was connected 
1658  * @return
1659  */
1660 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1661 {
1662         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1663
1664         if (ws_gui_app->last_word != NULL)
1665         {
1666                 ws_gui_add_bookmark_dialog(ws_gui_app);
1667         }
1668         else
1669         {
1670                 gtk_infoprint(
1671                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1672                               _("ws_ni_select_word_to_add"));
1673         }
1674         
1675         
1676 }
1677
1678 /** removes bookmark from bookmarks database 
1679  *
1680  * @param menuitem - object which recived the signal
1681  * @param user_data - user data set when the signal handler was connected 
1682  * @return
1683  */
1684 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem, 
1685                                        gpointer user_data)
1686 {
1687         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1688
1689         if (ws_gui_app->last_word != NULL)
1690         {
1691                 ws_gui_remove_bookmark_dialog(ws_gui_app);
1692
1693                 gchar *temp;
1694                 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1695                                       "prefix",
1696                                       &temp,
1697                                       NULL);
1698                 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1699                 
1700         }
1701         else
1702         {
1703                 gtk_infoprint(
1704                               GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1705                               _("ws_ni_select_word_to_remove"));
1706         }
1707         
1708         
1709 }
1710
1711 /** checks wheather dictionaries are available or not; according to the result
1712  * dimmes proper menuitem 
1713  *
1714  * @param menuitem - object which recived the signal
1715  * @param user_data - user data set when the signal handler was connected 
1716  * @return
1717  */
1718 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1719 {
1720         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1721         if (gconf_client_dir_exists(ws_gui_app->client, 
1722                                     GCONF_PATH, NULL) == TRUE)
1723         {
1724                 ws_gui_app->directories = gconf_client_all_dirs(
1725                                                         ws_gui_app->client,
1726                                                         GCONF_PATH,
1727                                                         NULL
1728                                                         );
1729                 
1730         
1731                 if(g_slist_length(ws_gui_app->directories) != 0)
1732                 {
1733                         gtk_widget_set_sensitive(GTK_WIDGET
1734                         (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1735                         TRUE);
1736                         gtk_widget_set_sensitive(GTK_WIDGET
1737                         (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1738                         TRUE);
1739                         gtk_widget_set_sensitive(GTK_WIDGET
1740                         (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1741                         TRUE);
1742                 }
1743
1744         }
1745         else 
1746         {
1747         gtk_widget_set_sensitive(GTK_WIDGET
1748                              (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1749                              FALSE);
1750         gtk_widget_set_sensitive(GTK_WIDGET
1751                              (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1752                              FALSE);
1753         gtk_widget_set_sensitive(GTK_WIDGET
1754                            (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1755                            FALSE);
1756         }
1757
1758 }
1759
1760 /** sets sensitivity of menu items due to bookmark's mode
1761  *
1762  * @param user_data - user data set when the function was called 
1763  * @return
1764  */
1765 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1766 {
1767         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1768         int i;
1769         gchar *string;
1770         gchar *name;
1771
1772         if (ws_gui_app->bookmark_mode == TRUE)
1773         {
1774                 g_slist_free(ws_gui_app->directories_last);
1775                 ws_gui_app->directories_last = NULL;
1776                 ws_gui_app->directories_last = g_slist_alloc();
1777                 g_slist_free(ws_gui_app->directories);
1778                 ws_gui_app->directories = g_slist_alloc();
1779
1780                 ws_gui_app->directories = gconf_client_all_dirs(
1781                                                         ws_gui_app->client, 
1782                                                         GCONF_PATH, NULL);
1783                 
1784         for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
1785         {
1786                 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
1787                 name = g_path_get_basename(string);
1788                 string = g_strconcat(string, "/active", NULL);
1789                 
1790                 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE) 
1791                 {
1792                         ws_gui_app->directories_last = 
1793                                 g_slist_append(ws_gui_app->directories_last, 
1794                                                string);
1795                 }
1796
1797                 if (strcmp(name, "bookmarks") == 0)
1798                 {
1799                         gconf_client_set_bool(ws_gui_app->client, 
1800                                               string, 
1801                                               TRUE, 
1802                                               NULL);
1803                 }
1804                 else
1805                 {
1806                         gconf_client_set_bool(ws_gui_app->client, 
1807                                               string, 
1808                                               FALSE, 
1809                                               NULL);
1810                 }
1811         }
1812
1813         //setting sensitivity of components
1814         gtk_widget_set_sensitive(
1815                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1816                 FALSE);
1817         gtk_widget_set_sensitive(
1818                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1819                 TRUE);
1820         gtk_widget_set_sensitive(
1821                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1822                TRUE);
1823         gtk_widget_set_sensitive(
1824                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1825                 FALSE);
1826         gtk_widget_set_sensitive(
1827                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1828                 FALSE);
1829         }
1830         else 
1831         {
1832         gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1833         if (g_slist_length(ws_gui_app->directories_last) > 0)
1834         {
1835         gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1836         }
1837         
1838         for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1839         {
1840                 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last, 
1841                                                   i);
1842                 
1843                 //string = g_strconcat(string, "/active", NULL);
1844                 if (string != NULL)
1845                 {
1846                 gconf_client_set_bool(ws_gui_app->client, 
1847                                 string, 
1848                                 TRUE, 
1849                                 NULL);
1850                 }
1851         }
1852
1853         //setting sensitivity of components
1854         gtk_widget_set_sensitive(
1855                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1856                 TRUE);
1857         gtk_widget_set_sensitive(
1858                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1859                 FALSE);
1860         gtk_widget_set_sensitive(
1861                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1862                FALSE);
1863         gtk_widget_set_sensitive(
1864                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1865                 TRUE);
1866         gtk_widget_set_sensitive(
1867                 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1868                 TRUE);
1869         }
1870 }
1871
1872 /** sets sensitivity of menu items due to user selection made
1873  *
1874  * @param user_data - user data set when the function was called 
1875  * @return
1876  */
1877 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
1878 {
1879         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1880         if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
1881         {
1882                gtk_widget_set_sensitive(
1883                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1884                TRUE);
1885         }
1886         else
1887         {
1888                gtk_widget_set_sensitive(
1889                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1890                FALSE);
1891         }
1892
1893         if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
1894         {
1895                gtk_widget_set_sensitive(
1896                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1897                FALSE);
1898         }
1899         else
1900         {
1901                gtk_widget_set_sensitive(
1902                GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1903                TRUE);
1904         }
1905 }
1906 /** reads gconf entries and sets variables with a proper data; it is necessary
1907  * for changing the bookmarks mode
1908  *
1909  * @param user_data - user data set when the function was called
1910  * @return
1911  */
1912 void ws_gui_read_active_dictionaries(gpointer user_data)
1913 {
1914         WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1915
1916         
1917         ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
1918                                              GCONF_PATH,
1919                                              NULL);
1920 }