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 = nullptr;
31 BookmarkSyncManager *m_bookmarkSyncManager = nullptr;
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(QStringLiteral("http"))
44 , m_ownloudServer()
45 , m_owncloudUsername()
46 , m_owncloudPassword()
47 , m_status()
48 , m_status_type(CloudSyncManager::Unknown)
49{
50}
51
52CloudSyncManager::CloudSyncManager(QObject *parent)
53 : QObject(parent)
54 , d(new Private)
55{
56}
57
58CloudSyncManager::~CloudSyncManager()
59{
60 delete d;
61}
62
63bool CloudSyncManager::workOffline() const
64{
65 return d->m_workOffline;
66}
67
68void CloudSyncManager::setWorkOffline(bool offline)
69{
70 if (offline != d->m_workOffline) {
71 d->m_workOffline = offline;
72 Q_EMIT workOfflineChanged(d->m_workOffline);
73 }
74}
75
76bool CloudSyncManager::isSyncEnabled() const
77{
78 return d->m_syncEnabled;
79}
80
81QString CloudSyncManager::owncloudServer() const
82{
83 return d->m_owncloudProtocol + d->m_ownloudServer;
84}
85
86QString CloudSyncManager::owncloudUsername() const
87{
88 return d->m_owncloudUsername;
89}
90
91QString CloudSyncManager::owncloudPassword() const
92{
93 return d->m_owncloudPassword;
94}
95
96void CloudSyncManager::setSyncEnabled(bool enabled)
97{
98 if (d->m_syncEnabled != enabled) {
99 d->m_syncEnabled = enabled;
100 Q_EMIT syncEnabledChanged(d->m_syncEnabled);
101 }
102}
103
104void CloudSyncManager::setOwncloudCredentials(const QString &server, const QString &user, const QString &password)
105{
106 QUrl const oldApiUrl = apiUrl();
107 blockSignals(true);
108 setOwncloudServer(server);
109 setOwncloudUsername(user);
110 setOwncloudPassword(password);
111 blockSignals(false);
112 if (oldApiUrl != apiUrl()) {
113 Q_EMIT apiUrlChanged(apiUrl());
114 }
115}
116
117void CloudSyncManager::setOwncloudServer(const QString &server)
118{
119 QString const oldProtocol = d->m_owncloudProtocol;
120 QString const oldServer = d->m_ownloudServer;
121
122 if (server.startsWith(QLatin1StringView("http://"))) {
123 d->m_owncloudProtocol = QStringLiteral("http://");
124 d->m_ownloudServer = server.mid(7);
125 } else if (server.startsWith(QLatin1StringView("https://"))) {
126 d->m_owncloudProtocol = QStringLiteral("https://");
127 d->m_ownloudServer = server.mid(8);
128 } else {
129 d->m_owncloudProtocol = QStringLiteral("http://");
130 d->m_ownloudServer = server;
131 }
132
133 if (oldServer != d->m_ownloudServer) {
134 Q_EMIT owncloudServerChanged(owncloudServer());
135 Q_EMIT apiUrlChanged(apiUrl());
136 } else if (oldProtocol != d->m_owncloudProtocol) {
137 Q_EMIT apiUrlChanged(apiUrl());
138 }
139}
140
141void CloudSyncManager::setOwncloudUsername(const QString &username)
142{
143 if (d->m_owncloudUsername != username) {
144 d->m_owncloudUsername = username;
145 Q_EMIT owncloudUsernameChanged(d->m_owncloudUsername);
146 Q_EMIT apiUrlChanged(apiUrl());
147 }
148}
149
150void CloudSyncManager::setOwncloudPassword(const QString &password)
151{
152 if (d->m_owncloudPassword != password) {
153 d->m_owncloudPassword = password;
154 Q_EMIT owncloudPasswordChanged(d->m_owncloudPassword);
155 Q_EMIT apiUrlChanged(apiUrl());
156 }
157}
158
159void CloudSyncManager::setStatus(const QString &status, CloudSyncManager::Status status_type)
160{
161 if (d->m_status != status && d->m_status_type != status_type) {
162 d->m_status = status;
163 d->m_status_type = status_type;
164 Q_EMIT statusChanged(d->m_status);
165 }
166}
167
168CloudSyncManager::Status CloudSyncManager::status() const
169{
170 return d->m_status_type;
171}
172
173QString CloudSyncManager::statusDescription() const
174{
175 return d->m_status;
176}
177
178QString CloudSyncManager::apiPath() const
179{
180 return QStringLiteral("index.php/apps/marble/api/v1");
181}
182
183QUrl CloudSyncManager::apiUrl() const
184{
185 return QUrl(QStringLiteral("%1%2:%3@%4/%5")
186 .arg(d->m_owncloudProtocol)
187 .arg(d->m_owncloudUsername)
188 .arg(d->m_owncloudPassword)
189 .arg(d->m_ownloudServer)
190 .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.
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 Mon Nov 4 2024 16:37:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.