Imported version 0.3-2 v0.3-2
authorRoman Moravcik <roman.moravcik@gmail.com>
Thu, 18 Feb 2010 16:40:00 +0000 (17:40 +0100)
committerRoman Moravcik <roman.moravcik@gmail.com>
Thu, 18 Feb 2010 16:40:00 +0000 (17:40 +0100)
debian/changelog
po/sk.po
src/Makefile.am
src/conf.cpp
src/conf.hpp
src/dictmngr.cpp [new file with mode: 0644]
src/dictmngr.hpp [new file with mode: 0644]
src/libwrapper.cpp
src/libwrapper.hpp
src/mstardict.cpp
src/mstardict.hpp

index 518d83c..00620c4 100644 (file)
@@ -1,3 +1,10 @@
+mstardict (0.3-2) unstable; urgency=low
+
+  * Splited code of dictionary management.
+  * Fixed full-text search.
+
+ -- Roman Moravcik <roman.moravcik@gmail.com>  Wed,  3 Feb 2010 17:49:37 +0100
+
 mstardict (0.3-1) unstable; urgency=low
 
   * Added dictionary management.
index 24bdd21..2695860 100644 (file)
--- a/po/sk.po
+++ b/po/sk.po
@@ -7,35 +7,43 @@ msgid ""
 msgstr ""
 "Project-Id-Version: mstardict\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-02-01 15:35+0100\n"
-"PO-Revision-Date: 2010-02-01 15:36+0100\n"
+"POT-Creation-Date: 2010-02-03 16:08+0100\n"
+"PO-Revision-Date: 2010-02-03 16:08+0100\n"
 "Last-Translator: Roman Moravčík <roman.moravcik@gmail.com>\n"
 "Language-Team: Slovak <sk-i18n@lists.linux.sk>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: ../src/mstardict.cpp:243 ../src/mstardict.cpp:536
+#: ../src/mstardict.cpp:246 ../src/mstardict.cpp:593
 msgid "Dictionaries"
 msgstr "Slovníky"
 
-#: ../src/mstardict.cpp:403
+#: ../src/mstardict.cpp:441
+msgid "Searching"
+msgstr "Hľadám"
+
+#: ../src/mstardict.cpp:443
+msgid "Cancel"
+msgstr "Zrušiť"
+
+#: ../src/mstardict.cpp:475
 msgid "Translation"
 msgstr "Preklad"
 
-#: ../src/mstardict.cpp:450
+#: ../src/mstardict.cpp:518
 msgid "MStardict"
 msgstr "Slovník"
 
 #. no_search_result label
-#: ../src/mstardict.cpp:470 ../src/mstardict.cpp:576
+#: ../src/mstardict.cpp:535 ../src/mstardict.cpp:676
 msgid "No search result"
 msgstr "Žiadne výsledky hľadania"
 
-#: ../src/mstardict.cpp:543
+#: ../src/mstardict.cpp:599
 msgid "Quit"
 msgstr "Zavrieť"
 
-#: ../src/mstardict.cpp:589
+#: ../src/mstardict.cpp:689
 msgid "No loaded dictionary"
 msgstr "Žiadne načítané slovníky"
index cb058e7..c45e984 100644 (file)
@@ -2,6 +2,7 @@ SUBDIRS=lib
 bin_PROGRAMS = mstardict
 mstardict_SOURCES = \
        conf.cpp conf.hpp \
+       dictmngr.cpp dictmngr.hpp \
        libwrapper.cpp libwrapper.hpp \
        mstardict.cpp mstardict.hpp
 
index 81108dd..aad6d0d 100644 (file)
 
 #include "conf.hpp"
 
-MStarDictConf::MStarDictConf()
+Conf::Conf()
 {
     /* get the default client */
     gconf_client = gconf_client_get_default();
 }
 
-MStarDictConf::~MStarDictConf()
+Conf::~Conf()
 {
 }
 
-bool MStarDictConf::GetStringList(const gchar *key,
-                                 std::list < std::string > &list)
+bool Conf::GetStringList(const gchar *key,
+                        std::list < std::string > &list)
 {
     GConfValue *value = NULL;
     GSList *slist = NULL;
@@ -68,8 +68,8 @@ bool MStarDictConf::GetStringList(const gchar *key,
     return true;
 }
 
-bool MStarDictConf::SetStringList(const gchar *key,
-                                 std::list < std::string > &list)
+bool Conf::SetStringList(const gchar *key,
+                        std::list < std::string > &list)
 {
     GSList *slist = NULL;
     gboolean ret = false;
index 4f47eaf..be47fce 100644 (file)
 #include <gconf/gconf.h>
 #include <gconf/gconf-client.h>
 
-class MStarDictConf {
+class Conf {
   private:
     GConfClient *gconf_client;
 
   public:
-    MStarDictConf();
-    ~MStarDictConf();
+    Conf();
+    ~Conf();
 
     bool GetStringList(const gchar *key,
                       std::list < std::string > &list);
diff --git a/src/dictmngr.cpp b/src/dictmngr.cpp
new file mode 100644 (file)
index 0000000..6c346d5
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ *  MStarDict - International dictionary for Maemo.
+ *  Copyright (C) 2010 Roman Moravcik
+ *
+ *  base on code of stardict:
+ *  Copyright (C) 2003-2007 Hu Zheng <huzheng_001@163.com>
+ *
+ *  based on code of sdcv:
+ *  Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <cerrno>
+#include <cstring>
+#include <cstdlib>
+#include <cstdio>
+#include <clocale>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+
+#include <getopt.h>
+#include <string>
+#include <vector>
+#include <memory>
+#include <list>
+
+#include "conf.hpp"
+#include "libwrapper.hpp"
+#include "mstardict.hpp"
+#include "dictmngr.hpp"
+
+enum {
+    BOOKNAME_DICT_INFO_COLUMN,
+    FILENAME_DICT_INFO_COLUMN,
+    N_DICT_INFO_COLUMNS
+};
+
+class GetAllDictList {
+  public:
+    GetAllDictList(std::list < std::string > &dict_all_list_):dict_all_list(dict_all_list_) {
+    } void operator() (const std::string & url, bool disable) {
+       dict_all_list.push_back(url);
+    }
+  private:
+    std::list < std::string > &dict_all_list;
+};
+
+DictMngr::DictMngr(MStarDict *mStarDict)
+{
+    oStarDict = mStarDict;
+}
+
+DictMngr::~DictMngr()
+{
+}
+
+void
+DictMngr::CreateDictMngrDialog()
+{
+    GtkWidget *dialog, *selector;
+    GtkCellRenderer *renderer;
+    HildonTouchSelectorColumn *column;
+    GtkTreeModel *tree_model;
+    GtkTreeIter iter;
+    gboolean iter_valid = TRUE;
+    std::list < std::string > all_dict_list;
+    std::list < std::string > selected_dict_list;
+    GtkListStore *dict_list = NULL;
+
+    dict_list = gtk_list_store_new(N_DICT_INFO_COLUMNS,
+                                  G_TYPE_STRING,       /* bookname */
+                                  G_TYPE_STRING);      /* filename */
+
+    /* create dialog */
+    dialog = gtk_dialog_new();
+    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
+    gtk_window_set_title(GTK_WINDOW(dialog), _("Dictionaries"));
+    gtk_dialog_add_button(GTK_DIALOG(dialog), "OK", GTK_RESPONSE_ACCEPT);
+    gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
+
+    /* dictionary selector */
+    selector = hildon_touch_selector_new();
+    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), selector);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xpad", 10, NULL);
+    column =
+       hildon_touch_selector_append_column(HILDON_TOUCH_SELECTOR
+                                           (selector),
+                                           GTK_TREE_MODEL(dict_list),
+                                           renderer, "text", BOOKNAME_DICT_INFO_COLUMN, NULL);
+    hildon_touch_selector_column_set_text_column(column, 0);
+
+    /* fill list with all available dictionaries */
+    GetAllDictionaryList(all_dict_list);
+    for (std::list < std::string >::iterator i = all_dict_list.begin();
+        i != all_dict_list.end(); ++i) {
+       DictInfo dictinfo;
+
+       dictinfo.load_from_ifo_file(i->c_str(), 0);
+       gtk_list_store_append(dict_list, &iter);
+       gtk_list_store_set(dict_list, &iter,
+                          BOOKNAME_DICT_INFO_COLUMN,
+                          dictinfo.bookname.c_str(), FILENAME_DICT_INFO_COLUMN, i->c_str(), -1);
+    }
+    g_object_unref(dict_list);
+
+    /* set selector mode to multiple */
+    hildon_touch_selector_set_column_selection_mode(HILDON_TOUCH_SELECTOR
+                                                   (selector),
+                                                   HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
+    hildon_touch_selector_unselect_all(HILDON_TOUCH_SELECTOR(selector), BOOKNAME_DICT_INFO_COLUMN);
+
+    /* select all load dictionaries */
+    tree_model =
+       hildon_touch_selector_get_model(HILDON_TOUCH_SELECTOR(selector), BOOKNAME_DICT_INFO_COLUMN);
+    for (iter_valid = gtk_tree_model_get_iter_first(tree_model, &iter);
+        iter_valid; iter_valid = gtk_tree_model_iter_next(tree_model, &iter)) {
+       const gchar *bookname;
+
+       gtk_tree_model_get(tree_model, &iter, BOOKNAME_DICT_INFO_COLUMN, &bookname, -1);
+       for (size_t iLib = 0; iLib < oStarDict->oLibs->query_dictmask.size(); iLib++) {
+           if (!strcmp(oStarDict->oLibs->dict_name(iLib).c_str(), bookname)) {
+               hildon_touch_selector_select_iter(HILDON_TOUCH_SELECTOR
+                                                 (selector),
+                                                 BOOKNAME_DICT_INFO_COLUMN, &iter, FALSE);
+               break;
+           }
+       }
+    }
+
+    /* show dialog */
+    gtk_widget_show_all(GTK_WIDGET(dialog));
+
+    /* run the dialog */
+    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+       GList *selected_dicts = NULL;
+
+       selected_dicts =
+           hildon_touch_selector_get_selected_rows(HILDON_TOUCH_SELECTOR
+                                                   (selector), BOOKNAME_DICT_INFO_COLUMN);
+       if (selected_dicts) {
+           GList *dict = selected_dicts;
+           const gchar *filename;
+
+           while (dict) {
+               gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_model), &iter,
+                                       (GtkTreePath *) (dict->data));
+               gtk_tree_model_get(GTK_TREE_MODEL(tree_model), &iter,
+                                  FILENAME_DICT_INFO_COLUMN, &filename, -1);
+               selected_dict_list.push_back(std::string(filename));
+               dict = dict->next;
+           }
+           g_list_foreach(selected_dicts, (GFunc) gtk_tree_path_free, NULL);
+           g_list_free(selected_dicts);
+       }
+
+       if (oStarDict->oConf->SetStringList("/apps/maemo/mstardict/dict_list", selected_dict_list)) {
+           /* reload dictionaries */
+           ReLoadDictionaries(selected_dict_list);
+
+//         /* trigger re-search */
+//         oStarDict->onSearchEntryChanged(GTK_EDITABLE(oStarDict->search), oStarDict);
+       }
+    }
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
+void
+DictMngr::GetAllDictionaryList(std::list < std::string > &dict_list)
+{
+    strlist_t dicts_dir_list;
+    strlist_t order_list;
+    strlist_t disable_list;
+
+    /* dictionary directory */
+    dicts_dir_list.push_back(std::string("/home/user/MyDocs/mstardict"));
+    for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, GetAllDictList(dict_list));
+}
+
+void
+DictMngr::LoadDictionaries()
+{
+    std::list < std::string > dict_list;
+
+    if (!oStarDict->oConf->GetStringList("/apps/maemo/mstardict/dict_list", dict_list)) {
+       GetAllDictionaryList(dict_list);
+       oStarDict->oConf->SetStringList("/apps/maemo/mstardict/dict_list", dict_list);
+    }
+
+    oStarDict->oLibs->load(dict_list);
+    oStarDict->oLibs->query_dictmask.clear();
+    for (std::list < std::string >::iterator i = dict_list.begin(); i != dict_list.end(); ++i) {
+       size_t iLib;
+       if (oStarDict->oLibs->find_lib_by_filename(i->c_str(), iLib)) {
+           InstantDictIndex instance_dict_index;
+           instance_dict_index.type = InstantDictType_LOCAL;
+           instance_dict_index.index = iLib;
+           oStarDict->oLibs->query_dictmask.push_back(instance_dict_index);
+       }
+    }
+
+    if (oStarDict->oLibs->iCurrentIndex)
+       g_free(oStarDict->oLibs->iCurrentIndex);
+    oStarDict->oLibs->iCurrentIndex =
+       (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * oStarDict->oLibs->query_dictmask.size());
+
+    if (oStarDict->oLibs->query_dictmask.empty())
+       oStarDict->ShowNoDictionary(true);
+}
+
+void
+DictMngr::ReLoadDictionaries(std::list < std::string > &dict_list)
+{
+    oStarDict->oLibs->reload(dict_list, 0, 0);
+    oStarDict->oLibs->query_dictmask.clear();
+    for (std::list < std::string >::iterator i = dict_list.begin(); i != dict_list.end(); ++i) {
+       size_t iLib;
+       if (oStarDict->oLibs->find_lib_by_filename(i->c_str(), iLib)) {
+           InstantDictIndex instance_dict_index;
+           instance_dict_index.type = InstantDictType_LOCAL;
+           instance_dict_index.index = iLib;
+           oStarDict->oLibs->query_dictmask.push_back(instance_dict_index);
+       }
+    }
+
+    if (oStarDict->oLibs->iCurrentIndex)
+       g_free(oStarDict->oLibs->iCurrentIndex);
+    oStarDict->oLibs->iCurrentIndex =
+       (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * oStarDict->oLibs->query_dictmask.size());
+
+    if (oStarDict->oLibs->query_dictmask.empty())
+       oStarDict->ShowNoDictionary(true);
+}
diff --git a/src/dictmngr.hpp b/src/dictmngr.hpp
new file mode 100644 (file)
index 0000000..fbf728b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  MStarDict - International dictionary for Maemo.
+ *  Copyright (C) 2010 Roman Moravcik
+ *
+ *  base on code of stardict:
+ *  Copyright (C) 2003-2007 Hu Zheng <huzheng_001@163.com>
+ *
+ *  based on code of sdcv:
+ *  Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+class MStarDict;
+
+class DictMngr {
+  private:
+    MStarDict *oStarDict;
+
+  public:
+    DictMngr(MStarDict *mStarDict);
+    ~DictMngr();
+
+    void CreateDictMngrDialog();
+    void GetAllDictionaryList(std::list < std::string > &dict_list);
+    void LoadDictionaries();
+    void ReLoadDictionaries(std::list < std::string > &dict_list);
+};
index 62c322a..a10c287 100644 (file)
@@ -175,20 +175,20 @@ Library::ListWords(CurrentIndex *iIndex)
                                                       sizeof(CurrentIndex) *
                                                       query_dictmask.size());
 
-    pMStarDict->ResultsListClear();
+    oStarDict->ResultsListClear();
 
     int iWordCount = 0;
     const gchar *poCurrentWord = poGetCurrentWord(iIndex, query_dictmask, 0);
     if (poCurrentWord) {
-       pMStarDict->ResultsListInsertLast(poCurrentWord);
+       oStarDict->ResultsListInsertLast(poCurrentWord);
        iWordCount++;
 
        while (iWordCount < 30 && (poCurrentWord = poGetNextWord(NULL, iIndex, query_dictmask, 0))) {
-           pMStarDict->ResultsListInsertLast(poCurrentWord);
+           oStarDict->ResultsListInsertLast(poCurrentWord);
            iWordCount++;
        }
     }
-    pMStarDict->ReScroll();
+    oStarDict->ResultsReScroll();
 
     if (iCurrent)
        g_free(iCurrent);
@@ -292,17 +292,17 @@ Library::LookupWithFuzzy(const gchar *sWord)
     gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM];
     bool bFound = false;
 
-    pMStarDict->ResultsListClear();
+    oStarDict->ResultsListClear();
 
     bFound = Libs::LookupWithFuzzy(sWord, fuzzy_reslist, MAX_FUZZY_MATCH_ITEM, query_dictmask);
     if (bFound) {
        SimpleLookup(fuzzy_reslist[0], iCurrentIndex);
 
        for (int i = 0; i < MAX_FUZZY_MATCH_ITEM && fuzzy_reslist[i]; i++) {
-           pMStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
+           oStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
            g_free(fuzzy_reslist[i]);
        }
-       pMStarDict->ReScroll();
+       oStarDict->ResultsReScroll();
     }
 
     return bFound;
@@ -316,15 +316,15 @@ Library::LookupWithRule(const gchar *sWord)
     gchar **ppMatchWord =
        (gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
 
-    pMStarDict->ResultsListClear();
+    oStarDict->ResultsListClear();
 
     iMatchCount = Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask);
     if (iMatchCount) {
        for (gint i = 0; i < iMatchCount; i++)
-           pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+           oStarDict->ResultsListInsertLast(ppMatchWord[i]);
 
        SimpleLookup(ppMatchWord[0], iCurrentIndex);
-       pMStarDict->ReScroll();
+       oStarDict->ResultsReScroll();
 
        for (gint i = 0; i < iMatchCount; i++)
            g_free(ppMatchWord[i]);
@@ -343,15 +343,15 @@ Library::LookupWithRegex(const gchar *sWord)
     gchar **ppMatchWord =
        (gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
 
-    pMStarDict->ResultsListClear();
+    oStarDict->ResultsListClear();
 
     iMatchCount = Libs::LookupWithRegex(sWord, ppMatchWord, query_dictmask);
     if (iMatchCount) {
        for (gint i = 0; i < iMatchCount; i++)
-           pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+           oStarDict->ResultsListInsertLast(ppMatchWord[i]);
 
        SimpleLookup(ppMatchWord[0], iCurrentIndex);
-       pMStarDict->ReScroll();
+       oStarDict->ResultsReScroll();
 
        for (gint i = 0; i < iMatchCount; i++)
            g_free(ppMatchWord[i]);
@@ -362,18 +362,35 @@ Library::LookupWithRegex(const gchar *sWord)
     return bFound;
 }
 
+static void
+LookupProgressDialogUpdate(gpointer data,
+                          double fraction)
+{
+    GtkWidget *dialog = GTK_WIDGET(data);
+    GtkWidget *progress;
+
+    progress = GTK_WIDGET(g_object_get_data(G_OBJECT(dialog), "progress"));
+    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), fraction);
+
+    while (gtk_events_pending())
+       gtk_main_iteration();
+}
+
 bool
 Library::LookupData(const gchar *sWord)
 {
+    GtkWidget *dialog;
     bool cancel = false;
     bool bFound = false;
 
     std::vector < std::vector < gchar * > > reslist(query_dictmask.size());
 
-    pMStarDict->ResultsListClear();
-    pMStarDict->ShowProgressIndicator(true);
 
-    bFound = Libs::LookupData(sWord, &reslist[0], NULL, NULL, &cancel, query_dictmask);
+    oStarDict->ResultsListClear();
+    oStarDict->ShowProgressIndicator(true);
+    dialog = oStarDict->CreateLookupProgressDialog(&cancel);
+
+    bFound = Libs::LookupData(sWord, &reslist[0], LookupProgressDialogUpdate, (gpointer) dialog, &cancel, query_dictmask);
     if (bFound) {
        for (size_t iLib = 0; iLib < query_dictmask.size(); iLib++) {
            if (!reslist[iLib].empty()) {
@@ -381,19 +398,21 @@ Library::LookupData(const gchar *sWord)
 
                for (std::vector < gchar *>::iterator i = reslist[iLib].begin();
                     i != reslist[iLib].end(); ++i) {
-                   pMStarDict->ResultsListInsertLast(*i);
+                   oStarDict->ResultsListInsertLast(*i);
                }
                break;
            }
        }
-       pMStarDict->ReScroll();
+       oStarDict->ResultsReScroll();
     }
-    pMStarDict->ShowProgressIndicator(false);
+    oStarDict->ShowProgressIndicator(false);
+    oStarDict->DestroyLookupProgressDialog(dialog);
     return bFound;
 }
 
-Library::Library():Libs(NULL, FALSE, 0, 0)
+Library::Library(MStarDict *mStarDict):Libs(NULL, FALSE, 0, 0)
 {
+    oStarDict = mStarDict;
     iCurrentIndex = NULL;
 }
 
index 067f35a..2909eca 100644 (file)
@@ -34,6 +34,7 @@
 
 using std::string;
 using std::vector;
+class MStarDict;
 
 //this structure is wrapper and it need for unification
 //results of search whith return Dicts class
@@ -52,8 +53,11 @@ typedef TSearchResultList::iterator PSearchResult;
 //this class is wrapper around Dicts class for easy use
 //of it
 class Library:public Libs {
+  private:
+    MStarDict *oStarDict;
+
   public:
-    Library();
+    Library(MStarDict *mStarDict);
     ~Library();
 
     std::vector < InstantDictIndex > query_dictmask;
@@ -71,8 +75,6 @@ class Library:public Libs {
     bool LookupWithRule(const gchar *sWord);
     bool LookupWithRegex(const gchar *sWord);
     bool LookupData(const gchar *sWord);
-
-  private:
 };
 
 #endif //!_LIBWRAPPER_HPP_
index 5e4e9e2..1ea7cb4 100644 (file)
 #include <list>
 
 #include "conf.hpp"
+#include "dictmngr.hpp"
 #include "libwrapper.hpp"
-#include "file.hpp"
 #include "mstardict.hpp"
 
-MStarDict *pMStarDict;
-
 enum {
     DEF_COLUMN,
     N_COLUMNS
 };
 
-enum {
-    BOOKNAME_DICT_INFO_COLUMN,
-    FILENAME_DICT_INFO_COLUMN,
-    N_DICT_INFO_COLUMNS
-};
-
-class GetAllDictList {
-  public:
-    GetAllDictList(std::list < std::string > &dict_all_list_):dict_all_list(dict_all_list_) {
-    } void operator() (const std::string & url, bool disable) {
-       dict_all_list.push_back(url);
-    }
-  private:
-    std::list < std::string > &dict_all_list;
-};
-
 MStarDict::MStarDict()
 {
     main_window = NULL;
@@ -87,10 +69,13 @@ MStarDict::MStarDict()
                                      G_TYPE_STRING);   /* DEF_COLUMN */
 
     /* initialize configuration */
-    oConf = new MStarDictConf();
+    oConf = new Conf();
+
+    /* initialize dict manager */
+    oDict = new DictMngr(this);
 
     /* initialize stardict library */
-    oLibs = new Library();
+    oLibs = new Library(this);
 }
 
 MStarDict::~MStarDict()
@@ -101,6 +86,9 @@ MStarDict::~MStarDict()
     /* deinitialize stardict library */
     delete oLibs;
 
+    /* deinitialize dict manager */
+    delete oDict;
+
     /* deinitialize configuration */
     delete oConf;
 }
@@ -159,39 +147,33 @@ gboolean
 MStarDict::onSearchEntryChanged(GtkEditable* editable,
                                MStarDict* mStarDict)
 {
-    GtkTreeSelection *selection;
     const gchar *sWord;
     bool bFound = false;
     std::string query;
 
-    sWord = gtk_entry_get_text(GTK_ENTRY(editable));
-
     if (mStarDict->oLibs->query_dictmask.empty())
        return true;
 
+    sWord = gtk_entry_get_text(GTK_ENTRY(editable));
     if (strcmp(sWord, "") == 0) {
        mStarDict->ShowNoResults(true);
     } else {
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mStarDict->results_view));
-       gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);
-
-       /* unselect rows */
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mStarDict->results_view));
-       gtk_tree_selection_unselect_all(selection);
-
-       /* show progress indicator */
-//     mStarDict->ShowProgressIndicator(true);
+       mStarDict->ShowProgressIndicator(true);
+       mStarDict->ResultsUnselectAll(GTK_SELECTION_NONE);
 
        switch (analyse_query(sWord, query)) {
        case qtFUZZY:
            bFound = mStarDict->oLibs->LookupWithFuzzy(query.c_str());
            break;
+
        case qtPATTERN:
            bFound = mStarDict->oLibs->LookupWithRule(query.c_str());
            break;
+
        case qtREGEX:
            bFound = mStarDict->oLibs->LookupWithRegex(query.c_str());
            break;
+
        case qtSIMPLE:
            bFound = mStarDict->oLibs->SimpleLookup(query.c_str(), mStarDict->oLibs->iCurrentIndex);
            if (!bFound) {
@@ -209,24 +191,18 @@ MStarDict::onSearchEntryChanged(GtkEditable* editable,
            }
            mStarDict->oLibs->ListWords(mStarDict->oLibs->iCurrentIndex);
            break;
-       case qtDATA:
-           bFound = mStarDict->oLibs->LookupData(query.c_str());
-           break;
+
        default:
-           /* nothing */ ;
+           break;
        }
 
-       /* unselect selected rows */
-       gtk_tree_selection_unselect_all(selection);
-       gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
-
-       /* hide progress indicator */
-//     mStarDict->ShowProgressIndicator(false);
-
        if (bFound)
            mStarDict->ShowNoResults(false);
        else
            mStarDict->ShowNoResults(true);
+
+       mStarDict->ResultsUnselectAll(GTK_SELECTION_SINGLE);
+       mStarDict->ShowProgressIndicator(false);
     }
 
     return true;
@@ -236,113 +212,7 @@ gboolean
 MStarDict::onDictionariesMenuItemClicked(GtkButton *button,
                                         MStarDict *mStarDict)
 {
-    GtkWidget *dialog, *selector;
-    GtkCellRenderer *renderer;
-    HildonTouchSelectorColumn *column;
-    GtkTreeModel *tree_model;
-    GtkTreeIter iter;
-    gboolean iter_valid = TRUE;
-    std::list < std::string > all_dict_list;
-    std::list < std::string > selected_dict_list;
-    GtkListStore *dict_list = NULL;
-
-    dict_list = gtk_list_store_new(N_DICT_INFO_COLUMNS,
-                                  G_TYPE_STRING,       /* bookname */
-                                  G_TYPE_STRING);      /* filename */
-
-    /* create dialog */
-    dialog = gtk_dialog_new();
-    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
-    gtk_window_set_title(GTK_WINDOW(dialog), _("Dictionaries"));
-    gtk_dialog_add_button(GTK_DIALOG(dialog), "OK", GTK_RESPONSE_ACCEPT);
-    gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
-
-    /* dictionary selector */
-    selector = hildon_touch_selector_new();
-    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), selector);
-
-    renderer = gtk_cell_renderer_text_new();
-    g_object_set(G_OBJECT(renderer), "xpad", 10, NULL);
-    column =
-       hildon_touch_selector_append_column(HILDON_TOUCH_SELECTOR
-                                           (selector),
-                                           GTK_TREE_MODEL(dict_list),
-                                           renderer, "text", BOOKNAME_DICT_INFO_COLUMN, NULL);
-    hildon_touch_selector_column_set_text_column(column, 0);
-
-    /* fill list with all available dictionaries */
-    mStarDict->GetAllDictionaryList(all_dict_list);
-    for (std::list < std::string >::iterator i = all_dict_list.begin();
-        i != all_dict_list.end(); ++i) {
-       DictInfo dictinfo;
-
-       dictinfo.load_from_ifo_file(i->c_str(), 0);
-       gtk_list_store_append(dict_list, &iter);
-       gtk_list_store_set(dict_list, &iter,
-                          BOOKNAME_DICT_INFO_COLUMN,
-                          dictinfo.bookname.c_str(), FILENAME_DICT_INFO_COLUMN, i->c_str(), -1);
-    }
-    g_object_unref(dict_list);
-
-    /* set selector mode to multiple */
-    hildon_touch_selector_set_column_selection_mode(HILDON_TOUCH_SELECTOR
-                                                   (selector),
-                                                   HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
-    hildon_touch_selector_unselect_all(HILDON_TOUCH_SELECTOR(selector), BOOKNAME_DICT_INFO_COLUMN);
-
-    /* select all load dictionaries */
-    tree_model =
-       hildon_touch_selector_get_model(HILDON_TOUCH_SELECTOR(selector), BOOKNAME_DICT_INFO_COLUMN);
-    for (iter_valid = gtk_tree_model_get_iter_first(tree_model, &iter);
-        iter_valid; iter_valid = gtk_tree_model_iter_next(tree_model, &iter)) {
-       const gchar *bookname;
-
-       gtk_tree_model_get(tree_model, &iter, BOOKNAME_DICT_INFO_COLUMN, &bookname, -1);
-       for (size_t iLib = 0; iLib < mStarDict->oLibs->query_dictmask.size(); iLib++) {
-           if (!strcmp(mStarDict->oLibs->dict_name(iLib).c_str(), bookname)) {
-               hildon_touch_selector_select_iter(HILDON_TOUCH_SELECTOR
-                                                 (selector),
-                                                 BOOKNAME_DICT_INFO_COLUMN, &iter, FALSE);
-               break;
-           }
-       }
-    }
-
-    /* show dialog */
-    gtk_widget_show_all(GTK_WIDGET(dialog));
-
-    /* run the dialog */
-    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-       GList *selected_dicts = NULL;
-
-       selected_dicts =
-           hildon_touch_selector_get_selected_rows(HILDON_TOUCH_SELECTOR
-                                                   (selector), BOOKNAME_DICT_INFO_COLUMN);
-       if (selected_dicts) {
-           GList *dict = selected_dicts;
-           const gchar *filename;
-
-           while (dict) {
-               gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_model), &iter,
-                                       (GtkTreePath *) (dict->data));
-               gtk_tree_model_get(GTK_TREE_MODEL(tree_model), &iter,
-                                  FILENAME_DICT_INFO_COLUMN, &filename, -1);
-               selected_dict_list.push_back(std::string(filename));
-               dict = dict->next;
-           }
-           g_list_foreach(selected_dicts, (GFunc) gtk_tree_path_free, NULL);
-           g_list_free(selected_dicts);
-       }
-
-       if (mStarDict->oConf->SetStringList("/apps/maemo/mstardict/dict_list", selected_dict_list)) {
-           /* reload dictionaries */
-           mStarDict->ReLoadDictionaries(selected_dict_list);
-
-           /* trigger re-search */
-           mStarDict->onSearchEntryChanged(GTK_EDITABLE(mStarDict->search), mStarDict);
-       }
-    }
-    gtk_widget_destroy(GTK_WIDGET(dialog));
+    mStarDict->oDict->CreateDictMngrDialog();
     return true;
 }
 
@@ -354,71 +224,57 @@ MStarDict::onQuitMenuItemClicked(GtkButton *button,
     return true;
 }
 
-void
-MStarDict::GetAllDictionaryList(std::list < std::string > &dict_list)
+gboolean
+MStarDict::onLookupProgressDialogResponse(GtkDialog *dialog,
+                                         gint response_id,
+                                         bool *cancel)
 {
-    strlist_t dicts_dir_list;
-    strlist_t order_list;
-    strlist_t disable_list;
+    *cancel = true;
+    return true;
+}
 
-    /* dictionary directory */
-    dicts_dir_list.push_back(std::string("/home/user/MyDocs/mstardict"));
-    for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, GetAllDictList(dict_list));
+gboolean
+MStarDict::onMainWindowKeyPressEvent(GtkWidget *window,
+                                    GdkEventKey *event,
+                                    MStarDict *mStarDict)
+{
+    if (event->type == GDK_KEY_PRESS && event->keyval == GDK_KP_Enter) {
+       mStarDict->SearchWord();
+    }
+    return false;
 }
 
-void
-MStarDict::LoadDictionaries()
+GtkWidget *
+MStarDict::CreateLookupProgressDialog(bool *cancel)
 {
-    std::list < std::string > dict_list;
+    GtkWidget *dialog, *progress;
 
-    if (!oConf->GetStringList("/apps/maemo/mstardict/dict_list", dict_list)) {
-       GetAllDictionaryList(dict_list);
-       oConf->SetStringList("/apps/maemo/mstardict/dict_list", dict_list);
-    }
+    /* create dialog */
+    dialog = gtk_dialog_new();
+    gtk_window_set_title(GTK_WINDOW(dialog), _("Searching"));
+    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_window));
+    gtk_dialog_add_button(GTK_DIALOG(dialog), _("Cancel"), GTK_RESPONSE_OK);
 
-    oLibs->load(dict_list);
-    oLibs->query_dictmask.clear();
-    for (std::list < std::string >::iterator i = dict_list.begin(); i != dict_list.end(); ++i) {
-       size_t iLib;
-       if (oLibs->find_lib_by_filename(i->c_str(), iLib)) {
-           InstantDictIndex instance_dict_index;
-           instance_dict_index.type = InstantDictType_LOCAL;
-           instance_dict_index.index = iLib;
-           oLibs->query_dictmask.push_back(instance_dict_index);
-       }
-    }
+    g_signal_connect(dialog, "response", G_CALLBACK(onLookupProgressDialogResponse), cancel);
 
-    if (oLibs->iCurrentIndex)
-       g_free(oLibs->iCurrentIndex);
-    oLibs->iCurrentIndex =
-       (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * oLibs->query_dictmask.size());
+    /* add progress bar */
+    progress = gtk_progress_bar_new();
+    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), progress);
+    g_object_set_data(G_OBJECT(dialog), "progress", progress);
 
-    if (oLibs->query_dictmask.empty())
-       ShowNoDictionary(true);
+    /* show dialog */
+    gtk_widget_show_all(dialog);
+
+    while (gtk_events_pending())
+       gtk_main_iteration();
+
+    return dialog;
 }
 
 void
-MStarDict::ReLoadDictionaries(std::list < std::string > &dict_list)
+MStarDict::DestroyLookupProgressDialog(GtkWidget *dialog)
 {
-    oLibs->reload(dict_list, 0, 0);
-    oLibs->query_dictmask.clear();
-    for (std::list < std::string >::iterator i = dict_list.begin(); i != dict_list.end(); ++i) {
-       size_t iLib;
-       if (oLibs->find_lib_by_filename(i->c_str(), iLib)) {
-           InstantDictIndex instance_dict_index;
-           instance_dict_index.type = InstantDictType_LOCAL;
-           instance_dict_index.index = iLib;
-           oLibs->query_dictmask.push_back(instance_dict_index);
-       }
-    }
-
-    if (oLibs->iCurrentIndex)
-       g_free(oLibs->iCurrentIndex);
-    oLibs->iCurrentIndex =
-       (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * oLibs->query_dictmask.size());
-
-    if (oLibs->query_dictmask.empty())
-       ShowNoDictionary(true);
+    gtk_widget_destroy(GTK_WIDGET(dialog));
 }
 
 void
@@ -527,6 +383,7 @@ MStarDict::CreateMainWindow()
 
     /* window signals */
     g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
+    g_signal_connect(G_OBJECT(main_window), "key_press_event", G_CALLBACK(onMainWindowKeyPressEvent), this);
 
     /* show all widget instead of alignment */
     gtk_widget_show_all(GTK_WIDGET(main_window));
@@ -561,6 +418,41 @@ MStarDict::CreateMainMenu()
 }
 
 void
+MStarDict::SearchWord()
+{
+    const gchar *sWord;
+    bool bFound = false;
+    std::string query;
+
+    if (oLibs->query_dictmask.empty())
+       return;
+
+    sWord = gtk_entry_get_text(GTK_ENTRY(search));
+    if (strcmp(sWord, "") == 0) {
+       ShowNoResults(true);
+    } else {
+       /* unselect rows */
+       ResultsUnselectAll(GTK_SELECTION_NONE);
+
+       switch (analyse_query(sWord, query)) {
+       case qtDATA:
+           bFound = oLibs->LookupData(query.c_str());
+           break;
+       default:
+           /* nothing */ ;
+       }
+
+       /* unselect selected rows */
+       ResultsUnselectAll(GTK_SELECTION_SINGLE);
+
+       if (bFound)
+           ShowNoResults(false);
+       else
+           ShowNoResults(true);
+    }
+}
+
+void
 MStarDict::ResultsListClear()
 {
     gtk_list_store_clear(results_list);
@@ -575,12 +467,22 @@ MStarDict::ResultsListInsertLast(const gchar *word)
 }
 
 void
-MStarDict::ReScroll()
+MStarDict::ResultsReScroll()
 {
     hildon_pannable_area_scroll_to(HILDON_PANNABLE_AREA(results_view_scroll), -1, 0);
 }
 
 void
+MStarDict::ResultsUnselectAll(GtkSelectionMode mode)
+{
+    GtkTreeSelection *selection;
+
+    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(results_view));
+    gtk_tree_selection_set_mode(selection, mode);
+    gtk_tree_selection_unselect_all(selection);
+}
+
+void
 MStarDict::ShowNoResults(bool bNoResults)
 {
     if (bNoResults) {
@@ -630,13 +532,12 @@ main(int argc,
 
     /* create main window */
     MStarDict mStarDict;
-    pMStarDict = &mStarDict;
     mStarDict.CreateMainWindow();
     mStarDict.CreateMainMenu();
     mStarDict.ShowNoResults(true);
 
-    /* load all dictionaries */
-    mStarDict.LoadDictionaries();
+    /* load dictionaries */
+    mStarDict.oDict->LoadDictionaries();
 
     gtk_main();
     return 0;
index 412ea40..f2af68a 100644 (file)
 #include <gtk/gtk.h>
 #include <hildon/hildon.h>
 
+class Conf;
+class DictMngr;
 class Library;
-class MStarDictConf;
 class MStarDict;
 
-extern MStarDict *pMStarDict;
-
 class MStarDict {
   private:
     GtkWidget *main_window;
@@ -43,8 +42,6 @@ class MStarDict {
 
     GtkListStore *results_list;
 
-    Library *oLibs;
-    MStarDictConf *oConf;
     TSearchResultList results;
 
     static gboolean onResultsViewSelectionChanged(GtkTreeSelection *selection,
@@ -55,24 +52,35 @@ class MStarDict {
                                                  MStarDict *mStarDict);
     static gboolean onQuitMenuItemClicked(GtkButton *button,
                                          MStarDict *mStarDict);
+    static gboolean onLookupProgressDialogResponse(GtkDialog *dialog,
+                                                  gint response_id,
+                                                  bool *cancel);
+    static gboolean onMainWindowKeyPressEvent(GtkWidget *window,
+                                             GdkEventKey *event,
+                                             MStarDict *mStarDict);
 
   public:
      MStarDict();
     ~MStarDict();
 
+    Conf *oConf;
+    DictMngr *oDict;
+    Library *oLibs;
+
+    GtkWidget *CreateLookupProgressDialog(bool *cancel);
+    void DestroyLookupProgressDialog(GtkWidget *dialog);
     void CreateTranslationWindow(const gchar *bookname,
                                 const gchar *def,
                                 const gchar *exp);
     void CreateMainWindow();
     void CreateMainMenu();
 
-    void GetAllDictionaryList(std::list < std::string > &dict_list);
-    void LoadDictionaries();
-    void ReLoadDictionaries(std::list < std::string > &dict_list);
+    void SearchWord();
 
     void ResultsListClear();
     void ResultsListInsertLast(const gchar *word);
-    void ReScroll();
+    void ResultsReScroll();
+    void ResultsUnselectAll(GtkSelectionMode mode);
     void ShowNoResults(bool bNoResults);
     void ShowNoDictionary(bool bNoDictionary);
     void ShowProgressIndicator(bool bShow);