QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
iossyncdelegate.h
1 #ifndef QTDATASYNC_IOSSYNCDELEGATE_H
2 #define QTDATASYNC_IOSSYNCDELEGATE_H
3 
4 #include <chrono>
5 #include <functional>
6 
7 #include <QtCore/qobject.h>
8 #include <QtCore/qscopedpointer.h>
9 #include <QtCore/qsettings.h>
10 
11 #include <QtDataSync/setup.h>
12 #include <QtDataSync/syncmanager.h>
13 
14 #include "QtDataSyncIos/qtdatasyncios_global.h"
15 
16 namespace QtDataSync {
17 
18 class IosSyncDelegatePrivate;
20 class Q_DATASYNCIOS_EXPORT IosSyncDelegate : public QObject
21 {
22  Q_OBJECT
23 
25  Q_PROPERTY(qint64 interval READ interval WRITE setInterval NOTIFY intervalChanged)
27  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
28 
30  Q_PROPERTY(bool waitFullSync READ waitFullSync WRITE setWaitFullSync NOTIFY waitFullSyncChanged)
32  Q_PROPERTY(bool persistState READ persistState CONSTANT)
33 
34 public:
36  enum class SyncResult {
37  NewData,
38  NoData,
39  Error
40  };
41  Q_ENUM(SyncResult)
42 
43 
44  static void init(IosSyncDelegate *delegate = nullptr);
46  static IosSyncDelegate *currentDelegate();
47 
49  explicit IosSyncDelegate(QObject *parent = nullptr);
51  explicit IosSyncDelegate(QSettings *settings, QObject *parent = nullptr);
52  ~IosSyncDelegate() override;
53 
55  qint64 interval() const;
57  std::chrono::minutes intervalMinutes() const;
59  bool isEnabled() const;
61  bool waitFullSync() const;
63  virtual bool persistState() const;
64 
66  template <typename TRep, typename TPeriod>
67  void setInterval(const std::chrono::duration<TRep, TPeriod> &interval);
69  void setInterval(std::chrono::minutes interval);
70 
71 public Q_SLOTS:
73  void setInterval(qint64 interval);
75  void setEnabled(bool enabled);
77  void setWaitFullSync(bool waitFullSync);
78 
79 Q_SIGNALS:
81  void intervalChanged(qint64 interval, QPrivateSignal);
83  void enabledChanged(bool enabled, QPrivateSignal);
85  void waitFullSyncChanged(bool waitFullSync, QPrivateSignal);
86 
87 protected:
89  virtual QString setupName() const;
91  virtual void prepareSetup(Setup &setup);
93  virtual SyncResult onSyncCompleted(SyncManager::SyncState state);
94 
96  virtual void performSync(std::function<void(QtDataSync::IosSyncDelegate::SyncResult)> callback);
97 
98 private Q_SLOTS:
99  void backendReady();
100 
101 private:
102  friend class QtDataSync::IosSyncDelegatePrivate;
104 };
105 
106 template<typename TRep, typename TPeriod>
107 void IosSyncDelegate::setInterval(const std::chrono::duration<TRep, TPeriod> &interval)
108 {
109  setInterval(std::chrono::duration_cast<std::chrono::minutes>(interval));
110 }
111 
112 }
113 
114 #endif // QTDATASYNC_IOSSYNCDELEGATE_H
The class to setup and create datasync instances.
Definition: setup.h:59
qint64 interval() const
READ accessor for IosSyncDelegate::interval.
A helper class to perform background synchronization on Ios.
The primary namespace of the QtDataSync library.
SyncState
The possible states the sync engine can be in.
Definition: syncmanager.h:37
SyncResult
The possible results of a synchronization attempt.
void setInterval(const std::chrono::duration< TRep, TPeriod > &interval)
WRITE accessor for IosSyncDelegate::interval.