mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Changed ids to text
This commit is contained in:
parent
d47bcdff64
commit
999a2c5ef2
@ -31,36 +31,30 @@ Application::Application(int &argc, char **argv) : QGuiApplication(argc, argv) {
|
|||||||
view_.show();
|
view_.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::selectedFolderId() const {
|
QString Application::selectedFolderId() const {
|
||||||
QObject* rootObject = (QObject*)view_.rootObject();
|
QObject* rootObject = (QObject*)view_.rootObject();
|
||||||
|
|
||||||
int index = rootObject->property("currentFolderIndex").toInt();
|
int index = rootObject->property("currentFolderIndex").toInt();
|
||||||
QModelIndex modelIndex = folderModel_.index(index);
|
QModelIndex modelIndex = folderModel_.index(index);
|
||||||
return folderModel_.data(modelIndex, FolderModel::IdRole).toInt();
|
return folderModel_.data(modelIndex, FolderModel::IdRole).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::selectedNoteId() const {
|
QString Application::selectedNoteId() const {
|
||||||
QObject* rootObject = (QObject*)view_.rootObject();
|
QObject* rootObject = (QObject*)view_.rootObject();
|
||||||
|
|
||||||
int index = rootObject->property("currentNoteIndex").toInt();
|
int index = rootObject->property("currentNoteIndex").toInt();
|
||||||
QModelIndex modelIndex = noteModel_.index(index);
|
QModelIndex modelIndex = noteModel_.index(index);
|
||||||
return noteModel_.data(modelIndex, NoteModel::IdRole).toInt();
|
return noteModel_.data(modelIndex, NoteModel::IdRole).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::view_currentFolderChanged() {
|
void Application::view_currentFolderChanged() {
|
||||||
int folderId = selectedFolderId();
|
QString folderId = selectedFolderId();
|
||||||
noteCollection_ = NoteCollection(db_, folderId, "title ASC");
|
noteCollection_ = NoteCollection(db_, folderId, "title ASC");
|
||||||
noteModel_.setCollection(noteCollection_);
|
noteModel_.setCollection(noteCollection_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::view_currentNoteChanged() {
|
void Application::view_currentNoteChanged() {
|
||||||
int noteId = selectedNoteId();
|
QString noteId = selectedNoteId();
|
||||||
Note note = noteCollection_.byId(noteId);
|
Note note = noteCollection_.byId(noteId);
|
||||||
selectedQmlNote_.setNote(note);
|
selectedQmlNote_.setNote(note);
|
||||||
|
|
||||||
// TODO: get note by id
|
|
||||||
//Note note = noteCollection_.by
|
|
||||||
//selectedQmlNote_ = QmlNote(noteId);
|
|
||||||
//noteCollection_ = NoteCollection(db_, folderId, "title ASC");
|
|
||||||
//noteModel_.setCollection(noteCollection_);
|
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ private:
|
|||||||
NoteService noteService_;
|
NoteService noteService_;
|
||||||
FolderModel folderModel_;
|
FolderModel folderModel_;
|
||||||
NoteModel noteModel_;
|
NoteModel noteModel_;
|
||||||
int selectedFolderId() const;
|
QString selectedFolderId() const;
|
||||||
int selectedNoteId() const;
|
QString selectedNoteId() const;
|
||||||
NoteCache noteCache_;
|
NoteCache noteCache_;
|
||||||
QmlNote selectedQmlNote_;
|
QmlNote selectedQmlNote_;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ using namespace jop;
|
|||||||
Database::Database(const QString &path) {
|
Database::Database(const QString &path) {
|
||||||
version_ = -1;
|
version_ = -1;
|
||||||
|
|
||||||
QFile::remove(path);
|
// QFile::remove(path);
|
||||||
|
|
||||||
db_ = QSqlDatabase::addDatabase("QSQLITE");
|
db_ = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
db_.setDatabaseName(path);
|
db_.setDatabaseName(path);
|
||||||
|
@ -12,12 +12,12 @@ void Item::fromSqlQuery(const QSqlQuery &q) {
|
|||||||
int i_title = q.record().indexOf("title");
|
int i_title = q.record().indexOf("title");
|
||||||
int i_created_time = q.record().indexOf("created_time");
|
int i_created_time = q.record().indexOf("created_time");
|
||||||
|
|
||||||
id_ = q.value(i_id).toInt();
|
id_ = q.value(i_id).toString();
|
||||||
title_ = q.value(i_title).toString();
|
title_ = q.value(i_title).toString();
|
||||||
createdTime_ = q.value(i_created_time).toInt();
|
createdTime_ = q.value(i_created_time).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::id() const {
|
QString Item::id() const {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ int Item::createdTime() const {
|
|||||||
return createdTime_;
|
return createdTime_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::setId(int v) {
|
void Item::setId(const QString& v) {
|
||||||
id_ = v;
|
id_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@ public:
|
|||||||
|
|
||||||
Item();
|
Item();
|
||||||
|
|
||||||
int id() const;
|
QString id() const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
int createdTime() const;
|
int createdTime() const;
|
||||||
bool isPartial() const;
|
bool isPartial() const;
|
||||||
|
|
||||||
void setId(int v);
|
void setId(const QString &v);
|
||||||
void setTitle(const QString& v);
|
void setTitle(const QString& v);
|
||||||
void setCreatedTime(int v);
|
void setCreatedTime(int v);
|
||||||
void setIsPartial(bool v);
|
void setIsPartial(bool v);
|
||||||
@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int id_;
|
QString id_;
|
||||||
QString title_;
|
QString title_;
|
||||||
int createdTime_;
|
int createdTime_;
|
||||||
bool isPartial_;
|
bool isPartial_;
|
||||||
|
@ -4,14 +4,14 @@ using namespace jop;
|
|||||||
|
|
||||||
NoteCollection::NoteCollection() {}
|
NoteCollection::NoteCollection() {}
|
||||||
|
|
||||||
NoteCollection::NoteCollection(Database& db, int parentId, const QString& orderBy) {
|
NoteCollection::NoteCollection(Database& db, const QString& parentId, const QString& orderBy) {
|
||||||
db_ = db;
|
db_ = db;
|
||||||
parentId_ = parentId;
|
parentId_ = parentId;
|
||||||
orderBy_ = orderBy;
|
orderBy_ = orderBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
Note NoteCollection::at(int index) const {
|
Note NoteCollection::at(int index) const {
|
||||||
if (!parentId_) return Note();
|
if (parentId_ == "") return Note();
|
||||||
|
|
||||||
if (cache_.isset(index)) return cache_.get(index);
|
if (cache_.isset(index)) return cache_.get(index);
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ Note NoteCollection::at(int index) const {
|
|||||||
int noteIndex = from;
|
int noteIndex = from;
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
Note note;
|
Note note;
|
||||||
note.setId(q.value(0).toInt());
|
note.setId(q.value(0).toString());
|
||||||
note.setTitle(q.value(1).toString());
|
note.setTitle(q.value(1).toString());
|
||||||
note.setBody(q.value(2).toString());
|
note.setBody(q.value(2).toString());
|
||||||
note.setIsPartial(true);
|
note.setIsPartial(true);
|
||||||
@ -48,7 +48,7 @@ Note NoteCollection::at(int index) const {
|
|||||||
|
|
||||||
// TODO: cache result
|
// TODO: cache result
|
||||||
int NoteCollection::count() const {
|
int NoteCollection::count() const {
|
||||||
if (!parentId_) return 0;
|
if (parentId_ == "") return 0;
|
||||||
|
|
||||||
QSqlQuery q = db_.query("SELECT count(*) as row_count FROM notes WHERE parent_id = :parent_id");
|
QSqlQuery q = db_.query("SELECT count(*) as row_count FROM notes WHERE parent_id = :parent_id");
|
||||||
q.bindValue(":parent_id", parentId_);
|
q.bindValue(":parent_id", parentId_);
|
||||||
@ -57,7 +57,7 @@ int NoteCollection::count() const {
|
|||||||
return q.value(0).toInt();
|
return q.value(0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
Note NoteCollection::byId(int id) const {
|
Note NoteCollection::byId(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 (int i = 0; i < indexes.size(); i++) {
|
||||||
Note note = cache_.get(indexes[i]);
|
Note note = cache_.get(indexes[i]);
|
||||||
@ -75,7 +75,7 @@ Note NoteCollection::byId(int id) const {
|
|||||||
|
|
||||||
// TODO: refactor creation of note from SQL query object
|
// TODO: refactor creation of note from SQL query object
|
||||||
Note note;
|
Note note;
|
||||||
note.setId(q.value(0).toInt());
|
note.setId(q.value(0).toString());
|
||||||
note.setTitle(q.value(1).toString());
|
note.setTitle(q.value(1).toString());
|
||||||
note.setBody(q.value(2).toString());
|
note.setBody(q.value(2).toString());
|
||||||
return note;
|
return note;
|
||||||
|
@ -15,14 +15,14 @@ class NoteCollection {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
NoteCollection();
|
NoteCollection();
|
||||||
NoteCollection(Database& db, int parentId, const QString& orderBy);
|
NoteCollection(Database& db, const QString &parentId, const QString& orderBy);
|
||||||
Note at(int index) const;
|
Note at(int index) const;
|
||||||
int count() const;
|
int count() const;
|
||||||
Note byId(int id) const;
|
Note byId(const QString &id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int parentId_;
|
QString parentId_;
|
||||||
QString orderBy_;
|
QString orderBy_;
|
||||||
Database db_;
|
Database db_;
|
||||||
mutable SparseVector<Note> cache_;
|
mutable SparseVector<Note> cache_;
|
||||||
|
@ -16,7 +16,7 @@ int FolderService::count() const {
|
|||||||
return q.value(0).toInt();
|
return q.value(0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
Folder FolderService::byId(int id) const {
|
Folder FolderService::byId(const QString& id) const {
|
||||||
QSqlQuery q = database_.query("SELECT title, created_time FROM folders WHERE id = :id");
|
QSqlQuery q = database_.query("SELECT title, created_time FROM folders WHERE id = :id");
|
||||||
q.bindValue(":id", id);
|
q.bindValue(":id", id);
|
||||||
q.exec();
|
q.exec();
|
||||||
@ -37,7 +37,7 @@ const QList<Folder> FolderService::overviewList() const {
|
|||||||
q.exec();
|
q.exec();
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
Folder f;
|
Folder f;
|
||||||
f.setId(q.value(0).toInt());
|
f.setId(q.value(0).toString());
|
||||||
f.setTitle(q.value(1).toString());
|
f.setTitle(q.value(1).toString());
|
||||||
f.setIsPartial(true);
|
f.setIsPartial(true);
|
||||||
output << f;
|
output << f;
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
FolderService();
|
FolderService();
|
||||||
FolderService(Database& database);
|
FolderService(Database& database);
|
||||||
int count() const;
|
int count() const;
|
||||||
Folder byId(int id) const;
|
Folder byId(const QString &id) const;
|
||||||
//Folder partialAt(int index) const;
|
//Folder partialAt(int index) const;
|
||||||
const QList<Folder> overviewList() const;
|
const QList<Folder> overviewList() const;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ NoteCache::NoteCache() {
|
|||||||
|
|
||||||
void NoteCache::add(QList<Note> notes) {
|
void NoteCache::add(QList<Note> notes) {
|
||||||
foreach (Note note, notes) {
|
foreach (Note note, notes) {
|
||||||
cache_[note.id()] = note;
|
//cache_[note.id()] = note;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ const QList<Note> NoteService::overviewList(const QString& folderId, int from, i
|
|||||||
|
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
Note f;
|
Note f;
|
||||||
f.setId(q.value(0).toInt());
|
f.setId(q.value(0).toString());
|
||||||
f.setTitle(q.value(1).toString());
|
f.setTitle(q.value(1).toString());
|
||||||
f.setIsPartial(true);
|
f.setIsPartial(true);
|
||||||
output << f;
|
output << f;
|
||||||
@ -46,7 +46,7 @@ std::pair<const Note &, bool> NoteService::overviewAt(const QString &folderId, i
|
|||||||
if (!q.isValid()) return std::make_pair(Note(), false);
|
if (!q.isValid()) return std::make_pair(Note(), false);
|
||||||
|
|
||||||
Note f;
|
Note f;
|
||||||
f.setId(q.value(0).toInt());
|
f.setId(q.value(0).toString());
|
||||||
f.setTitle(q.value(1).toString());
|
f.setTitle(q.value(1).toString());
|
||||||
f.setIsPartial(true);
|
f.setIsPartial(true);
|
||||||
|
|
||||||
|
@ -165,18 +165,12 @@ xmltomd::Resource parseResource(QXmlStreamReader& reader) {
|
|||||||
return xmltomd::Resource();
|
return xmltomd::Resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//qApp->exit(0);
|
|
||||||
|
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
// qDebug() << reader.text();
|
|
||||||
// qApp->exit(0);
|
|
||||||
QString s = reader.readElementText();
|
QString s = reader.readElementText();
|
||||||
s = s.replace("\n", "");
|
s = s.replace("\n", "");
|
||||||
ba.append(s);
|
ba.append(s);
|
||||||
output.data = QByteArray::fromBase64(ba);
|
output.data = QByteArray::fromBase64(ba);
|
||||||
// qDebug() << output.data.toBase64();
|
|
||||||
// exit(0);
|
|
||||||
} else if (reader.name() == "mime") {
|
} else if (reader.name() == "mime") {
|
||||||
output.mime = reader.readElementText();
|
output.mime = reader.readElementText();
|
||||||
} else if (reader.name() == "resource-attributes") {
|
} else if (reader.name() == "resource-attributes") {
|
||||||
@ -192,10 +186,6 @@ xmltomd::Resource parseResource(QXmlStreamReader& reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output.id.length()) {
|
|
||||||
//output.id = createUuid(QString("%1%2%3%4").arg(output.filename).arg(output.timestamp).arg(QDateTime::currentMSecsSinceEpoch()).arg((int)qrand()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,9 +386,11 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
db.exec("BEGIN TRANSACTION");
|
db.exec("BEGIN TRANSACTION");
|
||||||
|
|
||||||
|
QString folderId = createUuid(QString("%1%2%3%4").arg(fileInfo.baseName()).arg(fileInfo.created().toTime_t()).arg((int)qrand()).arg(QDateTime::currentMSecsSinceEpoch()));
|
||||||
|
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
query.prepare("INSERT INTO folders (id, title, created_time, updated_time) VALUES (?, ?, ?, ?)");
|
query.prepare("INSERT INTO folders (id, title, created_time, updated_time) VALUES (?, ?, ?, ?)");
|
||||||
query.addBindValue(createUuid(QString("%1%2%3%4").arg(fileInfo.baseName()).arg(fileInfo.created().toTime_t()).arg((int)qrand()).arg(QDateTime::currentMSecsSinceEpoch())));
|
query.addBindValue(folderId);
|
||||||
query.addBindValue(fileInfo.baseName());
|
query.addBindValue(fileInfo.baseName());
|
||||||
query.addBindValue(fileInfo.created().toTime_t());
|
query.addBindValue(fileInfo.created().toTime_t());
|
||||||
query.addBindValue(fileInfo.created().toTime_t());
|
query.addBindValue(fileInfo.created().toTime_t());
|
||||||
@ -446,21 +438,22 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
QString markdown = xmltomd::evernoteXmlToMd(n.content, n.resources);
|
QString markdown = xmltomd::evernoteXmlToMd(n.content, n.resources);
|
||||||
|
|
||||||
QString html(n.content);
|
// QString html(n.content);
|
||||||
html.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
|
// html.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
|
||||||
html.replace("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">", "");
|
// html.replace("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">", "");
|
||||||
html = html.trimmed();
|
// html = html.trimmed();
|
||||||
|
|
||||||
html = "<style>* { margin: 0; padding:0; }</style><div style=\"width: 100%\"><div style=\"float: left; width: 45%; font-family:monospace;\">" + html + "</div><div style=\"float: left; width: 45%;\"><pre style=\"white-space: pre-wrap;\">" + markdown + "</pre></div></div>";
|
// html = "<style>* { margin: 0; padding:0; }</style><div style=\"width: 100%\"><div style=\"float: left; width: 45%; font-family:monospace;\">" + html + "</div><div style=\"float: left; width: 45%;\"><pre style=\"white-space: pre-wrap;\">" + markdown + "</pre></div></div>";
|
||||||
|
|
||||||
QString generatedPath = "D:/Web/www/joplin/tests/generated";
|
// QString generatedPath = "D:/Web/www/joplin/tests/generated";
|
||||||
filePutContents(QString("%1/%2_%3.html").arg(generatedPath).arg(i).arg(noteIndex), html);
|
// filePutContents(QString("%1/%2_%3.html").arg(generatedPath).arg(i).arg(noteIndex), html);
|
||||||
|
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
query.prepare("INSERT INTO notes (id, title, body, created_time, updated_time, longitude, latitude, altitude, source, author, source_url, is_todo, todo_due, todo_completed, source_application, application_data, `order`) VALUES (:id, :title,:body,:created_time,:updated_time,:longitude,:latitude,:altitude,:source,:author,:source_url,:is_todo,:todo_due,:todo_completed,:source_application,:application_data,:order)");
|
query.prepare("INSERT INTO notes (id, title, body, parent_id, created_time, updated_time, longitude, latitude, altitude, source, author, source_url, is_todo, todo_due, todo_completed, source_application, application_data, `order`) VALUES (:id, :title,:body, :parent_id, :created_time,:updated_time,:longitude,:latitude,:altitude,:source,:author,:source_url,:is_todo,:todo_due,:todo_completed,:source_application,:application_data,:order)");
|
||||||
query.bindValue(":id", n.id);
|
query.bindValue(":id", n.id);
|
||||||
query.bindValue(":title", n.title);
|
query.bindValue(":title", n.title);
|
||||||
query.bindValue(":body", markdown);
|
query.bindValue(":body", markdown);
|
||||||
|
query.bindValue(":parent_id", folderId);
|
||||||
query.bindValue(":created_time", n.created);
|
query.bindValue(":created_time", n.created);
|
||||||
query.bindValue(":updated_time", n.updated);
|
query.bindValue(":updated_time", n.updated);
|
||||||
query.bindValue(":longitude", n.longitude);
|
query.bindValue(":longitude", n.longitude);
|
||||||
|
Loading…
Reference in New Issue
Block a user