First Backbone draft ready
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 3 Aug 2010 11:24:27 +0000 (13:24 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 3 Aug 2010 11:24:27 +0000 (13:24 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/backbone/main.cpp
trunk/src/base/mDictionary.pro
trunk/src/base/mDictionary.pro.user
trunk/src/includes/CommonDictInterface.h
trunk/src/includes/settings.h
trunk/src/includes/translation.h

index 6ebb152..1cf89d2 100644 (file)
@@ -34,8 +34,8 @@ Backbone::~Backbone()
 
 }
 
-Backbone::Backbone(const Backbone &b) {
-    dicts = QList<CommonDictInterface* > (b.dicts);
+Backbone::Backbone(const Backbone &b){
+    dicts = QHash<CommonDictInterface*, bool > (b.dicts);
     plugins = QList<CommonDictInterface* > (b.plugins);
     resultv = QHash<QString, Translation* > (b.resultv);
 }
@@ -44,27 +44,32 @@ int Backbone::searchLimit() {
     return searchLimitv;
 }
 
-QHash<const CommonDictInterface*, bool > Backbone::getDictionaries() {
+QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
     return dicts;
 }
 
-QList<const CommonDictInterface* > Backbone::getPlugins() {
+QList<CommonDictInterface* > Backbone::getPlugins() {
     return plugins;
 }
 
+QList<QString> Backbone::getHistory() {
+    //TODO code needed
+}
+
 QHash<QString, Translation*> Backbone::result() {
     return resultv;
 }
 
 void Backbone::stopSearching() {
-    foreach(CommonDictInterface* dict, dicts)
+    foreach(CommonDictInterface* dict, dicts.keys())
         dict->stop();
 }
 
 void Backbone::search(QString word) {
     //TODO add running searches in new threads
-    foreach(CommonDictInterface* dict, dicts)
-        dict->search(word, searchLimit());
+    foreach(CommonDictInterface* dict, dicts.keys())
+        if(dicts[dict] == 1)
+            dict->search(word, searchLimit());
 }
 
  void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
@@ -75,5 +80,17 @@ void Backbone::search(QString word) {
              dicts[dict] = 0;
  }
 
+ void Backbone::addDictionary(Settings *settings) {
+     CommonDictInterface* dict = settings->type()->getNew(settings);
+     dicts[dict] = 1;
+ }
+
+ void Backbone::quit() {
+    foreach(CommonDictInterface* dict, dicts.keys())
+        dict->stop();
+    Q_EMIT closeOk();
+}
+
+
 
 
index 9387819..3cd4fc7 100644 (file)
 
 #include <QObject>
 #include <QList>
+#include <QHash>
 #include "../../includes/CommonDictInterface.h"
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
 
-uint qHash(CommonDictInterface* dict) {
-    return dict->hash();
-}
 
 //! Inner part of dictionary - glues together GUI and plugins
 class Backbone : public QObject
@@ -45,13 +43,13 @@ public:
     Backbone(const Backbone& b);
 
     //! \return all loadded dictionaries with activity state flag
-    QHash<const CommonDictInterface*, bool > getDictionaries();
+    QHash<CommonDictInterface*, bool > getDictionaries();
 
     //! \return all loadded plugins
-    QList<const CommonDictInterface* > getPlugins();
+    QList<CommonDictInterface* > getPlugins();
 
     //! \return history of performed searches
-    QList<const QString> getHistory(); //TODO implementation needed (in future)
+    QList<QString> getHistory(); //TODO implementation needed (in future)
 
     //! \return return search fesult
     QHash<QString, Translation*> result();
index f195704..c0d3099 100644 (file)
@@ -1,11 +1,14 @@
 #include <QtGui/QApplication>
 #include "backbone.h"
 
+uint qHash(CommonDictInterface* dict) {
+    return dict->hash();
+}
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
-    backbone w;
-    w.show();
+    Backbone w;
 
     return a.exec();
 }
index 814e660..89e3adb 100644 (file)
@@ -15,4 +15,7 @@ SOURCES += \
     backbone/backbone.cpp
 
 HEADERS  += \
-    backbone/backbone.h
+    backbone/backbone.h \
+    ../includes/translation.h \
+    ../includes/settings.h \
+    ../includes/CommonDictInterface.h
index cb903d6..e1335af 100644 (file)
@@ -15,7 +15,7 @@
   <valuemap type="QVariantMap">
    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Desktop</value>
    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
-   <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
+   <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">2</value>
    <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
    <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
     <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
@@ -46,7 +46,7 @@
     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Debug</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/src/base/mDictionary-build-desktop</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionary-build</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Debug</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/src/base/mDictionary-build-desktop</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionary-build</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
index 6310ba7..9cc4da4 100644 (file)
 *******************************************************************************/
 
 // Created by Bartosz Szatkowski
+
+
+#ifndef COMMONDICTINTERFACE_H
+#define COMMONDICTINTERFACE_H
+
 #include <QString>
 #include <QDialog>
 #include <QObject>
 #include <QList>
-#include "CommonDictInterface.h"
 #include "translation.h"
-#include "settings.h"
+class Settings;
 
 
 
@@ -34,7 +38,7 @@
 class CommonDictInterface : public QObject {
   Q_OBJECT
   public:
-    CommonDictInterface(const QObject *parent = 0) = 0;
+    CommonDictInterface(const QObject *parent = 0) ;
 
     //! returns source language code iso 639-2
     virtual QString langFrom() const = 0; 
@@ -64,6 +68,8 @@ class CommonDictInterface : public QObject {
     //! returns whether plugin can start searching 
     virtual bool isAvailable() const = 0;
 
+    virtual uint hash() const = 0;
+
  public Q_SLOTS:
     /*! performes search in dictionary
         \param  word word to search in dictionary
@@ -84,4 +90,5 @@ class CommonDictInterface : public QObject {
 
     //! emited after dictionary is ready to use afer being loaded
     void loaded(CommonDictInterface*);
-}
+};
+#endif
index 4313692..14a0c2d 100644 (file)
 *******************************************************************************/
 
 //Created by Bartosz Szatkowski
+
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
 #include <QString>
 #include "CommonDictInterface.h"
 
 //! Plugin specific configuration 
 class Settings {
   public:
-<<<<<<< HEAD
     //! \retrun value fo given key
     //! \param key
-    QString value(const QString key) const = 0;
+    virtual QString value(const QString key) const = 0;
 
     //! sets key to value
-    void setValue(const QString key, const QString value) = 0;
+    virtual void setValue(const QString key, const QString value) = 0;
 
     //! \return dict CommonDictInterface
-    CommonDictInterface type() const = 0;
+    virtual CommonDictInterface* type() const = 0;
 
     //! sets settings type to given dictionary
-    void setType(const CommonDictInterface) = 0;
-}
+    virtual void setType(const CommonDictInterface*) = 0;
+};
+
+#endif
index a56fa11..0ef07f2 100644 (file)
 *******************************************************************************/
 
 //Created by Bartosz Szatkowski
+
+#ifndef TRANSLATION_H
+#define TRANSLATION_H
+
 #include <QString>
 
+
+
 //! Keeping raw form of translation to be parsed only when needed
 class Translation {
   public:
     //! \return word to be translated
-    QString key() const = 0;
+    virtual QString key() const = 0;
  
-    //! \returns dictionary information (plugin name, languages, <logo> etc)\
-    //!     to be displayed in translation table header
-    QString dictionaryInfo() const = 0;
+    /*! \returns dictionary information (plugin name, languages, <logo> etc)\
+         to be displayed in translation table header */
+    virtual QString dictionaryInfo() const = 0;
 
     //! \return parsed raw format into html
-    QString toHtml() const = 0;
-}
+    virtual QString toHtml() const = 0;
+};
+
+#endif