1/*
2 This file is part of the Kasten Framework, made within the KDE community.
3
4 Copyright 2007-2009,2012 Friedrich W. H. Kossebau <kossebau@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) version 3, or any
10 later version accepted by the membership of KDE e.V. (or its
11 successor approved by the membership of KDE e.V.), which shall
12 act as a proxy defined in Section 6 of version 3 of the license.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#ifndef ABSTRACTMODELSYNCHRONIZER_H
24#define ABSTRACTMODELSYNCHRONIZER_H
25
26// lib
27#include "kastencore_export.h"
28#include "kastencore.h"
29// Qt
30#include <QtCore/QObject>
31
32class KUrl;
33
34
35namespace Kasten2
36{
37
38class AbstractLoadJob;
39class AbstractConnectJob;
40class AbstractSyncToRemoteJob;
41class AbstractSyncFromRemoteJob;
42class AbstractSyncWithRemoteJob;
43class AbstractDocument;
44
45class AbstractModelSynchronizerPrivate;
46
47// TODO: better names? Active Translator?
48// synchronizers are created by factory functions (like plugins)
49
50// TODO: should synchronizers set the document to readonly if remote is readonly? or who?
51// TODO: should synchronizers offer to change writeflag at remote?
52// TODO: allow synchronizers which can read-only, perhaps also write-only (usecase?)
53
54/**
55possible actions:
561. synchronizer loads document and synchronizes until closing
57 -> done by factory functions
582. synchronizer gets attached to a document new created or with other synchronizer
593. synchronizer used to export a model
60*/
61class KASTENCORE_EXPORT AbstractModelSynchronizer : public QObject
62{
63 Q_OBJECT
64
65 public:
66 enum ConnectOption // TODO: better names
67 {
68 SyncLocalAndRemote = 0,
69 ReplaceRemote = 1,
70 ReplaceLocal = 2
71 };
72 protected:
73 explicit AbstractModelSynchronizer( AbstractModelSynchronizerPrivate* d );
74
75 public:
76 AbstractModelSynchronizer();
77
78 virtual ~AbstractModelSynchronizer();
79
80 public:
81 KUrl url() const;
82
83 public: // API to be implemented
84 // TODO: makes this a job, too
85 // TODO: filesystem synchronizer (or: to-passive-storage) does not need this: subclass or interface?
86// virtual void startOffering( AbstractDocument* document ) = 0;
87 // TODO: once the synchronizer is attached to a document, this function should not be called
88 // is there a way to ensure this?
89 virtual AbstractLoadJob* startLoad( const KUrl& url ) = 0;
90 /** */
91 // TODO: not in constructor? cannot be called twice, each synchronizer is attached to its document
92// virtual AbstractDocument* createWorkingCopy( const KUrl& originUrl, int* success ) const = 0;
93
94 /** */
95 // TODO: static? or by function? or another class? but
96// virtual void copyTo( const KUrl& url, AbstractDocument* document, int* success ) const = 0;
97
98 /** overwrite remote with local (save) */
99 virtual AbstractSyncToRemoteJob* startSyncToRemote() = 0;
100 /** overwrite local with remote (reload) */
101 virtual AbstractSyncFromRemoteJob* startSyncFromRemote() = 0;
102
103 /** changes the */ // TODO: better name for replace: overwrite?
104 virtual AbstractSyncWithRemoteJob* startSyncWithRemote( const KUrl& url, AbstractModelSynchronizer::ConnectOption option ) = 0;
105
106 virtual AbstractConnectJob* startConnect( AbstractDocument* document,
107 const KUrl& url, AbstractModelSynchronizer::ConnectOption option ) = 0;
108// virtual bool syncBiDirectly() = 0;
109// virtual bool canSyncBiDirectly() const = 0;
110// virtual bool deleteDocument();
111
112 virtual AbstractDocument* document() const = 0;
113 virtual LocalSyncState localSyncState() const = 0;
114 virtual RemoteSyncState remoteSyncState() const = 0;
115
116
117 Q_SIGNALS:
118 void urlChanged( const KUrl& url );
119 // TODO: next two could be part of an interface? parameter quite specific
120 void dataPulled( int ) const;
121 void dataPushed( int ) const;
122
123 // TODO: should be signal the diff? how to say then remote is in synch again?
124 // could be done by pairs of flags instead of notset = isnot
125 // TODO: this signal should be part of AbstractModel?
126 void localSyncStateChanged( Kasten2::LocalSyncState newState );
127 void remoteSyncStateChanged( Kasten2::RemoteSyncState newState );
128
129 protected: // get
130 void setUrl( const KUrl& url );
131
132 protected:
133 Q_DECLARE_PRIVATE( AbstractModelSynchronizer )
134 protected:
135 AbstractModelSynchronizerPrivate* const d_ptr;
136};
137
138}
139
140#endif
141