diff --git a/src/models/links/links.cpp b/src/models/links/links.cpp index ca9df59..84d1af8 100644 --- a/src/models/links/links.cpp +++ b/src/models/links/links.cpp @@ -1,200 +1,200 @@ #include "links.h" #include #include "db/db.h" #include "linker.h" #ifdef STATIC_MAUIKIT #include "tagging.h" #else #include #endif Links::Links(QObject *parent) : BaseList(parent) { this->db = DB::getInstance(); - this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment); + this->tag = Tagging::getInstance(); this->sortList(); connect(this, &Links::sortByChanged, this, &Links::sortList); connect(this, &Links::orderChanged, this, &Links::sortList); } void Links::sortList() { emit this->preListChanged(); this->links = this->db->getDBData(QString("select * from links ORDER BY %1 %2").arg( OWL::KEYMAP[this->sort], this->order == ORDER::ASC ? "asc" : "desc")); emit this->postListChanged(); } QVariantMap Links::get(const int &index) const { if(index >= this->links.size() || index < 0) return QVariantMap(); QVariantMap res; const auto note = this->links.at(index); for(auto key : note.keys()) res.insert(OWL::KEYMAP[key], note[key]); return res; } OWL::DB_LIST Links::items() const { return this->links; } bool Links::insert(const QVariantMap &link) { emit this->preItemAppended(); auto url = link[OWL::KEYMAP[OWL::KEY::LINK]].toString(); auto color = link[OWL::KEYMAP[OWL::KEY::COLOR]].toString(); auto pin = link[OWL::KEYMAP[OWL::KEY::PIN]].toInt(); auto fav = link[OWL::KEYMAP[OWL::KEY::FAV]].toInt(); auto tags = link[OWL::KEYMAP[OWL::KEY::TAG]].toStringList(); auto preview = link[OWL::KEYMAP[OWL::KEY::PREVIEW]].toString(); auto title = link[OWL::KEYMAP[OWL::KEY::TITLE]].toString(); auto image_path = OWL::saveImage(Linker::getUrl(preview), OWL::LinksPath+QUuid::createUuid().toString()); QVariantMap link_map = { {OWL::KEYMAP[OWL::KEY::LINK], url}, {OWL::KEYMAP[OWL::KEY::TITLE], title}, {OWL::KEYMAP[OWL::KEY::PIN], pin}, {OWL::KEYMAP[OWL::KEY::FAV], fav}, {OWL::KEYMAP[OWL::KEY::PREVIEW], image_path}, {OWL::KEYMAP[OWL::KEY::COLOR], color}, {OWL::KEYMAP[OWL::KEY::ADD_DATE], QDateTime::currentDateTime().toString()}, {OWL::KEYMAP[OWL::KEY::UPDATED], QDateTime::currentDateTime().toString()} }; if(this->db->insert(OWL::TABLEMAP[OWL::TABLE::LINKS], link_map)) { for(auto tg : tags) this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color); this->links << OWL::DB ({ {OWL::KEY::LINK, url}, {OWL::KEY::TITLE, title}, {OWL::KEY::COLOR, color}, {OWL::KEY::PREVIEW, image_path}, {OWL::KEY::PIN, QString::number(pin)}, {OWL::KEY::FAV, QString::number(fav)}, {OWL::KEY::UPDATED, QDateTime::currentDateTime().toString()}, {OWL::KEY::ADD_DATE, QDateTime::currentDateTime().toString()} }); emit postItemAppended(); return true; } else qDebug()<< "LINK COULD NOT BE INSTED"; return false; } bool Links::update(const int &index, const QVariant &value, const int &role) { if(index < 0 || index >= links.size()) return false; const auto oldValue = this->links[index][static_cast(role)]; if(oldValue == value.toString()) return false; qDebug()<< "VALUE TO UPDATE"<< OWL::KEYMAP[static_cast(role)] << oldValue; this->links[index].insert(static_cast(role), value.toString()); this->update(this->links[index]); return true; } bool Links::update(const QVariantMap &data, const int &index) { if(index < 0 || index >= this->links.size()) return false; auto newData = this->links[index]; QVector roles; for(auto key : data.keys()) if(newData[OWL::MAPKEY[key]] != data[key].toString()) { newData.insert(OWL::MAPKEY[key], data[key].toString()); roles << OWL::MAPKEY[key]; } this->links[index] = newData; if(this->update(newData)) { qDebug() << "update link" << newData; emit this->updateModel(index, roles); return true; } return false; } bool Links::update(const OWL::DB &link) { auto url = link[OWL::KEY::LINK]; auto color = link[OWL::KEY::COLOR]; auto pin = link[OWL::KEY::PIN].toInt(); auto fav = link[OWL::KEY::FAV].toInt(); auto tags = link[OWL::KEY::TAG].split(",", QString::SkipEmptyParts); auto updated = link[OWL::KEY::UPDATED]; QVariantMap link_map = { {OWL::KEYMAP[OWL::KEY::COLOR], color}, {OWL::KEYMAP[OWL::KEY::PIN], pin}, {OWL::KEYMAP[OWL::KEY::FAV], fav}, {OWL::KEYMAP[OWL::KEY::UPDATED], updated} }; for(auto tg : tags) this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color); return this->db->update(OWL::TABLEMAP[OWL::TABLE::LINKS], link_map, {{OWL::KEYMAP[OWL::KEY::LINK], url}} ); } bool Links::remove(const int &index) { emit this->preItemRemoved(index); auto linkUrl = this->links.at(index)[OWL::KEY::LINK]; QVariantMap link = {{OWL::KEYMAP[OWL::KEY::LINK], linkUrl}}; if(this->db->remove(OWL::TABLEMAP[OWL::TABLE::LINKS], link)) { this->links.removeAt(index); emit this->postItemRemoved(); return true; } return false; } QVariantList Links::getTags(const int &index) { if(index < 0 || index >= this->links.size()) return QVariantList(); auto link = this->links.at(index)[OWL::KEY::LINK]; return this->tag->getAbstractTags(OWL::TABLEMAP[OWL::TABLE::LINKS], link); } diff --git a/src/models/notes/notes.cpp b/src/models/notes/notes.cpp index 6773a99..670a117 100644 --- a/src/models/notes/notes.cpp +++ b/src/models/notes/notes.cpp @@ -1,196 +1,196 @@ #include "notes.h" #include #include "db/db.h" #ifdef STATIC_MAUIKIT #include "tagging.h" #else #include #endif Notes::Notes(QObject *parent) : BaseList(parent) { qDebug()<< "CREATING NOTES LIST"; this->db = DB::getInstance(); - this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment); + this->tag = Tagging::getInstance(); this->sortList(); connect(this, &Notes::sortByChanged, this, &Notes::sortList); connect(this, &Notes::orderChanged, this, &Notes::sortList); } void Notes::sortList() { emit this->preListChanged(); this->notes = this->db->getDBData(QString("select * from notes ORDER BY %1 %2").arg( OWL::KEYMAP[this->sort], this->order == ORDER::ASC ? "asc" : "desc")); emit this->postListChanged(); } OWL::DB_LIST Notes::items() const { return this->notes; } bool Notes::insert(const QVariantMap ¬e) { qDebug()<<"TAGS"<< note[OWL::KEYMAP[OWL::KEY::TAG]].toStringList(); emit this->preItemAppended(); auto title = note[OWL::KEYMAP[OWL::KEY::TITLE]].toString(); auto body = note[OWL::KEYMAP[OWL::KEY::BODY]].toString(); auto color = note[OWL::KEYMAP[OWL::KEY::COLOR]].toString(); auto pin = note[OWL::KEYMAP[OWL::KEY::PIN]].toInt(); auto fav = note[OWL::KEYMAP[OWL::KEY::FAV]].toInt(); auto tags = note[OWL::KEYMAP[OWL::KEY::TAG]].toStringList(); auto id = QUuid::createUuid().toString(); QVariantMap note_map = { {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::PIN], pin}, {OWL::KEYMAP[OWL::KEY::FAV], fav}, {OWL::KEYMAP[OWL::KEY::UPDATED], QDateTime::currentDateTime().toString()}, {OWL::KEYMAP[OWL::KEY::ADD_DATE], QDateTime::currentDateTime().toString()} }; if(this->db->insert(OWL::TABLEMAP[OWL::TABLE::NOTES], note_map)) { for(auto tg : tags) this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id, color); this->notes << OWL::DB ({ {OWL::KEY::ID, id}, {OWL::KEY::TITLE, title}, {OWL::KEY::BODY, body}, {OWL::KEY::COLOR, color}, {OWL::KEY::PIN, QString::number(pin)}, {OWL::KEY::FAV, QString::number(fav)}, {OWL::KEY::UPDATED, QDateTime::currentDateTime().toString()}, {OWL::KEY::ADD_DATE, QDateTime::currentDateTime().toString()} }); emit postItemAppended(); return true; } else qDebug()<< "NOTE COULD NOT BE INSTED"; return false; } bool Notes::update(const int &index, const QVariant &value, const int &role) { if(index < 0 || index >= notes.size()) return false; const auto oldValue = this->notes[index][static_cast(role)]; if(oldValue == value.toString()) return false; this->notes[index].insert(static_cast(role), value.toString()); this->update(this->notes[index]); return true; } bool Notes::update(const QVariantMap &data, const int &index) { if(index < 0 || index >= this->notes.size()) return false; auto newData = this->notes[index]; QVector roles; for(auto key : data.keys()) if(newData[OWL::MAPKEY[key]] != data[key].toString()) { newData.insert(OWL::MAPKEY[key], data[key].toString()); roles << OWL::MAPKEY[key]; } this->notes[index] = newData; if(this->update(newData)) { emit this->updateModel(index, roles); return true; } return false; } bool Notes::update(const OWL::DB ¬e) { auto id = note[OWL::KEY::ID]; auto title = note[OWL::KEY::TITLE]; auto body = note[OWL::KEY::BODY]; auto color = note[OWL::KEY::COLOR]; auto pin = note[OWL::KEY::PIN].toInt(); auto fav = note[OWL::KEY::FAV].toInt(); auto tags = note[OWL::KEY::TAG].split(",", QString::SkipEmptyParts); auto updated =note[OWL::KEY::UPDATED]; QVariantMap note_map = { {OWL::KEYMAP[OWL::KEY::TITLE], title}, {OWL::KEYMAP[OWL::KEY::BODY], body}, {OWL::KEYMAP[OWL::KEY::COLOR], color}, {OWL::KEYMAP[OWL::KEY::PIN], pin}, {OWL::KEYMAP[OWL::KEY::FAV], fav}, {OWL::KEYMAP[OWL::KEY::UPDATED], updated} }; for(auto tg : tags) this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id, color); return this->db->update(OWL::TABLEMAP[OWL::TABLE::NOTES], note_map, {{OWL::KEYMAP[OWL::KEY::ID], id}} ); } bool Notes::remove(const int &index) { emit this->preItemRemoved(index); auto id = this->notes.at(index)[OWL::KEY::ID]; QVariantMap note = {{OWL::KEYMAP[OWL::KEY::ID], id}}; if(this->db->remove(OWL::TABLEMAP[OWL::TABLE::NOTES], note)) { this->notes.removeAt(index); emit this->postItemRemoved(); return true; } return false; } QVariantList Notes::getTags(const int &index) { if(index < 0 || index >= this->notes.size()) return QVariantList(); auto id = this->notes.at(index)[OWL::KEY::ID]; return this->tag->getAbstractTags(OWL::TABLEMAP[OWL::TABLE::NOTES], id); } QVariantMap Notes::get(const int &index) const { if(index >= this->notes.size() || index < 0) return QVariantMap(); QVariantMap res; const auto note = this->notes.at(index); for(auto key : note.keys()) res.insert(OWL::KEYMAP[key], note[key]); return res; } diff --git a/src/views/links/Previewer.qml b/src/views/links/Previewer.qml index 77d85e7..9c82052 100644 --- a/src/views/links/Previewer.qml +++ b/src/views/links/Previewer.qml @@ -1,166 +1,163 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.0 import org.kde.mauikit 1.0 as Maui import "../../widgets" Maui.Dialog { parent: parent heightHint: 0.97 widthHint: 0.97 maxWidth: 800*unit maxHeight: maxWidth page.margins: 0 property color selectedColor : "transparent" property alias webView: webViewer.item signal linkSaved(var link) headBar.leftContent: [ Maui.ToolButton { id: pinButton iconName: "edit-pin" checkable: true iconColor: checked ? highlightColor : textColor // onClicked: checked = !checked }, Maui.ToolButton { iconName: "document-save" }, Maui.ToolButton { iconName: "document-launch" onClicked: Maui.FM.openUrl(webView.url) } ] headBar.rightContent: ColorsBar { id: colorBar onColorPicked: selectedColor = color } footBar.leftContent: [ Maui.ToolButton { id: favButton iconName: "love" checkable: true iconColor: checked ? "#ff007f" : textColor }, Maui.ToolButton { iconName: "document-share" onClicked: isAndroid ? Maui.Android.shareLink(webView.url) : shareDialog.show(webView.url) }, Maui.ToolButton { iconName: "document-export" }, Maui.ToolButton { iconName: "entry-delete" } ] onAccepted: { packLink() close() } onRejected: close() acceptText: qsTr("Save") rejectText: qsTr("Discard") colorScheme.backgroundColor: selectedColor ColumnLayout { anchors.fill: parent // Item // { // Layout.fillWidth: true // height: rowHeightAlt // Label // { // clip: true // text: webView.title // width: parent.width // height: parent.height // horizontalAlignment: Qt.AlignHCenter // verticalAlignment: Qt.AlignVCenter // font.bold: true // font.pointSize: fontSizes.big // font.weight: Font.Bold // elide: Label.ElideRight // } // } Loader { id: webViewer Layout.fillWidth: true Layout.fillHeight: true Layout.margins: 0 source: isAndroid ? "qrc:/src/views/links/WebViewAndroid.qml" : "qrc:/src/views/links/WebViewLinux.qml" onVisibleChanged: { if(!visible) webView.url = "about:blank" } } Maui.TagsBar { id: tagBar Layout.fillWidth: true allowEditMode: true - - onTagsEdited: - { - for(var i in tags) - append({tag : tags[i]}) - } + list.abstract: true + list.key: "links" + onTagsEdited: list.updateToAbstract(tags) } } function show(link) { console.log("STATE:" , link.fav) webView.url = link.link - tagBar.populate(link.tags) + tagBar.list.lot = link.link pinButton.checked = link.pin == 1 favButton.checked = link.fav == 1 selectedColor = link.color open() } function packLink() { console.log(favButton.checked) linkSaved({ title: webView.title, link: webView.url, color: selectedColor, tag: tagBar.getTags(), pin: pinButton.checked ? 1 : 0, fav: favButton.checked ? 1 : 0, updated: new Date() }) } } diff --git a/src/widgets/NewLinkDialog.qml b/src/widgets/NewLinkDialog.qml index aedf296..230d35a 100644 --- a/src/widgets/NewLinkDialog.qml +++ b/src/widgets/NewLinkDialog.qml @@ -1,235 +1,233 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.0 import org.kde.mauikit 1.0 as Maui import org.kde.kirigami 2.2 as Kirigami Maui.Dialog { parent: parent heightHint: 0.95 widthHint: 0.95 maxHeight: previewReady ? unit * 800 : contentLayout.implicitHeight maxWidth: unit *700 signal linkSaved(var link) property string selectedColor : "#ffffe6" property string fgColor: Qt.darker(selectedColor, 2.5) property bool previewReady : false x: (parent.width / 2) - (width / 2) y: (parent.height /2 ) - (height / 2) modal: true padding: isAndroid ? 1 : undefined Connections { target: linker onPreviewReady: { previewReady = true fill(link) } } headBar.visible: previewReady footBar.visible: previewReady headBar.leftContent: Maui.ToolButton { id: pinButton iconName: "window-pin" checkable: true iconColor: checked ? highlightColor : textColor // onClicked: checked = !checked } headBar.rightContent: ColorsBar { onColorPicked: selectedColor = color } footBar.leftContent: [ Maui.ToolButton { id: favButton iconName: "love" checkable: true iconColor: checked ? "#ff007f" : textColor }, Maui.ToolButton { iconName: "document-share" onClicked: isAndroid ? Maui.Android.shareText(link.text) : shareDialog.show(link.text) }, Maui.ToolButton { iconName: "document-export" } ] acceptText: qsTr("Save") rejectText: qsTr("Discard") onAccepted: { packLink() clear() } onRejected: clear() ColumnLayout { id: contentLayout anchors.fill: parent TextField { id: link Layout.fillWidth: true Layout.margins: space.medium height: rowHeight verticalAlignment: Qt.AlignVCenter placeholderText: qsTr("URL") font.weight: Font.Bold font.bold: true font.pointSize: fontSizes.large color: fgColor Layout.alignment: Qt.AlignCenter background: Rectangle { color: "transparent" } onAccepted: linker.extract(link.text) } TextField { id: title visible: previewReady Layout.fillWidth: true Layout.margins: space.medium height: 24 placeholderText: qsTr("Title") font.weight: Font.Bold font.bold: true font.pointSize: fontSizes.large color: fgColor background: Rectangle { color: "transparent" } } Item { Layout.fillWidth: true Layout.fillHeight: true visible: previewReady ListView { id: previewList anchors.fill: parent anchors.centerIn: parent visible: count > 0 clip: true snapMode: ListView.SnapOneItem orientation: ListView.Horizontal interactive: count > 1 highlightFollowsCurrentItem: true model: ListModel{} onMovementEnded: { var index = indexAt(contentX, contentY) currentIndex = index } delegate: ItemDelegate { height: previewList.height width: previewList.width background: Rectangle { color: "transparent" } Image { id: img source: model.url fillMode: Image.PreserveAspectFit asynchronous: true width: parent.width height: parent.height sourceSize.height: height horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter } } } } Maui.TagsBar { id: tagBar visible: previewReady Layout.fillWidth: true allowEditMode: true - - onTagsEdited: - { - for(var i in tags) - append({tag : tags[i]}) - } + list.abstract: true + list.key: "links" + onTagsEdited: list.updateToAbstract(tags) } } function clear() { title.clear() link.clear() previewList.model.clear() tagBar.clear() previewReady = false close() } function fill(link) { title.text = link.title populatePreviews(link.image) + tagBar.list.lot= link.url open() } function populatePreviews(imgs) { for(var i in imgs) { console.log("PREVIEW:", imgs[i]) previewList.model.append({url : imgs[i]}) } } function packLink() { var data = ({ link : link.text, title: title.text, preview: previewList.count > 0 ? previewList.model.get(previewList.currentIndex).url : "", color: selectedColor, tag: tagBar.getTags(), pin: pinButton.checked, fav: favButton.checked }) linkSaved(data) } } diff --git a/src/widgets/NewNoteDialog.qml b/src/widgets/NewNoteDialog.qml index 2505841..22a6268 100644 --- a/src/widgets/NewNoteDialog.qml +++ b/src/widgets/NewNoteDialog.qml @@ -1,219 +1,217 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.0 import org.kde.mauikit 1.0 as Maui Maui.Dialog { parent: parent heightHint: 0.95 widthHint: 0.95 maxWidth: 700*unit maxHeight: maxWidth property string selectedColor : "#ffffe6" property string fgColor: Qt.darker(selectedColor, 2.5) property bool showEditActions : false rejectButton.visible: false signal noteSaved(var note) page.margins: 0 colorScheme.backgroundColor: selectedColor headBar.leftContent: [ Maui.ToolButton { iconName: "edit-undo" enabled: editor.body.canUndo onClicked: editor.body.undo() opacity: enabled ? 1 : 0.5 }, Maui.ToolButton { iconName: "edit-redo" enabled: editor.body.canRedo onClicked: editor.body.redo() opacity: enabled ? 1 : 0.5 }, Maui.ToolButton { iconName: "format-text-bold" focusPolicy: Qt.TabFocus iconColor: checked ? highlightColor : textColor checkable: true checked: editor.document.bold onClicked: editor.document.bold = !editor.document.bold }, Maui.ToolButton { iconName: "format-text-italic" iconColor: checked ? highlightColor : textColor focusPolicy: Qt.TabFocus checkable: true checked: editor.document.italic onClicked: editor.document.italic = !editor.document.italic }, Maui.ToolButton { iconName: "format-text-underline" iconColor: checked ? highlightColor : textColor focusPolicy: Qt.TabFocus checkable: true checked: editor.document.underline onClicked: editor.document.underline = !editor.document.underline }, Maui.ToolButton { iconName: "format-text-uppercase" iconColor: checked ? highlightColor : textColor focusPolicy: Qt.TabFocus checkable: true checked: editor.document.uppercase onClicked: editor.document.uppercase = !editor.document.uppercase }, Maui.ToolButton { iconName: "image" } ] headBar.rightContent: ColorsBar { onColorPicked: selectedColor = color } footBar.leftContent: [ Maui.ToolButton { id: pinButton iconName: "edit-pin" checkable: true iconColor: checked ? highlightColor : textColor // onClicked: checked = !checked }, Maui.ToolButton { id: favButton iconName: "love" checkable: true iconColor: checked ? "#ff007f" : textColor }, Maui.ToolButton { iconName: "document-share" onClicked: isAndroid ? Maui.Android.shareText(editor.body.text) : shareDialog.show(editor.body.text) }, Maui.ToolButton { iconName: "document-export" }, Maui.ToolButton { iconName: "entry-delete" } ] acceptText: qsTr("Save") rejectText: qsTr("Discard") onAccepted: { if(editor.body.text.length > 0) packNote() clear() } onRejected: clear() ColumnLayout { anchors.fill: parent TextField { id: title Layout.fillWidth: true Layout.margins: space.medium height: 24 placeholderText: qsTr("Title") font.weight: Font.Bold font.bold: true font.pointSize: fontSizes.large color: fgColor background: Rectangle { color: "transparent" } } Maui.Editor { id: editor Layout.fillHeight: true Layout.fillWidth: true colorScheme.backgroundColor: selectedColor headBar.visible: false } Maui.TagsBar { id: tagBar Layout.fillWidth: true allowEditMode: true - - onTagsEdited: - { - for(var i in tags) - append({tag : tags[i]}) - } + list.abstract: true + list.key: "notes" + onTagsEdited: list.updateToAbstract(tags) } } onOpened: if(isMobile) editor.body.forceActiveFocus() function clear() { title.clear() editor.body.clear() close() } function fill(note) { title.text = note.title editor.body.text = note.body selectedColor = note.color pinButton.checked = note.pin == 1 favButton.checked = note.fav == 1 - tagBar.populate(note.tags) + + tagBar.list.lot= note.id open() } function packNote() { noteSaved({ id: notesView.currentNote.id, title: title.text.trim(), body: editor.body.text, color: selectedColor, tag: tagBar.getTags(), pin: pinButton.checked ? 1 : 0, fav: favButton.checked ? 1 : 0, updated: new Date() }) } }