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