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),
184 case WS_DBUS_INFO_CACHING_FINISHED:
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),
192 gtk_widget_set_sensitive(
193 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
199 case WS_DBUS_ERROR_DICTIONARY_NOT_LOAD:
201 if (ws_gui_app->ws_gui_history_cur_pos >= 0 &&
202 ws_gui_app->ws_gui_history_cur_pos <=HISTORY_LEN)
204 g_array_remove_index(ws_gui_app->ws_gui_history,
205 ws_gui_app->ws_gui_history_cur_pos);
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,
213 _("ws_ni_dictionary_unavailable"));
214 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
216 GTK_DIALOG(ws_gui_app->ws_message_dialog))
219 gtk_widget_destroy(ws_gui_app->ws_message_dialog);
224 case WS_DBUS_BOOKMARKS_ADDED_OK:
226 gtk_infoprint(GTK_WINDOW(
227 ws_gui_app->ws_gui_hildon_window),
228 _("ws_ni_bookmark_added"));
232 case WS_DBUS_BOOKMARKS_REMOVED_OK:
234 gtk_infoprint(GTK_WINDOW(
235 ws_gui_app->ws_gui_hildon_window),
236 _("ws_ni_bookmark_removed"));
240 case WS_DBUS_BOOKMARKS_ADDED_FAIL:
242 gtk_infoprint(GTK_WINDOW(
243 ws_gui_app->ws_gui_hildon_window),
244 _("ws_ni_bookmark_not_added"));
248 case WS_DBUS_BOOKMARKS_REMOVED_FAIL:
250 gtk_infoprint(GTK_WINDOW(
251 ws_gui_app->ws_gui_hildon_window),
252 _("ws_ni_bookmark_not_removed"));
256 case WS_DBUS_LOAD_BOOKMARK_FAILED:
258 gtk_widget_set_sensitive(
259 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
261 ws_gui_app->bookmark_avail = FALSE;
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,
269 _("ws_ni_bookmarks_unavailable"));
272 GTK_DIALOG(ws_gui_app->ws_message_dialog))
276 ws_gui_app->ws_message_dialog);
284 /** this function handles signals from dbus; it is called when progress bar
285 status has been changed
287 * @param error - error message recived from DBUS
288 * @param words - array with recived data structure
289 * @param user_data - pointer to data structure
292 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
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)
300 hildon_banner_set_fraction(
301 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
306 /** this function handles signal from dbus and transfer recived
307 (found in a dictionary) words to the words list
309 * @param error - error message recived from DBUS
310 * @param words - array with recived data structure
311 * @param user_data - pointer to data structure
314 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
316 timer(TIMER_START, (gchar*)__FUNCTION__);
320 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
323 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
326 for (i=0;i<words->len;++i)
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);
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);
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),
341 gtk_widget_set_sensitive(
342 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
344 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
347 ws_gui_app->ws_gui_w_list->ws_gui_model =
348 create_and_fill_model(tmp, ws_gui_app);
350 if (ws_gui_app->history_flag == TRUE)
352 if (gtk_tree_model_get_iter_from_string
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,
358 ws_gui_app->ws_gui_history_cur_pos)) == TRUE);
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));
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);
369 ws_gui_app->history_flag = FALSE;
370 ws_gui_fill_html(format_html(data.value.s, ws_gui_app),
372 ws_gui_app->html_flag = TRUE;
378 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
379 _("ws_ni_no_words_found"));
381 ws_gui_app->history_mode = 0;
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;
390 timer(TIMER_STOP, (gchar*)__FUNCTION__);
393 /** this function handles signal from dbus and send recived data to
396 * @param error - error message recived from DBUS
397 * @param words - array with recived data structure
398 * @param user_data - pointer to data structure
401 void ws_gui_dbus_return_translation (GError *error,
405 //timer(TIMER_START, (gchar*)__FUNCTION__);
406 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
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__);
418 /** this function handles signal from dbus and send recived data to
421 * @param error - error message recived from DBUS
422 * @param words - array with recived data structure
423 * @param user_data - pointer to data structure
426 void ws_dbus_server_return_extracted_dict2(GError *error,
430 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
434 data = g_array_index (words, osso_rpc_t, 0);
435 if (ws_gui_load_dict(data.value.s, ws_gui_app) == TRUE)
437 gtk_infoprint(GTK_WINDOW(
438 ws_gui_app->ws_gui_hildon_window),
439 _("ws_ni_dictionary_added"));
444 * this function allows to free allocated memory
446 * @param user_data - pointer to data structure
448 void ws_gui_free_memory(gpointer user_data)
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);
459 /** this function handle press signals (keyboard)
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.
467 gboolean hildon_key_press_listener (GtkWidget * widget,
468 GdkEventKey * keyevent,
471 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
473 switch ((guint)(keyevent->keyval)) {
474 case HILDON_HARDKEY_UP:
476 gtk_container_set_focus_vadjustment(
477 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
478 gtk_scrolled_window_get_vadjustment(
480 ws_gui_app->ws_gui_scrolledwindow_left)));
481 ws_gui_app->v_new_value =
482 gtk_adjustment_get_value(
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)
488 gtk_adjustment_set_value(
489 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
490 ws_gui_app->v_new_value);
496 case HILDON_HARDKEY_DOWN:
498 gtk_container_set_focus_vadjustment(
499 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
500 gtk_scrolled_window_get_vadjustment(
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;
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))
511 gtk_adjustment_set_value(
512 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
513 ws_gui_app->v_new_value);
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)
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);
525 case HILDON_HARDKEY_LEFT:
527 gtk_container_set_focus_hadjustment(
528 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
529 gtk_scrolled_window_get_hadjustment(
531 ws_gui_app->ws_gui_scrolledwindow_left)));
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;
537 if (ws_gui_app->h_new_value >
538 ws_gui_app->ws_gui_hadj->lower)
540 gtk_adjustment_set_value(
541 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
542 ws_gui_app->h_new_value);
547 case HILDON_HARDKEY_RIGHT:
549 gtk_container_set_focus_hadjustment(
550 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
551 gtk_scrolled_window_get_hadjustment(
553 ws_gui_app->ws_gui_scrolledwindow_left)));
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;
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))
563 gtk_adjustment_set_value(
564 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
565 ws_gui_app->h_new_value);
570 case HILDON_HARDKEY_SELECT:
571 ws_gui_search(NULL, ws_gui_app);
574 case HILDON_HARDKEY_FULLSCREEN:
575 ws_gui_full_screen(NULL, ws_gui_app);
578 case HILDON_HARDKEY_INCREASE:
579 ws_gui_html_zoom_in(NULL, ws_gui_app);
582 case HILDON_HARDKEY_DECREASE:
583 ws_gui_html_zoom_out(NULL, ws_gui_app);
586 case HILDON_HARDKEY_ESC:
587 ws_gui_search_stop(NULL, ws_gui_app);
597 /** this function allow to hide words list using menu item from application menu
599 * @param checkmenuitem - the object which received the signal
600 * @param user_data - user data set when the signal handler was connected
603 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
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)))
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),
614 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
615 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
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),
624 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
625 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
630 /** this function allow to hide words list using toggle button placed in
633 * @param toolbar - the object which received the signal
634 * @param user_data - user data set when the signal handler was connected
637 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
639 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
641 if (gtk_toggle_tool_button_get_active(
642 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
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),
648 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
649 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
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),
658 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
659 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
664 /** add word to the history
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
670 void ws_gui_history_add(char *new_word, gpointer user_data)
672 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
674 if (ws_gui_app->history_mode == 0)
679 gchar *tmp_last_searched;
680 gchar *tmp_iter = NULL;
681 gchar *previous_word = " ";
683 if (ws_gui_app->ws_gui_history_cur_pos > -1 &&
684 g_array_index(ws_gui_app->ws_gui_history,
686 ws_gui_app->ws_gui_history_cur_pos) != NULL)
688 previous_word = NULL;
689 previous_word = g_array_index(
690 ws_gui_app->ws_gui_history,
692 ws_gui_app->ws_gui_history_cur_pos);
695 i = ws_gui_app->ws_gui_history_cur_pos + 1;
696 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
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);
701 if (previous_word != NULL && strcmp(previous_word, new_word) != 0)
705 g_array_remove_index(
706 ws_gui_app->ws_gui_history_list,
708 g_array_remove_index(
709 ws_gui_app->ws_gui_history_iter,
713 g_array_remove_index(
714 ws_gui_app->ws_gui_history,
718 ws_gui_app->ws_gui_history,
724 ws_gui_app->ws_gui_history_cur_pos ++;
727 if (ws_gui_app->bookmark_mode == FALSE)
729 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
733 tmp_last_searched = g_strdup(ws_gui_app->last_searched_in_book);
736 g_array_append_val(ws_gui_app->ws_gui_history_list,
739 tmp_word = g_strdup(new_word);
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);
745 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
747 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
748 g_array_remove_index(ws_gui_app->ws_gui_history_list,
750 g_array_remove_index(ws_gui_app->ws_gui_history_iter,
753 ws_gui_app->ws_gui_history_cur_pos--;
757 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
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);
766 /** display previously choosen word (previous from the history array)
767 if avaible, sets current position in the history array
769 * @param button - button which recived a signal
770 * @param user_data - user data set when the signal handler was connected
773 void ws_gui_history_back(GtkButton *button, gpointer user_data)
775 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
777 ws_gui_app->history_flag = TRUE;
779 if (ws_gui_app->ws_gui_history_cur_pos > 0)
781 ws_gui_app->ws_gui_history_cur_pos =
782 ws_gui_app->ws_gui_history_cur_pos - 1;
784 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
786 (g_array_index(ws_gui_app->ws_gui_history_list,
788 ws_gui_app->ws_gui_history_cur_pos)),
792 ws_dbus_client_find_word (ws_gui_app->dbus_data,
793 g_array_index(ws_gui_app->ws_gui_history_list,
795 ws_gui_app->ws_gui_history_cur_pos)
801 gtk_widget_set_sensitive (
802 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
804 gtk_widget_set_sensitive(
805 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
809 ws_gui_check_history(ws_gui_app);
813 /** display choosen word, next in the history array (if avaible),
814 sets current position in the history array
816 * @param button - button which recived a signal
817 * @param user_data - user data set when the signal handler was connected
820 void ws_gui_history_next(GtkButton *button, gpointer user_data)
822 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
824 ws_gui_app->history_flag = TRUE;
826 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
828 ws_gui_app->ws_gui_history_cur_pos+1);
830 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
833 ws_gui_app->ws_gui_history_cur_pos =
834 ws_gui_app->ws_gui_history_cur_pos + 1;
836 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
838 (g_array_index(ws_gui_app->ws_gui_history_list,
840 ws_gui_app->ws_gui_history_cur_pos)),
843 ws_dbus_client_find_word(ws_gui_app->dbus_data,
844 g_array_index(ws_gui_app->ws_gui_history_list,
846 ws_gui_app->ws_gui_history_cur_pos)
851 gtk_widget_set_sensitive(
852 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
854 gtk_widget_set_sensitive(
855 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
859 ws_gui_check_history(ws_gui_app);
862 /** check current position in the history array and sets sensitivity of buttons
863 / menu items, depends on availablity of words in the history
865 * @param user_data - user data set when the signal handler was connected
868 void ws_gui_check_history(gpointer user_data)
870 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
872 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
874 ws_gui_app->ws_gui_history_cur_pos+1);
876 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
879 gtk_widget_set_sensitive(
880 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
882 gtk_widget_set_sensitive(
883 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
888 gtk_widget_set_sensitive(
889 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
891 gtk_widget_set_sensitive(
892 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
896 tmp = g_array_index(ws_gui_app->ws_gui_history,
898 ws_gui_app->ws_gui_history_cur_pos-1);
899 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
901 gtk_widget_set_sensitive(
902 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
904 gtk_widget_set_sensitive(
905 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
910 gtk_widget_set_sensitive (
911 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
913 gtk_widget_set_sensitive(
914 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
919 /** create TreeView Model, which allows to display words list
921 * @param words_list - array with words(found in a dictionary), recived from
923 * @param user_data - user data set when the signal handler was connected
926 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
928 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
930 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
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);
937 /* Append a row and fill in some data */
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);
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,
948 tmp = g_strdup(g_array_index(words_list, gchar*, i));
951 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
953 if (ws_gui_app->last_word == NULL)
955 ws_gui_app->last_word = g_strdup("\0");
959 ws_gui_app->history_flag == FALSE &&
960 (0 != strcmp(ws_gui_app->last_word, tmp)))
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);
971 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
974 /** create TreeView and TreeModel using create_and_fill_model() function;
975 it is necessary to display found words in a words list;
977 * @param words_list - array with words(found in a dictionary),
979 * @param user_data - user data set when the signal handler was connected
982 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
984 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
986 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
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),
993 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
997 ws_gui_app->ws_gui_w_list->ws_gui_model =
998 create_and_fill_model(words_list, ws_gui_app);
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);
1005 return ws_gui_app->ws_gui_w_list->ws_gui_view;
1008 /** handle signal from words list, get selected word and calls
1009 'find translation' function
1011 * @param selection - the object which received the signal
1012 * @param user_data - user data set when the signal handler was connected
1015 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
1018 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1020 ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
1022 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ":::GUI:: CALLBACK Z SELECTION!!!");
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))
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,
1034 if (ws_gui_app->last_word == NULL)
1036 ws_gui_app->last_word = g_strdup("\0");
1039 if (string != NULL && (0 != strcmp(string, ws_gui_app->last_word)))
1041 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
1044 g_free(ws_gui_app->last_word);
1045 ws_gui_app->last_word = NULL;
1046 ws_gui_app->last_word = g_strdup (string);
1049 if (string != NULL && ws_gui_app->history_flag == FALSE)
1051 ws_gui_history_add(string, ws_gui_app);
1057 /** switch application between fun screen and normal mode
1059 * @param menuitem - object which recived the signal
1060 * @param user_data - user data set when the signal handler was connected
1063 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
1066 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1067 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
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),
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"));
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),
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"));
1091 /** search for selected text in a dictionary
1093 * @param menuitem - object which recived the signal
1094 * @param user_data - user data set when the signal handler was connected
1097 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1099 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
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);
1108 if (temp != NULL || strcmp(temp, " "))
1110 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1114 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1118 hildon_banner_show_information(
1119 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1121 _("ws_ni_no_text_selected"));
1125 /** select whole text in the translation (html) area
1127 * @param menuitem - object which recived the signal
1128 * @param user_data - user data set when the signal handler was connected
1131 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
1133 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1134 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1137 /** copy selected text to the clipoard from context popup menu
1139 * @param menuitem - object which recived the signal
1140 * @param user_data - user data set when the signal handler was connected
1143 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
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),
1151 /** paste copied text into toolbar entry
1153 * @param menuitem - object which recived the signal
1154 * @param user_data - user data set when the signal handler was connected
1157 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1159 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
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),
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),
1174 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1178 /** zoom in text in translation (html) area
1180 * @param menuitem - object which recived the signal
1181 * @param user_data - user data set when the signal handler was connected
1184 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
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)
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"));
1197 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1200 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1202 gtk_infoprint(GTK_WINDOW(
1203 ws_gui_app->ws_gui_hildon_window),
1204 _("ws_ib_zoom_default"));
1208 gtk_infoprint(GTK_WINDOW(
1209 ws_gui_app->ws_gui_hildon_window),
1210 _("ws_ib_zoom_in"));
1215 /** zoom out text in translation (html) area
1217 * @param menuitem - object which recived the signal
1218 * @param user_data - user data set when the signal handler was connected
1221 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
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)
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"));
1234 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1237 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1239 gtk_infoprint(GTK_WINDOW(
1240 ws_gui_app->ws_gui_hildon_window),
1241 _("ws_ib_zoom_default"));
1245 gtk_infoprint(GTK_WINDOW(
1246 ws_gui_app->ws_gui_hildon_window),
1247 _("ws_ib_zoom_out"));
1252 /** start searching, send typed word to DBUS and query for words
1254 * @param widget - object which recived the signal
1255 * @param user_data - user data set when the signal handler was connected
1258 void ws_gui_search(GtkWidget * widget, gpointer user_data)
1260 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1262 if (ws_gui_app->ws_gui_banner_flag == FALSE)
1264 gchar* ws_gui_text = NULL;
1265 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1270 if (ws_gui_app->bookmark_mode == FALSE)
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);
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);
1283 g_strstrip(ws_gui_text);
1284 if (strlen(ws_gui_text) != 0)
1286 gtk_widget_show(ws_gui_app->ws_gui_banner);
1288 gtk_widget_set_sensitive(
1289 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1291 gtk_widget_set_sensitive(
1292 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
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);
1304 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1305 _("ws_ni_no_word_typed"));
1307 g_free(ws_gui_app->last_word);
1308 ws_gui_app->last_word=NULL;
1312 /** stop search process
1314 * @param button - object which recived the signal
1315 * @param user_data - user data set when the signal handler was connected
1318 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
1320 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1321 if (ws_gui_app->ws_gui_banner_flag == TRUE)
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);
1327 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1328 _("ws_ni_search_aborted"));
1332 /** this function is called just before closing application;
1333 it sends signal to DBUS and destroys it;
1335 * @param widget - object which recived the signal
1337 * @param user_data - user data set when the signal handler was connected
1340 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
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);
1353 /** this function is called just before closing application,
1354 from application menu; it sends signal to DBUS and destroys it;
1356 * @param menuitem - object which recived the signal
1357 * @param user_data - user data set when the signal handler was connected
1360 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
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);
1373 /** fill translation area with text (html) recived from DBUS
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
1379 void ws_gui_fill_html(char *html_context, gpointer user_data)
1381 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1382 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1384 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1389 /** read adjustment of left scrollwindow, which is necessary to navigate with
1390 arrow keys inside words list
1392 * @param user_data - user data set when the signal handler was connected
1395 void ws_gui_read_adjustment(gpointer user_data)
1397 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
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));
1404 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1405 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1407 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1408 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
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;
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)));
1423 /** allows to display image in html area
1425 * @param html - object which received a signal
1426 * @param url - url to the image
1427 * @param stream - html stream
1430 void ws_gui_url_requested (
1433 GtkHTMLStream *stream)
1437 if (url && !strncmp (url, "file:", 5)) {
1439 fd = open (url, O_RDONLY);
1443 buf = alloca (8192);
1444 while ((size = read (fd, buf, 8192)) > 0) {
1445 gtk_html_stream_write (stream, buf, size);
1447 gtk_html_stream_close(stream, size == -1
1448 ? GTK_HTML_STREAM_ERROR
1449 : GTK_HTML_STREAM_OK);
1456 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1459 /** handles button press event and examines what kind of event was it
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
1468 gboolean ws_gui_button_press(GtkWidget *widget,
1469 GdkEventButton *event,
1472 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1473 if (ws_gui_app->ws_gui_sel_flag == FALSE)
1475 if (event->type == GDK_2BUTTON_PRESS)
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);
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),
1494 ws_gui_app->ws_gui_sel_flag = FALSE;
1500 /** handles button release event and examines whether 'click' or 'tap and hold'
1501 event it supposed to be
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
1509 gboolean ws_gui_button_release (GtkWidget *widget,
1510 GdkEventButton *event,
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)
1519 ws_gui_app->ws_gui_double_click = FALSE;
1522 else if (tmp < PRESS_TIME)
1524 struct _GtkHTML *tmp = (struct _GtkHTML *)
1525 (ws_gui_app->ws_gui_html);
1526 html_engine_unselect_all(tmp->engine);
1532 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1534 * @param user_data - user data set when the signal handler was connected
1537 guint ws_gui_show_popup (gpointer user_data)
1539 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1540 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1541 if (tmp > PRESS_TIME)
1543 ws_gui_create_popup_menu(ws_gui_app);
1545 return (guint)(FALSE);
1549 /** checks clipboard content and sets sensitivity of widgets
1551 * @param widget - object which recived a signal
1552 * @param user_data - user data set when the signal handler was connected
1555 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
1557 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1558 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1560 gtk_widget_set_sensitive(
1561 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1566 gtk_widget_set_sensitive(
1567 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1571 struct _GtkHTML *tmp = (struct _GtkHTML *)(ws_gui_app->ws_gui_html);
1573 if (html_engine_is_selection_active(tmp->engine) == TRUE)
1575 gtk_widget_set_sensitive(GTK_WIDGET
1576 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1581 gtk_widget_set_sensitive(GTK_WIDGET
1582 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1586 if (ws_gui_app->html_flag == FALSE)
1588 gtk_widget_set_sensitive(GTK_WIDGET
1589 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1594 gtk_widget_set_sensitive(GTK_WIDGET
1595 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1601 /** gets received string (with translation), formats it and sends it to be
1604 * @param received_string - content received from Manager
1605 * @param user_data - user data set when the function has been called
1608 gchar * format_html (gchar * received_string, gpointer user_data)
1610 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1613 str_final = g_string_new(received_string);
1614 str_tmp = g_string_new(received_string);
1618 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
1622 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1624 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1625 str_final = g_string_erase(str_final,
1626 (long)(tmp - str_final->str),
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\">");
1636 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1637 if (ws_gui_app->last_word != NULL)
1639 str_tmp = g_string_erase(str_tmp,
1640 (long)(tmp2 - str_tmp->str),
1641 14 + strlen(ws_gui_app->last_word));
1645 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1647 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1648 str_final = g_string_erase(str_final,
1649 (long)(tmp - str_final->str),
1651 str_final = g_string_insert(str_final,
1652 (long)(tmp - str_final->str),
1653 "</font></th></tr></table>");
1655 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1656 str_tmp = g_string_erase(str_tmp,
1657 (long)(tmp2 - str_tmp->str),
1661 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1663 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1664 str_final = g_string_erase (str_final,
1665 (long)(tmp - str_final->str),
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\">");
1672 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1673 str_tmp = g_string_erase(str_tmp,
1674 (long)(tmp2 - str_tmp->str),
1678 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1680 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1681 str_final = g_string_erase(str_final,
1682 (long)(tmp - str_final->str),
1684 str_final = g_string_insert(str_final,
1685 (long)(tmp - str_final->str),
1686 "</td></tr></table></center>");
1688 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1689 str_tmp = g_string_erase(str_tmp,
1690 (long)(tmp2 - str_tmp->str),
1694 str_final = g_string_append(str_final,
1695 "</td></tr></table></body></html>");
1697 ws_gui_app->raw_translation = g_string_insert(
1698 ws_gui_app->raw_translation,
1702 return str_final->str;
1705 /** open bookmarks database
1707 * @param menuitem - object which recived the signal
1708 * @param user_data - user data set when the signal handler was connected
1711 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1713 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1715 ws_gui_read_active_dictionaries(ws_gui_app);
1717 g_free(ws_gui_app->last_word);
1718 ws_gui_app->last_word = NULL;
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),
1726 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1728 if(ws_gui_app->ws_gui_history->len >= 0)
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;
1735 ws_gui_check_history(ws_gui_app);
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);
1744 /** closes bookmarks database
1746 * @param menuitem - object which recived the signal
1747 * @param user_data - user data set when the signal handler was connected
1750 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1752 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1754 ws_gui_read_active_dictionaries(ws_gui_app);
1756 g_free(ws_gui_app->last_word);
1757 ws_gui_app->last_word = NULL;
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);
1763 if(ws_gui_app->ws_gui_history->len >= 0)
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;
1770 ws_gui_check_history(ws_gui_app);
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)
1777 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1779 ws_gui_app->last_searched,
1781 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1782 ws_gui_search(NULL, ws_gui_app);
1786 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
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);
1796 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1797 ws_gui_search(NULL, ws_gui_app);
1801 /** adds bookmark to bookmarks database
1803 * @param menuitem - object which recived the signal
1804 * @param user_data - user data set when the signal handler was connected
1807 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1809 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1811 if (ws_gui_app->last_word != NULL)
1813 ws_gui_add_bookmark_dialog(ws_gui_app);
1818 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1819 _("ws_ni_select_word_to_add"));
1823 /** removes bookmark from bookmarks database
1825 * @param menuitem - object which recived the signal
1826 * @param user_data - user data set when the signal handler was connected
1829 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
1832 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1834 if (ws_gui_app->last_word != NULL)
1836 ws_gui_remove_bookmark_dialog(ws_gui_app);
1839 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1843 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1849 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1850 _("ws_ni_select_word_to_remove"));
1856 /** checks wheather dictionaries are available or not; according to the result
1857 * dimmes proper menuitem
1859 * @param menuitem - object which recived the signal
1860 * @param user_data - user data set when the signal handler was connected
1863 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1865 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1866 if (gconf_client_dir_exists(ws_gui_app->client,
1867 GCONF_PATH, NULL) == TRUE)
1869 ws_gui_app->directories = gconf_client_all_dirs(
1876 if(g_slist_length(ws_gui_app->directories) != 0)
1878 gtk_widget_set_sensitive(GTK_WIDGET
1879 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1881 gtk_widget_set_sensitive(GTK_WIDGET
1882 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1884 gtk_widget_set_sensitive(GTK_WIDGET
1885 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1892 gtk_widget_set_sensitive(GTK_WIDGET
1893 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1895 gtk_widget_set_sensitive(GTK_WIDGET
1896 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1898 gtk_widget_set_sensitive(GTK_WIDGET
1899 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1905 /** sets sensitivity of menu items due to bookmark's mode
1907 * @param user_data - user data set when the function was called
1910 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1912 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1917 if (ws_gui_app->bookmark_mode == TRUE)
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();
1925 ws_gui_app->directories = gconf_client_all_dirs(
1929 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
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);
1935 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
1937 ws_gui_app->directories_last =
1938 g_slist_append(ws_gui_app->directories_last,
1942 if (strcmp(name, "bookmarks") == 0)
1944 gconf_client_set_bool(ws_gui_app->client,
1951 gconf_client_set_bool(ws_gui_app->client,
1958 //setting sensitivity of components
1959 gtk_widget_set_sensitive(
1960 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1962 gtk_widget_set_sensitive(
1963 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1965 gtk_widget_set_sensitive(
1966 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1968 gtk_widget_set_sensitive(
1969 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1971 gtk_widget_set_sensitive(
1972 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1977 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1978 if (g_slist_length(ws_gui_app->directories_last) > 0)
1980 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1983 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1985 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
1988 //string = g_strconcat(string, "/active", NULL);
1991 gconf_client_set_bool(ws_gui_app->client,
1998 //setting sensitivity of components
1999 gtk_widget_set_sensitive(
2000 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
2002 gtk_widget_set_sensitive(
2003 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
2005 gtk_widget_set_sensitive(
2006 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2008 gtk_widget_set_sensitive(
2009 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2011 gtk_widget_set_sensitive(
2012 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
2017 /** sets sensitivity of menu items due to user selection made
2019 * @param user_data - user data set when the function was called
2022 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
2024 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2025 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
2027 gtk_widget_set_sensitive(
2028 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2033 gtk_widget_set_sensitive(
2034 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
2038 if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
2040 gtk_widget_set_sensitive(
2041 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2046 gtk_widget_set_sensitive(
2047 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2051 /** reads gconf entries and sets variables with a proper data; it is necessary
2052 * for changing the bookmarks mode
2054 * @param user_data - user data set when the function was called
2057 void ws_gui_read_active_dictionaries(gpointer user_data)
2059 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2062 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
2067 void ws_gui_clear_array(GArray *history)
2069 if(history->len >= 0)
2071 history = g_array_remove_range(history, 0, history->len);