testdaemon.h 2.72 KB
Newer Older
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
 * Copyright 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
19 20 21 22 23 24 25 26
 */

#ifndef TESTDAEMON_H
#define TESTDAEMON_H

#include <core/daemon.h>
#include <core/backends/pairinghandler.h>

27 28 29 30 31 32 33 34 35
#include <QCoreApplication>
#include <KJobTrackerInterface>

#ifdef HAVE_KIO
#include <KIO/AccessManager>
#else
#include <QNetworkAccessManager>
#endif

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
36 37 38
class TestDaemon : public Daemon
{
public:
Nicolas Fella's avatar
Nicolas Fella committed
39
    TestDaemon(QObject* parent = nullptr)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40
        : Daemon(parent, true)
Nicolas Fella's avatar
Nicolas Fella committed
41
        , m_nam(nullptr)
42
        , m_jobTrackerInterface(nullptr)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
43
    {
Simon Redman's avatar
Simon Redman committed
44 45 46
        // Necessary to force the event loop to run because the test harness seems to behave differently
        // and we need the QTimer::SingleShot in Daemon's constructor to fire
        QCoreApplication::processEvents();
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
47 48
    }

49 50 51 52
    void addDevice(Device* device) {
        Daemon::addDevice(device);
    }

53
    void reportError(const QString & title, const QString & description) override
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
54 55 56 57
    {
        qWarning() << "error:" << title << description;
    }

58
    void askPairingConfirmation(Device * d) override {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
59 60 61
        d->acceptPairing();
    }

62
    QNetworkAccessManager* networkAccessManager() override
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
63 64
    {
        if (!m_nam) {
65
#ifdef HAVE_KIO
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
66
            m_nam = new KIO::AccessManager(this);
67 68 69
#else
            m_nam = new QNetworkAccessManager(this);
#endif
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
70 71 72 73
        }
        return m_nam;
    }

74
    Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) override
75 76 77 78
    {
        qDebug() << eventId << title << text << iconName;
    }

79 80 81 82
    void quit() override {
        qDebug() << "quit was called";
    }

83 84 85 86 87 88 89 90
    KJobTrackerInterface* jobTracker() override
    {
        if (!m_jobTrackerInterface) {
            m_jobTrackerInterface = new KJobTrackerInterface();
        }
        return m_jobTrackerInterface;
    }

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
91 92
private:
    QNetworkAccessManager* m_nam;
93
     KJobTrackerInterface* m_jobTrackerInterface;
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
94 95 96
};

#endif