From 832d6c90147ca3d176a1c8afc1f4380594898b5e Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 9 Nov 2011 01:43:21 +0000 Subject: Add widgets for setting rw property values --- mpris2/interfacetest.cpp | 100 +++++++++++- mpris2/interfacetest.h | 10 +- mpris2/playerinterfacetest.cpp | 30 ++++ mpris2/playerinterfacetest.h | 4 + mpris2/playertestwidget.cpp | 37 +++++ mpris2/playertestwidget.h | 5 + ui/playertest.ui | 344 ++++++++++++++++++++++++++--------------- 7 files changed, 397 insertions(+), 133 deletions(-) diff --git a/mpris2/interfacetest.cpp b/mpris2/interfacetest.cpp index 7265bab..c6af22e 100644 --- a/mpris2/interfacetest.cpp +++ b/mpris2/interfacetest.cpp @@ -77,7 +77,7 @@ bool InterfaceTest::getAllProps() return true; } -bool InterfaceTest::getProp(const QString& propName) +bool InterfaceTest::getProp(const QString& propName, InterfaceTest::PropErrorAllowance allowError) { if (!propsIface->isValid() || !iface->isValid()) { emit interfaceError(Other, "", @@ -103,15 +103,31 @@ bool InterfaceTest::getProp(const QString& propName) " interface was not implemented correctly at " MPRIS2_PATH "(replied \"unknown method\" for method \"Get\")"); } else if (propsReply.error().type() == QDBusError::InvalidArgs) { - emit interfaceError(Property, propName, - DBUS_PROPS_IFACE ".Get failed; reported \"invalid args\" (ie: unknown property)"); + if (allowError & PropAllowMissing) { + emit interfaceInfo(Property, propName, + DBUS_PROPS_IFACE ".Get failed; reported \"invalid args\" (ie: unknown property)"); + } else { + emit interfaceError(Property, propName, + DBUS_PROPS_IFACE ".Get failed; reported \"invalid args\" (ie: unknown property)"); + } } else if (propsReply.error().name() == "org.freedesktop.DBus.UnknownProperty") { - emit interfaceError(Property, propName, - DBUS_PROPS_IFACE ".Get failed; reported \"unknown property\""); + if (allowError & PropAllowMissing) { + emit interfaceInfo(Property, propName, + DBUS_PROPS_IFACE ".Get failed; reported \"unknown property\""); + } else { + emit interfaceError(Property, propName, + DBUS_PROPS_IFACE ".Get failed; reported \"unknown property\""); + } } else { - emit interfaceError(Other, "", - "Calling " DBUS_PROPS_IFACE - ".Get resulted in the error " + propsReply.error().name()); + if (allowError) { + emit interfaceWarning(Other, "", + "Calling " DBUS_PROPS_IFACE + ".Get resulted in the unexpected error " + propsReply.error().name()); + } else { + emit interfaceError(Other, "", + "Calling " DBUS_PROPS_IFACE + ".Get resulted in the error " + propsReply.error().name()); + } } return false; } @@ -120,6 +136,74 @@ bool InterfaceTest::getProp(const QString& propName) return true; } +bool InterfaceTest::setProp(const QString& propName, const QDBusVariant& propValue, InterfaceTest::PropErrorAllowance allowError) +{ + if (!propsIface->isValid() || !iface->isValid()) { + emit interfaceError(Other, "", + "No object with the " + + iface->interface() + + " and " + DBUS_PROPS_IFACE + " interfaces was not found at " + MPRIS2_PATH); + return false; + } + + QDBusReply propsReply = propsIface->call("Set", iface->interface(), propName, QVariant::fromValue(propValue)); + if (propsReply.isValid()) { + return true; + } else { + if (propsReply.error().type() == QDBusError::UnknownInterface) { + emit interfaceError(Other, "", + "The " DBUS_PROPS_IFACE + " interface was not implemented correctly at " + MPRIS2_PATH "(replied \"unknown interface\")"); + } else if (propsReply.error().type() == QDBusError::UnknownMethod) { + emit interfaceError(Other, "", + "The " DBUS_PROPS_IFACE + " interface was not implemented correctly at " + MPRIS2_PATH "(replied \"unknown method\" for method \"Set\")"); + } else if (propsReply.error().type() == QDBusError::InvalidArgs) { + if (allowError & PropAllowMissing || allowError & PropAllowReadOnly) { + emit interfaceInfo(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"invalid args\""); + } else { + emit interfaceError(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"invalid args\""); + } + } else if (propsReply.error().name() == "org.freedesktop.DBus.UnknownProperty") { + if (allowError & PropAllowMissing) { + emit interfaceInfo(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"unknown property\""); + } else { + emit interfaceError(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"unknown property\""); + } + } else if (propsReply.error().name() == "com.trolltech.QtDBus.Error.InternalError") { + // Qt returns InternalError for read-only properties + if (allowError & PropAllowReadOnly) { + emit interfaceInfo(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"internal error\" (Qt's way of saying \"read only\")"); + } else { + emit interfaceError(Property, propName, + DBUS_PROPS_IFACE ".Set failed; reported \"internal error\" (Qt's way of saying \"read only\")"); + } + } else { + if (allowError) { + emit interfaceWarning(Other, "", + "Calling " DBUS_PROPS_IFACE + ".Set resulted in the unexpected error " + propsReply.error().name()); + } else { + emit interfaceError(Other, "", + "Calling " DBUS_PROPS_IFACE + ".Set resulted in the error " + propsReply.error().name()); + } + } + return false; + } +} + + bool InterfaceTest::checkPropValid(const QString& propName, QVariant::Type expType, const QVariantMap& oldProps) { if (!props.contains(propName)) { emit interfaceError(Property, propName, "Property " + propName + " is missing"); diff --git a/mpris2/interfacetest.h b/mpris2/interfacetest.h index cfc174c..6e4d8e8 100644 --- a/mpris2/interfacetest.h +++ b/mpris2/interfacetest.h @@ -22,6 +22,7 @@ #define INTERFACETEST_H class QDBusInterface; +class QDBusVariant; class QDBusMessage; class QTimer; #include @@ -117,8 +118,15 @@ namespace Mpris2 void delayedIncrementalCheck(); protected: + enum PropErrorAllowance { + PropDisallowErrors = 0, + PropAllowMissing = 1, + PropAllowReadOnly = 2, + PropAllowErrors = PropAllowMissing | PropAllowReadOnly + }; bool getAllProps(); - bool getProp(const QString& propName); + bool getProp(const QString& propName, PropErrorAllowance allowError = PropDisallowErrors); + bool setProp(const QString& propName, const QDBusVariant& value, PropErrorAllowance allowError = PropAllowReadOnly); bool checkPropValid(const QString& propName, QVariant::Type expType, const QVariantMap& oldProps = QVariantMap()); bool checkNonEmptyStringPropValid(const QString& propName, const QVariantMap& oldProps = QVariantMap()); diff --git a/mpris2/playerinterfacetest.cpp b/mpris2/playerinterfacetest.cpp index 278fa81..00658fc 100644 --- a/mpris2/playerinterfacetest.cpp +++ b/mpris2/playerinterfacetest.cpp @@ -781,4 +781,34 @@ void PlayerInterfaceTest::testOpenUri(const QString& uri) } } +void PlayerInterfaceTest::testSetLoopStatus(const QString& loopStatus) +{ + // FIXME: look at whether value is valid + if (setProp("LoopStatus", QDBusVariant(QVariant(loopStatus)))) { + emit interfaceInfo(Property, "LoopStatus", "Setting LoopStatus did not return an error"); + } +} + +void PlayerInterfaceTest::testSetShuffle(bool shuffle) +{ + if (setProp("Shuffle", QDBusVariant(QVariant(shuffle)))) { + emit interfaceInfo(Property, "Shuffle", "Setting Shuffle did not return an error"); + } +} + +void PlayerInterfaceTest::testSetVolume(double volume) +{ + // FIXME: look at whether volume is out of bounds + if (setProp("Volume", QDBusVariant(QVariant(volume)))) { + emit interfaceInfo(Property, "Volume", "Setting Volume did not return an error"); + } +} + +void PlayerInterfaceTest::testSetRate(double rate) +{ + // FIXME: look at whether rate is out of bounds + if (setProp("Rate", QDBusVariant(QVariant(rate)))) { + emit interfaceInfo(Property, "Rate", "Setting Rate did not return an error"); + } +} diff --git a/mpris2/playerinterfacetest.h b/mpris2/playerinterfacetest.h index 21f1281..34656f9 100644 --- a/mpris2/playerinterfacetest.h +++ b/mpris2/playerinterfacetest.h @@ -45,6 +45,10 @@ namespace Mpris2 { void testSeek(qint64 offset); void testSetPosition(const QDBusObjectPath& trackId, qint64 offset); void testOpenUri(const QString& uri); + void testSetLoopStatus(const QString& loopStatus); + void testSetShuffle(bool shuffle); + void testSetVolume(double volume); + void testSetRate(double rate); signals: void Seeked(qint64 newPosition); diff --git a/mpris2/playertestwidget.cpp b/mpris2/playertestwidget.cpp index b3832ff..ad7a0ab 100644 --- a/mpris2/playertestwidget.cpp +++ b/mpris2/playertestwidget.cpp @@ -30,6 +30,9 @@ PlayerTestWidget::PlayerTestWidget(PlayerInterfaceTest* test, QWidget* parent) : QWidget(parent) { ui.setupUi(this); + ui.loopStatusCombo->addItem("None"); + ui.loopStatusCombo->addItem("Track"); + ui.loopStatusCombo->addItem("Playlist"); metadataModel = new MetadataModel(this); ui.metadataTableView->setModel(metadataModel); this->test = test; @@ -43,6 +46,16 @@ PlayerTestWidget::PlayerTestWidget(PlayerInterfaceTest* test, QWidget* parent) connect(estPosTimer, SIGNAL(timeout()), this, SLOT(updateEstPos())); + connect(ui.loopStatusSetBtn, SIGNAL(clicked(bool)), + this, SLOT(testSetLoopStatus())); + connect(ui.shuffleOnBtn, SIGNAL(clicked(bool)), + this, SLOT(testShuffleOn())); + connect(ui.shuffleOffBtn, SIGNAL(clicked(bool)), + this, SLOT(testShuffleOff())); + connect(ui.volumeSetBtn, SIGNAL(clicked(bool)), + this, SLOT(testSetVolume())); + connect(ui.rateSetBtn, SIGNAL(clicked(bool)), + this, SLOT(testSetRate())); connect(ui.nextBtn, SIGNAL(clicked(bool)), test, SLOT(testNext())); connect(ui.prevBtn, SIGNAL(clicked(bool)), @@ -188,3 +201,27 @@ void PlayerTestWidget::Seeked(qint64 position) ui.lastKnownPosLbl->setEnabled(true); } +void PlayerTestWidget::testSetLoopStatus() +{ + test->testSetLoopStatus(ui.loopStatusCombo->currentText()); +} + +void PlayerTestWidget::testShuffleOn() +{ + test->testSetShuffle(true); +} + +void PlayerTestWidget::testShuffleOff() +{ + test->testSetShuffle(false); +} + +void PlayerTestWidget::testSetVolume() +{ + test->testSetVolume(ui.volumeSpinBox->value()); +} + +void PlayerTestWidget::testSetRate() +{ + test->testSetRate(ui.rateSpinBox->value()); +} diff --git a/mpris2/playertestwidget.h b/mpris2/playertestwidget.h index 7ead34b..6a70006 100644 --- a/mpris2/playertestwidget.h +++ b/mpris2/playertestwidget.h @@ -45,6 +45,11 @@ namespace Mpris2 { void testSetPos(); void testOpenUri(); void Seeked(qint64 position); + void testSetLoopStatus(); + void testSetVolume(); + void testSetRate(); + void testShuffleOn(); + void testShuffleOff(); private slots: void propertiesChanged(const QStringList& properties); diff --git a/ui/playertest.ui b/ui/playertest.ui index f9bbd7f..15f7547 100644 --- a/ui/playertest.ui +++ b/ui/playertest.ui @@ -56,30 +56,73 @@ - + - Shuffle: + >>> - - - false - + + + + + true + + + + + + + Set + + + + + + + - <unknown> + Shuffle: - + + + + + + false + + + <unknown> + + + + + + + On + + + + + + + Off + + + + + + Volume: - + false @@ -89,14 +132,45 @@ - + + + + >>> + + + + + + + + + -9999.989999999999782 + + + 9999.989999999999782 + + + 0.050000000000000 + + + + + + + Set + + + + + + Maximum rate: - + false @@ -106,14 +180,14 @@ - + Minimum rate: - + false @@ -123,14 +197,14 @@ - + Rate: - + false @@ -140,14 +214,48 @@ - + + + + >>> + + + + + + + + + -9999.989999999999782 + + + 9999.989999999999782 + + + 0.250000000000000 + + + 1.000000000000000 + + + + + + + Set + + + + + + Last received position: - + false @@ -157,14 +265,14 @@ - + Predicted position: - + false @@ -174,14 +282,14 @@ - + Can control: - + false @@ -191,63 +299,82 @@ - + Can play: - + + + + false + + + <unknown> + + + + Can pause: - + + + + false + + + <unknown> + + + + Can go previous: - + + + + false + + + <unknown> + + + + Can go next: - - - - - - false - - - <unknown> - - - - - - - Next - - - - + + + + false + + + <unknown> + + - + Can seek: - + false @@ -257,83 +384,6 @@ - - - - - - false - - - <unknown> - - - - - - - Previous - - - - - - - - - - - false - - - <unknown> - - - - - - - Play - - - - - - - Stop - - - - - - - - - - - false - - - <unknown> - - - - - - - Pause - - - - - - - Play/Pause - - - - - @@ -356,6 +406,52 @@ + + + + + + Play + + + + + + + Pause + + + + + + + Play/Pause + + + + + + + Stop + + + + + + + Previous + + + + + + + Next + + + + + -- cgit v1.2.3