summaryrefslogtreecommitdiff
path: root/mpris2/rootinterfacetest.cpp
blob: 7359fa0463b28920bf49c05b3699ae5fa6dbf818 (plain)
1
2
3
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright 2011  Alex Merry <dev@randomguy3.me.uk>
 *
 * 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) any later version.
 *
 * 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
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "rootinterfacetest.h"

#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>

#define MPRIS2_ROOT_IFACE "org.mpris.MediaPlayer2"

using namespace Mpris2;

RootInterfaceTest::RootInterfaceTest(const QString& service, QObject* parent)
    : InterfaceTest(MPRIS2_ROOT_IFACE, service, parent)
{
}

RootInterfaceTest::~RootInterfaceTest()
{
}

void RootInterfaceTest::checkPropertyIdentity(const QVariantMap& oldProps)
{
    if (checkNonEmptyStringPropValid("Identity", oldProps)) {
        QString identity = props["Identity"].toString();
        if (("org.mpris.MediaPlayer2." + identity) == iface->service()) {
            emit interfaceWarning(Property, "Identity", "Identity is the same as the service name (one is user-readable, the other is the 'internal' name)");
        }
    }
}

void RootInterfaceTest::checkPropertyDesktopEntry(const QVariantMap& oldProps)
{
    if (checkNonEmptyStringPropValid("DesktopEntry", oldProps)) {
        // TODO: check for desktop file existence
        // check that desktop name matches identity, warn otherwise
    }
}

void RootInterfaceTest::checkPropertySupportedUriSchemes(const QVariantMap& oldProps)
{
    if (checkPropValid("SupportedUriSchemes", QVariant::StringList, oldProps)) {
        QStringList uriSchemes = props["SupportedUriSchemes"].toStringList();
        if (!uriSchemes.contains("file")) {
            emit interfaceWarning(Property, "SupportedUriSchemes", "\"file\" is not listed as a supported URI scheme (this is unusual)");
        }
        // TODO: check valid protocols
    }
}

void RootInterfaceTest::checkPropertySupportedMimeTypes(const QVariantMap& oldProps)
{
    if (checkPropValid("SupportedMimeTypes", QVariant::StringList, oldProps)) {
        QStringList mimeTypes = props["SupportedMimeTypes"].toStringList();
        if (mimeTypes.isEmpty()) {
            emit interfaceWarning(Property, "SupportedMimeTypes", "The media player claims not to support any mime types");
        }
        // TODO: check valid mimetypes
    }
}

void RootInterfaceTest::checkProps(const QVariantMap& oldProps)
{
    checkPropValid("CanQuit", QVariant::Bool, oldProps);
    checkPropValid("CanRaise", QVariant::Bool, oldProps);
    checkPropValid("HasTrackList", QVariant::Bool, oldProps);
    checkPropertyIdentity(oldProps);
    checkPropertyDesktopEntry(oldProps);
    checkPropertySupportedUriSchemes(oldProps);
    checkPropertySupportedMimeTypes(oldProps);
}

void RootInterfaceTest::checkUpdatedProperty(const QString& propName)
{
    if (propName == "CanQuit") {
        checkPropValid("CanQuit", QVariant::Bool);
    } else if (propName == "CanRaise") {
        checkPropValid("CanRaise", QVariant::Bool);
    } else if (propName == "HasTrackList") {
        checkPropValid("HasTrackList", QVariant::Bool);
    } else if (propName == "Identity") {
        checkPropertyIdentity();
    } else if (propName == "DesktopEntry") {
        checkPropertyDesktopEntry();
    } else if (propName == "SupportedUriSchemes") {
        checkPropertySupportedUriSchemes();
    } else if (propName == "SupportedMimeTypes") {
        checkPropertySupportedMimeTypes();
    }
}

void RootInterfaceTest::testQuit()
{
    QDBusReply<void> reply = iface->call("Quit");
    if (!reply.isValid() && props["CanQuit"].toBool()) {
        emit interfaceError(Method, "Quit", "CanQuit is true, but call to Quit failed with error " + reply.error().message());
    } else if (reply.isValid()) {
        if (!props["CanQuit"].toBool()) {
            emit interfaceInfo(Method, "Quit", "Call to Quit successful, even though CanQuit is false");
        } else {
            emit interfaceInfo(Method, "Quit", "Call to Quit successful; the media player should now quit");
            // TODO: check to see if it has gone away in a few seconds
        }
    }
}

void RootInterfaceTest::testRaise()
{
    QDBusReply<void> reply = iface->call("Raise");
    if (!reply.isValid() && props["CanRaise"].toBool()) {
        emit interfaceError(Method, "Raise", "CanRaise is true, but call to Raise failed with error " + reply.error().message());
    } else if (reply.isValid()) {
        if (!props["CanRaise"].toBool()) {
            emit interfaceInfo(Method, "Raise", "Call to Raise successful, even though CanRaise is false");
        } else {
            emit interfaceInfo(Method, "Raise", "Call to Raise successful; the media player should now be raised");
        }
    }
}

// vim:et:sw=4:sts=4