1 /*******************************************************************************
2 This file is part of WhiteStork.
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.
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.
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
18 Copyright 2006 ComArch S.A.
19 *******************************************************************************/
20 #include <ws_gui_callbacks.h>
22 #include <ws_gui_layout.h>
25 /** \brief show how much time did take a callback of another function
28 static double timer(gboolean start, gchar* message)
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;
39 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
41 // things to do on the beggining of function's work
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);
50 // we just want to end some timer - print some information
53 gettimeofday(&actual_time,NULL);
54 last_time = g_array_index(stack, struct timeval, 0);
55 g_array_remove_index(stack, 0);
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;
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;
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));
74 g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] "
78 ((long)(result.tv_sec*1e6)+(result.tv_usec)));
79 // stack is empty so we delete everything
82 g_array_free(stack, TRUE);
91 /** this function handles signals from dbus; it is called
92 when there are any messages from other modules
94 * @param error - error message recived from DBUS
95 * @param words - array with recived data structure
96 * @param user_data - pointer to data structure
99 void ws_gui_signal_hander (GError *error, GArray *words, gpointer user_data)
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)
106 case WS_DBUS_ERROR_ENGINE_NOT_FOUND:
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,
114 _("ws_ni_error_occured"));
115 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
117 g_signal_connect_swapped(
118 GTK_OBJECT (ws_gui_app->ws_message_dialog),
120 G_CALLBACK (gtk_main_quit),
125 case WS_DBUS_ERROR_FILE_NOT_FOUND:
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,
133 _("ws_ni_no_dictionary_available"));
135 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
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;
146 gtk_widget_set_sensitive(
147 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
149 gtk_widget_set_sensitive(
150 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
154 GTK_DIALOG(ws_gui_app->ws_message_dialog))
158 ws_gui_app->ws_message_dialog);
163 case WS_DBUS_INFO_CACHING:
165 ws_gui_app->ws_gui_banner_caching =
166 hildon_banner_show_progress(
167 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
170 ws_gui_app->caching_flag = TRUE;
171 hildon_banner_set_fraction(
172 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
174 gtk_widget_set_sensitive(
175 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
177 gtk_widget_set_sensitive(
178 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
180 gtk_widget_set_sensitive(
181 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
183 gtk_widget_set_sensitive(
184 GTK_WIDGET(ws_gui_app->ws_gui_w_list->ws_gui_view),
190 case WS_DBUS_INFO_CACHING_FINISHED:
193 GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
194 ws_gui_app->caching_flag = FALSE;
195 gtk_widget_set_sensitive(
196 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
198 gtk_widget_set_sensitive(
199 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
201 gtk_widget_set_sensitive(
202 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
204 gtk_widget_set_sensitive(
205 GTK_WIDGET(ws_gui_app->ws_gui_w_list->ws_gui_view),
211 case WS_DBUS_ERROR_DICTIONARY_NOT_LOAD:
213 if (ws_gui_app->ws_gui_history_cur_pos >= 0 &&
214 ws_gui_app->ws_gui_history_cur_pos <=HISTORY_LEN)
216 g_array_remove_index(ws_gui_app->ws_gui_history,
217 ws_gui_app->ws_gui_history_cur_pos);
220 ws_gui_app->ws_message_dialog = gtk_message_dialog_new(
221 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
222 GTK_DIALOG_DESTROY_WITH_PARENT,
225 _("ws_ni_dictionary_unavailable"));
226 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
228 GTK_DIALOG(ws_gui_app->ws_message_dialog))
231 gtk_widget_destroy(ws_gui_app->ws_message_dialog);
236 case WS_DBUS_BOOKMARKS_ADDED_OK:
238 gtk_infoprint(GTK_WINDOW(
239 ws_gui_app->ws_gui_hildon_window),
240 _("ws_ni_bookmark_added"));
244 case WS_DBUS_BOOKMARKS_REMOVED_OK:
246 gtk_infoprint(GTK_WINDOW(
247 ws_gui_app->ws_gui_hildon_window),
248 _("ws_ni_bookmark_removed"));
252 case WS_DBUS_BOOKMARKS_ADDED_FAIL:
254 gtk_infoprint(GTK_WINDOW(
255 ws_gui_app->ws_gui_hildon_window),
256 _("ws_ni_bookmark_not_added"));
260 case WS_DBUS_BOOKMARKS_REMOVED_FAIL:
262 gtk_infoprint(GTK_WINDOW(
263 ws_gui_app->ws_gui_hildon_window),
264 _("ws_ni_bookmark_not_removed"));
268 case WS_DBUS_LOAD_BOOKMARK_FAILED:
270 gtk_widget_set_sensitive(
271 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
273 ws_gui_app->bookmark_avail = FALSE;
275 ws_gui_app->ws_message_dialog =
276 gtk_message_dialog_new(
277 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
278 GTK_DIALOG_DESTROY_WITH_PARENT,
281 _("ws_ni_bookmarks_unavailable"));
284 GTK_DIALOG(ws_gui_app->ws_message_dialog))
288 ws_gui_app->ws_message_dialog);
294 case WS_DBUS_EXTRACT_FILE:
296 ws_gui_app->ws_gui_banner_extracting =
297 hildon_banner_show_animation(
298 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
300 _("ws_pb_extracting"));
302 ws_gui_app->caching_flag = TRUE;
304 gtk_widget_set_sensitive(
305 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
307 gtk_widget_set_sensitive(
308 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
314 case WS_DBUS_EXTRACT_FILE_FINISHED:
317 GTK_WIDGET(ws_gui_app->ws_gui_banner_extracting));
318 ws_gui_app->caching_flag = FALSE;
320 gtk_infoprint(GTK_WINDOW(
321 ws_gui_app->ws_gui_hildon_window),
322 _("ws_ni_dictionary_added"));
324 gtk_widget_set_sensitive(
325 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
327 gtk_widget_set_sensitive(
328 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
336 /** this function handles signals from dbus; it is called when progress bar
337 status has been changed
339 * @param error - error message recived from DBUS
340 * @param words - array with recived data structure
341 * @param user_data - pointer to data structure
344 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
346 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
347 osso_rpc_t osss_data;
348 osss_data = g_array_index (words, osso_rpc_t, 0);
349 double progress = osss_data.value.d;
350 if (ws_gui_app->caching_flag == TRUE)
352 hildon_banner_set_fraction(
353 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
358 /** this function clean GtkListStore row by row
360 * @param list - GtkListStore to be remoeved
363 void ws_gui_clear_list (GtkListStore* list)
368 tmp = gtk_tree_model_get_iter_first(
369 GTK_TREE_MODEL(list),
374 tmp = gtk_list_store_remove(list, &iter);
380 /** this function handles signal from dbus and transfer recived
381 (found in a dictionary) words to the words list
383 * @param error - error message recived from DBUS
384 * @param words - array with recived data structure
385 * @param user_data - pointer to data structure
388 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
390 timer(TIMER_START, (gchar*)__FUNCTION__);
394 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
396 g_signal_handlers_block_by_func(G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_view),
397 G_CALLBACK (ws_gui_view_cursor_changed),
402 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
405 for (i=0;i<words->len;++i)
407 data = g_array_index (words, osso_rpc_t, i);
408 tmp_word = g_strconcat(data.value.s,NULL);
409 g_array_append_val(tmp, tmp_word);
412 g_assert(ws_gui_app->ws_gui_banner);
413 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
415 ws_gui_app->ws_gui_banner_flag = FALSE;
416 gtk_widget_set_sensitive(
417 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
419 gtk_widget_set_sensitive(
420 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
423 ws_gui_clear_list(ws_gui_app->ws_gui_w_list->ws_gui_store);
426 ws_gui_app->ws_gui_w_list->ws_gui_model =
427 create_and_fill_model(tmp, ws_gui_app);
429 if (ws_gui_app->history_flag == TRUE)
432 GValue value = { 0, };
433 GtkTreeIter tmp_iter;
435 gboolean keep_searching = TRUE;
437 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(
438 ws_gui_app->ws_gui_w_list->ws_gui_model), &tmp_iter) == TRUE)
441 pattern = strdup(g_array_index(ws_gui_app->ws_gui_history,
443 ws_gui_app->ws_gui_history_cur_pos));
445 gtk_tree_model_get_value(GTK_TREE_MODEL(
446 ws_gui_app->ws_gui_w_list->ws_gui_model),
451 if (strcmp(((gchar *)g_value_get_string (&value)), pattern) == 0)
453 gtk_tree_selection_select_iter(
454 ws_gui_app->ws_gui_w_list->ws_gui_selection,
460 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_model), &tmp_iter) == TRUE && keep_searching == TRUE)
462 gtk_tree_model_get_value(GTK_TREE_MODEL(
463 ws_gui_app->ws_gui_w_list->ws_gui_model),
468 if (strcmp((gchar *)g_value_get_string (&value), pattern) == 0)
470 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(
471 ws_gui_app->ws_gui_w_list->ws_gui_model),
474 ws_gui_app->ws_gui_history_iter,
476 ws_gui_app->ws_gui_history_cur_pos));
478 gtk_tree_selection_select_iter(
479 ws_gui_app->ws_gui_w_list->ws_gui_selection,
482 keep_searching = FALSE;
489 ws_gui_app->history_flag = FALSE;
490 ws_dbus_client_find_translation(ws_gui_app->dbus_data,
491 g_array_index(ws_gui_app->ws_gui_history,
493 ws_gui_app->ws_gui_history_cur_pos));
495 ws_gui_app->html_flag = TRUE;
501 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
502 _("ws_ni_no_words_found"));
504 ws_gui_fill_html(" ", ws_gui_app);
505 ws_gui_app->html_flag = FALSE;
506 g_free(ws_gui_app->last_word);
507 ws_gui_app->last_word = NULL;
510 g_signal_handlers_unblock_by_func(G_OBJECT(
511 ws_gui_app->ws_gui_w_list->ws_gui_view),
512 G_CALLBACK (ws_gui_view_cursor_changed),
516 timer(TIMER_STOP, (gchar*)__FUNCTION__);
519 /** this function handles signal from dbus and send recived data to
522 * @param error - error message recived from DBUS
523 * @param words - array with recived data structure
524 * @param user_data - pointer to data structure
527 void ws_gui_dbus_return_translation (GError *error,
531 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
535 data = g_array_index (words, osso_rpc_t, 0);
536 ws_gui_fill_html(format_html(data.value.s, ws_gui_app), ws_gui_app);
537 ws_gui_app->html_flag = TRUE;
541 /** this function handles signal from dbus and send recived data to
544 * @param error - error message recived from DBUS
545 * @param words - array with recived data structure
546 * @param user_data - pointer to data structure
549 void ws_dbus_server_return_extracted_bzip(GError *error,
553 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
557 data = g_array_index (words, osso_rpc_t, 0);
559 if (data.value.s[0] == '\0')
561 gtk_infoprint(GTK_WINDOW(
562 ws_gui_app->ws_gui_hildon_window),
563 _("ws_ni_dictionary_not_added"));
567 if (ws_gui_load_dict(data.value.s, ws_gui_app) == TRUE)
575 * this function allows to free allocated memory
577 * @param user_data - pointer to data structure
579 void ws_gui_free_memory(gpointer user_data)
581 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
582 g_array_free(ws_gui_app->ws_gui_history, TRUE);
583 pango_font_description_free(ws_gui_app->p);
584 g_free(ws_gui_app->last_word);
585 g_free(ws_gui_app->ws_gui_w_list);
586 g_free(ws_gui_app->ws_gui_menu);
590 /** this function handle press signals (keyboard)
594 * @param user_data - ponter to data structure
595 * @return TRUE to stop other handlers from being invoked for the event.
596 FALSE to propagate the event further.
598 gboolean hildon_key_press_listener (GtkWidget * widget,
599 GdkEventKey * keyevent,
602 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
604 switch ((guint)(keyevent->keyval)) {
605 case HILDON_HARDKEY_UP:
607 gtk_container_set_focus_vadjustment(
608 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
609 gtk_scrolled_window_get_vadjustment(
611 ws_gui_app->ws_gui_scrolledwindow_left)));
612 ws_gui_app->v_new_value =
613 gtk_adjustment_get_value(
615 ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
616 if (ws_gui_app->v_new_value >
617 ws_gui_app->ws_gui_vadj->lower)
619 gtk_adjustment_set_value(
620 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
621 ws_gui_app->v_new_value);
627 case HILDON_HARDKEY_DOWN:
629 gtk_container_set_focus_vadjustment(
630 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
631 gtk_scrolled_window_get_vadjustment(
633 ws_gui_app->ws_gui_scrolledwindow_left)));
634 ws_gui_app->v_new_value = gtk_adjustment_get_value(
635 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj))
636 + ws_gui_app->v_delta;
638 if (ws_gui_app->v_new_value <
639 (ws_gui_app->ws_gui_vadj->upper -
640 ws_gui_app->ws_gui_vadj->page_size))
642 gtk_adjustment_set_value(
643 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
644 ws_gui_app->v_new_value);
649 case HILDON_HARDKEY_LEFT:
651 gtk_container_set_focus_hadjustment(
652 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
653 gtk_scrolled_window_get_hadjustment(
655 ws_gui_app->ws_gui_scrolledwindow_left)));
657 ws_gui_app->h_new_value = gtk_adjustment_get_value(
658 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
659 - ws_gui_app->h_delta;
661 if (ws_gui_app->h_new_value >
662 ws_gui_app->ws_gui_hadj->lower)
664 gtk_adjustment_set_value(
665 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
666 ws_gui_app->h_new_value);
671 case HILDON_HARDKEY_RIGHT:
673 gtk_container_set_focus_hadjustment(
674 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
675 gtk_scrolled_window_get_hadjustment(
677 ws_gui_app->ws_gui_scrolledwindow_left)));
679 ws_gui_app->h_new_value = gtk_adjustment_get_value(
680 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
681 + ws_gui_app->h_delta;
683 if (ws_gui_app->h_new_value <
684 (ws_gui_app->ws_gui_hadj->upper -
685 ws_gui_app->ws_gui_hadj->page_size))
687 gtk_adjustment_set_value(
688 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
689 ws_gui_app->h_new_value);
694 case HILDON_HARDKEY_SELECT:
695 ws_gui_search(NULL, ws_gui_app);
698 case HILDON_HARDKEY_FULLSCREEN:
699 ws_gui_full_screen(NULL, ws_gui_app);
702 case HILDON_HARDKEY_INCREASE:
703 ws_gui_html_zoom_in(NULL, ws_gui_app);
706 case HILDON_HARDKEY_DECREASE:
707 ws_gui_html_zoom_out(NULL, ws_gui_app);
710 case HILDON_HARDKEY_ESC:
711 ws_gui_search_stop(NULL, ws_gui_app);
721 /** this function allow to hide words list using menu item from application menu
723 * @param checkmenuitem - the object which received the signal
724 * @param user_data - user data set when the signal handler was connected
727 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
730 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
731 if (gtk_check_menu_item_get_active(
732 GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
734 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
735 gtk_toggle_tool_button_set_active(
736 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide),
738 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
739 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
744 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
745 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
746 ws_gui_app->ws_gui_toobar_button_hide),
748 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
749 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
754 /** this function allow to hide words list using toggle button placed in
757 * @param toolbar - the object which received the signal
758 * @param user_data - user data set when the signal handler was connected
761 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
763 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
765 if (gtk_toggle_tool_button_get_active(
766 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
768 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
769 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
770 ws_gui_app->ws_gui_toobar_button_hide),
772 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
773 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
778 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
779 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
780 ws_gui_app->ws_gui_toobar_button_hide),
782 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
783 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
788 /** add word to the history
790 * @param new_word - word which is going to be append to the history array
791 * @param user_data - user data set when the signal handler was connected
794 void ws_gui_history_add(char *new_word, gpointer user_data)
796 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
798 if (ws_gui_app->history_flag != TRUE)
803 gchar *tmp_last_searched;
804 gchar *tmp_iter = NULL;
805 gchar *previous_word = " ";
807 if (ws_gui_app->ws_gui_history_cur_pos > -1 &&
808 g_array_index(ws_gui_app->ws_gui_history,
810 ws_gui_app->ws_gui_history_cur_pos) != NULL)
812 previous_word = NULL;
813 previous_word = g_array_index(
814 ws_gui_app->ws_gui_history,
816 ws_gui_app->ws_gui_history_cur_pos);
819 i = ws_gui_app->ws_gui_history_cur_pos + 1;
820 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
823 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);
825 if (previous_word != NULL &&
826 strcmp(previous_word, new_word) != 0)
830 g_array_remove_index(
831 ws_gui_app->ws_gui_history_list,
833 g_array_remove_index(
834 ws_gui_app->ws_gui_history_iter,
838 g_array_remove_index(
839 ws_gui_app->ws_gui_history,
843 ws_gui_app->ws_gui_history,
849 ws_gui_app->ws_gui_history_cur_pos ++;
851 if (ws_gui_app->bookmark_mode == FALSE)
853 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
857 tmp_last_searched = g_strdup(ws_gui_app->last_searched_in_book);
860 g_array_append_val(ws_gui_app->ws_gui_history_list,
863 tmp_word = g_strdup(new_word);
865 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
866 g_array_append_val(ws_gui_app->ws_gui_history_iter, tmp_iter);
869 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
871 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
872 g_array_remove_index(ws_gui_app->ws_gui_history_list,
874 g_array_remove_index(ws_gui_app->ws_gui_history_iter,
877 ws_gui_app->ws_gui_history_cur_pos--;
881 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
886 ws_gui_check_history(ws_gui_app);
889 /** display previously choosen word (previous from the history array)
890 if avaible, sets current position in the history array
892 * @param button - button which recived a signal
893 * @param user_data - user data set when the signal handler was connected
896 void ws_gui_history_back(GtkButton *button, gpointer user_data)
898 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
900 ws_gui_app->history_flag = TRUE;
902 if (ws_gui_app->ws_gui_history_cur_pos > 0)
904 ws_gui_app->ws_gui_history_cur_pos =
905 ws_gui_app->ws_gui_history_cur_pos - 1;
909 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n\n\n\nHISTORY BACK:\n pattern: %s,\nlist: %s,\niter: %s\n\n", g_array_index(ws_gui_app->ws_gui_history,
911 ws_gui_app->ws_gui_history_cur_pos), g_array_index(ws_gui_app->ws_gui_history_list,
913 ws_gui_app->ws_gui_history_cur_pos), g_array_index(ws_gui_app->ws_gui_history_iter,
915 ws_gui_app->ws_gui_history_cur_pos));
918 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
920 (g_array_index(ws_gui_app->ws_gui_history_list,
922 ws_gui_app->ws_gui_history_cur_pos)),
927 ws_dbus_client_find_word (ws_gui_app->dbus_data,
928 g_array_index(ws_gui_app->ws_gui_history_list,
930 ws_gui_app->ws_gui_history_cur_pos)
935 gtk_widget_set_sensitive (
936 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
938 gtk_widget_set_sensitive(
939 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
943 ws_gui_check_history(ws_gui_app);
946 /** display choosen word, next in the history array (if avaible),
947 sets current position in the history array
949 * @param button - button which recived a signal
950 * @param user_data - user data set when the signal handler was connected
953 void ws_gui_history_next(GtkButton *button, gpointer user_data)
955 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
957 ws_gui_app->history_flag = TRUE;
959 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
961 ws_gui_app->ws_gui_history_cur_pos+1);
963 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
966 ws_gui_app->ws_gui_history_cur_pos =
967 ws_gui_app->ws_gui_history_cur_pos + 1;
970 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n\n\n\nHISTORY NEXT:\n pattern: %s,\nlist: %s,\niter: %s\n\n", g_array_index(ws_gui_app->ws_gui_history,
972 ws_gui_app->ws_gui_history_cur_pos), g_array_index(ws_gui_app->ws_gui_history_list,
974 ws_gui_app->ws_gui_history_cur_pos), g_array_index(ws_gui_app->ws_gui_history_iter,
976 ws_gui_app->ws_gui_history_cur_pos));
978 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
980 (g_array_index(ws_gui_app->ws_gui_history_list,
982 ws_gui_app->ws_gui_history_cur_pos)),
986 ws_dbus_client_find_word(ws_gui_app->dbus_data,
987 g_array_index(ws_gui_app->ws_gui_history_list,
989 ws_gui_app->ws_gui_history_cur_pos)
995 gtk_widget_set_sensitive(
996 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
998 gtk_widget_set_sensitive(
999 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
1003 ws_gui_check_history(ws_gui_app);
1006 /** check current position in the history array and sets sensitivity of buttons
1007 / menu items, depends on availablity of words in the history
1009 * @param user_data - user data set when the signal handler was connected
1012 void ws_gui_check_history(gpointer user_data)
1014 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1016 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
1018 ws_gui_app->ws_gui_history_cur_pos+1);
1020 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
1023 gtk_widget_set_sensitive(
1024 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
1026 gtk_widget_set_sensitive(
1027 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
1032 gtk_widget_set_sensitive(
1033 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
1035 gtk_widget_set_sensitive(
1036 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
1040 tmp = g_array_index(ws_gui_app->ws_gui_history,
1042 ws_gui_app->ws_gui_history_cur_pos-1);
1043 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
1045 gtk_widget_set_sensitive(
1046 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
1048 gtk_widget_set_sensitive(
1049 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
1054 gtk_widget_set_sensitive (
1055 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
1057 gtk_widget_set_sensitive(
1058 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
1063 /** create TreeView Model, which allows to display words list
1065 * @param words_list - array with words(found in a dictionary), recived from
1067 * @param user_data - user data set when the signal handler was connected
1070 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
1072 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1074 g_signal_handlers_block_by_func(G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_view),
1075 G_CALLBACK (ws_gui_view_cursor_changed),
1079 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
1082 valid = gtk_tree_model_get_iter_first(
1083 GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
1084 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
1086 /* Append a row and fill in some data */
1089 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
1090 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
1092 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
1093 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
1097 tmp = g_strdup(g_array_index(words_list, gchar*, i));
1100 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
1103 if (ws_gui_app->history_flag == FALSE && tmp != NULL)
1105 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
1106 ws_gui_history_add(tmp, ws_gui_app);
1108 g_free(ws_gui_app->last_word);
1109 ws_gui_app->last_word = NULL;
1110 ws_gui_app->last_word = g_strdup (tmp);
1111 ws_gui_app->history_flag = FALSE;
1114 g_signal_handlers_unblock_by_func(G_OBJECT(
1115 ws_gui_app->ws_gui_w_list->ws_gui_view),
1116 G_CALLBACK (ws_gui_view_cursor_changed),
1119 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
1123 /** create TreeView and TreeModel using create_and_fill_model() function;
1124 it is necessary to display found words in a words list;
1126 * @param words_list - array with words(found in a dictionary),
1127 * recived from DBUS;
1128 * @param user_data - user data set when the signal handler was connected
1131 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
1133 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1135 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
1137 ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
1138 gtk_tree_view_insert_column_with_attributes(
1139 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
1142 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
1146 ws_gui_app->ws_gui_w_list->ws_gui_model =
1147 create_and_fill_model(words_list, ws_gui_app);
1149 gtk_tree_view_set_model(
1150 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
1151 ws_gui_app->ws_gui_w_list->ws_gui_model);
1152 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
1154 return ws_gui_app->ws_gui_w_list->ws_gui_view;
1157 /** switch application between fun screen and normal mode
1159 * @param menuitem - object which recived the signal
1160 * @param user_data - user data set when the signal handler was connected
1163 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
1166 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1167 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
1169 gtk_window_fullscreen(
1170 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1171 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1172 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1174 ws_gui_app->ws_gui_full_screen_flag = TRUE;
1175 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1176 _("ws_ib_fullscreen_on"));
1180 gtk_window_unfullscreen(
1181 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1182 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1183 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1185 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1186 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1187 _("ws_ib_fullscreen_off"));
1191 /** search for selected text in a dictionary
1193 * @param menuitem - object which recived the signal
1194 * @param user_data - user data set when the signal handler was connected
1197 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1199 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1201 ws_gui_app->ws_gui_clipboard_primary =
1202 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1203 GDK_SELECTION_PRIMARY);
1204 temp = gtk_clipboard_wait_for_text(
1205 ws_gui_app->ws_gui_clipboard_primary);
1208 if (temp != NULL || strcmp(temp, " "))
1210 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1214 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1218 hildon_banner_show_information(
1219 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1221 _("ws_ni_no_text_selected"));
1225 /** select whole text in the translation (html) area
1227 * @param menuitem - object which recived the signal
1228 * @param user_data - user data set when the signal handler was connected
1231 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
1233 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1234 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1237 /** copy selected text to the clipoard from context popup menu
1239 * @param menuitem - object which recived the signal
1240 * @param user_data - user data set when the signal handler was connected
1243 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
1245 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1246 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1247 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1251 /** paste copied text into toolbar entry
1253 * @param menuitem - object which recived the signal
1254 * @param user_data - user data set when the signal handler was connected
1257 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1259 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1263 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1264 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1268 temp = g_strconcat(temp2, temp, NULL);
1269 temp = g_strdelimit(temp, "\n", ' ');
1270 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1274 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1278 /** zoom in text in translation (html) area
1280 * @param menuitem - object which recived the signal
1281 * @param user_data - user data set when the signal handler was connected
1284 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1286 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1287 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1288 if (ws_gui_app->zoom > ZOOM_MAX)
1290 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1291 gtk_infoprint(GTK_WINDOW(
1292 ws_gui_app->ws_gui_hildon_window),
1293 _("ws_ib_max_zoom"));
1297 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1300 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1302 gtk_infoprint(GTK_WINDOW(
1303 ws_gui_app->ws_gui_hildon_window),
1304 _("ws_ib_zoom_default"));
1308 gtk_infoprint(GTK_WINDOW(
1309 ws_gui_app->ws_gui_hildon_window),
1310 _("ws_ib_zoom_in"));
1315 /** zoom out text in translation (html) area
1317 * @param menuitem - object which recived the signal
1318 * @param user_data - user data set when the signal handler was connected
1321 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1323 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1324 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1325 if (ws_gui_app->zoom < ZOOM_MIN)
1327 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1328 gtk_infoprint(GTK_WINDOW(
1329 ws_gui_app->ws_gui_hildon_window),
1330 _("ws_ib_min_zoom"));
1334 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1337 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1339 gtk_infoprint(GTK_WINDOW(
1340 ws_gui_app->ws_gui_hildon_window),
1341 _("ws_ib_zoom_default"));
1345 gtk_infoprint(GTK_WINDOW(
1346 ws_gui_app->ws_gui_hildon_window),
1347 _("ws_ib_zoom_out"));
1352 /** start searching, send typed word to DBUS and query for words
1354 * @param widget - object which recived the signal
1355 * @param user_data - user data set when the signal handler was connected
1358 void ws_gui_search(GtkWidget * widget, gpointer user_data)
1360 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1362 if (ws_gui_app->ws_gui_banner_flag == FALSE)
1364 gchar* ws_gui_text = NULL;
1365 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1370 if (ws_gui_app->bookmark_mode == FALSE)
1372 g_free(ws_gui_app->last_searched);
1373 ws_gui_app->last_searched = NULL;
1374 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1378 g_free(ws_gui_app->last_searched_in_book);
1379 ws_gui_app->last_searched_in_book = NULL;
1380 ws_gui_app->last_searched_in_book = g_strdup(ws_gui_text);
1383 g_strstrip(ws_gui_text);
1384 if (strlen(ws_gui_text) != 0)
1386 gtk_widget_show(ws_gui_app->ws_gui_banner);
1388 gtk_widget_set_sensitive(
1389 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1391 gtk_widget_set_sensitive(
1392 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1395 ws_gui_app->ws_gui_banner_flag = TRUE;
1396 ws_gui_fill_html(" ", ws_gui_app);
1397 ws_gui_app->html_flag = FALSE;
1398 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1404 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1405 _("ws_ni_no_word_typed"));
1407 g_free(ws_gui_app->last_word);
1408 ws_gui_app->last_word=NULL;
1412 /** stop search process
1414 * @param button - object which recived the signal
1415 * @param user_data - user data set when the signal handler was connected
1418 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
1420 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1421 if (ws_gui_app->ws_gui_banner_flag == TRUE)
1423 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1424 ws_gui_app->ws_gui_banner_flag = FALSE;
1425 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1427 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1428 _("ws_ni_search_aborted"));
1430 gtk_widget_set_sensitive(GTK_WIDGET
1431 (ws_gui_app->ws_gui_toobar_button_stop),
1436 /** this function is called just before closing application;
1437 it sends signal to DBUS and destroys it;
1439 * @param widget - object which recived the signal
1441 * @param user_data - user data set when the signal handler was connected
1444 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
1446 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1447 ws_gui_app->bookmark_mode = FALSE;
1448 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1449 g_timer_destroy(ws_gui_app->timer);
1450 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1451 ws_dbus_destroy (ws_gui_app->dbus_data);
1452 ws_gui_free_memory(ws_gui_app);
1457 /** this function is called just before closing application,
1458 from application menu; it sends signal to DBUS and destroys it;
1460 * @param menuitem - object which recived the signal
1461 * @param user_data - user data set when the signal handler was connected
1464 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1466 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1467 ws_gui_app->bookmark_mode = FALSE;
1468 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1469 g_timer_destroy(ws_gui_app->timer);
1470 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1471 ws_dbus_destroy (ws_gui_app->dbus_data);
1472 ws_gui_free_memory(ws_gui_app);
1477 /** fill translation area with text (html) recived from DBUS
1479 * @param html_context - text which is going to be displayed; it should be html
1480 * @param user_data - user data set when the function was called
1483 void ws_gui_fill_html(char *html_context, gpointer user_data)
1485 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1486 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1488 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1493 /** read adjustment of left scrollwindow, which is necessary to navigate with
1494 arrow keys inside words list
1496 * @param user_data - user data set when the signal handler was connected
1499 void ws_gui_read_adjustment(gpointer user_data)
1501 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1503 ws_gui_app->ws_gui_hadj =
1504 gtk_scrolled_window_get_hadjustment(
1505 GTK_SCROLLED_WINDOW(
1506 ws_gui_app->ws_gui_scrolledwindow_left));
1508 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1509 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1511 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1512 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1514 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1515 ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1516 ws_gui_app->v_new_value =
1517 gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1518 ws_gui_app->v_delta;
1520 gtk_container_set_focus_vadjustment(
1521 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
1522 gtk_scrolled_window_get_vadjustment(
1523 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1527 /** allows to display image in html area
1529 * @param html - object which received a signal
1530 * @param url - url to the image
1531 * @param stream - html stream
1534 void ws_gui_url_requested (
1537 GtkHTMLStream *stream)
1541 if (url && !strncmp (url, "file:", 5)) {
1543 fd = open (url, O_RDONLY);
1547 buf = alloca (8192);
1548 while ((size = read (fd, buf, 8192)) > 0) {
1549 gtk_html_stream_write (stream, buf, size);
1551 gtk_html_stream_close(stream, size == -1
1552 ? GTK_HTML_STREAM_ERROR
1553 : GTK_HTML_STREAM_OK);
1560 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1563 /** handles button press event and examines what kind of event was it
1566 * @param widget - object which received a signal
1567 * @param event - type of event which has been performed
1568 * @param user_data - user data set when the signal handler was connected
1569 * @return TRUE to stop other handlers from being invoked for the event.
1570 FALSE to propagate the event further
1572 gboolean ws_gui_button_press(GtkWidget *widget,
1573 GdkEventButton *event,
1576 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1577 if (ws_gui_app->ws_gui_sel_flag == FALSE)
1579 if (event->type == GDK_2BUTTON_PRESS)
1581 ws_gui_app->ws_gui_double_click = TRUE;
1582 g_timer_stop(ws_gui_app->timer);
1583 g_timer_reset(ws_gui_app->timer);
1587 g_signal_stop_emission_by_name(G_OBJECT(
1588 ws_gui_app->ws_gui_html),
1589 "button-press-event");
1590 g_timer_start(ws_gui_app->timer);
1591 gtk_timeout_add((guint)(PRESS_TIME*1000),
1592 (GtkFunction)(ws_gui_show_popup),
1598 ws_gui_app->ws_gui_sel_flag = FALSE;
1604 /** handles button release event and examines whether 'click' or 'tap and hold'
1605 event it supposed to be
1607 * @param widget - object which received a signal
1608 * @param event - type of event which has been performed
1609 * @param user_data - user data set when the signal handler was connected
1610 * @return TRUE to stop other handlers from being invoked for the event.
1611 FALSE to propagate the event further
1613 gboolean ws_gui_button_release (GtkWidget *widget,
1614 GdkEventButton *event,
1617 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1618 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1619 g_timer_stop(ws_gui_app->timer);
1620 g_timer_reset(ws_gui_app->timer);
1621 if (ws_gui_app->ws_gui_double_click == TRUE)
1623 ws_gui_app->ws_gui_double_click = FALSE;
1626 else if (tmp < PRESS_TIME)
1628 struct _GtkHTML *tmp = (struct _GtkHTML *)
1629 (ws_gui_app->ws_gui_html);
1630 html_engine_unselect_all(tmp->engine);
1636 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1638 * @param user_data - user data set when the signal handler was connected
1641 guint ws_gui_show_popup (gpointer user_data)
1643 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1644 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1645 if (tmp > PRESS_TIME)
1647 ws_gui_create_popup_menu(ws_gui_app);
1649 return (guint)(FALSE);
1653 /** checks clipboard content and sets sensitivity of widgets
1655 * @param widget - object which recived a signal
1656 * @param user_data - user data set when the signal handler was connected
1659 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
1661 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1662 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1664 gtk_widget_set_sensitive(
1665 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1670 gtk_widget_set_sensitive(
1671 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1675 struct _GtkHTML *tmp = (struct _GtkHTML *)(ws_gui_app->ws_gui_html);
1677 if (html_engine_is_selection_active(tmp->engine) == TRUE)
1679 gtk_widget_set_sensitive(GTK_WIDGET
1680 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1685 gtk_widget_set_sensitive(GTK_WIDGET
1686 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1690 if (ws_gui_app->html_flag == FALSE)
1692 gtk_widget_set_sensitive(GTK_WIDGET
1693 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1698 gtk_widget_set_sensitive(GTK_WIDGET
1699 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1705 /** gets received string (with translation), formats it and sends it to be
1708 * @param received_string - content received from Manager
1709 * @param user_data - user data set when the function has been called
1712 gchar * format_html (gchar * received_string, gpointer user_data)
1714 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1717 str_final = g_string_new(received_string);
1718 str_tmp = g_string_new(received_string);
1722 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
1726 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1728 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1729 str_final = g_string_erase(str_final,
1730 (long)(tmp - str_final->str),
1732 str_final = g_string_insert(str_final,
1733 (long)(tmp - str_final->str),
1734 "<html><head></head><body><center><table width=\"400px\"><tr>"
1735 "<td><table border=1 width=100%><tr>"
1736 "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1737 "<img align=left src=\"file:/usr/share/pixmaps/"
1738 "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1740 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1741 if (ws_gui_app->last_word != NULL)
1743 str_tmp = g_string_erase(str_tmp,
1744 (long)(tmp2 - str_tmp->str),
1745 14 + strlen(ws_gui_app->last_word));
1749 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1751 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1752 str_final = g_string_erase(str_final,
1753 (long)(tmp - str_final->str),
1755 str_final = g_string_insert(str_final,
1756 (long)(tmp - str_final->str),
1757 "</font></th></tr></table>");
1759 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1760 str_tmp = g_string_erase(str_tmp,
1761 (long)(tmp2 - str_tmp->str),
1765 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1767 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1768 str_final = g_string_erase (str_final,
1769 (long)(tmp - str_final->str),
1771 str_final = g_string_insert (str_final,
1772 (long)(tmp - str_final->str),
1773 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1774 "share/pixmaps/ws_tra.png\">");
1776 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1777 str_tmp = g_string_erase(str_tmp,
1778 (long)(tmp2 - str_tmp->str),
1782 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1784 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1785 str_final = g_string_erase(str_final,
1786 (long)(tmp - str_final->str),
1788 str_final = g_string_insert(str_final,
1789 (long)(tmp - str_final->str),
1790 "</td></tr></table></center>");
1792 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1793 str_tmp = g_string_erase(str_tmp,
1794 (long)(tmp2 - str_tmp->str),
1798 str_final = g_string_append(str_final,
1799 "</td></tr></table></body></html>");
1801 ws_gui_app->raw_translation = g_string_insert(
1802 ws_gui_app->raw_translation,
1806 return str_final->str;
1809 /** open bookmarks database
1811 * @param menuitem - object which recived the signal
1812 * @param user_data - user data set when the signal handler was connected
1815 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1817 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1819 ws_gui_read_active_dictionaries(ws_gui_app);
1821 g_free(ws_gui_app->last_word);
1822 ws_gui_app->last_word = NULL;
1824 ws_gui_app->bookmark_mode = TRUE;
1825 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1826 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1830 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1832 if(ws_gui_app->ws_gui_history->len >= 0)
1834 ws_gui_clear_array(ws_gui_app->ws_gui_history);
1835 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1836 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1837 ws_gui_app->ws_gui_history_cur_pos = -1;
1839 ws_gui_check_history(ws_gui_app);
1841 ws_gui_fill_html(" ", ws_gui_app);
1842 ws_gui_app->html_flag = FALSE;
1843 //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1844 ws_gui_search(NULL, ws_gui_app);
1848 /** closes bookmarks database
1850 * @param menuitem - object which recived the signal
1851 * @param user_data - user data set when the signal handler was connected
1854 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1856 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1858 ws_gui_read_active_dictionaries(ws_gui_app);
1860 g_free(ws_gui_app->last_word);
1861 ws_gui_app->last_word = NULL;
1863 ws_gui_app->bookmark_mode = FALSE;
1864 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1865 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1867 if(ws_gui_app->ws_gui_history->len >= 0)
1869 ws_gui_clear_array(ws_gui_app->ws_gui_history);
1870 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1871 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1872 ws_gui_app->ws_gui_history_cur_pos = -1;
1874 ws_gui_check_history(ws_gui_app);
1876 ws_gui_fill_html(" ", ws_gui_app);
1877 ws_gui_app->html_flag = FALSE;
1878 g_strstrip(ws_gui_app->last_searched);
1879 if (ws_gui_app->last_searched != NULL)
1881 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1883 ws_gui_app->last_searched,
1885 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1886 ws_gui_search(NULL, ws_gui_app);
1890 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1895 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
1896 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
1897 ws_gui_app->ws_gui_w_list->ws_gui_model =
1898 create_and_fill_model(tmp, ws_gui_app);
1900 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1901 ws_gui_search(NULL, ws_gui_app);
1905 /** adds bookmark to bookmarks database
1907 * @param menuitem - object which recived the signal
1908 * @param user_data - user data set when the signal handler was connected
1911 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1913 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1915 if (ws_gui_app->last_word != NULL)
1917 ws_gui_add_bookmark_dialog(ws_gui_app);
1922 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1923 _("ws_ni_select_word_to_add"));
1927 /** removes bookmark from bookmarks database
1929 * @param menuitem - object which recived the signal
1930 * @param user_data - user data set when the signal handler was connected
1933 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
1936 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1938 if (ws_gui_app->last_word != NULL)
1940 ws_gui_remove_bookmark_dialog(ws_gui_app);
1943 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1947 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1953 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1954 _("ws_ni_select_word_to_remove"));
1960 /** checks wheather dictionaries are available or not; according to the result
1961 * dimmes proper menuitem
1963 * @param menuitem - object which recived the signal
1964 * @param user_data - user data set when the signal handler was connected
1967 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1969 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1970 if (gconf_client_dir_exists(ws_gui_app->client,
1971 GCONF_PATH, NULL) == TRUE)
1973 ws_gui_app->directories = gconf_client_all_dirs(
1980 if(g_slist_length(ws_gui_app->directories) != 0)
1982 gtk_widget_set_sensitive(GTK_WIDGET
1983 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1985 gtk_widget_set_sensitive(GTK_WIDGET
1986 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1988 gtk_widget_set_sensitive(GTK_WIDGET
1989 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1996 gtk_widget_set_sensitive(GTK_WIDGET
1997 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1999 gtk_widget_set_sensitive(GTK_WIDGET
2000 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
2002 gtk_widget_set_sensitive(GTK_WIDGET
2003 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
2009 /** sets sensitivity of menu items due to bookmark's mode
2011 * @param user_data - user data set when the function was called
2014 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
2016 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2021 if (ws_gui_app->bookmark_mode == TRUE)
2023 g_slist_free(ws_gui_app->directories_last);
2024 ws_gui_app->directories_last = NULL;
2025 ws_gui_app->directories_last = g_slist_alloc();
2026 g_slist_free(ws_gui_app->directories);
2027 ws_gui_app->directories = g_slist_alloc();
2029 ws_gui_app->directories = gconf_client_all_dirs(
2033 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
2035 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
2036 name = g_path_get_basename(string);
2037 string = g_strconcat(string, "/active", NULL);
2039 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
2041 ws_gui_app->directories_last =
2042 g_slist_append(ws_gui_app->directories_last,
2046 if (strcmp(name, "bookmarks") == 0)
2048 gconf_client_set_bool(ws_gui_app->client,
2055 gconf_client_set_bool(ws_gui_app->client,
2062 //setting sensitivity of components
2063 gtk_widget_set_sensitive(
2064 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
2066 gtk_widget_set_sensitive(
2067 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
2069 gtk_widget_set_sensitive(
2070 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2072 gtk_widget_set_sensitive(
2073 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2075 gtk_widget_set_sensitive(
2076 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
2081 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
2082 if (g_slist_length(ws_gui_app->directories_last) > 0)
2084 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
2087 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
2089 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
2094 gconf_client_set_bool(ws_gui_app->client,
2101 //setting sensitivity of components
2102 gtk_widget_set_sensitive(
2103 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
2105 gtk_widget_set_sensitive(
2106 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
2108 gtk_widget_set_sensitive(
2109 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2111 gtk_widget_set_sensitive(
2112 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2114 gtk_widget_set_sensitive(
2115 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
2120 /** sets sensitivity of menu items due to user selection made
2122 * @param user_data - user data set when the function was called
2125 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
2127 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2128 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
2130 gtk_widget_set_sensitive(
2131 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2136 gtk_widget_set_sensitive(
2137 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2141 if (ws_gui_app->last_word == NULL ||
2142 (ws_gui_app->last_word[0] == '\0') ||
2143 ws_gui_app->bookmark_mode == TRUE)
2145 gtk_widget_set_sensitive(
2146 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2151 gtk_widget_set_sensitive(
2152 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2156 /** reads gconf entries and sets variables with a proper data; it is necessary
2157 * for changing the bookmarks mode
2159 * @param user_data - user data set when the function was called
2162 void ws_gui_read_active_dictionaries(gpointer user_data)
2164 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2167 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
2172 void ws_gui_clear_array(GArray *history)
2174 if(history->len >= 0)
2176 history = g_array_remove_range(history, 0, history->len);
2180 void ws_gui_view_cursor_changed(GtkTreeView *treeview, gpointer user_data)
2182 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2184 if (gtk_tree_selection_get_selected(ws_gui_app->ws_gui_w_list->ws_gui_selection,
2185 &ws_gui_app->ws_gui_w_list->ws_gui_model,
2186 &ws_gui_app->ws_gui_w_list->ws_gui_iter))
2188 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
2189 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
2196 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
2199 g_free(ws_gui_app->last_word);
2200 ws_gui_app->last_word = NULL;
2201 ws_gui_app->last_word = g_strdup (string);
2203 if (ws_gui_app->history_flag == FALSE)
2205 ws_gui_history_add(string, ws_gui_app);