2
* This file is part of system-settings
4
* Copyright (C) 2016 Canonical Ltd.
6
* This program is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 3, as published
8
* by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranties of
12
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
* PURPOSE. See the GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "click/apiclient_impl.h"
20
#include "click/tokendownloader_impl.h"
23
namespace UpdatePlugin
27
TokenDownloaderImpl::TokenDownloaderImpl(ApiClient *client,
28
QSharedPointer<Update> update,
30
: TokenDownloader(client, update, parent)
32
connect(m_client, SIGNAL(tokenRequestSucceeded(const QString)),
33
this, SLOT(handleSuccess(const QString)));
34
connect(m_client, SIGNAL(networkError()),
35
this, SLOT(handleFailure()));
36
connect(m_client, SIGNAL(serverError()),
37
this, SLOT(handleFailure()));
38
connect(m_client, SIGNAL(credentialError()),
39
this, SLOT(handleFailure()));
40
connect(m_client, SIGNAL(credentialError()),
41
this, SIGNAL(credentialError()));
44
TokenDownloaderImpl::~TokenDownloaderImpl()
49
ApiClient* TokenDownloaderImpl::client() const
54
void TokenDownloaderImpl::cancel()
59
void TokenDownloaderImpl::download(const QString &url)
61
QUrl query(m_update->downloadUrl());
63
m_client->requestToken(query);
66
void TokenDownloaderImpl::handleSuccess(const QString &token)
68
m_update->setToken(token);
69
if (token.isEmpty()) {
70
downloadFailed(m_update);
72
downloadSucceeded(m_update);
76
void TokenDownloaderImpl::handleFailure()
78
Q_EMIT downloadFailed(m_update);