Merge branch 'gui'
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 10 Aug 2010 07:05:42 +0000 (09:05 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 10 Aug 2010 07:05:42 +0000 (09:05 +0200)
Conflicts:
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

12 files changed:
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/main.cpp
trunk/src/includes/CommonDictInterface.h
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h

index 313835f..69d575a 100644 (file)
@@ -124,8 +124,6 @@ void DictManagerWidget::hideEvent(QHideEvent *e)
     }
     backbone->selectedDictionaries(checkedDicts);
 
-    qDebug()<<"asda";
-
     QWidget::hideEvent(e);
 }
 
@@ -163,5 +161,6 @@ void DictManagerWidget::settingsButtonClicked() {
     QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
     if(selected.count() > 0) {
         dictsHash[selected[0]]->dictDialog()->changeSettings(this);
+        refreshDictsList();
     }
 }
index 146b5d8..7e673d8 100644 (file)
@@ -50,6 +50,8 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
 
     ui->menuBar->addAction(menuWidget);
 
+    connect(this, SIGNAL(searchWordList(QStringList)),
+            searchBarWidget, SLOT(searchWordList(QStringList)));
 
     connect(wordListWidget, SIGNAL(showTranslation(QList<Translation*>)),
             translationWidget, SLOT(show(QList<Translation*>)));
@@ -84,3 +86,7 @@ void MainWindow::closeOk() {
     closingApplication = true;
     close();*/
 }
+
+void MainWindow::search(QStringList words) {
+    emit searchWordList(words);
+}
index f9902b9..eb9b999 100644 (file)
@@ -42,6 +42,8 @@ class MainWindow : public QMainWindow
 public:
     explicit MainWindow(Backbone* backbone, QWidget *parent = 0);
     ~MainWindow();
+    void search(QStringList);
+
 
 public Q_SLOTS:
     //! Confirmation from backbone that we can close program
@@ -50,6 +52,7 @@ public Q_SLOTS:
 Q_SIGNALS:
     //! Request to backbone to stop all it's activities
     void quit();
+    void searchWordList(QStringList);
 
 protected:
     /*! When user wants to close application, we first sends signal to stop all
index 3ff3a7e..168b968 100644 (file)
@@ -55,8 +55,8 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
 
 
     //connects request to backbone
-    connect(this, SIGNAL(searchForTranslations(QString)),
-            backbone, SLOT(search(QString)));
+    connect(this, SIGNAL(searchForTranslations(QStringList)),
+            backbone, SLOT(search(QStringList)));
 
     connect(this, SIGNAL(stopSearching()),
             backbone, SLOT(stopSearching()));
@@ -167,7 +167,19 @@ void SearchBarWidget::searchPushButtonClicked() {
         searchPushButton->setText(tr("Stop"));
         setEnabled(false);
         _isSearching = true;
-        emit searchForTranslations(searchWordLineEdit->text());
+        QStringList searchWord;
+        searchWord << searchWordLineEdit->text();
+        emit searchForTranslations(searchWord);
+    }
+}
+
+void SearchBarWidget::searchWordList(QStringList words) {
+    if(!_isSearching) {
+        searchingProgressBar->show();
+        searchPushButton->setText(tr("Stop"));
+        setEnabled(false);
+        _isSearching = true;
+        emit searchForTranslations(words);
     }
 }
 
index ec93ed4..0c7ca2d 100644 (file)
@@ -47,7 +47,7 @@ public:
 
 Q_SIGNALS:
     //! Requests to search for translation of word passed as parameter
-    void searchForTranslations(QString);
+    void searchForTranslations(QStringList);
 
     //! Request to stop all active searchings
     void stopSearching();
@@ -60,6 +60,7 @@ public Q_SLOTS:
     */
     void setEnabled(bool enabled = true);
     void searchFinished();
+    void searchWordList(QStringList);
 
 private Q_SLOTS:
     void clearSearchWordToolButtonClicked();
index 8317835..37fe4d3 100644 (file)
@@ -41,7 +41,6 @@ TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
             this, SLOT(showContextMenu(QPoint)));
 
     setWindowTitle(tr("Translation"));
-
 }
 
 
index aa088bb..22ce39f 100644 (file)
 #include "MainWindow.h"
 #include "../backbone/backbone.h"
 #include "../../includes/translation.h"
+#include <QDebug>
 
-int main(int argc, char *argv[])
-{
+
+QStringList parseParameters(int argc, char *argv[]) {
+    bool wordListStarted = false;
+    QStringList result;
+    for(int i=1; i<argc; i++) {
+        QString argument(argv[i]);
+        if(!wordListStarted) {
+            if(argument == "-s") {
+                wordListStarted = true;
+            }
+        }
+        else {
+            if(!argument.startsWith("-") &&
+               !argument.startsWith("--")) {
+                result << argument;
+            }
+        }
+    }
+
+    return result;
+}
+
+int main(int argc, char *argv[]) {
     QApplication a(argc, argv);
 
+    QStringList search = parseParameters(argc, argv);
+
     qRegisterMetaType<Translation*>("Translation*");
     qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
     Backbone* backbone = new Backbone;
     MainWindow* w = new MainWindow(backbone);
     w->show();
 
+    if(search.count() > 0) {
+        w->search(search);
+    }
+
     return a.exec();
 }
index f3c322a..e55be96 100644 (file)
@@ -96,6 +96,9 @@ class CommonDictInterface : public QObject {
 
     //! emited after dictionary is ready to use afer being loaded
     void loaded(CommonDictInterface*);
+
+    //! emited after change dictionary settings
+    void settingsChanged();
 };
 
 Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1");
index 9336920..c8d882e 100644 (file)
@@ -69,23 +69,41 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
 
     setModal(true);
 
-   /* connect(browseButton, SIGNAL(clicked()),
+    connect(browseButton, SIGNAL(clicked()),
             this, SLOT(selectFile()));
 
-    connect(addButton, SIGNAL(clicked()),
-            this, SLOT(addDictionary()));*/
+    connect(saveButton, SIGNAL(clicked()),
+            this, SLOT(accept()));
 
     _dicitonaryFilePath = QString();
 }
 
+void XdxfSettingsDialog::selectFile() {
+    QString fileName = QFileDialog::getOpenFileName(this,
+                                     tr("Select dictionary file"),
+                                     "",
+                                     tr("XDXF Files (*.xdxf)"),
+                                     NULL,
+                                     NULL);
+    if (!fileName.isEmpty()) {
+        browseLabel->setText(tr("Dictionary file: ") + fileName);
+        _dicitonaryFilePath = fileName;
+    }
+}
+
+QString XdxfSettingsDialog::dicitonaryFilePath() {
+    return _dicitonaryFilePath;
+}
+
 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
                                           QWidget *parent) {
     XdxfSettingsDialog settingsDialog(plugin, parent);
-    //Settings* settings = new Settings;
-
-    if(settingsDialog.exec()==QDialog::Accepted) {
 
 
+    if(settingsDialog.exec()==QDialog::Accepted) {
+        Settings* settings = new Settings;
+        settings->setValue("path", settingsDialog.dicitonaryFilePath());
+        plugin->setSettings(settings);
         return NULL;
     }
 
index d7ed8b5..4eda7a1 100644 (file)
@@ -38,14 +38,13 @@ public:
     static Settings* getSettings(XdxfPlugin* plugin, QWidget *parent);
 
     //! Returns choosen by user dictionary file path
-    //QString dicitonaryFilePath();
+    QString dicitonaryFilePath();
 
     //! Returns if user want to cache dictionary
    // bool generateCache();
 
-signals:
-
-public slots:
+private Q_SLOTS:
+    void selectFile();
 
 private:
     QLabel* infoLabel;
index f1c8b60..61a482b 100644 (file)
@@ -31,13 +31,15 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
                     _type(tr("xdxf")), _infoNote(tr("")) {
     _settings = new Settings();
-    _dictDialog = new XdxfDictDialog(this);
+    _dictDialog = new XdxfDictDialog(this, this);
     _settings->setValue("type","xdxf");
     if(isCached())
         _settings->setValue("cached","true");
     else
         _settings->setValue("cached","false");
 
+    _wordsCount = 0;
+
     setPath("/usr/lib/mdictionary/dict.xdxf");
     stopped = false;
 }
@@ -78,22 +80,7 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
         return translations.toList();
     }
 
-    /*read information about dictionary*/
     QXmlStreamReader dictionaryReader(&dictionaryFile);
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="xdxf") {
-      if(dictionaryReader.attributes().hasAttribute("lang_from"))
-        _langFrom = dictionaryReader.attributes().value("lang_from").toString();
-      if(dictionaryReader.attributes().hasAttribute("lang_to"))
-        _langTo = dictionaryReader.attributes().value("lang_to").toString();
-    }
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="full_name")
-        _name=dictionaryReader.readElementText();
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="description")
-        _infoNote=dictionaryReader.readElementText();
-
     /*search words list*/
     QString a;
     int i=0;
@@ -182,6 +169,7 @@ DictDialog* XdxfPlugin::dictDialog() {
 void XdxfPlugin::setPath(QString path){
     this->path=path;
     _settings->setValue("path",path);
+    getDictionaryInfo();
 }
 
 
@@ -215,4 +203,58 @@ bool XdxfPlugin::isCached()
     return false;
 }
 
+void XdxfPlugin::setSettings(Settings *settings) {
+    _settings = settings;
+    setPath(_settings->value("path"));
+    emit settingsChanged();
+}
+
+
+void XdxfPlugin::getDictionaryInfo() {
+    QFile dictionaryFile(path);
+    if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        qDebug()<<"Error: could not open file";
+        return;
+    }
+
+    QXmlStreamReader dictionaryReader(&dictionaryFile);
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="xdxf") {
+      if(dictionaryReader.attributes().hasAttribute("lang_from"))
+        _langFrom = dictionaryReader.attributes().value("lang_from").toString();
+      if(dictionaryReader.attributes().hasAttribute("lang_to"))
+        _langTo = dictionaryReader.attributes().value("lang_to").toString();
+    }
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="full_name")
+        _name=dictionaryReader.readElementText();
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="description")
+        _infoNote=dictionaryReader.readElementText();
+
+    dictionaryFile.seek(0);
+
+    long wordsCount = 0;
+
+    QString line;
+    while(!dictionaryFile.atEnd()) {
+        line = dictionaryFile.readLine();
+        if(line.contains("<ar>")) {
+            wordsCount++;
+        }
+    }
+
+    dictionaryFile.close();
+}
+
+QString XdxfPlugin::removeAccents(QString string) {
+    QString normalized = string.normalized(QString::NormalizationForm_D);
+    for(int i=0; i<normalized.size(); i++) {
+        if(!normalized[i].isLetterOrNumber() && !normalized[i].isSpace()) {
+            normalized.remove(i,1);
+        }
+    }
+    return normalized;
+}
+
 Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
index b0a0b65..4c9c286 100644 (file)
@@ -77,6 +77,12 @@ public:
     //! returns current plugin settings
     Settings* settings();
 
+    //! returns words count in dictionary
+    long wordsCount();
+
+    //! Sets new settings
+    void setSettings(Settings*);
+
 public Q_SLOTS:
     /*! performs search in dictionary
       \param  word word to search in dictionary
@@ -90,6 +96,10 @@ public Q_SLOTS:
     //! stop current operation
     void stop();
 
+
+protected:
+    QString removeAccents(QString);
+
 private:
 /*! returns true or false depending on whether the dictionary is cached
     or not, not implemented yet
@@ -115,6 +125,12 @@ private:
     QString path;
     uint _hash;
 
+    //! number of words in dicrionary
+    long _wordsCount;
+
+    //! scan dictionary file to get information about it
+    void getDictionaryInfo();
+
     volatile bool stopped;
     Settings *_settings;
     XdxfDictDialog* _dictDialog;