2010-06-25 21:04:10 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-06-25 21:04:10 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-06-26 14:41:18 +02:00
|
|
|
#include "devicelister.h"
|
|
|
|
#include "devicemanager.h"
|
2010-06-26 01:38:21 +02:00
|
|
|
#include "filesystemdevice.h"
|
2012-02-12 14:41:50 +01:00
|
|
|
#include "core/application.h"
|
2010-06-26 01:38:21 +02:00
|
|
|
#include "library/librarybackend.h"
|
2010-07-04 01:00:07 +02:00
|
|
|
#include "library/librarymodel.h"
|
2010-06-26 14:41:18 +02:00
|
|
|
#include "library/librarywatcher.h"
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2012-02-26 16:05:46 +01:00
|
|
|
#include <QThread>
|
2010-06-26 14:41:18 +02:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
FilesystemDevice::FilesystemDevice(const QUrl& url, DeviceLister* lister,
|
|
|
|
const QString& unique_id,
|
|
|
|
DeviceManager* manager, Application* app,
|
|
|
|
int database_id, bool first_time)
|
|
|
|
: FilesystemMusicStorage(url.toLocalFile()),
|
|
|
|
ConnectedDevice(url, lister, unique_id, manager, app, database_id,
|
|
|
|
first_time),
|
|
|
|
watcher_(new LibraryWatcher),
|
|
|
|
watcher_thread_(new QThread(this)) {
|
2012-02-26 16:05:46 +01:00
|
|
|
watcher_->moveToThread(watcher_thread_);
|
|
|
|
watcher_thread_->start(QThread::IdlePriority);
|
2010-06-26 14:41:18 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
watcher_->set_device_name(
|
2019-01-21 10:06:48 +01:00
|
|
|
manager
|
2019-01-21 22:38:46 +01:00
|
|
|
->data(manager->ItemToIndex(manager->FindDeviceById(unique_id)),
|
2019-01-21 10:06:48 +01:00
|
|
|
DeviceManager::Role_FriendlyName)
|
|
|
|
.toString());
|
2020-01-12 08:34:35 +01:00
|
|
|
watcher_->set_backend(backend_.get());
|
2012-02-26 16:05:46 +01:00
|
|
|
watcher_->set_task_manager(app_->task_manager());
|
2010-06-26 14:41:18 +02:00
|
|
|
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(backend_.get(),
|
|
|
|
SIGNAL(DirectoryDiscovered(Directory, SubdirectoryList)), watcher_,
|
|
|
|
SLOT(AddDirectory(Directory, SubdirectoryList)));
|
2020-01-21 09:32:55 +01:00
|
|
|
// RemoveDirectory should be called from the sender's thread.
|
|
|
|
connect(backend_.get(), &LibraryBackend::DirectoryDeleted, watcher_,
|
|
|
|
&LibraryWatcher::RemoveDirectory, Qt::DirectConnection);
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(watcher_, SIGNAL(NewOrUpdatedSongs(SongList)), backend_.get(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(AddOrUpdateSongs(SongList)));
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(watcher_, SIGNAL(SongsMTimeUpdated(SongList)), backend_.get(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(UpdateMTimesOnly(SongList)));
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(watcher_, SIGNAL(SongsDeleted(SongList)), backend_.get(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(DeleteSongs(SongList)));
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(watcher_, SIGNAL(SubdirsDiscovered(SubdirectoryList)), backend_.get(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(AddOrUpdateSubdirs(SubdirectoryList)));
|
2020-01-12 08:34:35 +01:00
|
|
|
connect(watcher_, SIGNAL(SubdirsMTimeUpdated(SubdirectoryList)),
|
|
|
|
backend_.get(), SLOT(AddOrUpdateSubdirs(SubdirectoryList)));
|
|
|
|
connect(watcher_, SIGNAL(CompilationsNeedUpdating()), backend_.get(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(UpdateCompilations()));
|
2012-02-26 16:05:46 +01:00
|
|
|
connect(watcher_, SIGNAL(ScanStarted(int)), SIGNAL(TaskStarted(int)));
|
2020-01-13 10:02:40 +01:00
|
|
|
connect(watcher_, &LibraryWatcher::Error, app, &Application::AddError);
|
2010-08-08 19:41:06 +02:00
|
|
|
}
|
2010-06-26 14:41:18 +02:00
|
|
|
|
2010-08-08 19:41:06 +02:00
|
|
|
void FilesystemDevice::Init() {
|
|
|
|
InitBackendDirectory(url_.toLocalFile(), first_time_);
|
2010-07-04 14:10:44 +02:00
|
|
|
model_->Init();
|
2010-06-25 21:04:10 +02:00
|
|
|
}
|
2010-06-26 14:41:18 +02:00
|
|
|
|
|
|
|
FilesystemDevice::~FilesystemDevice() {
|
2019-02-20 09:03:44 +01:00
|
|
|
watcher_->Stop();
|
2012-02-26 16:05:46 +01:00
|
|
|
watcher_->deleteLater();
|
|
|
|
watcher_thread_->exit();
|
|
|
|
watcher_thread_->wait();
|
2010-06-26 14:41:18 +02:00
|
|
|
}
|