2010-06-24 18:26:49 +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-24 18:26:49 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "organisedialog.h"
|
|
|
|
#include "ui_organisedialog.h"
|
2014-02-06 14:48:00 +01:00
|
|
|
|
2018-10-05 17:19:05 +02:00
|
|
|
#include <algorithm>
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
2010-06-24 18:26:49 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
2010-06-24 23:46:18 +02:00
|
|
|
#include <QFileInfo>
|
2014-02-02 19:28:45 +01:00
|
|
|
#include <QHash>
|
2010-06-24 18:26:49 +02:00
|
|
|
#include <QMenu>
|
2010-06-24 19:34:23 +02:00
|
|
|
#include <QPushButton>
|
2012-01-04 23:29:26 +01:00
|
|
|
#include <QResizeEvent>
|
2010-06-24 19:34:23 +02:00
|
|
|
#include <QSettings>
|
2010-06-24 18:26:49 +02:00
|
|
|
#include <QSignalMapper>
|
2014-04-23 13:46:05 +02:00
|
|
|
#include <QtConcurrentRun>
|
2010-06-24 23:46:18 +02:00
|
|
|
#include <QtDebug>
|
2010-06-24 18:26:49 +02:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "iconloader.h"
|
|
|
|
#include "organiseerrordialog.h"
|
|
|
|
#include "core/musicstorage.h"
|
|
|
|
#include "core/organise.h"
|
|
|
|
#include "core/tagreaderclient.h"
|
|
|
|
#include "core/utilities.h"
|
2017-07-22 19:57:33 +02:00
|
|
|
#include "library/librarybackend.h"
|
2014-02-06 14:48:00 +01:00
|
|
|
|
2010-06-24 18:26:49 +02:00
|
|
|
const char* OrganiseDialog::kDefaultFormat =
|
|
|
|
"%artist/%album{ (Disc %disc)}/{%track - }%title.%extension";
|
2010-06-24 19:34:23 +02:00
|
|
|
const char* OrganiseDialog::kSettingsGroup = "OrganiseDialog";
|
2010-06-24 18:26:49 +02:00
|
|
|
|
2017-07-22 19:57:33 +02:00
|
|
|
OrganiseDialog::OrganiseDialog(
|
|
|
|
TaskManager* task_manager, LibraryBackend* backend, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QDialog(parent),
|
|
|
|
ui_(new Ui_OrganiseDialog),
|
|
|
|
task_manager_(task_manager),
|
2017-07-22 19:57:33 +02:00
|
|
|
backend_(backend),
|
2014-02-07 16:34:20 +01:00
|
|
|
total_size_(0),
|
|
|
|
resized_by_user_(false) {
|
2010-06-24 18:26:49 +02:00
|
|
|
ui_->setupUi(this);
|
2014-04-23 13:46:05 +02:00
|
|
|
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(Reset()));
|
2010-06-24 18:26:49 +02:00
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
ui_->aftercopying->setItemIcon(
|
|
|
|
1, IconLoader::Load("edit-delete", IconLoader::Base));
|
2010-07-24 20:12:47 +02:00
|
|
|
|
2010-06-24 18:26:49 +02:00
|
|
|
// Valid tags
|
|
|
|
QMap<QString, QString> tags;
|
|
|
|
tags[tr("Title")] = "title";
|
|
|
|
tags[tr("Album")] = "album";
|
|
|
|
tags[tr("Artist")] = "artist";
|
|
|
|
tags[tr("Artist's initial")] = "artistinitial";
|
|
|
|
tags[tr("Album artist")] = "albumartist";
|
|
|
|
tags[tr("Composer")] = "composer";
|
2013-03-03 13:00:24 +01:00
|
|
|
tags[tr("Performer")] = "performer";
|
|
|
|
tags[tr("Grouping")] = "grouping";
|
2015-04-10 21:05:07 +02:00
|
|
|
tags[tr("Lyrics")] = "lyrics";
|
2010-06-24 18:26:49 +02:00
|
|
|
tags[tr("Track")] = "track";
|
|
|
|
tags[tr("Disc")] = "disc";
|
|
|
|
tags[tr("BPM")] = "bpm";
|
|
|
|
tags[tr("Year")] = "year";
|
2015-06-30 18:34:34 +02:00
|
|
|
tags[tr("Original year")] = "originalyear";
|
2010-06-24 18:26:49 +02:00
|
|
|
tags[tr("Genre")] = "genre";
|
|
|
|
tags[tr("Comment")] = "comment";
|
|
|
|
tags[tr("Length")] = "length";
|
2014-02-03 21:54:02 +01:00
|
|
|
tags[tr("Bitrate", "Refers to bitrate in file organise dialog.")] = "bitrate";
|
2010-06-24 18:26:49 +02:00
|
|
|
tags[tr("Samplerate")] = "samplerate";
|
|
|
|
tags[tr("File extension")] = "extension";
|
|
|
|
|
|
|
|
// Naming scheme input field
|
|
|
|
new OrganiseFormat::SyntaxHighlighter(ui_->naming);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->destination, SIGNAL(currentIndexChanged(int)),
|
|
|
|
SLOT(UpdatePreviews()));
|
2010-06-24 18:26:49 +02:00
|
|
|
connect(ui_->naming, SIGNAL(textChanged()), SLOT(UpdatePreviews()));
|
|
|
|
connect(ui_->replace_ascii, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
|
|
|
connect(ui_->replace_the, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
|
|
|
connect(ui_->replace_spaces, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
|
|
|
|
|
|
|
// Get the titles of the tags to put in the insert menu
|
|
|
|
QStringList tag_titles = tags.keys();
|
2018-10-05 17:19:05 +02:00
|
|
|
std::stable_sort(tag_titles.begin(), tag_titles.end());
|
2010-06-24 18:26:49 +02:00
|
|
|
|
|
|
|
// Build the insert menu
|
|
|
|
QMenu* tag_menu = new QMenu(this);
|
|
|
|
QSignalMapper* tag_mapper = new QSignalMapper(this);
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QString& title : tag_titles) {
|
2010-06-24 18:26:49 +02:00
|
|
|
QAction* action = tag_menu->addAction(title, tag_mapper, SLOT(map()));
|
|
|
|
tag_mapper->setMapping(action, tags[title]);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(tag_mapper, SIGNAL(mapped(QString)), SLOT(InsertTag(QString)));
|
|
|
|
ui_->insert->setMenu(tag_menu);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
OrganiseDialog::~OrganiseDialog() { delete ui_; }
|
2010-06-24 18:26:49 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void OrganiseDialog::SetDestinationModel(QAbstractItemModel* model,
|
|
|
|
bool devices) {
|
2010-06-24 19:34:23 +02:00
|
|
|
ui_->destination->setModel(model);
|
2010-07-25 11:52:29 +02:00
|
|
|
|
|
|
|
ui_->eject_after->setVisible(devices);
|
2010-06-24 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:46:05 +02:00
|
|
|
bool OrganiseDialog::SetSongs(const SongList& songs) {
|
2010-08-30 17:28:55 +02:00
|
|
|
total_size_ = 0;
|
2014-01-20 17:25:12 +01:00
|
|
|
songs_.clear();
|
2010-08-08 15:06:52 +02:00
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const Song& song : songs) {
|
2011-04-28 14:27:53 +02:00
|
|
|
if (song.url().scheme() != "file") {
|
2010-08-08 15:06:52 +02:00
|
|
|
continue;
|
2014-01-25 10:28:46 +01:00
|
|
|
}
|
2010-08-08 15:06:52 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (song.filesize() > 0) total_size_ += song.filesize();
|
2010-08-30 17:28:55 +02:00
|
|
|
|
2014-01-20 17:25:12 +01:00
|
|
|
songs_ << song;
|
2010-08-08 15:06:52 +02:00
|
|
|
}
|
|
|
|
|
2010-08-30 17:28:55 +02:00
|
|
|
ui_->free_space->set_additional_bytes(total_size_);
|
|
|
|
UpdatePreviews();
|
2014-04-23 13:46:05 +02:00
|
|
|
SetLoadingSongs(false);
|
|
|
|
|
|
|
|
if (songs_future_.isRunning()) {
|
|
|
|
songs_future_.cancel();
|
|
|
|
}
|
|
|
|
songs_future_ = QFuture<SongList>();
|
2010-09-15 22:00:17 +02:00
|
|
|
|
2014-01-20 17:25:12 +01:00
|
|
|
return songs_.count();
|
2010-08-08 15:06:52 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:46:05 +02:00
|
|
|
bool OrganiseDialog::SetUrls(const QList<QUrl>& urls) {
|
2014-04-23 13:06:23 +02:00
|
|
|
QStringList filenames;
|
2010-06-24 23:46:18 +02:00
|
|
|
|
|
|
|
// Only add file:// URLs
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QUrl& url : urls) {
|
2014-04-23 13:06:23 +02:00
|
|
|
if (url.scheme() == "file") {
|
|
|
|
filenames << url.toLocalFile();
|
|
|
|
}
|
2010-06-24 18:26:49 +02:00
|
|
|
}
|
2010-06-24 23:46:18 +02:00
|
|
|
|
2014-04-23 13:06:23 +02:00
|
|
|
return SetFilenames(filenames);
|
2010-06-24 18:26:49 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:46:05 +02:00
|
|
|
bool OrganiseDialog::SetFilenames(const QStringList& filenames) {
|
|
|
|
songs_future_ =
|
|
|
|
QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames);
|
2015-11-27 15:22:59 +01:00
|
|
|
NewClosure(songs_future_, [=]() { SetSongs(songs_future_.result()); });
|
2014-04-23 13:46:05 +02:00
|
|
|
|
|
|
|
SetLoadingSongs(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OrganiseDialog::SetLoadingSongs(bool loading) {
|
|
|
|
if (loading) {
|
|
|
|
ui_->preview_stack->setCurrentWidget(ui_->loading_page);
|
|
|
|
ui_->button_box->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui_->preview_stack->setCurrentWidget(ui_->preview_page);
|
|
|
|
// The Ok button is enabled by UpdatePreviews
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SongList OrganiseDialog::LoadSongsBlocking(const QStringList& filenames) {
|
2014-01-20 17:25:12 +01:00
|
|
|
SongList songs;
|
|
|
|
Song song;
|
2010-06-24 18:26:49 +02:00
|
|
|
|
2014-04-23 13:06:23 +02:00
|
|
|
QStringList filenames_copy = filenames;
|
|
|
|
while (!filenames_copy.isEmpty()) {
|
|
|
|
const QString filename = filenames_copy.takeFirst();
|
|
|
|
|
|
|
|
// If it's a directory, add all the files inside.
|
|
|
|
if (QFileInfo(filename).isDir()) {
|
|
|
|
const QDir dir(filename);
|
2014-04-23 13:46:05 +02:00
|
|
|
for (const QString& entry :
|
|
|
|
dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot |
|
|
|
|
QDir::Readable)) {
|
2014-04-23 13:06:23 +02:00
|
|
|
filenames_copy << dir.filePath(entry);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-30 15:08:53 +01:00
|
|
|
TagReaderClient::Instance()->ReadFileBlocking(filename, &song);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (song.is_valid()) songs << song;
|
2010-06-24 18:26:49 +02:00
|
|
|
}
|
2014-04-23 13:46:05 +02:00
|
|
|
|
|
|
|
return songs;
|
2010-06-24 23:46:18 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 22:26:17 +02:00
|
|
|
void OrganiseDialog::SetCopy(bool copy) {
|
2010-07-24 20:12:47 +02:00
|
|
|
ui_->aftercopying->setCurrentIndex(copy ? 0 : 1);
|
2010-06-24 22:26:17 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void OrganiseDialog::InsertTag(const QString& tag) {
|
2010-06-24 18:26:49 +02:00
|
|
|
ui_->naming->insertPlainText("%" + tag);
|
|
|
|
}
|
|
|
|
|
2014-02-02 19:28:45 +01:00
|
|
|
Organise::NewSongInfoList OrganiseDialog::ComputeNewSongsFilenames(
|
|
|
|
const SongList& songs, const OrganiseFormat& format) {
|
|
|
|
// Check if we will have multiple files with the same name.
|
|
|
|
// If so, they will erase each other if the overwrite flag is set.
|
|
|
|
// Better to rename them: e.g. foo.bar -> foo(2).bar
|
|
|
|
QHash<QString, int> filenames;
|
|
|
|
Organise::NewSongInfoList new_songs_info;
|
|
|
|
|
|
|
|
for (const Song& song : songs) {
|
|
|
|
QString new_filename = format.GetFilenameForSong(song);
|
|
|
|
if (filenames.contains(new_filename)) {
|
|
|
|
QString song_number = QString::number(++filenames[new_filename]);
|
2014-02-07 16:34:20 +01:00
|
|
|
new_filename = Utilities::PathWithoutFilenameExtension(new_filename) +
|
|
|
|
"(" + song_number + ")." +
|
|
|
|
QFileInfo(new_filename).suffix();
|
2014-02-02 19:28:45 +01:00
|
|
|
}
|
|
|
|
filenames.insert(new_filename, 1);
|
|
|
|
new_songs_info << Organise::NewSongInfo(song, new_filename);
|
|
|
|
}
|
|
|
|
return new_songs_info;
|
|
|
|
}
|
|
|
|
|
2010-06-24 18:26:49 +02:00
|
|
|
void OrganiseDialog::UpdatePreviews() {
|
2014-04-23 13:46:05 +02:00
|
|
|
if (songs_future_.isRunning()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndex destination =
|
|
|
|
ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<MusicStorage> storage;
|
2010-07-19 23:16:22 +02:00
|
|
|
bool has_local_destination = false;
|
2010-07-19 21:56:29 +02:00
|
|
|
|
2010-07-19 23:16:22 +02:00
|
|
|
if (destination.isValid()) {
|
2010-08-09 23:50:46 +02:00
|
|
|
storage = destination.data(MusicStorage::Role_Storage)
|
2014-02-07 16:34:20 +01:00
|
|
|
.value<std::shared_ptr<MusicStorage>>();
|
2010-07-31 00:19:28 +02:00
|
|
|
if (storage) {
|
|
|
|
has_local_destination = !storage->LocalPath().isEmpty();
|
|
|
|
}
|
2010-07-19 23:16:22 +02:00
|
|
|
}
|
2010-07-19 21:56:29 +02:00
|
|
|
|
2010-07-30 00:16:12 +02:00
|
|
|
// Update the free space bar
|
|
|
|
quint64 capacity = destination.data(MusicStorage::Role_Capacity).toLongLong();
|
|
|
|
quint64 free = destination.data(MusicStorage::Role_FreeSpace).toLongLong();
|
|
|
|
|
|
|
|
if (!capacity) {
|
|
|
|
ui_->free_space->hide();
|
|
|
|
} else {
|
|
|
|
ui_->free_space->show();
|
|
|
|
ui_->free_space->set_free_bytes(free);
|
|
|
|
ui_->free_space->set_total_bytes(capacity);
|
|
|
|
}
|
|
|
|
|
2010-07-31 00:25:32 +02:00
|
|
|
// Update the format object
|
|
|
|
format_.set_format(ui_->naming->toPlainText());
|
|
|
|
format_.set_replace_non_ascii(ui_->replace_ascii->isChecked());
|
|
|
|
format_.set_replace_spaces(ui_->replace_spaces->isChecked());
|
|
|
|
format_.set_replace_the(ui_->replace_the->isChecked());
|
|
|
|
|
2010-09-04 15:28:57 +02:00
|
|
|
const bool format_valid = !has_local_destination || format_.IsValid();
|
2010-07-31 00:25:32 +02:00
|
|
|
|
|
|
|
// Are we gonna enable the ok button?
|
2014-01-20 17:25:12 +01:00
|
|
|
bool ok = format_valid && !songs_.isEmpty();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (capacity != 0 && total_size_ > free) ok = false;
|
2010-07-31 00:25:32 +02:00
|
|
|
|
2014-04-23 13:46:05 +02:00
|
|
|
ui_->button_box->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!format_valid) return;
|
2010-07-31 00:25:32 +02:00
|
|
|
|
2014-02-02 19:28:45 +01:00
|
|
|
new_songs_info_ = ComputeNewSongsFilenames(songs_, format_);
|
|
|
|
|
2010-07-19 21:56:29 +02:00
|
|
|
// Update the previews
|
2010-06-24 18:26:49 +02:00
|
|
|
ui_->preview->clear();
|
2010-07-19 23:16:22 +02:00
|
|
|
ui_->preview_group->setVisible(has_local_destination);
|
2010-07-24 20:12:47 +02:00
|
|
|
ui_->naming_group->setVisible(has_local_destination);
|
2010-07-19 21:56:29 +02:00
|
|
|
if (has_local_destination) {
|
2014-02-02 19:28:45 +01:00
|
|
|
for (const Organise::NewSongInfo& song_info : new_songs_info_) {
|
2014-02-07 16:34:20 +01:00
|
|
|
QString filename = storage->LocalPath() + "/" + song_info.new_filename_;
|
2010-07-19 21:56:29 +02:00
|
|
|
ui_->preview->addItem(QDir::toNativeSeparators(filename));
|
|
|
|
}
|
2010-06-24 18:26:49 +02:00
|
|
|
}
|
2012-01-04 23:21:39 +01:00
|
|
|
|
2012-01-04 23:29:26 +01:00
|
|
|
if (!resized_by_user_) {
|
|
|
|
adjustSize();
|
|
|
|
}
|
2012-01-04 23:21:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QSize OrganiseDialog::sizeHint() const { return QSize(650, 0); }
|
2010-06-24 19:34:23 +02:00
|
|
|
|
|
|
|
void OrganiseDialog::Reset() {
|
|
|
|
ui_->naming->setPlainText(kDefaultFormat);
|
|
|
|
ui_->replace_ascii->setChecked(false);
|
|
|
|
ui_->replace_spaces->setChecked(false);
|
|
|
|
ui_->replace_the->setChecked(false);
|
2014-02-01 03:35:34 +01:00
|
|
|
ui_->overwrite->setChecked(false);
|
2014-10-30 03:41:15 +01:00
|
|
|
ui_->mark_as_listened->setChecked(false);
|
2010-07-25 11:52:29 +02:00
|
|
|
ui_->eject_after->setChecked(false);
|
2010-06-24 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
2012-01-04 23:29:26 +01:00
|
|
|
void OrganiseDialog::showEvent(QShowEvent*) {
|
|
|
|
resized_by_user_ = false;
|
|
|
|
|
2010-06-24 19:34:23 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
|
|
|
|
ui_->replace_ascii->setChecked(s.value("replace_ascii", false).toBool());
|
|
|
|
ui_->replace_spaces->setChecked(s.value("replace_spaces", false).toBool());
|
|
|
|
ui_->replace_the->setChecked(s.value("replace_the", false).toBool());
|
2014-02-01 03:35:34 +01:00
|
|
|
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
|
2015-04-10 21:05:07 +02:00
|
|
|
ui_->mark_as_listened->setChecked(
|
|
|
|
s.value("mark_as_listened", false).toBool());
|
2010-07-25 11:52:29 +02:00
|
|
|
ui_->eject_after->setChecked(s.value("eject_after", false).toBool());
|
2010-06-25 01:40:04 +02:00
|
|
|
|
|
|
|
QString destination = s.value("destination").toString();
|
|
|
|
int index = ui_->destination->findText(destination);
|
|
|
|
if (index != -1 && !destination.isEmpty()) {
|
|
|
|
ui_->destination->setCurrentIndex(index);
|
|
|
|
}
|
2010-06-24 19:34:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OrganiseDialog::accept() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
s.setValue("format", ui_->naming->toPlainText());
|
|
|
|
s.setValue("replace_ascii", ui_->replace_ascii->isChecked());
|
|
|
|
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
|
|
|
|
s.setValue("replace_the", ui_->replace_the->isChecked());
|
|
|
|
s.setValue("overwrite", ui_->overwrite->isChecked());
|
2014-10-30 03:41:15 +01:00
|
|
|
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
|
2010-06-25 01:40:04 +02:00
|
|
|
s.setValue("destination", ui_->destination->currentText());
|
2010-07-25 11:52:29 +02:00
|
|
|
s.setValue("eject_after", ui_->eject_after->isChecked());
|
2010-06-24 19:34:23 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndex destination =
|
|
|
|
ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<MusicStorage> storage =
|
2010-08-14 14:30:51 +02:00
|
|
|
destination.data(MusicStorage::Role_StorageForceConnect)
|
2014-02-07 16:34:20 +01:00
|
|
|
.value<std::shared_ptr<MusicStorage>>();
|
2010-07-19 21:56:29 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!storage) return;
|
2010-08-14 14:30:51 +02:00
|
|
|
|
2010-06-24 20:33:38 +02:00
|
|
|
// It deletes itself when it's finished.
|
2010-07-24 20:12:47 +02:00
|
|
|
const bool copy = ui_->aftercopying->currentIndex() == 0;
|
2010-06-24 20:33:38 +02:00
|
|
|
Organise* organise = new Organise(
|
2010-07-25 11:52:29 +02:00
|
|
|
task_manager_, storage, format_, copy, ui_->overwrite->isChecked(),
|
2015-04-10 21:05:07 +02:00
|
|
|
ui_->mark_as_listened->isChecked(), new_songs_info_,
|
|
|
|
ui_->eject_after->isChecked());
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(organise, SIGNAL(Finished(QStringList)),
|
|
|
|
SLOT(OrganiseFinished(QStringList)));
|
2015-04-10 21:05:07 +02:00
|
|
|
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
|
2017-07-22 19:57:33 +02:00
|
|
|
if (backend_ != nullptr) {
|
|
|
|
connect(organise, SIGNAL(SongPathChanged(const Song&, const QFileInfo&)),
|
|
|
|
backend_, SLOT(SongPathChanged(const Song&, const QFileInfo&)));
|
|
|
|
}
|
2010-06-24 20:33:38 +02:00
|
|
|
organise->Start();
|
|
|
|
|
2010-06-24 19:34:23 +02:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
2010-08-14 13:51:50 +02:00
|
|
|
|
|
|
|
void OrganiseDialog::OrganiseFinished(const QStringList& files_with_errors) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (files_with_errors.isEmpty()) return;
|
2010-08-14 13:51:50 +02:00
|
|
|
|
2010-09-04 22:11:14 +02:00
|
|
|
error_dialog_.reset(new OrganiseErrorDialog);
|
|
|
|
error_dialog_->Show(OrganiseErrorDialog::Type_Copy, files_with_errors);
|
2010-08-14 13:51:50 +02:00
|
|
|
}
|
2012-01-04 23:29:26 +01:00
|
|
|
|
|
|
|
void OrganiseDialog::resizeEvent(QResizeEvent* e) {
|
|
|
|
if (e->spontaneous()) {
|
|
|
|
resized_by_user_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::resizeEvent(e);
|
|
|
|
}
|