developermodesettings.h 5.6 KB
Newer Older
1
/*
Tomi Leppänen's avatar
Tomi Leppänen committed
2
 * Copyright (c) 2013 – 2019 Jolla Ltd.
3
 * Copyright (c) 2019 – 2020 Open Mobile Platform LLC.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 * Contact: Thomas Perl <thomas.perl@jollamobile.com>
 *
 * You may use this file under the terms of the BSD license as follows:
 *
 * "Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *   * Neither the name of Nemo Mobile nor the names of its contributors
 *     may be used to endorse or promote products derived from this
 *     software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 */

#ifndef DEVELOPERMODESETTINGS_H
#define DEVELOPERMODESETTINGS_H

#include <QObject>
#include <QDBusInterface>

40
#include <systemsettingsglobal.h>
41 42
#include <daemon.h>

43

44 45 46
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
QT_END_NAMESPACE
47

48
class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
49 50 51
{
    Q_OBJECT
    Q_ENUMS(Status)
52
    Q_ENUMS(InstallationType)
53

Raine Makelainen's avatar
Raine Makelainen committed
54 55 56 57
    Q_PROPERTY(QString wlanIpAddress READ wlanIpAddress NOTIFY wlanIpAddressChanged)
    Q_PROPERTY(QString usbIpAddress READ usbIpAddress NOTIFY usbIpAddressChanged)
    Q_PROPERTY(QString username READ username CONSTANT)
    Q_PROPERTY(bool developerModeEnabled READ developerModeEnabled NOTIFY developerModeEnabledChanged)
58 59
    Q_PROPERTY(enum DeveloperModeSettings::Status workStatus READ workStatus NOTIFY workStatusChanged)
    Q_PROPERTY(int workProgress READ workProgress NOTIFY workProgressChanged)
60
    Q_PROPERTY(bool repositoryAccessRequired READ repositoryAccessRequired NOTIFY repositoryAccessRequiredChanged)
61 62
    Q_PROPERTY(bool debugHomeEnabled READ debugHomeEnabled NOTIFY debugHomeEnabledChanged)
    Q_PROPERTY(enum DeveloperModeSettings::InstallationType installationType READ installationType NOTIFY installationTypeChanged)
63 64 65 66 67 68 69

public:
    explicit DeveloperModeSettings(QObject *parent = NULL);
    virtual ~DeveloperModeSettings();

    enum Status {
        Idle = 0,
70 71 72 73
        Preparing,
        DownloadingPackages,
        InstallingPackages,
        RemovingPackages
74 75 76 77 78
    };    
    enum InstallationType {
        None,
        DeveloperMode,
        DebugHome
79 80 81 82
    };

    QString wlanIpAddress() const;
    QString usbIpAddress() const;
83
    QString username() const;
84
    bool developerModeEnabled() const;
85 86
    enum DeveloperModeSettings::Status workStatus() const;
    int workProgress() const;
87
    bool repositoryAccessRequired() const;
88 89 90
    bool debugHomeEnabled() const;
    QString packageName();
    enum DeveloperModeSettings::InstallationType installationType() const;
91 92 93 94

    Q_INVOKABLE void setDeveloperMode(bool enabled);
    Q_INVOKABLE void setUsbIpAddress(const QString &usbIpAddress);
    Q_INVOKABLE void refresh();
95
    Q_INVOKABLE void moveDebugToHome(bool enabled);
96 97 98 99 100

signals:
    void wlanIpAddressChanged();
    void usbIpAddressChanged();
    void developerModeEnabledChanged();
101 102
    void workStatusChanged();
    void workProgressChanged();
103
    void repositoryAccessRequiredChanged();
104 105
    void debugHomeEnabledChanged();
    void installationTypeChanged();
106 107

private slots:
108
    void reportTransactionErrorCode(PackageKit::Transaction::Error code, const QString &details);
109
    void updateState(int percentage, PackageKit::Transaction::Status status, PackageKit::Transaction::Role role);
110 111

private:
112 113 114 115
    enum Command {
        InstallCommand,
        RemoveCommand
    };
116

117 118 119 120
    void resetState();
    void setWorkStatus(Status status);
    void refreshPackageCacheAndInstall();
    void resolveAndExecute(Command command);
121
    bool installAndRemove(Command command);
122
    void connectCommandSignals(PackageKit::Transaction *transaction);
123
    void setInstallationType(InstallationType type);
124

125 126 127
    QString usbModedGetConfig(const QString &key, const QString &fallback);
    void usbModedSetConfig(const QString &key, const QString &value);

128 129 130 131
    QDBusInterface m_usbModeDaemon;
    QString m_wlanIpAddress;
    QString m_usbInterface;
    QString m_usbIpAddress;
132
    QString m_username;
133
    QString m_packageId;
134
    bool m_developerModeEnabled;
135 136
    DeveloperModeSettings::Status m_workStatus;
    int m_workProgress;
137 138
    PackageKit::Transaction::Role m_transactionRole;
    PackageKit::Transaction::Status m_transactionStatus;
139
    bool m_refreshedForInstall;
140 141
    bool m_localInstallFailed;
    QString m_localDeveloperModePackagePath;
142 143
    bool m_debugHomeEnabled;
    DeveloperModeSettings::InstallationType m_installationType;
144 145
};

146
Q_DECLARE_METATYPE(DeveloperModeSettings::Status)
147
Q_DECLARE_METATYPE(DeveloperModeSettings::InstallationType)
148 149

#endif /* DEVELOPERMODESETTINGS_H */