Commit 3b3406e9 authored by Andrew den Exter's avatar Andrew den Exter

[usb] Add api for the available modes property. Contributes to JB#33745

parent 97d8c03e
......@@ -41,6 +41,7 @@
#define USB_MODED_CALL_GET_CONFIG (0x02)
#define USB_MODED_CALL_MODE_REQUEST (0x04)
#define USB_MODED_CALL_GET_HIDDEN (0x08)
#define USB_MODED_CALL_GET_AVAILABLE_MODES (0x10)
class QUsbModed::Private
{
......@@ -49,6 +50,7 @@ public:
static const QString UsbModeKeyMode;
QStringList iSupportedModes;
QStringList iAvailableModes;
QStringList iHiddenModes;
QString iConfigMode;
QString iCurrentMode;
......@@ -99,6 +101,11 @@ QStringList QUsbModed::supportedModes() const
return iPrivate->iSupportedModes;
}
QStringList QUsbModed::availableModes() const
{
return iPrivate->iAvailableModes;
}
QStringList QUsbModed::hiddenModes() const
{
return iPrivate->iHiddenModes;
......@@ -201,6 +208,10 @@ void QUsbModed::setup()
connect(iPrivate->iInterface,
SIGNAL(sig_usb_supported_modes_ind(QString)),
SLOT(onUsbSupportedModesChanged(QString)));
connect(iPrivate->iInterface,
&QUsbModedInterface::sig_usb_available_modes_ind,
this,
&QUsbModed::updateAvailableModes);
connect(iPrivate->iInterface,
SIGNAL(sig_usb_hidden_modes_ind(QString)),
SLOT(onUsbHiddenModesChanged(QString)));
......@@ -215,6 +226,13 @@ void QUsbModed::setup()
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(onGetModesFinished(QDBusPendingCallWatcher*)));
iPrivate->iPendingCalls |= USB_MODED_CALL_GET_AVAILABLE_MODES;
connect(new QDBusPendingCallWatcher(
iPrivate->iInterface->get_available_modes(), iPrivate->iInterface),
&QDBusPendingCallWatcher::finished,
this,
&QUsbModed::onGetAvailableModesFinished);
iPrivate->iPendingCalls |= USB_MODED_CALL_GET_CONFIG;
connect(new QDBusPendingCallWatcher(
iPrivate->iInterface->get_config(), iPrivate->iInterface),
......@@ -249,6 +267,21 @@ void QUsbModed::onGetModesFinished(QDBusPendingCallWatcher* aCall)
setupCallFinished(USB_MODED_CALL_GET_MODES);
}
void QUsbModed::onGetAvailableModesFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
QString modes;
if (!reply.isError()) {
modes = reply.value();
DEBUG_(modes);
} else {
DEBUG_(reply.error());
}
updateAvailableModes(modes);
aCall->deleteLater();
setupCallFinished(USB_MODED_CALL_GET_AVAILABLE_MODES);
}
void QUsbModed::onGetConfigFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
......@@ -332,6 +365,21 @@ void QUsbModed::updateSupportedModes(QString aModes)
}
}
void QUsbModed::updateAvailableModes(const 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->iAvailableModes != modes) {
iPrivate->iAvailableModes = modes;
Q_EMIT availableModesChanged();
}
}
void QUsbModed::setupCallFinished(int aCallId)
{
ASSERT_(iPrivate->iPendingCalls & aCallId);
......
......@@ -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 availableModes READ availableModes NOTIFY availableModesChanged)
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)
......@@ -55,6 +56,7 @@ public:
bool available() const;
QStringList supportedModes() const;
QStringList availableModes() const;
QString currentMode() const;
QString configMode() const;
......@@ -70,6 +72,7 @@ public Q_SLOTS:
Q_SIGNALS:
void availableChanged();
void supportedModesChanged();
void availableModesChanged();
void currentModeChanged();
void configModeChanged();
void usbStateError(QString error);
......@@ -81,6 +84,7 @@ private Q_SLOTS:
void onServiceRegistered(QString service);
void onServiceUnregistered(QString service);
void onGetModesFinished(QDBusPendingCallWatcher* call);
void onGetAvailableModesFinished(QDBusPendingCallWatcher *call);
void onGetConfigFinished(QDBusPendingCallWatcher* call);
void onGetModeRequestFinished(QDBusPendingCallWatcher* call);
void onSetModeFinished(QDBusPendingCallWatcher* call);
......@@ -97,6 +101,7 @@ private:
void setup();
void setupCallFinished(int callId);
void updateSupportedModes(QString modes);
void updateAvailableModes(const QString &modes);
void updateHiddenModes(QString modes);
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment