Commit 067efb3f authored by camilo higuita's avatar camilo higuita

more work for syncing notes with nextcloud notes app

parent 97dd4a30
......@@ -14,7 +14,10 @@ include(FeatureSummary)
include(ECMAddAppIcon)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions( -Wall -O2 -fexceptions -std=c99)
include_directories(
......@@ -26,6 +29,9 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/utils
${CMAKE_CURRENT_BINARY_DIR}/src/utils
${CMAKE_CURRENT_SOURCE_DIR}/src/syncing
${CMAKE_CURRENT_BINARY_DIR}/src/syncing
)
set(buho_SRCS
......@@ -38,6 +44,7 @@ set(buho_SRCS
src/models/links/links.cpp
src/models/basemodel.cpp
src/models/baselist.cpp
src/syncing/nextnote.cpp
)
set(buho_HDRS
......@@ -50,6 +57,8 @@ set(buho_HDRS
src/models/links/links.h
src/models/basemodel.h
src/models/baselist.h
src/syncing/nextnote.h
src/syncing/abstractnotessyncer.h
)
set(buho_ASSETS
......
......@@ -19,5 +19,4 @@ void Buho::setFolders()
QDir books_path(OWL::BooksPath);
if (!books_path.exists())
books_path.mkpath(".");
}
#include "notes.h"
#include <QUuid>
#include "db/db.h"
#include "nextnote.h"
#ifdef STATIC_MAUIKIT
#include "tagging.h"
......@@ -8,11 +9,13 @@
#include <MauiKit/tagging.h>
#endif
Notes::Notes(QObject *parent) : BaseList(parent)
Notes::Notes(QObject *parent) : BaseList(parent),
db(DB::getInstance()),
tag(Tagging::getInstance()),
syncer(new NextNote(this))
{
qDebug()<< "CREATING NOTES LIST";
this->db = DB::getInstance();
this->tag = Tagging::getInstance();
this->sortList();
connect(this, &Notes::sortByChanged, this, &Notes::sortList);
......@@ -22,9 +25,12 @@ Notes::Notes(QObject *parent) : BaseList(parent)
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"));
syncer->setCredentials("milo.h@aol.com", "Corazon1corazon", "free01.thegood.cloud");
Please register or sign in to reply
syncer->getNotes();
// 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();
}
......
......@@ -7,6 +7,7 @@
class DB;
class Tagging;
class AbstractNotesSyncer;
class Notes : public BaseList
{
Q_OBJECT
......@@ -15,11 +16,14 @@ public:
OWL::DB_LIST items() const override;
private:
Tagging *tag;
DB *db;
Tagging *tag;
AbstractNotesSyncer *syncer;
OWL::DB_LIST notes;
void sortList();
signals:
public slots:
......
#ifndef ABSTRACTNOTESYNCER_H
#define ABSTRACTNOTESYNCER_H
#include <QObject>
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
/**
* @brief The AbstractNoteSyncer class
* is an abstraction for different services backend to sync notes.
* Different services to be added to Buho are expected to derived from this.
*/
class AbstractNotesSyncer : public QObject
{
Q_OBJECT
public:
AbstractNotesSyncer(QObject *parent) : QObject(parent) {};
virtual ~AbstractNotesSyncer() {};
virtual void setCredentials(const QString &user, const QString &password, const QString &provider) final
{
this->m_user = user;
this->m_password = password;
this->m_provider = provider;
}
/**
* @brief getNote
* gets a note identified by an ID
* @param id
* When the process is done it shoudl emit the noteReady(FMH::MODEL) signal
*/
// virtual FMH::MODEL getNote(const QString &id) = 0;
virtual void getNote(const QString &id) const = 0;
/**
* @brief getNotes
* returns all the notes or queried notes
* When the process is done it shoudl emit the notesReady(FMH::MODEL_LIST) signal
*/
virtual void getNotes() {}
virtual void getNotes() const {}
// virtual FMH::MODEL_LIST getNotes(const QString &query = QString()) = 0;
// virtual FMH::MODEL_LIST getNotes(const QString &query = QString()) const = 0;
/**
* @brief insertNote
* inserts a new note to the server
* @param note
* takes the new note to be inserted represented as FMH::MODEL
* When the process is done it shoudl emit the noteInserted(FMH::MODEL) signal
*/
// virtual bool insertNote(const FMH::MODEL &note) = 0;
virtual void insertNote(const FMH::MODEL &note) const = 0;
/**
* @brief updateNote
* allows to update a note in the server, it takes an ID and the updated note
* @param id
* id of the note to be updated
* @param note
* the note prepresented as FMH::MODEL contening the up-to-date values
* When the process is done it shoudl emit the noteUpdated(FMH::MODEL) signal
*/
// virtual bool updateNote(const QString &id, const FMH::MODEL &note) = 0;
virtual void updateNote(const QString &id, const FMH::MODEL &note) const = 0;
/**
* @brief removeNote
* removes a note from the server
* @param id
* ID of the note to be removed
* When the process is done it shoudl emit the noteRemoved(FMH::MODEL) signal
*/
// virtual bool removeNote(const QString &id) = 0;
virtual void removeNote(const QString &id) const = 0;
protected:
QString m_user = "";
QString m_password = "";
QString m_provider = "";
template<typename T>
inline void request(const QString &url, const QMap<QString, QString> &header, T cb)
{
auto downloader = new FMH::Downloader;
connect(downloader, &FMH::Downloader::dataReady, [&, downloader = std::move(downloader)](const QByteArray &array)
{
if(cb)
cb(array);
downloader->deleteLater();
});
downloader->getArray(url, header);
}
signals:
void noteReady(FMH::MODEL);
void notesReady(FMH::MODEL_LIST);
void noteInserted(FMH::MODEL);
void noteUpdated(FMH::MODEL);
void noteRemoved(FMH::MODEL);
/**
* @brief responseReady
* gets emitted when the data is ready after requesting the array
* with &Downloader::getArray()
*/
void responseReady(QByteArray array);
/**
* @brief responseError
* emitted if there's an error when trying to get the array
*/
void responseError(QString);
};
#endif // ABSTRACTNOTESYNCER_H
#include "nextnote.h"
QString NextNote::API = "https://PROVIDER/index.php/apps/notes/api/v0.2/";
NextNote::NextNote(QObject *parent) : AbstractNotesSyncer(parent)
{
}
NextNote::~NextNote()
{
}
void NextNote::getNote(const QString &id) const
{
}
void NextNote::getNotes()
{
//https://milo.h@aol.com:Corazon1corazon@free01.thegood.cloud/index.php/apps/notes/api/v0.2/notes
auto url = NextNote::formatUrl(this->m_user, this->m_password, this->m_provider)+"notes";
QString concatenated = this->m_user + ":" + this->m_password;
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
QMap<QString, QString> header {{"Authorization", headerData.toLocal8Bit()}};
this->request(url, header, [](QByteArray array)
{
qDebug()<< "GOT TEH NOTES" << array;
});
// request.setRawHeader("Authorization", headerData.toLocal8Bit());
}
void NextNote::insertNote(const FMH::MODEL &note) const
{
}
void NextNote::updateNote(const QString &id, const FMH::MODEL &note) const
{
}
void NextNote::removeNote(const QString &id) const
{
}
QString NextNote::formatUrl(const QString &user, const QString &password, const QString &provider)
{
auto url = NextNote::API;
url.replace("USER", user);
url.replace("PASSWORD", password);
url.replace("PROVIDER", provider);
return url;
}
#ifndef NEXTNOTE_H
#define NEXTNOTE_H
#include <QObject>
#include <QString>
#include "abstractnotessyncer.h"
/**
* @brief The NextNote class follows the NextCloud API specification
* for syncing notes.
*/
class NextNote : public AbstractNotesSyncer
{
Q_OBJECT
public:
explicit NextNote(QObject *parent = nullptr);
~NextNote();
void getNote(const QString &id) const override final;
void getNotes() override final;
void insertNote(const FMH::MODEL &note) const override final;
void updateNote(const QString &id, const FMH::MODEL &note) const override final;
void removeNote(const QString &id) const override final;
private:
static QString API;
static QString formatUrl(const QString &user, const QString &password, const QString &provider);
signals:
public slots:
};
#endif // NEXTNOTE_H
......@@ -2,6 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.7 as Kirigami
import "../../widgets"
Maui.Dialog
......@@ -22,7 +23,7 @@ Maui.Dialog
id: pinButton
icon.name: "pin"
checkable: true
icon.color: checked ? highlightColor : textColor
icon.color: checked ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
// onClicked: checked = !checked
},
......@@ -51,7 +52,7 @@ Maui.Dialog
id: favButton
icon.name: "love"
checkable: true
icon.color: checked ? "#ff007f" : textColor
icon.color: checked ? "#ff007f" : Kirigami.Theme.textColor
},
ToolButton
......
......@@ -3,7 +3,7 @@ import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.2 as Kirigami
import org.kde.kirigami 2.7 as Kirigami
import BuhoModel 1.0
import Notes 1.0
......@@ -114,7 +114,7 @@ Maui.Page
id: pinButton
icon.name: "pin"
checkable: true
icon.color: checked ? highlightColor : textColor
icon.color: checked ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
}
]
......@@ -154,10 +154,10 @@ Maui.Page
onItemClicked: noteClicked(cardsView.model.get(index))
}
color: altColor
color: Kirigami.Theme.backgroundColor
radius: radiusV
border.color: Qt.darker(altColor, 1.4)
border.color: Qt.darker(Kirigami.Theme.backgroundColor, 1.4)
}
......
import QtQuick 2.0
import QtQuick.Controls 2.2
import org.kde.kirigami 2.7 as Kirigami
Row
{
......@@ -111,7 +112,7 @@ Row
Rectangle
{
color: viewBackgroundColor
color: Kirigami.Theme.backgroundColor
anchors.verticalCenter: parent.verticalCenter
height: size
width: height
......
......@@ -2,7 +2,7 @@ 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
import org.kde.kirigami 2.7 as Kirigami
Maui.Dialog
{
......@@ -39,7 +39,7 @@ Maui.Dialog
id: pinButton
icon.name: "window-pin"
checkable: true
icon.color: checked ? highlightColor : textColor
icon.color: checked ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
// onClicked: checked = !checked
}
......@@ -55,7 +55,7 @@ Maui.Dialog
id: favButton
icon.name: "love"
checkable: true
icon.color: checked ? "#ff007f" : textColor
icon.color: checked ? "#ff007f" : Kirigami.Theme.textColor
},
ToolButton
......
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