diff --git a/rpm/libusb-moded-qt5.spec b/rpm/libusb-moded-qt5.spec index cda77ad..aa48eaa 100644 --- a/rpm/libusb-moded-qt5.spec +++ b/rpm/libusb-moded-qt5.spec @@ -10,7 +10,7 @@ Source0: %{name}-%{version}.tar.bz2 Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -Requires: usb-moded > 0.82 +Requires: usb-moded >= 0.85.4 BuildRequires: pkgconfig(Qt5Core) BuildRequires: pkgconfig(Qt5DBus) BuildRequires: pkgconfig(usb_moded) diff --git a/src/qusbmoded.cpp b/src/qusbmoded.cpp index 76ef4a1..762fe3e 100644 --- a/src/qusbmoded.cpp +++ b/src/qusbmoded.cpp @@ -40,6 +40,7 @@ #define USB_MODED_CALL_GET_MODES (0x01) #define USB_MODED_CALL_GET_CONFIG (0x02) #define USB_MODED_CALL_MODE_REQUEST (0x04) +#define USB_MODED_CALL_GET_HIDDEN (0x08) class QUsbModed::Private { @@ -48,6 +49,7 @@ class QUsbModed::Private static const QString UsbModeKeyMode; QStringList iSupportedModes; + QStringList iHiddenModes; QString iConfigMode; QString iCurrentMode; QDBusConnection iBus; @@ -97,6 +99,11 @@ QStringList QUsbModed::supportedModes() const return iPrivate->iSupportedModes; } +QStringList QUsbModed::hiddenModes() const +{ + return iPrivate->iHiddenModes; +} + bool QUsbModed::available() const { return iPrivate->iAvailable; @@ -136,6 +143,30 @@ bool QUsbModed::setConfigMode(QString aMode) return false; } +bool QUsbModed::hideMode(QString mode) +{ + if (iPrivate->iInterface) { + connect(new QDBusPendingCallWatcher( + iPrivate->iInterface->hide_mode(mode), iPrivate->iInterface), + SIGNAL(finished(QDBusPendingCallWatcher*)), + SLOT(onHideModeFinished(QDBusPendingCallWatcher*))); + return true; + } + return false; +} + +bool QUsbModed::unhideMode(QString mode) +{ + if (iPrivate->iInterface) { + connect(new QDBusPendingCallWatcher( + iPrivate->iInterface->unhide_mode(mode), iPrivate->iInterface), + SIGNAL(finished(QDBusPendingCallWatcher*)), + SLOT(onUnhideModeFinished(QDBusPendingCallWatcher*))); + return true; + } + return false; +} + void QUsbModed::onServiceRegistered(QString aService) { DEBUG_(aService); @@ -170,6 +201,9 @@ void QUsbModed::setup() connect(iPrivate->iInterface, SIGNAL(sig_usb_supported_modes_ind(QString)), SLOT(onUsbSupportedModesChanged(QString))); + connect(iPrivate->iInterface, + SIGNAL(sig_usb_hidden_modes_ind(QString)), + SLOT(onUsbHiddenModesChanged(QString))); connect(iPrivate->iInterface, SIGNAL(sig_usb_state_error_ind(QString)), SIGNAL(usbStateError(QString))); @@ -192,6 +226,12 @@ void QUsbModed::setup() iPrivate->iInterface->mode_request(), iPrivate->iInterface), SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onGetModeRequestFinished(QDBusPendingCallWatcher*))); + + iPrivate->iPendingCalls |= USB_MODED_CALL_GET_HIDDEN; + connect(new QDBusPendingCallWatcher( + iPrivate->iInterface->get_hidden(), iPrivate->iInterface), + SIGNAL(finished(QDBusPendingCallWatcher*)), + SLOT(onGetHiddenFinished(QDBusPendingCallWatcher*))); } void QUsbModed::onGetModesFinished(QDBusPendingCallWatcher* aCall) @@ -247,6 +287,36 @@ void QUsbModed::onGetModeRequestFinished(QDBusPendingCallWatcher* aCall) setupCallFinished(USB_MODED_CALL_MODE_REQUEST); } +void QUsbModed::onGetHiddenFinished(QDBusPendingCallWatcher* aCall) +{ + QDBusPendingReply reply(*aCall); + QString modes; + if (!reply.isError()) { + modes = reply.value(); + DEBUG_(modes); + } else { + DEBUG_(reply.error()); + } + updateHiddenModes(modes); + aCall->deleteLater(); + setupCallFinished(USB_MODED_CALL_GET_HIDDEN); +} + +void QUsbModed::updateHiddenModes(QString aModes) +{ + const QStringList result = aModes.split(',', QString::SkipEmptyParts); + const int n = result.count(); + QStringList modes; + for (int i=0; iiHiddenModes != modes) { + iPrivate->iHiddenModes = modes; + Q_EMIT hiddenModesChanged(); + } +} + void QUsbModed::updateSupportedModes(QString aModes) { const QStringList result = aModes.split(',', QString::SkipEmptyParts); @@ -306,6 +376,26 @@ void QUsbModed::onSetConfigFinished(QDBusPendingCallWatcher* aCall) aCall->deleteLater(); } +void QUsbModed::onHideModeFinished(QDBusPendingCallWatcher* aCall) +{ + QDBusPendingReply reply(*aCall); + if (reply.isError()) { + DEBUG_(reply.error()); + Q_EMIT hideModeFailed(reply.error().message()); + } + aCall->deleteLater(); +} + +void QUsbModed::onUnhideModeFinished(QDBusPendingCallWatcher* aCall) +{ + QDBusPendingReply reply(*aCall); + if (reply.isError()) { + DEBUG_(reply.error()); + Q_EMIT unhideModeFailed(reply.error().message()); + } + aCall->deleteLater(); +} + void QUsbModed::onUsbStateChanged(QString aMode) { DEBUG_(aMode); @@ -321,6 +411,12 @@ void QUsbModed::onUsbSupportedModesChanged(QString aModes) updateSupportedModes(aModes); } +void QUsbModed::onUsbHiddenModesChanged(QString modes) +{ + DEBUG_(modes); + updateHiddenModes(modes); +} + void QUsbModed::onUsbConfigChanged(QString aSect, QString aKey, QString aVal) { DEBUG_(aSect << aKey << aVal); diff --git a/src/qusbmoded.h b/src/qusbmoded.h index 8cf0624..dfc33fc 100644 --- a/src/qusbmoded.h +++ b/src/qusbmoded.h @@ -45,6 +45,7 @@ class QUSBMODED_EXPORT QUsbModed : public QUsbMode Q_OBJECT Q_PROPERTY(bool available READ available NOTIFY availableChanged) Q_PROPERTY(QStringList supportedModes READ supportedModes NOTIFY supportedModesChanged) + Q_PROPERTY(QStringList hiddenModes READ hiddenModes NOTIFY hiddenModesChanged) Q_PROPERTY(QString currentMode READ currentMode WRITE setCurrentMode NOTIFY currentModeChanged) Q_PROPERTY(QString configMode READ configMode WRITE setConfigMode NOTIFY configModeChanged) @@ -60,12 +61,21 @@ class QUSBMODED_EXPORT QUsbModed : public QUsbMode bool setCurrentMode(QString mode); bool setConfigMode(QString mode); + QStringList hiddenModes() const; + +public Q_SLOTS: + bool hideMode(QString mode); + bool unhideMode(QString mode); + Q_SIGNALS: void availableChanged(); void supportedModesChanged(); void currentModeChanged(); void configModeChanged(); void usbStateError(QString error); + void hiddenModesChanged(); + void hideModeFailed(QString mode); + void unhideModeFailed(QString mode); private Q_SLOTS: void onServiceRegistered(QString service); @@ -75,14 +85,19 @@ private Q_SLOTS: void onGetModeRequestFinished(QDBusPendingCallWatcher* call); void onSetModeFinished(QDBusPendingCallWatcher* call); void onSetConfigFinished(QDBusPendingCallWatcher* call); + void onHideModeFinished(QDBusPendingCallWatcher* call); + void onUnhideModeFinished(QDBusPendingCallWatcher* call); + void onGetHiddenFinished(QDBusPendingCallWatcher* call); void onUsbConfigChanged(QString section, QString key, QString value); void onUsbStateChanged(QString mode); void onUsbSupportedModesChanged(QString modes); + void onUsbHiddenModesChanged(QString modes); private: void setup(); void setupCallFinished(int callId); void updateSupportedModes(QString modes); + void updateHiddenModes(QString modes); private: class Private;