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 ************************************************************************************************/
22 #include "../../include/ws_gui_callbacks.h"
23 #include "../../include/ws_gui.h"
24 #include "../../include/ws_gui_layout.h"
25 #include "../../include/ws_dbus.h"
27 /** \brief show how much time did take a callback of another function
30 static double timer(gboolean start, gchar* message)
32 static GArray* stack = NULL;
33 static gboolean first_run = TRUE;
34 static struct timeval actual_time;
35 static struct timeval last_time;
36 static struct timeval result;
37 static double seconds = 0.0;
41 //g_debug("XDXF->%s() - TOP OF THE STACK!\n",__FUNCTION__);
42 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
45 if (start) // things to do on the beggining of function's work
47 g_debug("XDXF->%s() start counting time for function '%s()'.\n",__FUNCTION__,message);
48 g_array_prepend_val(stack, actual_time);
49 gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
52 else { // we just want to end some timer - print some information about working time;
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 - actual_time.tv_usec) / 1000000 + 1;
59 last_time.tv_usec -= 1000000 * nsec;
60 last_time.tv_sec += nsec;
62 if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
63 int nsec = (last_time.tv_usec - actual_time.tv_usec) / 1000000;
64 last_time.tv_usec += 1000000 * nsec;
65 last_time.tv_sec -= nsec;
67 result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
68 result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
69 seconds = (((double)(result.tv_usec)) / 1e6) + ((double)(result.tv_sec));
71 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)));
72 if(stack->len == 0) // stack is empty so we delete everything
74 g_array_free(stack, TRUE);
87 /** this function handles signals from dbus; it is called when there are any messages from other modules
89 * @param error - error message recived from DBUS
90 * @param words - array with recived data structure
91 * @param user_data - pointer to data structure
94 void ws_gui_signal_hander (GError *error, GArray *words, gpointer user_data)
96 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
98 osss_data = g_array_index (words, osso_rpc_t, 0);
99 switch(osss_data.value.i)
101 case WS_DBUS_ERROR_ENGINE_NOT_FOUND:
103 ws_gui_app->ws_message_dialog = gtk_message_dialog_new (GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
104 GTK_DIALOG_DESTROY_WITH_PARENT,
108 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
110 g_signal_connect_swapped (GTK_OBJECT (ws_gui_app->ws_message_dialog), "response", G_CALLBACK (gtk_main_quit), ws_gui_app);
111 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. Engine not found");
115 case WS_DBUS_ERROR_FILE_NOT_FOUND:
117 ws_gui_app->ws_message_dialog = gtk_message_dialog_new (GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
118 GTK_DIALOG_DESTROY_WITH_PARENT,
121 "There is no dictionary file available");
123 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
124 //g_signal_connect_swapped (GTK_OBJECT (ws_gui_app->ws_message_dialog), "response", G_CALLBACK (gtk_main_quit), ws_gui_app);
127 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
128 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
129 ws_gui_app->ws_gui_w_list->ws_gui_model = create_and_fill_model(tmp, ws_gui_app);
130 ws_gui_fill_html(" ", ws_gui_app);
132 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar), FALSE);
133 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search), FALSE);
135 if (gtk_dialog_run (GTK_DIALOG (ws_gui_app->ws_message_dialog)) == GTK_RESPONSE_OK)
137 gtk_widget_destroy(ws_gui_app->ws_message_dialog);
143 case WS_DBUS_INFO_CACHING:
145 ws_gui_app->ws_gui_banner_caching = hildon_banner_show_progress(GTK_WIDGET(ws_gui_app->ws_gui_hildon_window), NULL, "caching ..." );
146 ws_gui_app->caching_flag = TRUE;
147 hildon_banner_set_fraction(HILDON_BANNER(ws_gui_app->ws_gui_banner_caching), 0.0);
148 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar), FALSE);
149 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search), FALSE);
153 case WS_DBUS_INFO_CACHING_FINISHED:
155 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
156 ws_gui_app->caching_flag = FALSE;
157 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar), TRUE);
158 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search), TRUE);
164 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
166 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
167 osso_rpc_t osss_data;
168 osss_data = g_array_index (words, osso_rpc_t, 0);
169 double progress = osss_data.value.d;
170 if (ws_gui_app->caching_flag == TRUE)
172 hildon_banner_set_fraction(HILDON_BANNER(ws_gui_app->ws_gui_banner_caching), progress);
176 /** this function handles signal from dbus and transfer recived (found in a dictionary) words to the words list
178 * @param error - error message recived from DBUS
179 * @param words - array with recived data structure
180 * @param user_data - pointer to data structure
183 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
185 timer(TIMER_START, (gchar*)__FUNCTION__);
190 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
193 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
196 for (i=0;i<words->len;++i)
198 data = g_array_index (words, osso_rpc_t, i);
199 tmp_word = g_strconcat(data.value.s,NULL);
200 //data = g_array_index (words, char *, i);
201 //tmp_word = g_strconcat(data,NULL);
202 g_array_append_val(tmp, tmp_word);
206 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner));
207 ws_gui_app->ws_gui_banner_flag = FALSE;
208 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop), FALSE);
209 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop), FALSE);
210 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
212 ws_gui_app->ws_gui_w_list->ws_gui_model = create_and_fill_model(tmp, ws_gui_app);
213 //gtk_html_set_editable(GTK_HTML(ws_gui_app->ws_gui_html), TRUE);
217 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "No words found" );
219 timer(TIMER_STOP, (gchar*)__FUNCTION__);
222 /** this function handles signal from dbus and send recived data to the translation area
224 * @param error - error message recived from DBUS
225 * @param words - array with recived data structure
226 * @param user_data - pointer to data structure
229 void ws_gui_dbus_return_translation (GError *error, GArray *words, gpointer user_data)
231 timer(TIMER_START, (gchar*)__FUNCTION__);
232 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
233 //g_printf("\n\n .::GUI::. User data in dbus_return_translation: %p\n\n", ws_gui_app);
237 data = g_array_index (words, osso_rpc_t, 0);
238 gtk_html_zoom_reset(GTK_HTML(ws_gui_app->ws_gui_html));
239 ws_gui_fill_html(data.value.s, ws_gui_app);
241 timer(TIMER_STOP, (gchar*)__FUNCTION__);
245 * this function allows to free allocated memory
247 * @param user_data - pointer to data structure
249 void ws_gui_free_memory(gpointer user_data)
251 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
252 g_array_free(ws_gui_app->ws_gui_history, TRUE);
253 g_free(ws_gui_app->ws_gui_w_list);
254 g_free(ws_gui_app->ws_gui_menu);
258 /** this function handle press signals (keyboard)
262 * @param user_data - ponter to data structure
263 * @return TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
265 gboolean hildon_key_press_listener (GtkWidget * widget, GdkEventKey * keyevent, gpointer user_data)
267 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
268 //g_printf("\nKey code: Enter=%d, passede=%d", GDK_Return,(keyevent->keyval));
269 switch ((guint)(keyevent->keyval)) {
272 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)));
273 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
274 if (ws_gui_app->v_new_value > ws_gui_app->ws_gui_vadj->lower)
276 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj), ws_gui_app->v_new_value);
281 case GDK_Down: //down
283 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)));
284 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) + ws_gui_app->v_delta;
285 if (ws_gui_app->v_new_value < (ws_gui_app->ws_gui_vadj->upper - ws_gui_app->ws_gui_vadj->page_size))
287 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj), ws_gui_app->v_new_value);
292 case GDK_Left: //left
294 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)));
295 ws_gui_app->h_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) - ws_gui_app->h_delta;
296 if (ws_gui_app->h_new_value > ws_gui_app->ws_gui_hadj->lower)
298 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj), ws_gui_app->h_new_value);
303 case GDK_Right: //right
305 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)));
306 ws_gui_app->h_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj)) + ws_gui_app->h_delta;
307 if (ws_gui_app->h_new_value < (ws_gui_app->ws_gui_hadj->upper - ws_gui_app->ws_gui_hadj->page_size))
309 gtk_adjustment_set_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj), ws_gui_app->h_new_value);
314 case GDK_Return: /*start search*/
315 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. Return");
316 ws_gui_search(NULL, ws_gui_app);
319 case GDK_F6: //FULL SCREEN
320 ws_gui_full_screen(NULL, ws_gui_app);
323 case GDK_F7: //zoom in, f7
324 ws_gui_html_zoom_in(NULL, ws_gui_app);
327 case GDK_F8://zoom out, f8
328 ws_gui_html_zoom_out(NULL, ws_gui_app);
331 case GDK_Escape: //escape
332 ws_gui_search_stop(NULL, ws_gui_app);
335 case GDK_BackSpace: //backspace
346 /** this function allow to hide words list using menu item from application menu
348 * @param checkmenuitem - the object which received the signal
349 * @param user_data - user data set when the signal handler was connected
352 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
354 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
355 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
357 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
358 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), TRUE);
359 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), TRUE);
363 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
364 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), FALSE);
365 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), FALSE);
369 /** this function allow to hide words list using toggle button placed in the find toolbar
371 * @param toolbar - the object which received the signal
372 * @param user_data - user data set when the signal handler was connected
375 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
377 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
378 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
380 gtk_widget_hide(ws_gui_app->ws_gui_scrolledwindow_left);
381 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), TRUE);
382 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), TRUE);
386 gtk_widget_show(ws_gui_app->ws_gui_scrolledwindow_left);
387 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide), FALSE);
388 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list), FALSE);
392 /** add word to the history
394 * @param new_word - word which is going to be append to the history array
395 * @param user_data - user data set when the signal handler was connected
398 void ws_gui_history_add(char *new_word, gpointer user_data)
401 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
404 i = ws_gui_app->ws_gui_history_cur_pos + 1;
405 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
409 g_array_remove_index(ws_gui_app->ws_gui_history, i);
410 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
414 ws_gui_app->ws_gui_history_cur_pos ++;
416 tmp_word = g_strdup(new_word);
417 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
418 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
420 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
421 ws_gui_app->ws_gui_history_cur_pos--;
425 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
427 ws_gui_check_history(ws_gui_app);
430 /** display previously choosen word (previous from the history array) if avaible, sets current position in the history array
432 * @param button - button which recived a signal
433 * @param user_data - user data set when the signal handler was connected
436 void ws_gui_history_back(GtkButton *button, gpointer user_data)
438 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
440 if (ws_gui_app->ws_gui_history_cur_pos > 0) {
441 ws_gui_app->ws_gui_history_cur_pos = ws_gui_app->ws_gui_history_cur_pos - 1;
442 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)));
446 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "no words in the history" );
447 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), FALSE);
448 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), FALSE);
451 ws_gui_check_history(ws_gui_app);
455 /** display choosen word, next in the history array (if avaible), sets current position in the history array
457 * @param button - button which recived a signal
458 * @param user_data - user data set when the signal handler was connected
461 void ws_gui_history_next(GtkButton *button, gpointer user_data)
463 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
465 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos+1);
467 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1) && (tmp != NULL))
469 ws_gui_app->ws_gui_history_cur_pos = ws_gui_app->ws_gui_history_cur_pos + 1;
470 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)));
474 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "end of history" );
475 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), FALSE);
476 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), FALSE);
479 ws_gui_check_history(ws_gui_app);
482 /** check current position in the history array and sets sensitivity of buttons / menu items, depends on availablity of words in the history
484 * @param user_data - user data set when the signal handler was connected
487 void ws_gui_check_history(gpointer user_data)
489 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
491 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos+1);
493 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN) && (tmp != NULL))
495 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), TRUE);
496 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), TRUE);
500 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward), FALSE);
501 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next), FALSE);
504 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, ws_gui_app->ws_gui_history_cur_pos-1);
505 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
507 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), TRUE);
508 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), TRUE);
512 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back), FALSE);
513 gtk_widget_set_sensitive (GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev), FALSE);
517 /** create TreeView Model, which allows to display words list
519 * @param words_list - array with words(found in a dictionary), recived from DBUS;
520 * @param user_data - user data set when the signal handler was connected
523 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
525 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
527 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
529 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);
531 /* Append a row and fill in some data */
534 //tmp2 = g_utf8_normalize(tmp, strlen(tmp), G_NORMALIZE_ALL);
535 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store, &ws_gui_app->ws_gui_w_list->ws_gui_iter);
536 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);
538 tmp = g_strdup(g_array_index(words_list, gchar*, i));
541 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
544 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
545 ws_gui_history_add(tmp, ws_gui_app);
548 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
551 /** create TreeView and TreeModel using create_and_fill_model() function; it is necessary to display found words in a words list;
553 * @param words_list - array with words(found in a dictionary), recived from DBUS;
554 * @param user_data - user data set when the signal handler was connected
557 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
559 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
561 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
563 ws_gui_app->ws_gui_w_list->ws_gui_renderer = gtk_cell_renderer_text_new ();
564 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);
566 ws_gui_app->ws_gui_w_list->ws_gui_model = create_and_fill_model (words_list, ws_gui_app);
568 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);
570 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
571 return ws_gui_app->ws_gui_w_list->ws_gui_view;
574 /** handle signal from words list, get selected word and calls 'find translation' function
576 * @param selection - the object which received the signal
577 * @param user_data - user data set when the signal handler was connected
580 void ws_gui_tree_selection_changed(GtkTreeSelection *selection, gpointer user_data)
582 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
585 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))
587 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);
589 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
591 ws_gui_history_add(string, ws_gui_app);
599 /** switch application between fun screen and normal mode
601 * @param menuitem - object which recived the signal
602 * @param user_data - user data set when the signal handler was connected
605 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
608 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
609 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
611 gtk_window_fullscreen(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
612 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen), TRUE);
613 ws_gui_app->ws_gui_full_screen_flag = TRUE;
617 gtk_window_unfullscreen(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
618 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen), FALSE);
619 ws_gui_app->ws_gui_full_screen_flag = FALSE;
623 /** select whole text in the translation (html) area
625 * @param menuitem - object which recived the signal
626 * @param user_data - user data set when the signal handler was connected
629 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
631 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
632 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
635 /** copy selected text to the clipoard from context popup menu
637 * @param menuitem - object which recived the signal
638 * @param user_data - user data set when the signal handler was connected
641 void ws_gui_html_copy_popup(GtkMenuItem *menuitem, gpointer user_data)
643 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
645 /*gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
646 //ws_gui_app->ws_gui_clipboard = gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html), GDK_SELECTION_CLIPBOARD);
647 gtk_clipboard_request_contents(ws_gui_app->ws_gui_clipboard, GDK_SELECTION_TYPE_STRING, selection_received, ws_gui_app);
648 if (ws_gui_app->selection_data != NULL)
650 gtk_clipboard_store(ws_gui_app->ws_gui_clipboard);
651 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "COPY --- Selection != NULL");
654 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. COPY --- In clipboard we have: \"%s\"", gtk_clipboard_wait_for_text (ws_gui_app->ws_gui_clipboard));*/
655 gtk_clipboard_request_contents(ws_gui_app->ws_gui_clipboard_primary, GDK_SELECTION_TYPE_STRING, selection_received, ws_gui_app);
656 ws_gui_app->ws_gui_clipboard_primary = gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html), GDK_SELECTION_PRIMARY);
657 tmp = gtk_clipboard_wait_for_text (ws_gui_app->ws_gui_clipboard_primary);
660 gtk_clipboard_set_text(ws_gui_app->ws_gui_clipboard, tmp, strlen(tmp));
662 gtk_clipboard_store(ws_gui_app->ws_gui_clipboard);
665 /** copy selected text to the clipoard from context popup menu
667 * @param menuitem - object which recived the signal
668 * @param user_data - user data set when the signal handler was connected
671 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
673 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
675 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
680 /** paste copied text into toolbar entry
682 * @param menuitem - object which recived the signal
683 * @param user_data - user data set when the signal handler was connected
686 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
688 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
690 gtk_clipboard_request_contents(ws_gui_app->ws_gui_clipboard, GDK_SELECTION_CLIPBOARD, selection_received, ws_gui_app);
693 //gtk_editable_paste_clipboard (GTK_EDITABLE(ws_gui_app->ws_gui_hildon_find_toolbar));
696 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
697 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. PASTE --- In clipboard we have: \"%s\"", temp);
698 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. Paste: %s", temp);
699 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar), "prefix", &temp2, NULL);
700 temp = g_strconcat(temp2, temp, NULL);
701 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar), "prefix", temp, NULL);
702 //gtk_html_paste(GTK_HTML(ws_gui_app->ws_gui_html), TRUE);
705 /** zoom in text in translation (html) area
707 * @param menuitem - object which recived the signal
708 * @param user_data - user data set when the signal handler was connected
711 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
713 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
714 gtk_html_zoom_in(GTK_HTML(ws_gui_app->ws_gui_html));
717 /** zoom out text in translation (html) area
719 * @param menuitem - object which recived the signal
720 * @param user_data - user data set when the signal handler was connected
723 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
725 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
726 gtk_html_zoom_out(GTK_HTML(ws_gui_app->ws_gui_html));
729 /** start searching, send typed word to DBUS and query for words
731 * @param widget - object which recived the signal
732 * @param user_data - user data set when the signal handler was connected
735 void ws_gui_search(GtkWidget * widget, gpointer user_data)
737 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
738 gchar* ws_gui_text = NULL;
741 if (ws_gui_app->ws_gui_banner_flag == TRUE) {
742 ws_gui_app->ws_gui_banner_flag = FALSE;
745 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar), "prefix", &ws_gui_text, NULL);
747 if (strlen(ws_gui_text) != 0)
749 ws_gui_app->ws_gui_banner = hildon_banner_show_animation(GTK_WIDGET(ws_gui_app->ws_gui_hildon_window), NULL, "searching ..." );
751 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),TRUE);
752 gtk_widget_set_sensitive(GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_stop), TRUE);
754 ws_gui_app->ws_gui_banner_flag = TRUE;
755 ws_gui_fill_html(empty, ws_gui_app);
756 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
759 else gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "No word typed.");
763 /** stop search process
765 * @param button - object which recived the signal
766 * @param user_data - user data set when the signal handler was connected
769 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
771 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
772 if (ws_gui_app->ws_gui_banner_flag == TRUE)
774 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->ws_gui_banner));
775 ws_gui_app->ws_gui_banner_flag = FALSE;
776 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
777 gtk_infoprint(GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), "Search has been aborted" );
782 /** this function is called just before closing application; it sends signal to DBUS and destroys it;
784 * @param widget - object which recived the signal
786 * @param user_data - user data set when the signal handler was connected
789 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
791 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
792 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
793 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\nClosing WhiteStork Dictionary ... \n\n");
794 ws_dbus_destroy (ws_gui_app->dbus_data);
795 ws_gui_free_memory(ws_gui_app);
800 /** this function is called just before closing application, from application menu; it sends signal to DBUS and destroys it;
802 * @param menuitem - object which recived the signal
803 * @param user_data - user data set when the signal handler was connected
806 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
808 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
809 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
810 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\nClosing WhiteStork Dictionary ... \n\n");
811 ws_dbus_destroy (ws_gui_app->dbus_data);
812 ws_gui_free_memory(ws_gui_app);
817 /** fill translation area with text (html) recived from DBUS
819 * @param html_context - text which is going to be displayed; it should be html;
820 * @param user_data - user data set when the function was called
823 void ws_gui_fill_html(char *html_context, gpointer user_data)
825 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
826 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
828 gtk_html_load_from_string (GTK_HTML(ws_gui_app->ws_gui_html), html_context, -1);
829 //gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), TRUE);
832 /** read adjustment of left scrollwindow, which is necessary to navigate with arrow keys inside words list
834 * @param user_data - user data set when the signal handler was connected
837 void ws_gui_read_adjustment(gpointer user_data)
839 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
841 ws_gui_app->ws_gui_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
843 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper - ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
845 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
847 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper - ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
848 ws_gui_app->v_new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) + ws_gui_app->v_delta;
850 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)));
854 void ws_gui_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *stream)
858 if (url && !strncmp (url, "file:", 5)) {
860 fd = open (url, O_RDONLY);
867 while ((size = read (fd, buf, 8192)) > 0) {
868 gtk_html_stream_write (stream, buf, size);
870 gtk_html_stream_close (stream,
872 ? GTK_HTML_STREAM_ERROR
873 : GTK_HTML_STREAM_OK);
880 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
883 //gboolean button (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
884 gboolean button (GtkWidget *widget, gpointer user_data)
886 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
887 //html_engine_block_selection(GTK_HTML(ws_gui_app->ws_gui_html));
888 //html_engine_select_region(GTK_HTML(ws_gui_app->ws_gui_html), 0, 0, 50, 50);
889 gtk_clipboard_request_contents(ws_gui_app->ws_gui_clipboard_primary, GDK_SELECTION_TYPE_STRING, selection_received, ws_gui_app);
891 //ws_gui_app->ws_gui_clipboard_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
892 /*gchar *tmp = gtk_clipboard_wait_for_text (ws_gui_app->ws_gui_clipboard_primary);
895 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
896 gtk_clipboard_store(ws_gui_app->ws_gui_clipboard_primary);
898 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. is_selection_active: %b", html_engine_is_selection_active(GTK_HTML(ws_gui_app->ws_gui_html)));
899 ws_gui_html_copy_popup(NULL, ws_gui_app);
905 void selection_received (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer user_data)
907 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
908 ws_gui_app->selection_data = gtk_selection_data_copy(selection_data);
909 //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ".::GUI::. selection");