| 1 | /* |
| 2 | * Copyright (C) 2014 Canonical Ltd. |
| 3 | * |
| 4 | * Contact: Alberto Mardegan <[email protected]> |
| 5 | * |
| 6 | * This file is part of lomiri-online-accounts-ui |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 3, as published |
| 10 | * by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <online-accounts-common/globals.h> |
| 22 | #include "request-mock.h" |
| 23 | |
| 24 | #include <QDebug> |
| 25 | |
| 26 | using namespace OnlineAccountsUi; |
| 27 | |
| 28 | RequestPrivate::RequestPrivate(const QString &interface, |
| 29 | int id, |
| 30 | const QString &clientProfile, |
| 31 | const QVariantMap ¶meters, |
| 32 | Request *request): |
| 33 | QObject(request), |
| 34 | q_ptr(request), |
| 35 | m_parameters(parameters), |
| 36 | m_clientApparmorProfile(clientProfile), |
| 37 | m_window(0), |
| 38 | m_delay(0), |
| 39 | m_inProgress(false) |
| 40 | { |
| 41 | Q_UNUSED(interface); |
| 42 | Q_UNUSED(id); |
| 43 | } |
| 44 | |
| 45 | RequestPrivate::~RequestPrivate() |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | Request::Request(const QString &interface, |
| 50 | int id, |
| 51 | const QString &clientProfile, |
| 52 | const QVariantMap ¶meters, |
| 53 | QObject *parent): |
| 54 | QObject(parent), |
| 55 | d_ptr(new RequestPrivate(interface, id, clientProfile, parameters, this)) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | Request::~Request() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | void Request::setWindow(QWindow *window) |
| 64 | { |
| 65 | Q_D(Request); |
| 66 | Q_EMIT d->setWindowCalled(window); |
| 67 | } |
| 68 | |
| 69 | WId Request::windowId() const |
| 70 | { |
| 71 | Q_D(const Request); |
| 72 | return d->m_parameters[OAU_KEY_WINDOW_ID].toUInt(); |
| 73 | } |
| 74 | |
| 75 | bool Request::isInProgress() const |
| 76 | { |
| 77 | Q_D(const Request); |
| 78 | return d->m_inProgress; |
| 79 | } |
| 80 | |
| 81 | const QVariantMap &Request::parameters() const |
| 82 | { |
| 83 | Q_D(const Request); |
| 84 | return d->m_parameters; |
| 85 | } |
| 86 | |
| 87 | QString Request::clientApparmorProfile() const |
| 88 | { |
| 89 | Q_D(const Request); |
| 90 | return d->m_clientApparmorProfile; |
| 91 | } |
| 92 | |
| 93 | QWindow *Request::window() const |
| 94 | { |
| 95 | Q_D(const Request); |
| 96 | return d->m_window; |
| 97 | } |
| 98 | |
| 99 | void Request::setDelay(int delay) |
| 100 | { |
| 101 | Q_D(Request); |
| 102 | d->m_delay = delay; |
| 103 | } |
| 104 | |
| 105 | int Request::delay() const |
| 106 | { |
| 107 | Q_D(const Request); |
| 108 | return d->m_delay; |
| 109 | } |
| 110 | |
| 111 | void Request::start() |
| 112 | { |
| 113 | Q_D(Request); |
| 114 | if (d->m_inProgress) { |
| 115 | qWarning() << "Request already started!"; |
| 116 | return; |
| 117 | } |
| 118 | d->m_inProgress = true; |
| 119 | } |
| 120 | |
| 121 | void Request::cancel() |
| 122 | { |
| 123 | setCanceled(); |
| 124 | } |
| 125 | |
| 126 | void Request::fail(const QString &name, const QString &message) |
| 127 | { |
| 128 | Q_D(Request); |
| 129 | Q_EMIT d->failCalled(name, message); |
| 130 | |
| 131 | Q_EMIT completed(); |
| 132 | } |
| 133 | |
| 134 | void Request::setCanceled() |
| 135 | { |
| 136 | Q_D(Request); |
| 137 | if (d->m_inProgress) { |
| 138 | fail(OAU_ERROR_USER_CANCELED, QStringLiteral("Canceled")); |
| 139 | d->m_inProgress = false; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void Request::setResult(const QVariantMap &result) |
| 144 | { |
| 145 | Q_D(Request); |
| 146 | if (d->m_inProgress) { |
| 147 | Q_EMIT d->setResultCalled(result); |
| 148 | |
| 149 | Q_EMIT completed(); |
| 150 | d->m_inProgress = false; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | QString Request::mountPoint() const |
| 155 | { |
| 156 | return ""; |
| 157 | } |