Marble

CloudSyncManager.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Utku Aydın <utkuaydin34@gmail.com>
4//
5
6#include "CloudSyncManager.h"
7#include "BookmarkSyncManager.h"
8#include "RouteSyncManager.h"
9
10namespace Marble
11{
12
13class Q_DECL_HIDDEN CloudSyncManager::Private {
14
15public:
16 Private();
17 ~Private();
18
19 bool m_workOffline;
20
21 bool m_syncEnabled;
22
23 QString m_owncloudProtocol;
24 QString m_ownloudServer;
25 QString m_owncloudUsername;
26 QString m_owncloudPassword;
27 QString m_status;
28 CloudSyncManager::Status m_status_type;
29
30 RouteSyncManager* m_routeSyncManager;
31 BookmarkSyncManager* m_bookmarkSyncManager;
32};
33
34CloudSyncManager::Private::~Private()
35{
36 delete m_routeSyncManager;
37 delete m_bookmarkSyncManager;
38}
39
40CloudSyncManager::Private::Private() :
41 m_workOffline( false ),
42 m_syncEnabled( false ),
43 m_owncloudProtocol( "http" ),
44 m_ownloudServer(),
45 m_owncloudUsername(),
46 m_owncloudPassword(),
47 m_status(),
48 m_status_type( CloudSyncManager::Unknown),
49 m_routeSyncManager( nullptr ),
50 m_bookmarkSyncManager( nullptr )
51{
52}
53
54CloudSyncManager::CloudSyncManager( QObject *parent ) :
55 QObject( parent ),
56 d( new Private )
57{
58}
59
60CloudSyncManager::~CloudSyncManager()
61{
62 delete d;
63}
64
65bool CloudSyncManager::workOffline() const
66{
67 return d->m_workOffline;
68}
69
70void CloudSyncManager::setWorkOffline( bool offline )
71{
72 if ( offline != d->m_workOffline ) {
73 d->m_workOffline = offline;
74 emit workOfflineChanged( d->m_workOffline );
75 }
76}
77
78bool CloudSyncManager::isSyncEnabled() const
79{
80 return d->m_syncEnabled;
81}
82
83QString CloudSyncManager::owncloudServer() const
84{
85 return d->m_owncloudProtocol + d->m_ownloudServer;
86}
87
88QString CloudSyncManager::owncloudUsername() const
89{
90 return d->m_owncloudUsername;
91}
92
93QString CloudSyncManager::owncloudPassword() const
94{
95 return d->m_owncloudPassword;
96}
97
98void CloudSyncManager::setSyncEnabled( bool enabled )
99{
100 if ( d->m_syncEnabled != enabled ) {
101 d->m_syncEnabled = enabled;
102 emit syncEnabledChanged( d->m_syncEnabled );
103 }
104}
105
106void CloudSyncManager::setOwncloudCredentials( const QString &server, const QString &user, const QString &password )
107{
108 QUrl const oldApiUrl = apiUrl();
109 blockSignals( true );
110 setOwncloudServer( server );
111 setOwncloudUsername( user );
112 setOwncloudPassword( password );
113 blockSignals( false );
114 if ( oldApiUrl != apiUrl() ) {
115 emit apiUrlChanged( apiUrl() );
116 }
117}
118
119void CloudSyncManager::setOwncloudServer( const QString &server )
120{
121 QString const oldProtocol = d->m_owncloudProtocol;
122 QString const oldServer = d->m_ownloudServer;
123
124 if (server.startsWith(QLatin1String("http://"))) {
125 d->m_owncloudProtocol = "http://";
126 d->m_ownloudServer = server.mid( 7 );
127 } else if (server.startsWith(QLatin1String("https://"))) {
128 d->m_owncloudProtocol = "https://";
129 d->m_ownloudServer = server.mid ( 8 );
130 } else {
131 d->m_owncloudProtocol = "http://";
132 d->m_ownloudServer = server;
133 }
134
135 if ( oldServer != d->m_ownloudServer ) {
136 emit owncloudServerChanged( owncloudServer() );
137 emit apiUrlChanged( apiUrl() );
138 } else if ( oldProtocol != d->m_owncloudProtocol ) {
139 emit apiUrlChanged( apiUrl() );
140 }
141}
142
143void CloudSyncManager::setOwncloudUsername( const QString &username )
144{
145 if ( d->m_owncloudUsername != username ) {
146 d->m_owncloudUsername = username;
147 emit owncloudUsernameChanged( d->m_owncloudUsername );
148 emit apiUrlChanged( apiUrl() );
149 }
150}
151
152void CloudSyncManager::setOwncloudPassword( const QString &password )
153{
154 if ( d->m_owncloudPassword != password ) {
155 d->m_owncloudPassword = password;
156 emit owncloudPasswordChanged( d->m_owncloudPassword );
157 emit apiUrlChanged( apiUrl() );
158 }
159}
160
161void CloudSyncManager::setStatus( const QString &status, CloudSyncManager::Status status_type )
162{
163 if( d->m_status != status && d->m_status_type != status_type) {
164 d->m_status = status;
165 d->m_status_type = status_type;
166 emit statusChanged( d->m_status );
167 }
168}
169
170CloudSyncManager::Status CloudSyncManager::status() const
171{
172 return d->m_status_type;
173}
174
175QString CloudSyncManager::statusDescription() const
176{
177 return d->m_status;
178}
179
180QString CloudSyncManager::apiPath() const
181{
182 return "index.php/apps/marble/api/v1";
183}
184
185QUrl CloudSyncManager::apiUrl() const
186{
187 return QUrl( QString( "%0%1:%2@%3/%4" )
188 .arg( d->m_owncloudProtocol )
189 .arg( d->m_owncloudUsername ).arg( d->m_owncloudPassword )
190 .arg( d->m_ownloudServer ).arg( apiPath() ) );
191}
192
193RouteSyncManager *CloudSyncManager::routeSyncManager()
194{
195 if ( !d->m_routeSyncManager ) {
196 d->m_routeSyncManager = new RouteSyncManager( this );
197 }
198
199 return d->m_routeSyncManager;
200}
201
202BookmarkSyncManager *CloudSyncManager::bookmarkSyncManager()
203{
204 if ( !d->m_bookmarkSyncManager ) {
205 d->m_bookmarkSyncManager = new BookmarkSyncManager( this );
206 }
207
208 return d->m_bookmarkSyncManager;
209}
210
211}
212
213#include "moc_CloudSyncManager.cpp"
Q_SCRIPTABLE CaptureState status()
Binds a QML item to a specific geodetic location in screen coordinates.
T qobject_cast(QObject *object)
QString arg(Args &&... args) const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:49:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.