Commit d0d0ab6e authored by camilo higuita's avatar camilo higuita

work on initial interfaces for the books feature

parent f05a19ec
......@@ -24,6 +24,7 @@
#include "./src/linker.h"
#include "./src/models/notes/notes.h"
#include "./src/models/books/books.h"
#include "./src/models/links/links.h"
int main(int argc, char *argv[])
......@@ -61,6 +62,7 @@ int main(int argc, char *argv[])
Linker linker;
context->setContextProperty("linker", &linker);
qmlRegisterType<Notes>("Notes", 1, 0, "Notes");
qmlRegisterType<Books>("Books", 1, 0, "Books");
qmlRegisterType<Links>("Links", 1, 0, "Links");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
......@@ -172,7 +172,11 @@ Maui.ApplicationWindow
NewBookDialog
{
id: newBookDialog
onBookSaved: console.log("saving new vbook", title)
onBookSaved:
{
if(title && title.length)
booksView.list.insert({title: title})
}
}
// /***** VIEWS *****/
......
......@@ -20,12 +20,26 @@ FOREIGN KEY(id) REFERENCES NOTES(id)
);
CREATE TABLE IF NOT EXISTS BOOKS (
url TEXT PRIMARY KEY,
id TEXT PRIMARY KEY,
url TEXT,
title TEXT NOT NULL,
favorite INT,
adddate DATE,
modified DATE
);
CREATE TABLE IF NOT EXISTS BOOKLETS (
id TEXT,
book TEXT,
url TEXT,
title TEXT NOT NULL,
favorite INTEGER NOT NULL,
adddate DATE
adddate DATE,
modified DATE
PRIMARY KEY(id, book)
FOREIGN KEY(book) REFERENCES BOOKS(id)
);
CREATE TABLE IF NOT EXISTS LINKS (
url TEXT PRIMARY KEY,
title TEXT,
......
......@@ -7,6 +7,14 @@ Books::Books(QObject *parent) : MauiList(parent),
{
this->syncer->setProvider(new NextNote);
connect(syncer, &Syncer::booksReady, [&](FMH::MODEL_LIST books)
{
emit this->preListChanged();
this->m_list = books;
qDebug()<< "ALL THE BOOKS ARE < "<< this->m_list;
emit this->postListChanged();
});
this->syncer->getBooks();
}
......@@ -53,13 +61,16 @@ bool Books::insert(const QVariantMap &book)
emit this->preItemAppended();
auto __book = FMH::toModel(book);
__book[FMH::MODEL_KEY::THUMBNAIL] = "qrc:/booklet.svg";
__book[FMH::MODEL_KEY::LABEL] =__book[FMH::MODEL_KEY::TITLE];
__book[FMH::MODEL_KEY::MODIFIED] = QDateTime::currentDateTime().toString(Qt::TextDate);
__book[FMH::MODEL_KEY::ADDDATE] = QDateTime::currentDateTime().toString(Qt::TextDate);
this->syncer->insertNote(__book);
this->syncer->insertBook(__book);
this->m_list << __book;
qDebug() << m_list;
emit this->postItemAppended();
return true;
}
......
......@@ -33,7 +33,7 @@ void Syncer::setProvider(AbstractNotesProvider *provider)
void Syncer::insertNote(FMH::MODEL &note)
{
if(!this->insertLocal(note))
if(!this->insertNoteLocal(note))
{
qWarning()<< "The note could not be inserted locally, "
"therefore it was not attempted to insert it to the remote provider server, "
......@@ -41,13 +41,13 @@ void Syncer::insertNote(FMH::MODEL &note)
return;
}
this->insertRemote(note);
this->insertNoteRemote(note);
emit this->noteInserted(note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note inserted on the DB locally"});
}
void Syncer::updateNote(const QString &id, const FMH::MODEL &note)
{
if(!this->updateLocal(id, note))
if(!this->updateNoteLocal(id, note))
{
qWarning()<< "The note could not be updated locally, "
"therefore it was not attempted to update it on the remote server provider, "
......@@ -58,7 +58,7 @@ void Syncer::updateNote(const QString &id, const FMH::MODEL &note)
//to update remote note we need to pass the stamp as the id
const auto stamp = Syncer::noteStampFromId(this->db, id);
if(!stamp.isEmpty())
this->updateRemote(stamp, note);
this->updateNoteRemote(stamp, note);
emit this->noteUpdated(note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note updated on the DB locally"});
}
......@@ -69,7 +69,7 @@ void Syncer::removeNote(const QString &id)
//and before removing the note locally we need to retireved first
const auto stamp = Syncer::noteStampFromId(this->db, id);
if(!this->removeLocal(id))
if(!this->removeNoteLocal(id))
{
qWarning()<< "The note could not be inserted locally, "
"therefore it was not attempted to insert it to the remote provider server, "
......@@ -78,7 +78,7 @@ void Syncer::removeNote(const QString &id)
}
if(!stamp.isEmpty())
this->removeRemote(stamp);
this->removeNoteRemote(stamp);
emit this->noteRemoved(FMH::MODEL(), {STATE::TYPE::LOCAL, STATE::STATUS::OK, "The note has been removed from the local DB"});
}
......@@ -101,27 +101,30 @@ void Syncer::getBooks()
const auto books = this->collectAllBooks();
// this service is still missing
// if(this->provider && this->provider->isValid())
// this->provider->getNotes();
// else
// qWarning()<< "Credentials are missing to get notes or the provider has not been set";
// if(this->provider && this->provider->isValid())
// this->provider->getNotes();
// else
// qWarning()<< "Credentials are missing to get notes or the provider has not been set";
emit this->booksReady(books);
}
void Syncer::insertBook(const FMH::MODEL &book)
void Syncer::insertBook(FMH::MODEL &book)
{
if(!this->db->insert(OWL::TABLEMAP[OWL::TABLE::BOOKS], FMH::toMap(book)))
if(!this->insertBookLocal(book))
{
qWarning()<< "Could not insert Book, Syncer::insertBook";
return;
}
emit this->bookInserted(book, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Book inserted locally sucessfully"});
}
void Syncer::stampNote(FMH::MODEL &note)
void Syncer::addId(FMH::MODEL &model)
{
const auto id = QUuid::createUuid().toString();
note[FMH::MODEL_KEY::ID] = id;
model[FMH::MODEL_KEY::ID] = id;
}
......@@ -182,7 +185,7 @@ void Syncer::setConections()
__note[FMH::MODEL_KEY::MODIFIED] = QDateTime::fromSecsSinceEpoch(note[FMH::MODEL_KEY::MODIFIED].toInt()).toString(Qt::TextDate);
__note[FMH::MODEL_KEY::ADDDATE] = __note[FMH::MODEL_KEY::MODIFIED];
if(!this->insertLocal(__note))
if(!this->insertNoteLocal(__note))
{
qWarning()<< "Remote note could not be inserted to the local storage";
continue;
......@@ -206,7 +209,7 @@ void Syncer::setConections()
FMH::MODEL_KEY::MODIFIED,
FMH::MODEL_KEY::FAVORITE});
__note[FMH::MODEL_KEY::MODIFIED] = QDateTime::fromSecsSinceEpoch(note[FMH::MODEL_KEY::MODIFIED].toInt()).toString(Qt::TextDate);
this->updateLocal(id, __note);
this->updateNoteLocal(id, __note);
emit this->noteInserted(note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note inserted on local db, from the server provider"});
}
}
......@@ -218,7 +221,7 @@ void Syncer::setConections()
{
const auto id = Syncer::noteIdFromStamp(this->db, this->provider->provider(), note[FMH::MODEL_KEY::ID]);
if(!note.isEmpty())
this->updateLocal(id, FMH::filterModel(note, {FMH::MODEL_KEY::TITLE}));
this->updateNoteLocal(id, FMH::filterModel(note, {FMH::MODEL_KEY::TITLE}));
emit this->noteUpdated(note, {STATE::TYPE::REMOTE, STATE::STATUS::OK, "Note updated on server provider"});
});
......@@ -228,11 +231,11 @@ void Syncer::setConections()
});
}
bool Syncer::insertLocal(FMH::MODEL &note)
bool Syncer::insertNoteLocal(FMH::MODEL &note)
{
qDebug()<<"TAGS"<< note[FMH::MODEL_KEY::TAG];
Syncer::stampNote(note); //adds a local id to the note
Syncer::addId(note); //adds a local id to the note
// create a file for the note
const auto __notePath = Syncer::saveNoteFile(note);
......@@ -260,13 +263,13 @@ bool Syncer::insertLocal(FMH::MODEL &note)
return false;
}
void Syncer::insertRemote(FMH::MODEL &note)
void Syncer::insertNoteRemote(FMH::MODEL &note)
{
if(this->provider && this->provider->isValid())
this->provider->insertNote(note);
}
bool Syncer::updateLocal(const QString &id, const FMH::MODEL &note)
bool Syncer::updateNoteLocal(const QString &id, const FMH::MODEL &note)
{
for(const auto &tg : note[FMH::MODEL_KEY::TAG])
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id);
......@@ -281,24 +284,107 @@ bool Syncer::updateLocal(const QString &id, const FMH::MODEL &note)
FMH::MODEL_KEY::FAVORITE})), QVariantMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id}});
}
void Syncer::updateRemote(const QString &id, const FMH::MODEL &note)
void Syncer::updateNoteRemote(const QString &id, const FMH::MODEL &note)
{
if(this->provider && this->provider->isValid())
this->provider->updateNote(id, note);
}
bool Syncer::removeLocal(const QString &id)
bool Syncer::removeNoteLocal(const QString &id)
{
this->db->remove(OWL::TABLEMAP[OWL::TABLE::NOTES_SYNC], {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id}});
return this->db->remove(OWL::TABLEMAP[OWL::TABLE::NOTES], {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id}});
}
void Syncer::removeRemote(const QString &id)
void Syncer::removeNoteRemote(const QString &id)
{
if(this->provider && this->provider->isValid())
this->provider->removeNote(id);
}
bool Syncer::insertBookLocal(FMH::MODEL &book)
{
const auto __path = QUrl::fromLocalFile(OWL::BooksPath+book[FMH::MODEL_KEY::TITLE]);
if(FMH::fileExists(__path))
{
qWarning()<< "The directory for the book already exists. Syncer::insertBookLocal" << book[FMH::MODEL_KEY::TITLE];
return false;
}
if(!FM::createDir(QUrl::fromLocalFile(OWL::BooksPath), book[FMH::MODEL_KEY::TITLE]))
{
qWarning() << "Could not create directory for the given book name. Syncer::insertBookLocal" << book[FMH::MODEL_KEY::TITLE];
return false;
}
Syncer::addId(book);
book[FMH::MODEL_KEY::URL] = __path.toString();
return(this->db->insert(OWL::TABLEMAP[OWL::TABLE::BOOKS], FMH::toMap(FMH::filterModel(book,{FMH::MODEL_KEY::ID,
FMH::MODEL_KEY::URL,
FMH::MODEL_KEY::TITLE,
FMH::MODEL_KEY::FAVORITE,
FMH::MODEL_KEY::ADDDATE,
FMH::MODEL_KEY::MODIFIED}
))));
}
void Syncer::insertBookRemote(FMH::MODEL &book)
{
}
bool Syncer::updateBookLocal(const QString &id, const FMH::MODEL &book)
{
return false;
}
void Syncer::updateBookRemote(const QString &id, const FMH::MODEL &book)
{
}
bool Syncer::removeBookLocal(const QString &id)
{
return false;
}
void Syncer::removeBookRemote(const QString &id)
{
}
bool Syncer::insertBookletLocal(FMH::MODEL &booklet)
{
return false;
}
void Syncer::insertBookletRemote(FMH::MODEL &booklet)
{
}
bool Syncer::updateBookletLocal(const QString &id, const FMH::MODEL &booklet)
{
return false;
}
void Syncer::updateBookletRemote(const QString &id, const FMH::MODEL &booklet)
{
}
bool Syncer::removeBookletLocal(const QString &id)
{
return false;
}
void Syncer::removeBookletRemote(const QString &id)
{
}
const FMH::MODEL_LIST Syncer::collectAllNotes()
{
FMH::MODEL_LIST __notes = this->db->getDBData("select * from notes");
......
......@@ -140,7 +140,7 @@ public:
* @brief insertBook
* @param book
*/
void insertBook(const FMH::MODEL &book);
void insertBook(FMH::MODEL &book);
/**
* @brief updateBook
......@@ -217,7 +217,7 @@ private:
* @param note
* the note model is passed by ref and a STAMP key value is inserted
*/
static void stampNote(FMH::MODEL &note);
static void addId(FMH::MODEL &model);
static const QString noteIdFromStamp(DB *_db, const QString &provider, const QString &stamp) ;
static const QString noteStampFromId(DB *_db, const QString &id) ;
......@@ -233,7 +233,7 @@ protected:
* @return bool
* true if the note was inserted sucessfully in the local storage
*/
bool insertLocal(FMH::MODEL &note);
bool insertNoteLocal(FMH::MODEL &note);
/**
* @brief insertRemote
......@@ -241,14 +241,25 @@ protected:
* @param note
* the note to be inserted
*/
void insertRemote(FMH::MODEL &note);
bool updateLocal(const QString &id, const FMH::MODEL &note);
void updateRemote(const QString &id, const FMH::MODEL &note);
bool removeLocal(const QString &id);
void removeRemote(const QString &id);
void insertNoteRemote(FMH::MODEL &note);
bool updateNoteLocal(const QString &id, const FMH::MODEL &note);
void updateNoteRemote(const QString &id, const FMH::MODEL &note);
bool removeNoteLocal(const QString &id);
void removeNoteRemote(const QString &id);
bool insertBookLocal(FMH::MODEL &book);
void insertBookRemote(FMH::MODEL &book);
bool updateBookLocal(const QString &id, const FMH::MODEL &book);
void updateBookRemote(const QString &id, const FMH::MODEL &book);
bool removeBookLocal(const QString &id);
void removeBookRemote(const QString &id);
bool insertBookletLocal(FMH::MODEL &booklet);
void insertBookletRemote(FMH::MODEL &booklet);
bool updateBookletLocal(const QString &id, const FMH::MODEL &booklet);
void updateBookletRemote(const QString &id, const FMH::MODEL &booklet);
bool removeBookletLocal(const QString &id);
void removeBookletRemote(const QString &id);
const FMH::MODEL_LIST collectAllNotes();
const FMH::MODEL_LIST collectAllBooks();
......
import QtQuick 2.9
import "../../widgets"
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.7 as Kirigami
import Books 1.0
StackView
{
id: control
property alias list : _booksList
property alias cardsView : cardsView
property bool showDetails: false
StackView
{
id: _stackView
......@@ -31,6 +33,16 @@ StackView
}
Maui.BaseModel
{
id: _booksModel
list: _booksList
}
Books
{
id: _booksList
}
Maui.Page
{
......@@ -64,36 +76,64 @@ StackView
adaptContent: !showDetails
itemSize: showDetails ? iconSizes.big : iconSizes.huge
// centerContent: true
spacing: space.big
spacing: space.huge
cellWidth: showDetails ? parent.width : itemSize * 1.5
cellHeight: itemSize * 1.5
model: ListModel
model: _booksModel
delegate: ItemDelegate
{
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 0}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 3}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 10}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 2}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 9}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 2}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 3}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 1}
ListElement {label: "test"; thumbnail:"qrc:/booklet.svg"; mime: "image"; count: 0}
id: _delegate
width: cardsView.cellWidth * 0.9
height: cardsView.cellHeight
}
hoverEnabled: !isMobile
background: Rectangle
{
color: "transparent"
}
delegate: Maui.IconDelegate
{
id: _delegate
ColumnLayout
{
anchors.fill : parent
isDetails: control.showDetails
folderSize: cardsView.itemSize
showThumbnails: true
showEmblem: false
width: cardsView.cellWidth
height: cardsView.cellHeight * 0.9
Item
{
Layout.fillWidth: true
Layout.preferredHeight: cardsView.itemSize
Image
{
id: _img
anchors.centerIn: parent
source: "qrc:/booklet.svg"
sourceSize.width: cardsView.itemSize
sourceSize.height: cardsView.itemSize
}
}
Rectangle
{
Layout.fillWidth: true
Layout.fillHeight: true
color: hovered ? Kirigami.Theme.highlightColor : "transparent"
radius: radiusV
Label
{
width: parent.width
height: parent.height
color: hovered ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
text: model.title
horizontalAlignment: Qt.AlignHCenter
}
}
}
Maui.Badge
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment