ConnectedDevices have a LibraryModel
This commit is contained in:
parent
b750df38ce
commit
28ea240eb8
|
@ -52,10 +52,11 @@ set(SOURCES
|
||||||
core/taskmanager.cpp
|
core/taskmanager.cpp
|
||||||
core/utilities.cpp
|
core/utilities.cpp
|
||||||
|
|
||||||
devices/device.cpp
|
devices/connecteddevice.cpp
|
||||||
devices/devicekitlister.cpp
|
devices/devicekitlister.cpp
|
||||||
devices/devicelister.cpp
|
devices/devicelister.cpp
|
||||||
devices/devicetest.cpp
|
devices/devicetest.cpp
|
||||||
|
devices/filesystemdevice.cpp
|
||||||
|
|
||||||
engines/enginebase.cpp
|
engines/enginebase.cpp
|
||||||
|
|
||||||
|
@ -173,10 +174,11 @@ set(HEADERS
|
||||||
core/songloader.h
|
core/songloader.h
|
||||||
core/taskmanager.h
|
core/taskmanager.h
|
||||||
|
|
||||||
devices/device.h
|
devices/connecteddevice.h
|
||||||
devices/devicekitlister.h
|
devices/devicekitlister.h
|
||||||
devices/devicelister.h
|
devices/devicelister.h
|
||||||
devices/devicetest.h
|
devices/devicetest.h
|
||||||
|
devices/filesystemdevice.h
|
||||||
|
|
||||||
engines/enginebase.h
|
engines/enginebase.h
|
||||||
|
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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<Database, MemoryDatabase>(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<LibraryBackend>();
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONNECTEDDEVICE_H
|
||||||
|
#define CONNECTEDDEVICE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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>* database_;
|
||||||
|
LibraryBackend* backend_;
|
||||||
|
LibraryModel* model_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONNECTEDDEVICE_H
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "devicekitlister.h"
|
#include "devicekitlister.h"
|
||||||
|
#include "filesystemdevice.h"
|
||||||
#include "dbus/udisks.h"
|
#include "dbus/udisks.h"
|
||||||
#include "dbus/udisksdevice.h"
|
#include "dbus/udisksdevice.h"
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ DeviceKitLister::DeviceData DeviceKitLister::ReadDeviceData(
|
||||||
// aren't partitions
|
// aren't partitions
|
||||||
if (device.deviceIsSystemInternal() ||
|
if (device.deviceIsSystemInternal() ||
|
||||||
device.devicePresentationHide() ||
|
device.devicePresentationHide() ||
|
||||||
|
device.deviceMountPaths().isEmpty() ||
|
||||||
!device.deviceIsPartition()) {
|
!device.deviceIsPartition()) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -195,9 +197,9 @@ void DeviceKitLister::DBusDeviceChanged(const QDBusObjectPath &path) {
|
||||||
DeviceData data = ReadDeviceData(path);
|
DeviceData data = ReadDeviceData(path);
|
||||||
|
|
||||||
if (already_known && !data.suitable)
|
if (already_known && !data.suitable)
|
||||||
DeviceRemoved(data.unique_id());
|
DBusDeviceRemoved(path);
|
||||||
else if (!already_known && data.suitable)
|
else if (!already_known && data.suitable)
|
||||||
DeviceAdded(data.unique_id());
|
DBusDeviceAdded(path);
|
||||||
else if (already_known && data.suitable) {
|
else if (already_known && data.suitable) {
|
||||||
{
|
{
|
||||||
QMutexLocker l(&mutex_);
|
QMutexLocker l(&mutex_);
|
||||||
|
@ -214,3 +216,7 @@ QString DeviceKitLister::FindUniqueIdByPath(const QDBusObjectPath &path) const {
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectedDevice* DeviceKitLister::Connect(const QString &id, QObject *parent) {
|
||||||
|
return new FilesystemDevice(DeviceInfo(id, Field_MountPath).toString(), parent);
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
QStringList DeviceUniqueIDs();
|
QStringList DeviceUniqueIDs();
|
||||||
QVariant DeviceInfo(const QString& id, int field);
|
QVariant DeviceInfo(const QString& id, int field);
|
||||||
|
|
||||||
|
ConnectedDevice* Connect(const QString &id, QObject *parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
|
class ConnectedDevice;
|
||||||
|
|
||||||
class DeviceLister : public QObject {
|
class DeviceLister : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -41,10 +43,14 @@ public:
|
||||||
// moved to the new thread.
|
// moved to the new thread.
|
||||||
void Start();
|
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 QStringList DeviceUniqueIDs() = 0;
|
||||||
virtual QVariant DeviceInfo(const QString& id, int field) = 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:
|
signals:
|
||||||
void DeviceAdded(const QString& id);
|
void DeviceAdded(const QString& id);
|
||||||
void DeviceRemoved(const QString& id);
|
void DeviceRemoved(const QString& id);
|
||||||
|
|
|
@ -14,9 +14,11 @@
|
||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "device.h"
|
#include "filesystemdevice.h"
|
||||||
|
#include "library/librarybackend.h"
|
||||||
|
|
||||||
Device::Device(QObject *parent)
|
FilesystemDevice::FilesystemDevice(const QString& mount_point, QObject* parent)
|
||||||
: QObject(parent)
|
: ConnectedDevice(parent)
|
||||||
{
|
{
|
||||||
|
backend_->AddDirectory(mount_point);
|
||||||
}
|
}
|
|
@ -14,16 +14,16 @@
|
||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DEVICE_H
|
#ifndef FILESYSTEMDEVICE_H
|
||||||
#define DEVICE_H
|
#define FILESYSTEMDEVICE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "connecteddevice.h"
|
||||||
|
|
||||||
class Device : public QObject {
|
class FilesystemDevice : public ConnectedDevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Device(QObject *parent = 0);
|
FilesystemDevice(const QString& mount_point, QObject* parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICE_H
|
#endif // FILESYSTEMDEVICE_H
|
Loading…
Reference in New Issue