diff options
author | Robert Griebl <robert.griebl@qt.io> | 2019-10-13 16:56:51 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2019-10-28 14:11:42 +0100 |
commit | 495cc72c005cbb7796e557b0995f130c1d128a7b (patch) | |
tree | 9266c35d1b5851cd4b88b1856f425df0f1ca7d34 /src/manager-lib | |
parent | 0a1cccfccd8f76014bc697c5c9006c5ebb9723e8 (diff) | |
download | qtapplicationmanager-495cc72c005cbb7796e557b0995f130c1d128a7b.tar.gz |
Change intent implementation to better fit new architecture
- IntentServer is now a list model as all the other singletons.
- IntentModel is the companion filter model for the IntentServer, just like
the ApplicationModel is for the ApplicationManager
- Intent is now a Q_OBJECT instead of a Q_GADGET
Change-Id: Ifead097c543fb00b08ab21210e4526a6f65ba167
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'src/manager-lib')
-rw-r--r-- | src/manager-lib/applicationmanager.cpp | 16 | ||||
-rw-r--r-- | src/manager-lib/applicationmanager.h | 1 | ||||
-rw-r--r-- | src/manager-lib/applicationmodel.cpp | 42 | ||||
-rw-r--r-- | src/manager-lib/applicationmodel.h | 5 | ||||
-rw-r--r-- | src/manager-lib/intentaminterface.cpp | 2 |
5 files changed, 58 insertions, 8 deletions
diff --git a/src/manager-lib/applicationmanager.cpp b/src/manager-lib/applicationmanager.cpp index c5cea56d..35eb1c65 100644 --- a/src/manager-lib/applicationmanager.cpp +++ b/src/manager-lib/applicationmanager.cpp @@ -1318,9 +1318,8 @@ Application *ApplicationManager::application(const QString &id) const /*! \qmlmethod int ApplicationManager::indexOfApplication(string id) - Maps the application \a id to its position within the model. - - Returns \c -1 if the specified \a id is invalid. + Maps the application corresponding to the given \a id to its position within the model. Returns + \c -1 if the specified \a id is invalid. */ int ApplicationManager::indexOfApplication(const QString &id) const { @@ -1332,6 +1331,17 @@ int ApplicationManager::indexOfApplication(const QString &id) const } /*! + \qmlmethod int ApplicationManager::indexOfApplication(ApplicationObject application) + + Maps the \a application to its position within this model. Returns \c -1 if the specified + application is invalid. +*/ +int ApplicationManager::indexOfApplication(Application *application) const +{ + return d->apps.indexOf(application); +} + +/*! \qmlmethod list<string> ApplicationManager::applicationIds() Returns a list of all available application ids. This can be used to further query for specific diff --git a/src/manager-lib/applicationmanager.h b/src/manager-lib/applicationmanager.h index 9835d126..d7d8f0fa 100644 --- a/src/manager-lib/applicationmanager.h +++ b/src/manager-lib/applicationmanager.h @@ -136,6 +136,7 @@ public: Q_INVOKABLE Application *application(int index) const; Q_INVOKABLE Application *application(const QString &id) const; Q_INVOKABLE int indexOfApplication(const QString &id) const; + Q_INVOKABLE int indexOfApplication(Application *application) const; Q_INVOKABLE void acknowledgeOpenUrlRequest(const QString &requestId, const QString &appId); Q_INVOKABLE void rejectOpenUrlRequest(const QString &requestId); diff --git a/src/manager-lib/applicationmodel.cpp b/src/manager-lib/applicationmodel.cpp index c697087d..4deed932 100644 --- a/src/manager-lib/applicationmodel.cpp +++ b/src/manager-lib/applicationmodel.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2019 Luxoft Sweden AB ** Copyright (C) 2018 Pelagicore AG ** Contact: https://www.qt.io/licensing/ @@ -42,10 +43,12 @@ #include <QQmlContext> #include <QQmlEngine> +#include <QQmlInfo> #include <QJSEngine> #include <QJSValueList> #include "global.h" +#include "logging.h" #include "applicationmanager.h" #include "applicationmodel.h" #include "application.h" @@ -105,6 +108,9 @@ If the application passed should be included in this model, then the function must return \c true; \c false otherwise. + If you need no filtering at all, you should set this property to an undefined (the default) or + null value. + \note Whenever this function is changed, the filter is reevaluated. However, dynamic properties used in this function, like \c isRunning, don't trigger a reevaluation when those properties change. Changes in the source model are reflected. Since the type is derived from @@ -120,6 +126,9 @@ application should have a smaller index in this model than the second, the function must return \c true; \c false otherwise. + If you need no sorting at all, you should set this property to an undefined (the default) or + null value. + \note Whenever this function is changed, the model is sorted. However, dynamic properties used in this function, like \c isRunning, don't trigge a sort when when those properties change. Changes in the source model are reflected. Since the type is derived from @@ -140,8 +149,9 @@ public: }; -ApplicationModel::ApplicationModel() - : d(new ApplicationModelPrivate()) +ApplicationModel::ApplicationModel(QObject *parent) + : QSortFilterProxyModel(parent) + , d(new ApplicationModelPrivate()) { setSourceModel(ApplicationManager::instance()); @@ -162,6 +172,8 @@ bool ApplicationModel::filterAcceptsRow(int source_row, const QModelIndex &sourc if (!d->m_engine) d->m_engine = getJSEngine(); + if (!d->m_engine) + qCWarning(LogSystem) << "ApplicationModel can't filter without a JavaScript engine"; if (d->m_engine && d->m_filterFunction.isCallable()) { const QObject *app = ApplicationManager::instance()->application(source_row); @@ -176,6 +188,8 @@ bool ApplicationModel::lessThan(const QModelIndex &source_left, const QModelInde { if (!d->m_engine) d->m_engine = getJSEngine(); + if (!d->m_engine) + qCWarning(LogSystem) << "ApplicationModel can't sort without a JavaScript engine"; if (d->m_engine && d->m_sortFunction.isCallable()) { const QObject *app1 = ApplicationManager::instance()->application(source_left.row()); @@ -195,6 +209,10 @@ QJSValue ApplicationModel::filterFunction() const void ApplicationModel::setFilterFunction(const QJSValue &callback) { + if (!callback.isCallable() && !callback.isNull() && !callback.isUndefined()) { + qmlWarning(this) << "The filterFunction property of ApplicationModel needs to be either " + "callable, or undefined/null to clear it."; + } if (!callback.equals(d->m_filterFunction)) { d->m_filterFunction = callback; emit filterFunctionChanged(); @@ -209,6 +227,10 @@ QJSValue ApplicationModel::sortFunction() const void ApplicationModel::setSortFunction(const QJSValue &callback) { + if (!callback.isCallable() && !callback.isNull() && !callback.isUndefined()) { + qmlWarning(this) << "The sortFunction property of ApplicationModel needs to be either " + "callable, or undefined/null to clear it."; + } if (!callback.equals(d->m_sortFunction)) { d->m_sortFunction = callback; emit sortFunctionChanged(); @@ -220,8 +242,8 @@ void ApplicationModel::setSortFunction(const QJSValue &callback) /*! \qmlmethod int ApplicationModel::indexOfApplication(string id) - Maps the application \a id to its position within this model. Returns \c -1 if the specified - \a id is invalid, or not part of this model. + Maps the application corresponding to the given \a id to its position within this model. Returns + \c -1 if the specified application is invalid, or not part of this model. */ int ApplicationModel::indexOfApplication(const QString &id) const { @@ -230,6 +252,18 @@ int ApplicationModel::indexOfApplication(const QString &id) const } /*! + \qmlmethod int ApplicationModel::indexOfApplication(ApplicationObject application) + + Maps the \a application to its position within this model. Returns \c -1 if the specified + application is invalid, or not part of this model. +*/ +int ApplicationModel::indexOfApplication(Application *application) const +{ + int idx = ApplicationManager::instance()->indexOfApplication(application); + return idx != -1 ? mapFromSource(idx) : idx; +} + +/*! \qmlmethod int ApplicationModel::mapToSource(int index) Maps an application's \a index in this model to the corresponding index in the diff --git a/src/manager-lib/applicationmodel.h b/src/manager-lib/applicationmodel.h index 1ec1d503..6d0ef279 100644 --- a/src/manager-lib/applicationmodel.h +++ b/src/manager-lib/applicationmodel.h @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2019 Luxoft Sweden AB ** Copyright (C) 2018 Pelagicore AG ** Contact: https://www.qt.io/licensing/ @@ -51,6 +52,7 @@ QT_FORWARD_DECLARE_CLASS(QJSEngine); QT_BEGIN_NAMESPACE_AM class ApplicationModelPrivate; +class Application; class ApplicationModel : public QSortFilterProxyModel { @@ -62,7 +64,7 @@ class ApplicationModel : public QSortFilterProxyModel Q_PROPERTY(QJSValue sortFunction READ sortFunction WRITE setSortFunction NOTIFY sortFunctionChanged) public: - ApplicationModel(); + ApplicationModel(QObject *parent = nullptr); int count() const; @@ -73,6 +75,7 @@ public: void setSortFunction(const QJSValue &callback); Q_INVOKABLE int indexOfApplication(const QString &id) const; + Q_INVOKABLE int indexOfApplication(Application *application) const; Q_INVOKABLE int mapToSource(int ourIndex) const; Q_INVOKABLE int mapFromSource(int sourceIndex) const; diff --git a/src/manager-lib/intentaminterface.cpp b/src/manager-lib/intentaminterface.cpp index fe1ea01c..d8bf21aa 100644 --- a/src/manager-lib/intentaminterface.cpp +++ b/src/manager-lib/intentaminterface.cpp @@ -410,6 +410,7 @@ IntentServerInProcessIpcConnection *IntentServerInProcessIpcConnection::createSy { auto ipcConnection = create(nullptr, iface); ipcConnection->m_isSystemUi = true; + ipcConnection->setParent(iface); return ipcConnection; } @@ -519,6 +520,7 @@ void IntentServerDBusIpcConnection::replyFromApplication(const QString &requestI convertFromDBusVariant(result).toMap()); } + #endif // defined(AM_MULTI_PROCESS) QT_END_NAMESPACE_AM |