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

index b8c8d0e..4a5f8e4 100644 (file)
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_PREREQ(2.52)
 
-AC_INIT(mstardict, 0.2, roman.moravcik@gmail.com)
+AC_INIT(mstardict, 0.3, roman.moravcik@gmail.com)
 AC_CONFIG_SRCDIR(src/mstardict.cpp)
 
 dnl Don't include maintainer make-rules by default
@@ -33,7 +33,7 @@ AC_FUNC_MMAP
 
 AC_CHECK_LIB(z,zlibVersion,LIBS="$LIBS -lz",[AC_MSG_ERROR([zlib not found])])
 
-PKG_CHECK_MODULES(MSTARDICT, glib-2.0 >= 2.6.1 hildon-1)
+PKG_CHECK_MODULES(MSTARDICT, glib-2.0 >= 2.6.1 hildon-1 gconf-2.0 >= 2.6.2)
 
 MSTARDICT_CFLAGS="-Wall $MSTARDICT_CFLAGS"
 
index 58eefc0..518d83c 100644 (file)
@@ -1,3 +1,9 @@
+mstardict (0.3-1) unstable; urgency=low
+
+  * Added dictionary management.
+
+ -- Roman Moravcik <roman.moravcik@gmail.com>  Tue,  2 Feb 2010 13:01:02 +0100
+
 mstardict (0.2-5) unstable; urgency=low
 
   * Reimplemented lookup with Fuzzy and Rule (not working yet)
index 851e055..084c92f 100644 (file)
@@ -2,12 +2,12 @@ Source: mstardict
 Priority: optional
 Section: user/utilities
 Maintainer: Roman Moravcik <roman.moravcik@gmail.com>
-Build-Depends: debhelper (>= 5.0.0), gettext, libhildon1-dev, libosso-dev, libgtk2.0-dev, libglib2.0-dev, libsigc++-2.0-dev, zlib1g-dev, maemo-optify
+Build-Depends: debhelper (>= 5.0.0), gettext, libhildon1-dev, libosso-dev, libgtk2.0-dev, libglib2.0-dev, libsigc++-2.0-dev, zlib1g-dev, maemo-optify, libgconf2-dev
 Standards-Version: 3.8.3
 
 Package: mstardict
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}
 Description: International dictionary for Maemo
  MStarDict is a StarDict clone written with using Gtk2 for Maemo.
  It can use StarDict DICT files as a word database for translation.
index fddf3df..24bdd21 100644 (file)
--- a/po/sk.po
+++ b/po/sk.po
@@ -7,22 +7,35 @@ msgid ""
 msgstr ""
 "Project-Id-Version: mstardict\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-01-27 11:20+0100\n"
-"PO-Revision-Date: 2010-01-27 11:21+0100\n"
+"POT-Creation-Date: 2010-02-01 15:35+0100\n"
+"PO-Revision-Date: 2010-02-01 15:36+0100\n"
 "Last-Translator: Roman Moravčík <roman.moravcik@gmail.com>\n"
-"Language-Team: Slovak\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:73
+#: ../src/mstardict.cpp:243 ../src/mstardict.cpp:536
+msgid "Dictionaries"
+msgstr "Slovníky"
+
+#: ../src/mstardict.cpp:403
 msgid "Translation"
 msgstr "Preklad"
 
-#: ../src/mstardict.cpp:209
+#: ../src/mstardict.cpp:450
 msgid "MStardict"
 msgstr "Slovník"
 
-#: ../src/mstardict.cpp:217
+#. no_search_result label
+#: ../src/mstardict.cpp:470 ../src/mstardict.cpp:576
 msgid "No search result"
 msgstr "Žiadne výsledky hľadania"
+
+#: ../src/mstardict.cpp:543
+msgid "Quit"
+msgstr "Zavrieť"
+
+#: ../src/mstardict.cpp:589
+msgid "No loaded dictionary"
+msgstr "Žiadne načítané slovníky"
index 1d9e885..cb058e7 100644 (file)
@@ -1,8 +1,9 @@
 SUBDIRS=lib
 bin_PROGRAMS = mstardict
 mstardict_SOURCES = \
-       mstardict.cpp mstardict.hpp \
-       libwrapper.cpp libwrapper.hpp
+       conf.cpp conf.hpp \
+       libwrapper.cpp libwrapper.hpp \
+       mstardict.cpp mstardict.hpp
 
 mstardict_DEPENDENCIES = lib/libstardict.a
 mstardict_LDADD = @MSTARDICT_LIBS@ @LIBINTL@ lib/libstardict.a
diff --git a/src/conf.cpp b/src/conf.cpp
new file mode 100644 (file)
index 0000000..81108dd
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  MStarDict - International dictionary for Maemo.
+ *  Copyright (C) 2010 Roman Moravcik
+ *
+ *  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 <list>
+#include <string>
+
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
+#include "conf.hpp"
+
+MStarDictConf::MStarDictConf()
+{
+    /* get the default client */
+    gconf_client = gconf_client_get_default();
+}
+
+MStarDictConf::~MStarDictConf()
+{
+}
+
+bool MStarDictConf::GetStringList(const gchar *key,
+                                 std::list < std::string > &list)
+{
+    GConfValue *value = NULL;
+    GSList *slist = NULL;
+
+    if (!gconf_client)
+       return false;
+
+    value = gconf_client_get(gconf_client, key, NULL);
+    if (value) {
+       slist = gconf_value_get_list(value);
+
+       if (slist) {
+           GSList *entry = slist;
+
+           list.clear();
+           while (entry) {
+               list.push_back(std::string(gconf_value_get_string((GConfValue *)entry->data)));
+               entry = entry->next;
+           }
+       }
+       gconf_value_free(value);
+    } else {
+       return false;
+    }
+    return true;
+}
+
+bool MStarDictConf::SetStringList(const gchar *key,
+                                 std::list < std::string > &list)
+{
+    GSList *slist = NULL;
+    gboolean ret = false;
+
+    if (!gconf_client)
+       return false;
+
+    for (std::list < std::string >::iterator i = list.begin(); i != list.end(); ++i) {
+       slist = g_slist_append(slist, (gpointer) i->c_str());
+    }
+
+    if (slist) {
+       ret = gconf_client_set_list(gconf_client, key, GCONF_VALUE_STRING, slist, NULL);
+       g_slist_free(slist);
+    }
+    return ret;
+}
diff --git a/src/conf.hpp b/src/conf.hpp
new file mode 100644 (file)
index 0000000..4f47eaf
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  MStarDict - International dictionary for Maemo.
+ *  Copyright (C) 2010 Roman Moravcik
+ *
+ *  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
+ */
+
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
+class MStarDictConf {
+  private:
+    GConfClient *gconf_client;
+
+  public:
+    MStarDictConf();
+    ~MStarDictConf();
+
+    bool GetStringList(const gchar *key,
+                      std::list < std::string > &list);
+    bool SetStringList(const gchar *key,
+                      std::list < std::string > &list);
+};
index fcb53fb..62c322a 100644 (file)
@@ -1,21 +1,26 @@
-/* 
- * This file part of sdcv - console version of Stardict program
- * http://sdcv.sourceforge.net
- * Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
+/*
+ *  MStarDict - International dictionary for Maemo.
+ *  Copyright (C) 2010 Roman Moravcik
  *
- * 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.
+ *  base on code of stardict:
+ *  Copyright (C) 2003-2007 Hu Zheng <huzheng_001@163.com>
  *
- * 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 Library General Public License for more details.
+ *  based on code of sdcv:
+ *  Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
  *
- * 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.
+ *  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 "libwrapper.hpp"
 #include "mstardict.hpp"
 
-static std::string xdxf2text(const char *p)
+static
+std::string xdxf2text(const char *p)
 {
-       std::string res;
-       for (; *p; ++p) {
-               if (*p!='<') {
-                       if (g_str_has_prefix(p, "&gt;")) {
-                               res+=">";
-                               p+=3;
-                       } else if (g_str_has_prefix(p, "&lt;")) {
-                               res+="<";
-                               p+=3;
-                       } else if (g_str_has_prefix(p, "&amp;")) {
-                               res+="&";
-                               p+=4;
-                       } else if (g_str_has_prefix(p, "&quot;")) {
-                               res+="\"";
-                               p+=5;
-                       } else
-                               res+=*p;
-                       continue;
-               }
-
-               const char *next=strchr(p, '>');
-               if (!next)
-                       continue;
-
-               std::string name(p+1, next-p-1);
-
-               if (name=="abr")
-                       res+="";
-               else if (name=="/abr")
-                       res+="";
-               else if (name=="k") {
-                       const char *begin=next;
-                       if ((next=strstr(begin, "</k>"))!=NULL)
-                               next+=sizeof("</k>")-1-1;
-                       else
-                               next=begin;
-               } else if (name=="b")
-                       res+="";
-               else if (name=="/b")
-                       res+="";
-               else if (name=="i")
-                       res+="";
-               else if (name=="/i")
-                       res+="";
-               else if (name=="tr")
-                       res+="[";
-               else if (name=="/tr")
-                       res+="]";
-               else if (name=="ex")
-                       res+="";
-               else if (name=="/ex")
-                       res+="";
-               else if (!name.empty() && name[0]=='c' && name!="co") {
-                       std::string::size_type pos=name.find("code");
-                       if (pos!=std::string::size_type(-1)) {
-                               pos+=sizeof("code=\"")-1;
-                               std::string::size_type end_pos=name.find("\"");
-                               std::string color(name, pos, end_pos-pos);
-                               res+="";
-                       } else {
-                               res+="";
-                       }
-               } else if (name=="/c")
-                       res+="";
-
-               p=next;
+    std::string res;
+    for (; *p; ++p) {
+       if (*p != '<') {
+           if (g_str_has_prefix(p, "&gt;")) {
+               res += ">";
+               p += 3;
+           } else if (g_str_has_prefix(p, "&lt;")) {
+               res += "<";
+               p += 3;
+           } else if (g_str_has_prefix(p, "&amp;")) {
+               res += "&";
+               p += 4;
+           } else if (g_str_has_prefix(p, "&quot;")) {
+               res += "\"";
+               p += 5;
+           } else
+               res += *p;
+           continue;
        }
-       return res;
+
+       const char *next = strchr(p, '>');
+       if (!next)
+           continue;
+
+       std::string name(p + 1, next - p - 1);
+
+       if (name == "abr")
+           res += "";
+       else if (name == "/abr")
+           res += "";
+       else if (name == "k") {
+           const char *begin = next;
+           if ((next = strstr(begin, "</k>")) != NULL)
+               next += sizeof("</k>") - 1 - 1;
+           else
+               next = begin;
+       } else if (name == "b")
+           res += "";
+       else if (name == "/b")
+           res += "";
+       else if (name == "i")
+           res += "";
+       else if (name == "/i")
+           res += "";
+       else if (name == "tr")
+           res += "[";
+       else if (name == "/tr")
+           res += "]";
+       else if (name == "ex")
+           res += "";
+       else if (name == "/ex")
+           res += "";
+       else if (!name.empty() && name[0] == 'c' && name != "co") {
+           std::string::size_type pos = name.find("code");
+           if (pos != std::string::size_type(-1)) {
+               pos += sizeof("code=\"") - 1;
+               std::string::size_type end_pos = name.find("\"");
+               std::string color(name, pos, end_pos - pos);
+               res += "";
+           } else {
+               res += "";
+           }
+       } else if (name == "/c")
+           res += "";
+
+       p = next;
+    }
+    return res;
 }
 
-static string parse_data(const gchar *data)
+static
+string parse_data(const gchar *data)
 {
-       if (!data)
-               return "";
-
-       string res;
-       guint32 data_size, sec_size=0;
-       gchar *m_str;
-       const gchar *p=data;
-       data_size=*((guint32 *)p);
-       p+=sizeof(guint32);
-       while (guint32(p - data)<data_size) {
-               switch (*p++) {
-               case 'g':
-               case 'm':
-               case 'l': //need more work...
-                       sec_size = strlen(p);
-                       if (sec_size) {
-                               res+="\n";
-                               m_str = g_strndup(p, sec_size);
-                               res += m_str;
-                               g_free(m_str);
-                       }
-                       sec_size++;
-                       break;
-               case 'x':
-                       sec_size = strlen(p);
-                       if (sec_size) {
-                               res+="\n";
-                               m_str = g_strndup(p, sec_size);
-                               res += xdxf2text(m_str);
-                               g_free(m_str);
-                       }
-                       sec_size++;
-                       break;
-               case 't':
-                       sec_size = strlen(p);
-                       if(sec_size){
-                               res+="\n";
-                               m_str = g_strndup(p, sec_size);
-                               res += "["+string(m_str)+"]";
-                               g_free(m_str);
-                       }
-                       sec_size++;
-                       break;
-               case 'y':
-                       sec_size = strlen(p);
-                       sec_size++;                             
-                       break;
-               case 'W':
-               case 'P':
-                       sec_size=*((guint32 *)p);
-                       sec_size+=sizeof(guint32);
-                       break;
-               }
-               p += sec_size;
+    if (!data)
+       return "";
+
+    string res;
+    guint32 data_size, sec_size = 0;
+    gchar *m_str;
+    const gchar *p = data;
+    data_size = *((guint32 *) p);
+    p += sizeof(guint32);
+    while (guint32(p - data) < data_size) {
+       switch (*p++) {
+       case 'g':
+       case 'm':
+       case 'l':               //need more work...
+           sec_size = strlen(p);
+           if (sec_size) {
+               res += "\n";
+               m_str = g_strndup(p, sec_size);
+               res += m_str;
+               g_free(m_str);
+           }
+           sec_size++;
+           break;
+       case 'x':
+           sec_size = strlen(p);
+           if (sec_size) {
+               res += "\n";
+               m_str = g_strndup(p, sec_size);
+               res += xdxf2text(m_str);
+               g_free(m_str);
+           }
+           sec_size++;
+           break;
+       case 't':
+           sec_size = strlen(p);
+           if (sec_size) {
+               res += "\n";
+               m_str = g_strndup(p, sec_size);
+               res += "[" + string(m_str) + "]";
+               g_free(m_str);
+           }
+           sec_size++;
+           break;
+       case 'y':
+           sec_size = strlen(p);
+           sec_size++;
+           break;
+       case 'W':
+       case 'P':
+           sec_size = *((guint32 *) p);
+           sec_size += sizeof(guint32);
+           break;
        }
+       p += sec_size;
+    }
 
-       return res;
+    return res;
 }
 
-void Library::ListWords(CurrentIndex* iIndex)
+void
+Library::ListWords(CurrentIndex *iIndex)
 {
-       CurrentIndex *iCurrent = (CurrentIndex*)g_memdup(iIndex, sizeof(CurrentIndex)*query_dictmask.size());
+    CurrentIndex *iCurrent = (CurrentIndex *) g_memdup(iIndex,
+                                                      sizeof(CurrentIndex) *
+                                                      query_dictmask.size());
 
-       pMStarDict->ResultsListClear();
+    pMStarDict->ResultsListClear();
 
-       int iWordCount=0;
-       const gchar * poCurrentWord = poGetCurrentWord(iIndex, query_dictmask, 0);
-       if (poCurrentWord) {
-               pMStarDict->ResultsListInsertLast(poCurrentWord);
-               iWordCount++;
+    int iWordCount = 0;
+    const gchar *poCurrentWord = poGetCurrentWord(iIndex, query_dictmask, 0);
+    if (poCurrentWord) {
+       pMStarDict->ResultsListInsertLast(poCurrentWord);
+       iWordCount++;
 
-               while (iWordCount < 30 && (poCurrentWord = poGetNextWord(NULL, iIndex, query_dictmask, 0))) {
-                       pMStarDict->ResultsListInsertLast(poCurrentWord);
-                       iWordCount++;
-               }
+       while (iWordCount < 30 && (poCurrentWord = poGetNextWord(NULL, iIndex, query_dictmask, 0))) {
+           pMStarDict->ResultsListInsertLast(poCurrentWord);
+           iWordCount++;
        }
-       pMStarDict->ReScroll();
+    }
+    pMStarDict->ReScroll();
 
-       if (iCurrent)
-               g_free (iCurrent);
+    if (iCurrent)
+       g_free(iCurrent);
 }
 
-bool Library::BuildResultData(std::vector<InstantDictIndex> &dictmask, const char* sWord, CurrentIndex *iIndex, int iLib, TSearchResultList& res_list)
+bool
+Library::BuildResultData(std::vector < InstantDictIndex > &dictmask,
+                        const char *sWord,
+                        CurrentIndex *iIndex,
+                        int iLib,
+                        TSearchResultList &res_list)
 {
-       int iRealLib;
-       bool bFound = false, bLookupWord = false, bLookupSynonymWord = false;
-       gint nWord=0, count=0, i=0, j=0;
-
-       iRealLib = dictmask[iLib].index;
-
-       bLookupWord = LookupWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
-       if (!bLookupWord)
-               bLookupWord = LookupSimilarWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
-       if (!bLookupWord)
-               bLookupWord = SimpleLookupWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
-
-       bLookupSynonymWord = LookupSynonymWord(sWord, iIndex[iLib].synidx, iIndex[iLib].synidx_suggest, iRealLib, 0);
-       if (!bLookupSynonymWord)
-               bLookupSynonymWord = LookupSynonymSimilarWord(sWord, iIndex[iLib].synidx, iIndex[iLib].synidx_suggest, iRealLib, 0);
-       if (!bLookupSynonymWord)
-               bLookupSynonymWord = SimpleLookupSynonymWord(sWord, iIndex[iLib].synidx, iIndex[iLib].synidx_suggest, iRealLib, 0);
-
-       g_debug ("bookname: %s, iLib: %d, iRealLib: %d, str: %s", dict_name(iLib).c_str(), iLib, iRealLib, sWord);
-
-       if (bLookupWord || bLookupSynonymWord) {
-               if (bLookupWord)
-                       nWord++;
-
-               if (bLookupSynonymWord)
-                       nWord+=GetOrigWordCount(iIndex[iLib].synidx, iRealLib, false);
-
-               if (bLookupWord) {
-                       count = GetOrigWordCount(iIndex[iLib].idx, iRealLib, true);
-                       for (i=0;i<count;i++) {
-                               res_list.push_back(TSearchResult(dict_name(iLib),
-                                                                poGetWord(iIndex[iLib].idx, iRealLib, 0),
-                                                                parse_data(poGetOrigWordData(iIndex[iLib].idx+i, iRealLib))));
-                       }
-                       i = 1;
-               } else {
-                       i = 0;
-               }
-               for (j = 0; i < nWord; i++, j++) {
-                               res_list.push_back(TSearchResult(dict_name(iLib),
-                                                                poGetWord(iIndex[iLib].synidx+j, iRealLib, 0),
-                                                                parse_data(poGetOrigWordData(iIndex[iLib].synidx+j, iRealLib))));
-               }
-
-               bFound = true;
+    int iRealLib;
+    bool bFound = false, bLookupWord = false, bLookupSynonymWord = false;
+    gint nWord = 0, count = 0, i = 0, j = 0;
+
+    iRealLib = dictmask[iLib].index;
+
+    bLookupWord = LookupWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
+    if (!bLookupWord)
+       bLookupWord =
+           LookupSimilarWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
+    if (!bLookupWord)
+       bLookupWord =
+           SimpleLookupWord(sWord, iIndex[iLib].idx, iIndex[iLib].idx_suggest, iRealLib, 0);
+
+    bLookupSynonymWord =
+       LookupSynonymWord(sWord, iIndex[iLib].synidx, iIndex[iLib].synidx_suggest, iRealLib, 0);
+    if (!bLookupSynonymWord)
+       bLookupSynonymWord =
+           LookupSynonymSimilarWord(sWord, iIndex[iLib].synidx,
+                                    iIndex[iLib].synidx_suggest, iRealLib, 0);
+    if (!bLookupSynonymWord)
+       bLookupSynonymWord =
+           SimpleLookupSynonymWord(sWord, iIndex[iLib].synidx,
+                                   iIndex[iLib].synidx_suggest, iRealLib, 0);
+
+    if (bLookupWord || bLookupSynonymWord) {
+       if (bLookupWord)
+           nWord++;
+
+       if (bLookupSynonymWord)
+           nWord += GetOrigWordCount(iIndex[iLib].synidx, iRealLib, false);
+
+       if (bLookupWord) {
+           count = GetOrigWordCount(iIndex[iLib].idx, iRealLib, true);
+           for (i = 0; i < count; i++) {
+               res_list.push_back(TSearchResult(dict_name(iLib),
+                                                poGetWord(iIndex[iLib].idx, iRealLib,
+                                                          0),
+                                                parse_data
+                                                (poGetOrigWordData
+                                                 (iIndex[iLib].idx + i, iRealLib))));
+           }
+           i = 1;
+       } else {
+           i = 0;
+       }
+       for (j = 0; i < nWord; i++, j++) {
+           res_list.push_back(TSearchResult(dict_name(iLib),
+                                            poGetWord(iIndex[iLib].synidx + j,
+                                                      iRealLib, 0),
+                                            parse_data(poGetOrigWordData
+                                                       (iIndex[iLib].synidx + j, iRealLib))));
        }
 
-       return bFound;
+       bFound = true;
+    }
+
+    return bFound;
 }
 
-bool Library::SimpleLookup(const gchar* sWord, CurrentIndex* piIndex)
+bool
+Library::SimpleLookup(const gchar *sWord,
+                     CurrentIndex *piIndex)
 {
-       CurrentIndex *iIndex;
-       TSearchResultList results;
-       bool bFound = false;
+    CurrentIndex *iIndex;
+    TSearchResultList results;
+    bool bFound = false;
 
-       if (!piIndex)
-               iIndex = (CurrentIndex *)g_malloc(sizeof(CurrentIndex) * query_dictmask.size());
-       else
-               iIndex = piIndex;
+    if (!piIndex)
+       iIndex = (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * query_dictmask.size());
+    else
+       iIndex = piIndex;
 
-       for (size_t iLib=0; iLib<query_dictmask.size(); iLib++) {
-               bFound = BuildResultData(query_dictmask, sWord, iIndex, iLib, results);
-       }
+    for (size_t iLib = 0; iLib < query_dictmask.size(); iLib++) {
+       if (BuildResultData(query_dictmask, sWord, iIndex, iLib, results))
+           bFound = true;
+    }
 
-       if (!piIndex)
-               g_free(iIndex);
+    if (!piIndex)
+       g_free(iIndex);
 
-       return bFound;
+    return bFound;
 }
 
-void Library::LookupWithFuzzy(const gchar* sWord)
+bool
+Library::LookupWithFuzzy(const gchar *sWord)
 {
-       static const int MAX_FUZZY_MATCH_ITEM=100;
-       gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM];
-       bool bFound = false;
+    static const int MAX_FUZZY_MATCH_ITEM = 100;
+    gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM];
+    bool bFound = false;
 
-       pMStarDict->ResultsListClear();
+    pMStarDict->ResultsListClear();
 
-       bFound = Libs::LookupWithFuzzy(sWord, fuzzy_reslist, MAX_FUZZY_MATCH_ITEM, query_dictmask);
-       if (bFound) {
-               SimpleLookup(fuzzy_reslist[0], iCurrentIndex);
+    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]);
-                       g_free(fuzzy_reslist[i]);
-               }
-               pMStarDict->ReScroll();
+       for (int i = 0; i < MAX_FUZZY_MATCH_ITEM && fuzzy_reslist[i]; i++) {
+           pMStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
+           g_free(fuzzy_reslist[i]);
        }
+       pMStarDict->ReScroll();
+    }
+
+    return bFound;
 }
 
-void Library::LookupWithRule(const gchar* sWord)
+bool
+Library::LookupWithRule(const gchar *sWord)
 {
-       gint iMatchCount=0;
-       gchar **ppMatchWord = (gchar **)g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
+    gint iMatchCount = 0;
+    bool bFound = false;
+    gchar **ppMatchWord =
+       (gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
 
-       pMStarDict->ResultsListClear();
+    pMStarDict->ResultsListClear();
 
-       iMatchCount=Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask);
-       if (iMatchCount) {
-               for (gint i=0; i<iMatchCount; i++)
-                       pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+    iMatchCount = Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask);
+    if (iMatchCount) {
+       for (gint i = 0; i < iMatchCount; i++)
+           pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
 
-               SimpleLookup(ppMatchWord[0], iCurrentIndex);
-               pMStarDict->ReScroll();
+       SimpleLookup(ppMatchWord[0], iCurrentIndex);
+       pMStarDict->ReScroll();
 
-               for(gint i=0; i<iMatchCount; i++)
-                       g_free(ppMatchWord[i]);
-       }
-       g_free(ppMatchWord);
+       for (gint i = 0; i < iMatchCount; i++)
+           g_free(ppMatchWord[i]);
+
+       bFound = true;
+    }
+    g_free(ppMatchWord);
+    return bFound;
 }
 
-void Library::LookupData(const string &str, TSearchResultList& res_list)
+bool
+Library::LookupWithRegex(const gchar *sWord)
 {
-       bool cancel = false;
-       std::vector<gchar *> drl[query_dictmask.size()];
-       if (!Libs::LookupData(str.c_str(), drl, NULL, NULL, &cancel, query_dictmask))
-               return;
-       for (size_t iLib=0; iLib<query_dictmask.size(); iLib++)
-               for (std::vector<gchar *>::size_type j=0; j<drl[iLib].size(); ++j) {
-//                     SimpleLookup(drl[iLib][j], res_list);
-                       g_free(drl[iLib][j]);
+    gint iMatchCount = 0;
+    bool bFound = false;
+    gchar **ppMatchWord =
+       (gchar **) g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
+
+    pMStarDict->ResultsListClear();
+
+    iMatchCount = Libs::LookupWithRegex(sWord, ppMatchWord, query_dictmask);
+    if (iMatchCount) {
+       for (gint i = 0; i < iMatchCount; i++)
+           pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+
+       SimpleLookup(ppMatchWord[0], iCurrentIndex);
+       pMStarDict->ReScroll();
+
+       for (gint i = 0; i < iMatchCount; i++)
+           g_free(ppMatchWord[i]);
+
+       bFound = true;
+    }
+    g_free(ppMatchWord);
+    return bFound;
+}
+
+bool
+Library::LookupData(const gchar *sWord)
+{
+    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);
+    if (bFound) {
+       for (size_t iLib = 0; iLib < query_dictmask.size(); iLib++) {
+           if (!reslist[iLib].empty()) {
+               SimpleLookup(reslist[iLib][0], iCurrentIndex);
+
+               for (std::vector < gchar *>::iterator i = reslist[iLib].begin();
+                    i != reslist[iLib].end(); ++i) {
+                   pMStarDict->ResultsListInsertLast(*i);
                }
+               break;
+           }
+       }
+       pMStarDict->ReScroll();
+    }
+    pMStarDict->ShowProgressIndicator(false);
+    return bFound;
 }
 
-Library::Library () : Libs (NULL, FALSE, 0, 0)
+Library::Library():Libs(NULL, FALSE, 0, 0)
 {
-       iCurrentIndex = NULL;
+    iCurrentIndex = NULL;
 }
 
-Library::~Library ()
+Library::~Library()
 {
-       if (iCurrentIndex)
-               g_free (iCurrentIndex);
+    if (iCurrentIndex)
+       g_free(iCurrentIndex);
 }
index 20a7acc..067f35a 100644 (file)
@@ -1,3 +1,28 @@
+/*
+ *  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
+ */
+
 #ifndef _LIBWRAPPER_HPP_
 #define _LIBWRAPPER_HPP_
 
@@ -13,37 +38,41 @@ using std::vector;
 //this structure is wrapper and it need for unification
 //results of search whith return Dicts class
 struct TSearchResult {
-       string bookname;
-       string def;
-       string exp;
-
-       TSearchResult(const string& bookname_, const string& def_, const string& exp_)
-               : bookname(bookname_), def(def_), exp(exp_)
-               {
-               }
-};
+    string bookname;
+    string def;
+    string exp;
+
+    TSearchResult(const string &bookname_, const string &def_, const string &exp_)
+    :bookname(bookname_), def(def_), exp(exp_) {
+}};
 
-typedef vector<TSearchResult> TSearchResultList;
+typedef vector < TSearchResult > TSearchResultList;
 typedef TSearchResultList::iterator PSearchResult;
 
 //this class is wrapper around Dicts class for easy use
 //of it
-class Library : public Libs {
-public:
-       Library();
-       ~Library();
-
-       std::vector<InstantDictIndex> query_dictmask;
-       CurrentIndex *iCurrentIndex;
-
-       void ListWords(CurrentIndex* iIndex);
-       bool BuildResultData(std::vector<InstantDictIndex> &dictmask, const char* sWord, CurrentIndex *iIndex, int iLib, TSearchResultList& res_list);
-
-       bool SimpleLookup(const gchar* sWord, CurrentIndex* piIndex);
-       void LookupWithFuzzy(const gchar* sWord);
-       void LookupWithRule(const gchar* sWord);
-private:
-       void LookupData(const string &str, TSearchResultList& res_list);
+class Library:public Libs {
+  public:
+    Library();
+    ~Library();
+
+    std::vector < InstantDictIndex > query_dictmask;
+    CurrentIndex *iCurrentIndex;
+
+    void ListWords(CurrentIndex *iIndex);
+    bool BuildResultData(std::vector < InstantDictIndex > &dictmask,
+                        const char *sWord,
+                        CurrentIndex *iIndex,
+                        int iLib,
+                        TSearchResultList &res_list);
+    bool SimpleLookup(const gchar *sWord,
+                     CurrentIndex *piIndex);
+    bool LookupWithFuzzy(const gchar *sWord);
+    bool LookupWithRule(const gchar *sWord);
+    bool LookupWithRegex(const gchar *sWord);
+    bool LookupData(const gchar *sWord);
+
+  private:
 };
 
-#endif//!_LIBWRAPPER_HPP_
+#endif //!_LIBWRAPPER_HPP_
index f52d81e..5e4e9e2 100644 (file)
@@ -1,17 +1,23 @@
 /*
  *  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
@@ -38,7 +44,9 @@
 #include <string>
 #include <vector>
 #include <memory>
+#include <list>
 
+#include "conf.hpp"
 #include "libwrapper.hpp"
 #include "file.hpp"
 #include "mstardict.hpp"
 MStarDict *pMStarDict;
 
 enum {
-       DEF_COLUMN,
-       N_COLUMNS
+    DEF_COLUMN,
+    N_COLUMNS
 };
 
-MStarDict::MStarDict ()
+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()
 {
-       label_widget = NULL;
-       results_widget = NULL;
-       results_view = NULL;
-       results_view_scroll = NULL;
+    main_window = NULL;
+    label_widget = NULL;
+    results_widget = NULL;
+    results_view = NULL;
+    results_view_scroll = NULL;
 
-       /* create list of ressults */
-       results_list = gtk_list_store_new (N_COLUMNS,
-                                          G_TYPE_STRING);      /* DEF_COLUMN */
+    /* create list of ressults */
+    results_list = gtk_list_store_new(N_COLUMNS,
+                                     G_TYPE_STRING);   /* DEF_COLUMN */
 
-       /* initialize stardict library */
-       oLibs = new Library ();
+    /* initialize configuration */
+    oConf = new MStarDictConf();
+
+    /* initialize stardict library */
+    oLibs = new Library();
 }
 
-MStarDict::~MStarDict ()
+MStarDict::~MStarDict()
 {
-       /* destroy list of results */
-       g_object_unref (results_list);
+    /* destroy list of results */
+    g_object_unref(results_list);
+
+    /* deinitialize stardict library */
+    delete oLibs;
 
-       /* deinitialize stardict library */
-       delete oLibs;
+    /* deinitialize configuration */
+    delete oConf;
 }
 
 gboolean
-MStarDict::onResultsViewSelectionChanged (GtkTreeSelection *selection,
-                                             MStarDict *mStarDict)
+MStarDict::onResultsViewSelectionChanged(GtkTreeSelection *selection,
+                                        MStarDict *mStarDict)
 {
-       GtkTreeModel *model;
-       GtkTreeIter iter;
-       char *bookname, *def, *exp;
-       const gchar *sWord;
-       bool bFound = false;
-
-       if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
-               /* unselect selected rows */
-               gtk_tree_selection_unselect_all (selection);
-
-               gtk_tree_model_get (model, &iter, DEF_COLUMN, &sWord, -1);
-
-               /* clear previous search results */
-               mStarDict->results.clear();
-
-               for (size_t iLib=0; iLib<mStarDict->oLibs->query_dictmask.size(); iLib++) {
-                       bFound = mStarDict->oLibs->BuildResultData(mStarDict->oLibs->query_dictmask,
-                                                                  sWord,
-                                                                  mStarDict->oLibs->iCurrentIndex,
-                                                                  iLib,
-                                                                  mStarDict->results);
-               }
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    char *bookname, *def, *exp;
+    const gchar *sWord;
+    bool bFound = false;
+
+    if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+       /* unselect selected rows */
+       gtk_tree_selection_unselect_all(selection);
+
+       gtk_tree_model_get(model, &iter, DEF_COLUMN, &sWord, -1);
+
+       /* clear previous search results */
+       mStarDict->results.clear();
+
+       for (size_t iLib = 0; iLib < mStarDict->oLibs->query_dictmask.size(); iLib++) {
+           bFound =
+               mStarDict->oLibs->BuildResultData(mStarDict->oLibs->query_dictmask, sWord,
+                                                 mStarDict->oLibs->iCurrentIndex, iLib,
+                                                 mStarDict->results);
+       }
+
+       bookname =
+           g_markup_printf_escaped
+           ("<span color=\"dimgray\" size=\"x-small\">%s</span>",
+            mStarDict->results[0].bookname.c_str());
+       def =
+           g_markup_printf_escaped
+           ("<span color=\"darkred\" weight=\"heavy\" size=\"large\">%s</span>",
+            mStarDict->results[0].def.c_str());
+       exp = g_strdup(mStarDict->results[0].exp.c_str());
+
+       /* create translation window */
+       mStarDict->CreateTranslationWindow(bookname, def, exp);
 
-               bookname = g_markup_printf_escaped ("<span color=\"dimgray\" size=\"x-small\">%s</span>",
-                                                   mStarDict->results[0].bookname.c_str());
-               def = g_markup_printf_escaped ("<span color=\"darkred\" weight=\"heavy\" size=\"large\">%s</span>",
-                                              mStarDict->results[0].def.c_str());
-               exp = g_strdup (mStarDict->results[0].exp.c_str());
+       g_free(bookname);
+       g_free(def);
+       g_free(exp);
+    }
 
-               /* create translation window */
-               mStarDict->CreateTranslationWindow (bookname, def, exp);
+    /* grab focus to search entry */
+    gtk_widget_grab_focus(GTK_WIDGET(mStarDict->search));
 
-               g_free (bookname);
-               g_free (def);
-               g_free (exp);
+    return true;
+}
+
+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;
+
+    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);
+
+       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) {
+               const gchar *sugWord = mStarDict->oLibs->GetSuggestWord(query.c_str(),
+                                                                       mStarDict->
+                                                                       oLibs->iCurrentIndex,
+                                                                       mStarDict->
+                                                                       oLibs->query_dictmask, 0);
+               if (sugWord) {
+                   gchar *sSugWord = g_strdup(sugWord);
+                   bFound =
+                       mStarDict->oLibs->SimpleLookup(sSugWord, mStarDict->oLibs->iCurrentIndex);
+                   g_free(sSugWord);
+               }
+           }
+           mStarDict->oLibs->ListWords(mStarDict->oLibs->iCurrentIndex);
+           break;
+       case qtDATA:
+           bFound = mStarDict->oLibs->LookupData(query.c_str());
+           break;
+       default:
+           /* nothing */ ;
        }
 
-       /* grab focus to search entry */
-       gtk_widget_grab_focus (GTK_WIDGET (mStarDict->search));
+       /* unselect selected rows */
+       gtk_tree_selection_unselect_all(selection);
+       gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
+
+       /* hide progress indicator */
+//     mStarDict->ShowProgressIndicator(false);
 
-       return TRUE;
+       if (bFound)
+           mStarDict->ShowNoResults(false);
+       else
+           mStarDict->ShowNoResults(true);
+    }
+
+    return true;
 }
 
 gboolean
-MStarDict::onSearchEntryChanged (GtkEditable *editable,
-                                   MStarDict *mStarDict)
+MStarDict::onDictionariesMenuItemClicked(GtkButton *button,
+                                        MStarDict *mStarDict)
 {
-       GtkTreeSelection *selection;
-       const gchar *sWord;
-       bool bFound = false;
-       std::string query;
-
-       sWord = gtk_entry_get_text (GTK_ENTRY (editable));
-
-       if (strcmp (sWord, "") == 0) {
-               gtk_widget_show (mStarDict->label_widget);
-               gtk_widget_hide (mStarDict->results_widget);
-       } 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);
-
-               switch (analyse_query(sWord, query)) {
-                       case qtFUZZY:
-                               g_debug ("FUZZY");
-                               mStarDict->oLibs->LookupWithFuzzy(sWord);
-                               break;
-                       case qtREGEX:
-                               g_debug ("REGEX");
-                               mStarDict->oLibs->LookupWithRule(sWord);
-                               break;
-                       case qtSIMPLE:
-                               g_debug ("SIMPLE");
-                               bFound = mStarDict->oLibs->SimpleLookup(sWord, mStarDict->oLibs->iCurrentIndex);
-                               if (!bFound) {
-                                       const gchar *sugWord = mStarDict->oLibs->GetSuggestWord(sWord, mStarDict->oLibs->iCurrentIndex, mStarDict->oLibs->query_dictmask, 0);
-                                       if (sugWord) {
-                                               gchar *sSugWord = g_strdup(sugWord);
-                                               bFound = mStarDict->oLibs->SimpleLookup(sSugWord, mStarDict->oLibs->iCurrentIndex);
-                                               g_free(sSugWord);
-                                       }
-                               }
-                               mStarDict->oLibs->ListWords(mStarDict->oLibs->iCurrentIndex);
-                               break;
-                       case qtDATA:
-                               g_debug ("DATA");
-//                             oLibs->LookupData(query, res_list);
-                               break;
-                       default:
-                               g_debug ("DEFAULT");
-                               /*nothing*/;
-                       }
-
-               /* unselect selected rows */
-               gtk_tree_selection_unselect_all (selection);
-               gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
-
-               gtk_widget_hide (mStarDict->label_widget);
-               gtk_widget_show (mStarDict->results_widget);
+    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);
        }
 
-       return TRUE;
+       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));
+    return true;
 }
 
-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);
+gboolean
+MStarDict::onQuitMenuItemClicked(GtkButton *button,
+                                MStarDict *mStarDict)
+{
+    gtk_main_quit();
+    return true;
+}
+
+void
+MStarDict::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
+MStarDict::LoadDictionaries()
+{
+    std::list < std::string > dict_list;
+
+    if (!oConf->GetStringList("/apps/maemo/mstardict/dict_list", dict_list)) {
+       GetAllDictionaryList(dict_list);
+       oConf->SetStringList("/apps/maemo/mstardict/dict_list", dict_list);
+    }
+
+    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);
        }
-private:
-       std::list<std::string> &dict_all_list;
-};
+    }
+
+    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);
+}
 
 void
-MStarDict::LoadDictionaries ()
+MStarDict::ReLoadDictionaries(std::list < std::string > &dict_list)
 {
-       strlist_t dicts_dir_list;
-       strlist_t order_list;
-       strlist_t disable_list;
-
-       std::list<std::string> load_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(load_list));
-       oLibs->load(load_list);
-
-       oLibs->query_dictmask.clear();
-       for (std::list<std::string>::iterator i = load_list.begin(); i != load_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);
-               }
+    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->iCurrentIndex)
+       g_free(oLibs->iCurrentIndex);
+    oLibs->iCurrentIndex =
+       (CurrentIndex *) g_malloc(sizeof(CurrentIndex) * oLibs->query_dictmask.size());
 
+    if (oLibs->query_dictmask.empty())
+       ShowNoDictionary(true);
 }
 
 void
-MStarDict::CreateTranslationWindow (const gchar *bookname,
-                                     const gchar *def,
-                                     const gchar *exp)
+MStarDict::CreateTranslationWindow(const gchar *bookname,
+                                  const gchar *def,
+                                  const gchar *exp)
 {
-       GtkWidget *window, *alignment, *pannable, *vbox, *label;
-
-       window = hildon_stackable_window_new ();
-       gtk_window_set_title (GTK_WINDOW (window), _("Translation"));
-
-       alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
-       gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-                                  HILDON_MARGIN_DEFAULT,
-                                  HILDON_MARGIN_DEFAULT,
-                                  HILDON_MARGIN_DOUBLE,
-                                  HILDON_MARGIN_DEFAULT);
-       gtk_container_add (GTK_CONTAINER (window), alignment);
-
-       pannable = hildon_pannable_area_new ();
-       g_object_set (G_OBJECT (pannable), "mov-mode", HILDON_MOVEMENT_MODE_BOTH,
-                     NULL);
-       gtk_container_add (GTK_CONTAINER (alignment), pannable);
-
-       vbox = gtk_vbox_new (FALSE, 0);
-       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable),
-                                               vbox);
-
-       label = gtk_label_new ("Bookname");
-       gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
-       gtk_label_set_markup (GTK_LABEL (label), bookname);
-       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
-       label = gtk_label_new ("Definition");
-       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-       gtk_label_set_markup (GTK_LABEL (label), def);
-       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
-       label = gtk_label_new ("Expresion");
-       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
-       gtk_label_set_markup (GTK_LABEL (label), exp);
-       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
-       gtk_widget_show_all (window);
+    GtkWidget *window, *alignment, *pannable, *vbox, *label;
+
+    window = hildon_stackable_window_new();
+    gtk_window_set_title(GTK_WINDOW(window), _("Translation"));
+
+    alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
+    gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
+                             HILDON_MARGIN_DEFAULT,
+                             HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DEFAULT);
+    gtk_container_add(GTK_CONTAINER(window), alignment);
+
+    pannable = hildon_pannable_area_new();
+    g_object_set(G_OBJECT(pannable), "mov-mode", HILDON_MOVEMENT_MODE_BOTH, NULL);
+    gtk_container_add(GTK_CONTAINER(alignment), pannable);
+
+    vbox = gtk_vbox_new(FALSE, 0);
+    hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable), vbox);
+
+    label = gtk_label_new("Bookname");
+    gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+    gtk_label_set_markup(GTK_LABEL(label), bookname);
+    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+    label = gtk_label_new("Definition");
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+    gtk_label_set_markup(GTK_LABEL(label), def);
+    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+    label = gtk_label_new("Expresion");
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+    gtk_label_set_markup(GTK_LABEL(label), exp);
+    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+    gtk_widget_show_all(window);
 }
 
 void
-MStarDict::CreateMainWindow ()
+MStarDict::CreateMainWindow()
 {
-       HildonProgram *program = NULL;
-       GtkWidget *window, *alignment, *vbox;
-       GtkCellRenderer *renderer;
-       GtkTreeSelection *selection;
-
-       /* hildon program */
-       program = hildon_program_get_instance ();
-       g_set_application_name (_("MStardict"));
-
-       /* main window */
-       window = hildon_stackable_window_new ();
-       hildon_program_add_window (program, HILDON_WINDOW (window));
-
-       /* aligment */
-       alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
-       gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-                                  HILDON_MARGIN_HALF,
-                                  0,
-                                  HILDON_MARGIN_DEFAULT,
-                                  HILDON_MARGIN_DEFAULT);
-       gtk_container_add (GTK_CONTAINER (window), alignment);
-
-       /* main vbox */
-       vbox = gtk_vbox_new (FALSE, 0);
-       gtk_container_add (GTK_CONTAINER (alignment), vbox);
-
-       /* no_search_result label */
-       label_widget = gtk_label_new (_("No search result"));
-       hildon_helper_set_logical_color (label_widget, GTK_RC_FG, 
-                                        GTK_STATE_NORMAL, "SecondaryTextColor");
-       hildon_helper_set_logical_font (label_widget, "LargeSystemFont");
-       gtk_box_pack_start (GTK_BOX (vbox), label_widget, TRUE, TRUE, 0);
-
-       /* alignment for pannable area */
-       results_widget = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
-       gtk_alignment_set_padding (GTK_ALIGNMENT (results_widget),
-                                  0,
-                                  0,
-                                  HILDON_MARGIN_DEFAULT,
-                                  HILDON_MARGIN_DEFAULT);
-       gtk_box_pack_start (GTK_BOX (vbox), results_widget, TRUE, TRUE, 0);
-
-       /* pannable for tree view */
-       results_view_scroll = hildon_pannable_area_new ();
-       gtk_container_add (GTK_CONTAINER (results_widget), results_view_scroll);
-
-       /* result tree view */
-       results_view = hildon_gtk_tree_view_new (HILDON_UI_MODE_EDIT);
-       gtk_tree_view_set_model (GTK_TREE_VIEW (results_view),
-                                GTK_TREE_MODEL (results_list));
-       gtk_container_add (GTK_CONTAINER (results_view_scroll), results_view);
-
-       selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (results_view));
-       g_signal_connect (selection, "changed",
-                         G_CALLBACK (onResultsViewSelectionChanged), this);
-
-       /* def column */
-       renderer = gtk_cell_renderer_text_new ();
-       gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (results_view),
-                                                    -1,
-                                                    "Def", renderer,
-                                                    "text", DEF_COLUMN,
-                                                    NULL);
-       g_object_set (G_OBJECT (renderer), "xpad", 10, NULL);
-
-       /* search entry */
-       search = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT);
-       gtk_box_pack_end (GTK_BOX (vbox), search, FALSE, TRUE, 0);
-       g_signal_connect (search, "changed",
-                         G_CALLBACK (onSearchEntryChanged), this);
-
-       /* window signals */
-       g_signal_connect (G_OBJECT (window), "destroy",
-                         G_CALLBACK (gtk_main_quit), NULL);
-
-       /* show all widget instead of alignment */
-       gtk_widget_show_all (GTK_WIDGET (window));
-       gtk_widget_hide (results_widget);
-
-       /* grab focus to search entry */
-       gtk_widget_grab_focus (GTK_WIDGET (search));
+    HildonProgram *program = NULL;
+    GtkWidget *alignment, *vbox;
+    GtkCellRenderer *renderer;
+    GtkTreeSelection *selection;
+
+    /* hildon program */
+    program = hildon_program_get_instance();
+    g_set_application_name(_("MStardict"));
+
+    /* main window */
+    main_window = hildon_stackable_window_new();
+    hildon_program_add_window(program, HILDON_WINDOW(main_window));
+
+    /* aligment */
+    alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
+    gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
+                             HILDON_MARGIN_HALF, 0, HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DEFAULT);
+    gtk_container_add(GTK_CONTAINER(main_window), alignment);
+
+    /* main vbox */
+    vbox = gtk_vbox_new(FALSE, 0);
+    gtk_container_add(GTK_CONTAINER(alignment), vbox);
+
+    /* no_search_result label */
+    label_widget = gtk_label_new(_("No search result"));
+    hildon_helper_set_logical_color(label_widget, GTK_RC_FG,
+                                   GTK_STATE_NORMAL, "SecondaryTextColor");
+    hildon_helper_set_logical_font(label_widget, "LargeSystemFont");
+    gtk_box_pack_start(GTK_BOX(vbox), label_widget, TRUE, TRUE, 0);
+
+    /* alignment for pannable area */
+    results_widget = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
+    gtk_alignment_set_padding(GTK_ALIGNMENT(results_widget),
+                             0, 0, HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DEFAULT);
+    gtk_box_pack_start(GTK_BOX(vbox), results_widget, TRUE, TRUE, 0);
+
+    /* pannable for tree view */
+    results_view_scroll = hildon_pannable_area_new();
+    gtk_container_add(GTK_CONTAINER(results_widget), results_view_scroll);
+
+    /* result tree view */
+    results_view = hildon_gtk_tree_view_new(HILDON_UI_MODE_EDIT);
+    gtk_tree_view_set_model(GTK_TREE_VIEW(results_view), GTK_TREE_MODEL(results_list));
+    gtk_container_add(GTK_CONTAINER(results_view_scroll), results_view);
+
+    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(results_view));
+    g_signal_connect(selection, "changed", G_CALLBACK(onResultsViewSelectionChanged), this);
+
+    /* def column */
+    renderer = gtk_cell_renderer_text_new();
+    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW
+                                               (results_view), -1, "Def",
+                                               renderer, "text", DEF_COLUMN, NULL);
+    g_object_set(G_OBJECT(renderer), "xpad", 10, NULL);
+
+    /* search entry */
+    search = hildon_entry_new(HILDON_SIZE_FINGER_HEIGHT);
+    gtk_box_pack_end(GTK_BOX(vbox), search, FALSE, TRUE, 0);
+    g_signal_connect(search, "changed", G_CALLBACK(onSearchEntryChanged), this);
+
+    /* window signals */
+    g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
+
+    /* show all widget instead of alignment */
+    gtk_widget_show_all(GTK_WIDGET(main_window));
+
+    /* grab focus to search entry */
+    gtk_widget_grab_focus(GTK_WIDGET(search));
+}
+
+void
+MStarDict::CreateMainMenu()
+{
+    HildonAppMenu *menu;
+    GtkWidget *item;
+
+    menu = HILDON_APP_MENU(hildon_app_menu_new());
+    hildon_window_set_app_menu(HILDON_WINDOW(main_window), menu);
+
+    /* dictionaries menu item */
+    item = hildon_gtk_button_new(HILDON_SIZE_AUTO);
+    gtk_button_set_label(GTK_BUTTON(item), _("Dictionaries"));
+    hildon_app_menu_append(menu, GTK_BUTTON(item));
+    g_signal_connect(item, "clicked", G_CALLBACK(onDictionariesMenuItemClicked), this);
+
+    /* quit menu item */
+    item = hildon_gtk_button_new(HILDON_SIZE_AUTO);
+    gtk_button_set_label(GTK_BUTTON(item), _("Quit"));
+    hildon_app_menu_append(menu, GTK_BUTTON(item));
+    g_signal_connect(item, "clicked", G_CALLBACK(onQuitMenuItemClicked), this);
+
+    /* show main menu */
+    gtk_widget_show_all(GTK_WIDGET(menu));
 }
 
 void
 MStarDict::ResultsListClear()
 {
-       gtk_list_store_clear (results_list);
+    gtk_list_store_clear(results_list);
 }
 
 void
 MStarDict::ResultsListInsertLast(const gchar *word)
 {
-       GtkTreeIter iter;
-       gtk_list_store_append (results_list, &iter);
-       gtk_list_store_set (results_list, &iter, DEF_COLUMN, word, -1);
+    GtkTreeIter iter;
+    gtk_list_store_append(results_list, &iter);
+    gtk_list_store_set(results_list, &iter, DEF_COLUMN, word, -1);
 }
 
 void
 MStarDict::ReScroll()
 {
-       hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (results_view_scroll), -1, 0);
+    hildon_pannable_area_scroll_to(HILDON_PANNABLE_AREA(results_view_scroll), -1, 0);
 }
 
-int
-main (int argc, char **argv)
+void
+MStarDict::ShowNoResults(bool bNoResults)
 {
-       /* initialize hildon */
-       hildon_gtk_init (&argc, &argv);
-
-       /* initialize localization */
-       setlocale(LC_ALL, "");
-       bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
-       bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
-       textdomain(GETTEXT_PACKAGE);
+    if (bNoResults) {
+       gtk_label_set_text(GTK_LABEL(label_widget), _("No search result"));
+       gtk_widget_show(label_widget);
+       gtk_widget_hide(results_widget);
+    } else {
+       gtk_widget_hide(label_widget);
+       gtk_widget_show(results_widget);
+    }
+}
 
-       /* create main window */
-       MStarDict mStarDict;
-       pMStarDict = &mStarDict;
-       mStarDict.CreateMainWindow();
+void
+MStarDict::ShowNoDictionary(bool bNoDictionary)
+{
+    if (bNoDictionary) {
+       gtk_label_set_text(GTK_LABEL(label_widget), _("No loaded dictionary"));
+       gtk_widget_show(label_widget);
+       gtk_widget_hide(results_widget);
+    } else {
+       gtk_widget_hide(label_widget);
+       gtk_widget_show(results_widget);
+    }
+}
 
-       /* load all dictionaries */
-       mStarDict.LoadDictionaries();
+void
+MStarDict::ShowProgressIndicator(bool bShow)
+{
+    if (bShow)
+       hildon_gtk_window_set_progress_indicator(GTK_WINDOW(main_window), 1);
+    else
+       hildon_gtk_window_set_progress_indicator(GTK_WINDOW(main_window), 0);
+}
 
-       gtk_main ();
-       return 0;
+int
+main(int argc,
+     char **argv)
+{
+    /* initialize hildon */
+    hildon_gtk_init(&argc, &argv);
+
+    /* initialize localization */
+    setlocale(LC_ALL, "");
+    bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+    textdomain(GETTEXT_PACKAGE);
+
+    /* create main window */
+    MStarDict mStarDict;
+    pMStarDict = &mStarDict;
+    mStarDict.CreateMainWindow();
+    mStarDict.CreateMainMenu();
+    mStarDict.ShowNoResults(true);
+
+    /* load all dictionaries */
+    mStarDict.LoadDictionaries();
+
+    gtk_main();
+    return 0;
 }
index a4b6bd8..412ea40 100644 (file)
@@ -1,17 +1,23 @@
 /*
  *  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
 #include <hildon/hildon.h>
 
 class Library;
+class MStarDictConf;
 class MStarDict;
 
 extern MStarDict *pMStarDict;
 
 class MStarDict {
-private:
-       GtkWidget *label_widget;
-       GtkWidget *results_widget;
-       GtkWidget *search;
-       GtkWidget *results_view;
-       GtkWidget *results_view_scroll;
+  private:
+    GtkWidget *main_window;
+    GtkWidget *label_widget;
+    GtkWidget *results_widget;
+    GtkWidget *search;
+    GtkWidget *results_view;
+    GtkWidget *results_view_scroll;
 
-       GtkListStore *results_list;
+    GtkListStore *results_list;
 
-       Library *oLibs;
-       TSearchResultList results;
+    Library *oLibs;
+    MStarDictConf *oConf;
+    TSearchResultList results;
 
-       static gboolean onResultsViewSelectionChanged (GtkTreeSelection *selection, MStarDict *mStarDict);
-       static gboolean onSearchEntryChanged (GtkEditable *editable, MStarDict *mStarDict);
+    static gboolean onResultsViewSelectionChanged(GtkTreeSelection *selection,
+                                                 MStarDict *mStarDict);
+    static gboolean onSearchEntryChanged(GtkEditable *editable,
+                                        MStarDict *mStarDict);
+    static gboolean onDictionariesMenuItemClicked(GtkButton *button,
+                                                 MStarDict *mStarDict);
+    static gboolean onQuitMenuItemClicked(GtkButton *button,
+                                         MStarDict *mStarDict);
 
-public:
-       MStarDict();
-       ~MStarDict();
+  public:
+     MStarDict();
+    ~MStarDict();
 
-       void CreateTranslationWindow(const gchar *bookname, const gchar *def, const gchar *exp);
-       void CreateMainWindow();
+    void CreateTranslationWindow(const gchar *bookname,
+                                const gchar *def,
+                                const gchar *exp);
+    void CreateMainWindow();
+    void CreateMainMenu();
 
-       void LoadDictionaries();
+    void GetAllDictionaryList(std::list < std::string > &dict_list);
+    void LoadDictionaries();
+    void ReLoadDictionaries(std::list < std::string > &dict_list);
 
-       void ResultsListClear();
-       void ResultsListInsertLast(const gchar *word);
-       void ReScroll();
+    void ResultsListClear();
+    void ResultsListInsertLast(const gchar *word);
+    void ReScroll();
+    void ShowNoResults(bool bNoResults);
+    void ShowNoDictionary(bool bNoDictionary);
+    void ShowProgressIndicator(bool bShow);
 };