diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5700d274a..89dcdc2ab 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,10 +52,11 @@ set(SOURCES
core/taskmanager.cpp
core/utilities.cpp
- devices/device.cpp
+ devices/connecteddevice.cpp
devices/devicekitlister.cpp
devices/devicelister.cpp
devices/devicetest.cpp
+ devices/filesystemdevice.cpp
engines/enginebase.cpp
@@ -173,10 +174,11 @@ set(HEADERS
core/songloader.h
core/taskmanager.h
- devices/device.h
+ devices/connecteddevice.h
devices/devicekitlister.h
devices/devicelister.h
devices/devicetest.h
+ devices/filesystemdevice.h
engines/enginebase.h
diff --git a/src/devices/connecteddevice.cpp b/src/devices/connecteddevice.cpp
new file mode 100644
index 000000000..2adde5bfc
--- /dev/null
+++ b/src/devices/connecteddevice.cpp
@@ -0,0 +1,46 @@
+/* This file is part of Clementine.
+
+ Clementine is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Clementine is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Clementine. If not, see .
+*/
+
+#include "connecteddevice.h"
+#include "core/database.h"
+#include "library/library.h"
+#include "library/librarybackend.h"
+#include "library/librarymodel.h"
+
+ConnectedDevice::ConnectedDevice(QObject *parent)
+ : QObject(parent),
+ lister_(NULL),
+ database_(new BackgroundThreadImplementation(this)),
+ backend_(NULL),
+ model_(NULL)
+{
+ // Wait for the database thread to start
+ database_->Start(true);
+
+ // Create the backend in the database thread.
+ // The backend gets parented to the database.
+ backend_ = database_->CreateInThread();
+ backend_->Init(database_->Worker(), Library::kSongsTable, Library::kDirsTable,
+ Library::kSubdirsTable, Library::kFtsTable);
+
+ // Create the model
+ model_ = new LibraryModel(backend_, this);
+}
+
+void ConnectedDevice::set_lister(DeviceLister *lister, const QString &id) {
+ lister_ = lister;
+ unique_id_ = id;
+}
diff --git a/src/devices/connecteddevice.h b/src/devices/connecteddevice.h
new file mode 100644
index 000000000..596d3e64d
--- /dev/null
+++ b/src/devices/connecteddevice.h
@@ -0,0 +1,50 @@
+/* This file is part of Clementine.
+
+ Clementine is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Clementine is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Clementine. If not, see .
+*/
+
+#ifndef CONNECTEDDEVICE_H
+#define CONNECTEDDEVICE_H
+
+#include
+
+#include "core/backgroundthread.h"
+
+class Database;
+class DeviceLister;
+class LibraryBackend;
+class LibraryModel;
+
+class ConnectedDevice : public QObject {
+ Q_OBJECT
+
+public:
+ ConnectedDevice(QObject *parent = 0);
+
+ void set_lister(DeviceLister* lister, const QString& id);
+ DeviceLister* lister() const { return lister_; }
+ QString unique_id() const { return unique_id_; }
+
+ LibraryModel* model() const { return model_; }
+
+protected:
+ DeviceLister* lister_;
+ QString unique_id_;
+
+ BackgroundThread* database_;
+ LibraryBackend* backend_;
+ LibraryModel* model_;
+};
+
+#endif // CONNECTEDDEVICE_H
diff --git a/src/devices/devicekitlister.cpp b/src/devices/devicekitlister.cpp
index f7b8badac..fb61369f7 100644
--- a/src/devices/devicekitlister.cpp
+++ b/src/devices/devicekitlister.cpp
@@ -15,6 +15,7 @@
*/
#include "devicekitlister.h"
+#include "filesystemdevice.h"
#include "dbus/udisks.h"
#include "dbus/udisksdevice.h"
@@ -142,6 +143,7 @@ DeviceKitLister::DeviceData DeviceKitLister::ReadDeviceData(
// aren't partitions
if (device.deviceIsSystemInternal() ||
device.devicePresentationHide() ||
+ device.deviceMountPaths().isEmpty() ||
!device.deviceIsPartition()) {
return ret;
}
@@ -195,9 +197,9 @@ void DeviceKitLister::DBusDeviceChanged(const QDBusObjectPath &path) {
DeviceData data = ReadDeviceData(path);
if (already_known && !data.suitable)
- DeviceRemoved(data.unique_id());
+ DBusDeviceRemoved(path);
else if (!already_known && data.suitable)
- DeviceAdded(data.unique_id());
+ DBusDeviceAdded(path);
else if (already_known && data.suitable) {
{
QMutexLocker l(&mutex_);
@@ -214,3 +216,7 @@ QString DeviceKitLister::FindUniqueIdByPath(const QDBusObjectPath &path) const {
}
return QString();
}
+
+ConnectedDevice* DeviceKitLister::Connect(const QString &id, QObject *parent) {
+ return new FilesystemDevice(DeviceInfo(id, Field_MountPath).toString(), parent);
+}
diff --git a/src/devices/devicekitlister.h b/src/devices/devicekitlister.h
index d8e649ba5..a2cf083ab 100644
--- a/src/devices/devicekitlister.h
+++ b/src/devices/devicekitlister.h
@@ -45,6 +45,8 @@ public:
QStringList DeviceUniqueIDs();
QVariant DeviceInfo(const QString& id, int field);
+ ConnectedDevice* Connect(const QString &id, QObject *parent);
+
protected:
void Init();
diff --git a/src/devices/devicelister.h b/src/devices/devicelister.h
index 0583d7696..62cfe907a 100644
--- a/src/devices/devicelister.h
+++ b/src/devices/devicelister.h
@@ -19,6 +19,8 @@
#include
+class ConnectedDevice;
+
class DeviceLister : public QObject {
Q_OBJECT
@@ -41,10 +43,14 @@ public:
// moved to the new thread.
void Start();
- // Query information about the devices that are available. Thread-safe.
+ // Query information about the devices that are available. Must be thread-safe.
virtual QStringList DeviceUniqueIDs() = 0;
virtual QVariant DeviceInfo(const QString& id, int field) = 0;
+ // Create a new ConnectedDevice instance for the given device. Must be
+ // thread-safe.
+ virtual ConnectedDevice* Connect(const QString& id, QObject* parent) = 0;
+
signals:
void DeviceAdded(const QString& id);
void DeviceRemoved(const QString& id);
diff --git a/src/devices/device.cpp b/src/devices/filesystemdevice.cpp
similarity index 76%
rename from src/devices/device.cpp
rename to src/devices/filesystemdevice.cpp
index cdbbf852d..8de9e61f0 100644
--- a/src/devices/device.cpp
+++ b/src/devices/filesystemdevice.cpp
@@ -14,9 +14,11 @@
along with Clementine. If not, see .
*/
-#include "device.h"
+#include "filesystemdevice.h"
+#include "library/librarybackend.h"
-Device::Device(QObject *parent)
- : QObject(parent)
+FilesystemDevice::FilesystemDevice(const QString& mount_point, QObject* parent)
+ : ConnectedDevice(parent)
{
+ backend_->AddDirectory(mount_point);
}
diff --git a/src/devices/device.h b/src/devices/filesystemdevice.h
similarity index 75%
rename from src/devices/device.h
rename to src/devices/filesystemdevice.h
index 5e0ab69f9..bd874a786 100644
--- a/src/devices/device.h
+++ b/src/devices/filesystemdevice.h
@@ -14,16 +14,16 @@
along with Clementine. If not, see .
*/
-#ifndef DEVICE_H
-#define DEVICE_H
+#ifndef FILESYSTEMDEVICE_H
+#define FILESYSTEMDEVICE_H
-#include
+#include "connecteddevice.h"
-class Device : public QObject {
+class FilesystemDevice : public ConnectedDevice {
Q_OBJECT
public:
- Device(QObject *parent = 0);
+ FilesystemDevice(const QString& mount_point, QObject* parent = 0);
};
-#endif // DEVICE_H
+#endif // FILESYSTEMDEVICE_H