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);
346 ws_gui_app->ws_gui_w_list->ws_gui_model =
347 create_and_fill_model(tmp, ws_gui_app);
349 if (ws_gui_app->history_flag == TRUE)
351 if (gtk_tree_model_get_iter_from_string
353 ws_gui_app->ws_gui_w_list->ws_gui_model),
354 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
355 g_array_index(ws_gui_app->ws_gui_history_iter,
357 ws_gui_app->ws_gui_history_cur_pos)) == TRUE);
360 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n\nString from iter: %s", gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(
361 ws_gui_app->ws_gui_w_list->ws_gui_model), &ws_gui_app->ws_gui_w_list->ws_gui_iter));
362 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "GUI-TrePath: %s\n\n", gtk_tree_path_to_string(ws_gui_app->ws_gui_w_list->path));
364 gtk_tree_selection_select_iter(
365 ws_gui_app->ws_gui_w_list->ws_gui_selection,
366 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
368 ws_gui_app->history_flag = FALSE;
369 ws_gui_fill_html(format_html(data.value.s, ws_gui_app),
371 ws_gui_app->html_flag = TRUE;
377 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
378 _("ws_ni_no_words_found"));
380 ws_gui_app->history_mode = 0;
382 ws_gui_fill_html(" ", ws_gui_app);
383 ws_gui_app->html_flag = FALSE;
384 g_free(ws_gui_app->last_word);
385 ws_gui_app->last_word = NULL;
389 timer(TIMER_STOP, (gchar*)__FUNCTION__);
392 /** this function handles signal from dbus and send recived data to
395 * @param error - error message recived from DBUS
396 * @param words - array with recived data structure
397 * @param user_data - pointer to data structure
400 void ws_gui_dbus_return_translation (GError *error,
404 //timer(TIMER_START, (gchar*)__FUNCTION__);
405 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
409 data = g_array_index (words, osso_rpc_t, 0);
410 //gtk_html_zoom_reset(GTK_HTML(ws_gui_app->ws_gui_html));
411 ws_gui_fill_html(format_html(data.value.s, ws_gui_app), ws_gui_app);
412 ws_gui_app->html_flag = TRUE;
413 //timer(TIMER_STOP, (gchar*)__FUNCTION__);
418 * this function allows to free allocated memory
420 * @param user_data - pointer to data structure
422 void ws_gui_free_memory(gpointer user_data)
424 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
425 g_array_free(ws_gui_app->ws_gui_history, TRUE);
426 pango_font_description_free(ws_gui_app->p);
427 g_free(ws_gui_app->last_word);
428 g_free(ws_gui_app->ws_gui_w_list);
429 g_free(ws_gui_app->ws_gui_menu);
433 /** this function handle press signals (keyboard)
437 * @param user_data - ponter to data structure
438 * @return TRUE to stop other handlers from being invoked for the event.
439 FALSE to propagate the event further.
441 gboolean hildon_key_press_listener (GtkWidget * widget,
442 GdkEventKey * keyevent,
445 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
447 switch ((guint)(keyevent->keyval)) {
448 case HILDON_HARDKEY_UP:
450 gtk_container_set_focus_vadjustment(
451 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
452 gtk_scrolled_window_get_vadjustment(
454 ws_gui_app->ws_gui_scrolledwindow_left)));
455 ws_gui_app->v_new_value =
456 gtk_adjustment_get_value(
458 ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
459 if (ws_gui_app->v_new_value >
460 ws_gui_app->ws_gui_vadj->lower)
462 gtk_adjustment_set_value(
463 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
464 ws_gui_app->v_new_value);
470 case HILDON_HARDKEY_DOWN:
472 gtk_container_set_focus_vadjustment(
473 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
474 gtk_scrolled_window_get_vadjustment(
476 ws_gui_app->ws_gui_scrolledwindow_left)));
477 ws_gui_app->v_new_value = gtk_adjustment_get_value(
478 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj))
479 + ws_gui_app->v_delta;
481 if (ws_gui_app->v_new_value <
482 (ws_gui_app->ws_gui_vadj->upper -
483 ws_gui_app->ws_gui_vadj->page_size))
485 gtk_adjustment_set_value(
486 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
487 ws_gui_app->v_new_value);
489 /*if (gtk_tree_model_iter_next(
490 ws_gui_app->ws_gui_w_list->ws_gui_model, &ws_gui_app->ws_gui_w_list->ws_gui_iter) == TRUE)
492 gtk_tree_selection_select_iter(
493 ws_gui_app->ws_gui_w_list->ws_gui_selection,
494 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
499 case HILDON_HARDKEY_LEFT:
501 gtk_container_set_focus_hadjustment(
502 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
503 gtk_scrolled_window_get_hadjustment(
505 ws_gui_app->ws_gui_scrolledwindow_left)));
507 ws_gui_app->h_new_value = gtk_adjustment_get_value(
508 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
509 - ws_gui_app->h_delta;
511 if (ws_gui_app->h_new_value >
512 ws_gui_app->ws_gui_hadj->lower)
514 gtk_adjustment_set_value(
515 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
516 ws_gui_app->h_new_value);
521 case HILDON_HARDKEY_RIGHT:
523 gtk_container_set_focus_hadjustment(
524 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
525 gtk_scrolled_window_get_hadjustment(
527 ws_gui_app->ws_gui_scrolledwindow_left)));
529 ws_gui_app->h_new_value = gtk_adjustment_get_value(
530 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
531 + ws_gui_app->h_delta;
533 if (ws_gui_app->h_new_value <
534 (ws_gui_app->ws_gui_hadj->upper -
535 ws_gui_app->ws_gui_hadj->page_size))
537 gtk_adjustment_set_value(
538 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
539 ws_gui_app->h_new_value);
544 case HILDON_HARDKEY_SELECT:
545 ws_gui_search(NULL, ws_gui_app);
548 case HILDON_HARDKEY_FULLSCREEN:
549 ws_gui_full_screen(NULL, ws_gui_app);
552 case HILDON_HARDKEY_INCREASE:
553 ws_gui_html_zoom_in(NULL, ws_gui_app);
556 case HILDON_HARDKEY_DECREASE:
557 ws_gui_html_zoom_out(NULL, ws_gui_app);
560 case HILDON_HARDKEY_ESC:
561 ws_gui_search_stop(NULL, ws_gui_app);
571 /** this function allow to hide words list using menu item from application menu
573 * @param checkmenuitem - the object which received the signal
574 * @param user_data - user data set when the signal handler was connected
577 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
580 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
581 if (gtk_check_menu_item_get_active(
582 GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
584 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
585 gtk_toggle_tool_button_set_active(
586 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide),
588 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
589 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
594 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
595 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
596 ws_gui_app->ws_gui_toobar_button_hide),
598 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
599 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
604 /** this function allow to hide words list using toggle button placed in
607 * @param toolbar - the object which received the signal
608 * @param user_data - user data set when the signal handler was connected
611 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
613 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
615 if (gtk_toggle_tool_button_get_active(
616 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
618 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
619 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
620 ws_gui_app->ws_gui_toobar_button_hide),
622 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
623 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
628 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
629 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
630 ws_gui_app->ws_gui_toobar_button_hide),
632 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
633 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
638 /** add word to the history
640 * @param new_word - word which is going to be append to the history array
641 * @param user_data - user data set when the signal handler was connected
644 void ws_gui_history_add(char *new_word, gpointer user_data)
646 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
648 if (ws_gui_app->history_mode == 0)
653 gchar *tmp_last_searched;
654 gchar *tmp_iter = NULL;
655 gchar *previous_word = " ";
657 if (ws_gui_app->ws_gui_history_cur_pos > -1 &&
658 g_array_index(ws_gui_app->ws_gui_history,
660 ws_gui_app->ws_gui_history_cur_pos) != NULL)
662 previous_word = NULL;
663 previous_word = g_array_index(
664 ws_gui_app->ws_gui_history,
666 ws_gui_app->ws_gui_history_cur_pos);
669 i = ws_gui_app->ws_gui_history_cur_pos + 1;
670 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
673 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);
675 if (previous_word != NULL && strcmp(previous_word, new_word) != 0)
679 g_array_remove_index(
680 ws_gui_app->ws_gui_history_list,
682 g_array_remove_index(
683 ws_gui_app->ws_gui_history_iter,
687 g_array_remove_index(
688 ws_gui_app->ws_gui_history,
692 ws_gui_app->ws_gui_history,
698 ws_gui_app->ws_gui_history_cur_pos ++;
701 if (ws_gui_app->bookmark_mode == FALSE)
703 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
707 tmp_last_searched = g_strdup(ws_gui_app->last_searched_in_book);
710 g_array_append_val(ws_gui_app->ws_gui_history_list,
713 tmp_word = g_strdup(new_word);
715 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
716 g_array_append_val(ws_gui_app->ws_gui_history_iter, tmp_iter);
719 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
721 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
722 g_array_remove_index(ws_gui_app->ws_gui_history_list,
724 g_array_remove_index(ws_gui_app->ws_gui_history_iter,
727 ws_gui_app->ws_gui_history_cur_pos--;
731 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
736 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);
737 ws_gui_check_history(ws_gui_app);
740 /** display previously choosen word (previous from the history array)
741 if avaible, sets current position in the history array
743 * @param button - button which recived a signal
744 * @param user_data - user data set when the signal handler was connected
747 void ws_gui_history_back(GtkButton *button, gpointer user_data)
749 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
751 ws_gui_app->history_flag = TRUE;
753 if (ws_gui_app->ws_gui_history_cur_pos > 0)
755 ws_gui_app->ws_gui_history_cur_pos =
756 ws_gui_app->ws_gui_history_cur_pos - 1;
758 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
760 (g_array_index(ws_gui_app->ws_gui_history_list,
762 ws_gui_app->ws_gui_history_cur_pos)),
766 ws_dbus_client_find_word (ws_gui_app->dbus_data,
767 g_array_index(ws_gui_app->ws_gui_history_list,
769 ws_gui_app->ws_gui_history_cur_pos)
775 gtk_widget_set_sensitive (
776 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
778 gtk_widget_set_sensitive(
779 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
783 ws_gui_check_history(ws_gui_app);
787 /** display choosen word, next in the history array (if avaible),
788 sets current position in the history array
790 * @param button - button which recived a signal
791 * @param user_data - user data set when the signal handler was connected
794 void ws_gui_history_next(GtkButton *button, gpointer user_data)
796 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
798 ws_gui_app->history_flag = TRUE;
800 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
802 ws_gui_app->ws_gui_history_cur_pos+1);
804 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
807 ws_gui_app->ws_gui_history_cur_pos =
808 ws_gui_app->ws_gui_history_cur_pos + 1;
810 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
812 (g_array_index(ws_gui_app->ws_gui_history_list,
814 ws_gui_app->ws_gui_history_cur_pos)),
817 ws_dbus_client_find_word(ws_gui_app->dbus_data,
818 g_array_index(ws_gui_app->ws_gui_history_list,
820 ws_gui_app->ws_gui_history_cur_pos)
825 gtk_widget_set_sensitive(
826 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
828 gtk_widget_set_sensitive(
829 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
833 ws_gui_check_history(ws_gui_app);
836 /** check current position in the history array and sets sensitivity of buttons
837 / menu items, depends on availablity of words in the history
839 * @param user_data - user data set when the signal handler was connected
842 void ws_gui_check_history(gpointer user_data)
844 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
846 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
848 ws_gui_app->ws_gui_history_cur_pos+1);
850 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
853 gtk_widget_set_sensitive(
854 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
856 gtk_widget_set_sensitive(
857 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
862 gtk_widget_set_sensitive(
863 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
865 gtk_widget_set_sensitive(
866 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
870 tmp = g_array_index(ws_gui_app->ws_gui_history,
872 ws_gui_app->ws_gui_history_cur_pos-1);
873 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
875 gtk_widget_set_sensitive(
876 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
878 gtk_widget_set_sensitive(
879 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
884 gtk_widget_set_sensitive (
885 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
887 gtk_widget_set_sensitive(
888 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
893 /** create TreeView Model, which allows to display words list
895 * @param words_list - array with words(found in a dictionary), recived from
897 * @param user_data - user data set when the signal handler was connected
900 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
902 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
904 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
907 valid = gtk_tree_model_get_iter_first(
908 GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
909 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
911 /* Append a row and fill in some data */
914 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
915 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
917 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
918 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
922 tmp = g_strdup(g_array_index(words_list, gchar*, i));
925 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
927 if (tmp != NULL && ws_gui_app->history_flag == FALSE)
929 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
930 ws_gui_history_add(tmp, ws_gui_app);
931 g_free(ws_gui_app->last_word);
932 ws_gui_app->last_word = NULL;
933 ws_gui_app->last_word = g_strdup (tmp);
936 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
939 /** create TreeView and TreeModel using create_and_fill_model() function;
940 it is necessary to display found words in a words list;
942 * @param words_list - array with words(found in a dictionary),
944 * @param user_data - user data set when the signal handler was connected
947 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
949 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
951 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
953 ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
954 gtk_tree_view_insert_column_with_attributes(
955 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
958 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
962 ws_gui_app->ws_gui_w_list->ws_gui_model =
963 create_and_fill_model(words_list, ws_gui_app);
965 gtk_tree_view_set_model(
966 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
967 ws_gui_app->ws_gui_w_list->ws_gui_model);
968 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
970 return ws_gui_app->ws_gui_w_list->ws_gui_view;
973 /** handle signal from words list, get selected word and calls
974 'find translation' function
976 * @param selection - the object which received the signal
977 * @param user_data - user data set when the signal handler was connected
980 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
983 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
985 ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
987 if (gtk_tree_selection_get_selected(selection,
988 &ws_gui_app->ws_gui_w_list->ws_gui_model,
989 &ws_gui_app->ws_gui_w_list->ws_gui_iter))
991 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
992 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
997 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
999 g_free(ws_gui_app->last_word);
1000 ws_gui_app->last_word = NULL;
1001 ws_gui_app->last_word = g_strdup (string);
1004 if (string != NULL && ws_gui_app->history_flag == FALSE)
1006 ws_gui_history_add(string, ws_gui_app);
1012 /** switch application between fun screen and normal mode
1014 * @param menuitem - object which recived the signal
1015 * @param user_data - user data set when the signal handler was connected
1018 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
1021 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1022 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
1024 gtk_window_fullscreen(
1025 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1026 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1027 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1029 ws_gui_app->ws_gui_full_screen_flag = TRUE;
1030 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1031 _("ws_ib_fullscreen_on"));
1035 gtk_window_unfullscreen(
1036 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1037 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1038 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1040 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1041 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1042 _("ws_ib_fullscreen_off"));
1046 /** search for selected text in a dictionary
1048 * @param menuitem - object which recived the signal
1049 * @param user_data - user data set when the signal handler was connected
1052 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1054 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1056 ws_gui_app->ws_gui_clipboard_primary =
1057 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1058 GDK_SELECTION_PRIMARY);
1059 temp = gtk_clipboard_wait_for_text(
1060 ws_gui_app->ws_gui_clipboard_primary);
1063 if (temp != NULL || strcmp(temp, " "))
1065 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1069 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1073 hildon_banner_show_information(
1074 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1076 _("ws_ni_no_text_selected"));
1080 /** select whole text in the translation (html) area
1082 * @param menuitem - object which recived the signal
1083 * @param user_data - user data set when the signal handler was connected
1086 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
1088 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1089 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1092 /** copy selected text to the clipoard from context popup menu
1094 * @param menuitem - object which recived the signal
1095 * @param user_data - user data set when the signal handler was connected
1098 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
1100 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1101 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1102 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1106 /** paste copied text into toolbar entry
1108 * @param menuitem - object which recived the signal
1109 * @param user_data - user data set when the signal handler was connected
1112 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1114 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1118 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1119 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1123 temp = g_strconcat(temp2, temp, NULL);
1124 temp = g_strdelimit(temp, "\n", ' ');
1125 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1129 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1133 /** zoom in text in translation (html) area
1135 * @param menuitem - object which recived the signal
1136 * @param user_data - user data set when the signal handler was connected
1139 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1141 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1142 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1143 if (ws_gui_app->zoom > ZOOM_MAX)
1145 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1146 gtk_infoprint(GTK_WINDOW(
1147 ws_gui_app->ws_gui_hildon_window),
1148 _("ws_ib_max_zoom"));
1152 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1155 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1157 gtk_infoprint(GTK_WINDOW(
1158 ws_gui_app->ws_gui_hildon_window),
1159 _("ws_ib_zoom_default"));
1163 gtk_infoprint(GTK_WINDOW(
1164 ws_gui_app->ws_gui_hildon_window),
1165 _("ws_ib_zoom_in"));
1170 /** zoom out text in translation (html) area
1172 * @param menuitem - object which recived the signal
1173 * @param user_data - user data set when the signal handler was connected
1176 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1178 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1179 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1180 if (ws_gui_app->zoom < ZOOM_MIN)
1182 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1183 gtk_infoprint(GTK_WINDOW(
1184 ws_gui_app->ws_gui_hildon_window),
1185 _("ws_ib_min_zoom"));
1189 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1192 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
1194 gtk_infoprint(GTK_WINDOW(
1195 ws_gui_app->ws_gui_hildon_window),
1196 _("ws_ib_zoom_default"));
1200 gtk_infoprint(GTK_WINDOW(
1201 ws_gui_app->ws_gui_hildon_window),
1202 _("ws_ib_zoom_out"));
1207 /** start searching, send typed word to DBUS and query for words
1209 * @param widget - object which recived the signal
1210 * @param user_data - user data set when the signal handler was connected
1213 void ws_gui_search(GtkWidget * widget, gpointer user_data)
1215 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1217 if (ws_gui_app->ws_gui_banner_flag == FALSE)
1219 gchar* ws_gui_text = NULL;
1220 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1225 if (ws_gui_app->bookmark_mode == FALSE)
1227 g_free(ws_gui_app->last_searched);
1228 ws_gui_app->last_searched = NULL;
1229 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1233 g_free(ws_gui_app->last_searched_in_book);
1234 ws_gui_app->last_searched_in_book = NULL;
1235 ws_gui_app->last_searched_in_book = g_strdup(ws_gui_text);
1238 g_strstrip(ws_gui_text);
1239 if (strlen(ws_gui_text) != 0)
1241 gtk_widget_show(ws_gui_app->ws_gui_banner);
1243 gtk_widget_set_sensitive(
1244 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1246 gtk_widget_set_sensitive(
1247 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1250 ws_gui_app->ws_gui_banner_flag = TRUE;
1251 ws_gui_fill_html(" ", ws_gui_app);
1252 ws_gui_app->html_flag = FALSE;
1253 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1259 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1260 _("ws_ni_no_word_typed"));
1262 g_free(ws_gui_app->last_word);
1263 ws_gui_app->last_word=NULL;
1267 /** stop search process
1269 * @param button - object which recived the signal
1270 * @param user_data - user data set when the signal handler was connected
1273 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
1275 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1276 if (ws_gui_app->ws_gui_banner_flag == TRUE)
1278 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1279 ws_gui_app->ws_gui_banner_flag = FALSE;
1280 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1282 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1283 _("ws_ni_search_aborted"));
1287 /** this function is called just before closing application;
1288 it sends signal to DBUS and destroys it;
1290 * @param widget - object which recived the signal
1292 * @param user_data - user data set when the signal handler was connected
1295 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
1297 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1298 ws_gui_app->bookmark_mode = FALSE;
1299 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1300 g_timer_destroy(ws_gui_app->timer);
1301 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1302 ws_dbus_destroy (ws_gui_app->dbus_data);
1303 ws_gui_free_memory(ws_gui_app);
1308 /** this function is called just before closing application,
1309 from application menu; it sends signal to DBUS and destroys it;
1311 * @param menuitem - object which recived the signal
1312 * @param user_data - user data set when the signal handler was connected
1315 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1317 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1318 ws_gui_app->bookmark_mode = FALSE;
1319 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1320 g_timer_destroy(ws_gui_app->timer);
1321 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1322 ws_dbus_destroy (ws_gui_app->dbus_data);
1323 ws_gui_free_memory(ws_gui_app);
1328 /** fill translation area with text (html) recived from DBUS
1330 * @param html_context - text which is going to be displayed; it should be html
1331 * @param user_data - user data set when the function was called
1334 void ws_gui_fill_html(char *html_context, gpointer user_data)
1336 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1337 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1339 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1344 /** read adjustment of left scrollwindow, which is necessary to navigate with
1345 arrow keys inside words list
1347 * @param user_data - user data set when the signal handler was connected
1350 void ws_gui_read_adjustment(gpointer user_data)
1352 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1354 ws_gui_app->ws_gui_hadj =
1355 gtk_scrolled_window_get_hadjustment(
1356 GTK_SCROLLED_WINDOW(
1357 ws_gui_app->ws_gui_scrolledwindow_left));
1359 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1360 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1362 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1363 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1365 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1366 ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1367 ws_gui_app->v_new_value =
1368 gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1369 ws_gui_app->v_delta;
1371 gtk_container_set_focus_vadjustment(
1372 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
1373 gtk_scrolled_window_get_vadjustment(
1374 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1378 /** allows to display image in html area
1380 * @param html - object which received a signal
1381 * @param url - url to the image
1382 * @param stream - html stream
1385 void ws_gui_url_requested (
1388 GtkHTMLStream *stream)
1392 if (url && !strncmp (url, "file:", 5)) {
1394 fd = open (url, O_RDONLY);
1398 buf = alloca (8192);
1399 while ((size = read (fd, buf, 8192)) > 0) {
1400 gtk_html_stream_write (stream, buf, size);
1402 gtk_html_stream_close(stream, size == -1
1403 ? GTK_HTML_STREAM_ERROR
1404 : GTK_HTML_STREAM_OK);
1411 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1414 /** handles button press event and examines what kind of event was it
1417 * @param widget - object which received a signal
1418 * @param event - type of event which has been performed
1419 * @param user_data - user data set when the signal handler was connected
1420 * @return TRUE to stop other handlers from being invoked for the event.
1421 FALSE to propagate the event further
1423 gboolean ws_gui_button_press(GtkWidget *widget,
1424 GdkEventButton *event,
1427 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1428 if (ws_gui_app->ws_gui_sel_flag == FALSE)
1430 if (event->type == GDK_2BUTTON_PRESS)
1432 ws_gui_app->ws_gui_double_click = TRUE;
1433 g_timer_stop(ws_gui_app->timer);
1434 g_timer_reset(ws_gui_app->timer);
1438 g_signal_stop_emission_by_name(G_OBJECT(
1439 ws_gui_app->ws_gui_html),
1440 "button-press-event");
1441 g_timer_start(ws_gui_app->timer);
1442 gtk_timeout_add((guint)(PRESS_TIME*1000),
1443 (GtkFunction)(ws_gui_show_popup),
1449 ws_gui_app->ws_gui_sel_flag = FALSE;
1455 /** handles button release event and examines whether 'click' or 'tap and hold'
1456 event it supposed to be
1458 * @param widget - object which received a signal
1459 * @param event - type of event which has been performed
1460 * @param user_data - user data set when the signal handler was connected
1461 * @return TRUE to stop other handlers from being invoked for the event.
1462 FALSE to propagate the event further
1464 gboolean ws_gui_button_release (GtkWidget *widget,
1465 GdkEventButton *event,
1468 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1469 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1470 g_timer_stop(ws_gui_app->timer);
1471 g_timer_reset(ws_gui_app->timer);
1472 if (ws_gui_app->ws_gui_double_click == TRUE)
1474 ws_gui_app->ws_gui_double_click = FALSE;
1477 else if (tmp < PRESS_TIME)
1479 struct _GtkHTML *tmp = (struct _GtkHTML *)
1480 (ws_gui_app->ws_gui_html);
1481 html_engine_unselect_all(tmp->engine);
1487 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1489 * @param user_data - user data set when the signal handler was connected
1492 guint ws_gui_show_popup (gpointer user_data)
1494 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1495 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1496 if (tmp > PRESS_TIME)
1498 ws_gui_create_popup_menu(ws_gui_app);
1500 return (guint)(FALSE);
1504 /** checks clipboard content and sets sensitivity of widgets
1506 * @param widget - object which recived a signal
1507 * @param user_data - user data set when the signal handler was connected
1510 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
1512 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1513 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1515 gtk_widget_set_sensitive(
1516 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1521 gtk_widget_set_sensitive(
1522 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1526 struct _GtkHTML *tmp = (struct _GtkHTML *)(ws_gui_app->ws_gui_html);
1528 if (html_engine_is_selection_active(tmp->engine) == TRUE)
1530 gtk_widget_set_sensitive(GTK_WIDGET
1531 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1536 gtk_widget_set_sensitive(GTK_WIDGET
1537 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
1541 if (ws_gui_app->html_flag == FALSE)
1543 gtk_widget_set_sensitive(GTK_WIDGET
1544 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1549 gtk_widget_set_sensitive(GTK_WIDGET
1550 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
1556 /** gets received string (with translation), formats it and sends it to be
1559 * @param received_string - content received from Manager
1560 * @param user_data - user data set when the function has been called
1563 gchar * format_html (gchar * received_string, gpointer user_data)
1565 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1568 str_final = g_string_new(received_string);
1569 str_tmp = g_string_new(received_string);
1573 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
1577 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1579 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1580 str_final = g_string_erase(str_final,
1581 (long)(tmp - str_final->str),
1583 str_final = g_string_insert(str_final,
1584 (long)(tmp - str_final->str),
1585 "<html><head></head><body><center><table width=\"400px\"><tr>"
1586 "<td><table border=1 width=100%><tr>"
1587 "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1588 "<img align=left src=\"file:/usr/share/pixmaps/"
1589 "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1591 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1592 if (ws_gui_app->last_word != NULL)
1594 str_tmp = g_string_erase(str_tmp,
1595 (long)(tmp2 - str_tmp->str),
1596 14 + strlen(ws_gui_app->last_word));
1600 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1602 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1603 str_final = g_string_erase(str_final,
1604 (long)(tmp - str_final->str),
1606 str_final = g_string_insert(str_final,
1607 (long)(tmp - str_final->str),
1608 "</font></th></tr></table>");
1610 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1611 str_tmp = g_string_erase(str_tmp,
1612 (long)(tmp2 - str_tmp->str),
1616 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1618 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1619 str_final = g_string_erase (str_final,
1620 (long)(tmp - str_final->str),
1622 str_final = g_string_insert (str_final,
1623 (long)(tmp - str_final->str),
1624 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1625 "share/pixmaps/ws_tra.png\">");
1627 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1628 str_tmp = g_string_erase(str_tmp,
1629 (long)(tmp2 - str_tmp->str),
1633 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1635 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1636 str_final = g_string_erase(str_final,
1637 (long)(tmp - str_final->str),
1639 str_final = g_string_insert(str_final,
1640 (long)(tmp - str_final->str),
1641 "</td></tr></table></center>");
1643 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1644 str_tmp = g_string_erase(str_tmp,
1645 (long)(tmp2 - str_tmp->str),
1649 str_final = g_string_append(str_final,
1650 "</td></tr></table></body></html>");
1652 ws_gui_app->raw_translation = g_string_insert(
1653 ws_gui_app->raw_translation,
1657 return str_final->str;
1660 /** open bookmarks database
1662 * @param menuitem - object which recived the signal
1663 * @param user_data - user data set when the signal handler was connected
1666 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1668 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1670 ws_gui_read_active_dictionaries(ws_gui_app);
1672 g_free(ws_gui_app->last_word);
1673 ws_gui_app->last_word = NULL;
1675 ws_gui_app->bookmark_mode = TRUE;
1676 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1677 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1681 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1683 if(ws_gui_app->ws_gui_history->len >= 0)
1685 ws_gui_clear_array(ws_gui_app->ws_gui_history);
1686 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1687 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1688 ws_gui_app->ws_gui_history_cur_pos = -1;
1690 ws_gui_check_history(ws_gui_app);
1692 ws_gui_fill_html(" ", ws_gui_app);
1693 ws_gui_app->html_flag = FALSE;
1694 //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1695 ws_gui_search(NULL, ws_gui_app);
1699 /** closes bookmarks database
1701 * @param menuitem - object which recived the signal
1702 * @param user_data - user data set when the signal handler was connected
1705 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1707 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1709 ws_gui_read_active_dictionaries(ws_gui_app);
1711 g_free(ws_gui_app->last_word);
1712 ws_gui_app->last_word = NULL;
1714 ws_gui_app->bookmark_mode = FALSE;
1715 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1716 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1718 if(ws_gui_app->ws_gui_history->len >= 0)
1720 ws_gui_clear_array(ws_gui_app->ws_gui_history);
1721 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
1722 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
1723 ws_gui_app->ws_gui_history_cur_pos = -1;
1725 ws_gui_check_history(ws_gui_app);
1727 ws_gui_fill_html(" ", ws_gui_app);
1728 ws_gui_app->html_flag = FALSE;
1729 g_strstrip(ws_gui_app->last_searched);
1730 if (ws_gui_app->last_searched != NULL)
1732 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1734 ws_gui_app->last_searched,
1736 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1737 ws_gui_search(NULL, ws_gui_app);
1741 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1746 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
1747 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
1748 ws_gui_app->ws_gui_w_list->ws_gui_model =
1749 create_and_fill_model(tmp, ws_gui_app);
1751 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1752 ws_gui_search(NULL, ws_gui_app);
1756 /** adds bookmark to bookmarks database
1758 * @param menuitem - object which recived the signal
1759 * @param user_data - user data set when the signal handler was connected
1762 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1764 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1766 if (ws_gui_app->last_word != NULL)
1768 ws_gui_add_bookmark_dialog(ws_gui_app);
1773 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1774 _("ws_ni_select_word_to_add"));
1778 /** removes bookmark from bookmarks database
1780 * @param menuitem - object which recived the signal
1781 * @param user_data - user data set when the signal handler was connected
1784 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
1787 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1789 if (ws_gui_app->last_word != NULL)
1791 ws_gui_remove_bookmark_dialog(ws_gui_app);
1794 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1798 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1804 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1805 _("ws_ni_select_word_to_remove"));
1811 /** checks wheather dictionaries are available or not; according to the result
1812 * dimmes proper menuitem
1814 * @param menuitem - object which recived the signal
1815 * @param user_data - user data set when the signal handler was connected
1818 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1820 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1821 if (gconf_client_dir_exists(ws_gui_app->client,
1822 GCONF_PATH, NULL) == TRUE)
1824 ws_gui_app->directories = gconf_client_all_dirs(
1831 if(g_slist_length(ws_gui_app->directories) != 0)
1833 gtk_widget_set_sensitive(GTK_WIDGET
1834 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1836 gtk_widget_set_sensitive(GTK_WIDGET
1837 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1839 gtk_widget_set_sensitive(GTK_WIDGET
1840 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1847 gtk_widget_set_sensitive(GTK_WIDGET
1848 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1850 gtk_widget_set_sensitive(GTK_WIDGET
1851 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1853 gtk_widget_set_sensitive(GTK_WIDGET
1854 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1860 /** sets sensitivity of menu items due to bookmark's mode
1862 * @param user_data - user data set when the function was called
1865 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1867 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1872 if (ws_gui_app->bookmark_mode == TRUE)
1874 g_slist_free(ws_gui_app->directories_last);
1875 ws_gui_app->directories_last = NULL;
1876 ws_gui_app->directories_last = g_slist_alloc();
1877 g_slist_free(ws_gui_app->directories);
1878 ws_gui_app->directories = g_slist_alloc();
1880 ws_gui_app->directories = gconf_client_all_dirs(
1884 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
1886 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
1887 name = g_path_get_basename(string);
1888 string = g_strconcat(string, "/active", NULL);
1890 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
1892 ws_gui_app->directories_last =
1893 g_slist_append(ws_gui_app->directories_last,
1897 if (strcmp(name, "bookmarks") == 0)
1899 gconf_client_set_bool(ws_gui_app->client,
1906 gconf_client_set_bool(ws_gui_app->client,
1913 //setting sensitivity of components
1914 gtk_widget_set_sensitive(
1915 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1917 gtk_widget_set_sensitive(
1918 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1920 gtk_widget_set_sensitive(
1921 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1923 gtk_widget_set_sensitive(
1924 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1926 gtk_widget_set_sensitive(
1927 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1932 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1933 if (g_slist_length(ws_gui_app->directories_last) > 0)
1935 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1938 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1940 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
1943 //string = g_strconcat(string, "/active", NULL);
1946 gconf_client_set_bool(ws_gui_app->client,
1953 //setting sensitivity of components
1954 gtk_widget_set_sensitive(
1955 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1957 gtk_widget_set_sensitive(
1958 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1960 gtk_widget_set_sensitive(
1961 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1963 gtk_widget_set_sensitive(
1964 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1966 gtk_widget_set_sensitive(
1967 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1972 /** sets sensitivity of menu items due to user selection made
1974 * @param user_data - user data set when the function was called
1977 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
1979 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1980 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
1982 gtk_widget_set_sensitive(
1983 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1988 gtk_widget_set_sensitive(
1989 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1993 if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
1995 gtk_widget_set_sensitive(
1996 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2001 gtk_widget_set_sensitive(
2002 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
2006 /** reads gconf entries and sets variables with a proper data; it is necessary
2007 * for changing the bookmarks mode
2009 * @param user_data - user data set when the function was called
2012 void ws_gui_read_active_dictionaries(gpointer user_data)
2014 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
2017 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
2022 void ws_gui_clear_array(GArray *history)
2024 if(history->len >= 0)
2026 history = g_array_remove_range(history, 0, history->len);