Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb34611' into 'master'
[usb-moded-qt5] Expose hidden modes list. Contributes to JB#34611



See merge request !1
  • Loading branch information
martinjones committed Apr 6, 2016
2 parents 0a4b8ff + 4a2b13e commit a21adc0
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpm/libusb-moded-qt5.spec
Expand Up @@ -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)
Expand Down
96 changes: 96 additions & 0 deletions src/qusbmoded.cpp
Expand Up @@ -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
{
Expand All @@ -48,6 +49,7 @@ class QUsbModed::Private
static const QString UsbModeKeyMode;

QStringList iSupportedModes;
QStringList iHiddenModes;
QString iConfigMode;
QString iCurrentMode;
QDBusConnection iBus;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand All @@ -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)
Expand Down Expand Up @@ -247,6 +287,36 @@ void QUsbModed::onGetModeRequestFinished(QDBusPendingCallWatcher* aCall)
setupCallFinished(USB_MODED_CALL_MODE_REQUEST);
}

void QUsbModed::onGetHiddenFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> 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; i<n; i++) {
QString mode(result.at(i).trimmed());
if (!modes.contains(mode)) modes.append(mode);
}
if (iPrivate->iHiddenModes != modes) {
iPrivate->iHiddenModes = modes;
Q_EMIT hiddenModesChanged();
}
}

void QUsbModed::updateSupportedModes(QString aModes)
{
const QStringList result = aModes.split(',', QString::SkipEmptyParts);
Expand Down Expand Up @@ -306,6 +376,26 @@ void QUsbModed::onSetConfigFinished(QDBusPendingCallWatcher* aCall)
aCall->deleteLater();
}

void QUsbModed::onHideModeFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
if (reply.isError()) {
DEBUG_(reply.error());
Q_EMIT hideModeFailed(reply.error().message());
}
aCall->deleteLater();
}

void QUsbModed::onUnhideModeFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
if (reply.isError()) {
DEBUG_(reply.error());
Q_EMIT unhideModeFailed(reply.error().message());
}
aCall->deleteLater();
}

void QUsbModed::onUsbStateChanged(QString aMode)
{
DEBUG_(aMode);
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/qusbmoded.h
Expand Up @@ -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)

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit a21adc0

Please sign in to comment.