00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00032 #include <ws_gui_callbacks.h>
00033 #include <ws_gui.h>
00034 #include <ws_gui_layout.h>
00035 #include <ws_dbus.h>
00036
00040 static double timer(gboolean start, gchar* message)
00041 {
00042 static GArray* stack = NULL;
00043 static gboolean first_run = TRUE;
00044 static struct timeval actual_time;
00045 static struct timeval last_time;
00046 static struct timeval result;
00047 static double seconds = 0.0;
00048 if(first_run)
00049 {
00050 first_run = FALSE;
00051 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
00052 };
00053
00054 if (start)
00055 {
00056 g_debug("XDXF->%s() start counting time for function '%s()'.\n",
00057 __FUNCTION__,message);
00058 g_array_prepend_val(stack, actual_time);
00059 gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
00060 return -1.0;
00061 }
00062
00063
00064 else {
00065 gettimeofday(&actual_time,NULL);
00066 last_time = g_array_index(stack, struct timeval, 0);
00067 g_array_remove_index(stack, 0);
00068
00069 if (actual_time.tv_usec < last_time.tv_usec) {
00070 int nsec = (last_time.tv_usec -
00071 actual_time.tv_usec) / 1000000 + 1;
00072 last_time.tv_usec -= 1000000 * nsec;
00073 last_time.tv_sec += nsec;
00074 }
00075 if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
00076 int nsec = (last_time.tv_usec -
00077 actual_time.tv_usec) / 1000000;
00078 last_time.tv_usec += 1000000 * nsec;
00079 last_time.tv_sec -= nsec;
00080 }
00081 result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
00082 result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
00083 seconds = (((double)(result.tv_usec)) / 1e6) +
00084 ((double)(result.tv_sec));
00085
00086 g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] "
00087 "or %ld [us].\n",
00088 __FUNCTION__,
00089 message,seconds,
00090 ((long)(result.tv_sec*1e6)+(result.tv_usec)));
00091
00092 if(stack->len == 0)
00093 {
00094 g_array_free(stack, TRUE);
00095 first_run = TRUE;
00096 }
00097 return seconds;
00098 }
00099 return -2.0;
00100 }
00101
00102
00111 void ws_gui_signal_hander (GError *error, GArray *words, gpointer user_data)
00112 {
00113 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00114 osso_rpc_t osss_data;
00115 osss_data = g_array_index (words, osso_rpc_t, 0);
00116 switch(osss_data.value.i)
00117 {
00118 case WS_DBUS_ERROR_ENGINE_NOT_FOUND:
00119 {
00120 ws_gui_app->ws_message_dialog =
00121 gtk_message_dialog_new(
00122 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
00123 GTK_DIALOG_DESTROY_WITH_PARENT,
00124 GTK_MESSAGE_ERROR,
00125 GTK_BUTTONS_OK,
00126 _("ws_ni_error_occured"));
00127 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
00128
00129 g_signal_connect_swapped(
00130 GTK_OBJECT (ws_gui_app->ws_message_dialog),
00131 "response",
00132 G_CALLBACK (gtk_main_quit),
00133 ws_gui_app);
00134 break;
00135 }
00136
00137 case WS_DBUS_ERROR_FILE_NOT_FOUND:
00138 {
00139 ws_gui_app->ws_message_dialog =
00140 gtk_message_dialog_new(
00141 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
00142 GTK_DIALOG_DESTROY_WITH_PARENT,
00143 GTK_MESSAGE_ERROR,
00144 GTK_BUTTONS_OK,
00145 _("ws_ni_no_dictionary_available"));
00146
00147 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
00148
00149 GArray *tmp;
00150 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
00151 gtk_list_store_clear(
00152 ws_gui_app->ws_gui_w_list->ws_gui_store);
00153 ws_gui_app->ws_gui_w_list->ws_gui_model =
00154 create_and_fill_model(tmp, ws_gui_app);
00155 ws_gui_fill_html(" ", ws_gui_app);
00156 ws_gui_app->html_flag = FALSE;
00157
00158 gtk_widget_set_sensitive(
00159 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
00160 FALSE);
00161 gtk_widget_set_sensitive(
00162 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
00163 FALSE);
00164
00165 if (gtk_dialog_run(
00166 GTK_DIALOG(ws_gui_app->ws_message_dialog))
00167 == GTK_RESPONSE_OK)
00168 {
00169 gtk_widget_destroy(
00170 ws_gui_app->ws_message_dialog);
00171 }
00172 break;
00173 }
00174
00175 case WS_DBUS_INFO_CACHING:
00176 {
00177 ws_gui_app->ws_gui_banner_caching =
00178 hildon_banner_show_progress(
00179 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
00180 NULL,
00181 _("ws_pb_caching"));
00182 ws_gui_app->caching_flag = TRUE;
00183 hildon_banner_set_fraction(
00184 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
00185 0.0);
00186 gtk_widget_set_sensitive(
00187 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
00188 FALSE);
00189 gtk_widget_set_sensitive(
00190 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
00191 FALSE);
00192 gtk_widget_set_sensitive(
00193 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
00194 FALSE);
00195 gtk_widget_set_sensitive(
00196 GTK_WIDGET(ws_gui_app->ws_gui_w_list->ws_gui_view),
00197 FALSE);
00198
00199 break;
00200 }
00201
00202 case WS_DBUS_INFO_CACHING_FINISHED:
00203 {
00204 gtk_widget_destroy(
00205 GTK_WIDGET(ws_gui_app->ws_gui_banner_caching));
00206 ws_gui_app->caching_flag = FALSE;
00207 gtk_widget_set_sensitive(
00208 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
00209 TRUE);
00210 gtk_widget_set_sensitive(
00211 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
00212 TRUE);
00213 gtk_widget_set_sensitive(
00214 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
00215 TRUE);
00216 gtk_widget_set_sensitive(
00217 GTK_WIDGET(ws_gui_app->ws_gui_w_list->ws_gui_view),
00218 TRUE);
00219
00220 break;
00221 }
00222
00223 case WS_DBUS_ERROR_DICTIONARY_NOT_LOAD:
00224 {
00225 if (ws_gui_app->ws_gui_history_cur_pos >= 0 &&
00226 ws_gui_app->ws_gui_history_cur_pos <=HISTORY_LEN)
00227 {
00228 g_array_remove_index(ws_gui_app->ws_gui_history,
00229 ws_gui_app->ws_gui_history_cur_pos);
00230 }
00231
00232 ws_gui_app->ws_message_dialog = gtk_message_dialog_new(
00233 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
00234 GTK_DIALOG_DESTROY_WITH_PARENT,
00235 GTK_MESSAGE_ERROR,
00236 GTK_BUTTONS_OK,
00237 _("ws_ni_dictionary_unavailable"));
00238 gtk_widget_show_all(ws_gui_app->ws_message_dialog);
00239 if (gtk_dialog_run(
00240 GTK_DIALOG(ws_gui_app->ws_message_dialog))
00241 == GTK_RESPONSE_OK)
00242 {
00243 gtk_widget_destroy(ws_gui_app->ws_message_dialog);
00244 }
00245 break;
00246 }
00247
00248 case WS_DBUS_BOOKMARKS_ADDED_OK:
00249 {
00250 hildon_banner_show_information(GTK_WIDGET(
00251 ws_gui_app->ws_gui_hildon_window),
00252 NULL,
00253 _("ws_ni_bookmark_added"));
00254 break;
00255 }
00256
00257 case WS_DBUS_BOOKMARKS_REMOVED_OK:
00258 {
00259 hildon_banner_show_information(GTK_WIDGET(
00260 ws_gui_app->ws_gui_hildon_window),
00261 NULL,
00262 _("ws_ni_bookmark_removed"));
00263 break;
00264 }
00265
00266 case WS_DBUS_BOOKMARKS_ADDED_FAIL:
00267 {
00268 hildon_banner_show_information(GTK_WIDGET(
00269 ws_gui_app->ws_gui_hildon_window),
00270 NULL,
00271 _("ws_ni_bookmark_not_added"));
00272 break;
00273 }
00274
00275 case WS_DBUS_BOOKMARKS_REMOVED_FAIL:
00276 {
00277 hildon_banner_show_information(GTK_WIDGET(
00278 ws_gui_app->ws_gui_hildon_window),
00279 NULL,
00280 _("ws_ni_bookmark_not_removed"));
00281 break;
00282 }
00283
00284 case WS_DBUS_LOAD_BOOKMARK_FAILED:
00285 {
00286 gtk_widget_set_sensitive(
00287 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
00288 FALSE);
00289 ws_gui_app->bookmark_avail = FALSE;
00290
00291 ws_gui_app->ws_message_dialog =
00292 gtk_message_dialog_new(
00293 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window),
00294 GTK_DIALOG_DESTROY_WITH_PARENT,
00295 GTK_MESSAGE_ERROR,
00296 GTK_BUTTONS_OK,
00297 _("ws_ni_bookmarks_unavailable"));
00298
00299 if (gtk_dialog_run(
00300 GTK_DIALOG(ws_gui_app->ws_message_dialog))
00301 == GTK_RESPONSE_OK)
00302 {
00303 gtk_widget_destroy(
00304 ws_gui_app->ws_message_dialog);
00305 }
00306
00307
00308 break;
00309 }
00310 case WS_DBUS_EXTRACT_FILE:
00311 {
00312 ws_gui_app->ws_gui_banner_extracting =
00313 hildon_banner_show_animation(
00314 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
00315 NULL,
00316 _("ws_pb_extracting"));
00317
00318 ws_gui_app->caching_flag = TRUE;
00319
00320 gtk_widget_set_sensitive(
00321 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
00322 FALSE);
00323 gtk_widget_set_sensitive(
00324 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
00325 FALSE);
00326
00327 break;
00328 }
00329
00330 case WS_DBUS_EXTRACT_FILE_FINISHED:
00331 {
00332 gtk_widget_destroy(
00333 GTK_WIDGET(ws_gui_app->ws_gui_banner_extracting));
00334
00335 ws_gui_app->caching_flag = FALSE;
00336
00337 hildon_banner_show_information(GTK_WIDGET(
00338 ws_gui_app->ws_gui_hildon_window),
00339 NULL,
00340 _("ws_ni_dictionary_added"));
00341
00342 gtk_widget_set_sensitive(
00343 GTK_WIDGET(ws_gui_app->ws_gui_hildon_find_toolbar),
00344 TRUE);
00345 gtk_widget_set_sensitive(
00346 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
00347 TRUE);
00348
00349 break;
00350 }
00351
00352 case WS_DBUS_WORDS_LIST_FULL:
00353 {
00354 gtk_widget_show_all(GTK_WIDGET(ws_gui_app->ws_gui_list_eventbox));
00355
00356 break;
00357 }
00358
00359 case WS_DBUS_WORDS_LIST_FILLED_NOT_FULL:
00360 {
00361 gtk_widget_hide_all(GTK_WIDGET(ws_gui_app->ws_gui_list_eventbox));
00362
00363 break;
00364 }
00365
00366 case WS_DBUS_WORDS_LIST_FINISHED:
00367 {
00368 gtk_widget_set_sensitive(
00369 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
00370 TRUE);
00371 gtk_widget_hide(GTK_WIDGET(ws_gui_app->ws_gui_banner_list_searching));
00372 break;
00373 }
00374
00375 case WS_DBUS_TRANSLATION_FINISHED:
00376 {
00377 gtk_widget_hide(ws_gui_app->ws_gui_banner_translation_loading);
00378 break;
00379 }
00380
00381 case WS_DBUS_WORDS_LIST_STARTED:
00382 {
00383 gtk_widget_set_sensitive(
00384 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_bookmarks),
00385 FALSE);
00386 gtk_widget_show(GTK_WIDGET(ws_gui_app->ws_gui_banner_list_searching));
00387 break;
00388 }
00389
00390 case WS_DBUS_TRANSLATION_STARTED:
00391 {
00392 gtk_widget_show(ws_gui_app->ws_gui_banner_translation_loading);
00393 break;
00394 }
00395
00396 }
00397 }
00398
00399
00400
00401 void ws_gui_search_home_handler(GError *error, GArray *word, gpointer user_data)
00402 {
00403 g_debug("->%s", __FUNCTION__);
00404 WSGuiApp *data = (WSGuiApp*) user_data;
00405 osso_rpc_t* osso_data = NULL;
00406
00407
00408 osso_data = &g_array_index (word, osso_rpc_t, 0);
00409
00410
00411 gchar* tmp = NULL;
00412 tmp = g_strdup(osso_data->value.s + 11);
00413
00414 g_object_set(G_OBJECT(data->ws_gui_hildon_find_toolbar),
00415 "prefix",
00416 tmp,
00417 NULL);
00418 ws_gui_search(NULL, data);
00419 }
00420
00429 void ws_dbus_progress_bar(GError *error, GArray *words, gpointer user_data)
00430 {
00431 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00432 osso_rpc_t osss_data;
00433 osss_data = g_array_index (words, osso_rpc_t, 0);
00434 double progress = osss_data.value.d;
00435 if (ws_gui_app->caching_flag == TRUE)
00436 {
00437 hildon_banner_set_fraction(
00438 HILDON_BANNER(ws_gui_app->ws_gui_banner_caching),
00439 progress);
00440 }
00441 }
00442
00448 void ws_gui_clear_list (GtkListStore* list, gpointer user_data)
00449 {
00450
00451 GtkTreeIter iter;
00452 gboolean tmp;
00453
00454
00455 tmp = gtk_tree_model_get_iter_first(
00456 GTK_TREE_MODEL(list),
00457 &iter);
00458
00459 while (tmp == TRUE)
00460 {
00461
00462 tmp = gtk_list_store_remove(list, &iter);
00463
00464 }
00465 }
00466
00467
00476 void ws_gui_dbus_return_words (GError *error, GArray *words, gpointer user_data)
00477 {
00478 timer(TIMER_START, (gchar*)__FUNCTION__);
00479 guint i;
00480 osso_rpc_t data;
00481
00482 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00483 ws_gui_app->no_words_found = FALSE;
00484
00485 g_signal_handlers_block_by_func(G_OBJECT
00486 (ws_gui_app->ws_gui_w_list->ws_gui_view),
00487 G_CALLBACK (ws_gui_view_cursor_changed),
00488 ws_gui_app);
00489
00490
00491 GArray *tmp;
00492 tmp = g_array_new(TRUE, TRUE, sizeof(gchar*));
00493 gchar *tmp_word;
00494
00495 for (i=0;i<words->len;++i)
00496 {
00497 data = g_array_index (words, osso_rpc_t, i);
00498 tmp_word = g_strdup(data.value.s);
00499 g_array_append_val(tmp, tmp_word);
00500 }
00501
00502
00503
00504
00505 ws_gui_app->loading = FALSE;
00506 ws_gui_set_toolbar_avail(ws_gui_app);
00507
00508
00509
00510
00511
00512
00513 ws_gui_app->ws_gui_w_list->ws_gui_model =
00514 create_and_fill_model(tmp, ws_gui_app);
00515
00516 if (ws_gui_app->history_flag == TRUE)
00517 {
00518
00519 GValue value = { 0, };
00520 GtkTreeIter tmp_iter;
00521 gchar *pattern;
00522 gboolean keep_searching = TRUE;
00523
00524 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(
00525 ws_gui_app->ws_gui_w_list->ws_gui_model), &tmp_iter) == TRUE)
00526 {
00527
00528 pattern = strdup(g_array_index(ws_gui_app->ws_gui_history,
00529 gchar*,
00530 ws_gui_app->ws_gui_history_cur_pos));
00531
00532 gtk_tree_model_get_value(GTK_TREE_MODEL(
00533 ws_gui_app->ws_gui_w_list->ws_gui_model),
00534 &tmp_iter,
00535 COL_WORD,
00536 &value);
00537
00538 if ((g_value_get_string (&value) != NULL) &&
00539 (strcmp(((gchar *)g_value_get_string (&value)),
00540 pattern) == 0))
00541 {
00542 gtk_tree_selection_select_iter(
00543 ws_gui_app->ws_gui_w_list->ws_gui_selection,
00544 &tmp_iter);
00545
00546 }
00547 else
00548 {
00549 while (gtk_tree_model_iter_next(GTK_TREE_MODEL
00550 (ws_gui_app->ws_gui_w_list->ws_gui_model),
00551 &tmp_iter) == TRUE && keep_searching == TRUE)
00552 {
00553 gtk_tree_model_get_value(GTK_TREE_MODEL(
00554 ws_gui_app->ws_gui_w_list->ws_gui_model),
00555 &tmp_iter,
00556 COL_WORD,
00557 &value);
00558
00559 if ((g_value_get_string (&value) != NULL) &&
00560 (strcmp(((gchar *)g_value_get_string (&value)),
00561 pattern) == 0))
00562 {
00563 gtk_tree_model_get_iter_from_string (
00564 GTK_TREE_MODEL(
00565 ws_gui_app->ws_gui_w_list->ws_gui_model),
00566 &tmp_iter,
00567 g_array_index(
00568 ws_gui_app->ws_gui_history_iter,
00569 gchar*,
00570 ws_gui_app->ws_gui_history_cur_pos));
00571
00572 gtk_tree_selection_select_iter(
00573 ws_gui_app->ws_gui_w_list->ws_gui_selection,
00574 &tmp_iter);
00575
00576 keep_searching = FALSE;
00577 }
00578 }
00579 }
00580 }
00581 g_free(pattern);
00582
00583 ws_gui_app->history_flag = FALSE;
00584 ws_dbus_client_find_translation(ws_gui_app->dbus_data,
00585 g_array_index(ws_gui_app->ws_gui_history,
00586 gchar*,
00587 ws_gui_app->ws_gui_history_cur_pos));
00588
00589 ws_gui_app->html_flag = TRUE;
00590 g_value_unset (&value);
00591 }
00592
00593
00594
00595
00596
00597
00598 if ((tmp->len == 0 || tmp_word == NULL) && ws_gui_app->stop_clicked != TRUE )
00599 {
00600 hildon_banner_show_information(GTK_WIDGET(
00601 ws_gui_app->ws_gui_hildon_window),
00602 NULL,
00603 _("ws_ni_no_words_found"));
00604
00605
00606
00607 g_free(ws_gui_app->last_word);
00608 ws_gui_app->last_word = NULL;
00609 ws_gui_app->no_words_found = TRUE;
00610 }
00611
00612 g_signal_handlers_unblock_by_func(G_OBJECT(
00613 ws_gui_app->ws_gui_w_list->ws_gui_view),
00614 G_CALLBACK (ws_gui_view_cursor_changed),
00615 ws_gui_app);
00616
00617 for (i=0;i<tmp->len;++i)
00618 {
00619 g_free(g_array_index(tmp, gchar* , i));
00620 }
00621 g_array_free(tmp, TRUE);
00622
00623 timer(TIMER_STOP, (gchar*)__FUNCTION__);
00624 }
00625
00634 void ws_gui_dbus_return_translation (GError *error,
00635 GArray *words,
00636 gpointer user_data)
00637 {
00638 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00639 gchar *html_content = NULL;
00640 osso_rpc_t data;
00641
00642 data = g_array_index (words, osso_rpc_t, 0);
00643
00644 html_content = format_html(data.value.s, ws_gui_app);
00645 ws_gui_fill_html(html_content, ws_gui_app);
00646 g_free(html_content);
00647 ws_gui_app->html_flag = TRUE;
00648
00649
00650 ws_gui_app->loading = FALSE;
00651 ws_gui_set_toolbar_avail(ws_gui_app);
00652
00653 }
00654
00663 void ws_dbus_server_return_extracted_bzip(GError *error,
00664 GArray *words,
00665 gpointer user_data)
00666 {
00667 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00668
00669 osso_rpc_t data;
00670
00671 data = g_array_index (words, osso_rpc_t, 0);
00672
00673 if (data.value.s[0] == '\0')
00674 {
00675 hildon_banner_show_information(GTK_WIDGET(
00676 ws_gui_app->ws_gui_hildon_window),
00677 NULL,
00678 _("ws_ni_dictionary_not_added"));
00679 }
00680 else
00681 {
00682 if (ws_gui_load_dict(data.value.s, ws_gui_app) == TRUE)
00683 {
00684
00685 }
00686 }
00687 }
00688
00694 void ws_gui_free_memory(gpointer user_data)
00695 {
00696 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00697 guint i = 0;
00698 for (i = 0; i<ws_gui_app->ws_gui_history->len; ++i)
00699 {
00700 g_free(g_array_index(ws_gui_app->ws_gui_history, gchar *, i));
00701 }
00702 g_array_free(ws_gui_app->ws_gui_history, TRUE);
00703
00704 for (i = 0; i<ws_gui_app->ws_gui_history_list->len; ++i)
00705 {
00706 g_free(g_array_index(ws_gui_app->ws_gui_history_list, gchar *, i));
00707 }
00708 g_array_free(ws_gui_app->ws_gui_history_list, TRUE);
00709
00710 for (i = 0; i<ws_gui_app->ws_gui_history_iter->len; ++i)
00711 {
00712 g_free(g_array_index(ws_gui_app->ws_gui_history_iter, gchar *, i));
00713 }
00714 g_array_free(ws_gui_app->ws_gui_history_iter, TRUE);
00715
00716
00717 pango_font_description_free(ws_gui_app->p);
00718
00719 g_free(ws_gui_app->welcome_note);
00720 ws_gui_app->welcome_note = NULL;
00721
00722 g_string_free(ws_gui_app->raw_translation, TRUE);
00723 g_free(ws_gui_app->last_word);
00724 g_free(ws_gui_app->ws_gui_w_list);
00725 g_free(ws_gui_app->ws_gui_menu);
00726 g_free(ws_gui_app);
00727 }
00728
00737 gboolean hildon_key_press_listener (GtkWidget * widget,
00738 GdkEventKey * keyevent,
00739 gpointer user_data)
00740 {
00741 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
00742
00743 switch ((guint)(keyevent->keyval)) {
00744 case HILDON_HARDKEY_UP:
00745 {
00746 gtk_container_set_focus_vadjustment(
00747 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
00748 gtk_scrolled_window_get_vadjustment(
00749 GTK_SCROLLED_WINDOW(
00750 ws_gui_app->ws_gui_scrolledwindow_left)));
00751 ws_gui_app->v_new_value =
00752 gtk_adjustment_get_value(
00753 GTK_ADJUSTMENT(
00754 ws_gui_app->ws_gui_vadj)) - ws_gui_app->v_delta;
00755 if (ws_gui_app->v_new_value >
00756 ws_gui_app->ws_gui_vadj->lower)
00757 {
00758 gtk_adjustment_set_value(
00759 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
00760 ws_gui_app->v_new_value);
00761 }
00762
00763 break;
00764 }
00765
00766 case HILDON_HARDKEY_DOWN:
00767 {
00768 gtk_container_set_focus_vadjustment(
00769 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
00770 gtk_scrolled_window_get_vadjustment(
00771 GTK_SCROLLED_WINDOW(
00772 ws_gui_app->ws_gui_scrolledwindow_left)));
00773 ws_gui_app->v_new_value = gtk_adjustment_get_value(
00774 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj))
00775 + ws_gui_app->v_delta;
00776
00777 if (ws_gui_app->v_new_value <
00778 (ws_gui_app->ws_gui_vadj->upper -
00779 ws_gui_app->ws_gui_vadj->page_size))
00780 {
00781 gtk_adjustment_set_value(
00782 GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj),
00783 ws_gui_app->v_new_value);
00784 }
00785 break;
00786 }
00787
00788 case HILDON_HARDKEY_LEFT:
00789 {
00790 gtk_container_set_focus_hadjustment(
00791 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
00792 gtk_scrolled_window_get_hadjustment(
00793 GTK_SCROLLED_WINDOW(
00794 ws_gui_app->ws_gui_scrolledwindow_left)));
00795
00796 ws_gui_app->h_new_value = gtk_adjustment_get_value(
00797 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
00798 - ws_gui_app->h_delta;
00799
00800 if (ws_gui_app->h_new_value >
00801 ws_gui_app->ws_gui_hadj->lower)
00802 {
00803 gtk_adjustment_set_value(
00804 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
00805 ws_gui_app->h_new_value);
00806 }
00807 }
00808 break;
00809
00810 case HILDON_HARDKEY_RIGHT:
00811 {
00812 gtk_container_set_focus_hadjustment(
00813 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
00814 gtk_scrolled_window_get_hadjustment(
00815 GTK_SCROLLED_WINDOW(
00816 ws_gui_app->ws_gui_scrolledwindow_left)));
00817
00818 ws_gui_app->h_new_value = gtk_adjustment_get_value(
00819 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj))
00820 + ws_gui_app->h_delta;
00821
00822 if (ws_gui_app->h_new_value <
00823 (ws_gui_app->ws_gui_hadj->upper -
00824 ws_gui_app->ws_gui_hadj->page_size))
00825 {
00826 gtk_adjustment_set_value(
00827 GTK_ADJUSTMENT(ws_gui_app->ws_gui_hadj),
00828 ws_gui_app->h_new_value);
00829 }
00830 }
00831 break;
00832
00833 case HILDON_HARDKEY_SELECT:
00834 ws_gui_search(NULL, ws_gui_app);
00835 break;
00836
00837 case HILDON_HARDKEY_FULLSCREEN:
00838 ws_gui_full_screen(NULL, ws_gui_app);
00839 break;
00840
00841 case HILDON_HARDKEY_INCREASE:
00842 ws_gui_html_zoom_in(NULL, ws_gui_app);
00843 break;
00844
00845 case HILDON_HARDKEY_DECREASE:
00846 ws_gui_html_zoom_out(NULL, ws_gui_app);
00847 break;
00848
00849 case HILDON_HARDKEY_ESC:
00850 ws_gui_search_stop(NULL, ws_gui_app);
00851 break;
00852
00853 default:
00854 return FALSE;
00855 break;
00856 }
00857 return TRUE;
00858 }
00859
00866 void ws_gui_words_list_hide_from_menu(GtkCheckMenuItem *checkmenuitem,
00867 gpointer user_data)
00868 {
00869 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
00870 if (gtk_check_menu_item_get_active(
00871 GTK_CHECK_MENU_ITEM(ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list)))
00872 {
00873 gtk_widget_hide(ws_gui_app->ws_gui_list_vbox);
00874 gtk_toggle_tool_button_set_active(
00875 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide),
00876 TRUE);
00877 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
00878 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
00879 TRUE);
00880 }
00881 else
00882 {
00883 gtk_widget_show(ws_gui_app->ws_gui_list_vbox);
00884 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
00885 ws_gui_app->ws_gui_toobar_button_hide),
00886 FALSE);
00887 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
00888 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
00889 FALSE);
00890 }
00891 }
00892
00900 void ws_gui_words_list_hide(GtkToggleButton *togglebutton, gpointer user_data)
00901 {
00902 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
00903
00904 if (gtk_toggle_tool_button_get_active(
00905 GTK_TOGGLE_TOOL_BUTTON(ws_gui_app->ws_gui_toobar_button_hide)))
00906 {
00907 gtk_widget_hide(ws_gui_app->ws_gui_list_vbox);
00908 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
00909 ws_gui_app->ws_gui_toobar_button_hide),
00910 TRUE);
00911 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
00912 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
00913 TRUE);
00914 }
00915 else
00916 {
00917 gtk_widget_show(ws_gui_app->ws_gui_list_vbox);
00918 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(
00919 ws_gui_app->ws_gui_toobar_button_hide),
00920 FALSE);
00921 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
00922 ws_gui_app->ws_gui_menu->ws_gui_menu_hide_list),
00923 FALSE);
00924 }
00925 }
00926
00933 void ws_gui_history_add(char *new_word, gpointer user_data)
00934 {
00935 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
00936
00937 if (ws_gui_app->history_flag != TRUE)
00938 {
00939
00940 guint i;
00941 gchar *tmp_word;
00942 gchar *tmp_last_searched;
00943 gchar *tmp_iter = NULL;
00944 gchar *previous_word = " ";
00945
00946 if (ws_gui_app->ws_gui_history_cur_pos > -1 &&
00947 g_array_index(ws_gui_app->ws_gui_history,
00948 gchar*,
00949 ws_gui_app->ws_gui_history_cur_pos) != NULL)
00950 {
00951 previous_word = NULL;
00952 previous_word = g_array_index(
00953 ws_gui_app->ws_gui_history,
00954 gchar*,
00955 ws_gui_app->ws_gui_history_cur_pos);
00956 }
00957
00958 i = ws_gui_app->ws_gui_history_cur_pos + 1;
00959 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
00960 gchar*,
00961 i);
00962
00963
00964 if (previous_word != NULL &&
00965 strcmp(previous_word, new_word) != 0)
00966 {
00967 while (tmp != NULL)
00968 {
00969 g_array_remove_index(
00970 ws_gui_app->ws_gui_history_list,
00971 i);
00972 g_array_remove_index(
00973 ws_gui_app->ws_gui_history_iter,
00974 i);
00975
00976
00977 g_array_remove_index(
00978 ws_gui_app->ws_gui_history,
00979 i);
00980
00981 tmp = g_array_index(
00982 ws_gui_app->ws_gui_history,
00983 gchar*,
00984 i);
00985 }
00986
00987 i = 0;
00988 ws_gui_app->ws_gui_history_cur_pos ++;
00989
00990 if (ws_gui_app->bookmark_mode == FALSE)
00991 {
00992 tmp_last_searched = g_strdup(ws_gui_app->last_searched);
00993 }
00994 else
00995 {
00996 tmp_last_searched = g_strdup(ws_gui_app->last_searched_in_book);
00997 }
00998
00999 g_array_append_val(ws_gui_app->ws_gui_history_list,
01000 tmp_last_searched);
01001
01002 tmp_word = g_strdup(new_word);
01003
01004 g_array_append_val(ws_gui_app->ws_gui_history, tmp_word);
01005 g_array_append_val(ws_gui_app->ws_gui_history_iter, tmp_iter);
01006
01007
01008 if(ws_gui_app->ws_gui_history->len > HISTORY_LEN)
01009 {
01010 g_array_remove_index(ws_gui_app->ws_gui_history, 0);
01011 g_array_remove_index(ws_gui_app->ws_gui_history_list,
01012 0);
01013 g_array_remove_index(ws_gui_app->ws_gui_history_iter,
01014 0);
01015
01016 ws_gui_app->ws_gui_history_cur_pos--;
01017 }
01018
01019 i = 0;
01020
01021 tmp = g_array_index(ws_gui_app->ws_gui_history, gchar*, i);
01022 }
01023
01024 }
01025
01026 ws_gui_check_history(ws_gui_app);
01027 }
01028
01036 void ws_gui_history_back(GtkButton *button, gpointer user_data)
01037 {
01038 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01039
01040 ws_gui_app->history_flag = TRUE;
01041
01042 if (ws_gui_app->ws_gui_history_cur_pos > -1)
01043 {
01044 ws_gui_app->ws_gui_history_cur_pos =
01045 ws_gui_app->ws_gui_history_cur_pos - 1;
01046
01047
01048 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01049 "prefix",
01050 (g_array_index(ws_gui_app->ws_gui_history_list,
01051 gchar*,
01052 ws_gui_app->ws_gui_history_cur_pos)),
01053 NULL);
01054
01055 ws_dbus_client_find_word (ws_gui_app->dbus_data,
01056 g_strstrip(g_array_index(ws_gui_app->ws_gui_history_list,
01057 gchar*,
01058 ws_gui_app->ws_gui_history_cur_pos))
01059 );
01060
01061
01062 ws_gui_app->loading = TRUE;
01063 ws_gui_set_toolbar_avail(ws_gui_app);
01064 }
01065 else
01066 {
01067 ws_gui_app->loading = FALSE;
01068 ws_gui_set_toolbar_avail(ws_gui_app);
01069 }
01070
01071 ws_gui_check_history(ws_gui_app);
01072 }
01073
01081 void ws_gui_history_next(GtkButton *button, gpointer user_data)
01082 {
01083 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01084
01085 ws_gui_app->history_flag = TRUE;
01086
01087 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
01088 gchar*,
01089 ws_gui_app->ws_gui_history_cur_pos+1);
01090
01091 if ((ws_gui_app->ws_gui_history_cur_pos < HISTORY_LEN-1)
01092 && (tmp != NULL))
01093 {
01094 ws_gui_app->ws_gui_history_cur_pos =
01095 ws_gui_app->ws_gui_history_cur_pos + 1;
01096
01097
01098
01099 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01100 "prefix",
01101 (g_array_index(ws_gui_app->ws_gui_history_list,
01102 gchar*,
01103 ws_gui_app->ws_gui_history_cur_pos)),
01104 NULL);
01105
01106
01107 ws_dbus_client_find_word(ws_gui_app->dbus_data,
01108 g_strstrip(g_array_index(ws_gui_app->ws_gui_history_list,
01109 gchar*,
01110 ws_gui_app->ws_gui_history_cur_pos))
01111 );
01112
01113
01114
01115 ws_gui_app->loading = TRUE;
01116 ws_gui_set_toolbar_avail(ws_gui_app);
01117 }
01118 else
01119 {
01120
01121 gtk_widget_set_sensitive(
01122 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
01123 FALSE);
01124
01125
01126 gtk_widget_set_sensitive(
01127 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
01128 FALSE);
01129 }
01130
01131 ws_gui_check_history(ws_gui_app);
01132 }
01133
01140 void ws_gui_check_history(gpointer user_data)
01141 {
01142 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01143
01144 gchar *tmp = g_array_index(ws_gui_app->ws_gui_history,
01145 gchar*,
01146 ws_gui_app->ws_gui_history_cur_pos+1);
01147
01148 if ((ws_gui_app->ws_gui_history_cur_pos+1 < HISTORY_LEN)
01149 && (tmp != NULL))
01150 {
01151
01152 gtk_widget_set_sensitive(
01153 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
01154 TRUE);
01155
01156
01157 gtk_widget_set_sensitive(
01158 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
01159 TRUE);
01160 }
01161 else
01162 {
01163
01164 gtk_widget_set_sensitive(
01165 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_forward),
01166 FALSE);
01167
01168
01169 gtk_widget_set_sensitive(
01170 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_next),
01171 FALSE);
01172 }
01173
01174 tmp = g_array_index(ws_gui_app->ws_gui_history,
01175 gchar*,
01176 ws_gui_app->ws_gui_history_cur_pos-1);
01177 if ((ws_gui_app->ws_gui_history_cur_pos > 0) && (tmp != NULL))
01178 {
01179
01180 gtk_widget_set_sensitive(
01181 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
01182 TRUE);
01183
01184
01185 gtk_widget_set_sensitive(
01186 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
01187 TRUE);
01188 }
01189 else
01190 {
01191 gtk_widget_set_sensitive (
01192 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_back),
01193 FALSE);
01194 gtk_widget_set_sensitive(
01195 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_find_prev),
01196 FALSE);
01197 }
01198 }
01199
01207 GtkTreeModel * create_and_fill_model (GArray *words_list, gpointer user_data)
01208 {
01209 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01210
01211 g_signal_handlers_block_by_func(G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_view),
01212 G_CALLBACK (ws_gui_view_cursor_changed),
01213 ws_gui_app);
01214
01215 guint i = 0;
01216 gchar *tmp = g_strdup(g_array_index(words_list, gchar*, i));
01217
01218 if (tmp != NULL)
01219 {
01220 ws_gui_clear_list(ws_gui_app->ws_gui_w_list->ws_gui_store, ws_gui_app);
01221 }
01222
01223 gboolean valid;
01224 valid = gtk_tree_model_get_iter_first(
01225 GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store),
01226 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
01227
01228
01229 while (tmp != NULL)
01230 {
01231 gtk_list_store_append (ws_gui_app->ws_gui_w_list->ws_gui_store,
01232 &ws_gui_app->ws_gui_w_list->ws_gui_iter);
01233
01234 gtk_list_store_set (ws_gui_app->ws_gui_w_list->ws_gui_store,
01235 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
01236 COL_WORD, tmp,
01237 -1);
01238 i=i+1;
01239 g_free(tmp);
01240 tmp = NULL;
01241 tmp = g_strdup(g_array_index(words_list, gchar*, i));
01242 };
01243
01244 g_free(tmp);
01245 tmp = NULL;
01246 tmp = g_strdup(g_array_index(words_list, gchar*, 0));
01247
01248
01249 if (ws_gui_app->history_flag == FALSE && tmp != NULL)
01250 {
01251
01252 ws_dbus_client_find_translation(ws_gui_app->dbus_data, tmp);
01253 ws_gui_history_add(tmp, ws_gui_app);
01254
01255 g_free(ws_gui_app->last_word);
01256 ws_gui_app->last_word = NULL;
01257 ws_gui_app->last_word = g_strdup (tmp);
01258 ws_gui_app->history_flag = FALSE;
01259 }
01260
01261 g_signal_handlers_unblock_by_func(G_OBJECT(
01262 ws_gui_app->ws_gui_w_list->ws_gui_view),
01263 G_CALLBACK (ws_gui_view_cursor_changed),
01264 ws_gui_app);
01265
01266 g_free(tmp);
01267 return GTK_TREE_MODEL(ws_gui_app->ws_gui_w_list->ws_gui_store);
01268
01269 }
01270
01279 GtkWidget * create_view_and_model (GArray *words_list, gpointer user_data)
01280 {
01281 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01282
01283 ws_gui_app->ws_gui_w_list->ws_gui_view = gtk_tree_view_new ();
01284
01285 ws_gui_app->ws_gui_w_list->ws_gui_renderer=gtk_cell_renderer_text_new();
01286 gtk_tree_view_insert_column_with_attributes(
01287 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
01288 -1,
01289 "Name",
01290 ws_gui_app->ws_gui_w_list->ws_gui_renderer,
01291 "text",
01292 COL_WORD,
01293 NULL);
01294 ws_gui_app->ws_gui_w_list->ws_gui_model =
01295 create_and_fill_model(words_list, ws_gui_app);
01296
01297 gtk_tree_view_set_model(
01298 GTK_TREE_VIEW (ws_gui_app->ws_gui_w_list->ws_gui_view),
01299 ws_gui_app->ws_gui_w_list->ws_gui_model);
01300 g_object_unref (ws_gui_app->ws_gui_w_list->ws_gui_model);
01301
01302 return ws_gui_app->ws_gui_w_list->ws_gui_view;
01303 }
01304
01311 void ws_gui_full_screen(GtkMenuItem *menuitem, gpointer user_data)
01312 {
01313
01314 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01315 if (ws_gui_app->ws_gui_full_screen_flag == FALSE) {
01316
01317 gtk_window_fullscreen(
01318 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
01319 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
01320 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
01321 TRUE);
01322 ws_gui_app->ws_gui_full_screen_flag = TRUE;
01323 hildon_banner_show_information(GTK_WIDGET(
01324 ws_gui_app->ws_gui_hildon_window),
01325 NULL,
01326 _("ws_ib_fullscreen_on"));
01327 }
01328 else
01329 {
01330 gtk_window_unfullscreen(
01331 GTK_WINDOW(ws_gui_app->ws_gui_hildon_window));
01332 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
01333 ws_gui_app->ws_gui_menu->ws_gui_menu_full_screen),
01334 FALSE);
01335 ws_gui_app->ws_gui_full_screen_flag = FALSE;
01336 hildon_banner_show_information(GTK_WIDGET(
01337 ws_gui_app->ws_gui_hildon_window),
01338 NULL,
01339 _("ws_ib_fullscreen_off"));
01340 }
01341 }
01342
01349 void ws_gui_popup_search(GtkMenuItem *menuitem, gpointer user_data)
01350 {
01351 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01352 gchar *temp;
01353 ws_gui_app->ws_gui_clipboard_primary =
01354 gtk_widget_get_clipboard(ws_gui_app->ws_gui_html,
01355 GDK_SELECTION_PRIMARY);
01356 temp = gtk_clipboard_wait_for_text(
01357 ws_gui_app->ws_gui_clipboard_primary);
01358
01359 g_strstrip(temp);
01360 if (temp != NULL || strcmp(temp, " "))
01361 {
01362
01363 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01364 "prefix",
01365 temp,
01366 NULL);
01367 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
01368
01369 }
01370 else
01371 {
01372 hildon_banner_show_information(
01373 GTK_WIDGET(ws_gui_app->ws_gui_hildon_window),
01374 NULL,
01375 _("ws_ni_no_text_selected"));
01376 }
01377 }
01378
01385 void ws_gui_html_select_all(GtkMenuItem *menuitem, gpointer user_data)
01386 {
01387 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01388 gtk_html_select_all(GTK_HTML(ws_gui_app->ws_gui_html));
01389 }
01390
01397 void ws_gui_html_copy(GtkMenuItem *menuitem, gpointer user_data)
01398 {
01399 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01400 gtk_html_copy(GTK_HTML(ws_gui_app->ws_gui_html));
01401 hildon_banner_show_information(GTK_WIDGET(
01402 ws_gui_app->ws_gui_hildon_window),
01403 NULL,
01404 _("ws_ib_copied"));
01405 }
01406
01413 void ws_gui_html_paste(GtkMenuItem *menuitem, gpointer user_data)
01414 {
01415 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01416
01417 gchar *temp;
01418 gchar *temp2;
01419 temp = gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard);
01420
01421
01422 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01423 "prefix",
01424 &temp2,
01425 NULL);
01426
01427
01428 temp = g_strconcat(temp2, temp, NULL);
01429
01430 temp = g_strdelimit(temp, "\n", ' ');
01431
01432
01433 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01434 "prefix",
01435 temp,
01436 NULL);
01437 hildon_banner_show_information(GTK_WIDGET(
01438 ws_gui_app->ws_gui_hildon_window),
01439 NULL,
01440 _("ws_ib_pasted"));
01441 }
01442
01449 void ws_gui_html_zoom_in(GtkMenuItem *menuitem, gpointer user_data)
01450 {
01451 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01452 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
01453 if (ws_gui_app->zoom > ZOOM_MAX)
01454 {
01455 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
01456 hildon_banner_show_information(GTK_WIDGET(
01457 ws_gui_app->ws_gui_hildon_window),
01458 NULL,
01459 _("ws_ib_max_zoom"));
01460 }
01461 else
01462 {
01463 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
01464 ws_gui_app->zoom);
01465
01466 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
01467 {
01468 hildon_banner_show_information(GTK_WIDGET(
01469 ws_gui_app->ws_gui_hildon_window),
01470 NULL,
01471 _("ws_ib_zoom_default"));
01472 }
01473 else
01474 {
01475 hildon_banner_show_information(GTK_WIDGET(
01476 ws_gui_app->ws_gui_hildon_window),
01477 NULL,
01478 _("ws_ib_zoom_in"));
01479 }
01480 }
01481 }
01482
01489 void ws_gui_html_zoom_out(GtkMenuItem *menuitem, gpointer user_data)
01490 {
01491 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01492 ws_gui_app->zoom = ws_gui_app->zoom - ZOOM_STEP;
01493 if (ws_gui_app->zoom < ZOOM_MIN)
01494 {
01495 ws_gui_app->zoom = ws_gui_app->zoom + ZOOM_STEP;
01496 hildon_banner_show_information(GTK_WIDGET(
01497 ws_gui_app->ws_gui_hildon_window),
01498 NULL,
01499 _("ws_ib_min_zoom"));
01500 }
01501 else
01502 {
01503 gtk_html_set_magnification(GTK_HTML(ws_gui_app->ws_gui_html),
01504 ws_gui_app->zoom);
01505
01506 if ((WS_GUI_ABS(ws_gui_app->zoom - ZOOM_DEFAULT)) < 0.000001)
01507 {
01508 hildon_banner_show_information(GTK_WIDGET(
01509 ws_gui_app->ws_gui_hildon_window),
01510 NULL,
01511 _("ws_ib_zoom_default"));
01512 }
01513 else
01514 {
01515 hildon_banner_show_information(GTK_WIDGET(
01516 ws_gui_app->ws_gui_hildon_window),
01517 NULL,
01518 _("ws_ib_zoom_out"));
01519 }
01520 }
01521 }
01522
01529 void ws_gui_search(GtkWidget * widget, gpointer user_data)
01530 {
01531 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01532
01533 ws_gui_app->stop_clicked = FALSE;
01534
01535
01536
01537 gchar* ws_gui_text = NULL;
01538 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01539 "prefix",
01540 &ws_gui_text,
01541 NULL);
01542
01543 if (ws_gui_app->bookmark_mode == FALSE)
01544 {
01545 if (ws_gui_app->first_run == TRUE)
01546 {
01547 ws_gui_app->first_run = FALSE;
01548 }
01549
01550 g_free(ws_gui_app->last_searched);
01551 ws_gui_app->last_searched = NULL;
01552 ws_gui_app->last_searched = g_strdup(ws_gui_text);
01553 }
01554 else
01555 {
01556 g_free(ws_gui_app->last_searched_in_book);
01557 ws_gui_app->last_searched_in_book = NULL;
01558 ws_gui_app->last_searched_in_book = g_strdup(ws_gui_text);
01559 }
01560
01561 g_strstrip(ws_gui_text);
01562 if (strlen(ws_gui_text) != 0)
01563 {
01564
01565
01566 ws_gui_app->loading = TRUE;
01567 ws_gui_set_toolbar_avail(ws_gui_app);
01568
01569
01570
01571
01572 ws_dbus_client_find_word (ws_gui_app->dbus_data, ws_gui_text);
01573
01574
01575 g_free(ws_gui_text);
01576 }
01577 else
01578 {
01579 hildon_banner_show_information(GTK_WIDGET(
01580 ws_gui_app->ws_gui_hildon_window),
01581 NULL,
01582 _("ws_ni_no_word_typed"));
01583 }
01584 g_free(ws_gui_app->last_word);
01585 ws_gui_app->last_word=NULL;
01586
01587 }
01588
01595 void ws_gui_search_stop(GtkButton *button, gpointer user_data)
01596 {
01597 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01598 ws_gui_app->stop_clicked = TRUE;
01599
01600 if (ws_gui_app->loading == TRUE)
01601 {
01602
01603
01604 ws_gui_app->loading = FALSE;
01605 ws_gui_set_toolbar_avail(ws_gui_app);
01606
01607
01608
01609 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_STOP_SEARCH);
01610 hildon_banner_show_information(GTK_WIDGET(
01611 ws_gui_app->ws_gui_hildon_window),
01612 NULL,
01613 _("ws_ni_search_aborted"));
01614 }
01615 }
01616
01625 void ws_gui_on_exit (GtkWidget *widget, GdkEvent *event, gpointer user_data)
01626 {
01627 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01628 ws_gui_app->bookmark_mode = FALSE;
01629 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
01630 g_timer_destroy(ws_gui_app->timer);
01631 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
01632 ws_dbus_destroy (ws_gui_app->dbus_data);
01633 ws_gui_free_memory(ws_gui_app);
01634 gtk_main_quit();
01635 exit (0);
01636 }
01637
01645 void ws_gui_menu_quit(GtkMenuItem *menuitem, gpointer user_data)
01646 {
01647 WSGuiApp* ws_gui_app = (WSGuiApp *)user_data;
01648 ws_gui_app->bookmark_mode = FALSE;
01649 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
01650 g_timer_destroy(ws_gui_app->timer);
01651 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
01652 ws_dbus_destroy (ws_gui_app->dbus_data);
01653 ws_gui_free_memory(ws_gui_app);
01654 gtk_main_quit();
01655 exit (0);
01656 }
01657
01664 void ws_gui_fill_html(char *html_context, gpointer user_data)
01665 {
01666 WSGuiApp* ws_gui_app = (WSGuiApp*)user_data;
01667
01668 gtk_html_set_editable (GTK_HTML(ws_gui_app->ws_gui_html), FALSE);
01669
01670
01671 if (ws_gui_app->first_run == TRUE && ws_gui_app->bookmark_mode==FALSE)
01672 {
01673 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
01674 ws_gui_app->welcome_note,
01675 -1);
01676 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
01677 "prefix",
01678 "",
01679 NULL);
01680 }
01681 else
01682 {
01683 gtk_html_load_from_string(GTK_HTML(ws_gui_app->ws_gui_html),
01684 html_context,
01685 -1);
01686 }
01687 }
01688
01695 void ws_gui_read_adjustment(gpointer user_data)
01696 {
01697 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01698
01699 ws_gui_app->ws_gui_hadj =
01700 gtk_scrolled_window_get_hadjustment(
01701 GTK_SCROLLED_WINDOW(
01702 ws_gui_app->ws_gui_scrolledwindow_left));
01703
01704 ws_gui_app->h_delta = (ws_gui_app->ws_gui_hadj->upper -
01705 ws_gui_app->ws_gui_hadj->lower)/SCROLL_STEP_H;
01706
01707 ws_gui_app->ws_gui_vadj = gtk_scrolled_window_get_vadjustment(
01708 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left));
01709
01710 ws_gui_app->v_delta = (ws_gui_app->ws_gui_vadj->upper -
01711 ws_gui_app->ws_gui_vadj->lower)/SCROLL_STEP_V;
01712 ws_gui_app->v_new_value =
01713 gtk_adjustment_get_value(GTK_ADJUSTMENT(ws_gui_app->ws_gui_vadj)) +
01714 ws_gui_app->v_delta;
01715
01716 gtk_container_set_focus_vadjustment(
01717 GTK_CONTAINER(ws_gui_app->ws_gui_scrolledwindow_left),
01718 gtk_scrolled_window_get_vadjustment(
01719 GTK_SCROLLED_WINDOW(ws_gui_app->ws_gui_scrolledwindow_left)));
01720
01721 }
01722
01730 void ws_gui_url_requested (
01731 GtkHTML *html,
01732 const char *url,
01733 GtkHTMLStream *stream)
01734 {
01735 int fd;
01736
01737 if (url && !strncmp (url, "file:", 5)) {
01738 url += 5;
01739 fd = open (url, O_RDONLY);
01740 if (fd != -1) {
01741 gchar *buf;
01742 size_t size;
01743 buf = alloca (8192);
01744 while ((size = read (fd, buf, 8192)) > 0) {
01745 gtk_html_stream_write (stream, buf, size);
01746 }
01747 gtk_html_stream_close(stream, size == -1
01748 ? GTK_HTML_STREAM_ERROR
01749 : GTK_HTML_STREAM_OK);
01750 close (fd);
01751
01752 return;
01753 }
01754 }
01755
01756 gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR);
01757 }
01758
01768 gboolean ws_gui_button_press(GtkWidget *widget,
01769 GdkEventButton *event,
01770 gpointer user_data)
01771 {
01772 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01773 if (ws_gui_app->ws_gui_sel_flag == FALSE)
01774 {
01775 if (event->type == GDK_2BUTTON_PRESS)
01776 {
01777 ws_gui_app->ws_gui_double_click = TRUE;
01778 g_timer_stop(ws_gui_app->timer);
01779 g_timer_reset(ws_gui_app->timer);
01780 return FALSE;
01781 }
01782
01783 g_signal_stop_emission_by_name(G_OBJECT(
01784 ws_gui_app->ws_gui_html),
01785 "button-press-event");
01786 g_timer_start(ws_gui_app->timer);
01787 gtk_timeout_add((guint)(PRESS_TIME*1000),
01788 (GtkFunction)(ws_gui_show_popup),
01789 ws_gui_app);
01790 return FALSE;
01791 }
01792 else
01793 {
01794 ws_gui_app->ws_gui_sel_flag = FALSE;
01795 return FALSE;
01796 }
01797
01798 }
01799
01809 gboolean ws_gui_button_release (GtkWidget *widget,
01810 GdkEventButton *event,
01811 gpointer user_data)
01812 {
01813 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01814 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
01815 g_timer_stop(ws_gui_app->timer);
01816 g_timer_reset(ws_gui_app->timer);
01817 if (ws_gui_app->ws_gui_double_click == TRUE)
01818 {
01819 ws_gui_app->ws_gui_double_click = FALSE;
01820 return FALSE;
01821 }
01822 else if (tmp < PRESS_TIME)
01823 {
01824 struct _GtkHTML *tmp = (struct _GtkHTML *)
01825 (ws_gui_app->ws_gui_html);
01826 html_engine_unselect_all(tmp->engine);
01827 return TRUE;
01828 }
01829 return FALSE;
01830 }
01831
01837 guint ws_gui_show_popup (gpointer user_data)
01838 {
01839 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01840 gdouble tmp = g_timer_elapsed(ws_gui_app->timer, NULL);
01841 if (tmp > PRESS_TIME)
01842 {
01843 ws_gui_create_popup_menu(ws_gui_app);
01844 }
01845 return (guint)(FALSE);
01846
01847 }
01848
01855 void ws_gui_check_clipboard (GtkWidget *widget, gpointer user_data)
01856 {
01857 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01858 if (gtk_clipboard_wait_for_text(ws_gui_app->ws_gui_clipboard) != NULL)
01859 {
01860 gtk_widget_set_sensitive(
01861 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
01862 TRUE);
01863 }
01864 else
01865 {
01866 gtk_widget_set_sensitive(
01867 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_paste),
01868 FALSE);
01869 }
01870
01871 struct _GtkHTML *tmp = (struct _GtkHTML *)(ws_gui_app->ws_gui_html);
01872
01873 if (html_engine_is_selection_active(tmp->engine) == TRUE)
01874 {
01875 gtk_widget_set_sensitive(GTK_WIDGET
01876 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
01877 TRUE);
01878 }
01879 else
01880 {
01881 gtk_widget_set_sensitive(GTK_WIDGET
01882 (ws_gui_app->ws_gui_menu->ws_gui_menu_copy),
01883 FALSE);
01884 }
01885
01886 if (ws_gui_app->html_flag == FALSE)
01887 {
01888 gtk_widget_set_sensitive(GTK_WIDGET
01889 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
01890 FALSE);
01891 }
01892 else
01893 {
01894 gtk_widget_set_sensitive(GTK_WIDGET
01895 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_all),
01896 TRUE);
01897 }
01898
01899 }
01900
01908 gchar * format_html (gchar * received_string, gpointer user_data)
01909 {
01910 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
01911 GString *str_final;
01912 GString *str_tmp;
01913 str_final = g_string_new(received_string);
01914 str_tmp = g_string_new(received_string);
01915 gchar * tmp;
01916 gchar * tmp2;
01917 gchar * returned_value;
01918
01919 ws_gui_app->raw_translation=g_string_erase(ws_gui_app->raw_translation,
01920 0,
01921 -1);
01922
01923 while (strstr(str_final->str, "<PATTERN_OPEN>") != NULL)
01924 {
01925 tmp = strstr(str_final->str, "<PATTERN_OPEN>");
01926 str_final = g_string_erase(str_final,
01927 (long)(tmp - str_final->str),
01928 14);
01929 str_final = g_string_insert(str_final,
01930 (long)(tmp - str_final->str),
01931 "<html><head></head><body><center><table width=\"95%\"><tr>"
01932 "<td><table border=1 width=100%><tr>"
01933 "<th background=\"file:/usr/share/pixmaps/ws_top.png\">"
01934 "<img align=left src=\"file:/usr/share/pixmaps/"
01935 "engine_xdxf_icon.png\"><font color=\"#eeeeee\">");
01936
01937 tmp2 = strstr(str_tmp->str, "<PATTERN_OPEN>");
01938 if (ws_gui_app->last_word != NULL)
01939 {
01940 str_tmp = g_string_erase(str_tmp,
01941 (long)(tmp2 - str_tmp->str),
01942 14 + strlen(ws_gui_app->last_word));
01943 }
01944 }
01945
01946 while (strstr(str_final->str, "<PATTERN_CLOSED>") != NULL)
01947 {
01948 tmp = strstr(str_final->str, "<PATTERN_CLOSED>");
01949 str_final = g_string_erase(str_final,
01950 (long)(tmp - str_final->str),
01951 16);
01952 str_final = g_string_insert(str_final,
01953 (long)(tmp - str_final->str),
01954 "</font></th></tr></table>");
01955
01956 tmp2 = strstr(str_tmp->str, "<PATTERN_CLOSED>");
01957 str_tmp = g_string_erase(str_tmp,
01958 (long)(tmp2 - str_tmp->str),
01959 16);
01960 }
01961
01962 while (strstr(str_final->str, "<TRANSLATION_OPEN>") != NULL)
01963 {
01964 tmp = strstr(str_final->str, "<TRANSLATION_OPEN>");
01965 str_final = g_string_erase (str_final,
01966 (long)(tmp - str_final->str),
01967 18);
01968 str_final = g_string_insert (str_final,
01969 (long)(tmp - str_final->str),
01970 "<table border=1 width=100%><tr><td background=\"file:/usr/"
01971 "share/pixmaps/ws_tra.png\">");
01972
01973 tmp2 = strstr(str_tmp->str, "<TRANSLATION_OPEN>");
01974 str_tmp = g_string_erase(str_tmp,
01975 (long)(tmp2 - str_tmp->str),
01976 18);
01977 }
01978
01979 while (strstr(str_final->str, "<TRANSLATION_CLOSED>") != NULL)
01980 {
01981 tmp = strstr(str_final->str, "<TRANSLATION_CLOSED>");
01982 str_final = g_string_erase(str_final,
01983 (long)(tmp - str_final->str),
01984 20);
01985 str_final = g_string_insert(str_final,
01986 (long)(tmp - str_final->str),
01987 "</td></tr></table></center>");
01988
01989 tmp2 = strstr(str_tmp->str, "<TRANSLATION_CLOSED>");
01990 str_tmp = g_string_erase(str_tmp,
01991 (long)(tmp2 - str_tmp->str),
01992 20);
01993 }
01994
01995 str_final = g_string_append(str_final,
01996 "</td></tr></table></body></html>");
01997
01998 ws_gui_app->raw_translation = g_string_insert(
01999 ws_gui_app->raw_translation,
02000 0,
02001 str_tmp->str);
02002
02003 returned_value = g_strdup(str_final->str);
02004 g_string_free(str_final, TRUE);
02005 g_string_free(str_tmp, TRUE);
02006 return returned_value;
02007 }
02008
02015 void ws_gui_dictionary_open_bookmark(GtkMenuItem *menuitem, gpointer user_data)
02016 {
02017 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02018
02019 ws_gui_read_active_dictionaries(ws_gui_app);
02020
02021
02022 ws_gui_clear_list(ws_gui_app->ws_gui_w_list->ws_gui_store, ws_gui_app);
02023 g_free(ws_gui_app->last_word);
02024 ws_gui_app->last_word = NULL;
02025
02026 ws_gui_app->bookmark_mode = TRUE;
02027 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
02028 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
02029 "prefix",
02030 "*",
02031 NULL);
02032 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_ON);
02033
02034 if(ws_gui_app->ws_gui_history->len >= 0)
02035 {
02036 ws_gui_clear_array(ws_gui_app->ws_gui_history);
02037 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
02038 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
02039 ws_gui_app->ws_gui_history_cur_pos = -1;
02040 }
02041 ws_gui_check_history(ws_gui_app);
02042 ws_gui_fill_html(" ", ws_gui_app);
02043 ws_gui_app->html_flag = FALSE;
02044 ws_dbus_client_find_word(ws_gui_app->dbus_data, "*");
02045 gtk_widget_hide(ws_gui_app->ws_gui_list_hbox);
02046
02047 ws_gui_search(NULL, ws_gui_app);
02048 }
02049
02056 void ws_gui_dictionary_close_bookmark(GtkMenuItem *menuitem, gpointer user_data)
02057 {
02058 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02059
02060 ws_gui_read_active_dictionaries(ws_gui_app);
02061
02062 g_free(ws_gui_app->last_word);
02063 ws_gui_app->last_word = NULL;
02064
02065 ws_gui_app->bookmark_mode = FALSE;
02066 ws_gui_set_bookmarks_sensitivity(ws_gui_app);
02067 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_BOOKMARK_MODE_OFF);
02068
02069 if(ws_gui_app->ws_gui_history->len >= 0)
02070 {
02071 ws_gui_clear_array(ws_gui_app->ws_gui_history);
02072 ws_gui_clear_array(ws_gui_app->ws_gui_history_list);
02073 ws_gui_clear_array(ws_gui_app->ws_gui_history_iter);
02074 ws_gui_app->ws_gui_history_cur_pos = -1;
02075 }
02076 ws_gui_check_history(ws_gui_app);
02077
02078 ws_gui_fill_html(" ", ws_gui_app);
02079 ws_gui_app->html_flag = TRUE;
02080
02081 if (g_strstrip(ws_gui_app->last_searched) != NULL && ws_gui_app->first_run == FALSE)
02082 {
02083 g_object_set(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
02084 "prefix",
02085 ws_gui_app->last_searched,
02086 NULL);
02087
02088 ws_gui_search(NULL, ws_gui_app);
02089 }
02090 else
02091 {
02092 gtk_list_store_clear(ws_gui_app->ws_gui_w_list->ws_gui_store);
02093 }
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110 }
02111
02118 void ws_gui_dictionary_add_bookmark(GtkMenuItem *menuitem, gpointer user_data)
02119 {
02120 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02121
02122 if (ws_gui_app->last_word != NULL)
02123 {
02124 ws_gui_add_bookmark_dialog(ws_gui_app);
02125 }
02126 else
02127 {
02128 hildon_banner_show_information(GTK_WIDGET(
02129 ws_gui_app->ws_gui_hildon_window),
02130 NULL,
02131 _("ws_ni_select_word_to_add"));
02132 }
02133 }
02134
02141 void ws_gui_dictionary_remove_bookmark(GtkMenuItem *menuitem,
02142 gpointer user_data)
02143 {
02144 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02145
02146 if (ws_gui_app->last_word != NULL)
02147 {
02148 ws_gui_remove_bookmark_dialog(ws_gui_app);
02149
02150 ws_gui_clear_list(ws_gui_app->ws_gui_w_list->ws_gui_store, ws_gui_app);
02151 gchar *temp;
02152 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
02153 "prefix",
02154 &temp,
02155 NULL);
02156 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
02157
02158
02159 }
02160 else
02161 {
02162 hildon_banner_show_information(GTK_WIDGET(
02163 ws_gui_app->ws_gui_hildon_window),
02164 NULL,
02165 _("ws_ni_select_word_to_remove"));
02166 }
02167
02168
02169 }
02170
02178 void ws_gui_dict_availablity(GtkMenuItem *menuitem, gpointer user_data)
02179 {
02180 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02181 if (gconf_client_dir_exists(ws_gui_app->client,
02182 GCONF_PATH, NULL) == TRUE)
02183 {
02184 ws_gui_app->directories = gconf_client_all_dirs(
02185 ws_gui_app->client,
02186 GCONF_PATH,
02187 NULL
02188 );
02189
02190
02191 if(g_slist_length(ws_gui_app->directories) != 0)
02192 {
02193 gtk_widget_set_sensitive(GTK_WIDGET
02194 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
02195 TRUE);
02196 gtk_widget_set_sensitive(GTK_WIDGET
02197 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
02198 TRUE);
02199 gtk_widget_set_sensitive(GTK_WIDGET
02200 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
02201 TRUE);
02202 }
02203
02204 }
02205 else
02206 {
02207 gtk_widget_set_sensitive(GTK_WIDGET
02208 (ws_gui_app->ws_gui_menu->ws_gui_menu_remove_dict),
02209 FALSE);
02210 gtk_widget_set_sensitive(GTK_WIDGET
02211 (ws_gui_app->ws_gui_menu->ws_gui_menu_select_dict),
02212 FALSE);
02213 gtk_widget_set_sensitive(GTK_WIDGET
02214 (ws_gui_app->ws_gui_menu->ws_gui_menu_optimize_dict),
02215 FALSE);
02216 }
02217
02218 }
02219
02225 void ws_gui_set_bookmarks_sensitivity(gpointer user_data)
02226 {
02227 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02228 int i;
02229 gchar *string;
02230 gchar *name;
02231
02232 if (ws_gui_app->bookmark_mode == TRUE)
02233 {
02234 g_slist_free(ws_gui_app->directories_last);
02235 ws_gui_app->directories_last = NULL;
02236 ws_gui_app->directories_last = g_slist_alloc();
02237 g_slist_free(ws_gui_app->directories);
02238 ws_gui_app->directories = g_slist_alloc();
02239
02240 ws_gui_app->directories = gconf_client_all_dirs(
02241 ws_gui_app->client,
02242 GCONF_PATH, NULL);
02243
02244 for (i=0; i<g_slist_length(ws_gui_app->directories); i++)
02245 {
02246 string = (gchar*)g_slist_nth_data(ws_gui_app->directories, i);
02247 name = g_path_get_basename(string);
02248 string = g_strconcat(string, "/active", NULL);
02249
02250 if (gconf_client_get_bool(ws_gui_app->client, string, NULL) == TRUE)
02251 {
02252 ws_gui_app->directories_last =
02253 g_slist_append(ws_gui_app->directories_last,
02254 string);
02255 }
02256
02257 if (strcmp(name, "bookmarks") == 0)
02258 {
02259 gconf_client_set_bool(ws_gui_app->client,
02260 string,
02261 TRUE,
02262 NULL);
02263 }
02264 else
02265 {
02266 gconf_client_set_bool(ws_gui_app->client,
02267 string,
02268 FALSE,
02269 NULL);
02270 }
02271 }
02272
02273
02274 gtk_widget_set_sensitive(
02275 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
02276 FALSE);
02277 gtk_widget_set_sensitive(
02278 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
02279 TRUE);
02280 gtk_widget_set_sensitive(
02281 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
02282 TRUE);
02283 gtk_widget_set_sensitive(
02284 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
02285 FALSE);
02286 gtk_widget_set_sensitive(
02287 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
02288 FALSE);
02289 }
02290 else
02291 {
02292 gchar *bookmarks_path = g_strconcat(GCONF_PATH, "/bookmarks/active", NULL);
02293 if (g_slist_length(ws_gui_app->directories_last) > 0)
02294 {
02295 gconf_client_set_bool(ws_gui_app->client, bookmarks_path, FALSE, NULL);
02296 }
02297
02298 for (i=0; i<g_slist_length(ws_gui_app->directories_last); i++)
02299 {
02300 string = (gchar*)g_slist_nth_data(ws_gui_app->directories_last,
02301 i);
02302
02303 if (string != NULL)
02304 {
02305 gconf_client_set_bool(ws_gui_app->client,
02306 string,
02307 TRUE,
02308 NULL);
02309 }
02310 }
02311
02312
02313 gtk_widget_set_sensitive(
02314 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_open_bookmark),
02315 TRUE);
02316 gtk_widget_set_sensitive(
02317 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_close_bookmark),
02318 FALSE);
02319 gtk_widget_set_sensitive(
02320 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
02321 FALSE);
02322 gtk_widget_set_sensitive(
02323 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
02324 TRUE);
02325 gtk_widget_set_sensitive(
02326 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_dictionaries),
02327 TRUE);
02328
02329 g_free(bookmarks_path);
02330 }
02331
02332 }
02333
02339 void ws_gui_set_bookmark_menu_items(GtkMenuItem *menuitem, gpointer user_data)
02340 {
02341 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02342 if (ws_gui_app->bookmark_mode == TRUE && ws_gui_app->last_word != NULL)
02343 {
02344 gtk_widget_set_sensitive(
02345 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
02346 TRUE);
02347 }
02348 else
02349 {
02350 gtk_widget_set_sensitive(
02351 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_remove_bookmark),
02352 FALSE);
02353 }
02354
02355 if (ws_gui_app->last_word == NULL ||
02356 (ws_gui_app->last_word[0] == '\0') ||
02357 ws_gui_app->bookmark_mode == TRUE)
02358 {
02359 gtk_widget_set_sensitive(
02360 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
02361 FALSE);
02362 }
02363 else
02364 {
02365 gtk_widget_set_sensitive(
02366 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_add_bookmark),
02367 TRUE);
02368 }
02369 }
02376 void ws_gui_read_active_dictionaries(gpointer user_data)
02377 {
02378 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02379
02380
02381 ws_gui_app->directories = gconf_client_all_dirs(ws_gui_app->client,
02382 GCONF_PATH,
02383 NULL);
02384 }
02385
02386 void ws_gui_clear_array(GArray *history)
02387 {
02388 if(history->len >= 0)
02389 {
02390 history = g_array_remove_range(history, 0, history->len);
02391 }
02392 }
02393
02394 void ws_gui_view_cursor_changed(GtkTreeView *treeview, gpointer user_data)
02395 {
02396 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02397 gchar *string;
02398 if (gtk_tree_selection_get_selected(ws_gui_app->ws_gui_w_list->ws_gui_selection,
02399 &ws_gui_app->ws_gui_w_list->ws_gui_model,
02400 &ws_gui_app->ws_gui_w_list->ws_gui_iter))
02401 {
02402 gtk_tree_model_get(ws_gui_app->ws_gui_w_list->ws_gui_model,
02403 &ws_gui_app->ws_gui_w_list->ws_gui_iter,
02404 COL_WORD,
02405 &string,
02406 -1);
02407 if (string != NULL)
02408 {
02409
02410 ws_gui_app->loading = TRUE;
02411 ws_gui_set_toolbar_avail(ws_gui_app);
02412
02413 ws_dbus_client_find_translation(ws_gui_app->dbus_data, string);
02414
02415
02416 g_free(ws_gui_app->last_word);
02417 ws_gui_app->last_word = NULL;
02418 ws_gui_app->last_word = g_strdup (string);
02419
02420 if (ws_gui_app->history_flag == FALSE)
02421 {
02422 ws_gui_history_add(string, ws_gui_app);
02423
02424 }
02425 g_free (string);
02426 }
02427
02428 }
02429
02430
02431 }
02432
02433 void ws_gui_set_toolbar_avail(gpointer user_data) {
02434
02435 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02436
02437 if (ws_gui_app->loading == TRUE)
02438 {
02439 gtk_widget_set_sensitive(
02440 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
02441 TRUE);
02442
02443 gtk_widget_set_sensitive(
02444 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
02445 FALSE);
02446
02447 }
02448 else
02449 {
02450 gtk_widget_set_sensitive(
02451 GTK_WIDGET(ws_gui_app->ws_gui_toobar_button_stop),
02452 FALSE);
02453
02454 gtk_widget_set_sensitive(
02455 GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_menu_search),
02456 TRUE);
02457 }
02458 }
02459
02460 void ws_refresh_search_results(gpointer user_data) {
02461
02462 WSGuiApp* ws_gui_app=(WSGuiApp*)user_data;
02463
02464
02465 gchar *temp;
02466 g_object_get(G_OBJECT(ws_gui_app->ws_gui_hildon_find_toolbar),
02467 "prefix",
02468 &temp,
02469 NULL);
02470
02471 if (ws_gui_app->first_run == FALSE)
02472 {
02473 ws_dbus_client_find_word (ws_gui_app->dbus_data, temp);
02474 }
02475
02476
02477 }