Merge pull request #6550 from jbroadus/remove-dir-by-id
Remove directory by id.
This commit is contained in:
commit
a207501e35
|
@ -241,30 +241,30 @@ void LibraryBackend::AddDirectory(const QString& path) {
|
|||
emit DirectoryDiscovered(dir, SubdirectoryList());
|
||||
}
|
||||
|
||||
void LibraryBackend::RemoveDirectory(const Directory& dir) {
|
||||
void LibraryBackend::RemoveDirectory(int dir_id) {
|
||||
QMutexLocker l(db_->Mutex());
|
||||
QSqlDatabase db(db_->Connect());
|
||||
|
||||
// Remove songs first
|
||||
DeleteSongs(FindSongsInDirectory(dir.id));
|
||||
DeleteSongs(FindSongsInDirectory(dir_id));
|
||||
|
||||
ScopedTransaction transaction(&db);
|
||||
|
||||
// Delete the subdirs that were in this directory
|
||||
QSqlQuery q(db);
|
||||
q.prepare(QString("DELETE FROM %1 WHERE directory = :id").arg(subdirs_table_));
|
||||
q.bindValue(":id", dir.id);
|
||||
q.bindValue(":id", dir_id);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q)) return;
|
||||
|
||||
// Now remove the directory itself
|
||||
q = QSqlQuery(db);
|
||||
q.prepare(QString("DELETE FROM %1 WHERE ROWID = :id").arg(dirs_table_));
|
||||
q.bindValue(":id", dir.id);
|
||||
q.bindValue(":id", dir_id);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q)) return;
|
||||
|
||||
emit DirectoryDeleted(dir);
|
||||
emit DirectoryDeleted(dir_id);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class LibraryBackendInterface : public QObject {
|
|||
virtual Song GetSongByUrl(const QUrl& url, qint64 beginning = 0) = 0;
|
||||
|
||||
virtual void AddDirectory(const QString& path) = 0;
|
||||
virtual void RemoveDirectory(const Directory& dir) = 0;
|
||||
virtual void RemoveDirectory(int dir_id) = 0;
|
||||
|
||||
virtual bool ExecQuery(LibraryQuery* q) = 0;
|
||||
};
|
||||
|
@ -186,7 +186,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||
Song GetSongByUrl(const QUrl& url, qint64 beginning = 0);
|
||||
|
||||
void AddDirectory(const QString& path);
|
||||
void RemoveDirectory(const Directory& dir);
|
||||
void RemoveDirectory(int dir_id);
|
||||
|
||||
bool ExecQuery(LibraryQuery* q);
|
||||
SongList ExecLibraryQuery(LibraryQuery* query);
|
||||
|
@ -225,7 +225,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||
signals:
|
||||
void DirectoryDiscovered(const Directory& dir,
|
||||
const SubdirectoryList& subdirs);
|
||||
void DirectoryDeleted(const Directory& dir);
|
||||
void DirectoryDeleted(int dir_id);
|
||||
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void SongsDeleted(const SongList& songs);
|
||||
|
|
|
@ -30,8 +30,7 @@ LibraryDirectoryModel::LibraryDirectoryModel(LibraryBackend* backend,
|
|||
backend_(backend) {
|
||||
connect(backend_, SIGNAL(DirectoryDiscovered(Directory, SubdirectoryList)),
|
||||
SLOT(DirectoryDiscovered(Directory)));
|
||||
connect(backend_, SIGNAL(DirectoryDeleted(Directory)),
|
||||
SLOT(DirectoryDeleted(Directory)));
|
||||
connect(backend_, SIGNAL(DirectoryDeleted(int)), SLOT(DirectoryDeleted(int)));
|
||||
}
|
||||
|
||||
LibraryDirectoryModel::~LibraryDirectoryModel() {}
|
||||
|
@ -52,9 +51,9 @@ void LibraryDirectoryModel::DirectoryDiscovered(const Directory& dir) {
|
|||
appendRow(item);
|
||||
}
|
||||
|
||||
void LibraryDirectoryModel::DirectoryDeleted(const Directory& dir) {
|
||||
void LibraryDirectoryModel::DirectoryDeleted(int dir_id) {
|
||||
for (int i = 0; i < rowCount(); ++i) {
|
||||
if (item(i, 0)->data(kIdRole).toInt() == dir.id) {
|
||||
if (item(i, 0)->data(kIdRole).toInt() == dir_id) {
|
||||
removeRow(i);
|
||||
storage_.removeAt(i);
|
||||
break;
|
||||
|
@ -71,11 +70,9 @@ void LibraryDirectoryModel::AddDirectory(const QString& path) {
|
|||
void LibraryDirectoryModel::RemoveDirectory(const QModelIndex& index) {
|
||||
if (!backend_ || !index.isValid()) return;
|
||||
|
||||
Directory dir;
|
||||
dir.path = index.data().toString();
|
||||
dir.id = index.data(kIdRole).toInt();
|
||||
int dir_id = index.data(kIdRole).toInt();
|
||||
|
||||
backend_->RemoveDirectory(dir);
|
||||
backend_->RemoveDirectory(dir_id);
|
||||
}
|
||||
|
||||
QVariant LibraryDirectoryModel::data(const QModelIndex& index, int role) const {
|
||||
|
|
|
@ -44,7 +44,7 @@ class LibraryDirectoryModel : public QStandardItemModel {
|
|||
private slots:
|
||||
// To be called by the backend
|
||||
void DirectoryDiscovered(const Directory& directories);
|
||||
void DirectoryDeleted(const Directory& directories);
|
||||
void DirectoryDeleted(int dir_id);
|
||||
|
||||
private:
|
||||
static const int kIdRole = Qt::UserRole + 1;
|
||||
|
|
|
@ -209,10 +209,10 @@ void LibraryWatcher::WatchList::StopAll() {
|
|||
}
|
||||
}
|
||||
|
||||
void LibraryWatcher::WatchList::Stop(const Directory& dir) {
|
||||
void LibraryWatcher::WatchList::Stop(int dir_id) {
|
||||
QMutexLocker l(&mutex_);
|
||||
if (list_.contains(dir.id)) {
|
||||
list_[dir.id].active_ = false;
|
||||
if (list_.contains(dir_id)) {
|
||||
list_[dir_id].active_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -662,21 +662,22 @@ void LibraryWatcher::RemoveWatch(const Directory& dir,
|
|||
}
|
||||
}
|
||||
|
||||
void LibraryWatcher::RemoveDirectory(const Directory& dir) {
|
||||
watched_dirs_.Stop(dir);
|
||||
void LibraryWatcher::RemoveDirectory(int dir_id) {
|
||||
watched_dirs_.Stop(dir_id);
|
||||
// Invoke the DoRemoveDirectory slot on the watcher's thread.
|
||||
QMetaObject::invokeMethod(this, "DoRemoveDirectory", Q_ARG(Directory, dir));
|
||||
QMetaObject::invokeMethod(this, "DoRemoveDirectory", Q_ARG(int, dir_id));
|
||||
}
|
||||
|
||||
void LibraryWatcher::DoRemoveDirectory(const Directory& dir) {
|
||||
rescan_queue_.remove(dir.id);
|
||||
watched_dirs_.Remove(dir.id);
|
||||
void LibraryWatcher::DoRemoveDirectory(int dir_id) {
|
||||
rescan_queue_.remove(dir_id);
|
||||
|
||||
const WatchedDir& dir = watched_dirs_.list_[dir_id];
|
||||
// Stop watching the directory's subdirectories
|
||||
for (const QString& subdir_path : subdir_mapping_.keys(dir)) {
|
||||
fs_watcher_->RemovePath(subdir_path);
|
||||
subdir_mapping_.remove(subdir_path);
|
||||
}
|
||||
watched_dirs_.Remove(dir_id);
|
||||
}
|
||||
|
||||
bool LibraryWatcher::FindSongByPath(const SongList& list, const QString& path,
|
||||
|
|
|
@ -58,7 +58,7 @@ class LibraryWatcher : public QObject {
|
|||
// This thread-safe method will cause a scan of this directory to cancel to
|
||||
// unblock the watcher thread. It will then invoke the DoRemoveDirectory on
|
||||
// the watcher's thread to complete the removal.
|
||||
void RemoveDirectory(const Directory& dir);
|
||||
void RemoveDirectory(int dir_id);
|
||||
|
||||
void Stop() { watched_dirs_.StopAll(); }
|
||||
|
||||
|
@ -161,7 +161,7 @@ class LibraryWatcher : public QObject {
|
|||
void RescanPathsNow();
|
||||
void ScanSubdirectory(const QString& path, const Subdirectory& subdir,
|
||||
ScanTransaction* t, bool force_noincremental = false);
|
||||
void DoRemoveDirectory(const Directory& dir);
|
||||
void DoRemoveDirectory(int dir_id);
|
||||
|
||||
private:
|
||||
static bool FindSongByPath(const SongList& list, const QString& path,
|
||||
|
@ -227,7 +227,7 @@ class LibraryWatcher : public QObject {
|
|||
public:
|
||||
// These may be called from a different thread.
|
||||
void StopAll();
|
||||
void Stop(const Directory& dir);
|
||||
void Stop(int dir_id);
|
||||
|
||||
// This should only be called on the watcher thread.
|
||||
void Remove(int id);
|
||||
|
|
Loading…
Reference in New Issue