diff options
Diffstat (limited to 'src')
11 files changed, 105 insertions, 131 deletions
diff --git a/src/ivicore/qivisearchandbrowsemodel.cpp b/src/ivicore/qivisearchandbrowsemodel.cpp index abf2061..ce28a5b 100644 --- a/src/ivicore/qivisearchandbrowsemodel.cpp +++ b/src/ivicore/qivisearchandbrowsemodel.cpp @@ -197,16 +197,6 @@ void QIviSearchAndBrowseModelPrivate::onDataChanged(const QUuid &identifier, con } } -void QIviSearchAndBrowseModelPrivate::onIndexOfCallResult(const QUuid &identifier, int callID, int index) -{ - if (identifier != m_identifier || !m_indexOfFunctorHash.contains(callID)) - return; - - QJSValue functor = m_indexOfFunctorHash.take(callID); - QJSValueList list = { QJSValue(index) }; - functor.call(list); -} - void QIviSearchAndBrowseModelPrivate::onFetchMoreThresholdReached() { Q_Q(QIviSearchAndBrowseModel); @@ -1205,6 +1195,8 @@ QIviSearchAndBrowseModel *QIviSearchAndBrowseModel::goForward(int i, NavigationT Insert the \a item at the position \a index. If the backend doesn't accept the provided item, this operation will end in a no op. + + The returned PendingReply notifies about when the action has been done or whether it failed. */ /*! @@ -1213,134 +1205,123 @@ QIviSearchAndBrowseModel *QIviSearchAndBrowseModel::goForward(int i, NavigationT Insert the \a variant at the position \a index. If the backend doesn't accept the provided item, this operation will end in a no op. + + The returned QIviPendingReply notifies about when the action has been done or whether it failed. */ -void QIviSearchAndBrowseModel::insert(int index, const QVariant &variant) +QIviPendingReply<void> QIviSearchAndBrowseModel::insert(int index, const QVariant &variant) { Q_D(QIviSearchAndBrowseModel); const QIviSearchAndBrowseModelItem *item = qtivi_gadgetFromVariant<QIviSearchAndBrowseModelItem>(this, variant); if (!item) - return; + return QIviPendingReply<void>::createFailedReply(); QIviSearchAndBrowseModelInterface *backend = d->searchBackend(); if (!backend) { qtivi_qmlOrCppWarning(this, QLatin1String("Can't insert itmes without a connected backend")); - return; + return QIviPendingReply<void>::createFailedReply(); } if (!d->m_capabilities.testFlag(SupportsInsert)) { qtivi_qmlOrCppWarning(this, QLatin1String("The backend doesn't support inserting items")); - return; + return QIviPendingReply<void>::createFailedReply(); } - backend->insert(d->m_identifier, d->m_contentType, index, item); + return backend->insert(d->m_identifier, d->m_contentType, index, item); } /*! \qmlmethod SearchAndBrowseModel::remove(int index) Removes the item at position \a index. + + The returned PendingReply notifies about when the action has been done or whether it failed. */ /*! \fn void QIviSearchAndBrowseModel::remove(int index) Removes the item at position \a index. + + The returned QIviPendingReply notifies about when the action has been done or whether it failed. */ -void QIviSearchAndBrowseModel::remove(int index) +QIviPendingReply<void> QIviSearchAndBrowseModel::remove(int index) { Q_D(QIviSearchAndBrowseModel); QIviSearchAndBrowseModelInterface *backend = d->searchBackend(); if (!backend) { qtivi_qmlOrCppWarning(this, QLatin1String("Can't remove items without a connected backend")); - return; + return QIviPendingReply<void>::createFailedReply(); } if (!d->m_capabilities.testFlag(SupportsRemove)) { qtivi_qmlOrCppWarning(this, QLatin1String("The backend doesn't support removing of items")); - return; + return QIviPendingReply<void>::createFailedReply(); } - backend->remove(d->m_identifier, d->m_contentType, index); + return backend->remove(d->m_identifier, d->m_contentType, index); } /*! \qmlmethod SearchAndBrowseModel::move(int cur_index, int new_index) Moves the item at position \a cur_index to the new position \a new_index. + + The returned PendingReply notifies about when the action has been done or whether it failed. */ /*! \fn void QIviSearchAndBrowseModel::move(int cur_index, int new_index) Moves the item at position \a cur_index to the new position \a new_index. + + The returned QIviPendingReply notifies about when the action has been done or whether it failed. */ -void QIviSearchAndBrowseModel::move(int cur_index, int new_index) +QIviPendingReply<void> QIviSearchAndBrowseModel::move(int cur_index, int new_index) { Q_D(QIviSearchAndBrowseModel); QIviSearchAndBrowseModelInterface *backend = d->searchBackend(); if (!backend) { qtivi_qmlOrCppWarning(this, QLatin1String("Can't move items without a connected backend")); - return; + return QIviPendingReply<void>::createFailedReply(); } if (!d->m_capabilities.testFlag(SupportsMove)) { qtivi_qmlOrCppWarning(this, QLatin1String("The backend doesn't support moving of items")); - return; + return QIviPendingReply<void>::createFailedReply(); } - backend->move(d->m_identifier, d->m_contentType, cur_index, new_index); + return backend->move(d->m_identifier, d->m_contentType, cur_index, new_index); } /*! - \qmlmethod SearchAndBrowseModel::indexOf(SearchAndBrowseModelItem item, object functor) + \qmlmethod SearchAndBrowseModel::indexOf(SearchAndBrowseModelItem item) - Determines the index of \a item in this model and calls the \a functor once the result is ready. - The result is passed as the first argument to the functor and is -1 if the item is not part of the list. + Determines the index of \a item in this model. - \code - model.indexOf(item, function (index) { - console.log("The index of item is: ", index) - }) - \endcode + The result is returned as a PendingReply. */ /*! - \fn void QIviSearchAndBrowseModel::indexOf(const QVariant &variant, const QJSValue &functor) + \fn void QIviSearchAndBrowseModel::indexOf(const QVariant &variant) - Determines the index of \a variant in this model and calls the \a functor once the result is ready. - The result is passed as the first argument to the functor and is -1 if the item is not part of the list. + Determines the index of \a item in this model. - \code - model.indexOf(item, function (index) { - console.log("The index of item is: ", index) - }) - \endcode + The result is returned as a QIviPendingReply. */ -void QIviSearchAndBrowseModel::indexOf(const QVariant &variant, const QJSValue &functor) +QIviPendingReply<int> QIviSearchAndBrowseModel::indexOf(const QVariant &variant) { Q_D(QIviSearchAndBrowseModel); const QIviSearchAndBrowseModelItem *item = qtivi_gadgetFromVariant<QIviSearchAndBrowseModelItem>(this, variant); if (!item) - return; - - if (!functor.isCallable()) { - qtivi_qmlOrCppWarning(this, QLatin1String("Provided functor is not callable")); - return; - } + return QIviPendingReply<int>::createFailedReply(); QIviSearchAndBrowseModelInterface *backend = d->searchBackend(); if (!backend) { qtivi_qmlOrCppWarning(this, QLatin1String("Can't get the index without a connected backend")); - return; - } - - int callID = backend->indexOf(d->m_identifier, d->m_contentType, item); - if (callID == -1) { - qtivi_qmlOrCppWarning(this, QLatin1String("An error happened while calling the backend")); - return; + return QIviPendingReply<int>::createFailedReply(); } - d->m_indexOfFunctorHash.insert(callID, functor); + return backend->indexOf(d->m_identifier, d->m_contentType, item); } /*! @@ -1450,9 +1431,6 @@ void QIviSearchAndBrowseModel::connectToServiceObject(QIviServiceObject *service d, &QIviSearchAndBrowseModelPrivate::onCountChanged); QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::dataChanged, d, &QIviSearchAndBrowseModelPrivate::onDataChanged); - QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::indexOfCallResult, - d, &QIviSearchAndBrowseModelPrivate::onIndexOfCallResult, - Qt::QueuedConnection); QIviAbstractFeatureListModel::connectToServiceObject(serviceObject); diff --git a/src/ivicore/qivisearchandbrowsemodel.h b/src/ivicore/qivisearchandbrowsemodel.h index cf201e8..30d478a 100644 --- a/src/ivicore/qivisearchandbrowsemodel.h +++ b/src/ivicore/qivisearchandbrowsemodel.h @@ -44,6 +44,7 @@ #include <QtIviCore/QIviAbstractFeatureListModel> #include <QtIviCore/QIviServiceObject> +#include <QtIviCore/QIviPendingReply> #include <QtQml/QJSValue> QT_BEGIN_NAMESPACE @@ -141,11 +142,10 @@ public: Q_INVOKABLE void goBack(); Q_INVOKABLE bool canGoForward(int index) const; Q_INVOKABLE QIviSearchAndBrowseModel *goForward(int index, QIviSearchAndBrowseModel::NavigationType navigationType); - Q_INVOKABLE void insert(int index, const QVariant &variant); - Q_INVOKABLE void remove(int index); - Q_INVOKABLE void move(int cur_index, int new_index); - //TODO add a C++ version for this, similar to QTimer::singleShot() - Q_INVOKABLE void indexOf(const QVariant &variant, const QJSValue &functor); + Q_INVOKABLE QIviPendingReply<void> insert(int index, const QVariant &variant); + Q_INVOKABLE QIviPendingReply<void> remove(int index); + Q_INVOKABLE QIviPendingReply<void> move(int cur_index, int new_index); + Q_INVOKABLE QIviPendingReply<int> indexOf(const QVariant &variant); Q_INVOKABLE void reload(); template <typename T> T at(int i) const { @@ -178,7 +178,6 @@ private: Q_PRIVATE_SLOT(d_func(), void onDataFetched(const QUuid &identifer, const QList<QVariant> &items, int start, bool moreAvailable)) Q_PRIVATE_SLOT(d_func(), void onCountChanged(const QUuid &identifier, int new_length)) Q_PRIVATE_SLOT(d_func(), void onDataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count)) - Q_PRIVATE_SLOT(d_func(), void onIndexOfCallResult(const QUuid &identifier, int callID, int index)) Q_PRIVATE_SLOT(d_func(), void onFetchMoreThresholdReached()) }; diff --git a/src/ivicore/qivisearchandbrowsemodel_p.h b/src/ivicore/qivisearchandbrowsemodel_p.h index 5a3b2df..eff2bc1 100644 --- a/src/ivicore/qivisearchandbrowsemodel_p.h +++ b/src/ivicore/qivisearchandbrowsemodel_p.h @@ -77,7 +77,6 @@ public: void onDataFetched(const QUuid &identifer, const QList<QVariant> &items, int start, bool moreAvailable); void onCountChanged(const QUuid &identifier, int new_length); void onDataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count); - void onIndexOfCallResult(const QUuid &identifier, int callID, int index); void onFetchMoreThresholdReached(); void resetModel(); void parseQuery(); @@ -111,7 +110,6 @@ public: QStringList m_availableContentTypes; bool m_canGoBack; QIviSearchAndBrowseModel::LoadingType m_loadingType; - QHash<int, QJSValue> m_indexOfFunctorHash; }; QT_END_NAMESPACE diff --git a/src/ivicore/qivisearchandbrowsemodelinterface.cpp b/src/ivicore/qivisearchandbrowsemodelinterface.cpp index 547073d..43f10dc 100644 --- a/src/ivicore/qivisearchandbrowsemodelinterface.cpp +++ b/src/ivicore/qivisearchandbrowsemodelinterface.cpp @@ -209,24 +209,9 @@ void QIviSearchAndBrowseModelInterface::registerContentType(const QMetaObject &o */ /*! - \fn int QIviSearchAndBrowseModelInterface::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) + \fn QIviSearchAndBrowseModelInterface::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) Determines the index of \a item in the model identified by \a identifier and \a type. - An id will be returned which identifies this call (-1 for an error, or not supported). The result is sent by emitting the indexOfCallResult() signal - - The following code shows and example usage: - \code - QVector<ExampleItem> list; - - ExampleItem item = *static_cast<const ExampleItem*>(item); - static int callID = 0; - - emit indexOfCallResult(identifier, callID, list.indexOf(item)); - - return callID++; - \endcode - - \sa indexOfCallResult() */ /*! @@ -282,14 +267,4 @@ void QIviSearchAndBrowseModelInterface::registerContentType(const QMetaObject &o \sa insert() remove() move() */ -/*! - \fn void QIviSearchAndBrowseModelInterface::indexOfCallResult(const QUuid &identifier, int callID, int index) - - This signal is emitted as a result of a call to indexOf() and returns the \a index of the requested item. - If the item is not part of the list -1 should be returned. The \a identifier and \a callID arguments are used to map this result to the matching - model and the call. - - \sa indexOf() -*/ - QT_END_NAMESPACE diff --git a/src/ivicore/qivisearchandbrowsemodelinterface.h b/src/ivicore/qivisearchandbrowsemodelinterface.h index 1381f45..ea023a4 100644 --- a/src/ivicore/qivisearchandbrowsemodelinterface.h +++ b/src/ivicore/qivisearchandbrowsemodelinterface.h @@ -74,17 +74,16 @@ public: virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) = 0; //Every Item has a id property which is filled by the backend implementation. virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) = 0; //Returns the new type identifier used for the next level. The identifier will stay the same for the following calls but the type might differ. - virtual void insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) = 0; - virtual void remove(const QUuid &identifier, const QString &type, int index) = 0; - virtual void move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) = 0; - virtual int indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) = 0; + virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) = 0; + virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) = 0; + virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) = 0; + virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) = 0; Q_SIGNALS: void supportedCapabilitiesChanged(const QUuid &identifier, QIviSearchAndBrowseModel::Capabilities capabilities); void countChanged(const QUuid &identifier, int newLength); // Emitted by the backend if it already knows the total count of items in the model (can be used by the dataChanged display method) void dataFetched(const QUuid &identifier, const QList<QVariant> &data, int start, bool moreAvailable); void dataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count); //start and count defines which data gets replace by the new data content. If data is empty the rows will be removed, if count is 0, the data will be added. - void indexOfCallResult(const QUuid &identifier, int callID, int index); protected: template <typename T> diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp index 6c17c76..5514c19 100644 --- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp +++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp @@ -347,34 +347,40 @@ QString SearchAndBrowseBackend::goForward(const QUuid &identifier, const QString return new_type; } -void SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(index) Q_UNUSED(item) + + return QIviPendingReply<void>::createFailedReply(); } -void SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) +QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(index) + + return QIviPendingReply<void>::createFailedReply(); } -void SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) +QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(currentIndex) Q_UNUSED(newIndex) + + return QIviPendingReply<void>::createFailedReply(); } -int SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(item) - return -1; + return QIviPendingReply<int>::createFailedReply(); } diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h index 7cb5704..234aee4 100644 --- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h +++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h @@ -81,10 +81,10 @@ public: virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override; virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override; - virtual void insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; - virtual void remove(const QUuid &identifier, const QString &type, int index) override; - virtual void move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; - virtual int indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override; + virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; + virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; private slots: void search(const QUuid &identifier, const QString &queryString, const QString &type, int start, int count); diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp index 96c8804..27aff61 100644 --- a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp +++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp @@ -125,34 +125,40 @@ QString UsbBrowseBackend::goForward(const QUuid &identifier, const QString &type return itemId; } -void UsbBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<void> UsbBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(index) Q_UNUSED(item) + + return QIviPendingReply<void>::createFailedReply(); } -void UsbBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) +QIviPendingReply<void> UsbBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(index) + + return QIviPendingReply<void>::createFailedReply(); } -void UsbBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) +QIviPendingReply<void> UsbBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(currentIndex) Q_UNUSED(newIndex) + + return QIviPendingReply<void>::createFailedReply(); } -int UsbBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<int> UsbBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) { Q_UNUSED(identifier) Q_UNUSED(type) Q_UNUSED(item) - return -1; + return QIviPendingReply<int>::createFailedReply(); } diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h index 8063ddf..ac975ce 100644 --- a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h +++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h @@ -58,10 +58,10 @@ public: virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override; virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override; - virtual void insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; - virtual void remove(const QUuid &identifier, const QString &type, int index) override; - virtual void move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; - virtual int indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override; + virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; + virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; private: QString m_rootFolder; diff --git a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp index 4f81e7f..9aea6d8 100644 --- a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp +++ b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp @@ -119,30 +119,38 @@ QString SearchAndBrowseBackend::goForward(const QUuid &identifier, const QString return QString(); } -void SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) { if (type != "presets" || item->type() != "amfmtunerstation") - return; + return QIviPendingReply<void>::createFailedReply(); const QIviAmFmTunerStation &station = *static_cast<const QIviAmFmTunerStation*>(item); m_presets.insert(index, station); QVariantList stations = { QVariant::fromValue(station) }; emit dataChanged(identifier, stations, index, 0); + + QIviPendingReply<void> reply; + reply.setSuccess(); + return reply; } -void SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) +QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index) { if (type != "presets") - return; + return QIviPendingReply<void>::createFailedReply(); m_presets.removeAt(index); emit dataChanged(identifier, QVariantList(), index, 1); + + QIviPendingReply<void> reply; + reply.setSuccess(); + return reply; } -void SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) +QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) { if (type != "presets") - return; + return QIviPendingReply<void>::createFailedReply(); int min = qMin(currentIndex, newIndex); int max = qMax(currentIndex, newIndex); @@ -153,12 +161,18 @@ void SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, stations.append(QVariant::fromValue(m_presets.at(i))); emit dataChanged(identifier, stations, min, max - min + 1); + + QIviPendingReply<void> reply; + reply.setSuccess(); + return reply; } -int SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) +QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) { + Q_UNUSED(identifier) + if (item->type() != "amfmtunerstation") - return -1; + return QIviPendingReply<int>::createFailedReply(); QVector<QIviAmFmTunerStation> stations; @@ -167,12 +181,11 @@ int SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type else if (type == "presets") stations = m_presets; else - return -1; + return QIviPendingReply<int>::createFailedReply(); QIviAmFmTunerStation station = *static_cast<const QIviAmFmTunerStation*>(item); - static int callID = 0; - - emit indexOfCallResult(identifier, callID, stations.indexOf(station)); - return callID++; + QIviPendingReply<int> reply; + reply.setSuccess(stations.indexOf(station)); + return reply; } diff --git a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h index 4eec6f2..6010497 100644 --- a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h +++ b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h @@ -61,10 +61,10 @@ public: virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override; virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override; - virtual void insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; - virtual void remove(const QUuid &identifier, const QString &type, int index) override; - virtual void move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; - virtual int indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviSearchAndBrowseModelItem *item) override; + virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override; + virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override; + virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviSearchAndBrowseModelItem *item) override; private: AmFmTunerBackend *m_tunerBackend; |