diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2011-11-09 01:43:21 +0000 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2011-11-09 01:43:21 +0000 |
commit | 832d6c90147ca3d176a1c8afc1f4380594898b5e (patch) | |
tree | 8566a390701c9c9fdddb9d6ae65f2a64721e1fa5 | |
parent | 1df042375792e6d07794d5ea382c1f98bc2fd2b6 (diff) |
Add widgets for setting rw property values
-rw-r--r-- | mpris2/interfacetest.cpp | 100 | ||||
-rw-r--r-- | mpris2/interfacetest.h | 10 | ||||
-rw-r--r-- | mpris2/playerinterfacetest.cpp | 30 | ||||
-rw-r--r-- | mpris2/playerinterfacetest.h | 4 | ||||
-rw-r--r-- | mpris2/playertestwidget.cpp | 37 | ||||
-rw-r--r-- | mpris2/playertestwidget.h | 5 | ||||
-rw-r--r-- | 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<void> propsReply = propsIface->call("Set", iface->interface(), propName, QVariant::fromValue<QDBusVariant>(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 <QObject> @@ -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 @@ </widget> </item> <item row="2" column="0"> - <widget class="QLabel" name="label_3"> + <widget class="QLabel" name="label_17"> <property name="text"> - <string>Shuffle:</string> + <string>>>></string> </property> </widget> </item> <item row="2" column="1"> - <widget class="QLabel" name="shuffleLbl"> - <property name="enabled"> - <bool>false</bool> - </property> + <layout class="QHBoxLayout" name="horizontalLayout_10"> + <item> + <widget class="QComboBox" name="loopStatusCombo"> + <property name="editable"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="loopStatusSetBtn"> + <property name="text"> + <string>Set</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_3"> <property name="text"> - <string><unknown></string> + <string>Shuffle:</string> </property> </widget> </item> - <item row="3" column="0"> + <item row="3" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="QLabel" name="shuffleLbl"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string><unknown></string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="shuffleOnBtn"> + <property name="text"> + <string>On</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="shuffleOffBtn"> + <property name="text"> + <string>Off</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="4" column="0"> <widget class="QLabel" name="label_4"> <property name="text"> <string>Volume:</string> </property> </widget> </item> - <item row="3" column="1"> + <item row="4" column="1"> <widget class="QLabel" name="volumeLbl"> <property name="enabled"> <bool>false</bool> @@ -89,14 +132,45 @@ </property> </widget> </item> - <item row="4" column="0"> + <item row="5" column="0"> + <widget class="QLabel" name="label_19"> + <property name="text"> + <string>>>></string> + </property> + </widget> + </item> + <item row="5" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_12"> + <item> + <widget class="QDoubleSpinBox" name="volumeSpinBox"> + <property name="minimum"> + <double>-9999.989999999999782</double> + </property> + <property name="maximum"> + <double>9999.989999999999782</double> + </property> + <property name="singleStep"> + <double>0.050000000000000</double> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="volumeSetBtn"> + <property name="text"> + <string>Set</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="6" column="0"> <widget class="QLabel" name="label_5"> <property name="text"> <string>Maximum rate:</string> </property> </widget> </item> - <item row="4" column="1"> + <item row="6" column="1"> <widget class="QLabel" name="maxRateLbl"> <property name="enabled"> <bool>false</bool> @@ -106,14 +180,14 @@ </property> </widget> </item> - <item row="5" column="0"> + <item row="7" column="0"> <widget class="QLabel" name="label_6"> <property name="text"> <string>Minimum rate:</string> </property> </widget> </item> - <item row="5" column="1"> + <item row="7" column="1"> <widget class="QLabel" name="minRateLbl"> <property name="enabled"> <bool>false</bool> @@ -123,14 +197,14 @@ </property> </widget> </item> - <item row="6" column="0"> + <item row="8" column="0"> <widget class="QLabel" name="label_7"> <property name="text"> <string>Rate:</string> </property> </widget> </item> - <item row="6" column="1"> + <item row="8" column="1"> <widget class="QLabel" name="rateLbl"> <property name="enabled"> <bool>false</bool> @@ -140,14 +214,48 @@ </property> </widget> </item> - <item row="7" column="0"> + <item row="9" column="0"> + <widget class="QLabel" name="label_20"> + <property name="text"> + <string>>>></string> + </property> + </widget> + </item> + <item row="9" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_13"> + <item> + <widget class="QDoubleSpinBox" name="rateSpinBox"> + <property name="minimum"> + <double>-9999.989999999999782</double> + </property> + <property name="maximum"> + <double>9999.989999999999782</double> + </property> + <property name="singleStep"> + <double>0.250000000000000</double> + </property> + <property name="value"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="rateSetBtn"> + <property name="text"> + <string>Set</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="10" column="0"> <widget class="QLabel" name="label_8"> <property name="text"> <string>Last received position:</string> </property> </widget> </item> - <item row="7" column="1"> + <item row="10" column="1"> <widget class="QLabel" name="lastKnownPosLbl"> <property name="enabled"> <bool>false</bool> @@ -157,14 +265,14 @@ </property> </widget> </item> - <item row="8" column="0"> + <item row="11" column="0"> <widget class="QLabel" name="label_9"> <property name="text"> <string>Predicted position:</string> </property> </widget> </item> - <item row="8" column="1"> + <item row="11" column="1"> <widget class="QLabel" name="estPosLbl"> <property name="enabled"> <bool>false</bool> @@ -174,14 +282,14 @@ </property> </widget> </item> - <item row="9" column="0"> + <item row="12" column="0"> <widget class="QLabel" name="label_10"> <property name="text"> <string>Can control:</string> </property> </widget> </item> - <item row="9" column="1"> + <item row="12" column="1"> <widget class="QLabel" name="canControlLbl"> <property name="enabled"> <bool>false</bool> @@ -191,63 +299,82 @@ </property> </widget> </item> - <item row="10" column="0"> + <item row="13" column="0"> <widget class="QLabel" name="label_11"> <property name="text"> <string>Can play:</string> </property> </widget> </item> - <item row="11" column="0"> + <item row="13" column="1"> + <widget class="QLabel" name="canPlayLbl"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string><unknown></string> + </property> + </widget> + </item> + <item row="14" column="0"> <widget class="QLabel" name="label_12"> <property name="text"> <string>Can pause:</string> </property> </widget> </item> - <item row="12" column="0"> + <item row="14" column="1"> + <widget class="QLabel" name="canPauseLbl"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string><unknown></string> + </property> + </widget> + </item> + <item row="15" column="0"> <widget class="QLabel" name="label_13"> <property name="text"> <string>Can go previous:</string> </property> </widget> </item> - <item row="13" column="0"> + <item row="15" column="1"> + <widget class="QLabel" name="canGoPrevLbl"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string><unknown></string> + </property> + </widget> + </item> + <item row="16" column="0"> <widget class="QLabel" name="label_14"> <property name="text"> <string>Can go next:</string> </property> </widget> </item> - <item row="13" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QLabel" name="canGoNextLbl"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string><unknown></string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="nextBtn"> - <property name="text"> - <string>Next</string> - </property> - </widget> - </item> - </layout> + <item row="16" column="1"> + <widget class="QLabel" name="canGoNextLbl"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string><unknown></string> + </property> + </widget> </item> - <item row="14" column="0"> + <item row="17" column="0"> <widget class="QLabel" name="label_15"> <property name="text"> <string>Can seek:</string> </property> </widget> </item> - <item row="14" column="1"> + <item row="17" column="1"> <widget class="QLabel" name="canSeekLbl"> <property name="enabled"> <bool>false</bool> @@ -257,83 +384,6 @@ </property> </widget> </item> - <item row="12" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLabel" name="canGoPrevLbl"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string><unknown></string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="prevBtn"> - <property name="text"> - <string>Previous</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="10" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QLabel" name="canPlayLbl"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string><unknown></string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="playBtn"> - <property name="text"> - <string>Play</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="stopBtn"> - <property name="text"> - <string>Stop</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="11" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_5"> - <item> - <widget class="QLabel" name="canPauseLbl"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string><unknown></string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pauseBtn"> - <property name="text"> - <string>Pause</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="playPauseBtn"> - <property name="text"> - <string>Play/Pause</string> - </property> - </widget> - </item> - </layout> - </item> </layout> </item> <item> @@ -357,6 +407,52 @@ </layout> </item> <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QPushButton" name="playBtn"> + <property name="text"> + <string>Play</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pauseBtn"> + <property name="text"> + <string>Pause</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="playPauseBtn"> + <property name="text"> + <string>Play/Pause</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="stopBtn"> + <property name="text"> + <string>Stop</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="prevBtn"> + <property name="text"> + <string>Previous</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="nextBtn"> + <property name="text"> + <string>Next</string> + </property> + </widget> + </item> + </layout> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> <widget class="QLineEdit" name="openUriEdit"/> |