Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 219cf0a6 authored by Camilo higuita's avatar Camilo higuita

link and note snow use custom models and can be sorted

parent 0a95bc2a
......@@ -25,6 +25,7 @@
#include "src/linker.h"
#include "models/notes/notesmodel.h"
#include "models/links/linksmodel.h"
int main(int argc, char *argv[])
{
......@@ -62,10 +63,14 @@ int main(int argc, char *argv[])
context->setContextProperty("linker", &linker);
context->setContextProperty("tag", tag);
qmlRegisterType<DocumentHandler>("org.buho.editor", 1, 0, "DocumentHandler");
qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "Owl", 1, 0, "KEY", "Error");
qmlRegisterType<NotesModel>("Notes", 1, 0, "NotesModel");
qmlRegisterType<LinksModel>("Links", 1, 0, "LinksModel");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
......
......@@ -180,13 +180,6 @@ Maui.ApplicationWindow
}
Component.onCompleted:
{
notesView.populate()
linksView.populate()
}
function newNote()
{
currentView = views.notes
......@@ -209,8 +202,8 @@ Maui.ApplicationWindow
function previewLink(link)
{
var tags = owl.getLinkTags(link.link)
link.tags = tags
// var tags = linksView.model.getLinkTags(link.link)
// link.tags = tags
linksView.previewer.show(link)
}
......
......@@ -67,84 +67,6 @@ QVariantList DBActions::get(const QString &queryTxt)
return mapList;
}
bool DBActions::insertLink(const QVariantMap &link)
{
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->linkInserted(link_map);
return true;
}
return false;
}
bool DBActions::updateLink(const QVariantMap &link)
{
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 updated = link[OWL::KEYMAP[OWL::KEY::UPDATED]].toString();
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 DBActions::removeLink(const QVariantMap &link)
{
return this->db->remove(OWL::TABLEMAP[OWL::TABLE::LINKS], link);
}
QVariantList DBActions::getLinks()
{
return this->get("select * from links ORDER BY updated ASC");
}
QVariantList DBActions::getLinkTags(const QString &link)
{
return this->tag->getAbstractTags(OWL::TABLEMAP[OWL::TABLE::LINKS], link);
}
bool DBActions::execQuery(const QString &queryTxt)
{
auto query = this->db->getQuery(queryTxt);
......
......@@ -36,11 +36,6 @@ public:
Q_INVOKABLE QVariantList get(const QString &queryTxt);
/*main actions*/
Q_INVOKABLE bool insertLink(const QVariantMap &link);
Q_INVOKABLE bool updateLink(const QVariantMap &link);
Q_INVOKABLE bool removeLink(const QVariantMap &link);
Q_INVOKABLE QVariantList getLinks();
Q_INVOKABLE QVariantList getLinkTags(const QString &link);
protected:
OWL::DB_LIST getDBData(const QString &queryTxt);
......
......@@ -2,6 +2,7 @@
#include <QUuid>
#include "db/db.h"
#include "linker.h"
#ifdef STATIC_MAUIKIT
#include "tagging.h"
......@@ -17,50 +18,50 @@ Links::Links(QObject *parent) : QObject(parent)
void Links::sortBy(const OWL::KEY &key, const QString &order)
{
this->notes = this->db->getDBData(QString("select * from notes ORDER BY %1 %2").arg(OWL::KEYMAP[key], order));
this->links = this->db->getDBData(QString("select * from links ORDER BY %1 %2").arg(OWL::KEYMAP[key], order));
}
OWL::DB_LIST Links::items() const
{
return this->notes;
return this->links;
}
bool Links::insertNote(const QVariantMap &note)
bool Links::insertLink(const QVariantMap &link)
{
qDebug()<<"TAGS"<< note[OWL::KEYMAP[OWL::KEY::TAG]].toStringList();
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 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 image_path = OWL::saveImage(Linker::getUrl(preview), OWL::LinksPath+QUuid::createUuid().toString());
auto id = QUuid::createUuid().toString();
QVariantMap note_map =
QVariantMap link_map =
{
{OWL::KEYMAP[OWL::KEY::ID], id},
{OWL::KEYMAP[OWL::KEY::LINK], url},
{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()}
{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::NOTES], note_map))
if(this->db->insert(OWL::TABLEMAP[OWL::TABLE::LINKS], link_map))
{
for(auto tg : tags)
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id, color);
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color);
this->notes << OWL::DB
this->links << OWL::DB
({
{OWL::KEY::ID, id},
{OWL::KEY::LINK, url},
{OWL::KEY::TITLE, title},
{OWL::KEY::BODY, body},
{OWL::KEY::COLOR, color},
{OWL::KEY::PREVIEW, preview},
{OWL::KEY::PIN, QString::number(pin)},
{OWL::KEY::FAV, QString::number(fav)},
{OWL::KEY::UPDATED, QDateTime::currentDateTime().toString()},
......@@ -73,39 +74,37 @@ bool Links::insertNote(const QVariantMap &note)
return false;
}
bool Links::updateNote(const int &index, const QVariant &value, const int &role)
bool Links::updateLink(const int &index, const QVariant &value, const int &role)
{
if(index < 0 || index >= notes.size())
if(index < 0 || index >= links.size())
return false;
const auto oldValue = this->notes[index][static_cast<OWL::KEY>(role)];
const auto oldValue = this->links[index][static_cast<OWL::KEY>(role)];
if(oldValue == value.toString())
return false;
this->notes[index].insert(static_cast<OWL::KEY>(role), value.toString());
qDebug()<< "VALUE TO UPDATE"<< OWL::KEYMAP[static_cast<OWL::KEY>(role)] << oldValue;
this->links[index].insert(static_cast<OWL::KEY>(role), value.toString());
this->updateNote(this->notes[index]);
this->updateLink(this->links[index]);
return true;
}
bool Links::updateNote(const OWL::DB &note)
bool Links::updateLink(const OWL::DB &link)
{
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 =
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::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},
......@@ -113,18 +112,18 @@ bool Links::updateNote(const OWL::DB &note)
};
for(auto tg : tags)
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id, color);
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color);
return this->db->update(OWL::TABLEMAP[OWL::TABLE::NOTES], note_map, {{OWL::KEYMAP[OWL::KEY::ID], id}} );
return this->db->update(OWL::TABLEMAP[OWL::TABLE::LINKS], link_map, {{OWL::KEYMAP[OWL::KEY::LINK], url}} );
}
bool Links::removeNote(const QVariantMap &note)
bool Links::removeLink(const QVariantMap &link)
{
qDebug()<<note;
return this->db->remove(OWL::TABLEMAP[OWL::TABLE::NOTES], note);
qDebug()<<link;
return this->db->remove(OWL::TABLEMAP[OWL::TABLE::LINKS], link);
}
QVariantList Links::getNoteTags(const QString &id)
QVariantList Links::getLinkTags(const QString &link)
{
return this->tag->getAbstractTags(OWL::TABLEMAP[OWL::TABLE::NOTES], id);
return this->tag->getAbstractTags(OWL::TABLEMAP[OWL::TABLE::LINKS], link);
}
......@@ -18,19 +18,16 @@ public:
void sortBy(const OWL::KEY &key, const QString &order = "DESC");
Q_INVOKABLE bool insertLink(const QVariantMap &link);
bool updateLink(const int &index, const QVariant &value, const int &role);
bool updateLink(const OWL::DB &link);
Q_INVOKABLE bool removeLink(const QVariantMap &link);
bool insertNote(const QVariantMap &note);
bool updateNote(const int &index, const QVariant &value, const int &role);
bool updateNote(const OWL::DB &note);
bool removeNote(const QVariantMap &note);
QVariantList getNoteTags(const QString &id);
Q_INVOKABLE QVariantList getLinkTags(const QString &link);
private:
Tagging *tag;
DB *db;
OWL::DB_LIST notes;
OWL::DB_LIST links;
signals:
......
......@@ -4,29 +4,29 @@
LinksModel::LinksModel(QObject *parent)
: QAbstractListModel(parent)
{
this->mNotes = new Links(this);
this->mLinks = new Links(this);
}
int LinksModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mNotes)
if (parent.isValid() || !mLinks)
return 0;
return mNotes->items().size();
return mLinks->items().size();
}
QVariant LinksModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mNotes)
if (!index.isValid() || !mLinks)
return QVariant();
return mNotes->items().at(index.row())[static_cast<OWL::KEY>(role)];
return mLinks->items().at(index.row())[static_cast<OWL::KEY>(role)];
}
QVariantMap LinksModel::get(const int &index)
{
QVariantMap res;
const auto note = mNotes->items().at(index);
const auto note = mLinks->items().at(index);
for(auto key : note.keys())
res.insert(OWL::KEYMAP[key], note[key]);
return res;
......@@ -35,25 +35,25 @@ QVariantMap LinksModel::get(const int &index)
void LinksModel::sortBy(const int &index, const QString &order)
{
beginResetModel();
mNotes->sortBy(static_cast<OWL::KEY>(index), order);
mLinks->sortBy(static_cast<OWL::KEY>(index), order);
endResetModel();
}
bool LinksModel::insert(const QVariantMap &note)
bool LinksModel::insert(const QVariantMap &link)
{
const int index = mNotes->items().size();
const int index = mLinks->items().size();
beginInsertRows(QModelIndex(), index, index);
this->mNotes->insertNote(note);
this->mLinks->insertLink(link);
endInsertRows();
return false;
}
bool LinksModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mNotes)
if (!mLinks)
return false;
if (mNotes->updateNote(index.row(), value, role))
if (mLinks->updateLink(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
......@@ -92,36 +92,36 @@ QHash<int, QByteArray> LinksModel::roleNames() const
//Notes *NotesModel::notes() const
//{
// return mNotes;
// return mLinks;
//}
//void NotesModel::setNotes(Notes *value)
//{
// beginResetModel();
// if(mNotes)
// mNotes->disconnect(this);
// mNotes = value;
// if(mLinks)
// mLinks->disconnect(this);
// mLinks = value;
//// if(mNotes)
//// if(mLinks)
//// {
//// connect(mNotes, &Notes::preItemAppended, this, [=]()
//// connect(mLinks, &Notes::preItemAppended, this, [=]()
//// {
//// const int index = mNotes->items().size();
//// const int index = mLinks->items().size();
//// beginInsertRows(QModelIndex(), index, index);
//// });
//// connect(mNotes, &Notes::postItemAppended, this, [=]()
//// connect(mLinks, &Notes::postItemAppended, this, [=]()
//// {
//// endInsertRows();
//// });
//// connect(mNotes, &Notes::preItemRemoved, this, [=](int index)
//// connect(mLinks, &Notes::preItemRemoved, this, [=](int index)
//// {
//// beginInsertRows(QModelIndex(), index, index);
//// });
//// connect(mNotes, &Notes::preItemRemoved, this, [=]()
//// connect(mLinks, &Notes::preItemRemoved, this, [=]()
//// {
//// endRemoveRows();
//// });
......
#ifndef NOTESMODEL_H
#define NOTESMODEL_H
#ifndef LINKSMODEL_H
#define LINKSMODEL_H
#include <QAbstractListModel>
#include <QList>
......@@ -24,7 +24,7 @@ public:
Q_INVOKABLE QVariantMap get(const int &index);
Q_INVOKABLE void sortBy(const int &index, const QString &order);
Q_INVOKABLE bool insert(const QVariantMap &note);
Q_INVOKABLE bool insert(const QVariantMap &link);
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
......@@ -34,13 +34,8 @@ public:
virtual QHash<int, QByteArray> roleNames() const override;
friend bool operator<(const OWL::DB & m1, const OWL::DB & m2)
{
return m1[OWL::KEY::TITLE] < m2[OWL::KEY::TITLE];
}
private:
Links *mNotes;
Links *mLinks;
};
#endif // NOTESMODEL_H
import QtQuick 2.9
import "../../widgets"
import QtQuick.Controls 2.4
import org.kde.mauikit 1.0 as Maui
import "../../widgets"
import "../../utils/owl.js" as O
import Links 1.0
import Owl 1.0
Maui.Page
{
id: control
property alias cardsView : cardsView
property alias previewer : previewer
property alias model : linksModel
property var currentLink : ({})
signal linkClicked(var link)
headBarVisible: !cardsView.holder.visible
margins: space.big
......@@ -20,15 +29,46 @@ Maui.Page
Maui.ToolButton
{
iconName: cardsView.gridView ? "view-list-icons" : "view-list-details"
onClicked:
{
cardsView.gridView = !cardsView.gridView
cardsView.refresh()
}
onClicked: cardsView.gridView = !cardsView.gridView
},
Maui.ToolButton
{
iconName: "view-sort"
onClicked: sortMenu.open();
Menu
{
id: sortMenu
MenuItem
{
text: qsTr("Title")
onTriggered: linksModel.sortBy(KEY.TITLE, "ASC")
}
MenuItem
{
text: qsTr("Color")
onTriggered: linksModel.sortBy(KEY.COLOR, "ASC")
}
MenuItem
{
text: qsTr("Add date")
onTriggered: linksModel.sortBy(KEY.ADD_DATE, "DESC")
}
MenuItem
{
text: qsTr("Updated")
onTriggered: linksModel.sortBy(KEY.UPDATED, "DESC")
}
MenuItem
{
text: qsTr("Fav")
onTriggered: linksModel.sortBy(KEY.FAV, "DESC")
}
}
}
]
......@@ -56,8 +96,12 @@ Maui.Page
Previewer
{
id: previewer
onLinkSaved: if(owl.updateLink(link))
cardsView.currentItem.update(link)
onLinkSaved: cardsView.currentItem.update(link)
}
LinksModel
{
id: linksModel
}
CardsView
......@@ -71,6 +115,8 @@ Maui.Page
holder.body: "Click here to save a new link"
holder.emojiSize: iconSizes.huge
itemHeight: unit * 250
model: linksModel
Connections
{
target: cardsView.holder
......@@ -84,20 +130,4 @@ Maui.Page
cardsView.model.remove(cardsView.currentIndex)
}
}
function populate()
{
var data = owl.getLinks()
for(var i in data)
{
console.log("PREVIEW", data[i].preview)
append(data[i])
}
}
function append(link)
{
cardsView.model.append(link)
}
}
......@@ -21,7 +21,7 @@ Maui.Popup
anchors.fill: parent
margins: 0
padding: 0
headBarTitle: webView.title
headBarExit: false
headBar.leftContent: [
Maui.ToolButton
......@@ -170,6 +170,7 @@ Maui.Popup
function packLink()
{
linkSaved({
title: webView.title,
link: webView.url,
color: colorBar.currentColor,
tag: tagBar.getTags(),
......
......@@ -5,6 +5,7 @@ import "../../widgets"
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.2 as Kirigami
import "../../utils/owl.js" as O
import Notes 1.0
import Owl 1.0
......@@ -46,6 +47,12 @@ Maui.Page
onTriggered: notesModel.sortBy(KEY.TITLE, "ASC")
}
MenuItem
{
text: qsTr("Color")
onTriggered: notesModel.sortBy(KEY.COLOR, "ASC")
}
MenuItem
{
text: qsTr("Add date")
......@@ -148,17 +155,4 @@ Maui.Page
}
}
}
function populate()
{
// var data = owl.getNotes()
// for(var i in data)
// append(data[i])
}
function append(note)
{
cardsView.model.append(note)
}
}
......@@ -95,7 +95,8 @@ ItemDelegate
Layout.leftMargin: space.medium
Layout.bottomMargin: space.medium
Layout.rightMargin: space.medium
Layout.alignment: Qt.AlignLeft
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
Layout.preferredHeight: model.preview ? parent.height * 0.4 : undefined
Layout.fillWidth: true
Layout.fillHeight: true
...