From 3c2659ee8849b33a09c506e1087477c47f5c9e3e Mon Sep 17 00:00:00 2001 From: gadomska_anna Date: Wed, 21 Feb 2007 11:16:39 +0000 Subject: [PATCH] working with .bzip files - gui modifications git-svn-id: file:///svnroot/mdictionary/trunk@84 5bde0345-f819-0410-ac75-e5045f9217cc --- src/gui/include/ws_gui_callbacks.h | 6 + src/gui/include/ws_gui_layout.h | 6 + src/gui/src/ws_gui.c | 4 + src/gui/src/ws_gui_callbacks.c | 25 ++++ src/gui/src/ws_gui_layout.c | 259 ++++++++++++++++-------------------- 5 files changed, 158 insertions(+), 142 deletions(-) diff --git a/src/gui/include/ws_gui_callbacks.h b/src/gui/include/ws_gui_callbacks.h index a0ee18d..4694f3a 100644 --- a/src/gui/include/ws_gui_callbacks.h +++ b/src/gui/include/ws_gui_callbacks.h @@ -62,6 +62,12 @@ void ws_gui_dbus_return_translation (GError *error, GArray *words, gpointer user_data); +/** \brief handle dbus signal and load extracted dictionary + * + */ +void ws_dbus_server_return_extracted_dict2(GError *error, + GArray *words, + gpointer user_data); /** \brief is used to free memory, which was allocated * diff --git a/src/gui/include/ws_gui_layout.h b/src/gui/include/ws_gui_layout.h index 4272a39..ad54796 100644 --- a/src/gui/include/ws_gui_layout.h +++ b/src/gui/include/ws_gui_layout.h @@ -64,6 +64,12 @@ void ws_gui_dictionary_chooser(GtkMenuItem *menuitem, gpointer user_data); void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data); /** + * \brief load dictionary file using given filename + * + */ +gboolean ws_gui_load_dict(gchar *filename, gpointer user_data); + +/** * \brief remove dictionary from application * */ diff --git a/src/gui/src/ws_gui.c b/src/gui/src/ws_gui.c index 8c9cb18..b8cd3fb 100644 --- a/src/gui/src/ws_gui.c +++ b/src/gui/src/ws_gui.c @@ -104,6 +104,10 @@ int main(int argc, char *argv[]) "return_translations", ws_gui_dbus_return_translation, ws_gui_app); + ws_dbus_set_cb (ws_gui_app->dbus_data, + "return_extracted_dict", + ws_dbus_server_return_extracted_dict2, + ws_gui_app); ws_dbus_set_cb (ws_gui_app->dbus_data, "update_progressbar", ws_dbus_progress_bar, diff --git a/src/gui/src/ws_gui_callbacks.c b/src/gui/src/ws_gui_callbacks.c index f682d80..1bb8db9 100644 --- a/src/gui/src/ws_gui_callbacks.c +++ b/src/gui/src/ws_gui_callbacks.c @@ -415,6 +415,31 @@ void ws_gui_dbus_return_translation (GError *error, } +/** this function handles signal from dbus and send recived data to +the translation area + * + * @param error - error message recived from DBUS + * @param words - array with recived data structure + * @param user_data - pointer to data structure + * @return + */ +void ws_dbus_server_return_extracted_dict2(GError *error, + GArray *words, + gpointer user_data) +{ + WSGuiApp* ws_gui_app=(WSGuiApp*)user_data; + + osso_rpc_t data; + + data = g_array_index (words, osso_rpc_t, 0); + if (ws_gui_load_dict(data.value.s, ws_gui_app) == TRUE) + { + gtk_infoprint(GTK_WINDOW( + ws_gui_app->ws_gui_hildon_window), + _("ws_ni_dictionary_added")); + } +} + /** * this function allows to free allocated memory * diff --git a/src/gui/src/ws_gui_layout.c b/src/gui/src/ws_gui_layout.c index 94a3a57..b1f1401 100644 --- a/src/gui/src/ws_gui_layout.c +++ b/src/gui/src/ws_gui_layout.c @@ -1133,7 +1133,7 @@ void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data) WSGuiApp* ws_gui_app=(WSGuiApp*)user_data; GtkWidget *dialog; - GtkWidget *dialog2; + // GtkWidget *dialog2; dialog = hildon_file_chooser_dialog_new( GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), @@ -1148,9 +1148,9 @@ void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data) { gchar *filename; gchar *name; - gchar *path; + // gchar *path; gint len; - gchar *filepath; + // gchar *filepath; gchar* tmp; @@ -1160,9 +1160,9 @@ void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data) len = strlen(filename) - strlen(name) -1; tmp = g_strndup (filename, len); + tmp = g_path_get_basename(tmp); - //gchar *tmp2 = g_strndup(name, (g_strrstr(name, ".") - name)); - + if (g_str_has_suffix(name, ".xdxf") || g_str_has_suffix(name, ".idx") || g_str_has_suffix(name, ".ifo") @@ -1170,155 +1170,26 @@ void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data) || g_str_has_suffix(name, ".dict") || g_str_has_suffix(name, ".dict.dz")) { - len = strlen(filename) - strlen(name) -1; - filepath = g_strndup (filename, len); - path = g_strconcat(GCONF_PATH, "/", tmp, "/path", NULL); - gconf_client_set_string(ws_gui_app->client, - path, - filepath, - NULL); - g_free(path); - path = NULL; - path = g_strconcat(GCONF_PATH, - "/", - tmp, - "/active", - NULL); - gtk_widget_destroy (dialog); - - dialog2 = gtk_message_dialog_new(GTK_WINDOW( - ws_gui_app->ws_gui_hildon_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("ws_ni_dictionaries_activation_question")); - - gtk_widget_show_all(GTK_WIDGET(dialog2)); - - if (gtk_dialog_run (GTK_DIALOG (dialog2)) == - GTK_RESPONSE_YES) - { - gconf_client_set_bool(ws_gui_app->client, - path, - TRUE, - NULL); - } - else - { - gconf_client_set_bool(ws_gui_app->client, - path, - FALSE, - NULL); - } - gtk_widget_destroy (dialog2); - g_free(path); - path = NULL; - - path = g_strconcat(GCONF_PATH, - "/", - tmp, - "/optimized", - NULL); - dialog2 = gtk_message_dialog_new( - GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("ws_ni_dictionaries_optimalization_question")); - - gtk_widget_show_all(GTK_WIDGET(dialog2)); - - if (gtk_dialog_run (GTK_DIALOG (dialog2)) - == GTK_RESPONSE_YES) - { - gconf_client_set_bool(ws_gui_app->client, - path, - TRUE, - NULL); - } - else - { - gconf_client_set_bool(ws_gui_app->client, - path, - FALSE, - NULL); - } - gtk_widget_destroy (dialog2); - - if(ws_gui_app->ws_gui_history->len >= 0) + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "\n:::GUUUUIII GUIII::: check"); + if (ws_gui_load_dict(filename, ws_gui_app) == TRUE) { - ws_gui_clear_array(ws_gui_app->ws_gui_history); - ws_gui_clear_array(ws_gui_app->ws_gui_history_list); - ws_gui_clear_array(ws_gui_app->ws_gui_history_iter); - ws_gui_app->ws_gui_history_cur_pos = -1; - } - ws_gui_check_history(ws_gui_app); - - ws_dbus_notify(ws_gui_app->dbus_data, - WS_DBUS_INFO_CONFIG_CHANGED); - gtk_infoprint(GTK_WINDOW( + gtk_widget_destroy(dialog); + gtk_infoprint(GTK_WINDOW( ws_gui_app->ws_gui_hildon_window), _("ws_ni_dictionary_added")); + } } else if (g_str_has_suffix(name, ".bz2")) { - GtkWidget *dialog_optimize; - GtkWidget *dialog_activate; - gboolean optimize; - gboolean activate; - - gtk_widget_destroy (dialog); - - dialog_activate = gtk_message_dialog_new(GTK_WINDOW( - ws_gui_app->ws_gui_hildon_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("ws_ni_dictionaries_activation_question")); - - - if (gtk_dialog_run (GTK_DIALOG (dialog_activate)) - == GTK_RESPONSE_YES) - { - activate = TRUE; - gtk_widget_destroy (dialog_activate); - } - else - { - activate = FALSE; - gtk_widget_destroy (dialog_activate); - } - - dialog_optimize = gtk_message_dialog_new(GTK_WINDOW( - ws_gui_app->ws_gui_hildon_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("ws_ni_dictionaries_optimalization_question")); - - - if (gtk_dialog_run (GTK_DIALOG (dialog_optimize)) - == GTK_RESPONSE_YES) - { - optimize = TRUE; - gtk_widget_destroy (dialog_optimize); - } - else - { - optimize = FALSE; - gtk_widget_destroy (dialog_optimize); - } - - //funkcja (filename, activate, optimize); - + gtk_widget_destroy(dialog); + ws_dbus_extract_dictionary(ws_gui_app->dbus_data, filename); } else { - gtk_widget_destroy (dialog2); + gtk_widget_destroy (dialog); gtk_infoprint(GTK_WINDOW( ws_gui_app->ws_gui_hildon_window), _("ws_ni_dictionary_wrong_file")); - gtk_widget_destroy (dialog); } } @@ -1329,6 +1200,110 @@ void ws_gui_dictionary_loader(GtkMenuItem *menuitem, gpointer user_data) } +/** this function creates dialog popup window which allows to load dictionary + * + * @param filename - the object which received the signal + * @param user_data - set when the signal handler was connected + */ +gboolean ws_gui_load_dict(gchar *filename, gpointer user_data) +{ + WSGuiApp* ws_gui_app=(WSGuiApp*)user_data; + + GtkWidget *dialog1; + GtkWidget *dialog2; + gchar *name = g_path_get_basename(filename); + gchar *path; + gint len; + gchar *filepath; + + len = strlen(filename) - strlen(name) -1; + gchar *tmp = g_strndup (filename, len);; + tmp = g_path_get_basename(tmp); + + + filepath = g_strndup (filename, len); + path = g_strconcat(GCONF_PATH, "/", tmp, "/path", NULL); + gconf_client_set_string(ws_gui_app->client, + path, + filepath, + NULL); + g_free(path); + path = NULL; + path = g_strconcat(GCONF_PATH, + "/", + tmp, + "/active", + NULL); + + dialog1 = gtk_message_dialog_new(GTK_WINDOW( + ws_gui_app->ws_gui_hildon_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("ws_ni_dictionaries_activation_question")); + + gtk_widget_show_all(GTK_WIDGET(dialog1)); + + if (gtk_dialog_run (GTK_DIALOG (dialog1)) == GTK_RESPONSE_YES) + { + gconf_client_set_bool(ws_gui_app->client, + path, + TRUE, + NULL); + } + else + { + gconf_client_set_bool(ws_gui_app->client, + path, + FALSE, + NULL); + } + gtk_widget_destroy (dialog1); + g_free(path); + path = NULL; + + path = g_strconcat(GCONF_PATH, "/", tmp, "/optimized", NULL); + + dialog2 = gtk_message_dialog_new( + GTK_WINDOW(ws_gui_app->ws_gui_hildon_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("ws_ni_dictionaries_optimalization_question")); + + gtk_widget_show_all(GTK_WIDGET(dialog2)); + + if (gtk_dialog_run (GTK_DIALOG (dialog2)) == GTK_RESPONSE_YES) + { + gconf_client_set_bool(ws_gui_app->client, + path, + TRUE, + NULL); + } + else + { + gconf_client_set_bool(ws_gui_app->client, + path, + FALSE, + NULL); + } + gtk_widget_destroy (dialog2); + + if(ws_gui_app->ws_gui_history->len > 0) + { + ws_gui_clear_array(ws_gui_app->ws_gui_history); + ws_gui_clear_array(ws_gui_app->ws_gui_history_list); + ws_gui_clear_array(ws_gui_app->ws_gui_history_iter); + ws_gui_app->ws_gui_history_cur_pos = -1; + } + ws_gui_check_history(ws_gui_app); + + ws_dbus_notify(ws_gui_app->dbus_data, + WS_DBUS_INFO_CONFIG_CHANGED); + + return TRUE; +} + /** this function creates dialog popup window which allows to remove dictionary * which is no longer used * -- 1.7.9.5