syncer.h 1.89 KB
Newer Older
1 2 3 4
#ifndef SYNCER_H
#define SYNCER_H

#include <QObject>
5 6 7 8 9
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
10

camilo higuita's avatar
camilo higuita committed
11 12
#include "abstractnotesprovider.h"

13 14 15 16 17 18 19 20 21
/**
 * @brief The Syncer class
 * This interfaces between local storage and cloud
 * Its work is to try and keep thing synced and do the background work on updating notes
 * from local to cloud and viceversa.
 * This interface should be used to handle the whol offline and online work,
 * instead of manually inserting to the db or the cloud providers
 */

22 23
struct STATE
{
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
	enum TYPE : uint
	{
		LOCAL,
		REMOTE
	};

	enum STATUS : uint
	{
		OK,
		ERROR
	};

	TYPE type;
	STATUS status;
	QString msg = QString();
39 40 41
};

class Syncer: public QObject
42
{
43
	Q_OBJECT
44

45
public:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	explicit Syncer(QObject *parent = nullptr);
	/**
	 * @brief setProviderAccount
	 * sets the credentials to the current account
	 * for the current provider being used
	 * @param account
	 * the account data represented by FMH::MODEL
	 * where the valid keys are:
	 * FMH::MODEL_KEY::USER user name
	 * FMH::MODEL_KEY::PASSWORD users password
	 * FMH::MODEL_KEY::PROVIDER the url to the provider server
	 */
	void setAccount(const FMH::MODEL &account);

	/**
	 * @brief setProvider
	 * sets the provider interface
	 * this allows to change the provider source
	 * @param provider
	 * the provider must inherit the asbtract class AbstractNotesProvider.
	 * The value passed is then moved to this class private property Syncer::provider
	 */
	void setProvider(AbstractNotesProvider *provider);

camilo higuita's avatar
camilo higuita committed
70 71 72 73
    AbstractNotesProvider &getProvider() const
    {
        return *this->m_provider;
    }
74

camilo higuita's avatar
camilo higuita committed
75 76 77 78
    bool validProvider() const
    {
        return this->m_provider && this->m_provider->isValid();
    }
79

80
private:
81 82 83 84 85
	/**
	 * @brief server
	 * Abstract instance to the online server to perfom CRUD actions
	 */
	AbstractNotesProvider * m_provider;
camilo higuita's avatar
camilo higuita committed
86
    virtual void setConections() = 0;
87

88 89
};

90

91
#endif // SYNCER_H