summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2022-12-13 17:41:49 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-01-24 16:34:55 +0000
commitf37d3f52f5b68df716dccdc61343db1facf8778b (patch)
treeaa7115591d1dfa1f7ed466f7d1769651756bad3a
parentc30347c25c88b449ae6d48ba1c991c246112d29b (diff)
Add QIfConfiguration based settings to qtifmedia
* All feature classes use "qtifmedia" as default configurationId * In addition to control the simulation using env variables settings can now be passed as serviceSettings * Adds a way to set and change the connectionUrl for every instance within the qtifmedia_qtro backend. * If the connectionUrl changes the QtRO node will be reconnecting to the new url * Adds a setting to define the connectionTimeout Task-number: QTBUG-99079 Change-Id: Ie125ea33eaaa4f3d04e061bcf23857cafae78d39 Reviewed-by: Robert Griebl <robert.griebl@qt.io> (cherry picked from commit 3ed46564afbeae26023d998d89e7645dc0446a00) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/ifmedia/mediaplayer/main.qml11
-rw-r--r--src/ifmedia/qifamfmtuner.cpp5
-rw-r--r--src/ifmedia/qifamfmtuner.h1
-rw-r--r--src/ifmedia/qifmediadevicediscoverymodel.cpp5
-rw-r--r--src/ifmedia/qifmediaindexercontrol.cpp5
-rw-r--r--src/ifmedia/qifmediaplayer.cpp5
-rw-r--r--src/plugins/ifmedia/doc/src/backends.qdoc85
-rw-r--r--src/plugins/ifmedia/media_qtro/filterandbrowsemodel.cpp91
-rw-r--r--src/plugins/ifmedia/media_qtro/filterandbrowsemodel.h3
-rw-r--r--src/plugins/ifmedia/media_qtro/mediadiscoverybackend.cpp91
-rw-r--r--src/plugins/ifmedia/media_qtro/mediadiscoverybackend.h3
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaindexerbackend.cpp89
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaindexerbackend.h3
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaplayerbackend.cpp89
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaplayerbackend.h3
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaplugin.cpp13
-rw-r--r--src/plugins/ifmedia/media_qtro/mediaplugin.h3
-rw-r--r--src/plugins/ifmedia/media_simulator/database_helper.h22
-rw-r--r--src/plugins/ifmedia/media_simulator/mediadiscoverybackend.cpp13
-rw-r--r--src/plugins/ifmedia/media_simulator/mediadiscoverybackend.h2
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaindexerbackend.cpp12
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaindexerbackend.h2
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaplayerbackend.cpp4
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaplayerbackend.h2
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaplugin.cpp32
-rw-r--r--src/plugins/ifmedia/media_simulator/mediaplugin.h5
-rw-r--r--src/plugins/ifmedia/media_simulator/searchandbrowsebackend.cpp4
-rw-r--r--src/plugins/ifmedia/media_simulator/searchandbrowsebackend.h2
-rw-r--r--src/tools/media-simulation-server/main.cpp12
29 files changed, 509 insertions, 108 deletions
diff --git a/examples/ifmedia/mediaplayer/main.qml b/examples/ifmedia/mediaplayer/main.qml
index f0655810..4be2cfce 100644
--- a/examples/ifmedia/mediaplayer/main.qml
+++ b/examples/ifmedia/mediaplayer/main.qml
@@ -17,7 +17,6 @@ ApplicationWindow {
MediaPlayer {
id: mediaPlayer
- discoveryMode: AbstractFeature.LoadOnlySimulationBackends
}
SplitView {
@@ -276,4 +275,14 @@ ApplicationWindow {
}
}
}
+
+ InterfaceFrameworkConfiguration {
+ name: "qtifmedia"
+ discoveryMode: AbstractFeature.LoadOnlySimulationBackends
+
+// Enable this to pass settings to the simulation backend
+// serviceSettings: {
+// "useTemporaryDatabase": true
+// }
+ }
}
diff --git a/src/ifmedia/qifamfmtuner.cpp b/src/ifmedia/qifamfmtuner.cpp
index f5c201ba..bc6bf069 100644
--- a/src/ifmedia/qifamfmtuner.cpp
+++ b/src/ifmedia/qifamfmtuner.cpp
@@ -120,6 +120,8 @@ QIfAmFmTunerBackendInterface *QIfAmFmTunerPrivate::tunerBackend() const
\brief Provides a interface to control the AM/FM tuner.
The QIfAmFmTuner provides the methods to control a AM/FM tuner.
+
+ Uses \c qtifmedia as configurationId for \l QIfConfiguration based settings.
*/
/*!
@@ -130,6 +132,8 @@ QIfAmFmTunerBackendInterface *QIfAmFmTunerPrivate::tunerBackend() const
\brief Provides a interface to control the AM/FM tuner.
The AmFmTuner provides the methods to control a AM/FM tuner.
+
+ Uses \c qtifmedia as configurationId for \l InterfaceFrameworkConfiguration based settings.
*/
/*!
@@ -150,6 +154,7 @@ QIfAmFmTunerBackendInterface *QIfAmFmTunerPrivate::tunerBackend() const
QIfAmFmTuner::QIfAmFmTuner(QObject *parent)
: QIfAbstractFeature(*new QIfAmFmTunerPrivate(QLatin1String(QIfAmFmTuner_iid), this), parent)
{
+ setConfigurationId(QStringLiteral("qtifmedia"));
}
/*!
diff --git a/src/ifmedia/qifamfmtuner.h b/src/ifmedia/qifamfmtuner.h
index 2d00971f..68632575 100644
--- a/src/ifmedia/qifamfmtuner.h
+++ b/src/ifmedia/qifamfmtuner.h
@@ -37,7 +37,6 @@ public:
};
Q_ENUM(Band)
-
int frequency() const;
int minimumFrequency() const;
int maximumFrequency() const;
diff --git a/src/ifmedia/qifmediadevicediscoverymodel.cpp b/src/ifmedia/qifmediadevicediscoverymodel.cpp
index f00d1ecf..9e0a6cc6 100644
--- a/src/ifmedia/qifmediadevicediscoverymodel.cpp
+++ b/src/ifmedia/qifmediadevicediscoverymodel.cpp
@@ -102,6 +102,8 @@ QIfMediaDeviceDiscoveryModelBackendInterface *QIfMediaDeviceDiscoveryModelPrivat
The QIfMediaDeviceDiscoveryModel expects a single backend to be available. It is recommended to use it
with \l {QIfAbstractFeatureListModel::}{discoveryMode} set to \l QIfAbstractFeature::AutoDiscovery.
+
+ Uses \c qtifmedia as configurationId for \l QIfConfiguration based settings.
*/
/*!
@@ -140,6 +142,8 @@ QIfMediaDeviceDiscoveryModelBackendInterface *QIfMediaDeviceDiscoveryModelPrivat
The MediaDeviceDiscoveryModel expects a single backend to be available. It is recommended to use it
with \l {AbstractFeatureListModel::}{discoveryMode} set to AbstractFeature.AutoDiscovery.
+
+ Uses \c qtifmedia as configurationId for \l InterfaceFrameworkConfiguration based settings.
*/
/*!
@@ -160,6 +164,7 @@ QIfMediaDeviceDiscoveryModelBackendInterface *QIfMediaDeviceDiscoveryModelPrivat
QIfMediaDeviceDiscoveryModel::QIfMediaDeviceDiscoveryModel(QObject *parent)
: QIfAbstractFeatureListModel(*new QIfMediaDeviceDiscoveryModelPrivate(QLatin1String(QIfMediaDeviceDiscovery_iid), this), parent)
{
+ setConfigurationId(QStringLiteral("qtifmedia"));
}
/*!
diff --git a/src/ifmedia/qifmediaindexercontrol.cpp b/src/ifmedia/qifmediaindexercontrol.cpp
index 617172e8..a6467b5c 100644
--- a/src/ifmedia/qifmediaindexercontrol.cpp
+++ b/src/ifmedia/qifmediaindexercontrol.cpp
@@ -62,6 +62,8 @@ QIfMediaIndexerControlBackendInterface *QIfMediaIndexerControlPrivate::indexerBa
The QIfMediaIndexerControl expects a single backend to be available. It is recommended to use it
with \l {QIfAbstractFeature::}{discoveryMode} set to \l QIfAbstractFeature::AutoDiscovery.
+
+ Uses \c qtifmedia as configurationId for \l QIfConfiguration based settings.
*/
/*!
@@ -76,6 +78,8 @@ QIfMediaIndexerControlBackendInterface *QIfMediaIndexerControlPrivate::indexerBa
The MediaIndexerControl expects a single backend to be available. It is recommended to use it
with \l {AbstractFeature::}{discoveryMode} set to AbstractFeature.AutoDiscovery.
+
+ Uses \c qtifmedia as configurationId for \l InterfaceFrameworkConfiguration based settings.
*/
/*!
@@ -99,6 +103,7 @@ QIfMediaIndexerControl::QIfMediaIndexerControl(QObject *parent)
: QIfAbstractFeature(*new QIfMediaIndexerControlPrivate(QLatin1String(QIfMediaIndexer_iid), this), parent)
{
qRegisterMetaType<QIfMediaIndexerControl::State>();
+ setConfigurationId(QStringLiteral("qtifmedia"));
}
/*!
diff --git a/src/ifmedia/qifmediaplayer.cpp b/src/ifmedia/qifmediaplayer.cpp
index 91688a81..496138d6 100644
--- a/src/ifmedia/qifmediaplayer.cpp
+++ b/src/ifmedia/qifmediaplayer.cpp
@@ -139,6 +139,8 @@ QIfMediaPlayerBackendInterface *QIfMediaPlayerPrivate::playerBackend() const
By default the autoDiscovery is turned to Automatic for this feature and most likely will connect to
a local media player instance.
+
+ Uses \c qtifmedia as configurationId for \l QIfConfiguration based settings.
*/
/*!
@@ -153,6 +155,8 @@ QIfMediaPlayerBackendInterface *QIfMediaPlayerPrivate::playerBackend() const
By default the autoDiscovery is turned to Automatic for this feature and most likely will connect to
a local media player instance.
+
+ Uses \c qtifmedia as configurationId for \l InterfaceFrameworkConfiguration based settings.
*/
/*!
@@ -187,6 +191,7 @@ QIfMediaPlayerBackendInterface *QIfMediaPlayerPrivate::playerBackend() const
QIfMediaPlayer::QIfMediaPlayer(QObject *parent)
: QIfAbstractFeature(*new QIfMediaPlayerPrivate(QLatin1String(QIfMediaPlayer_iid), this), parent)
{
+ setConfigurationId(QStringLiteral("qtifmedia"));
}
/*!
diff --git a/src/plugins/ifmedia/doc/src/backends.qdoc b/src/plugins/ifmedia/doc/src/backends.qdoc
index ef8373f9..9b30da2a 100644
--- a/src/plugins/ifmedia/doc/src/backends.qdoc
+++ b/src/plugins/ifmedia/doc/src/backends.qdoc
@@ -81,7 +81,7 @@ the following navigation paths:
\note On systems where \c taglib is disabled, indexing of files doesn't work and because of that
the media database can't be created.
-The MediaDiscoveryModel provides a simulation of USB thumb drives and can be configured using the the
+The MediaDiscoveryModel provides a simulation of USB thumb drives and can be configured using the
\c QTIFMEDIA_SIMULATOR_DEVICEFOLDER environment variable, which needs to be set to an absolute path.
Every sub-folder within that path is recognized as a new USB thumb drive.
@@ -93,9 +93,32 @@ the FilterAndBrowseModel connected to the media player's service object to brows
\section1 Configuration
-This backend uses environment variables for its configuration. By default it will write its database
-to the application's cache location. There is also a non persistent mode, where the indexed media
-database is not saved, but recreated on every start of the app.
+This backend can be configured using \l QIfConfiguration::serviceSettings.
+By default it will write its database to the application's cache location.
+There is also a non persistent mode, where the indexed media database is not saved, but recreated
+on every start of the app.
+The backend uses \c qtifmedia as its configurationId and accepts the following serviceSettings:
+
+\table
+\header
+ \li Name
+ \li Description
+\row
+ \li useTemporaryDatabase
+ \li The database is written to a temporary location and deleted when the application is stopped.
+\row
+ \li database
+ \li A path to the media database which should be used.
+\row
+ \li customMediaFolder
+ \li The local media directory (default: all media locations of the user - see also QStandardPaths)
+\row
+ \li customDeviceFolder
+ \li The path which will be used by the DiscoveryModel for discovering media devices.
+ (default: /home/<user>/usb-simulation)
+\endtable
+
+In addition the settings can be also provided by using the following environment variables:
\table
\header
@@ -116,3 +139,57 @@ database is not saved, but recreated on every start of the app.
(default: /home/<user>/usb-simulation)
\endtable
*/
+
+/*!
+\page qtifmedia-player-qtro-backend.html
+\title QtIfMedia MediaPlayer RemoteObjects Backend
+\ingroup qtifmedia_backend
+\ingroup qtif_backend
+
+\brief Connects to a media player using Qt Remote Objects.
+
+\section1 Supported interfaces
+\list
+ \li \l{org.qt-project.interfaceframework.MediaPlayer/1.0}
+ \li \l{org.qt-project.interfaceframework.MediaIndexer/1.0}
+ \li \l{org.qt-project.interfaceframework.MediaDiscovery/1.0}
+ \li \l{org.qt-project.interfaceframework.FilterAndBrowseModel/1.0}
+\endlist
+
+\section1 Configuration
+
+The backend uses \c qtifmedia as it's configurationId and accepts the following serviceSettings:
+
+\table
+\header
+ \li Name
+ \li Description
+\row
+ \li connectionUrl
+ \li The url the interface tries to connect to using Qt Remote Objects. Defaults to
+ \c local:qtifmedia. Changing this value at runtime will reconnect the backend to the new URL.
+\row
+ \li connectionTimeout
+ \li Defines when a timeout warning should be printed (in milliseconds).
+ To disable the warning set the timeout to -1.
+\endtable
+
+In addition to those global settings, the values can also be provided per backend interface and
+this allows the backend to connect to multiple remote objects instances. Interface specific
+settings need to be prefixed with the interface name. The following example uses a global \c
+connectionTimeout and a specific \c connectionUrl for the player interface, while all other
+interfaces use the default \c connectionUrl:
+
+\badcode
+{
+ connectionTimeout: 1000,
+ MediaPlayer: {
+ connectionUrl: "tcp://127.0.0.1:1234"
+ }
+}
+\endcode
+
+For backward compatibility a \c server.conf file in the current directory of the application (or
+specified by \c SERVER_CONF_PATH), but is marked as deprecated and will be removed
+in future Qt releases.
+*/
diff --git a/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.cpp b/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.cpp
index 108c6a30..c008a1a4 100644
--- a/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.cpp
+++ b/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.cpp
@@ -9,7 +9,7 @@
#include <QSettings>
#include <QIODevice>
-Q_LOGGING_CATEGORY(qLcROQIfFilterAndBrowseModel, "interfaceframework.media.qifsearchandbrowsebackend.remoteobjects", QtInfoMsg)
+Q_LOGGING_CATEGORY(qLcROQIfFilterAndBrowseModel, "interfaceframework.media.qiffilterandbrowsebackend.remoteobjects", QtInfoMsg)
QDataStream &operator<<(QDataStream &stream, const SearchAndBrowseItem &obj)
{
@@ -56,11 +56,6 @@ void FilterAndBrowseModel::initialize()
emit availableContentTypesChanged(m_replica->availableContentTypes());
emit initializationDone();
}
-
- QTimer::singleShot(3000, this, [this](){
- if (!m_replica->isInitialized())
- qCCritical(qLcROQIfFilterAndBrowseModel) << "QIfFilterAndBrowseModel wasn't initialized within the timeout period. Please make sure the server is running.";
- });
}
void FilterAndBrowseModel::registerInstance(const QUuid &identifier)
@@ -164,34 +159,92 @@ QIfPendingReply<int> FilterAndBrowseModel::indexOf(const QUuid &identifier, cons
return ifReply;
}
+void FilterAndBrowseModel::updateServiceSettings(const QVariantMap &settings)
+{
+ if (m_serviceSettings == settings)
+ return;
+
+ m_serviceSettings = settings;
+ connectToNode();
+}
+
bool FilterAndBrowseModel::connectToNode()
{
+ QUrl url;
+ const auto it = m_serviceSettings.constFind(QStringLiteral("FilterAndBrowseModel"));
+
+ if (it != m_serviceSettings.constEnd())
+ url = it->toMap().value(QStringLiteral("connectionUrl")).toUrl();
+ if (url.isEmpty())
+ url = m_serviceSettings.value(QStringLiteral("connectionUrl")).toUrl();
+
static QString configPath;
- if (configPath.isEmpty()) {
- if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
- configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
- } else {
- configPath = QStringLiteral("./server.conf");
- qCInfo(qLcROQIfFilterAndBrowseModel) << "Environment variable SERVER_CONF_PATH not defined, using " << configPath;
+ if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
+ configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "SERVER_CONF_PATH environment variable is set.\n"
+ << "Overriding service setting: 'FilterAndBrowseModel.connectionUrl'";
+
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "Using SERVER_CONF_PATH is deprecated and will be removed"
+ "in future Qt versions.";
}
}
- QSettings settings(configPath, QSettings::IniFormat);
- settings.beginGroup(QStringLiteral("qtifmedia"));
- QUrl registryUrl = QUrl(settings.value(QStringLiteral("Registry"), QStringLiteral("local:qtifmedia")).toString());
- if (m_url != registryUrl) {
- m_url = registryUrl;
+ if (url.isEmpty() && QFile::exists(QStringLiteral("./server.conf"))) {
+ configPath = QStringLiteral("./server.conf");
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "Reading url from ./server.conf.\n"
+ << "Overriding service setting: 'FilterAndBrowseModel.connectionUrl'";
+
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "Using ./server.conf. is deprecated and will be removed"
+ "in future Qt versions.";
+ }
+ }
+
+ if (url.isEmpty())
+ url = QStringLiteral("local:qtifmedia");
+
+ if (m_url != url) {
// QtRO doesn't allow to change the URL without destroying the Node
- delete m_node;
+ if (m_node) {
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "Disconnecting from" << m_url;
+ delete m_node;
+ }
+
+ m_url = url;
+
m_node = new QRemoteObjectNode(this);
+ qCInfo(qLcROQIfFilterAndBrowseModel) << "Connecting to" << m_url;
if (!m_node->connectToNode(m_url)) {
qCCritical(qLcROQIfFilterAndBrowseModel) << "Connection to" << m_url << "failed!";
m_replica.reset();
return false;
}
- qCInfo(qLcROQIfFilterAndBrowseModel) << "Connecting to" << m_url;
m_replica.reset(m_node->acquire<QIfFilterAndBrowseModelReplica>(m_remoteObjectsLookupName));
setupConnections();
+
+ const int defaultTimeout = 3000;
+ int connectionTimeout = defaultTimeout;
+ if (it != m_serviceSettings.constEnd())
+ connectionTimeout = it->toMap().value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout == defaultTimeout)
+ connectionTimeout = m_serviceSettings.value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout != -1) {
+ QTimer::singleShot(connectionTimeout, this, [this](){
+ if (!m_replica->isInitialized())
+ qCWarning(qLcROQIfFilterAndBrowseModel) << "QtIfMedia.QIfMediaDiscoveryModel wasn't initialized within the timeout period. Please make sure the server is running.";
+ });
+ }
}
return true;
}
diff --git a/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.h b/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.h
index 668e8002..4b6ff4f4 100644
--- a/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.h
+++ b/src/plugins/ifmedia/media_qtro/filterandbrowsemodel.h
@@ -51,6 +51,8 @@ public:
QIfPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) override;
QIfPendingReply<int> indexOf(const QUuid &identifier, const QVariant &item) override;
+ void updateServiceSettings(const QVariantMap &settings);
+
protected:
void setupConnections();
bool connectToNode();
@@ -61,6 +63,7 @@ private:
QRemoteObjectNode *m_node;
QUrl m_url;
QIfRemoteObjectsReplicaHelper *m_helper;
+ QVariantMap m_serviceSettings;
};
#endif // SEARCHANDBROWSEMODEL_H
diff --git a/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.cpp b/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.cpp
index 082c0ca6..a8273881 100644
--- a/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.cpp
+++ b/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.cpp
@@ -28,11 +28,6 @@ void MediaDiscoveryBackend::initialize()
onDevicesChanged(m_replica->devices());
emit initializationDone();
}
-
- QTimer::singleShot(3000, this, [this](){
- if (!m_replica->isInitialized())
- qCCritical(qLcROQIfMediaDiscovery) << "QtIfMedia.QIfMediaDiscoveryModel wasn't initialized within the timeout period. Please make sure the server is running.";
- });
}
void MediaDiscoveryBackend::onDevicesChanged(const QStringList &devices)
@@ -61,34 +56,92 @@ void MediaDiscoveryBackend::onDeviceRemoved(const QString &device)
emit deviceRemoved(dev);
}
+void MediaDiscoveryBackend::updateServiceSettings(const QVariantMap &settings)
+{
+ if (m_serviceSettings == settings)
+ return;
+
+ m_serviceSettings = settings;
+ connectToNode();
+}
+
bool MediaDiscoveryBackend::connectToNode()
{
+ QUrl url;
+ const auto it = m_serviceSettings.constFind(QStringLiteral("MediaDiscoveryModel"));
+
+ if (it != m_serviceSettings.constEnd())
+ url = it->toMap().value(QStringLiteral("connectionUrl")).toUrl();
+ if (url.isEmpty())
+ url = m_serviceSettings.value(QStringLiteral("connectionUrl")).toUrl();
+
static QString configPath;
- if (configPath.isEmpty()) {
- if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
- configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
- } else {
- configPath = QStringLiteral("./server.conf");
- qCInfo(qLcROQIfMediaDiscovery) << "Environment variable SERVER_CONF_PATH not defined, using " << configPath;
+ if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
+ configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaDiscovery) << "SERVER_CONF_PATH environment variable is set.\n"
+ << "Overriding service setting: 'MediaDiscoveryModel.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaDiscovery) << "Using SERVER_CONF_PATH is deprecated and will be removed"
+ "in future Qt versions.";
}
}
- QSettings settings(configPath, QSettings::IniFormat);
- settings.beginGroup(QStringLiteral("qtifmedia"));
- QUrl registryUrl = QUrl(settings.value(QStringLiteral("Registry"), QStringLiteral("local:qtifmedia")).toString());
- if (m_url != registryUrl) {
- m_url = registryUrl;
+ if (url.isEmpty() && QFile::exists(QStringLiteral("./server.conf"))) {
+ configPath = QStringLiteral("./server.conf");
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaDiscovery) << "Reading url from ./server.conf.\n"
+ << "Overriding service setting: 'MediaDiscoveryModel.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaDiscovery) << "Using ./server.conf. is deprecated and will be removed"
+ "in future Qt versions.";
+ }
+ }
+
+ if (url.isEmpty())
+ url = QStringLiteral("local:qtifmedia");
+
+ if (m_url != url) {
// QtRO doesn't allow to change the URL without destroying the Node
- delete m_node;
+ if (m_node) {
+ qCInfo(qLcROQIfMediaDiscovery) << "Disconnecting from" << m_url;
+ delete m_node;
+ }
+
+ m_url = url;
+
m_node = new QRemoteObjectNode(this);
+ qCInfo(qLcROQIfMediaDiscovery) << "Connecting to" << m_url;
if (!m_node->connectToNode(m_url)) {
qCCritical(qLcROQIfMediaDiscovery) << "Connection to" << m_url << "failed!";
m_replica.reset();
return false;
}
- qCInfo(qLcROQIfMediaDiscovery) << "Connecting to" << m_url;
- m_replica.reset(m_node->acquire<QIfMediaDiscoveryModelReplica>(QStringLiteral("QtIfMedia.QIfMediaDiscoveryModel")));
+ m_replica.reset(m_node->acquire<QIfMediaDiscoveryModelReplica>(QStringLiteral("QtIfMedia.QIfMediaDiscoveryModel")));
setupConnections();
+
+ const int defaultTimeout = 3000;
+ int connectionTimeout = defaultTimeout;
+ if (it != m_serviceSettings.constEnd())
+ connectionTimeout = it->toMap().value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout == defaultTimeout)
+ connectionTimeout = m_serviceSettings.value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout != -1) {
+ QTimer::singleShot(connectionTimeout, this, [this](){
+ if (!m_replica->isInitialized())
+ qCWarning(qLcROQIfMediaDiscovery) << "QtIfMedia.QIfMediaDiscoveryModel wasn't initialized within the timeout period. Please make sure the server is running.";
+ });
+ }
}
return true;
}
diff --git a/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.h b/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.h
index 0b45e914..666bcd64 100644
--- a/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.h
+++ b/src/plugins/ifmedia/media_qtro/mediadiscoverybackend.h
@@ -27,6 +27,8 @@ public Q_SLOTS:
void onDeviceAdded(const QString &device);
void onDeviceRemoved(const QString &device);
+ void updateServiceSettings(const QVariantMap &settings);
+
protected:
void setupConnections();
bool connectToNode();
@@ -38,6 +40,7 @@ private:
QHash<QString, QIfServiceObject*> m_deviceMap;
bool m_initialized;
QIfRemoteObjectsReplicaHelper *m_helper;
+ QVariantMap m_serviceSettings;
};
#endif // MEDIADISCOVERYBACKEND_H
diff --git a/src/plugins/ifmedia/media_qtro/mediaindexerbackend.cpp b/src/plugins/ifmedia/media_qtro/mediaindexerbackend.cpp
index f861cfb4..5481575b 100644
--- a/src/plugins/ifmedia/media_qtro/mediaindexerbackend.cpp
+++ b/src/plugins/ifmedia/media_qtro/mediaindexerbackend.cpp
@@ -26,11 +26,6 @@ void MediaIndexerBackend::initialize()
emit stateChanged(m_replica->state());
emit initializationDone();
}
-
- QTimer::singleShot(3000, this, [this](){
- if (!m_replica->isInitialized())
- qCCritical(qLcROQIfMediaIndexer) << "QtIfMedia.QIfMediaIndexer wasn't initialized within the timeout period. Please make sure the server is running.";
- });
}
void MediaIndexerBackend::pause()
@@ -43,34 +38,92 @@ void MediaIndexerBackend::resume()
m_replica->resume();
}
+void MediaIndexerBackend::updateServiceSettings(const QVariantMap &settings)
+{
+ if (m_serviceSettings == settings)
+ return;
+
+ m_serviceSettings = settings;
+ connectToNode();
+}
+
bool MediaIndexerBackend::connectToNode()
{
+ QUrl url;
+ const auto it = m_serviceSettings.constFind(QStringLiteral("MediaIndexer"));
+
+ if (it != m_serviceSettings.constEnd())
+ url = it->toMap().value(QStringLiteral("connectionUrl")).toUrl();
+ if (url.isEmpty())
+ url = m_serviceSettings.value(QStringLiteral("connectionUrl")).toUrl();
+
static QString configPath;
- if (configPath.isEmpty()) {
- if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
- configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
- } else {
- configPath = QStringLiteral("./server.conf");
- qCInfo(qLcROQIfMediaIndexer) << "Environment variable SERVER_CONF_PATH not defined, using " << configPath;
+ if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
+ configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaIndexer) << "SERVER_CONF_PATH environment variable is set.\n"
+ << "Overriding service setting: 'MediaIndexer.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaIndexer) << "Using SERVER_CONF_PATH is deprecated and will be removed"
+ "in future Qt versions.";
}
}
- QSettings settings(configPath, QSettings::IniFormat);
- settings.beginGroup(QStringLiteral("qtifmedia"));
- QUrl registryUrl = QUrl(settings.value(QStringLiteral("Registry"), QStringLiteral("local:qtifmedia")).toString());
- if (m_url != registryUrl) {
- m_url = registryUrl;
+ if (url.isEmpty() && QFile::exists(QStringLiteral("./server.conf"))) {
+ configPath = QStringLiteral("./server.conf");
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaIndexer) << "Reading url from ./server.conf.\n"
+ << "Overriding service setting: 'MediaIndexer.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaIndexer) << "Using ./server.conf. is deprecated and will be removed"
+ "in future Qt versions.";
+ }
+ }
+
+ if (url.isEmpty())
+ url = QStringLiteral("local:qtifmedia");
+
+ if (m_url != url) {
// QtRO doesn't allow to change the URL without destroying the Node
- delete m_node;
+ if (m_node) {
+ qCInfo(qLcROQIfMediaIndexer) << "Disconnecting from" << m_url;
+ delete m_node;
+ }
+
+ m_url = url;
+
m_node = new QRemoteObjectNode(this);
+ qCInfo(qLcROQIfMediaIndexer) << "Connecting to" << m_url;
if (!m_node->connectToNode(m_url)) {
qCCritical(qLcROQIfMediaIndexer) << "Connection to" << m_url << "failed!";
m_replica.reset();
return false;
}
- qCInfo(qLcROQIfMediaIndexer) << "Connecting to" << m_url;
m_replica.reset(m_node->acquire<QIfMediaIndexerReplica>(QStringLiteral("QtIfMedia.QIfMediaIndexer")));
setupConnections();
+
+ const int defaultTimeout = 3000;
+ int connectionTimeout = defaultTimeout;
+ if (it != m_serviceSettings.constEnd())
+ connectionTimeout = it->toMap().value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout == defaultTimeout)
+ connectionTimeout = m_serviceSettings.value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout != -1) {
+ QTimer::singleShot(connectionTimeout, this, [this](){
+ if (!m_replica->isInitialized())
+ qCWarning(qLcROQIfMediaIndexer) << "QtIfMedia.QIfMediaIndexer wasn't initialized within the timeout period. Please make sure the server is running.";
+ });
+ }
}
return true;
}
diff --git a/src/plugins/ifmedia/media_qtro/mediaindexerbackend.h b/src/plugins/ifmedia/media_qtro/mediaindexerbackend.h
index 7d31b51b..b5b08fac 100644
--- a/src/plugins/ifmedia/media_qtro/mediaindexerbackend.h
+++ b/src/plugins/ifmedia/media_qtro/mediaindexerbackend.h
@@ -21,6 +21,8 @@ public:
void pause() override;
void resume() override;
+ void updateServiceSettings(const QVariantMap &settings);
+
protected:
void setupConnections();
bool connectToNode();
@@ -30,6 +32,7 @@ private:
QRemoteObjectNode *m_node;
QUrl m_url;
QIfRemoteObjectsReplicaHelper *m_helper;
+ QVariantMap m_serviceSettings;
};
#endif // MEDIAINDEXERBACKEND_H
diff --git a/src/plugins/ifmedia/media_qtro/mediaplayerbackend.cpp b/src/plugins/ifmedia/media_qtro/mediaplayerbackend.cpp
index 57d4e0c3..1d9c63e1 100644
--- a/src/plugins/ifmedia/media_qtro/mediaplayerbackend.cpp
+++ b/src/plugins/ifmedia/media_qtro/mediaplayerbackend.cpp
@@ -36,11 +36,6 @@ void MediaPlayerBackend::initialize()
emit mutedChanged(m_replica->muted());
emit initializationDone();
}
-
- QTimer::singleShot(3000, this, [this](){
- if (!m_replica->isInitialized())
- qCCritical(qLcROQIfMediaPlayer) << "QtIfMedia.QIfMediaPlayer wasn't initialized within the timeout period. Please make sure the server is running.";
- });
}
void MediaPlayerBackend::play()
@@ -118,34 +113,92 @@ void MediaPlayerBackend::move(int currentIndex, int newIndex)
m_replica->move(currentIndex, newIndex);
}
+void MediaPlayerBackend::updateServiceSettings(const QVariantMap &settings)
+{
+ if (m_serviceSettings == settings)
+ return;
+
+ m_serviceSettings = settings;
+ connectToNode();
+}
+
bool MediaPlayerBackend::connectToNode()
{
+ QUrl url;
+ const auto it = m_serviceSettings.constFind(QStringLiteral("MediaPlayer"));
+
+ if (it != m_serviceSettings.constEnd())
+ url = it->toMap().value(QStringLiteral("connectionUrl")).toUrl();
+ if (url.isEmpty())
+ url = m_serviceSettings.value(QStringLiteral("connectionUrl")).toUrl();
+
static QString configPath;
- if (configPath.isEmpty()) {
- if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
- configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
- } else {
- configPath = QStringLiteral("./server.conf");
- qCInfo(qLcROQIfMediaPlayer) << "Environment variable SERVER_CONF_PATH not defined, using " << configPath;
+ if (qEnvironmentVariableIsSet("SERVER_CONF_PATH")) {
+ configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaPlayer) << "SERVER_CONF_PATH environment variable is set.\n"
+ << "Overriding service setting: 'MediaPlayer.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaPlayer) << "Using SERVER_CONF_PATH is deprecated and will be removed"
+ "in future Qt versions.";
+ }
+ }
+
+ if (url.isEmpty() && QFile::exists(QStringLiteral("./server.conf"))) {
+ configPath = QStringLiteral("./server.conf");
+
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("qtifmedia"));
+ url = QUrl(settings.value(QStringLiteral("Registry")).toString());
+ if (!url.isEmpty()) {
+ qCInfo(qLcROQIfMediaPlayer) << "Reading url from ./server.conf.\n"
+ << "Overriding service setting: 'MediaPlayer.connectionUrl'";
+
+ qCInfo(qLcROQIfMediaPlayer) << "Using ./server.conf. is deprecated and will be removed"
+ "in future Qt versions.";
}
}
- QSettings settings(configPath, QSettings::IniFormat);
- settings.beginGroup(QStringLiteral("qtifmedia"));
- QUrl registryUrl = QUrl(settings.value(QStringLiteral("Registry"), QStringLiteral("local:qtifmedia")).toString());
- if (m_url != registryUrl) {
- m_url = registryUrl;
+ if (url.isEmpty())
+ url = QStringLiteral("local:qtifmedia");
+
+ if (m_url != url) {
// QtRO doesn't allow to change the URL without destroying the Node
- delete m_node;
+ if (m_node) {
+ qCInfo(qLcROQIfMediaPlayer) << "Disconnecting from" << m_url;
+ delete m_node;
+ }
+
+ m_url = url;
+
m_node = new QRemoteObjectNode(this);
+ qCInfo(qLcROQIfMediaPlayer) << "Connecting to" << m_url;
if (!m_node->connectToNode(m_url)) {
qCCritical(qLcROQIfMediaPlayer) << "Connection to" << m_url << "failed!";
m_replica.reset();
return false;
}
- qCInfo(qLcROQIfMediaPlayer) << "Connecting to" << m_url;
m_replica.reset(m_node->acquire<QIfMediaPlayerReplica>(QStringLiteral("QtIfMedia.QIfMediaPlayer")));
setupConnections();
+
+ const int defaultTimeout = 3000;
+ int connectionTimeout = defaultTimeout;
+ if (it != m_serviceSettings.constEnd())
+ connectionTimeout = it->toMap().value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout == defaultTimeout)
+ connectionTimeout = m_serviceSettings.value(QStringLiteral("connectionTimeout"), defaultTimeout).toInt();
+
+ if (connectionTimeout != -1) {
+ QTimer::singleShot(connectionTimeout, this, [this](){
+ if (!m_replica->isInitialized())
+ qCWarning(qLcROQIfMediaPlayer) << "QtIfMedia.QIfMediaPlayer wasn't initialized within the timeout period. Please make sure the server is running.";
+ });
+ }
}
return true;
}
diff --git a/src/plugins/ifmedia/media_qtro/mediaplayerbackend.h b/src/plugins/ifmedia/media_qtro/mediaplayerbackend.h
index a24114cf..d0343bef 100644
--- a/src/plugins/ifmedia/media_qtro/mediaplayerbackend.h
+++ b/src/plugins/ifmedia/media_qtro/mediaplayerbackend.h
@@ -33,6 +33,8 @@ public:
void remove(int index) override;
void move(int currentIndex, int newIndex) override;
+ void updateServiceSettings(const QVariantMap &settings);
+
protected:
void setupConnections();
bool connectToNode();
@@ -42,6 +44,7 @@ private:
QRemoteObjectNode *m_node;
QUrl m_url;
QIfRemoteObjectsReplicaHelper *m_helper;
+ QVariantMap m_serviceSettings;
};
#endif // MEDIAPLAYERBACKEND_H
diff --git a/src/plugins/ifmedia/media_qtro/mediaplugin.cpp b/src/plugins/ifmedia/media_qtro/mediaplugin.cpp
index 88db30cc..880236cf 100644
--- a/src/plugins/ifmedia/media_qtro/mediaplugin.cpp
+++ b/src/plugins/ifmedia/media_qtro/mediaplugin.cpp
@@ -50,3 +50,16 @@ QIfFeatureInterface *MediaQtROPlugin::interfaceInstance(const QString &interface
return nullptr;
}
+
+QString MediaQtROPlugin::configurationId() const
+{
+ return QStringLiteral("qtifmedia");
+}
+
+void MediaQtROPlugin::updateServiceSettings(const QVariantMap &settings)
+{
+ m_player->updateServiceSettings(settings);
+ m_indexer->updateServiceSettings(settings);
+ m_searchModel->updateServiceSettings(settings);
+ m_discovery->updateServiceSettings(settings);
+}
diff --git a/src/plugins/ifmedia/media_qtro/mediaplugin.h b/src/plugins/ifmedia/media_qtro/mediaplugin.h
index 2df30dc7..b1049764 100644
--- a/src/plugins/ifmedia/media_qtro/mediaplugin.h
+++ b/src/plugins/ifmedia/media_qtro/mediaplugin.h
@@ -24,6 +24,9 @@ public:
QStringList interfaces() const override;
QIfFeatureInterface *interfaceInstance(const QString &interface) const override;
+ QString configurationId() const override;
+ void updateServiceSettings(const QVariantMap &settings) override;
+
private:
MediaPlayerBackend *m_player;
diff --git a/src/plugins/ifmedia/media_simulator/database_helper.h b/src/plugins/ifmedia/media_simulator/database_helper.h
index 66910a81..40e88aa8 100644
--- a/src/plugins/ifmedia/media_simulator/database_helper.h
+++ b/src/plugins/ifmedia/media_simulator/database_helper.h
@@ -17,20 +17,30 @@
#include "logging.h"
-QString mediaDatabaseFile()
+QString mediaDatabaseFile(const QVariantMap &serviceSettings)
{
QString dbFile;
- const QByteArray database = qgetenv("QTIFMEDIA_SIMULATOR_DATABASE");
+ bool useTemporaryDatabase = serviceSettings.value(QStringLiteral("useTemporaryDatabase")).toBool();
+ QString database = serviceSettings.value(QStringLiteral("database")).toString();
if (qEnvironmentVariableIsSet("QTIFMEDIA_TEMPORARY_DATABASE")) {
+ qCInfo(media) << "QTIFMEDIA_TEMPORARY_DATABASE environment variable is set.\n"
+ << "Overriding service setting: 'useTemporaryDatabas'";
+ useTemporaryDatabase = true;
+ } else if (qEnvironmentVariableIsSet("QTIFMEDIA_SIMULATOR_DATABASE")) {
+ qCInfo(media) << "QTIFMEDIA_SIMULATOR_DATABASE environment variable is set.\n"
+ << "Overriding service setting: 'database'";
+ database = QFile::decodeName(qgetenv("QTIFMEDIA_SIMULATOR_DATABASE"));
+ }
+
+ if (useTemporaryDatabase) {
auto *tempFile = new QTemporaryFile(qApp);
tempFile->open();
dbFile = tempFile->fileName();
- qCInfo(media) << "QTIFMEDIA_TEMPORARY_DATABASE environment variable is set.\n"
- << "Using the temporary database: " << tempFile->fileName();
+ qCInfo(media) << "Using the temporary database: " << tempFile->fileName();
} else if (!database.isEmpty()) {
- dbFile = QFile::decodeName(database);
+ dbFile = database;
if (!QFileInfo(dbFile).isAbsolute())
- qCInfo(media) << "Please set an valid absolute path for QTIFMEDIA_SIMULATOR_DATABASE. Current path:" << dbFile;
+ qCInfo(media) << "Please set an valid absolute path for the service setting 'database'. Current path:" << dbFile;
} else {
const QDir cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
if (!cacheLocation.exists())
diff --git a/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.cpp b/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.cpp
index 7b8f2c56..a4c767a0 100644
--- a/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.cpp
+++ b/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.cpp
@@ -11,13 +11,20 @@
#include <QTimer>
#include <QtDebug>
-MediaDiscoveryBackend::MediaDiscoveryBackend(QObject *parent)
+MediaDiscoveryBackend::MediaDiscoveryBackend(const QVariantMap &serviceSettings, QObject *parent)
: QIfMediaDeviceDiscoveryModelBackendInterface(parent)
{
m_deviceFolder = QDir::homePath() + "/usb-simulation";
- const QByteArray customDeviceFolder = qgetenv("QTIFMEDIA_SIMULATOR_DEVICEFOLDER");
+
+ QString customDeviceFolder = serviceSettings.value(QStringLiteral("customDeviceFolder")).toString();
+ if (qEnvironmentVariableIsSet("QTIFMEDIA_SIMULATOR_DEVICEFOLDER")) {
+ qCInfo(media) << "QTIFMEDIA_SIMULATOR_DEVICEFOLDER environment variable is set.\n"
+ << "Overriding service setting: 'customDeviceFolder'";
+ customDeviceFolder = qgetenv("QTIFMEDIA_SIMULATOR_DEVICEFOLDER");
+ }
+
if (customDeviceFolder.isEmpty())
- qCCritical(media) << "QTIFMEDIA_SIMULATOR_DEVICEFOLDER environment variable is not set, falling back to:" << m_deviceFolder;
+ qCInfo(media) << "The service setting 'customDeviceFolder' is not set, falling back to:" << m_deviceFolder;
else
m_deviceFolder = customDeviceFolder;
diff --git a/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.h b/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.h
index 7f5f1a9a..9de36dca 100644
--- a/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.h
+++ b/src/plugins/ifmedia/media_simulator/mediadiscoverybackend.h
@@ -16,7 +16,7 @@ class MediaDiscoveryBackend : public QIfMediaDeviceDiscoveryModelBackendInterfac
Q_OBJECT
public:
- MediaDiscoveryBackend(QObject *parent = nullptr);
+ MediaDiscoveryBackend(const QVariantMap &serviceSettings, QObject *parent = nullptr);
void initialize() override;
diff --git a/src/plugins/ifmedia/media_simulator/mediaindexerbackend.cpp b/src/plugins/ifmedia/media_simulator/mediaindexerbackend.cpp
index 58c6975c..13c62b98 100644
--- a/src/plugins/ifmedia/media_simulator/mediaindexerbackend.cpp
+++ b/src/plugins/ifmedia/media_simulator/mediaindexerbackend.cpp
@@ -28,7 +28,7 @@
#include <tstring.h>
#endif
-MediaIndexerBackend::MediaIndexerBackend(const QSqlDatabase &database, QObject *parent)
+MediaIndexerBackend::MediaIndexerBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent)
: QIfMediaIndexerControlBackendInterface(parent)
, m_db(database)
, m_state(QIfMediaIndexerControl::Idle)
@@ -38,10 +38,16 @@ MediaIndexerBackend::MediaIndexerBackend(const QSqlDatabase &database, QObject *
connect(&m_watcher, &QFutureWatcherBase::finished, this, &MediaIndexerBackend::onScanFinished);
+ QString customMediaFolder = serviceSettings.value(QStringLiteral("customMediaFolder")).toString();
+ if (qEnvironmentVariableIsSet("QTIFMEDIA_SIMULATOR_LOCALMEDIAFOLDER")) {
+ qCInfo(media) << "QTIFMEDIA_SIMULATOR_LOCALMEDIAFOLDER environment variable is set.\n"
+ << "Overriding service setting: 'customMediaFolder'";
+ customMediaFolder = qgetenv("QTIFMEDIA_SIMULATOR_LOCALMEDIAFOLDER");
+ }
+
QStringList mediaFolderList;
- const QByteArray customMediaFolder = qgetenv("QTIFMEDIA_SIMULATOR_LOCALMEDIAFOLDER");
if (!customMediaFolder.isEmpty()) {
- qCInfo(media) << "QTIFMEDIA_SIMULATOR_LOCALMEDIAFOLDER environment variable is set to:" << customMediaFolder;
+ qCInfo(media) << "The service setting 'customMediaFolder' is set to:" << customMediaFolder;
mediaFolderList.append(customMediaFolder);
} else {
mediaFolderList = QStandardPaths::standardLocations(QStandardPaths::MusicLocation);
diff --git a/src/plugins/ifmedia/media_simulator/mediaindexerbackend.h b/src/plugins/ifmedia/media_simulator/mediaindexerbackend.h
index 76e55b08..4251ea01 100644
--- a/src/plugins/ifmedia/media_simulator/mediaindexerbackend.h
+++ b/src/plugins/ifmedia/media_simulator/mediaindexerbackend.h
@@ -21,7 +21,7 @@ class MediaIndexerBackend : public QIfMediaIndexerControlBackendInterface
struct ScanData;
public:
- explicit MediaIndexerBackend(const QSqlDatabase &database, QObject *parent = nullptr);
+ explicit MediaIndexerBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent = nullptr);
void initialize() override;
void pause() override;
diff --git a/src/plugins/ifmedia/media_simulator/mediaplayerbackend.cpp b/src/plugins/ifmedia/media_simulator/mediaplayerbackend.cpp
index e4137c4d..558deb76 100644
--- a/src/plugins/ifmedia/media_simulator/mediaplayerbackend.cpp
+++ b/src/plugins/ifmedia/media_simulator/mediaplayerbackend.cpp
@@ -16,7 +16,7 @@
#include <QThreadPool>
#include <QtDebug>
-MediaPlayerBackend::MediaPlayerBackend(const QSqlDatabase &database, QObject *parent)
+MediaPlayerBackend::MediaPlayerBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent)
: QIfMediaPlayerBackendInterface(parent)
, m_count(0)
, m_currentIndex(-1)
@@ -26,6 +26,8 @@ MediaPlayerBackend::MediaPlayerBackend(const QSqlDatabase &database, QObject *pa
, m_threadPool(new QThreadPool(this))
, m_player(new QMediaPlayer(this))
{
+ Q_UNUSED(serviceSettings)
+
qRegisterMetaType<QIfAudioTrackItem>();
m_player->setAudioOutput(new QAudioOutput(m_player));
diff --git a/src/plugins/ifmedia/media_simulator/mediaplayerbackend.h b/src/plugins/ifmedia/media_simulator/mediaplayerbackend.h
index c7bc7be7..9e820557 100644
--- a/src/plugins/ifmedia/media_simulator/mediaplayerbackend.h
+++ b/src/plugins/ifmedia/media_simulator/mediaplayerbackend.h
@@ -36,7 +36,7 @@ public:
};
Q_ENUM(OperationType)
- MediaPlayerBackend(const QSqlDatabase &database, QObject *parent = nullptr);
+ MediaPlayerBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent = nullptr);
void initialize() override;
void play() override;
diff --git a/src/plugins/ifmedia/media_simulator/mediaplugin.cpp b/src/plugins/ifmedia/media_simulator/mediaplugin.cpp
index 01ab8ee9..04f9666c 100644
--- a/src/plugins/ifmedia/media_simulator/mediaplugin.cpp
+++ b/src/plugins/ifmedia/media_simulator/mediaplugin.cpp
@@ -21,15 +21,23 @@
MediaSimulatorPlugin::MediaSimulatorPlugin(QObject *parent)
: QObject(parent)
- , m_discovery(new MediaDiscoveryBackend(this))
+ , m_player(nullptr)
+ , m_browse(nullptr)
+ , m_discovery(nullptr)
+ , m_indexer(nullptr)
{
- QString dbFile = mediaDatabaseFile();
+}
+
+void MediaSimulatorPlugin::createInstances()
+{
+ QString dbFile = mediaDatabaseFile(m_serviceSettings);
createMediaDatabase(dbFile);
- m_player = new MediaPlayerBackend(createDatabaseConnection(QStringLiteral("player"), dbFile), this);
- m_browse = new SearchAndBrowseBackend(createDatabaseConnection(QStringLiteral("model"), dbFile), this);
- m_indexer = new MediaIndexerBackend(createDatabaseConnection(QStringLiteral("indexer"), dbFile), this);
+ m_player = new MediaPlayerBackend(m_serviceSettings, createDatabaseConnection(QStringLiteral("player"), dbFile), this);
+ m_browse = new SearchAndBrowseBackend(m_serviceSettings, createDatabaseConnection(QStringLiteral("model"), dbFile), this);
+ m_indexer = new MediaIndexerBackend(m_serviceSettings, createDatabaseConnection(QStringLiteral("indexer"), dbFile), this);
+ m_discovery = new MediaDiscoveryBackend(m_serviceSettings, this);
auto deviceMap = m_discovery->deviceMap();
for (auto it = deviceMap.cbegin(); it != deviceMap.cend(); it++) {
@@ -60,6 +68,9 @@ QStringList MediaSimulatorPlugin::interfaces() const
QIfFeatureInterface *MediaSimulatorPlugin::interfaceInstance(const QString &interface) const
{
+ if (!m_player)
+ const_cast<MediaSimulatorPlugin*>(this)->createInstances();
+
if (interface == QStringLiteral(QIfMediaPlayer_iid))
return m_player;
else if (interface == QStringLiteral(QIfFilterAndBrowseModel_iid))
@@ -71,3 +82,14 @@ QIfFeatureInterface *MediaSimulatorPlugin::interfaceInstance(const QString &inte
return nullptr;
}
+
+QString MediaSimulatorPlugin::configurationId() const
+{
+ return QStringLiteral("qtifmedia");
+}
+
+void MediaSimulatorPlugin::updateServiceSettings(const QVariantMap &settings)
+{
+ qCDebug(media) << Q_FUNC_INFO << settings;
+ m_serviceSettings = settings;
+}
diff --git a/src/plugins/ifmedia/media_simulator/mediaplugin.h b/src/plugins/ifmedia/media_simulator/mediaplugin.h
index 4e0ea91b..b2f0b84c 100644
--- a/src/plugins/ifmedia/media_simulator/mediaplugin.h
+++ b/src/plugins/ifmedia/media_simulator/mediaplugin.h
@@ -29,12 +29,17 @@ public:
QStringList interfaces() const override;
QIfFeatureInterface *interfaceInstance(const QString &interface) const override;
+ QString configurationId() const override;
+ void updateServiceSettings(const QVariantMap &settings) override;
+
private:
+ void createInstances();
MediaPlayerBackend *m_player;
SearchAndBrowseBackend *m_browse;
MediaDiscoveryBackend *m_discovery;
MediaIndexerBackend *m_indexer;
+ QVariantMap m_serviceSettings;
};
#endif // MEDIAPLUGIN_H
diff --git a/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.cpp b/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.cpp
index ce59ce11..d8649c62 100644
--- a/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.cpp
+++ b/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.cpp
@@ -43,10 +43,12 @@ QDataStream &operator>>(QDataStream &stream, SearchAndBrowseItem &obj)
return stream;
}
-SearchAndBrowseBackend::SearchAndBrowseBackend(const QSqlDatabase &database, QObject *parent)
+SearchAndBrowseBackend::SearchAndBrowseBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent)
: QIfFilterAndBrowseModelInterface(parent)
, m_threadPool(new QThreadPool(this))
{
+ Q_UNUSED(serviceSettings)
+
m_threadPool->setMaxThreadCount(1);
qRegisterMetaType<SearchAndBrowseItem>();
diff --git a/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.h b/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.h
index 176e0aa1..db8fbefa 100644
--- a/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.h
+++ b/src/plugins/ifmedia/media_simulator/searchandbrowsebackend.h
@@ -41,7 +41,7 @@ class SearchAndBrowseBackend : public QIfFilterAndBrowseModelInterface
Q_PROPERTY(QStringList availableContentTypes READ availableContentTypes CONSTANT)
public:
- explicit SearchAndBrowseBackend(const QSqlDatabase &database, QObject *parent = nullptr);
+ explicit SearchAndBrowseBackend(const QVariantMap &serviceSettings, const QSqlDatabase &database, QObject *parent = nullptr);
QStringList availableContentTypes() const;
diff --git a/src/tools/media-simulation-server/main.cpp b/src/tools/media-simulation-server/main.cpp
index ebfdf73b..923434a7 100644
--- a/src/tools/media-simulation-server/main.cpp
+++ b/src/tools/media-simulation-server/main.cpp
@@ -5,6 +5,7 @@
#include <QGuiApplication>
#include <QDir>
#include <QLockFile>
+#include <QIfConfiguration>
#include "database_helper.h"
@@ -41,13 +42,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- QString dbFile = mediaDatabaseFile();
+ QVariantMap serviceSettings = QIfConfiguration::serviceSettings("ifmedia");
+ QString dbFile = mediaDatabaseFile(serviceSettings);
createMediaDatabase(dbFile);
- MediaIndexerBackend *indexerBackend = new MediaIndexerBackend(createDatabaseConnection(QStringLiteral("indexer"), dbFile), qApp);
- MediaPlayerBackend *playerBackend = new MediaPlayerBackend(createDatabaseConnection(QStringLiteral("player"), dbFile), qApp);
- MediaDiscoveryBackend *discoveryBackend = new MediaDiscoveryBackend(qApp);
- SearchAndBrowseBackend *searchAndBrowseBackend = new SearchAndBrowseBackend(createDatabaseConnection(QStringLiteral("model"), dbFile), qApp);
+ MediaIndexerBackend *indexerBackend = new MediaIndexerBackend(serviceSettings, createDatabaseConnection(QStringLiteral("indexer"), dbFile), qApp);
+ MediaPlayerBackend *playerBackend = new MediaPlayerBackend(serviceSettings, createDatabaseConnection(QStringLiteral("player"), dbFile), qApp);
+ MediaDiscoveryBackend *discoveryBackend = new MediaDiscoveryBackend(serviceSettings, qApp);
+ SearchAndBrowseBackend *searchAndBrowseBackend = new SearchAndBrowseBackend(serviceSettings, createDatabaseConnection(QStringLiteral("model"), dbFile), qApp);
auto deviceMap = discoveryBackend->deviceMap();
for (auto it = deviceMap.cbegin(); it != deviceMap.cend(); it++) {