~ubuntuone-hackers/ubuntu-download-manager/vivid

« back to all changes in this revision

Viewing changes to src/downloads/client/ubuntu/download_manager/error.cpp

  • Committer: CI Train Bot
  • Author(s): Manuel de la Pena, CI Train Bot
  • Date: 2015-09-22 15:27:23 UTC
  • mfrom: (338.2.14 vivid-add-appid-metadata)
  • Revision ID: ci-train-bot@canonical.com-20150922152723-gyk5ul6h0d4d0l0h
The download object now carries the app id of the application that created the download. Fixes: #1481673
Approved by: Alfonso Sanchez-Beato

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013-2014 Canonical Ltd.
 
2
 * Copyright 2013-2015 Canonical Ltd.
3
3
 *
4
4
 * This library is free software; you can redistribute it and/or
5
5
 * modify it under the terms of version 3 of the GNU Lesser General Public
26
26
    const QString HTTP_ERROR_STRING = "HttpError: %1 - %2";
27
27
    const QString NETWORK_ERROR_STRING = "NetworkError: %1 - %2";
28
28
    const QString PROCESS_ERROR_STRING = "ProcessError: %1 - %2\nExit code: %3\nStdout: %4\nStderr:%5";
 
29
    const QString HASH_ERROR_STRING = "Hash validation error using %1: Expected result is %2 but result was %3.";
29
30
}
30
31
 
31
32
namespace Ubuntu {
45
46
          q_ptr(parent) {
46
47
    }
47
48
 
48
 
    Error::Type type() {
 
49
    Error::Type type() const {
49
50
        return _type;
50
51
    }
51
52
 
52
 
    QString errorString() {
 
53
    QString errorString() const {
53
54
        switch(_type) {
54
55
            case Error::DBus:
55
56
                return "DBusError";
59
60
                return "NetworkError";
60
61
            case Error::Process:
61
62
                return "ProcessError";
 
63
            case Error::Hash:
 
64
                return "HashError";
62
65
            default:
63
66
                return "";
64
67
        }
78
81
          q_ptr(parent) {
79
82
    }
80
83
 
81
 
    inline QString message() {
 
84
    inline QString message() const {
82
85
        return _err.message();
83
86
    }
84
87
 
85
 
    inline QString name() {
 
88
    inline QString name() const {
86
89
        return _err.name();
87
90
    }
88
91
 
89
 
    inline QString errorString() {
 
92
    inline QString errorString() const {
90
93
        return DBUS_ERROR_STRING.arg(_err.name(), _err.message());
91
94
    }
92
95
 
104
107
          q_ptr(parent) {
105
108
    }
106
109
 
107
 
    inline AuthError::Type type() {
 
110
    inline AuthError::Type type() const {
108
111
        switch(_err.getType()) {
109
112
            case Transfers::Errors::AuthErrorStruct::Proxy:
110
113
                return AuthError::Proxy;
113
116
        }
114
117
    }
115
118
 
116
 
    inline QString getTypeString() {
 
119
    inline QString getTypeString() const {
117
120
        switch(_err.getType()) {
118
121
            case Transfers::Errors::AuthErrorStruct::Proxy:
119
122
                return "Proxy";
122
125
        }
123
126
    }
124
127
 
125
 
    inline QString phrase() {
 
128
    inline QString phrase() const {
126
129
        return _err.getPhrase();
127
130
    }
128
131
 
129
 
    inline QString errorString() {
 
132
    inline QString errorString() const {
130
133
        return AUTH_ERROR_STRING.arg(getTypeString(), _err.getPhrase());
131
134
    }
132
135
 
144
147
          q_ptr(parent) {
145
148
    }
146
149
 
147
 
    inline int code() {
 
150
    inline int code() const {
148
151
        return _err.getCode();
149
152
    }
150
153
 
151
 
    inline QString phrase() {
 
154
    inline QString phrase() const {
152
155
        return _err.getPhrase();
153
156
    }
154
157
 
155
 
    inline QString errorString() {
 
158
    inline QString errorString() const {
156
159
        return HTTP_ERROR_STRING.arg(QString::number(_err.getCode()),
157
160
            _err.getPhrase());
158
161
    }
172
175
          q_ptr(parent) {
173
176
    }
174
177
 
175
 
    inline NetworkError::ErrorCode code() {
 
178
    inline NetworkError::ErrorCode code() const {
176
179
        auto intCode = static_cast<NetworkError::ErrorCode>(_err.getCode());
177
180
        return intCode;
178
181
    }
179
182
 
180
 
    inline QString phrase() {
 
183
    inline QString phrase() const {
181
184
        return _err.getPhrase();
182
185
    }
183
186
 
184
 
    inline QString errorString() {
 
187
    inline QString errorString() const {
185
188
        return NETWORK_ERROR_STRING.arg(QString::number(_err.getCode()),
186
189
            _err.getPhrase());
187
190
    }
201
204
          q_ptr(parent) {
202
205
    }
203
206
 
204
 
    QProcess::ProcessError code() {
 
207
    QProcess::ProcessError code() const {
205
208
        auto code = static_cast<QProcess::ProcessError>(_err.getCode());
206
209
        return code;
207
210
    }
208
211
 
209
 
    QString phrase() {
 
212
    QString phrase() const {
210
213
        return _err.getPhrase();
211
214
    }
212
215
 
213
 
    inline int exitCode() {
 
216
    inline int exitCode() const {
214
217
        return _err.getExitCode();
215
218
    }
216
219
 
217
 
    inline QString standardOut() {
 
220
    inline QString standardOut() const {
218
221
        return _err.getStandardOutput();
219
222
    }
220
223
 
221
 
    inline QString standardError() {
 
224
    inline QString standardError() const {
222
225
        return _err.getStandardError();
223
226
    }
224
227
 
225
 
    inline QString errorString() {
 
228
    inline QString errorString() const {
226
229
        return PROCESS_ERROR_STRING.arg(QString::number(_err.getCode()),
227
230
            _err.getPhrase(), QString::number(_err.getExitCode()),
228
231
            _err.getStandardOutput(), _err.getStandardError());
233
236
    ProcessError* q_ptr;
234
237
};
235
238
 
 
239
class HashErrorPrivate {
 
240
    Q_DECLARE_PUBLIC(HashError)
 
241
 
 
242
 public:
 
243
    HashErrorPrivate (Transfers::Errors::HashErrorStruct err, HashError* parent)
 
244
        : _err(err),
 
245
          q_ptr(parent) {
 
246
    }
 
247
 
 
248
    inline QString method() const {
 
249
        return _err.getMethod();
 
250
    }
 
251
 
 
252
    inline QString expected() const {
 
253
        return _err.getExpected();
 
254
    }
 
255
 
 
256
    inline QString checksum() const {
 
257
        return _err.getChecksum();
 
258
    }
 
259
 
 
260
    inline QString errorString() const {
 
261
        return HASH_ERROR_STRING.arg(_err.getMethod()).arg(_err.getExpected()).arg(_err.getChecksum());
 
262
    }
 
263
 
 
264
 private:
 
265
    Transfers::Errors::HashErrorStruct _err;
 
266
    HashError* q_ptr;
 
267
};
 
268
 
236
269
/*
237
270
 * PUBLIC IMPLEMENTATIONS
238
271
 */
413
446
    return d->errorString();
414
447
}
415
448
 
 
449
HashError::HashError(Transfers::Errors::HashErrorStruct errStruct, QObject* parent)
 
450
        : Error(Error::Hash, parent),
 
451
          d_ptr(new HashErrorPrivate(errStruct, this)) {
 
452
}
 
453
 
 
454
HashError::~HashError() {
 
455
    delete d_ptr;
 
456
}
 
457
 
 
458
QString
 
459
HashError::method() {
 
460
    Q_D(HashError);
 
461
    return d->method();
 
462
}
 
463
 
 
464
QString
 
465
HashError::expected() {
 
466
    Q_D(HashError);
 
467
    return d->expected();
 
468
}
 
469
 
 
470
QString
 
471
HashError::checksum() {
 
472
    Q_D(HashError);
 
473
    return d->checksum();
 
474
}
 
475
 
 
476
QString
 
477
HashError::errorString() {
 
478
    Q_D(HashError);
 
479
    return d->errorString();
 
480
}
 
481
 
416
482
}  // DownloadManager
417
483
 
418
484
}  // Ubuntu