summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2016-06-06 13:42:28 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2016-06-09 13:50:23 +0000
commit50f83270d9c018385844821077b0d432415839b3 (patch)
tree0dadc68da4ff49dc5ad51d0aaa247cdd1a368ece
parent031ec848087728a4d090cdf9a5a412ed7fb415c0 (diff)
downloadqtivi-50f83270d9c018385844821077b0d432415839b3.tar.gz
Extended the mediaplayer example and the media simulator plugin
The Mediaplayer shows now the discovered media devices and the list can be used to navigate thru the device content. The media_simulator uses a QFileSystemWatcher to watch for changes in a specific folder and every new folder acts as a detected USBMediaDevice which can be browsed using a SearchAndBrowseModel Change-Id: Ibef7447d4e43eb8b622cf90f4c6fb01c24caab7e Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--examples/media/mediaplayer/main.qml75
-rw-r--r--src/plugins/ivimedia/media_simulator/media_simulator.json2
-rw-r--r--src/plugins/ivimedia/media_simulator/media_simulator.pro10
-rw-r--r--src/plugins/ivimedia/media_simulator/mediadiscoverybackend.cpp99
-rw-r--r--src/plugins/ivimedia/media_simulator/mediadiscoverybackend.h69
-rw-r--r--src/plugins/ivimedia/media_simulator/mediaplayerbackend.cpp9
-rw-r--r--src/plugins/ivimedia/media_simulator/mediaplayerbackend.h2
-rw-r--r--src/plugins/ivimedia/media_simulator/mediaplugin.cpp16
-rw-r--r--src/plugins/ivimedia/media_simulator/mediaplugin.h4
-rw-r--r--src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp9
-rw-r--r--src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h2
-rw-r--r--src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp122
-rw-r--r--src/plugins/ivimedia/media_simulator/usbbrowsebackend.h63
-rw-r--r--src/plugins/ivimedia/media_simulator/usbdevice.cpp77
-rw-r--r--src/plugins/ivimedia/media_simulator/usbdevice.h66
15 files changed, 600 insertions, 25 deletions
diff --git a/examples/media/mediaplayer/main.qml b/examples/media/mediaplayer/main.qml
index f7a1c3f..80448c9 100644
--- a/examples/media/mediaplayer/main.qml
+++ b/examples/media/mediaplayer/main.qml
@@ -58,8 +58,8 @@ import QtIvi.Media 1.0
ApplicationWindow {
visible: true
- width: 640
- height: 480
+ width: 800
+ height: 600
title: qsTr("Media Player")
MediaPlayer {
@@ -152,7 +152,7 @@ ApplicationWindow {
spacing: 8
clip: true
Layout.fillHeight: true
- Layout.fillWidth: true
+ Layout.minimumWidth: 300
header: Rectangle {
width: ListView.view.width
@@ -191,7 +191,6 @@ ApplicationWindow {
id: column
width: parent.width
- Text { text: "Index: " + index }
Text { text: "Name: " + model.name }
Text { text: "Type: " + model.item.type }
Text { text: "CanForward: " + model.canGoForward }
@@ -209,5 +208,73 @@ ApplicationWindow {
}
}
}
+
+ ColumnLayout {
+ ListView {
+ id: browseView
+ spacing: 8
+ clip: true
+ Layout.fillHeight: true
+ Layout.minimumWidth: 300
+
+ header: Rectangle {
+ width: ListView.view.width
+ height: browseView.model !== discoveryModel ? 50 : 0
+ visible: height > 0
+ color: "#efefef"
+
+ Text {
+ anchors.centerIn: parent
+ text: "back"
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ if (filterModel.canGoBack)
+ filterModel.goBack()
+ else
+ browseView.model = discoveryModel
+ }
+ }
+ }
+
+ model: MediaDeviceDiscoveryModel {
+ id: discoveryModel
+ }
+
+ SearchAndBrowseModel {
+ id: filterModel
+ contentType: "file"
+ }
+
+ delegate: Rectangle {
+ width: ListView.view.width
+ height: column.height
+ color: "#efefef"
+
+ Column {
+ id: column
+ width: parent.width
+
+ Text { text: "Name: " + model.name }
+ Text { text: "Type: " + model.item.type }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ if (browseView.model === discoveryModel) {
+ filterModel.serviceObject = model.item
+ browseView.model = filterModel
+ return;
+ }
+
+ filterModel.goForward(index, SearchAndBrowseModel.InModelNavigation)
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/src/plugins/ivimedia/media_simulator/media_simulator.json b/src/plugins/ivimedia/media_simulator/media_simulator.json
index 4fd7713..74b66c2 100644
--- a/src/plugins/ivimedia/media_simulator/media_simulator.json
+++ b/src/plugins/ivimedia/media_simulator/media_simulator.json
@@ -1,3 +1,3 @@
{
- "interfaces" : [ "com.qt-project.qtivi.MediaPlayer", "com.qt-project.qtivi.SearchAndBrowseModel" ]
+ "interfaces" : [ "com.qt-project.qtivi.MediaPlayer", "com.qt-project.qtivi.SearchAndBrowseModel", "com.qt-project.qtivi.MediaDiscovery" ]
}
diff --git a/src/plugins/ivimedia/media_simulator/media_simulator.pro b/src/plugins/ivimedia/media_simulator/media_simulator.pro
index f89d3d4..423fffe 100644
--- a/src/plugins/ivimedia/media_simulator/media_simulator.pro
+++ b/src/plugins/ivimedia/media_simulator/media_simulator.pro
@@ -14,9 +14,15 @@ DISTFILES += media_simulator.json
HEADERS += \
mediaplugin.h \
mediaplayerbackend.h \
- searchandbrowsebackend.h
+ searchandbrowsebackend.h \
+ mediadiscoverybackend.h \
+ usbdevice.h \
+ usbbrowsebackend.h
SOURCES += \
mediaplugin.cpp \
mediaplayerbackend.cpp \
- searchandbrowsebackend.cpp
+ searchandbrowsebackend.cpp \
+ mediadiscoverybackend.cpp \
+ usbdevice.cpp \
+ usbbrowsebackend.cpp
diff --git a/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.cpp b/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.cpp
new file mode 100644
index 0000000..fabb4c9
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#include "mediadiscoverybackend.h"
+#include "usbdevice.h"
+
+#include <QDir>
+#include <QtDebug>
+
+MediaDiscoveryBackend::MediaDiscoveryBackend(QObject *parent)
+ : QIviMediaDeviceDiscoveryModelBackendInterface(parent)
+{
+ m_deviceFolder = QDir::homePath() + "/usb-simulation";
+ const QByteArray customDeviceFolder = qgetenv("QTIVIMEDIA_SIMULATOR_DEVICEFOLDER");
+ if (customDeviceFolder.isEmpty())
+ qCritical() << "QTIVIMEDIA_SIMULATOR_DEVICEFOLDER environment variable is not set, falling back to:" << m_deviceFolder;
+ else
+ m_deviceFolder = customDeviceFolder;
+
+}
+
+void MediaDiscoveryBackend::initialize()
+{
+#ifndef QT_NO_FILESYSTEMWATCHER
+ m_watcher.addPath(m_deviceFolder);
+ connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &MediaDiscoveryBackend::onDirectoryChanged);
+#endif
+
+ QDir deviceFolder(m_deviceFolder);
+ for (const QString &folder : deviceFolder.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ qDebug() << "Adding USB Device for: " << folder;
+ m_deviceMap.insert(folder, new USBDevice(deviceFolder.absoluteFilePath(folder)));
+ }
+ emit availableDevices(m_deviceMap.values());
+}
+
+void MediaDiscoveryBackend::onDirectoryChanged(const QString &path)
+{
+ Q_UNUSED(path)
+ QDir deviceFolder(m_deviceFolder);
+
+ //Check for removed Devices
+ for (const QString &folder : m_deviceMap.keys()) {
+ if (!deviceFolder.exists(folder)) {
+ qDebug() << "Removing USB Device for: " << folder;
+ QIviServiceObject *device = m_deviceMap.take(folder);
+ emit deviceRemoved(device);
+ }
+ }
+
+ //Check for newly added Devices
+ for (const QString &folder : deviceFolder.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ if (m_deviceMap.contains(folder))
+ continue;
+
+ qDebug() << "Adding USB Device for: " << folder;
+ USBDevice *device = new USBDevice(deviceFolder.absoluteFilePath(folder));
+ m_deviceMap.insert(folder, device);
+ emit deviceAdded(device);
+ }
+}
diff --git a/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.h b/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.h
new file mode 100644
index 0000000..9a10f91
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/mediadiscoverybackend.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef MEDIADISCOVERYBACKEND_H
+#define MEDIADISCOVERYBACKEND_H
+
+#include <QtIviMedia/QIviMediaDeviceDiscoveryModelBackendInterface>
+#include <QtIviMedia/QIviMediaDeviceDiscoveryModel>
+#include <QFileSystemWatcher>
+
+class MediaDiscoveryBackend : public QIviMediaDeviceDiscoveryModelBackendInterface
+{
+ Q_OBJECT
+
+public:
+ MediaDiscoveryBackend(QObject *parent = 0);
+
+ void initialize() Q_DECL_OVERRIDE;
+
+private slots:
+ void onDirectoryChanged(const QString &path);
+
+private:
+ QString m_deviceFolder;
+#ifndef QT_NO_FILESYSTEMWATCHER
+ QFileSystemWatcher m_watcher;
+#endif
+ QMap<QString, QIviServiceObject*> m_deviceMap;
+};
+
+#endif // MEDIADISCOVERYBACKEND_H
diff --git a/src/plugins/ivimedia/media_simulator/mediaplayerbackend.cpp b/src/plugins/ivimedia/media_simulator/mediaplayerbackend.cpp
index bd2d768..ecd2fb3 100644
--- a/src/plugins/ivimedia/media_simulator/mediaplayerbackend.cpp
+++ b/src/plugins/ivimedia/media_simulator/mediaplayerbackend.cpp
@@ -49,7 +49,7 @@
#include <QtConcurrent/QtConcurrent>
#include <QtDebug>
-MediaPlayerBackend::MediaPlayerBackend(QObject *parent)
+MediaPlayerBackend::MediaPlayerBackend(const QSqlDatabase &database, QObject *parent)
: QIviMediaPlayerBackendInterface(parent)
, m_player(new QMediaPlayer(this))
{
@@ -58,12 +58,7 @@ MediaPlayerBackend::MediaPlayerBackend(QObject *parent)
connect(m_player, &QMediaPlayer::positionChanged,
this, &MediaPlayerBackend::positionChanged);
- m_db = QSqlDatabase::addDatabase("QSQLITE");
- const QByteArray database = qgetenv("QTIVIMEDIA_SIMULATOR_DATABASE");
- if (database.isEmpty()) {
- qCritical() << "QTIVIMEDIA_SIMULATOR_DATABASE environment variable needs to be set to a valid database file location.";
- }
- m_db.setDatabaseName(database);
+ m_db = database;
m_db.open();
QSqlQuery query = m_db.exec(QLatin1String("CREATE TABLE IF NOT EXISTS \"queue\" (\"id\" INTEGER PRIMARY KEY, \"qindex\" INTEGER, \"track_index\" INTEGER)"));
diff --git a/src/plugins/ivimedia/media_simulator/mediaplayerbackend.h b/src/plugins/ivimedia/media_simulator/mediaplayerbackend.h
index 3ab7620..d5bdbfc 100644
--- a/src/plugins/ivimedia/media_simulator/mediaplayerbackend.h
+++ b/src/plugins/ivimedia/media_simulator/mediaplayerbackend.h
@@ -61,7 +61,7 @@ public:
};
Q_ENUM(OperationType)
- MediaPlayerBackend(QObject *parent = Q_NULLPTR);
+ MediaPlayerBackend(const QSqlDatabase &database, QObject *parent = Q_NULLPTR);
virtual void initialize() Q_DECL_OVERRIDE;
virtual void play() Q_DECL_OVERRIDE;
diff --git a/src/plugins/ivimedia/media_simulator/mediaplugin.cpp b/src/plugins/ivimedia/media_simulator/mediaplugin.cpp
index 26370d6..f7840ed 100644
--- a/src/plugins/ivimedia/media_simulator/mediaplugin.cpp
+++ b/src/plugins/ivimedia/media_simulator/mediaplugin.cpp
@@ -43,17 +43,26 @@
#include "mediaplugin.h"
#include "mediaplayerbackend.h"
#include "searchandbrowsebackend.h"
+#include "mediadiscoverybackend.h"
#include <QtIviMedia/QIviMediaPlayer>
#include <QtIviCore/QIviSearchAndBrowseModel>
#include <QStringList>
+#include <QtDebug>
MediaPlugin::MediaPlugin(QObject *parent)
: QObject(parent)
- , m_player(new MediaPlayerBackend(this))
- , m_browse(new SearchAndBrowseBackend(this))
+ , m_discovery(new MediaDiscoveryBackend(this))
{
+ m_db = QSqlDatabase::addDatabase("QSQLITE");
+ const QByteArray database = qgetenv("QTIVIMEDIA_SIMULATOR_DATABASE");
+ if (database.isEmpty()) {
+ qCritical() << "QTIVIMEDIA_SIMULATOR_DATABASE environment variable needs to be set to a valid database file location.";
+ }
+ m_db.setDatabaseName(database);
+ m_player = new MediaPlayerBackend(m_db, this);
+ m_browse = new SearchAndBrowseBackend(m_db, this);
}
QStringList MediaPlugin::interfaces() const
@@ -61,6 +70,7 @@ QStringList MediaPlugin::interfaces() const
QStringList list;
list << QIviStringMediaPlayerInterfaceName;
list << QIviStringSearchAndBrowseModelInterfaceName;
+ list << QIviStringMediaDeviceDiscoveryInterfaceName;
return list;
}
@@ -70,6 +80,8 @@ QObject *MediaPlugin::interfaceInstance(const QString &interface) const
return m_player;
else if (interface == QIviStringSearchAndBrowseModelInterfaceName)
return m_browse;
+ else if (interface == QIviStringMediaDeviceDiscoveryInterfaceName)
+ return m_discovery;
return 0;
}
diff --git a/src/plugins/ivimedia/media_simulator/mediaplugin.h b/src/plugins/ivimedia/media_simulator/mediaplugin.h
index 9dd3928..7e010ca 100644
--- a/src/plugins/ivimedia/media_simulator/mediaplugin.h
+++ b/src/plugins/ivimedia/media_simulator/mediaplugin.h
@@ -44,9 +44,11 @@
#define MEDIAPLUGIN_H
#include <QtIviCore/QIviServiceInterface>
+#include <QSqlDatabase>
class MediaPlayerBackend;
class SearchAndBrowseBackend;
+class MediaDiscoveryBackend;
class MediaPlugin : public QObject, QIviServiceInterface
{
@@ -63,6 +65,8 @@ public:
private:
MediaPlayerBackend *m_player;
SearchAndBrowseBackend *m_browse;
+ MediaDiscoveryBackend *m_discovery;
+ QSqlDatabase m_db;
};
#endif // MEDIAPLUGIN_H
diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
index 71f7fcc..977e8df 100644
--- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
+++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
@@ -47,7 +47,7 @@
#include <QtConcurrent/QtConcurrent>
#include <QtDebug>
-SearchAndBrowseBackend::SearchAndBrowseBackend(QObject *parent)
+SearchAndBrowseBackend::SearchAndBrowseBackend(const QSqlDatabase &database, QObject *parent)
: QIviSearchAndBrowseModelInterface(parent)
{
qRegisterMetaType<SearchAndBrowseItem>();
@@ -56,12 +56,7 @@ SearchAndBrowseBackend::SearchAndBrowseBackend(QObject *parent)
registerContentType<SearchAndBrowseItem>("album");
registerContentType<TrackItem>("track");
- m_db = QSqlDatabase::addDatabase("QSQLITE");
- const QByteArray database = qgetenv("QTIVIMEDIA_SIMULATOR_DATABASE");
- if (database.isEmpty()) {
- qCritical() << "QTIVIMEDIA_SIMULATOR_DATABASE environment variable needs to be set to a valid database file location.";
- }
- m_db.setDatabaseName(database);
+ m_db = database;
m_db.open();
}
diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
index 2f7e249..4619706 100644
--- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
+++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
@@ -96,7 +96,7 @@ class SearchAndBrowseBackend : public QIviSearchAndBrowseModelInterface
{
Q_OBJECT
public:
- explicit SearchAndBrowseBackend(QObject *parent = Q_NULLPTR);
+ explicit SearchAndBrowseBackend(const QSqlDatabase &database, QObject *parent = Q_NULLPTR);
virtual Flags supportedFlags() const Q_DECL_OVERRIDE;
virtual void fetchData(const QUuid &identifier, const QString &type, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms, int start, int count) Q_DECL_OVERRIDE;
diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp
new file mode 100644
index 0000000..eae79e9
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#include "usbbrowsebackend.h"
+#include <QDir>
+#include <QtDebug>
+
+UsbBrowseBackend::UsbBrowseBackend(const QString &path, QObject *parent)
+ : QIviSearchAndBrowseModelInterface(parent)
+ , m_rootFolder(path)
+{
+ qRegisterMetaType<SearchAndBrowseItem>();
+ registerContentType<SearchAndBrowseItem>("file");
+}
+
+QIviSearchAndBrowseModelInterface::Flags UsbBrowseBackend::supportedFlags() const
+{
+ return QIviSearchAndBrowseModelInterface::Flags(
+ QIviSearchAndBrowseModelInterface::SupportsSorting |
+ QIviSearchAndBrowseModelInterface::SupportsStatelessNavigation |
+ QIviSearchAndBrowseModelInterface::SupportsGetSize);
+}
+
+void UsbBrowseBackend::fetchData(const QUuid &identifier, const QString &type, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms, int start, int count)
+{
+ Q_UNUSED(term);
+ Q_UNUSED(orderTerms);
+
+ QVariantList list;
+ QString folder = m_rootFolder;
+ if (type != "file")
+ folder += type;
+ QDir dir(folder);
+ QFileInfoList infoList = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks);
+
+ emit countChanged(identifier, infoList.count());
+
+ for (int i = start; i < infoList.count() && i < count; i++) {
+ SearchAndBrowseItem item;
+ item.setType("file");
+ item.setName(infoList.at(i).fileName());
+ list.append(QVariant::fromValue(item));
+ }
+
+ emit dataFetched(identifier, list, start, list.count() >= count);
+}
+
+bool UsbBrowseBackend::canGoBack(const QUuid &identifier, const QString &type)
+{
+ Q_UNUSED(identifier)
+ return type != "file";
+}
+
+QString UsbBrowseBackend::goBack(const QUuid &identifier, const QString &type)
+{
+ Q_UNUSED(identifier)
+ QStringList types = type.split('/');
+
+ if (types.count() < 2 && type != "file")
+ return "file";
+
+ types.removeLast();
+ types.replace(types.count() - 1, types.at(types.count() - 1).split('?').at(0));
+
+ return types.join('/');
+}
+
+bool UsbBrowseBackend::canGoForward(const QUuid &identifier, const QString &type, const QString &itemId)
+{
+ Q_UNUSED(identifier);
+ if (type != "file")
+ return QDir(m_rootFolder + "/" + type + "/" + itemId).count();
+ else
+ return QDir(m_rootFolder + "/" + itemId).count();
+}
+
+QString UsbBrowseBackend::goForward(const QUuid &identifier, const QString &type, const QString &itemId)
+{
+ Q_UNUSED(identifier)
+ if (type != "file")
+ return type + "/" + itemId;
+ else
+ return itemId;
+}
diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h
new file mode 100644
index 0000000..bc724d9
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef USBBROWSEBACKEND_H
+#define USBBROWSEBACKEND_H
+
+#include "searchandbrowsebackend.h"
+
+class UsbBrowseBackend : public QIviSearchAndBrowseModelInterface
+{
+public:
+ UsbBrowseBackend(const QString &path, QObject *parent = 0);
+
+ virtual Flags supportedFlags() const Q_DECL_OVERRIDE;
+ virtual void fetchData(const QUuid &identifier, const QString &type, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms, int start, int count) Q_DECL_OVERRIDE;
+ virtual bool canGoBack(const QUuid &identifier, const QString &type) Q_DECL_OVERRIDE;
+ virtual QString goBack(const QUuid &identifier, const QString &type) Q_DECL_OVERRIDE;
+ virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) Q_DECL_OVERRIDE;
+ virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) Q_DECL_OVERRIDE;
+
+private:
+ QString m_rootFolder;
+};
+
+#endif // USBBROWSEBACKEND_H
diff --git a/src/plugins/ivimedia/media_simulator/usbdevice.cpp b/src/plugins/ivimedia/media_simulator/usbdevice.cpp
new file mode 100644
index 0000000..455e452
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/usbdevice.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#include "usbdevice.h"
+#include "usbbrowsebackend.h"
+#include <QtIviCore/QIviSearchAndBrowseModel>
+#include <QDir>
+
+USBDevice::USBDevice(const QString &folder, QObject *parent)
+ : QIviMediaUsbDevice(parent)
+ , m_browseModel(new UsbBrowseBackend(folder, this))
+ , m_folder(folder)
+{
+}
+
+QString USBDevice::name() const
+{
+ return QDir(m_folder).dirName();
+}
+
+void USBDevice::eject()
+{
+ qWarning("Ejecting a USB Device is not supported in the simulation");
+}
+
+QStringList USBDevice::interfaces() const
+{
+ QStringList list;
+ list << QIviStringSearchAndBrowseModelInterfaceName;
+ return list;
+}
+
+QObject *USBDevice::interfaceInstance(const QString &interface) const
+{
+ if (interface == QIviStringSearchAndBrowseModelInterfaceName)
+ return m_browseModel;
+
+ return nullptr;
+}
diff --git a/src/plugins/ivimedia/media_simulator/usbdevice.h b/src/plugins/ivimedia/media_simulator/usbdevice.h
new file mode 100644
index 0000000..b3c6b65
--- /dev/null
+++ b/src/plugins/ivimedia/media_simulator/usbdevice.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtIvi module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef USBDEVICE_H
+#define USBDEVICE_H
+
+#include <QtIviMedia/QIviMediaDevice>
+
+class UsbBrowseBackend;
+
+class USBDevice : public QIviMediaUsbDevice
+{
+ Q_OBJECT
+public:
+ explicit USBDevice(const QString &folder, QObject *parent = 0);
+
+ virtual QString name() const Q_DECL_OVERRIDE;
+ virtual void eject() Q_DECL_OVERRIDE;
+
+ virtual QStringList interfaces() const Q_DECL_OVERRIDE;
+ virtual QObject *interfaceInstance(const QString &interface) const Q_DECL_OVERRIDE;
+
+private:
+ UsbBrowseBackend *m_browseModel;
+ QString m_folder;
+};
+
+#endif // USBDEVICE_H