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)
729 /*ws_dbus_client_search_in_history(
730 ws_gui_app->dbus_data,
731 (g_array_index(ws_gui_app->ws_gui_history,
733 ws_gui_app->ws_gui_history_cur_pos)));
737 /*gtk_tree_model_get_iter_from_string
739 ws_gui_app->ws_gui_w_list->ws_gui_model),
740 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
741 g_array_index(ws_gui_app->ws_gui_history_iter,
743 ws_gui_app->ws_gui_history_cur_pos));
745 gtk_tree_selection_select_iter(
746 ws_gui_app->ws_gui_w_list->ws_gui_selection,
747 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
753 gtk_widget_set_sensitive (
754 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
756 gtk_widget_set_sensitive(
757 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
761 ws_gui_check_history(ws_gui_app);
765 /** display choosen word, next in the history array (if avaible),
766 sets current position in the history array
768 * @param button - button which recived a signal
769 * @param user_data - user data set when the signal handler was connected
772 void ws_gui_history_next(GtkButton *button, gpointer user_data)
774 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
776 ws_gui_app->history_flag = TRUE;
778 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
780 ws_gui_app->ws_gui_history_cur_pos+1);
782 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
785 ws_gui_app->ws_gui_history_cur_pos =
786 ws_gui_app->ws_gui_history_cur_pos + 1;
788 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
790 (g_array_index(ws_gui_app->ws_gui_history_list,
792 ws_gui_app->ws_gui_history_cur_pos)),
796 //ws_gui_search(NULL, ws_gui_app);
798 ws_dbus_client_find_word(ws_gui_app->dbus_data,
799 g_array_index(ws_gui_app->ws_gui_history_list,
801 ws_gui_app->ws_gui_history_cur_pos)
804 //ws_dbus_client_search_in_history(ws_gui_app->dbus_data,
805 // (g_array_index(ws_gui_app->ws_gui_history,
807 // ws_gui_app->ws_gui_history_cur_pos)));
812 gtk_widget_set_sensitive(
813 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
815 gtk_widget_set_sensitive(
816 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
820 ws_gui_check_history(ws_gui_app);
823 /** check current position in the history array and sets sensitivity of buttons
824 / menu items, depends on availablity of words in the history
826 * @param user_data - user data set when the signal handler was connected
829 void ws_gui_check_history(gpointer user_data)
831 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
833 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
835 ws_gui_app->ws_gui_history_cur_pos+1);
837 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
840 gtk_widget_set_sensitive(
841 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
843 gtk_widget_set_sensitive(
844 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
849 gtk_widget_set_sensitive(
850 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
852 gtk_widget_set_sensitive(
853 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
857 tmp = g_array_index(ws_gui_app->ws_gui_history,
859 ws_gui_app->ws_gui_history_cur_pos-1);
860 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
862 gtk_widget_set_sensitive(
863 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
865 gtk_widget_set_sensitive(
866 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
871 gtk_widget_set_sensitive (
872 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
874 gtk_widget_set_sensitive(
875 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
880 /** create TreeView Model, which allows to display words list
882 * @param words_list - array with words(found in a dictionary), recived from
884 * @param user_data - user data set when the signal handler was connected
887 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
889 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
891 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
894 valid = gtk_tree_model_get_iter_first(
895 GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
896 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
898 /* Append a row and fill in some data */
901 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
902 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
904 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
905 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
909 tmp = g_strdup(g_array_index(words_list, gchar*, i));
912 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
914 if (tmp != NULL && ws_gui_app->history_flag == FALSE)
916 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
917 ws_gui_history_add(tmp, ws_gui_app);
918 g_free(ws_gui_app->last_word);
919 ws_gui_app->last_word = NULL;
920 ws_gui_app->last_word = g_strdup (tmp);
923 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
926 /** create TreeView and TreeModel using create_and_fill_model() function;
927 it is necessary to display found words in a words list;
929 * @param words_list - array with words(found in a dictionary),
931 * @param user_data - user data set when the signal handler was connected
934 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
936 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
938 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
940 ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
941 gtk_tree_view_insert_column_with_attributes(
942 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
945 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
949 ws_gui_app->ws_gui_w_list->ws_gui_model =
950 create_and_fill_model(words_list, ws_gui_app);
952 gtk_tree_view_set_model(
953 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
954 ws_gui_app->ws_gui_w_list->ws_gui_model);
955 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
957 return ws_gui_app->ws_gui_w_list->ws_gui_view;
960 /** handle signal from words list, get selected word and calls
961 'find translation' function
963 * @param selection - the object which received the signal
964 * @param user_data - user data set when the signal handler was connected
967 void ws_gui_tree_selection_changed(GtkTreeSelection *selection,
970 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
972 ws_gui_app->ws_gui_w_list->ws_gui_selection = selection;
974 if (gtk_tree_selection_get_selected(selection,
975 &ws_gui_app->ws_gui_w_list->ws_gui_model,
976 &ws_gui_app->ws_gui_w_list->ws_gui_iter))
978 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
979 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
984 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
986 g_free(ws_gui_app->last_word);
987 ws_gui_app->last_word = NULL;
988 ws_gui_app->last_word = g_strdup (string);
991 if (string != NULL && ws_gui_app->history_flag == FALSE)
993 ws_gui_history_add(string, ws_gui_app);
999 /** switch application between fun screen and normal mode
1001 * @param menuitem - object which recived the signal
1002 * @param user_data - user data set when the signal handler was connected
1005 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
1008 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1009 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
1011 gtk_window_fullscreen(
1012 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1013 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1014 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1016 ws_gui_app->ws_gui_full_screen_flag = TRUE;
1017 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1018 _("ws_ib_fullscreen_on"));
1022 gtk_window_unfullscreen(
1023 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
1024 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
1025 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
1027 ws_gui_app->ws_gui_full_screen_flag = FALSE;
1028 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1029 _("ws_ib_fullscreen_off"));
1033 /** search for selected text in a dictionary
1035 * @param menuitem - object which recived the signal
1036 * @param user_data - user data set when the signal handler was connected
1039 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
1041 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1043 ws_gui_app->ws_gui_clipboard_primary =
1044 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
1045 GDK_SELECTION_PRIMARY);
1046 temp = gtk_clipboard_wait_for_text(
1047 ws_gui_app->ws_gui_clipboard_primary);
1050 if (temp != NULL || strcmp(temp, " "))
1052 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1056 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1060 hildon_banner_show_information(
1061 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
1063 _("ws_ni_no_text_selected"));
1067 /** select whole text in the translation (html) area
1069 * @param menuitem - object which recived the signal
1070 * @param user_data - user data set when the signal handler was connected
1073 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
1075 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1076 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
1079 /** copy selected text to the clipoard from context popup menu
1081 * @param menuitem - object which recived the signal
1082 * @param user_data - user data set when the signal handler was connected
1085 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
1087 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1088 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
1091 /** paste copied text into toolbar entry
1093 * @param menuitem - object which recived the signal
1094 * @param user_data - user data set when the signal handler was connected
1097 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
1099 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1103 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
1104 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1108 temp = g_strconcat(temp2, temp, NULL);
1109 temp = g_strdelimit(temp, "\n", ' ');
1110 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1116 /** zoom in text in translation (html) area
1118 * @param menuitem - object which recived the signal
1119 * @param user_data - user data set when the signal handler was connected
1122 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
1124 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1125 //gtk_html_zoom_in(GTK_HTML(ws_gui_app->ws_gui_html));
1126 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1127 if (ws_gui_app->zoom > ZOOM_MAX)
1129 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1130 gtk_infoprint(GTK_WINDOW(
1131 ws_gui_app->ws_gui_hildon_window),
1132 _("ws_ib_max_zoom"));
1136 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1138 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1139 _("ws_ib_zoom_in"));
1143 /** zoom out text in translation (html) area
1145 * @param menuitem - object which recived the signal
1146 * @param user_data - user data set when the signal handler was connected
1149 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
1151 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1152 //gtk_html_zoom_out(GTK_HTML(ws_gui_app->ws_gui_html));
1153 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
1154 if (ws_gui_app->zoom < ZOOM_MIN)
1156 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
1157 gtk_infoprint(GTK_WINDOW(
1158 ws_gui_app->ws_gui_hildon_window),
1159 _("ws_ib_min_zoom"));
1163 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
1165 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1166 _("ws_ib_zoom_out"));
1170 /** start searching, send typed word to DBUS and query for words
1172 * @param widget - object which recived the signal
1173 * @param user_data - user data set when the signal handler was connected
1176 void ws_gui_search(GtkWidget * widget, gpointer user_data)
1178 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1181 if (ws_gui_app->ws_gui_banner_flag == FALSE)
1183 gchar* ws_gui_text = NULL;
1184 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1189 if (ws_gui_app->bookmark_mode == FALSE)
1191 g_free(ws_gui_app->last_searched);
1192 ws_gui_app->last_searched = NULL;
1193 ws_gui_app->last_searched = g_strdup(ws_gui_text);
1196 g_strstrip(ws_gui_text);
1197 if (strlen(ws_gui_text) != 0)
1199 gtk_widget_show(ws_gui_app->ws_gui_banner);
1200 //g_signal_handler_block(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);
1202 gtk_widget_set_sensitive(
1203 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
1205 gtk_widget_set_sensitive(
1206 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop),
1209 ws_gui_app->ws_gui_banner_flag = TRUE;
1210 ws_gui_fill_html(" ", ws_gui_app);
1211 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
1217 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1218 _("ws_ni_no_word_typed"));
1220 g_free(ws_gui_app->last_word);
1221 ws_gui_app->last_word=NULL;
1225 /** stop search process
1227 * @param button - object which recived the signal
1228 * @param user_data - user data set when the signal handler was connected
1231 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
1233 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1234 if (ws_gui_app->ws_gui_banner_flag == TRUE)
1236 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner));
1237 //g_signal_handler_unblock(G_OBJECT(ws_gui_app->ws_gui_w_list->ws_gui_selection), 263);
1238 ws_gui_app->ws_gui_banner_flag = FALSE;
1239 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
1241 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1242 _("ws_ni_search_aborted"));
1246 /** this function is called just before closing application;
1247 it sends signal to DBUS and destroys it;
1249 * @param widget - object which recived the signal
1251 * @param user_data - user data set when the signal handler was connected
1254 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
1256 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1257 ws_gui_app->bookmark_mode = FALSE;
1258 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1259 g_timer_destroy(ws_gui_app->timer);
1260 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1261 ws_dbus_destroy (ws_gui_app->dbus_data);
1262 ws_gui_free_memory(ws_gui_app);
1267 /** this function is called just before closing application,
1268 from application menu; it sends signal to DBUS and destroys it;
1270 * @param menuitem - object which recived the signal
1271 * @param user_data - user data set when the signal handler was connected
1274 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
1276 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
1277 ws_gui_app->bookmark_mode = FALSE;
1278 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1279 g_timer_destroy(ws_gui_app->timer);
1280 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
1281 ws_dbus_destroy (ws_gui_app->dbus_data);
1282 ws_gui_free_memory(ws_gui_app);
1287 /** fill translation area with text (html) recived from DBUS
1289 * @param html_context - text which is going to be displayed; it should be html
1290 * @param user_data - user data set when the function was called
1293 void ws_gui_fill_html(char *html_context, gpointer user_data)
1295 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
1296 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
1298 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
1303 /** read adjustment of left scrollwindow, which is necessary to navigate with
1304 arrow keys inside words list
1306 * @param user_data - user data set when the signal handler was connected
1309 void ws_gui_read_adjustment(gpointer user_data)
1311 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1313 ws_gui_app->ws_gui_hadj =
1314 gtk_scrolled_window_get_hadjustment(
1315 GTK_SCROLLED_WINDOW(
1316 ws_gui_app->ws_gui_scrolledwindow_left));
1318 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
1319 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
1321 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
1322 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
1324 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
1325 ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
1326 ws_gui_app->v_new_value =
1327 gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
1328 ws_gui_app->v_delta;
1330 gtk_container_set_focus_vadjustment(
1331 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
1332 gtk_scrolled_window_get_vadjustment(
1333 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
1337 /** allows to display image in html area
1339 * @param html - object which received a signal
1340 * @param url - url to the image
1341 * @param stream - html stream
1344 void ws_gui_url_requested (
1347 GtkHTMLStream *stream)
1351 if (url && !strncmp (url, "file:", 5)) {
1353 fd = open (url, O_RDONLY);
1357 buf = alloca (8192);
1358 while ((size = read (fd, buf, 8192)) > 0) {
1359 gtk_html_stream_write (stream, buf, size);
1361 gtk_html_stream_close(stream, size == -1
1362 ? GTK_HTML_STREAM_ERROR
1363 : GTK_HTML_STREAM_OK);
1370 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
1373 /** handles button press event and examines what kind of event was it
1376 * @param widget - object which received a signal
1377 * @param event - type of event which has been performed
1378 * @param user_data - user data set when the signal handler was connected
1379 * @return TRUE to stop other handlers from being invoked for the event.
1380 FALSE to propagate the event further
1382 gboolean ws_gui_button_press(GtkWidget *widget,
1383 GdkEventButton *event,
1386 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1387 if (ws_gui_app->ws_gui_sel_flag == FALSE)
1389 if (event->type == GDK_2BUTTON_PRESS)
1391 ws_gui_app->ws_gui_double_click = TRUE;
1392 g_timer_stop(ws_gui_app->timer);
1393 g_timer_reset(ws_gui_app->timer);
1397 g_signal_stop_emission_by_name(G_OBJECT(
1398 ws_gui_app->ws_gui_html),
1399 "button-press-event");
1400 g_timer_start(ws_gui_app->timer);
1401 gtk_timeout_add((guint)(PRESS_TIME*1000),
1402 (GtkFunction)(ws_gui_show_popup),
1408 ws_gui_app->ws_gui_sel_flag = FALSE;
1414 /** handles button release event and examines whether 'click' or 'tap and hold'
1415 event it supposed to be
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_release (GtkWidget *widget,
1424 GdkEventButton *event,
1427 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1428 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1429 g_timer_stop(ws_gui_app->timer);
1430 g_timer_reset(ws_gui_app->timer);
1431 if (ws_gui_app->ws_gui_double_click == TRUE)
1433 ws_gui_app->ws_gui_double_click = FALSE;
1436 else if (tmp < PRESS_TIME)
1438 struct _GtkHTML *tmp = (struct _GtkHTML *)
1439 (ws_gui_app->ws_gui_html);
1440 html_engine_unselect_all(tmp->engine);
1446 /** displays popup menu if user holds a stylus more than PRESS_TIME seconds
1448 * @param user_data - user data set when the signal handler was connected
1451 guint ws_gui_show_popup (gpointer user_data)
1453 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1454 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
1455 if (tmp > PRESS_TIME)
1457 ws_gui_create_popup_menu(ws_gui_app);
1459 return (guint)(FALSE);
1463 /** checks clipboard content and sets sensitivity of widgets
1465 * @param widget - object which recived a signal
1466 * @param user_data - user data set when the signal handler was connected
1469 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
1471 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1472 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
1474 gtk_widget_set_sensitive(
1475 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1480 gtk_widget_set_sensitive(
1481 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
1486 /** gets received string (with translation), formats it and sends it to be
1489 * @param received_string - content received from Manager
1490 * @param user_data - user data set when the function has been called
1493 gchar * format_html (gchar * received_string, gpointer user_data)
1495 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1498 str_final = g_string_new(received_string);
1499 str_tmp = g_string_new(received_string);
1503 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
1507 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
1509 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
1510 str_final = g_string_erase(str_final,
1511 (long)(tmp - str_final->str),
1513 str_final = g_string_insert(str_final,
1514 (long)(tmp - str_final->str),
1515 "<html><head></head><body><center><table width=\"400px\"><tr>"
1516 "<td><table border=1 width=100%><tr>"
1517 "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
1518 "<img align=left src=\"file:/usr/share/pixmaps/"
1519 "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
1521 //g_debug("\n\nws_gui_app->last_word %s", ws_gui_app->last_word);
1522 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
1523 if (ws_gui_app->last_word != NULL)
1525 str_tmp = g_string_erase(str_tmp,
1526 (long)(tmp2 - str_tmp->str),
1527 14 + strlen(ws_gui_app->last_word));
1529 //str_tmp = g_string_insert(str_tmp, "<br>", 0);
1532 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
1534 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
1535 str_final = g_string_erase(str_final,
1536 (long)(tmp - str_final->str),
1538 str_final = g_string_insert(str_final,
1539 (long)(tmp - str_final->str),
1540 "</font></th></tr></table>");
1542 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
1543 str_tmp = g_string_erase(str_tmp,
1544 (long)(tmp2 - str_tmp->str),
1548 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
1550 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
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 "<table border=1 width=100%><tr><td background=\"file:/usr/"
1557 "share/pixmaps/ws_tra.png\">");
1559 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
1560 str_tmp = g_string_erase(str_tmp,
1561 (long)(tmp2 - str_tmp->str),
1563 /*str_tmp = g_string_insert(str_tmp,
1564 (long)(tmp2 - str_tmp->str),
1569 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
1571 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
1572 str_final = g_string_erase(str_final,
1573 (long)(tmp - str_final->str),
1575 str_final = g_string_insert(str_final,
1576 (long)(tmp - str_final->str),
1577 "</td></tr></table></center>");
1579 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
1580 str_tmp = g_string_erase(str_tmp,
1581 (long)(tmp2 - str_tmp->str),
1586 str_final = g_string_append(str_final,
1587 "</td></tr></table></body></html>");
1589 ws_gui_app->raw_translation = g_string_insert(
1590 ws_gui_app->raw_translation,
1595 //ws_gui_app->raw_translation = g_string_append(str_final, "<br>");
1597 return str_final->str;
1600 /** open bookmarks database
1602 * @param menuitem - object which recived the signal
1603 * @param user_data - user data set when the signal handler was connected
1606 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1608 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1610 ws_gui_read_active_dictionaries(ws_gui_app);
1612 g_free(ws_gui_app->last_word);
1613 ws_gui_app->last_word = NULL;
1615 ws_gui_app->bookmark_mode = TRUE;
1616 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1617 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1621 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
1623 ws_gui_fill_html(" ", ws_gui_app);
1624 //ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
1625 ws_gui_search(NULL, ws_gui_app);
1629 /** closes bookmarks database
1631 * @param menuitem - object which recived the signal
1632 * @param user_data - user data set when the signal handler was connected
1635 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1637 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1639 ws_gui_read_active_dictionaries(ws_gui_app);
1641 g_free(ws_gui_app->last_word);
1642 ws_gui_app->last_word = NULL;
1644 ws_gui_app->bookmark_mode = FALSE;
1645 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
1646 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
1647 ws_gui_fill_html(" ", ws_gui_app);
1648 g_strstrip(ws_gui_app->last_searched);
1649 if (ws_gui_app->last_searched != NULL)
1651 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1653 ws_gui_app->last_searched,
1655 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1656 ws_gui_search(NULL, ws_gui_app);
1660 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1664 //ws_dbus_client_find_word(ws_gui_app->dbus_data, ws_gui_app->last_searched);
1665 ws_gui_search(NULL, ws_gui_app);
1669 /** adds bookmark to bookmarks database
1671 * @param menuitem - object which recived the signal
1672 * @param user_data - user data set when the signal handler was connected
1675 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
1677 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1679 if (ws_gui_app->last_word != NULL)
1681 ws_gui_add_bookmark_dialog(ws_gui_app);
1686 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1687 _("ws_ni_select_word_to_add"));
1693 /** removes bookmark from bookmarks database
1695 * @param menuitem - object which recived the signal
1696 * @param user_data - user data set when the signal handler was connected
1699 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
1702 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1704 if (ws_gui_app->last_word != NULL)
1706 ws_gui_remove_bookmark_dialog(ws_gui_app);
1709 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
1713 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
1719 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
1720 _("ws_ni_select_word_to_remove"));
1726 /** checks wheather dictionaries are available or not; according to the result
1727 * dimmes proper menuitem
1729 * @param menuitem - object which recived the signal
1730 * @param user_data - user data set when the signal handler was connected
1733 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
1735 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1736 if (gconf_client_dir_exists(ws_gui_app->client,
1737 GCONF_PATH, NULL) == TRUE)
1739 ws_gui_app->directories = gconf_client_all_dirs(
1746 if(g_slist_length(ws_gui_app->directories) != 0)
1748 gtk_widget_set_sensitive(GTK_WIDGET
1749 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1751 gtk_widget_set_sensitive(GTK_WIDGET
1752 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1754 gtk_widget_set_sensitive(GTK_WIDGET
1755 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1762 gtk_widget_set_sensitive(GTK_WIDGET
1763 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
1765 gtk_widget_set_sensitive(GTK_WIDGET
1766 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
1768 gtk_widget_set_sensitive(GTK_WIDGET
1769 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
1775 /** sets sensitivity of menu items due to bookmark's mode
1777 * @param user_data - user data set when the function was called
1780 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
1782 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1787 if (ws_gui_app->bookmark_mode == TRUE)
1789 g_slist_free(ws_gui_app->directories_last);
1790 ws_gui_app->directories_last = NULL;
1791 ws_gui_app->directories_last = g_slist_alloc();
1792 g_slist_free(ws_gui_app->directories);
1793 ws_gui_app->directories = g_slist_alloc();
1795 ws_gui_app->directories = gconf_client_all_dirs(
1799 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
1801 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
1802 name = g_path_get_basename(string);
1803 string = g_strconcat(string, "/active", NULL);
1805 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
1807 ws_gui_app->directories_last =
1808 g_slist_append(ws_gui_app->directories_last,
1812 if (strcmp(name, "bookmarks") == 0)
1814 gconf_client_set_bool(ws_gui_app->client,
1821 gconf_client_set_bool(ws_gui_app->client,
1828 //setting sensitivity of components
1829 gtk_widget_set_sensitive(
1830 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1832 gtk_widget_set_sensitive(
1833 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1835 gtk_widget_set_sensitive(
1836 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1838 gtk_widget_set_sensitive(
1839 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1841 gtk_widget_set_sensitive(
1842 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1847 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
1848 if (g_slist_length(ws_gui_app->directories_last) > 0)
1850 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
1853 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
1855 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
1858 //string = g_strconcat(string, "/active", NULL);
1861 gconf_client_set_bool(ws_gui_app->client,
1868 //setting sensitivity of components
1869 gtk_widget_set_sensitive(
1870 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
1872 gtk_widget_set_sensitive(
1873 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
1875 gtk_widget_set_sensitive(
1876 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1878 gtk_widget_set_sensitive(
1879 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1881 gtk_widget_set_sensitive(
1882 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
1887 /** sets sensitivity of menu items due to user selection made
1889 * @param user_data - user data set when the function was called
1892 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
1894 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1895 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
1897 gtk_widget_set_sensitive(
1898 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1903 gtk_widget_set_sensitive(
1904 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
1908 if (ws_gui_app->last_word == NULL || ws_gui_app->bookmark_mode == TRUE)
1910 gtk_widget_set_sensitive(
1911 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1916 gtk_widget_set_sensitive(
1917 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
1921 /** reads gconf entries and sets variables with a proper data; it is necessary
1922 * for changing the bookmarks mode
1924 * @param user_data - user data set when the function was called
1927 void ws_gui_read_active_dictionaries(gpointer user_data)
1929 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
1932 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,