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

0001 #pragma once
0002 
0003 #include <QObject>
0004 
0005 #include <MauiKit3/Core/fmh.h>
0006 
0007 #include "abstractnotesprovider.h"
0008 
0009 /**
0010  * @brief The Syncer class
0011  * This interfaces between local storage and cloud
0012  * Its work is to try and keep thing synced and do the background work on updating notes
0013  * from local to cloud and viceversa.
0014  * This interface should be used to handle the whol offline and online work,
0015  * instead of manually inserting to the db or the cloud providers
0016  */
0017 
0018 struct STATE {
0019     enum TYPE : uint { LOCAL, REMOTE };
0020 
0021     enum STATUS : uint { OK, ERROR };
0022 
0023     TYPE type;
0024     STATUS status;
0025     QString msg = QString();
0026 };
0027 
0028 class Syncer : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit Syncer(QObject *parent = nullptr);
0034     /**
0035      * @brief setProviderAccount
0036      * sets the credentials to the current account
0037      * for the current provider being used
0038      * @param account
0039      * the account data represented by FMH::MODEL
0040      * where the valid keys are:
0041      * FMH::MODEL_KEY::USER user name
0042      * FMH::MODEL_KEY::PASSWORD users password
0043      * FMH::MODEL_KEY::PROVIDER the url to the provider server
0044      */
0045     void setAccount(const FMH::MODEL &account);
0046 
0047     /**
0048      * @brief setProvider
0049      * sets the provider interface
0050      * this allows to change the provider source
0051      * @param provider
0052      * the provider must inherit the asbtract class AbstractNotesProvider.
0053      * The value passed is then moved to this class private property Syncer::provider
0054      */
0055     void setProvider(AbstractNotesProvider *provider);
0056 
0057     AbstractNotesProvider &getProvider() const
0058     {
0059         return *this->m_provider;
0060     }
0061 
0062     bool validProvider() const
0063     {
0064         return this->m_provider && this->m_provider->isValid();
0065     }
0066 
0067 private:
0068     /**
0069      * @brief server
0070      * Abstract instance to the online server to perfom CRUD actions
0071      */
0072     AbstractNotesProvider *m_provider;
0073     virtual void setConections() = 0;
0074 };