~ci-train-bot/ubuntu-system-settings/ubuntu-system-settings-ubuntu-yakkety-landing-027

« back to all changes in this revision

Viewing changes to plugins/system-update/click/tokendownloader_impl.cpp

  • Committer: Bileto Bot
  • Author(s): jonas-drange
  • Date: 2016-08-17 11:18:05 UTC
  • mfrom: (1631.6.245 updates-rewrite)
  • Revision ID: ci-train-bot@canonical.com-20160817111805-moyvik9wloy79ul3
rewrite the system update panel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of system-settings
 
3
 *
 
4
 * Copyright (C) 2016 Canonical Ltd.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include "click/apiclient_impl.h"
 
20
#include "click/tokendownloader_impl.h"
 
21
#include "helpers.h"
 
22
 
 
23
namespace UpdatePlugin
 
24
{
 
25
namespace Click
 
26
{
 
27
TokenDownloaderImpl::TokenDownloaderImpl(ApiClient *client,
 
28
                                         QSharedPointer<Update> update,
 
29
                                         QObject *parent)
 
30
    : TokenDownloader(client, update, parent)
 
31
{
 
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()));
 
42
}
 
43
 
 
44
TokenDownloaderImpl::~TokenDownloaderImpl()
 
45
{
 
46
    cancel();
 
47
}
 
48
 
 
49
ApiClient* TokenDownloaderImpl::client() const
 
50
{
 
51
    return m_client;
 
52
}
 
53
 
 
54
void TokenDownloaderImpl::cancel()
 
55
{
 
56
    m_client->cancel();
 
57
}
 
58
 
 
59
void TokenDownloaderImpl::download(const QString &url)
 
60
{
 
61
    QUrl query(m_update->downloadUrl());
 
62
    query.setQuery(url);
 
63
    m_client->requestToken(query);
 
64
}
 
65
 
 
66
void TokenDownloaderImpl::handleSuccess(const QString &token)
 
67
{
 
68
    m_update->setToken(token);
 
69
    if (token.isEmpty()) {
 
70
        downloadFailed(m_update);
 
71
    } else {
 
72
        downloadSucceeded(m_update);
 
73
    }
 
74
}
 
75
 
 
76
void TokenDownloaderImpl::handleFailure()
 
77
{
 
78
    Q_EMIT downloadFailed(m_update);
 
79
}
 
80
}// Click
 
81
}// UpdatePlugin