~unity-team/unity-scope-click/devel

« back to all changes in this revision

Viewing changes to scope/tests/fake_launcher/fake_launcher.h

  • Committer: Tarmac
  • Author(s): Alejandro J. Cura
  • Date: 2014-06-20 21:29:21 UTC
  • mfrom: (294.1.14 launcher-integration)
  • Revision ID: tarmac-20140620212921-odeqeom2ji6lxw8c
Send the dbus signals to the launcher, when a download is started and when it's completed.

Approved by Rodney Dawes, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * In addition, as a special exception, the copyright holders give
 
17
 * permission to link the code of portions of this program with the
 
18
 * OpenSSL library under certain conditions as described in each
 
19
 * individual source file, and distribute linked combinations
 
20
 * including the two.
 
21
 * You must obey the GNU General Public License in all respects
 
22
 * for all of the code used other than OpenSSL.  If you modify
 
23
 * file(s) with this exception, you may extend this exception to your
 
24
 * version of the file(s), but you are not obligated to do so.  If you
 
25
 * do not wish to do so, delete this exception statement from your
 
26
 * version.  If you delete this exception statement from all source
 
27
 * files in the program, then also delete it here.
 
28
 */
 
29
 
 
30
#ifndef _FAKE_LAUNCHER_H_
 
31
#define _FAKE_LAUNCHER_H_
 
32
 
 
33
#include <QObject>
 
34
#include <QDBusObjectPath>
 
35
#include <QDBusAbstractAdaptor>
 
36
 
 
37
#include <click/dbus_constants.h>
 
38
#include <ubuntu/download_manager/manager.h>
 
39
 
 
40
class FakeIcon : public QObject {
 
41
    Q_OBJECT
 
42
 
 
43
public:
 
44
    explicit FakeIcon(QString title, QString icon_url, QObject *parent=0)
 
45
        : QObject(parent), title(title), icon_url(icon_url)
 
46
    {
 
47
    }
 
48
    void downloadFound(Download& download);
 
49
    void complete(QString app_id);
 
50
 
 
51
private slots:
 
52
    void handleProgress(qulonglong transferred, qulonglong total);
 
53
    void handleDownloadError(Error* error);
 
54
 
 
55
private:
 
56
    Download* download;
 
57
    QString title;
 
58
    QString icon_url;
 
59
    void failure(QString message);
 
60
};
 
61
 
 
62
class FakeLauncher : public QObject {
 
63
    Q_OBJECT
 
64
 
 
65
public:
 
66
    explicit FakeLauncher(QObject *parent=0) : QObject(parent)
 
67
    {
 
68
        manager = Ubuntu::DownloadManager::Manager::createSessionManager();
 
69
        connect(manager, SIGNAL(downloadsWithMetadataFound(QString,QString,DownloadsList*)),
 
70
                this, SLOT(handleDownloadsFound(QString,QString,DownloadsList*)));
 
71
    }
 
72
                                                             
 
73
public slots:
 
74
    void startInstallation(QString title, QString icon_url, QString package_name);
 
75
    void completeInstallation(QString package_name, QString app_id);
 
76
 
 
77
private slots:
 
78
    void handleDownloadsFound(const QString& key, const QString& value, DownloadsList* downloads);
 
79
 
 
80
signals:
 
81
 
 
82
private:
 
83
    Ubuntu::DownloadManager::Manager* manager;
 
84
    QMap<QString, FakeIcon*> installations;
 
85
};
 
86
 
 
87
 
 
88
class FakeLauncherAdaptor : public QDBusAbstractAdaptor
 
89
{
 
90
    Q_OBJECT
 
91
    Q_CLASSINFO("D-Bus Interface", LAUNCHER_INTERFACE)
 
92
 
 
93
private:
 
94
    FakeLauncher *_launcher;
 
95
 
 
96
public:
 
97
    FakeLauncherAdaptor(FakeLauncher *launcher) : QDBusAbstractAdaptor(launcher), _launcher(launcher)
 
98
    {
 
99
    }
 
100
 
 
101
public slots:
 
102
    Q_NOREPLY void startInstallation(QString title, QString icon_url, QString package_name)
 
103
    {
 
104
        _launcher->startInstallation(title, icon_url, package_name);
 
105
    }
 
106
 
 
107
    Q_NOREPLY void completeInstallation(QString package_name, QString app_id)
 
108
    {
 
109
        _launcher->completeInstallation(package_name, app_id);
 
110
    }
 
111
};
 
112
 
 
113
 
 
114
#endif /* _FAKE_LAUNCHER_H_ */
 
115
 
 
116