1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-13 22:12:50 +02:00
This commit is contained in:
Laurent Cozic
2017-02-07 19:42:35 +00:00
parent a53f84ea57
commit b503dca462
17 changed files with 59 additions and 102 deletions

View File

@@ -32,7 +32,6 @@ SOURCES += \
models/foldermodel.cpp \ models/foldermodel.cpp \
models/notemodel.cpp \ models/notemodel.cpp \
models/note.cpp \ models/note.cpp \
models/qmlnote.cpp \
webapi.cpp \ webapi.cpp \
synchronizer.cpp \ synchronizer.cpp \
settings.cpp \ settings.cpp \
@@ -71,7 +70,6 @@ HEADERS += \
models/notemodel.h \ models/notemodel.h \
models/note.h \ models/note.h \
sparsevector.hpp \ sparsevector.hpp \
models/qmlnote.h \
webapi.h \ webapi.h \
synchronizer.h \ synchronizer.h \
settings.h \ settings.h \

View File

@@ -53,7 +53,7 @@ Application::Application(int &argc, char **argv) :
QQmlContext *ctxt = view_.rootContext(); QQmlContext *ctxt = view_.rootContext();
ctxt->setContextProperty("folderListModel", &folderModel_); ctxt->setContextProperty("folderListModel", &folderModel_);
ctxt->setContextProperty("noteListModel", &noteModel_); ctxt->setContextProperty("noteListModel", &noteModel_);
ctxt->setContextProperty("noteModel", &selectedQmlNote_); //ctxt->setContextProperty("noteModel", &selectedQmlNote_);
ctxt->setContextProperty("settings", qmlSettings); ctxt->setContextProperty("settings", qmlSettings);
view_.setSource(QUrl("qrc:/app.qml")); view_.setSource(QUrl("qrc:/app.qml"));

View File

@@ -6,7 +6,6 @@
#include "database.h" #include "database.h"
#include "models/foldermodel.h" #include "models/foldermodel.h"
#include "models/notemodel.h" #include "models/notemodel.h"
#include "models/qmlnote.h"
#include "webapi.h" #include "webapi.h"
#include "synchronizer.h" #include "synchronizer.h"
#include "window.h" #include "window.h"
@@ -31,7 +30,6 @@ private:
NoteModel noteModel_; NoteModel noteModel_;
QString selectedFolderId() const; QString selectedFolderId() const;
QString selectedNoteId() const; QString selectedNoteId() const;
QmlNote selectedQmlNote_;
WebApi api_; WebApi api_;
Synchronizer synchronizer_; Synchronizer synchronizer_;
QTimer synchronizerTimer_; QTimer synchronizerTimer_;

View File

@@ -45,19 +45,23 @@ void BaseItemListController::updateItemCount() {
} }
void BaseItemListController::itemList_rowsRequested(int fromIndex, int toIndex) { void BaseItemListController::itemList_rowsRequested(int fromIndex, int toIndex) {
Q_UNUSED(fromIndex); Q_UNUSED(toIndex);
qFatal("BaseItemListController::itemList_rowsRequested() must be implemented by child class"); qFatal("BaseItemListController::itemList_rowsRequested() must be implemented by child class");
} }
const BaseModel *BaseItemListController::cacheGet(int index) const { const BaseModel *BaseItemListController::cacheGet(int index) const {
Q_UNUSED(index);
qFatal("BaseItemListController::cacheGet() not implemented"); qFatal("BaseItemListController::cacheGet() not implemented");
return NULL; return NULL;
} }
void BaseItemListController::cacheSet(int index, BaseModel* baseModel) const { void BaseItemListController::cacheSet(int index, BaseModel* baseModel) const {
Q_UNUSED(index); Q_UNUSED(baseModel);
qFatal("BaseItemListController::cacheSet() not implemented"); qFatal("BaseItemListController::cacheSet() not implemented");
} }
bool BaseItemListController::cacheIsset(int index) const { bool BaseItemListController::cacheIsset(int index) const {
Q_UNUSED(index);
qFatal("BaseItemListController::cacheIsset() not implemented"); qFatal("BaseItemListController::cacheIsset() not implemented");
return false; return false;
} }

View File

@@ -22,8 +22,8 @@ public:
private: private:
QObject* itemList_;
QString parentId_; QString parentId_;
QObject* itemList_;
QString orderBy_; QString orderBy_;
protected: protected:

View File

@@ -2,23 +2,23 @@
set -e set -e
mkdir -p /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug # mkdir -p /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug
cd /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug # cd /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug
rm -rf debug/ release/ Makefile* # rm -rf debug/ release/ Makefile*
export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin":$PATH # export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin":$PATH
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/Windows Kits/8.1/bin/x86" # export PATH=$PATH:"/cygdrive/c/Program Files (x86)/Windows Kits/8.1/bin/x86"
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include" # export PATH=$PATH:"/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"
"/cygdrive/c/Qt/5.7/msvc2015/bin/qmake.exe" D:\\Web\\www\\joplin\\QtClient\\JoplinQtClient\\JoplinQtClient.pro -spec win32-msvc2015 "CONFIG+=debug" "CONFIG+=qml_debug" "JOP_FRONT_END_GUI=1" # "/cygdrive/c/Qt/5.7/msvc2015/bin/qmake.exe" D:\\Web\\www\\joplin\\QtClient\\JoplinQtClient\\JoplinQtClient.pro -spec win32-msvc2015 "CONFIG+=debug" "CONFIG+=qml_debug" "JOP_FRONT_END_GUI=1"
"/cygdrive/c/Qt/Tools/QtCreator/bin/jom.exe" qmake_all # "/cygdrive/c/Qt/Tools/QtCreator/bin/jom.exe" qmake_all
"/cygdrive/c/Qt/Tools/QtCreator/bin/jom.exe" # "/cygdrive/c/Qt/Tools/QtCreator/bin/jom.exe"
rsync -a /cygdrive/d/Web/www/joplin/QtClient/dependencies/dll-debug/ /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug/debug # rsync -a /cygdrive/d/Web/www/joplin/QtClient/dependencies/dll-debug/ /cygdrive/d/Web/www/joplin/QtClient/build-JoplinQtClient-Visual_C_32_bits-Debug/debug
cd - # cd -
# BUILD_DIR=/home/laurent/src/notes/QtClient/build-JoplinQtClient-Desktop_Qt_5_7_1_GCC_64bit-Debug BUILD_DIR=/home/laurent/src/notes/QtClient/build-JoplinQtClient-Desktop_Qt_5_7_1_GCC_64bit-Debug
# mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR"
# cd "$BUILD_DIR" cd "$BUILD_DIR"
# /opt/Qt/5.7/gcc_64/bin/qmake /home/laurent/src/notes/QtClient/JoplinQtClient/JoplinQtClient.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug JOP_FRONT_END_CLI=1 /opt/Qt/5.7/gcc_64/bin/qmake /home/laurent/src/notes/QtClient/JoplinQtClient/JoplinQtClient.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug JOP_FRONT_END_CLI=1
# /usr/bin/make qmake_all /usr/bin/make qmake_all
# /usr/bin/make /usr/bin/make

View File

@@ -146,7 +146,7 @@ int CliApplication::exec() {
} }
qStdout() << QString("Total: %1 items").arg(children.size()) << endl; qStdout() << QString("Total: %1 items").arg(children.size()) << endl;
for (int i = 0; i < children.size(); i++) { for (size_t i = 0; i < children.size(); i++) {
qStdout() << children[i]->displayTitle() << endl; qStdout() << children[i]->displayTitle() << endl;
} }
} }

View File

@@ -22,7 +22,7 @@ void FolderListController::cacheSet(int index, BaseModel *baseModel) const {
} }
bool FolderListController::cacheIsset(int index) const { bool FolderListController::cacheIsset(int index) const {
return index > 0 && cache_.size() > index; return index > 0 && cache_.size() > (size_t)index;
} }
void FolderListController::cacheClear() const { void FolderListController::cacheClear() const {
@@ -31,12 +31,13 @@ void FolderListController::cacheClear() const {
void FolderListController::itemList_rowsRequested(int fromIndex, int toIndex) { void FolderListController::itemList_rowsRequested(int fromIndex, int toIndex) {
if (!cache_.size()) { if (!cache_.size()) {
cache_ = Folder::all(parentId(), orderBy()); qFatal("TODO: replace with root::children()");
//cache_ = Folder::all(parentId(), orderBy());
} }
//qDebug() << cache_.size(); //qDebug() << cache_.size();
if (fromIndex < 0 || toIndex >= cache_.size() || !cache_.size()) { if (fromIndex < 0 || (size_t)toIndex >= cache_.size() || !cache_.size()) {
qWarning() << "Invalid folder indexes" << fromIndex << toIndex; qWarning() << "Invalid folder indexes" << fromIndex << toIndex;
return; return;
} }

View File

@@ -32,6 +32,7 @@ QVariant AbstractListModel::data(const QModelIndex & index, int role) const {
} }
const BaseModel *AbstractListModel::atIndex(int index) const { const BaseModel *AbstractListModel::atIndex(int index) const {
Q_UNUSED(index);
qFatal("AbstractListModel::atIndex() not implemented"); qFatal("AbstractListModel::atIndex() not implemented");
return NULL; return NULL;
} }
@@ -72,15 +73,18 @@ int AbstractListModel::baseModelCount() const {
} }
const BaseModel *AbstractListModel::cacheGet(int index) const { const BaseModel *AbstractListModel::cacheGet(int index) const {
Q_UNUSED(index);
qFatal("AbstractListModel::cacheGet() not implemented"); qFatal("AbstractListModel::cacheGet() not implemented");
return NULL; return NULL;
} }
void AbstractListModel::cacheSet(int index, BaseModel* baseModel) const { void AbstractListModel::cacheSet(int index, BaseModel* baseModel) const {
Q_UNUSED(index); Q_UNUSED(baseModel);
qFatal("AbstractListModel::cacheSet() not implemented"); qFatal("AbstractListModel::cacheSet() not implemented");
} }
bool AbstractListModel::cacheIsset(int index) const { bool AbstractListModel::cacheIsset(int index) const {
Q_UNUSED(index);
qFatal("AbstractListModel::cacheIsset() not implemented"); qFatal("AbstractListModel::cacheIsset() not implemented");
return false; return false;
} }
@@ -126,6 +130,7 @@ QString AbstractListModel::indexToId(int index) const {
} }
int AbstractListModel::idToIndex(const QString &id) const { int AbstractListModel::idToIndex(const QString &id) const {
Q_UNUSED(id);
qFatal("AbstractListModel::idToIndex() not implemented"); qFatal("AbstractListModel::idToIndex() not implemented");
return -1; return -1;
} }

View File

@@ -10,7 +10,7 @@ using namespace jop;
QMap<int, QVector<BaseModel::Field>> BaseModel::tableFields_; QMap<int, QVector<BaseModel::Field>> BaseModel::tableFields_;
QHash<QString, QVariant> BaseModel::cache_; QHash<QString, QVariant> BaseModel::cache_;
BaseModel::BaseModel() : table_(jop::UndefinedTable), isNew_(-1) {} BaseModel::BaseModel() : isNew_(-1), table_(jop::UndefinedTable) {}
QStringList BaseModel::changedFields() const { QStringList BaseModel::changedFields() const {
QStringList output; QStringList output;
@@ -410,7 +410,7 @@ void BaseModel::setValue(const QString &name, const QJsonValue &value, QMetaType
} else if (type == QMetaType::Int) { } else if (type == QMetaType::Int) {
setValue(name, value.toInt()); setValue(name, value.toInt());
} else { } else {
qFatal("Unsupported value type %s %d", name.toStdString(), type); qFatal("Unsupported value type %s %d", name.toStdString().c_str(), type);
} }
} }

View File

@@ -38,7 +38,7 @@ std::vector<std::unique_ptr<BaseModel>> Folder::children(const QString &orderBy,
std::vector<jop::Table> tables; std::vector<jop::Table> tables;
tables.push_back(jop::FoldersTable); tables.push_back(jop::FoldersTable);
tables.push_back(jop::NotesTable); tables.push_back(jop::NotesTable);
for (int tableIndex = 0; tableIndex < tables.size(); tableIndex++) { for (size_t tableIndex = 0; tableIndex < tables.size(); tableIndex++) {
jop::Table table = tables[tableIndex]; jop::Table table = tables[tableIndex];
QString sql = QString("SELECT %1 FROM %2 WHERE parent_id = :parent_id ORDER BY %3 %4 %5") QString sql = QString("SELECT %1 FROM %2 WHERE parent_id = :parent_id ORDER BY %3 %4 %5")
@@ -143,26 +143,26 @@ int Folder::count(const QString &parentId) {
return BaseModel::count(jop::FoldersTable, parentId); return BaseModel::count(jop::FoldersTable, parentId);
} }
std::vector<std::unique_ptr<Folder>> Folder::all(const QString& parentId, const QString &orderBy) { // std::vector<std::unique_ptr<Folder>> Folder::all(const QString& parentId, const QString &orderBy) {
QSqlQuery q = jop::db().prepare(QString("SELECT %1 FROM %2 WHERE parent_id = :parent_id ORDER BY %3") // QSqlQuery q = jop::db().prepare(QString("SELECT %1 FROM %2 WHERE parent_id = :parent_id ORDER BY %3")
.arg(BaseModel::tableFieldNames(jop::FoldersTable).join(",")) // .arg(BaseModel::tableFieldNames(jop::FoldersTable).join(","))
.arg(BaseModel::tableName(jop::FoldersTable)) // .arg(BaseModel::tableName(jop::FoldersTable))
.arg(orderBy)); // .arg(orderBy));
q.bindValue(":parent_id", parentId); // q.bindValue(":parent_id", parentId);
jop::db().execQuery(q); // jop::db().execQuery(q);
std::vector<std::unique_ptr<Folder>> output; // std::vector<std::unique_ptr<Folder>> output;
//if (!jop::db().errorCheck(q)) return output; // //if (!jop::db().errorCheck(q)) return output;
while (q.next()) { // while (q.next()) {
std::unique_ptr<Folder> folder(new Folder()); // std::unique_ptr<Folder> folder(new Folder());
folder->loadSqlQuery(q); // folder->loadSqlQuery(q);
output.push_back(std::move(folder)); // output.push_back(std::move(folder));
} // }
return output; // return output;
} // }
QString Folder::displayTitle() const { QString Folder::displayTitle() const {
return QString("%1/").arg(value("title").toString()); return QString("%1/").arg(value("title").toString());

View File

@@ -16,7 +16,7 @@ public:
Folder(); Folder();
static int count(const QString& parentId); static int count(const QString& parentId);
static std::vector<std::unique_ptr<Folder>> all(const QString& orderBy = "title"); // static std::vector<std::unique_ptr<Folder>> all(const QString& parentId = QString(""), const QString &orderBy = QString("title"));
static std::vector<std::unique_ptr<Folder>> pathToFolders(const QString& path, bool returnLast, int& errorCode); static std::vector<std::unique_ptr<Folder>> pathToFolders(const QString& path, bool returnLast, int& errorCode);
static QString pathBaseName(const QString& path); static QString pathBaseName(const QString& path);
static std::unique_ptr<Folder> root(); static std::unique_ptr<Folder> root();

View File

@@ -13,7 +13,7 @@ FolderModel::FolderModel() : AbstractListModel(), orderBy_("title") {
const BaseModel *FolderModel::atIndex(int index) const { const BaseModel *FolderModel::atIndex(int index) const {
if (cache_.size()) { if (cache_.size()) {
if (index < 0 || index >= cache_.size()) { if (index < 0 || index >= (int)cache_.size()) {
qWarning() << "Invalid folder index:" << index; qWarning() << "Invalid folder index:" << index;
return NULL; return NULL;
} }
@@ -23,7 +23,8 @@ const BaseModel *FolderModel::atIndex(int index) const {
cacheClear(); cacheClear();
cache_ = Folder::all(orderBy_); qFatal("TODO: replace with root::children()");
//cache_ = Folder::all(orderBy_);
if (!cache_.size()) { if (!cache_.size()) {
qWarning() << "Invalid folder index:" << index; qWarning() << "Invalid folder index:" << index;
@@ -79,7 +80,7 @@ void FolderModel::cacheSet(int index, BaseModel* baseModel) const {
} }
bool FolderModel::cacheIsset(int index) const { bool FolderModel::cacheIsset(int index) const {
return index > 0 && cache_.size() > index; return index > 0 && (int)cache_.size() > index;
} }
void FolderModel::cacheClear() const { void FolderModel::cacheClear() const {

View File

@@ -56,7 +56,7 @@ void NoteModel::setFolderId(const QString &v) {
int NoteModel::idToIndex(const QString &id) const { int NoteModel::idToIndex(const QString &id) const {
std::vector<int> indexes = cache_.indexes(); std::vector<int> indexes = cache_.indexes();
for (int i = 0; i < indexes.size(); i++) { for (size_t i = 0; i < indexes.size(); i++) {
Note* note = cache_.get(indexes[i]); Note* note = cache_.get(indexes[i]);
if (note->idString() == id) return indexes[i]; if (note->idString() == id) return indexes[i];
} }

View File

@@ -1,18 +0,0 @@
#include "qmlnote.h"
using namespace jop;
QmlNote::QmlNote() {}
QString QmlNote::title() const {
return note_.value("title").toString();
}
QString QmlNote::body() const {
return note_.value("body").toString();
}
void QmlNote::setNote(const Note &note) {
// note_ = note;
emit changed();
}

View File

@@ -1,32 +0,0 @@
#ifndef QMLNOTE_H
#define QMLNOTE_H
#include <stable.h>
#include "note.h"
namespace jop {
class QmlNote : public QObject {
Q_OBJECT
public:
QmlNote();
QString title() const;
QString body() const;
void setNote(const Note& note);
signals:
void changed();
private:
Note note_;
};
}
#endif // QMLNOTE_H

View File

@@ -11,7 +11,7 @@ QString paths::configDir() {
QDir d(configDir_); QDir d(configDir_);
if (!d.exists()) { if (!d.exists()) {
bool dirCreated = d.mkpath("."); bool dirCreated = d.mkpath(".");
if (!dirCreated) qFatal(QString("Cannot create config directory: " + configDir_).toLatin1()); if (!dirCreated) qFatal("Cannot create config directory: %s", configDir_.toStdString().c_str());
} }
return configDir_; return configDir_;
} }