diff --git a/qml/harbour-sailbabel.qml b/qml/harbour-sailbabel.qml
index 99029e6..e55ce1d 100644
--- a/qml/harbour-sailbabel.qml
+++ b/qml/harbour-sailbabel.qml
@@ -9,16 +9,13 @@ ApplicationWindow {
AppModel {
id: appModel
- }
- Dictionary {
- id: dictionary
- onReadingFinished: {
- pageStack.replace('pages/MainPage.qml')
- pageStack.pushAttached('pages/History.qml')
+ onReadingDictionaryFinished: {
+ pageStack.replace(Qt.resolvedUrl('pages/MainPage.qml'))
+ pageStack.pushAttached(Qt.resolvedUrl('pages/History.qml'))
}
- onReadingError: {
- pageStack.replace('pages/Error.qml')
+ onReadingDictionaryFailed: {
+ pageStack.replace(Qt.resolvedUrl('pages/Error.qml'))
appModel.currentDictionary = ''
}
}
diff --git a/qml/pages/ChooseDictionary.qml b/qml/pages/ChooseDictionary.qml
index e97bb7f..29f3bde 100644
--- a/qml/pages/ChooseDictionary.qml
+++ b/qml/pages/ChooseDictionary.qml
@@ -55,7 +55,7 @@ Page {
if (fileIsDir) {
folderModel.folder = filePath
} else {
- appModel.currentDictionary = filePath
+ appModel.currentDictionary = 'file://' + filePath
pageStack.replace('LoadDictionary.qml')
}
}
diff --git a/qml/pages/Error.qml b/qml/pages/Error.qml
index ff347f4..77ba87d 100644
--- a/qml/pages/Error.qml
+++ b/qml/pages/Error.qml
@@ -15,30 +15,19 @@ Page {
width: parent.width
spacing: Theme.paddingMedium
PageHeader {
- title: 'SailBabel'
+ title: qsTr('Error')
}
- Text {
- x: Theme.horizontalPageMargin
- width: column.width-2*x
- color: Theme.primaryColor
- wrapMode: TextEdit.Wrap
- font.pixelSize: Theme.fontSizeMedium
- horizontalAlignment: TextEdit.AlignJustify
- text: qsTr('_error_description_')
- textFormat: Text.StyledText
- linkColor: Theme.highlightColor
- onLinkActivated: { Qt.openUrlExternally(link) }
+ TextField {
+ text: qsTr('Unable to open dictionary.')
+ readOnly: true
}
- Label {
- text: '
© Heiko Bauke, 2016–2017
Fork me on github!
https://github.com/rabauke/harbour-sailbabel'
- textFormat: Text.StyledText
- width: column.width
- color: Theme.primaryColor
- linkColor: Theme.highlightColor
- wrapMode: TextEdit.Wrap
- font.pixelSize: Theme.fontSizeSmall
- horizontalAlignment: TextEdit.AlignHCenter
- onLinkActivated: { Qt.openUrlExternally(link) }
+ Button {
+ text: qsTr('Ok')
+ anchors.horizontalCenter: column.horizontalCenter
+ onClicked: {
+ pageStack.replace(Qt.resolvedUrl('MainPage.qml'))
+ pageStack.pushAttached(Qt.resolvedUrl('History.qml'))
+ }
}
}
diff --git a/qml/pages/History.qml b/qml/pages/History.qml
index ad9defc..8de050f 100644
--- a/qml/pages/History.qml
+++ b/qml/pages/History.qml
@@ -62,7 +62,7 @@ Page {
onClicked: {
queryFieldText = searchHistoryListModel.get(model.index).query
resultsListModel.clear()
- var trans = dictionary.translateAtoB(queryFieldText)
+ var trans = appModel.dictionary.translateAtoB(queryFieldText)
for (var i in trans)
resultsListModel.append({
'lang1': trans[i][0],
@@ -73,7 +73,7 @@ Page {
'lang1': '',
'lang2': ''
})
- var trans = dictionary.translateBtoA(queryFieldText)
+ var trans = appModel.dictionary.translateBtoA(queryFieldText)
for (var i in trans)
resultsListModel.append({
'lang1': trans[i][0],
diff --git a/qml/pages/LoadDictionary.qml b/qml/pages/LoadDictionary.qml
index 4021e31..df7193f 100644
--- a/qml/pages/LoadDictionary.qml
+++ b/qml/pages/LoadDictionary.qml
@@ -27,11 +27,11 @@ Page {
anchors.horizontalCenter: label1.horizontalCenter
anchors.top: label1.bottom
anchors.topMargin: Theme.paddingMedium
- text: qsTr('%n dictionary entries found.', '', dictionary.size)
+ text: qsTr('%n dictionary entries found.', '', appModel.dictionary.size)
color: Theme.highlightColor
}
onStatusChanged: {
if (status === PageStatus.Active)
- dictionary.readAsync(appModel.currentDictionary)
+ appModel.dictionary.readAsync(appModel.currentDictionary)
}
}
diff --git a/qml/pages/MainPage.qml b/qml/pages/MainPage.qml
index 22b005a..d559ccb 100644
--- a/qml/pages/MainPage.qml
+++ b/qml/pages/MainPage.qml
@@ -74,8 +74,8 @@ Page {
'query': text
})
resultsListModel.clear()
- var transAtoB = dictionary.translateAtoB(text)
- var transBtoA = dictionary.translateBtoA(text)
+ var transAtoB = appModel.dictionary.translateAtoB(text)
+ var transBtoA = appModel.dictionary.translateBtoA(text)
var i
for (i in transAtoB)
resultsListModel.append({
diff --git a/src/AppModel.cpp b/src/AppModel.cpp
index 0e76073..5287d03 100644
--- a/src/AppModel.cpp
+++ b/src/AppModel.cpp
@@ -32,6 +32,12 @@ AppModel::AppModel(QObject* parent) : QObject{parent} {
const QVariant auto_load_dictionary{settings.value("autoLoadDictionary")};
if (auto_load_dictionary.canConvert())
m_auto_load_dictionary = auto_load_dictionary.toBool();
+
+ connect(&m_dictionary, &Dictionary::readingFinished, this,
+ [this]() { emit readingDictionaryFinished(); });
+ connect(&m_dictionary, &Dictionary::readingError, this, [this]() {
+ emit readingDictionaryFailed();
+ });
}
@@ -70,3 +76,8 @@ void AppModel::set_auto_load_dictionary(bool auto_load_dictionary) {
emit autoLoadDictionaryChanged();
}
}
+
+
+Dictionary* AppModel::get_dictionary() {
+ return &m_dictionary;
+}
diff --git a/src/AppModel.hpp b/src/AppModel.hpp
index 160064b..5d58088 100644
--- a/src/AppModel.hpp
+++ b/src/AppModel.hpp
@@ -7,6 +7,7 @@
#include
#endif
#include "Version.h"
+#include "Dictionary.hpp"
class AppModel : public QObject {
@@ -25,10 +26,13 @@ class AppModel : public QObject {
NOTIFY currentDictionaryChanged)
Q_PROPERTY(bool autoLoadDictionary READ get_auto_load_dictionary WRITE
set_auto_load_dictionary NOTIFY autoLoadDictionaryChanged)
+ Q_PROPERTY(Dictionary* dictionary READ get_dictionary CONSTANT)
signals:
void currentDictionaryChanged();
void autoLoadDictionaryChanged();
+ void readingDictionaryFinished();
+ void readingDictionaryFailed();
private:
QString get_current_dictionary() const;
@@ -37,7 +41,10 @@ class AppModel : public QObject {
bool get_auto_load_dictionary() const;
void set_auto_load_dictionary(bool auto_load_dictionary);
+ Dictionary* get_dictionary();
+
QString m_version{QString::fromStdString(project_version)};
QString m_current_dictionary;
bool m_auto_load_dictionary{true};
+ Dictionary m_dictionary;
};
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp
index a24ca49..4cdab9c 100644
--- a/src/Dictionary.cpp
+++ b/src/Dictionary.cpp
@@ -5,15 +5,16 @@
#include
#include
#include
+#include
Dictionary::Dictionary(QObject *parent) : QObject{parent} {
}
-void Dictionary::readAsync(const QString &filename) {
+void Dictionary::readAsync(const QUrl &filename) {
QThread *thread{new QThread};
- DictionaryLoader *worker{new DictionaryLoader(*this, filename)};
+ DictionaryLoader *worker{new DictionaryLoader(*this, filename.toLocalFile())};
worker->moveToThread(thread);
connect(worker, &DictionaryLoader::error, this, [this]() { emit readingError(); });
connect(thread, &QThread::started, worker, &DictionaryLoader::process);
diff --git a/src/Dictionary.hpp b/src/Dictionary.hpp
index 49456eb..286fc23 100644
--- a/src/Dictionary.hpp
+++ b/src/Dictionary.hpp
@@ -8,6 +8,7 @@
#include
#include
#include
+#include
class Dictionary;
@@ -24,7 +25,7 @@ class Dictionary : public QObject {
Q_PROPERTY(int size READ size NOTIFY sizeChanged)
Q_PROPERTY(bool dictionaryLoaded READ dictEmpty NOTIFY dictChanged)
- Q_INVOKABLE void readAsync(const QString &filename);
+ Q_INVOKABLE void readAsync(const QUrl &filename);
Q_INVOKABLE QVariantList translateAtoB(const QString &query) const;
Q_INVOKABLE QVariantList translateBtoA(const QString &query) const;