diff --git a/buho.pro.user b/buho.pro.user index 58eb7cf..b25db7e 100644 --- a/buho.pro.user +++ b/buho.pro.user @@ -1,652 +1,652 @@ - + EnvironmentId {415a6c17-06fa-4d4e-973e-41bbf4031d43} ProjectExplorer.Project.ActiveTarget 0 ProjectExplorer.Project.EditorSettings true false true Cpp CppGlobal QmlJS QmlJSGlobal 2 UTF-8 false 4 false 80 true true 1 true false 0 true true 0 8 true 1 true true true false ProjectExplorer.Project.PluginSettings ProjectExplorer.Project.Target.0 Desktop Desktop {891e8f4a-3093-4399-8ec9-9373da7aca35} 0 0 0 /home/camilo/Coding/qml/build-buho-Desktop-Debug true qmake QtProjectManager.QMakeBuildStep true false false false true Make Qt4ProjectManager.MakeStep -w -r false 2 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Debug Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true /home/camilo/Coding/qml/build-buho-Desktop-Release true qmake QtProjectManager.QMakeBuildStep false false false true true Make Qt4ProjectManager.MakeStep -w -r false 2 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Release Release Qt4ProjectManager.Qt4BuildConfiguration 0 true /home/camilo/Coding/qml/build-buho-Desktop-Profile true qmake QtProjectManager.QMakeBuildStep true false true true true Make Qt4ProjectManager.MakeStep -w -r false 2 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Profile Profile Qt4ProjectManager.Qt4BuildConfiguration 0 true 3 0 Deploy ProjectExplorer.BuildSteps.Deploy 1 Deploy Configuration ProjectExplorer.DefaultDeployConfiguration 1 false false 1000 true false false false false true 0.01 10 true 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 buho Qt4ProjectManager.Qt4RunConfiguration:/home/camilo/Coding/qml/buho/buho.pro true buho.pro false /home/camilo/Coding/qml/build-buho-Desktop-Debug 3768 false true false false true 1 ProjectExplorer.Project.Target.1 Android for armeabi-v7a (GCC 4.9, Qt 5.11.1 (android_armv7)) Android for armeabi-v7a (GCC 4.9, Qt 5.11.1 (android_armv7)) {ed729225-da45-4c84-94a3-2313df7be654} 0 0 0 /home/camilo/Coding/qml/build-buho-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_1_android_armv7-Debug true qmake QtProjectManager.QMakeBuildStep true false false false true Make Qt4ProjectManager.MakeStep -w -r false true Copy application data Qt4ProjectManager.AndroidPackageInstallationStep android-27 true Build Android APK QmakeProjectManager.AndroidBuildApkStep false false 4 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Debug Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true /home/camilo/Coding/qml/build-buho-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_1_android_armv7-Release true qmake QtProjectManager.QMakeBuildStep false false false true true Make Qt4ProjectManager.MakeStep -w -r false true Copy application data Qt4ProjectManager.AndroidPackageInstallationStep android-27 true Build Android APK QmakeProjectManager.AndroidBuildApkStep false false 4 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Release Release Qt4ProjectManager.Qt4BuildConfiguration 0 true /home/camilo/Coding/qml/build-buho-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_1_android_armv7-Profile true qmake QtProjectManager.QMakeBuildStep true false true true true Make Qt4ProjectManager.MakeStep -w -r false true Copy application data Qt4ProjectManager.AndroidPackageInstallationStep android-27 true Build Android APK QmakeProjectManager.AndroidBuildApkStep false false 4 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep -w -r true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Profile Profile Qt4ProjectManager.Qt4BuildConfiguration 0 true 3 true Deploy to Android device Qt4ProjectManager.AndroidDeployQtStep false 1 Deploy ProjectExplorer.BuildSteps.Deploy 1 Deploy to Android device Qt4ProjectManager.AndroidDeployConfiguration2 1 false false 1000 true false false false false true 0.01 10 true 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 buho buho Qt4ProjectManager.AndroidRunConfiguration:/home/camilo/Coding/qml/buho/buho.pro buho.pro 3768 false true false false true 1 ProjectExplorer.Project.TargetCount 2 ProjectExplorer.Project.Updater.FileVersion 18 Version 18 diff --git a/main.qml b/main.qml index d7c3c19..750b66d 100644 --- a/main.qml +++ b/main.qml @@ -1,104 +1,114 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import org.kde.kirigami 2.0 as Kirigami import org.kde.maui 1.0 as Maui import "src/widgets" import "src/views/notes" Maui.ApplicationWindow { id: root title: qsTr("Buho") /***** PROPS *****/ property var views : ({ notes: 0, links: 1, books: 2 }) headBar.middleContent: Row { spacing: space.medium Maui.ToolButton { display: root.isWide ? ToolButton.TextBesideIcon : ToolButton.IconOnly iconName: "draw-text" text: qsTr("Notes") } Maui.ToolButton { display: root.isWide ? ToolButton.TextBesideIcon : ToolButton.IconOnly iconName: "link" text: qsTr("Links") } Maui.ToolButton { display: root.isWide ? ToolButton.TextBesideIcon : ToolButton.IconOnly iconName: "document-new" text: qsTr("Books") } } footBar.middleContent: Maui.PieButton { id: addButton iconName: "list-add" model: ListModel { ListElement {iconName: "document-new"; mid: "page"} ListElement {iconName: "link"; mid: "link"} ListElement {iconName: "draw-text"; mid: "note"} } onItemClicked: { if(item.mid === "note") newNoteDialog.open() } } footBar.leftContent: Maui.ToolButton { iconName: "document-share" } footBar.rightContent: Maui.ToolButton { iconName: "archive-remove" } /***** COMPONENTS *****/ NewNoteDialog { id: newNoteDialog + onNoteSaved: + { + if(owl.insertNote(title, body, color, tags)) + notesView.append({ + title : title, + body: body, + color: color, + tags: tags + }) + } } /***** VIEWS *****/ SwipeView { anchors.fill: parent currentIndex: views.notes NotesView { id: notesView } } Component.onCompleted: { notesView.populate() } } diff --git a/src/db/dbactions.cpp b/src/db/dbactions.cpp index ee936a0..ad436b5 100644 --- a/src/db/dbactions.cpp +++ b/src/db/dbactions.cpp @@ -1,140 +1,122 @@ /*** Buho Copyright (C) 2018 Camilo Higuita This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #include "dbactions.h" #include #include #include #include DBActions::DBActions(QObject *parent) : DB(parent) { qDebug() << "Getting collectionDB info from: " << OWL::CollectionDBPath; qDebug()<< "Starting DBActions"; } DBActions::~DBActions() {} OWL::DB_LIST DBActions::getDBData(const QString &queryTxt) { OWL::DB_LIST mapList; auto query = this->getQuery(queryTxt); if(query.exec()) { while(query.next()) { OWL::DB data; for(auto key : OWL::KEYMAP.keys()) if(query.record().indexOf(OWL::KEYMAP[key])>-1) data.insert(key, query.value(OWL::KEYMAP[key]).toString()); mapList<< data; } }else qDebug()<< query.lastError()<< query.lastQuery(); return mapList; } QVariantList DBActions::get(const QString &queryTxt) { QVariantList mapList; auto query = this->getQuery(queryTxt); if(query.exec()) { while(query.next()) { QVariantMap data; for(auto key : OWL::KEYMAP.keys()) if(query.record().indexOf(OWL::KEYMAP[key])>-1) data[OWL::KEYMAP[key]] = query.value(OWL::KEYMAP[key]).toString(); mapList<< data; } }else qDebug()<< query.lastError()<< query.lastQuery(); return mapList; } bool DBActions::insertNote(const QString &title, const QString &body, const QString &color, const QString &tags) { - QVariantMap json_note = - { - {OWL::SLANG[OWL::W::TITLE], title}, - {OWL::SLANG[OWL::W::BODY], body} - }; - - auto json = QJsonDocument::fromVariant(json_note); - auto note_url = OWL::NotesPath+title+QUuid::createUuid().toString(); - OWL::saveJson(json, note_url); + auto id = QUuid::createUuid().toString(); QVariantMap note_map = { - {OWL::KEYMAP[OWL::KEY::URL], note_url}, + {OWL::KEYMAP[OWL::KEY::ID], id}, + {OWL::KEYMAP[OWL::KEY::TITLE], title}, + {OWL::KEYMAP[OWL::KEY::BODY], body}, {OWL::KEYMAP[OWL::KEY::COLOR], color}, {OWL::KEYMAP[OWL::KEY::ADD_DATE], QDateTime::currentDateTime()} }; - if(!tags.isEmpty()) - { - for(auto tag : tags.split(",")) - { - this->insert(OWL::TABLEMAP[OWL::TABLE::TAGS], {{OWL::KEYMAP[OWL::KEY::TAG], tag}}); - this->insert(OWL::TABLEMAP[OWL::TABLE::NOTES_TAGS], - { - {OWL::KEYMAP[OWL::KEY::TAG], tag}, - {OWL::KEYMAP[OWL::KEY::URL], note_url} - }); - } - } +// if(!tags.isEmpty()) +// { +// for(auto tag : tags.split(",")) +// { +// this->insert(OWL::TABLEMAP[OWL::TABLE::TAGS], {{OWL::KEYMAP[OWL::KEY::TAG], tag}}); +// this->insert(OWL::TABLEMAP[OWL::TABLE::NOTES_TAGS], +// { +// {OWL::KEYMAP[OWL::KEY::TAG], tag}, +// {OWL::KEYMAP[OWL::KEY::URL], note_url} +// }); +// } +// } return this->insert(OWL::TABLEMAP[OWL::TABLE::NOTES], note_map); } QVariantList DBActions::getNotes() { - QVariantList res; - auto data = this->getDBData("select * from notes"); - - for(auto note : data) - { - auto map = OWL::openJson(note[OWL::KEY::URL]); - map.insert(OWL::SLANG[OWL::W::ADD_DATE], note[OWL::KEY::ADD_DATE]); - map.insert(OWL::SLANG[OWL::W::COLOR], note[OWL::KEY::COLOR]); - - res << map; - } - - return res; + return this->get("select * from notes"); } bool DBActions::execQuery(const QString &queryTxt) { auto query = this->getQuery(queryTxt); return query.exec(); } diff --git a/src/db/script.sql b/src/db/script.sql index 66e5141..96d106b 100644 --- a/src/db/script.sql +++ b/src/db/script.sql @@ -1,13 +1,15 @@ CREATE TABLE IF NOT EXISTS NOTES ( -url TEXT PRIMARY KEY, +id TEXT PRIMARY KEY, +title TEXT, +body TEXT, color TEXT, addDate DATE ); CREATE TABLE IF NOT EXISTS BOOKS ( url TEXT PRIMARY KEY, title TEXT NOT NULL, fav INTEGER NOT NULL, addDate DATE ); diff --git a/src/utils/owl.h b/src/utils/owl.h index 772cc0c..00e4182 100644 --- a/src/utils/owl.h +++ b/src/utils/owl.h @@ -1,141 +1,147 @@ #ifndef OWL_H #define OWL_H #include #include #include #include #include #include #include #include #include #include #include namespace OWL { Q_NAMESPACE enum class W : uint8_t { TITLE, BODY, IMAGE, VIDEO, LINK, TAG, AUTHOR, DATE, NOTE, TAGS, ADD_DATE, COLOR }; static const QMap SLANG = { {W::TITLE, "title"}, {W::BODY, "body"}, {W::IMAGE, "image"}, {W::VIDEO, "video"}, {W::LINK, "link"}, {W::TAG, "tag"}, {W::AUTHOR, "author"}, {W::DATE, "date"}, {W::NOTE, "note"}, {W::TAGS, "tags"}, {W::ADD_DATE, "addDate"}, {W::COLOR, "color"} }; enum class TABLE : uint8_t { NOTES, NOTES_TAGS, TAGS, BOOKS, PAGES, BOOKS_PAGES, LINKS, LINKS_TAGS, PAGES_TAGS, NONE }; static const QMap TABLEMAP = { {TABLE::NOTES,"notes"}, {TABLE::NOTES_TAGS,"notes_tags"}, {TABLE::TAGS,"tags"}, {TABLE::BOOKS,"books"}, {TABLE::PAGES,"pages"}, {TABLE::BOOKS_PAGES,"books_pages"}, {TABLE::LINKS,"links"}, {TABLE::LINKS_TAGS,"links_tags"}, {TABLE::PAGES_TAGS,"pages_tags"}, {TABLE::LINKS_TAGS,"links_tags"} }; enum class KEY :uint8_t { URL, + ID, + TITLE, + BODY, FAV, COLOR, ADD_DATE, TAG, NONE }; typedef QMap DB; typedef QList DB_LIST; static const DB KEYMAP = { + {KEY::ID, "id"}, + {KEY::BODY, "body"}, + {KEY::TITLE, "title"}, {KEY::URL, "url"}, {KEY::FAV, "fav"}, {KEY::COLOR, "color"}, {KEY::ADD_DATE, "addDate"}, {KEY::TAG, "tag"} }; const QString CollectionDBPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/buho/"; const QString NotesPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/buho/notes/"; const QString BooksPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/buho/books/"; const QString LinksPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/buho/links/"; const QString App = "Buho"; const QString version = "1.0"; const QString DBName = "collection.db"; inline bool fileExists(const QString &url) { QFileInfo path(url); if (path.exists()) return true; else return false; } inline void saveJson(QJsonDocument document, QString fileName) { QFile jsonFile(fileName); jsonFile.open(QFile::WriteOnly); jsonFile.write(document.toJson()); } inline QVariantMap openJson(const QString &url) { QString val; QFile file; file.setFileName(url); file.open(QIODevice::ReadOnly | QIODevice::Text); val = file.readAll(); file.close(); QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); QJsonObject obj = d.object(); return obj.toVariantMap(); } } #endif // OWL_H diff --git a/src/views/notes/NotesView.qml b/src/views/notes/NotesView.qml index 3f1b273..d9d9d73 100644 --- a/src/views/notes/NotesView.qml +++ b/src/views/notes/NotesView.qml @@ -1,20 +1,25 @@ import QtQuick 2.9 import "../../widgets" import org.kde.maui 1.0 as Maui Maui.Page { headBarVisible: false CardsView { id: cardsView anchors.fill: parent } function populate() { var data = owl.getNotes() for(var i in data) - cardsView.model.append(data[i]) + append(data[i]) + } + + function append(item) + { + cardsView.model.append(item) } } diff --git a/src/widgets/NewNoteDialog.qml b/src/widgets/NewNoteDialog.qml index 5454810..1c8ff00 100644 --- a/src/widgets/NewNoteDialog.qml +++ b/src/widgets/NewNoteDialog.qml @@ -1,223 +1,223 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.0 import org.kde.maui 1.0 as Maui Popup { parent: ApplicationWindow.overlay height: parent.height * (isMobile ? 0.8 : 0.7) width: parent.width * (isMobile ? 0.9 : 0.7) property string selectedColor : "#ffffe6" - + signal noteSaved(string title, string body, string color, string tags) x: (parent.width / 2) - (width / 2) y: (parent.height /2 ) - (height / 2) padding: 1 Rectangle { id: bg color: selectedColor z: -1 anchors.fill: parent } ColumnLayout { anchors.fill: parent Maui.ToolBar { Layout.fillWidth: true leftContent: [ Maui.ToolButton { iconName: "format-text-bold" }, Maui.ToolButton { iconName: "format-text-italic-symbolic" }, Maui.ToolButton { iconName: "format-text-underline-symbolic" }, Maui.ToolButton { iconName: "format-text-uppercase" } ] rightContent: Row { spacing: space.medium Rectangle { color:"#ffded4" anchors.verticalCenter: parent.verticalCenter height: iconSizes.medium width: height radius: Math.max(height, width) border.color: borderColor MouseArea { anchors.fill: parent onClicked: selectedColor = parent.color } } Rectangle { color:"#d3ffda" anchors.verticalCenter: parent.verticalCenter height: iconSizes.medium width: height radius: Math.max(height, width) border.color: borderColor MouseArea { anchors.fill: parent onClicked: selectedColor = parent.color } } Rectangle { color:"#caf3ff" anchors.verticalCenter: parent.verticalCenter height: iconSizes.medium width: height radius: Math.max(height, width) border.color: borderColor MouseArea { anchors.fill: parent onClicked: selectedColor = parent.color } } Rectangle { color:"#ccc1ff" anchors.verticalCenter: parent.verticalCenter height: iconSizes.medium width: height radius: Math.max(height, width) border.color: borderColor MouseArea { anchors.fill: parent onClicked: selectedColor = parent.color } } Rectangle { color:"#ffcdf4" anchors.verticalCenter: parent.verticalCenter height: iconSizes.medium width: height radius: Math.max(height, width) border.color: borderColor MouseArea { anchors.fill: parent onClicked: selectedColor = parent.color } } Maui.ToolButton { iconName: "overflow-menu" } } } TextField { id: title Layout.fillWidth: true Layout.margins: space.medium height: 24 placeholderText: qsTr("Title") font.weight: Font.Bold font.bold: true background: Rectangle { color: "transparent" } } ScrollView { Layout.fillHeight: true Layout.fillWidth: true Layout.margins: space.medium TextArea { id: body placeholderText: qsTr("Body") background: Rectangle { color: "transparent" } } } Row { Layout.fillWidth: true width: parent.width Layout.margins: space.medium Layout.alignment: Qt.AlignRight spacing: space.medium Button { id: save text: qsTr("Save") onClicked: { - if(owl.insertNote(title.text, body.text)) - close() + close() + noteSaved(title.text, body.text, selectedColor, "") } } Button { id: discard text: qsTr("Discard") onClicked: { clearNote() close() } } } } onOpened: clearNote() function clearNote() { title.clear() body.clear() } }