File indexing completed on 2024-05-12 04:45:56

0001 #pragma once
0002 
0003 #include <QObject>
0004 #include <syncer.h>
0005 
0006 #include <MauiKit3/Core/fmh.h>
0007 
0008 /**
0009  * @brief The Syncer class
0010  * This interfaces between local storage and cloud
0011  * Its work is to try and keep thing synced and do the background work on updating notes
0012  * from local to cloud and viceversa.
0013  * This interface should be used to handle the whol offline and online work,
0014  * instead of manually inserting to the db or the cloud providers
0015  */
0016 
0017 class DB;
0018 class NotesController;
0019 class Tagging;
0020 class NotesSyncer : public Syncer
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit NotesSyncer(QObject *parent = nullptr);
0026     //// NOTES INTERFACES
0027     /// interfaces with the the notes from both, local and remote
0028 
0029     /**
0030      * @brief insertNote
0031      * saves a new note online and offline
0032      * The signal Syncer::noteInserted(FMH::MODEL, STATE) is emitted,
0033      * indicating the created note and the transaction resulting state
0034      * @param note
0035      * the note to be stored represented by FMH::MODEL
0036      */
0037     void insertNote(FMH::MODEL &note);
0038 
0039     /**
0040      * @brief updateNote
0041      * Update online and offline an existing note.
0042      * The signal Syncer::noteUpdated(FMH::MODEL, STATE) is emitted,
0043      * indicating the updated note and the transaction resulting state
0044      * @param id
0045      * ID of the existing note
0046      * @param note
0047      * the new note contents represented by FMH::MODEL
0048      */
0049     void updateNote(QString id, FMH::MODEL &note);
0050 
0051     /**
0052      * @brief removeNote
0053      * remove a note from online and offline storage
0054      * The signal Syncer::noteRemoved(FMH::MODEL, STATE) is emitted,
0055      * indicating the removed note and the transaction resulting state
0056      * @param id
0057      * ID of the exisiting  note
0058      */
0059     void removeNote(const QString &id);
0060 
0061     /**
0062      * @brief getNote
0063      * Retrieves an existing note, whether the note is located offline or online.
0064      * When the note is ready the signal Syncer::noteReady(FMH::MODEL) is emitted
0065      * @param id
0066      * ID of the exisiting  note
0067      */
0068     void getNote(const QString &id);
0069 
0070     /**
0071      * @brief getNotes
0072      * Retrieves all the notes, online and offline notes.
0073      * When the notes are ready the signal Syncer::notesReady(FMH::MODEL_LIST) is emitted.
0074      */
0075     void getNotes();
0076     void getLocalNotes();
0077     void getRemoteNotes();
0078 
0079 private:
0080     /**
0081      * @brief tag
0082      * Instance of the Maui project tag-ger. It adds tags to the abtract notes
0083      * For online tagging one could use the categories ?
0084      */
0085     Tagging *tag;
0086 
0087     /**
0088      * @brief db
0089      * Instance to the data base storing the notes information and location,
0090      * offline and online.
0091      */
0092     DB *db;
0093 
0094     NotesController *m_notesController;
0095     /**
0096      * @brief syncNote
0097      * Has the job to sync a note between the offline and online versions
0098      * @param id
0099      * ID of the note to be synced
0100      */
0101     void syncNote(const QString &id);
0102 
0103     static const QString noteIdFromStamp(const QString &provider, const QString &stamp);
0104     static const QString noteStampFromId(const QString &id);
0105 
0106     void setConections() override final;
0107 
0108 Q_SIGNALS:
0109     // FOR NOTES
0110     void noteInserted(FMH::MODEL note, STATE state);
0111     void noteUpdated(FMH::MODEL note, STATE state);
0112     void noteRemoved(FMH::MODEL note, STATE state);
0113     void noteReady(FMH::MODEL note);
0114     void notesReady(FMH::MODEL_LIST notes);
0115 
0116 };