2 * Copyright 2006, ComArch S.A
6 #include "../../include/ws_gui_callbacks.h"
7 #include "../../include/ws_gui.h"
8 #include "../../include/ws_gui_layout.h"
9 #include "../../include/ws_dbus.h"
11 /** \brief show how much time did take a callback of another function
14 static double timer(gboolean start, gchar* message)
16 static GArray* stack = NULL;
17 static gboolean first_run = TRUE;
18 static struct timeval actual_time;
19 static struct timeval last_time;
20 static struct timeval result;
21 static double seconds = 0.0;
25 //g_debug("XDXF->%s() - TOP OF THE STACK!\n",__FUNCTION__);
26 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
29 if (start) // things to do on the beggining of function's work
31 g_debug("XDXF->%s() start counting time for function '%s()'.\n",__FUNCTION__,message);
32 g_array_prepend_val(stack, actual_time);
33 gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
36 else { // we just want to end some timer - print some information about working time;
37 gettimeofday(&actual_time,NULL);
38 last_time = g_array_index(stack, struct timeval, 0);
39 g_array_remove_index(stack, 0);
41 if (actual_time.tv_usec < last_time.tv_usec) {
42 int nsec = (last_time.tv_usec - actual_time.tv_usec) / 1000000 + 1;
43 last_time.tv_usec -= 1000000 * nsec;
44 last_time.tv_sec += nsec;
46 if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
47 int nsec = (last_time.tv_usec - actual_time.tv_usec) / 1000000;
48 last_time.tv_usec += 1000000 * nsec;
49 last_time.tv_sec -= nsec;
51 result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
52 result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
53 seconds = (((double)(result.tv_usec)) / 1e6) + ((double)(result.tv_sec));
55 g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] or %ld [us].\n",__FUNCTION__,message,seconds,((long)(result.tv_sec*1e6)+(result.tv_usec)));
56 if(stack->len == 0) // stack is empty so we delete everything
58 g_array_free(stack, TRUE);
71 /** this function handles signals from dbus; it is called when there are any messages from other modules
73 * @param error - error message recived from DBUS
74 * @param words - array with recived data structure
75 * @param user_data - pointer to data structure
78 void ws_gui_signal_hander (GError *error, GArray *words, gpointer user_data)
80 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
82 osss_data = g_array_index (words, osso_rpc_t, 0);
83 switch(osss_data.value.i)
85 case WS_DBUS_ERROR_ENGINE_NOT_FOUND:
87 ws_gui_app->ws_message_dialog = gtk_message_dialog_new (GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
88 GTK_DIALOG_DESTROY_WITH_PARENT,
92 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
94 g_signal_connect_swapped (GTK_OBJECT (ws_gui_app->ws_message_dialog), "response", G_CALLBACK (gtk_main_quit), ws_gui_app);
95 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. Engine not found");
99 case WS_DBUS_ERROR_FILE_NOT_FOUND:
101 ws_gui_app->ws_message_dialog = gtk_message_dialog_new (GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
102 GTK_DIALOG_DESTROY_WITH_PARENT,
105 "There is no dictionary file available");
107 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
108 g_signal_connect_swapped (GTK_OBJECT (ws_gui_app->ws_message_dialog), "response", G_CALLBACK (gtk_main_quit), ws_gui_app);
112 case WS_DBUS_INFO_CACHING:
114 ws_gui_app->ws_gui_banner_caching = hildon_banner_show_animation(GTK_WIDGET(ws_gui_app->ws_gui_hildon_window), NULL, "caching ..." );
115 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar), FALSE);
116 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search), FALSE);
120 case WS_DBUS_INFO_CACHING_FINISHED:
122 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
123 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar), TRUE);
124 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search), TRUE);
130 /** this function handles signal from dbus and transfer recived (found in a dictionary) words to the words list
132 * @param error - error message recived from DBUS
133 * @param words - array with recived data structure
134 * @param user_data - pointer to data structure
137 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
139 timer(TIMER_START, (gchar*)__FUNCTION__);
144 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
147 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
150 for (i=0;i<words->len;++i)
152 data = g_array_index (words, osso_rpc_t, i);
153 tmp_word = g_strconcat(data.value.s,NULL);
154 //data = g_array_index (words, char *, i);
155 //tmp_word = g_strconcat(data,NULL);
156 g_array_append_val(tmp, tmp_word);
160 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner));
161 ws_gui_app->ws_gui_banner_flag = FALSE;
162 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop), FALSE);
163 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop), FALSE);
164 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
166 ws_gui_app->ws_gui_w_list->ws_gui_model = create_and_fill_model(tmp, ws_gui_app);
170 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "No words found" );
172 timer(TIMER_STOP, (gchar*)__FUNCTION__);
175 /** this function handles signal from dbus and send recived data to the translation area
177 * @param error - error message recived from DBUS
178 * @param words - array with recived data structure
179 * @param user_data - pointer to data structure
182 void ws_gui_dbus_return_translation (GError *error, GArray *words, gpointer user_data)
184 timer(TIMER_START, (gchar*)__FUNCTION__);
185 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
186 //g_printf("\n\n .::GUI::. User data in dbus_return_translation: %p\n\n", ws_gui_app);
191 data = g_array_index (words, osso_rpc_t, 0);
192 ws_gui_fill_html(data.value.s, ws_gui_app);
195 timer(TIMER_STOP, (gchar*)__FUNCTION__);
199 * this function allows to free allocated memory
201 * @param user_data - pointer to data structure
203 void ws_gui_free_memory(gpointer user_data)
205 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
206 g_array_free(ws_gui_app->ws_gui_history, TRUE);
207 g_free(ws_gui_app->ws_gui_w_list);
208 g_free(ws_gui_app->ws_gui_menu);
212 /** this function handle press signals (keyboard)
216 * @param user_data - ponter to data structure
217 * @return TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
219 gboolean hildon_key_press_listener (GtkWidget * widget, GdkEventKey * keyevent, gpointer user_data)
221 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
222 // g_printf("\nKey code: Enter=%d, passede=%d", GDK_Return,(keyevent->keyval));
223 switch ((guint)(keyevent->keyval)) {
226 gtk_container_set_focus_vadjustment(GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
227 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
228 if (ws_gui_app->v_new_value > ws_gui_app->ws_gui_vadj->lower)
230 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj), ws_gui_app->v_new_value);
235 case GDK_Down: //down
237 gtk_container_set_focus_vadjustment(GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
238 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) + ws_gui_app->v_delta;
239 if (ws_gui_app->v_new_value < (ws_gui_app->ws_gui_vadj->upper - ws_gui_app->ws_gui_vadj->page_size))
241 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj), ws_gui_app->v_new_value);
246 case GDK_Left: //left
248 gtk_container_set_focus_hadjustment(GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
249 ws_gui_app->h_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) - ws_gui_app->h_delta;
250 if (ws_gui_app->h_new_value > ws_gui_app->ws_gui_hadj->lower)
252 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj), ws_gui_app->h_new_value);
257 case GDK_Right: //right
259 gtk_container_set_focus_hadjustment(GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
260 ws_gui_app->h_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) + ws_gui_app->h_delta;
261 if (ws_gui_app->h_new_value < (ws_gui_app->ws_gui_hadj->upper - ws_gui_app->ws_gui_hadj->page_size))
263 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj), ws_gui_app->h_new_value);
268 case GDK_Return: /*start search*/
269 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. Return");
270 ws_gui_search(NULL, ws_gui_app);
273 case GDK_F6: //FULL SCREEN
274 ws_gui_full_screen(NULL, ws_gui_app);
277 case GDK_F7: //zoom in, f7
278 ws_gui_html_zoom_in(NULL, ws_gui_app);
281 case GDK_F8://zoom out, f8
282 ws_gui_html_zoom_out(NULL, ws_gui_app);
285 case GDK_Escape: //escape
286 ws_gui_search_stop(NULL, ws_gui_app);
289 case GDK_BackSpace: //backspace
300 /** this function allow to hide words list using menu item from application menu
302 * @param checkmenuitem - the object which received the signal
303 * @param user_data - user data set when the signal handler was connected
306 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
308 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
309 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
311 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
312 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), TRUE);
313 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), TRUE);
317 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
318 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), FALSE);
319 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), FALSE);
323 /** this function allow to hide words list using toggle button placed in the find toolbar
325 * @param toolbar - the object which received the signal
326 * @param user_data - user data set when the signal handler was connected
329 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
331 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
332 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
334 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
335 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), TRUE);
336 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), TRUE);
340 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
341 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), FALSE);
342 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), FALSE);
346 /** add word to the history
348 * @param new_word - word which is going to be append to the history array
349 * @param user_data - user data set when the signal handler was connected
352 void ws_gui_history_add(char *new_word, gpointer user_data)
355 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
358 i = ws_gui_app->ws_gui_history_cur_pos + 1;
359 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
363 g_array_remove_index(ws_gui_app->ws_gui_history, i);
364 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
368 ws_gui_app->ws_gui_history_cur_pos ++;
370 tmp_word = g_strdup(new_word);
371 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
372 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
374 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
375 ws_gui_app->ws_gui_history_cur_pos--;
379 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
381 ws_gui_check_history(ws_gui_app);
384 /** display previously choosen word (previous from the history array) if avaible, sets current position in the history array
386 * @param button - button which recived a signal
387 * @param user_data - user data set when the signal handler was connected
390 void ws_gui_history_back(GtkButton *button, gpointer user_data)
392 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
394 if (ws_gui_app->ws_gui_history_cur_pos > 0) {
395 ws_gui_app->ws_gui_history_cur_pos = ws_gui_app->ws_gui_history_cur_pos - 1;
396 ws_dbus_client_find_translation(ws_gui_app->dbus_data, (g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos)));
400 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "no words in the history" );
401 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), FALSE);
402 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), FALSE);
405 ws_gui_check_history(ws_gui_app);
409 /** display choosen word, next in the history array (if avaible), sets current position in the history array
411 * @param button - button which recived a signal
412 * @param user_data - user data set when the signal handler was connected
415 void ws_gui_history_next(GtkButton *button, gpointer user_data)
417 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
419 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos+1);
421 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1) && (tmp != NULL))
423 ws_gui_app->ws_gui_history_cur_pos = ws_gui_app->ws_gui_history_cur_pos + 1;
424 ws_dbus_client_find_translation(ws_gui_app->dbus_data, (g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos)));
428 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "end of history" );
429 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), FALSE);
430 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), FALSE);
433 ws_gui_check_history(ws_gui_app);
436 /** check current position in the history array and sets sensitivity of buttons / menu items, depends on availablity of words in the history
438 * @param user_data - user data set when the signal handler was connected
441 void ws_gui_check_history(gpointer user_data)
443 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
445 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos+1);
447 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN) && (tmp != NULL))
449 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), TRUE);
450 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), TRUE);
454 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), FALSE);
455 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), FALSE);
458 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos-1);
459 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
461 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), TRUE);
462 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), TRUE);
466 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), FALSE);
467 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), FALSE);
471 /** create TreeView Model, which allows to display words list
473 * @param words_list - array with words(found in a dictionary), recived from DBUS;
474 * @param user_data - user data set when the signal handler was connected
477 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
479 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
481 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
484 valid =gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store), &ws_gui_app->ws_gui_w_list->ws_gui_iter);
486 /* Append a row and fill in some data */
489 //tmp2 = g_utf8_normalize(tmp, strlen(tmp), G_NORMALIZE_ALL);
490 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store, &ws_gui_app->ws_gui_w_list->ws_gui_iter);
491 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store, &ws_gui_app->ws_gui_w_list->ws_gui_iter, COL_WORD, tmp, -1);
493 tmp = g_strdup(g_array_index(words_list, gchar*, i));
496 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
499 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
500 ws_gui_history_add(tmp, ws_gui_app);
503 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
506 /** create TreeView and TreeModel using create_and_fill_model() function; it is necessary to display found words in a words list;
508 * @param words_list - array with words(found in a dictionary), recived from DBUS;
509 * @param user_data - user data set when the signal handler was connected
512 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
514 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
516 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
518 ws_gui_app->ws_gui_w_list->ws_gui_renderer = gtk_cell_renderer_text_new ();
519 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view), -1, "Name", ws_gui_app->ws_gui_w_list->ws_gui_renderer, "text", COL_WORD, NULL);
521 ws_gui_app->ws_gui_w_list->ws_gui_model = create_and_fill_model (words_list, ws_gui_app);
523 gtk_tree_view_set_model (GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view), ws_gui_app->ws_gui_w_list->ws_gui_model);
525 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
526 return ws_gui_app->ws_gui_w_list->ws_gui_view;
529 /** handle signal from words list, get selected word and calls 'find translation' function
531 * @param selection - the object which received the signal
532 * @param user_data - user data set when the signal handler was connected
535 void ws_gui_tree_selection_changed(GtkTreeSelection *selection, gpointer user_data)
537 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
540 if (gtk_tree_selection_get_selected (selection, &ws_gui_app->ws_gui_w_list->ws_gui_model, &ws_gui_app->ws_gui_w_list->ws_gui_iter))
542 gtk_tree_model_get (ws_gui_app->ws_gui_w_list->ws_gui_model, &ws_gui_app->ws_gui_w_list->ws_gui_iter, COL_WORD, &string, -1);
544 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
546 ws_gui_history_add(string, ws_gui_app);
554 /** switch application between fun screen and normal mode
556 * @param menuitem - object which recived the signal
557 * @param user_data - user data set when the signal handler was connected
560 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
563 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
564 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
566 gtk_window_fullscreen(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
567 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen), TRUE);
568 ws_gui_app->ws_gui_full_screen_flag = TRUE;
572 gtk_window_unfullscreen(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
573 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen), FALSE);
574 ws_gui_app->ws_gui_full_screen_flag = FALSE;
578 /** select whole text in the translation (html) area
580 * @param menuitem - object which recived the signal
581 * @param user_data - user data set when the signal handler was connected
584 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
586 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
587 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
590 /** copy selected text to the clipoard
592 * @param menuitem - object which recived the signal
593 * @param user_data - user data set when the signal handler was connected
596 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
598 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
599 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
603 /** zoom in text in translation (html) area
605 * @param menuitem - object which recived the signal
606 * @param user_data - user data set when the signal handler was connected
609 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
611 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
612 gtk_html_zoom_in(GTK_HTML(ws_gui_app->ws_gui_html));
615 /** zoom out text in translation (html) area
617 * @param menuitem - object which recived the signal
618 * @param user_data - user data set when the signal handler was connected
621 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
623 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
624 gtk_html_zoom_out(GTK_HTML(ws_gui_app->ws_gui_html));
627 /** start searching, send typed word to DBUS and query for words
629 * @param widget - object which recived the signal
630 * @param user_data - user data set when the signal handler was connected
633 void ws_gui_search(GtkWidget * widget, gpointer user_data)
635 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
636 gchar* ws_gui_text = NULL;
639 if (ws_gui_app->ws_gui_banner_flag == TRUE) {
640 ws_gui_app->ws_gui_banner_flag = FALSE;
643 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar), "prefix", &ws_gui_text, NULL);
645 if (strlen(ws_gui_text) != 0)
647 ws_gui_app->ws_gui_banner = hildon_banner_show_animation(GTK_WIDGET(ws_gui_app->ws_gui_hildon_window), NULL, "searching ..." );
649 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),TRUE);
650 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop), TRUE);
652 ws_gui_app->ws_gui_banner_flag = TRUE;
653 ws_gui_fill_html(empty, ws_gui_app);
654 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
657 else gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "No word typed.");
662 /** stop search process
664 * @param button - object which recived the signal
665 * @param user_data - user data set when the signal handler was connected
668 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
670 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
671 if (ws_gui_app->ws_gui_banner_flag == TRUE)
673 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner));
674 ws_gui_app->ws_gui_banner_flag = FALSE;
675 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
676 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "Search has been aborted" );
681 /** this function is called just before closing application; it sends signal to DBUS and destroys it;
683 * @param widget - object which recived the signal
685 * @param user_data - user data set when the signal handler was connected
688 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
690 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
691 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
692 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\nClosing WhiteStork Dictionary ... \n\n");
693 ws_dbus_destroy (ws_gui_app->dbus_data);
698 /** this function is called just before closing application, from application menu; it sends signal to DBUS and destroys it;
700 * @param menuitem - object which recived the signal
701 * @param user_data - user data set when the signal handler was connected
704 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
706 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
707 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
708 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\nClosing WhiteStork Dictionary ... \n\n");
709 ws_dbus_destroy (ws_gui_app->dbus_data);
714 /** fill translation area with text (html) recived from DBUS
716 * @param html_context - text which is going to be displayed; it should be html;
717 * @param user_data - user data set when the function was called
720 void ws_gui_fill_html(char *html_context, gpointer user_data)
722 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
723 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
724 gtk_html_load_from_string (GTK_HTML(ws_gui_app->ws_gui_html), html_context, -1);
725 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), TRUE);
729 /** read adjustment of left scrollwindow, which is necessary to navigate with arrow keys inside words list
731 * @param user_data - user data set when the signal handler was connected
734 void ws_gui_read_adjustment(gpointer user_data)
736 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
738 ws_gui_app->ws_gui_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
740 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper - ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
742 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
744 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper - ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
745 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) + ws_gui_app->v_delta;
747 gtk_container_set_focus_vadjustment(GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left), gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
751 void ws_gui_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *stream)
755 if (url && !strncmp (url, "file:", 5)) {
757 fd = open (url, O_RDONLY);
764 while ((size = read (fd, buf, 8192)) > 0) {
765 gtk_html_stream_write (stream, buf, size);
767 gtk_html_stream_close (stream,
769 ? GTK_HTML_STREAM_ERROR
770 : GTK_HTML_STREAM_OK);
777 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);