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