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);
145 gtk_widget_set_sensitive(
146 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
148 gtk_widget_set_sensitive(
149 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
153 GTK_DIALOG(ws_gui_app->ws_message_dialog))
157 ws_gui_app->ws_message_dialog);
162 case WS_DBUS_INFO_CACHING:
164 ws_gui_app->ws_gui_banner_caching =
165 hildon_banner_show_progress(
166 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
169 ws_gui_app->caching_flag = TRUE;
170 hildon_banner_set_fraction(
171 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
173 gtk_widget_set_sensitive(
174 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
176 gtk_widget_set_sensitive(
177 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
183 case WS_DBUS_INFO_CACHING_FINISHED:
186 GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
187 ws_gui_app->caching_flag = FALSE;
188 gtk_widget_set_sensitive(
189 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
191 gtk_widget_set_sensitive(
192 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
198 case WS_DBUS_ERROR_DICTIONARY_NOT_LOAD:
200 if (ws_gui_app->ws_gui_history_cur_pos >= 0 &&
201 ws_gui_app->ws_gui_history_cur_pos <=HISTORY_LEN)
203 g_array_remove_index(ws_gui_app->ws_gui_history,
204 ws_gui_app->ws_gui_history_cur_pos);
207 ws_gui_app->ws_message_dialog = gtk_message_dialog_new(
208 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
209 GTK_DIALOG_DESTROY_WITH_PARENT,
212 _("ws_ni_dictionary_unavailable"));
213 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
215 GTK_DIALOG(ws_gui_app->ws_message_dialog))
218 gtk_widget_destroy(ws_gui_app->ws_message_dialog);
223 case WS_DBUS_BOOKMARKS_ADDED_OK:
225 gtk_infoprint(GTK_WINDOW(
226 ws_gui_app->ws_gui_hildon_window),
227 _("ws_ni_bookmark_added"));
231 case WS_DBUS_BOOKMARKS_REMOVED_OK:
233 gtk_infoprint(GTK_WINDOW(
234 ws_gui_app->ws_gui_hildon_window),
235 _("ws_ni_bookmark_removed"));
239 case WS_DBUS_BOOKMARKS_ADDED_FAIL:
241 gtk_infoprint(GTK_WINDOW(
242 ws_gui_app->ws_gui_hildon_window),
243 _("ws_ni_bookmark_not_added"));
247 case WS_DBUS_BOOKMARKS_REMOVED_FAIL:
249 gtk_infoprint(GTK_WINDOW(
250 ws_gui_app->ws_gui_hildon_window),
251 _("ws_ni_bookmark_not_removed"));
255 case WS_DBUS_LOAD_BOOKMARK_FAILED:
257 gtk_widget_set_sensitive(
258 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
260 ws_gui_app->bookmark_avail = FALSE;
262 ws_gui_app->ws_message_dialog =
263 gtk_message_dialog_new(
264 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
265 GTK_DIALOG_DESTROY_WITH_PARENT,
268 _("ws_ni_bookmarks_unavailable"));
271 GTK_DIALOG(ws_gui_app->ws_message_dialog))
275 ws_gui_app->ws_message_dialog);
283 /** this function handles signals from dbus; it is called when progress bar
284 status has been changed
286 * @param error - error message recived from DBUS
287 * @param words - array with recived data structure
288 * @param user_data - pointer to data structure
291 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
293 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
294 osso_rpc_t osss_data;
295 osss_data = g_array_index (words, osso_rpc_t, 0);
296 double progress = osss_data.value.d;
297 if (ws_gui_app->caching_flag == TRUE)
299 hildon_banner_set_fraction(
300 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
305 /** this function handles signal from dbus and transfer recived
306 (found in a dictionary) words to the words list
308 * @param error - error message recived from DBUS
309 * @param words - array with recived data structure
310 * @param user_data - pointer to data structure
313 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
315 timer(TIMER_START, (gchar*)__FUNCTION__);
319 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
322 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
325 for (i=0;i<words->len;++i)
327 data = g_array_index (words, osso_rpc_t, i);
328 tmp_word = g_strconcat(data.value.s,NULL);
329 g_array_append_val(tmp, tmp_word);
332 g_assert(ws_gui_app->ws_gui_banner);
333 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
334 //g_signal_handler_unblock(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);
336 ws_gui_app->ws_gui_banner_flag = FALSE;
337 gtk_widget_set_sensitive(
338 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
340 gtk_widget_set_sensitive(
341 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
343 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
345 ws_gui_app->ws_gui_w_list->ws_gui_model =
346 create_and_fill_model(tmp, ws_gui_app);
347 if (ws_gui_app->history_flag == TRUE)
349 gtk_tree_model_get_iter_from_string
351 ws_gui_app->ws_gui_w_list->ws_gui_model),
352 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
353 g_array_index(ws_gui_app->ws_gui_history_iter,
355 ws_gui_app->ws_gui_history_cur_pos));
357 gtk_tree_selection_select_iter(
358 ws_gui_app->ws_gui_w_list->ws_gui_selection,
359 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
361 ws_gui_app->history_flag = FALSE;
362 ws_gui_fill_html(format_html(data.value.s, ws_gui_app), ws_gui_app);
367 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
368 _("ws_ni_no_words_found"));
370 ws_gui_app->history_mode = 0;
372 ws_gui_fill_html(" ", ws_gui_app);
373 g_free(ws_gui_app->last_word);
374 ws_gui_app->last_word = NULL;
378 timer(TIMER_STOP, (gchar*)__FUNCTION__);
381 /** this function handles signal from dbus and send recived data to
384 * @param error - error message recived from DBUS
385 * @param words - array with recived data structure
386 * @param user_data - pointer to data structure
389 void ws_gui_dbus_return_translation (GError *error,
393 //timer(TIMER_START, (gchar*)__FUNCTION__);
394 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
398 data = g_array_index (words, osso_rpc_t, 0);
399 //gtk_html_zoom_reset(GTK_HTML(ws_gui_app->ws_gui_html));
400 ws_gui_fill_html(format_html(data.value.s, ws_gui_app), ws_gui_app);
402 //timer(TIMER_STOP, (gchar*)__FUNCTION__);
407 * this function allows to free allocated memory
409 * @param user_data - pointer to data structure
411 void ws_gui_free_memory(gpointer user_data)
413 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
414 g_array_free(ws_gui_app->ws_gui_history, TRUE);
415 pango_font_description_free(ws_gui_app->p);
416 g_free(ws_gui_app->last_word);
417 g_free(ws_gui_app->ws_gui_w_list);
418 g_free(ws_gui_app->ws_gui_menu);
422 /** this function handle press signals (keyboard)
426 * @param user_data - ponter to data structure
427 * @return TRUE to stop other handlers from being invoked for the event.
428 FALSE to propagate the event further.
430 gboolean hildon_key_press_listener (GtkWidget * widget,
431 GdkEventKey * keyevent,
434 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
436 switch ((guint)(keyevent->keyval)) {
437 case HILDON_HARDKEY_UP:
439 gtk_container_set_focus_vadjustment(
440 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
441 gtk_scrolled_window_get_vadjustment(
443 ws_gui_app->ws_gui_scrolledwindow_left)));
444 ws_gui_app->v_new_value =
445 gtk_adjustment_get_value(
447 ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
448 if (ws_gui_app->v_new_value >
449 ws_gui_app->ws_gui_vadj->lower)
451 gtk_adjustment_set_value(
452 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
453 ws_gui_app->v_new_value);
458 case HILDON_HARDKEY_DOWN:
460 gtk_container_set_focus_vadjustment(
461 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
462 gtk_scrolled_window_get_vadjustment(
464 ws_gui_app->ws_gui_scrolledwindow_left)));
465 ws_gui_app->v_new_value = gtk_adjustment_get_value(
466 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj))
467 + ws_gui_app->v_delta;
469 if (ws_gui_app->v_new_value <
470 (ws_gui_app->ws_gui_vadj->upper -
471 ws_gui_app->ws_gui_vadj->page_size))
473 gtk_adjustment_set_value(
474 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
475 ws_gui_app->v_new_value);
480 case HILDON_HARDKEY_LEFT:
482 gtk_container_set_focus_hadjustment(
483 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
484 gtk_scrolled_window_get_hadjustment(
486 ws_gui_app->ws_gui_scrolledwindow_left)));
488 ws_gui_app->h_new_value = gtk_adjustment_get_value(
489 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
490 - ws_gui_app->h_delta;
492 if (ws_gui_app->h_new_value >
493 ws_gui_app->ws_gui_hadj->lower)
495 gtk_adjustment_set_value(
496 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
497 ws_gui_app->h_new_value);
502 case HILDON_HARDKEY_RIGHT:
504 gtk_container_set_focus_hadjustment(
505 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
506 gtk_scrolled_window_get_hadjustment(
508 ws_gui_app->ws_gui_scrolledwindow_left)));
510 ws_gui_app->h_new_value = gtk_adjustment_get_value(
511 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
512 + ws_gui_app->h_delta;
514 if (ws_gui_app->h_new_value <
515 (ws_gui_app->ws_gui_hadj->upper -
516 ws_gui_app->ws_gui_hadj->page_size))
518 gtk_adjustment_set_value(
519 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
520 ws_gui_app->h_new_value);
525 case HILDON_HARDKEY_SELECT:
526 ws_gui_search(NULL, ws_gui_app);
529 case HILDON_HARDKEY_FULLSCREEN:
530 ws_gui_full_screen(NULL, ws_gui_app);
533 case HILDON_HARDKEY_INCREASE:
534 ws_gui_html_zoom_in(NULL, ws_gui_app);
537 case HILDON_HARDKEY_DECREASE:
538 ws_gui_html_zoom_out(NULL, ws_gui_app);
541 case HILDON_HARDKEY_ESC:
542 ws_gui_search_stop(NULL, ws_gui_app);
552 /** this function allow to hide words list using menu item from application menu
554 * @param checkmenuitem - the object which received the signal
555 * @param user_data - user data set when the signal handler was connected
558 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
561 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
562 if (gtk_check_menu_item_get_active(
563 GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
565 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
566 gtk_toggle_tool_button_set_active(
567 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide),
569 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
570 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
575 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
576 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
577 ws_gui_app->ws_gui_toobar_button_hide),
579 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
580 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
585 /** this function allow to hide words list using toggle button placed in
588 * @param toolbar - the object which received the signal
589 * @param user_data - user data set when the signal handler was connected
592 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
594 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
596 if (gtk_toggle_tool_button_get_active(
597 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
599 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
600 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
601 ws_gui_app->ws_gui_toobar_button_hide),
603 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
604 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
609 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
610 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
611 ws_gui_app->ws_gui_toobar_button_hide),
613 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
614 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
619 /** add word to the history
621 * @param new_word - word which is going to be append to the history array
622 * @param user_data - user data set when the signal handler was connected
625 void ws_gui_history_add(char *new_word, gpointer user_data)
627 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
629 if (ws_gui_app->history_mode == 0)
634 gchar *tmp_last_searched;
635 gchar *tmp_iter = NULL;
636 gchar *previous_word = " ";
638 if (ws_gui_app->ws_gui_history_cur_pos > -1 && g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos) != NULL)
640 previous_word = NULL;
641 previous_word = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos);
644 i = ws_gui_app->ws_gui_history_cur_pos + 1;
645 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
646 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);
648 // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n\n\n======= GUI: previous_word: %s", previous_word);
649 // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "======= GUI: obecne_word: %s", new_word);
650 // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "======= GUI: ITER TO: %s\n\n\n", tmp_iter);
652 if (previous_word != NULL && strcmp(previous_word, new_word) != 0)
657 g_array_remove_index(ws_gui_app->ws_gui_history, i);
658 g_array_remove_index(ws_gui_app->ws_gui_history_list, i);
659 g_array_remove_index(ws_gui_app->ws_gui_history_iter, i);
660 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
664 ws_gui_app->ws_gui_history_cur_pos ++;
666 tmp_word = g_strdup(new_word);
667 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
669 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
670 g_array_append_val(ws_gui_app->ws_gui_history_list, tmp_last_searched);
671 g_array_append_val(ws_gui_app->ws_gui_history_iter, tmp_iter);
674 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
676 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
677 g_array_remove_index(ws_gui_app->ws_gui_history_list, 0);
678 g_array_remove_index(ws_gui_app->ws_gui_history_iter, 0);
679 ws_gui_app->ws_gui_history_cur_pos--;
683 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
686 for (v=0; v<=ws_gui_app->ws_gui_history_cur_pos; v++)
688 // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "---------------slowko to: %s", g_array_index(ws_gui_app->ws_gui_history_list, gchar*, v));
694 ws_gui_check_history(ws_gui_app);
697 /** display previously choosen word (previous from the history array)
698 if avaible, sets current position in the history array
700 * @param button - button which recived a signal
701 * @param user_data - user data set when the signal handler was connected
704 void ws_gui_history_back(GtkButton *button, gpointer user_data)
706 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
708 ws_gui_app->history_flag = TRUE;
710 if (ws_gui_app->ws_gui_history_cur_pos > 0)
712 ws_gui_app->ws_gui_history_cur_pos =
713 ws_gui_app->ws_gui_history_cur_pos - 1;
715 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
717 (g_array_index(ws_gui_app->ws_gui_history_list,
719 ws_gui_app->ws_gui_history_cur_pos)),
723 ws_dbus_client_find_word (ws_gui_app->dbus_data,
724 g_array_index(ws_gui_app->ws_gui_history_list,
726 ws_gui_app->ws_gui_history_cur_pos)
732 gtk_widget_set_sensitive (
733 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
735 gtk_widget_set_sensitive(
736 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
740 ws_gui_check_history(ws_gui_app);
744 /** display choosen word, next in the history array (if avaible),
745 sets current position in the history array
747 * @param button - button which recived a signal
748 * @param user_data - user data set when the signal handler was connected
751 void ws_gui_history_next(GtkButton *button, gpointer user_data)
753 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
755 ws_gui_app->history_flag = TRUE;
757 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
759 ws_gui_app->ws_gui_history_cur_pos+1);
761 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
764 ws_gui_app->ws_gui_history_cur_pos =
765 ws_gui_app->ws_gui_history_cur_pos + 1;
767 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
769 (g_array_index(ws_gui_app->ws_gui_history_list,
771 ws_gui_app->ws_gui_history_cur_pos)),
775 //ws_gui_search(NULL, ws_gui_app);
777 ws_dbus_client_find_word(ws_gui_app->dbus_data,
778 g_array_index(ws_gui_app->ws_gui_history_list,
780 ws_gui_app->ws_gui_history_cur_pos)
783 //ws_dbus_client_search_in_history(ws_gui_app->dbus_data,
784 // (g_array_index(ws_gui_app->ws_gui_history,
786 // ws_gui_app->ws_gui_history_cur_pos)));
791 gtk_widget_set_sensitive(
792 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
794 gtk_widget_set_sensitive(
795 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
799 ws_gui_check_history(ws_gui_app);
802 /** check current position in the history array and sets sensitivity of buttons
803 / menu items, depends on availablity of words in the history
805 * @param user_data - user data set when the signal handler was connected
808 void ws_gui_check_history(gpointer user_data)
810 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
812 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
814 ws_gui_app->ws_gui_history_cur_pos+1);
816 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
819 gtk_widget_set_sensitive(
820 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
822 gtk_widget_set_sensitive(
823 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
828 gtk_widget_set_sensitive(
829 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
831 gtk_widget_set_sensitive(
832 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
836 tmp = g_array_index(ws_gui_app->ws_gui_history,
838 ws_gui_app->ws_gui_history_cur_pos-1);
839 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
841 gtk_widget_set_sensitive(
842 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
844 gtk_widget_set_sensitive(
845 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
850 gtk_widget_set_sensitive (
851 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
853 gtk_widget_set_sensitive(
854 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
859 /** create TreeView Model, which allows to display words list
861 * @param words_list - array with words(found in a dictionary), recived from
863 * @param user_data - user data set when the signal handler was connected
866 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
868 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
870 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
873 valid = gtk_tree_model_get_iter_first(
874 GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
875 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
877 /* Append a row and fill in some data */
880 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
881 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
883 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
884 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
888 tmp = g_strdup(g_array_index(words_list, gchar*, i));
891 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
893 if (tmp != NULL && ws_gui_app->history_flag == FALSE)
895 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
896 ws_gui_history_add(tmp, ws_gui_app);
897 g_free(ws_gui_app->last_word);
898 ws_gui_app->last_word = NULL;
899 ws_gui_app->last_word = g_strdup (tmp);
902 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
905 /** create TreeView and TreeModel using create_and_fill_model() function;
906 it is necessary to display found words in a words list;
908 * @param words_list - array with words(found in a dictionary),
910 * @param user_data - user data set when the signal handler was connected
913 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
915 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
917 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
919 ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
920 gtk_tree_view_insert_column_with_attributes(
921 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
924 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
928 ws_gui_app->ws_gui_w_list->ws_gui_model =
929 create_and_fill_model(words_list, ws_gui_app);
931 gtk_tree_view_set_model(
932 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
933 ws_gui_app->ws_gui_w_list->ws_gui_model);
934 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
936 return ws_gui_app->ws_gui_w_list->ws_gui_view;
939 /** handle signal from words list, get selected word and calls
940 'find translation' function
942 * @param selection - the object which received the signal
943 * @param user_data - user data set when the signal handler was connected
946 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
949 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
951 ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
953 if (gtk_tree_selection_get_selected(selection,
954 &ws_gui_app->ws_gui_w_list->ws_gui_model,
955 &ws_gui_app->ws_gui_w_list->ws_gui_iter))
957 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
958 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
963 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
965 g_free(ws_gui_app->last_word);
966 ws_gui_app->last_word = NULL;
967 ws_gui_app->last_word = g_strdup (string);
970 if (string != NULL && ws_gui_app->history_flag == FALSE)
972 ws_gui_history_add(string, ws_gui_app);
978 /** switch application between fun screen and normal mode
980 * @param menuitem - object which recived the signal
981 * @param user_data - user data set when the signal handler was connected
984 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
987 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
988 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
990 gtk_window_fullscreen(
991 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
992 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
993 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
995 ws_gui_app->ws_gui_full_screen_flag = TRUE;
996 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
997 _("ws_ib_fullscreen_on"));
1001 gtk_window_unfullscreen(
1002 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1003 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1004 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1006 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1007 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1008 _("ws_ib_fullscreen_off"));
1012 /** search for selected text in a dictionary
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_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1020 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1022 ws_gui_app->ws_gui_clipboard_primary =
1023 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1024 GDK_SELECTION_PRIMARY);
1025 temp = gtk_clipboard_wait_for_text(
1026 ws_gui_app->ws_gui_clipboard_primary);
1029 if (temp != NULL || strcmp(temp, " "))
1031 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1035 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1039 hildon_banner_show_information(
1040 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1042 _("ws_ni_no_text_selected"));
1046 /** select whole text in the translation (html) area
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_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
1054 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1055 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1058 /** copy selected text to the clipoard from context popup menu
1060 * @param menuitem - object which recived the signal
1061 * @param user_data - user data set when the signal handler was connected
1064 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
1066 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1067 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1070 /** paste copied text into toolbar entry
1072 * @param menuitem - object which recived the signal
1073 * @param user_data - user data set when the signal handler was connected
1076 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1078 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1082 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1083 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1087 temp = g_strconcat(temp2, temp, NULL);
1088 temp = g_strdelimit(temp, "\n", ' ');
1089 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1095 /** zoom in text in translation (html) area
1097 * @param menuitem - object which recived the signal
1098 * @param user_data - user data set when the signal handler was connected
1101 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1103 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1104 //gtk_html_zoom_in(GTK_HTML(ws_gui_app->ws_gui_html));
1105 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1106 if (ws_gui_app->zoom > ZOOM_MAX)
1108 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1109 gtk_infoprint(GTK_WINDOW(
1110 ws_gui_app->ws_gui_hildon_window),
1111 _("ws_ib_max_zoom"));
1115 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1117 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1118 _("ws_ib_zoom_in"));
1122 /** zoom out text in translation (html) area
1124 * @param menuitem - object which recived the signal
1125 * @param user_data - user data set when the signal handler was connected
1128 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1130 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1131 //gtk_html_zoom_out(GTK_HTML(ws_gui_app->ws_gui_html));
1132 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1133 if (ws_gui_app->zoom < ZOOM_MIN)
1135 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1136 gtk_infoprint(GTK_WINDOW(
1137 ws_gui_app->ws_gui_hildon_window),
1138 _("ws_ib_min_zoom"));
1142 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1144 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1145 _("ws_ib_zoom_out"));
1149 /** start searching, send typed word to DBUS and query for words
1151 * @param widget - object which recived the signal
1152 * @param user_data - user data set when the signal handler was connected
1155 void ws_gui_search(GtkWidget * widget, gpointer user_data)
1157 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1160 if (ws_gui_app->ws_gui_banner_flag == FALSE)
1162 gchar* ws_gui_text = NULL;
1163 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1168 if (ws_gui_app->bookmark_mode == FALSE)
1170 g_free(ws_gui_app->last_searched);
1171 ws_gui_app->last_searched = NULL;
1172 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1175 g_strstrip(ws_gui_text);
1176 if (strlen(ws_gui_text) != 0)
1178 gtk_widget_show(ws_gui_app->ws_gui_banner);
1179 //g_signal_handler_block(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);
1181 gtk_widget_set_sensitive(
1182 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1184 gtk_widget_set_sensitive(
1185 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1188 ws_gui_app->ws_gui_banner_flag = TRUE;
1189 ws_gui_fill_html(" ", ws_gui_app);
1190 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1196 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1197 _("ws_ni_no_word_typed"));
1199 g_free(ws_gui_app->last_word);
1200 ws_gui_app->last_word=NULL;
1204 /** stop search process
1206 * @param button - object which recived the signal
1207 * @param user_data - user data set when the signal handler was connected
1210 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
1212 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1213 if (ws_gui_app->ws_gui_banner_flag == TRUE)
1215 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1216 //g_signal_handler_unblock(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);
1217 ws_gui_app->ws_gui_banner_flag = FALSE;
1218 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1220 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1221 _("ws_ni_search_aborted"));
1225 /** this function is called just before closing application;
1226 it sends signal to DBUS and destroys it;
1228 * @param widget - object which recived the signal
1230 * @param user_data - user data set when the signal handler was connected
1233 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
1235 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1236 ws_gui_app->bookmark_mode = FALSE;
1237 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1238 g_timer_destroy(ws_gui_app->timer);
1239 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1240 ws_dbus_destroy (ws_gui_app->dbus_data);
1241 ws_gui_free_memory(ws_gui_app);
1246 /** this function is called just before closing application,
1247 from application menu; it sends signal to DBUS and destroys it;
1249 * @param menuitem - object which recived the signal
1250 * @param user_data - user data set when the signal handler was connected
1253 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1255 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1256 ws_gui_app->bookmark_mode = FALSE;
1257 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1258 g_timer_destroy(ws_gui_app->timer);
1259 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1260 ws_dbus_destroy (ws_gui_app->dbus_data);
1261 ws_gui_free_memory(ws_gui_app);
1266 /** fill translation area with text (html) recived from DBUS
1268 * @param html_context - text which is going to be displayed; it should be html
1269 * @param user_data - user data set when the function was called
1272 void ws_gui_fill_html(char *html_context, gpointer user_data)
1274 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1275 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1277 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1282 /** read adjustment of left scrollwindow, which is necessary to navigate with
1283 arrow keys inside words list
1285 * @param user_data - user data set when the signal handler was connected
1288 void ws_gui_read_adjustment(gpointer user_data)
1290 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1292 ws_gui_app->ws_gui_hadj =
1293 gtk_scrolled_window_get_hadjustment(
1294 GTK_SCROLLED_WINDOW(
1295 ws_gui_app->ws_gui_scrolledwindow_left));
1297 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1298 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1300 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1301 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1303 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1304 ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1305 ws_gui_app->v_new_value =
1306 gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1307 ws_gui_app->v_delta;
1309 gtk_container_set_focus_vadjustment(
1310 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
1311 gtk_scrolled_window_get_vadjustment(
1312 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1316 /** allows to display image in html area
1318 * @param html - object which received a signal
1319 * @param url - url to the image
1320 * @param stream - html stream
1323 void ws_gui_url_requested (
1326 GtkHTMLStream *stream)
1330 if (url && !strncmp (url, "file:", 5)) {
1332 fd = open (url, O_RDONLY);
1336 buf = alloca (8192);
1337 while ((size = read (fd, buf, 8192)) > 0) {
1338 gtk_html_stream_write (stream, buf, size);
1340 gtk_html_stream_close(stream, size == -1
1341 ? GTK_HTML_STREAM_ERROR
1342 : GTK_HTML_STREAM_OK);
1349 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1352 /** handles button press event and examines what kind of event was it
1355 * @param widget - object which received a signal
1356 * @param event - type of event which has been performed
1357 * @param user_data - user data set when the signal handler was connected
1358 * @return TRUE to stop other handlers from being invoked for the event.
1359 FALSE to propagate the event further
1361 gboolean ws_gui_button_press(GtkWidget *widget,
1362 GdkEventButton *event,
1365 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1366 if (ws_gui_app->ws_gui_sel_flag == FALSE)
1368 if (event->type == GDK_2BUTTON_PRESS)
1370 ws_gui_app->ws_gui_double_click = TRUE;
1371 g_timer_stop(ws_gui_app->timer);
1372 g_timer_reset(ws_gui_app->timer);
1376 g_signal_stop_emission_by_name(G_OBJECT(
1377 ws_gui_app->ws_gui_html),
1378 "button-press-event");
1379 g_timer_start(ws_gui_app->timer);
1380 gtk_timeout_add((guint)(PRESS_TIME*1000),
1381 (GtkFunction)(ws_gui_show_popup),
1387 ws_gui_app->ws_gui_sel_flag = FALSE;
1393 /** handles button release event and examines whether 'click' or 'tap and hold'
1394 event it supposed to be
1396 * @param widget - object which received a signal
1397 * @param event - type of event which has been performed
1398 * @param user_data - user data set when the signal handler was connected
1399 * @return TRUE to stop other handlers from being invoked for the event.
1400 FALSE to propagate the event further
1402 gboolean ws_gui_button_release (GtkWidget *widget,
1403 GdkEventButton *event,
1406 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1407 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1408 g_timer_stop(ws_gui_app->timer);
1409 g_timer_reset(ws_gui_app->timer);
1410 if (ws_gui_app->ws_gui_double_click == TRUE)
1412 ws_gui_app->ws_gui_double_click = FALSE;
1415 else if (tmp < PRESS_TIME)
1417 struct _GtkHTML *tmp = (struct _GtkHTML *)
1418 (ws_gui_app->ws_gui_html);
1419 html_engine_unselect_all(tmp->engine);
1425 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1427 * @param user_data - user data set when the signal handler was connected
1430 guint ws_gui_show_popup (gpointer user_data)
1432 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1433 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1434 if (tmp > PRESS_TIME)
1436 ws_gui_create_popup_menu(ws_gui_app);
1438 return (guint)(FALSE);
1442 /** checks clipboard content and sets sensitivity of widgets
1444 * @param widget - object which recived a signal
1445 * @param user_data - user data set when the signal handler was connected
1448 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
1450 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1451 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1453 gtk_widget_set_sensitive(
1454 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1459 gtk_widget_set_sensitive(
1460 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1465 /** gets received string (with translation), formats it and sends it to be
1468 * @param received_string - content received from Manager
1469 * @param user_data - user data set when the function has been called
1472 gchar * format_html (gchar * received_string, gpointer user_data)
1474 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1477 str_final = g_string_new(received_string);
1478 str_tmp = g_string_new(received_string);
1482 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
1486 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1488 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1489 str_final = g_string_erase(str_final,
1490 (long)(tmp - str_final->str),
1492 str_final = g_string_insert(str_final,
1493 (long)(tmp - str_final->str),
1494 "<html><head></head><body><center><table width=\"400px\"><tr>"
1495 "<td><table border=1 width=100%><tr>"
1496 "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1497 "<img align=left src=\"file:/usr/share/pixmaps/"
1498 "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1500 //g_debug("\n\nws_gui_app->last_word %s", ws_gui_app->last_word);
1501 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1502 if (ws_gui_app->last_word != NULL)
1504 str_tmp = g_string_erase(str_tmp,
1505 (long)(tmp2 - str_tmp->str),
1506 14 + strlen(ws_gui_app->last_word));
1508 //str_tmp = g_string_insert(str_tmp, "<br>", 0);
1511 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1513 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1514 str_final = g_string_erase(str_final,
1515 (long)(tmp - str_final->str),
1517 str_final = g_string_insert(str_final,
1518 (long)(tmp - str_final->str),
1519 "</font></th></tr></table>");
1521 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1522 str_tmp = g_string_erase(str_tmp,
1523 (long)(tmp2 - str_tmp->str),
1527 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1529 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
1530 str_final = g_string_erase (str_final,
1531 (long)(tmp - str_final->str),
1533 str_final = g_string_insert (str_final,
1534 (long)(tmp - str_final->str),
1535 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1536 "share/pixmaps/ws_tra.png\">");
1538 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1539 str_tmp = g_string_erase(str_tmp,
1540 (long)(tmp2 - str_tmp->str),
1542 /*str_tmp = g_string_insert(str_tmp,
1543 (long)(tmp2 - str_tmp->str),
1548 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1550 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1551 str_final = g_string_erase(str_final,
1552 (long)(tmp - str_final->str),
1554 str_final = g_string_insert(str_final,
1555 (long)(tmp - str_final->str),
1556 "</td></tr></table></center>");
1558 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1559 str_tmp = g_string_erase(str_tmp,
1560 (long)(tmp2 - str_tmp->str),
1565 str_final = g_string_append(str_final,
1566 "</td></tr></table></body></html>");
1568 ws_gui_app->raw_translation = g_string_insert(
1569 ws_gui_app->raw_translation,
1574 //ws_gui_app->raw_translation = g_string_append(str_final, "<br>");
1576 return str_final->str;
1579 /** open bookmarks database
1581 * @param menuitem - object which recived the signal
1582 * @param user_data - user data set when the signal handler was connected
1585 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1587 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1589 ws_gui_read_active_dictionaries(ws_gui_app);
1591 g_free(ws_gui_app->last_word);
1592 ws_gui_app->last_word = NULL;
1594 ws_gui_app->bookmark_mode = TRUE;
1595 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1596 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1600 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1602 ws_gui_fill_html(" ", ws_gui_app);
1603 //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1604 ws_gui_search(NULL, ws_gui_app);
1608 /** closes bookmarks database
1610 * @param menuitem - object which recived the signal
1611 * @param user_data - user data set when the signal handler was connected
1614 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1616 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1618 ws_gui_read_active_dictionaries(ws_gui_app);
1620 g_free(ws_gui_app->last_word);
1621 ws_gui_app->last_word = NULL;
1623 ws_gui_app->bookmark_mode = FALSE;
1624 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1625 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1626 ws_gui_fill_html(" ", ws_gui_app);
1627 g_strstrip(ws_gui_app->last_searched);
1628 if (ws_gui_app->last_searched != NULL)
1630 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1632 ws_gui_app->last_searched,
1634 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1635 ws_gui_search(NULL, ws_gui_app);
1639 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1644 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
1645 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
1646 ws_gui_app->ws_gui_w_list->ws_gui_model =
1647 create_and_fill_model(tmp, ws_gui_app);
1649 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1650 ws_gui_search(NULL, ws_gui_app);
1654 /** adds bookmark to bookmarks database
1656 * @param menuitem - object which recived the signal
1657 * @param user_data - user data set when the signal handler was connected
1660 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1662 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1664 if (ws_gui_app->last_word != NULL)
1666 ws_gui_add_bookmark_dialog(ws_gui_app);
1671 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1672 _("ws_ni_select_word_to_add"));
1678 /** removes bookmark from bookmarks database
1680 * @param menuitem - object which recived the signal
1681 * @param user_data - user data set when the signal handler was connected
1684 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
1687 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1689 if (ws_gui_app->last_word != NULL)
1691 ws_gui_remove_bookmark_dialog(ws_gui_app);
1694 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1698 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1704 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1705 _("ws_ni_select_word_to_remove"));
1711 /** checks wheather dictionaries are available or not; according to the result
1712 * dimmes proper menuitem
1714 * @param menuitem - object which recived the signal
1715 * @param user_data - user data set when the signal handler was connected
1718 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1720 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1721 if (gconf_client_dir_exists(ws_gui_app->client,
1722 GCONF_PATH, NULL) == TRUE)
1724 ws_gui_app->directories = gconf_client_all_dirs(
1731 if(g_slist_length(ws_gui_app->directories) != 0)
1733 gtk_widget_set_sensitive(GTK_WIDGET
1734 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1736 gtk_widget_set_sensitive(GTK_WIDGET
1737 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1739 gtk_widget_set_sensitive(GTK_WIDGET
1740 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1747 gtk_widget_set_sensitive(GTK_WIDGET
1748 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1750 gtk_widget_set_sensitive(GTK_WIDGET
1751 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1753 gtk_widget_set_sensitive(GTK_WIDGET
1754 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1760 /** sets sensitivity of menu items due to bookmark's mode
1762 * @param user_data - user data set when the function was called
1765 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1767 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1772 if (ws_gui_app->bookmark_mode == TRUE)
1774 g_slist_free(ws_gui_app->directories_last);
1775 ws_gui_app->directories_last = NULL;
1776 ws_gui_app->directories_last = g_slist_alloc();
1777 g_slist_free(ws_gui_app->directories);
1778 ws_gui_app->directories = g_slist_alloc();
1780 ws_gui_app->directories = gconf_client_all_dirs(
1784 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
1786 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
1787 name = g_path_get_basename(string);
1788 string = g_strconcat(string, "/active", NULL);
1790 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
1792 ws_gui_app->directories_last =
1793 g_slist_append(ws_gui_app->directories_last,
1797 if (strcmp(name, "bookmarks") == 0)
1799 gconf_client_set_bool(ws_gui_app->client,
1806 gconf_client_set_bool(ws_gui_app->client,
1813 //setting sensitivity of components
1814 gtk_widget_set_sensitive(
1815 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1817 gtk_widget_set_sensitive(
1818 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1820 gtk_widget_set_sensitive(
1821 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1823 gtk_widget_set_sensitive(
1824 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1826 gtk_widget_set_sensitive(
1827 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1832 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1833 if (g_slist_length(ws_gui_app->directories_last) > 0)
1835 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1838 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1840 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
1843 //string = g_strconcat(string, "/active", NULL);
1846 gconf_client_set_bool(ws_gui_app->client,
1853 //setting sensitivity of components
1854 gtk_widget_set_sensitive(
1855 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1857 gtk_widget_set_sensitive(
1858 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1860 gtk_widget_set_sensitive(
1861 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1863 gtk_widget_set_sensitive(
1864 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1866 gtk_widget_set_sensitive(
1867 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1872 /** sets sensitivity of menu items due to user selection made
1874 * @param user_data - user data set when the function was called
1877 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
1879 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1880 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
1882 gtk_widget_set_sensitive(
1883 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1888 gtk_widget_set_sensitive(
1889 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1893 if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
1895 gtk_widget_set_sensitive(
1896 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1901 gtk_widget_set_sensitive(
1902 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1906 /** reads gconf entries and sets variables with a proper data; it is necessary
1907 * for changing the bookmarks mode
1909 * @param user_data - user data set when the function was called
1912 void ws_gui_read_active_dictionaries(gpointer user_data)
1914 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1917 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,