ConnectedDevices have a LibraryModel

This commit is contained in:
David Sansome 2010-06-25 23:38:21 +00:00
parent b750df38ce
commit 28ea240eb8
8 changed files with 128 additions and 14 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -45,6 +45,8 @@ public:
QStringList DeviceUniqueIDs();
QVariant DeviceInfo(const QString& id, int field);
ConnectedDevice* Connect(const QString &id, QObject *parent);
protected:
void Init();

View File

@ -19,6 +19,8 @@
#include <QAbstractItemModel>
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);

View File

@ -14,9 +14,11 @@
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)
: QObject(parent)
FilesystemDevice::FilesystemDevice(const QString& mount_point, QObject* parent)
: ConnectedDevice(parent)
{
backend_->AddDirectory(mount_point);
}

View File

@ -14,16 +14,16 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DEVICE_H
#define DEVICE_H
#ifndef FILESYSTEMDEVICE_H
#define FILESYSTEMDEVICE_H
#include <QObject>
#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