Notify collection backend about renamed files when organising files
This commit is contained in:
parent
fc1a2dac90
commit
15c8f2a3ee
|
@ -323,6 +323,17 @@ SongList CollectionBackend::FindSongsInDirectory(int id) {
|
|||
|
||||
}
|
||||
|
||||
void CollectionBackend::SongPathChanged(const Song &song, const QFileInfo &new_file) {
|
||||
|
||||
// Take a song and update its path
|
||||
Song updated_song = song;
|
||||
updated_song.InitFromFilePartial(new_file.absoluteFilePath());
|
||||
SongList updated_songs;
|
||||
updated_songs << updated_song;
|
||||
AddOrUpdateSongs(updated_songs);
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::AddOrUpdateSubdirs(const SubdirectoryList &subdirs) {
|
||||
|
||||
QMutexLocker l(db_->Mutex());
|
||||
|
@ -575,10 +586,8 @@ QStringList CollectionBackend::GetAllArtistsWithAlbums(const QueryOptions &opt)
|
|||
}
|
||||
}
|
||||
|
||||
// QStringList ret;
|
||||
QSet<QString> artists;
|
||||
while (query.Next()) {
|
||||
//ret << query.Value(0).toString();
|
||||
artists << query.Value(0).toString();
|
||||
}
|
||||
|
||||
|
@ -586,8 +595,8 @@ QStringList CollectionBackend::GetAllArtistsWithAlbums(const QueryOptions &opt)
|
|||
artists << query2.Value(0).toString();
|
||||
}
|
||||
|
||||
// return ret;
|
||||
return QStringList(artists.toList());
|
||||
|
||||
}
|
||||
|
||||
CollectionBackend::AlbumList CollectionBackend::GetAllAlbums(const QueryOptions &opt) {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QFileInfo>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include <QSet>
|
||||
|
@ -194,6 +195,7 @@ class CollectionBackend : public CollectionBackendInterface {
|
|||
void IncrementPlayCount(int id);
|
||||
void IncrementSkipCount(int id, float progress);
|
||||
void ResetStatistics(int id);
|
||||
void SongPathChanged(const Song &song, const QFileInfo &new_file);
|
||||
|
||||
signals:
|
||||
void DirectoryDiscovered(const Directory &dir, const SubdirectoryList &subdirs);
|
||||
|
|
|
@ -655,7 +655,7 @@ SongList CollectionView::GetSelectedSongs() const {
|
|||
void CollectionView::Organise() {
|
||||
|
||||
if (!organise_dialog_)
|
||||
organise_dialog_.reset(new OrganiseDialog(app_->task_manager()));
|
||||
organise_dialog_.reset(new OrganiseDialog(app_->task_manager(), app_->collection_backend()));
|
||||
|
||||
organise_dialog_->SetDestinationModel(app_->collection_model()->directory_model());
|
||||
organise_dialog_->SetCopy(false);
|
||||
|
|
|
@ -197,7 +197,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
|||
//organise_dialog_(new OrganiseDialog(app_->task_manager())),
|
||||
equalizer_(new Equalizer),
|
||||
organise_dialog_([=]() {
|
||||
OrganiseDialog *dialog = new OrganiseDialog(app->task_manager());
|
||||
OrganiseDialog *dialog = new OrganiseDialog(app->task_manager(), app->collection_backend());
|
||||
dialog->SetDestinationModel(app->collection()->model()->directory_model());
|
||||
return dialog;
|
||||
}),
|
||||
|
|
|
@ -67,6 +67,7 @@ void RegisterMetaTypes() {
|
|||
qRegisterMetaType<const char*>("const char*");
|
||||
qRegisterMetaType<QList<int>>("QList<int>");
|
||||
qRegisterMetaType<QList<QUrl>>("QList<QUrl>");
|
||||
qRegisterMetaType<QFileInfo>("QFileInfo");
|
||||
qRegisterMetaType<QAbstractSocket::SocketState>();
|
||||
qRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState");
|
||||
qRegisterMetaType<QNetworkCookie>("QNetworkCookie");
|
||||
|
|
|
@ -216,6 +216,12 @@ void Organise::ProcessSomeFiles() {
|
|||
files_with_errors_ << task.song_info_.song_.basefilename();
|
||||
}
|
||||
else {
|
||||
if (job.remove_original_) {
|
||||
// Notify other aspects of system that song has been invalidated
|
||||
QString root = destination_->LocalPath();
|
||||
QFileInfo new_file = QFileInfo(root + "/" + task.song_info_.new_filename_);
|
||||
emit SongPathChanged(song, new_file);
|
||||
}
|
||||
if (job.mark_as_listened_) {
|
||||
emit FileCopied(job.metadata_.id());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QBasicTimer>
|
||||
#include <QFileInfo>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
|
@ -72,6 +73,7 @@ class Organise : public QObject {
|
|||
signals:
|
||||
void Finished(const QStringList &files_with_errors, QStringList);
|
||||
void FileCopied(int database_id);
|
||||
void SongPathChanged(const Song &song, const QFileInfo &new_file);
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *e);
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "core/utilities.h"
|
||||
#include "widgets/freespacebar.h"
|
||||
#include "widgets/linetextedit.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "organise.h"
|
||||
#include "organisedialog.h"
|
||||
#include "organiseerrordialog.h"
|
||||
|
@ -71,10 +72,11 @@ using std::stable_sort;
|
|||
const char *OrganiseDialog::kDefaultFormat = "%albumartist/%album{ (Disc %disc)}/{%track - }%albumartist - %album - %title.%extension";
|
||||
const char *OrganiseDialog::kSettingsGroup = "OrganiseDialog";
|
||||
|
||||
OrganiseDialog::OrganiseDialog(TaskManager *task_manager, QWidget *parent)
|
||||
OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
ui_(new Ui_OrganiseDialog),
|
||||
task_manager_(task_manager),
|
||||
backend_(backend),
|
||||
total_size_(0) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
@ -402,6 +404,9 @@ void OrganiseDialog::accept() {
|
|||
Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), ui_->albumcover->isChecked(), new_songs_info_, ui_->eject_after->isChecked());
|
||||
connect(organise, SIGNAL(Finished(QStringList, QStringList)), SLOT(OrganiseFinished(QStringList, QStringList)));
|
||||
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
|
||||
if (backend_)
|
||||
connect(organise, SIGNAL(SongPathChanged(const Song&, const QFileInfo&)), backend_, SLOT(SongPathChanged(const Song&, const QFileInfo&)));
|
||||
|
||||
organise->Start();
|
||||
|
||||
SaveGeometry();
|
||||
|
|
|
@ -48,6 +48,7 @@ class QResizeEvent;
|
|||
class QShowEvent;
|
||||
|
||||
class TaskManager;
|
||||
class CollectionBackend;
|
||||
class OrganiseErrorDialog;
|
||||
class Ui_OrganiseDialog;
|
||||
|
||||
|
@ -55,7 +56,7 @@ class OrganiseDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OrganiseDialog(TaskManager *task_manager, QWidget *parent = nullptr);
|
||||
OrganiseDialog(TaskManager *task_manager, CollectionBackend *backend = nullptr, QWidget *parent = nullptr);
|
||||
~OrganiseDialog();
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
@ -104,6 +105,7 @@ class OrganiseDialog : public QDialog {
|
|||
|
||||
Ui_OrganiseDialog *ui_;
|
||||
TaskManager *task_manager_;
|
||||
CollectionBackend *backend_;
|
||||
|
||||
OrganiseFormat format_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue