Commit 7a0577e4 authored by camilo higuita's avatar camilo higuita

more work done for the books feature

parent fdfd9d3d
......@@ -46,6 +46,7 @@ set(buho_SRCS
src/models/notes/notes.cpp
src/models/links/links.cpp
src/models/books/books.cpp
src/models/books/booklet.cpp
src/providers/nextnote.cpp
src/syncing/syncer.cpp
)
......@@ -59,6 +60,7 @@ set(buho_HDRS
src/models/notes/notes.h
src/models/links/links.h
src/models/books/books.h
src/models/books/booklet.h
src/providers/nextnote.h
src/providers/abstractnotesprovider.h
src/syncing/syncer.h
......
#include "booklet.h"
Booklet::Booklet()
{
}
#ifndef BOOKLET_H
#define BOOKLET_H
#include "owl.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/fmh.h>
#include <MauiKit/mauilist.h>
#endif
class Booklet : public MauiList
{
Q_OBJECT
Q_PROPERTY(SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
public:
Booklet(QObject *parent = nullptr);
enum ORDER : uint8_t
{
DESC,
ASC
};
Q_ENUM(ORDER)
enum SORTBY : uint8_t
{
TITLE = FMH::MODEL_KEY::TITLE,
ADDDATE = FMH::MODEL_KEY::ADDDATE,
MODIFIED = FMH::MODEL_KEY::MODIFIED,
COLOR = FMH::MODEL_KEY::COLOR,
FAVORITE = FMH::MODEL_KEY::FAVORITE,
PIN = FMH::MODEL_KEY::PIN
};
Q_ENUM(SORTBY)
FMH::MODEL_LIST items() const override final;
void setSortBy(const SORTBY &sort);
SORTBY getSortBy() const;
void setOrder(const ORDER &order);
ORDER getOrder() const;
private:
FMH::MODEL_LIST m_list;
void sortList();
SORTBY sort = SORTBY::MODIFIED;
ORDER order = ORDER::DESC;
signals:
void sortByChanged();
void orderChanged();
};
#endif // BOOKLET_H
#include "books.h"
#include "syncer.h"
#include "nextnote.h"
Books::Books(QObject *parent) : MauiList(parent)
Books::Books(QObject *parent) : MauiList(parent),
syncer(new Syncer(this))
{
this->syncer->setProvider(new NextNote);
this->syncer->getBooks();
}
FMH::MODEL_LIST Books::items() const
{
return this->m_list;
}
......@@ -12,10 +12,68 @@
#include <MauiKit/mauilist.h>
#endif
class Syncer;
class Books : public MauiList
{
Q_OBJECT
Q_PROPERTY(SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
public:
enum ORDER : uint8_t
{
DESC,
ASC
};
Q_ENUM(ORDER)
enum SORTBY : uint8_t
{
TITLE = FMH::MODEL_KEY::TITLE,
ADDDATE = FMH::MODEL_KEY::ADDDATE,
MODIFIED = FMH::MODEL_KEY::MODIFIED,
COLOR = FMH::MODEL_KEY::COLOR,
FAVORITE = FMH::MODEL_KEY::FAVORITE,
PIN = FMH::MODEL_KEY::PIN
};
Q_ENUM(SORTBY)
Books(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override final;
void setSortBy(const SORTBY &sort);
SORTBY getSortBy() const;
void setOrder(const ORDER &order);
ORDER getOrder() const;
private:
Syncer *syncer;
FMH::MODEL_LIST m_list;
void sortList();
SORTBY sort = SORTBY::MODIFIED;
ORDER order = ORDER::DESC;
signals:
void sortByChanged();
void orderChanged();
public slots:
QVariantMap get(const int &index) const;
/**
* @brief insert
* insertes a new book by using the syncer interface
* @param note
* @return
*/
bool insert(const QVariantMap &note);
bool update(const QVariantMap &data, const int &index);
bool remove(const int &index);
};
#endif // BOOKS_H
......@@ -56,7 +56,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::stampFromId(this->db, id);
const auto stamp = Syncer::noteStampFromId(this->db, id);
if(!stamp.isEmpty())
this->updateRemote(stamp, note);
......@@ -68,7 +68,7 @@ void Syncer::removeNote(const QString &id)
//to remove the remote note we need to pass the stamp as the id,
//and before removing the note locally we need to retireved first
const auto stamp = Syncer::stampFromId(this->db, id);
const auto stamp = Syncer::noteStampFromId(this->db, id);
if(!this->removeLocal(id))
{
qWarning()<< "The note could not be inserted locally, "
......@@ -96,6 +96,20 @@ void Syncer::getNotes()
emit this->notesReady(notes);
}
void Syncer::getBooks()
{
const auto books = this->collectAllNotes();
// 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";
emit this->booksReady(books);
}
void Syncer::stampNote(FMH::MODEL &note)
{
const auto id = QUuid::createUuid().toString();
......@@ -103,7 +117,7 @@ void Syncer::stampNote(FMH::MODEL &note)
}
const QString Syncer::idFromStamp(DB *_db, const QString &provider, const QString &stamp)
const QString Syncer::noteIdFromStamp(DB *_db, const QString &provider, const QString &stamp)
{
return [&]() -> QString {
const auto data = _db->getDBData(QString("select id from notes_sync where server = '%1' AND stamp = '%2'").arg(provider, stamp));
......@@ -111,7 +125,7 @@ const QString Syncer::idFromStamp(DB *_db, const QString &provider, const QStrin
}();
}
const QString Syncer::stampFromId(DB *_db, const QString &id)
const QString Syncer::noteStampFromId(DB *_db, const QString &id)
{
return [&]() -> QString {
const auto data = _db->getDBData(QString("select stamp from notes_sync where id = '%1'").arg(id));
......@@ -145,7 +159,7 @@ void Syncer::setConections()
// the note does not exists locally, so it needs to be inserted into the db
for(const auto &note : notes)
{
const auto id = Syncer::idFromStamp(this->db, this->provider->provider(), note[FMH::MODEL_KEY::ID]);
const auto id = Syncer::noteIdFromStamp(this->db, this->provider->provider(), note[FMH::MODEL_KEY::ID]);
// if the id is empty then the note does nto exists, so ithe note is inserted into the local db
if(id.isEmpty())
......@@ -194,7 +208,7 @@ void Syncer::setConections()
connect(this->provider, &AbstractNotesProvider::noteUpdated, [&](FMH::MODEL note)
{
const auto id = Syncer::idFromStamp(this->db, this->provider->provider(), note[FMH::MODEL_KEY::ID]);
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}));
emit this->noteUpdated(note, {STATE::TYPE::REMOTE, STATE::STATUS::OK, "Note updated on server provider"});
......@@ -286,6 +300,11 @@ const FMH::MODEL_LIST Syncer::collectAllNotes()
return __notes;
}
const FMH::MODEL_LIST Syncer::collectAllBooks()
{
return this->db->getDBData("select * from books");
}
const QUrl Syncer::saveNoteFile(const FMH::MODEL &note)
{
if(note.isEmpty() || !note.contains(FMH::MODEL_KEY::CONTENT))
......
......@@ -67,10 +67,15 @@ public:
* The value passed is then moved to this class private property Syncer::provider
*/
void setProvider(AbstractNotesProvider *provider);
//// NOTES INTERFACES
/// interfaces with the the notes from both, local and remote
/**
* @brief insertNote
* saves a new note online and offline
* The signal noteInserted(FMH::MODEL, STATE) is emitted,
* The signal Syncer::noteInserted(FMH::MODEL, STATE) is emitted,
* indicating the created note and the transaction resulting state
* @param note
* the note to be stored represented by FMH::MODEL
......@@ -80,7 +85,7 @@ public:
/**
* @brief updateNote
* Update online and offline an existing note.
* The signal noteUpdated(FMH::MODEL, STATE) is emitted,
* The signal Syncer::noteUpdated(FMH::MODEL, STATE) is emitted,
* indicating the updated note and the transaction resulting state
* @param id
* ID of the existing note
......@@ -92,7 +97,7 @@ public:
/**
* @brief removeNote
* remove a note from online and offline storage
* The signal noteRemoved(FMH::MODEL, STATE) is emitted,
* The signal Syncer::noteRemoved(FMH::MODEL, STATE) is emitted,
* indicating the removed note and the transaction resulting state
* @param id
* ID of the exisiting note
......@@ -102,7 +107,7 @@ public:
/**
* @brief getNote
* Retrieves an existing note, whether the note is located offline or online.
* When the note is ready the signal noteReady(FMH::MODEL) is emitted
* When the note is ready the signal Syncer::noteReady(FMH::MODEL) is emitted
* @param id
* ID of the exisiting note
*/
......@@ -111,10 +116,72 @@ public:
/**
* @brief getNotes
* Retrieves all the notes, online and offline notes.
* When the notes are ready the signal notesReady(FMH::MODEL_LIST) is emitted.
* When the notes are ready the signal Syncer::notesReady(FMH::MODEL_LIST) is emitted.
*/
void getNotes();
////BOOKS & BOOKLET INTERFACES
/// interfaces with the the books and booklets from both, local and remote
/**
* @brief getBooks
* Retrieves all the books, online and offline.
* When the books are ready the signal Syncer::booksReady(FMH::MODEL_LIST) is emitted
*/
void getBooks();
/**
* @brief getBook
* @param id
*/
void getBook(const QString &id);
/**
* @brief insertBook
* @param book
*/
void insertBook(const FMH::MODEL &book);
/**
* @brief updateBook
* @param id
* @param book
*/
void updateBook(const QString &id, const FMH::MODEL &book);
/**
* @brief removeBook
* @param id
*/
void removeBook(const QString &id);
//BOOKLETS INTERFACES
/**
* @brief getBooklet
* @param id
*/
void getBooklet(const QString &id);
/**
* @brief updateBooklet
* @param id
* @param booklet
*/
void updateBooklet(const QString &id, FMH::MODEL &booklet);
/**
* @brief insertBooklet
* @param booklet
*/
void insertBooklet(const FMH::MODEL &booklet);
/**
* @brief removeBooklet
* @param id
*/
void removeBooklet(const QString &id);
private:
/**
* @brief tag
......@@ -152,8 +219,8 @@ private:
*/
static void stampNote(FMH::MODEL &note);
static const QString idFromStamp(DB *_db, const QString &provider, const QString &stamp) ;
static const QString stampFromId(DB *_db, const QString &id) ;
static const QString noteIdFromStamp(DB *_db, const QString &provider, const QString &stamp) ;
static const QString noteStampFromId(DB *_db, const QString &id) ;
void setConections();
......@@ -184,17 +251,27 @@ protected:
void removeRemote(const QString &id);
const FMH::MODEL_LIST collectAllNotes();
const FMH::MODEL_LIST collectAllBooks();
static inline const QUrl saveNoteFile(const FMH::MODEL &note);
static inline const QString noteFileContent(const QUrl &path);
signals:
//FOR NOTES
void noteInserted(FMH::MODEL note, STATE state);
void noteUpdated(FMH::MODEL note, STATE state);
void noteRemoved(FMH::MODEL note, STATE state);
void noteReady(FMH::MODEL note);
void notesReady(FMH::MODEL_LIST notes);
//FOR BOOKS
void bookInserted(FMH::MODEL book, STATE state);
void bookUpdated(FMH::MODEL book, STATE state);
void bookRemoved(FMH::MODEL book, STATE state);
void bookReady(FMH::MODEL book);
void booksReady(FMH::MODEL_LIST books);
public slots:
};
......
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