2010-05-10 23:50:31 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-10 23:50:31 +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/>.
|
|
|
|
*/
|
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
#include "ui/edittagdialog.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_edittagdialog.h"
|
2015-11-27 15:22:59 +01:00
|
|
|
|
|
|
|
#include <limits>
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 15:12:40 +01:00
|
|
|
#include <QDateTime>
|
2011-01-24 01:09:57 +01:00
|
|
|
#include <QDir>
|
2010-12-21 14:42:06 +01:00
|
|
|
#include <QFuture>
|
2010-12-20 15:12:40 +01:00
|
|
|
#include <QLabel>
|
2010-12-20 16:46:38 +01:00
|
|
|
#include <QMenu>
|
2010-12-25 12:54:21 +01:00
|
|
|
#include <QMessageBox>
|
2010-12-20 17:36:16 +01:00
|
|
|
#include <QPushButton>
|
2010-12-25 00:35:34 +01:00
|
|
|
#include <QShortcut>
|
2010-12-21 14:42:06 +01:00
|
|
|
#include <QtConcurrentRun>
|
2010-05-10 23:50:31 +02:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/tagreaderclient.h"
|
|
|
|
#include "core/utilities.h"
|
|
|
|
#include "covers/albumcoverloader.h"
|
|
|
|
#include "covers/coverproviders.h"
|
|
|
|
#include "library/librarybackend.h"
|
|
|
|
#include "library/library.h"
|
|
|
|
#include "playlist/playlistdelegates.h"
|
|
|
|
#include "ui/albumcoverchoicecontroller.h"
|
|
|
|
#include "ui/albumcovermanager.h"
|
|
|
|
#include "ui/coverfromurldialog.h"
|
2015-12-01 06:43:26 +01:00
|
|
|
#include "ui/iconloader.h"
|
2015-11-27 15:22:59 +01:00
|
|
|
#include "ui/trackselectiondialog.h"
|
2012-01-29 19:44:00 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const char* EditTagDialog::kHintText =
|
|
|
|
QT_TR_NOOP("(different across multiple songs)");
|
2011-11-27 21:36:54 +01:00
|
|
|
const char* EditTagDialog::kSettingsGroup = "EditTagDialog";
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
EditTagDialog::EditTagDialog(Application* app, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QDialog(parent),
|
|
|
|
ui_(new Ui_EditTagDialog),
|
|
|
|
app_(app),
|
|
|
|
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
|
|
|
|
loading_(false),
|
|
|
|
ignore_edits_(false),
|
|
|
|
tag_fetcher_(new TagFetcher(this)),
|
|
|
|
cover_art_id_(0),
|
|
|
|
cover_art_is_set_(false),
|
|
|
|
results_dialog_(new TrackSelectionDialog(this)) {
|
2016-02-11 11:41:37 +01:00
|
|
|
QIcon nocover = IconLoader::Load("nocover", IconLoader::Other);
|
2012-06-17 17:55:19 +02:00
|
|
|
cover_options_.default_output_image_ =
|
2016-01-14 10:40:26 +01:00
|
|
|
AlbumCoverLoader::ScaleAndPad(cover_options_,
|
2016-02-11 11:41:37 +01:00
|
|
|
nocover.pixmap(nocover.availableSizes().last())
|
|
|
|
.toImage());
|
2012-02-13 21:44:04 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(app_->album_cover_loader(),
|
|
|
|
SIGNAL(ImageLoaded(quint64, QImage, QImage)),
|
|
|
|
SLOT(ArtLoaded(quint64, QImage, QImage)));
|
2012-02-13 21:44:04 +01:00
|
|
|
|
2011-03-12 22:19:41 +01:00
|
|
|
connect(tag_fetcher_, SIGNAL(ResultAvailable(Song, SongList)),
|
2011-03-12 23:29:13 +01:00
|
|
|
results_dialog_, SLOT(FetchTagFinished(Song, SongList)),
|
2011-03-05 20:24:44 +01:00
|
|
|
Qt::QueuedConnection);
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(tag_fetcher_, SIGNAL(Progress(Song, QString)), results_dialog_,
|
|
|
|
SLOT(FetchTagProgress(Song, QString)));
|
2011-03-06 15:07:41 +01:00
|
|
|
connect(results_dialog_, SIGNAL(SongChosen(Song, Song)),
|
|
|
|
SLOT(FetchTagSongChosen(Song, Song)));
|
2011-03-13 13:52:08 +01:00
|
|
|
connect(results_dialog_, SIGNAL(finished(int)), tag_fetcher_, SLOT(Cancel()));
|
2010-12-26 13:42:47 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
album_cover_choice_controller_->SetApplication(app_);
|
2011-07-23 20:34:41 +02:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-12-20 00:40:36 +01:00
|
|
|
ui_->splitter->setSizes(QList<int>() << 200 << width() - 200);
|
2011-08-27 16:00:49 +02:00
|
|
|
ui_->loading_label->hide();
|
2010-12-20 00:40:36 +01:00
|
|
|
|
2015-12-01 06:43:26 +01:00
|
|
|
ui_->fetch_tag->setIcon(IconLoader::Load("musicbrainz",
|
|
|
|
IconLoader::Provider));
|
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
// An editable field is one that has a label as a buddy. The label is
|
|
|
|
// important because it gets turned bold when the field is changed.
|
2014-02-10 14:29:07 +01:00
|
|
|
for (QLabel* label : findChildren<QLabel*>()) {
|
2010-12-20 00:40:36 +01:00
|
|
|
QWidget* widget = label->buddy();
|
|
|
|
if (widget) {
|
|
|
|
// Store information about the field
|
|
|
|
fields_ << FieldData(label, widget, widget->objectName());
|
|
|
|
|
|
|
|
// Connect the Reset signal
|
|
|
|
if (dynamic_cast<ExtendedEditor*>(widget)) {
|
|
|
|
connect(widget, SIGNAL(Reset()), SLOT(ResetField()));
|
|
|
|
}
|
|
|
|
|
2016-01-04 17:09:24 +01:00
|
|
|
// Connect the changed signal (emitted when value is changed
|
|
|
|
// programmatically or non-programmatically)
|
2010-12-20 00:40:36 +01:00
|
|
|
if (qobject_cast<QLineEdit*>(widget)) {
|
|
|
|
connect(widget, SIGNAL(textChanged(QString)), SLOT(FieldValueEdited()));
|
|
|
|
} else if (qobject_cast<QPlainTextEdit*>(widget)) {
|
|
|
|
connect(widget, SIGNAL(textChanged()), SLOT(FieldValueEdited()));
|
|
|
|
} else if (qobject_cast<QSpinBox*>(widget)) {
|
|
|
|
connect(widget, SIGNAL(valueChanged(int)), SLOT(FieldValueEdited()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-25 00:22:09 +01:00
|
|
|
// Set the colour of all the labels on the summary page
|
|
|
|
const bool light = palette().color(QPalette::Base).value() > 128;
|
2014-06-07 04:48:32 +02:00
|
|
|
const QColor color = palette().color(QPalette::WindowText);
|
2010-12-25 00:22:09 +01:00
|
|
|
QPalette summary_label_palette(palette());
|
2014-02-07 16:34:20 +01:00
|
|
|
summary_label_palette.setColor(
|
2014-06-07 04:48:32 +02:00
|
|
|
QPalette::WindowText, light ? color.lighter(150) : color.darker(150));
|
2010-12-25 00:22:09 +01:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (QLabel* label : ui_->summary_tab->findChildren<QLabel*>()) {
|
2010-12-25 00:22:09 +01:00
|
|
|
if (label->property("field_label").toBool()) {
|
|
|
|
label->setPalette(summary_label_palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pretend the summary text is just a label
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->summary->setMaximumHeight(ui_->art->height() -
|
|
|
|
ui_->summary_art_button->height() - 4);
|
2010-12-25 00:22:09 +01:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
connect(ui_->song_list->selectionModel(),
|
2014-02-07 16:34:20 +01:00
|
|
|
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
2010-12-20 00:40:36 +01:00
|
|
|
SLOT(SelectionChanged()));
|
2010-12-21 14:42:06 +01:00
|
|
|
connect(ui_->button_box, SIGNAL(clicked(QAbstractButton*)),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(ButtonClicked(QAbstractButton*)));
|
|
|
|
connect(ui_->rating, SIGNAL(RatingChanged(float)), SLOT(SongRated(float)));
|
2010-12-25 12:54:21 +01:00
|
|
|
connect(ui_->playcount_reset, SIGNAL(clicked()), SLOT(ResetPlayCounts()));
|
2011-01-15 21:00:39 +01:00
|
|
|
connect(ui_->fetch_tag, SIGNAL(clicked()), SLOT(FetchTag()));
|
2010-12-20 16:46:38 +01:00
|
|
|
|
|
|
|
// Set up the album cover menu
|
|
|
|
cover_menu_ = new QMenu(this);
|
2011-01-24 19:32:09 +01:00
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
2011-01-24 19:32:09 +01:00
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
connect(album_cover_choice_controller_->cover_from_file_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
|
2011-02-02 17:22:04 +01:00
|
|
|
connect(album_cover_choice_controller_->cover_to_file_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(SaveCoverToFile()));
|
2011-01-26 00:33:27 +01:00
|
|
|
connect(album_cover_choice_controller_->cover_from_url_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
|
|
|
|
connect(album_cover_choice_controller_->search_for_cover_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(SearchForCover()));
|
|
|
|
connect(album_cover_choice_controller_->unset_cover_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(UnsetCover()));
|
|
|
|
connect(album_cover_choice_controller_->show_cover_action(),
|
|
|
|
SIGNAL(triggered()), this, SLOT(ShowCover()));
|
2011-01-24 19:32:09 +01:00
|
|
|
|
|
|
|
cover_menu_->addActions(actions);
|
|
|
|
|
2010-12-20 16:46:38 +01:00
|
|
|
ui_->summary_art_button->setMenu(cover_menu_);
|
2010-12-20 17:36:16 +01:00
|
|
|
|
2010-12-25 00:22:09 +01:00
|
|
|
ui_->art->installEventFilter(this);
|
2011-03-14 21:01:27 +01:00
|
|
|
ui_->art->setAcceptDrops(true);
|
2010-12-25 00:22:09 +01:00
|
|
|
|
2010-12-20 17:36:16 +01:00
|
|
|
// Add the next/previous buttons
|
2015-11-27 15:22:59 +01:00
|
|
|
previous_button_ = new QPushButton(
|
|
|
|
IconLoader::Load("go-previous", IconLoader::Base), tr("Previous"), this);
|
|
|
|
next_button_ = new QPushButton(IconLoader::Load("go-next", IconLoader::Base),
|
|
|
|
tr("Next"), this);
|
2010-12-20 17:36:16 +01:00
|
|
|
ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole);
|
|
|
|
ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole);
|
|
|
|
|
|
|
|
connect(previous_button_, SIGNAL(clicked()), SLOT(PreviousSong()));
|
|
|
|
connect(next_button_, SIGNAL(clicked()), SLOT(NextSong()));
|
2010-12-25 00:35:34 +01:00
|
|
|
|
|
|
|
// Set some shortcuts for the buttons
|
|
|
|
new QShortcut(QKeySequence::Back, previous_button_, SLOT(click()));
|
|
|
|
new QShortcut(QKeySequence::Forward, next_button_, SLOT(click()));
|
2014-02-07 16:34:20 +01:00
|
|
|
new QShortcut(QKeySequence::MoveToPreviousPage, previous_button_,
|
|
|
|
SLOT(click()));
|
2010-12-25 00:35:34 +01:00
|
|
|
new QShortcut(QKeySequence::MoveToNextPage, next_button_, SLOT(click()));
|
2012-01-29 20:32:36 +01:00
|
|
|
|
|
|
|
// Show the shortcuts as tooltips
|
|
|
|
previous_button_->setToolTip(QString("%1 (%2 / %3)").arg(
|
|
|
|
previous_button_->text(),
|
|
|
|
QKeySequence(QKeySequence::Back).toString(QKeySequence::NativeText),
|
2014-02-07 16:34:20 +01:00
|
|
|
QKeySequence(QKeySequence::MoveToPreviousPage)
|
|
|
|
.toString(QKeySequence::NativeText)));
|
2012-01-29 20:32:36 +01:00
|
|
|
next_button_->setToolTip(QString("%1 (%2 / %3)").arg(
|
|
|
|
next_button_->text(),
|
|
|
|
QKeySequence(QKeySequence::Forward).toString(QKeySequence::NativeText),
|
2014-02-07 16:34:20 +01:00
|
|
|
QKeySequence(QKeySequence::MoveToNextPage)
|
|
|
|
.toString(QKeySequence::NativeText)));
|
2012-02-12 14:41:50 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Artist,
|
|
|
|
ui_->artist);
|
2012-02-12 14:41:50 +01:00
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Album, ui_->album);
|
2014-02-07 16:34:20 +01:00
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_AlbumArtist,
|
|
|
|
ui_->albumartist);
|
2012-02-12 14:41:50 +01:00
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Genre, ui_->genre);
|
2014-02-07 16:34:20 +01:00
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Composer,
|
|
|
|
ui_->composer);
|
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Performer,
|
|
|
|
ui_->performer);
|
|
|
|
new TagCompleter(app_->library_backend(), Playlist::Column_Grouping,
|
|
|
|
ui_->grouping);
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
EditTagDialog::~EditTagDialog() { delete ui_; }
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-21 14:42:06 +01:00
|
|
|
bool EditTagDialog::SetLoading(const QString& message) {
|
|
|
|
const bool loading = !message.isEmpty();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (loading == loading_) return false;
|
2010-12-21 14:42:06 +01:00
|
|
|
loading_ = loading;
|
|
|
|
|
|
|
|
ui_->button_box->setEnabled(!loading);
|
|
|
|
ui_->tab_widget->setEnabled(!loading);
|
|
|
|
ui_->song_list->setEnabled(!loading);
|
2011-01-15 21:00:39 +01:00
|
|
|
ui_->fetch_tag->setEnabled(!loading);
|
2011-08-27 16:00:49 +02:00
|
|
|
ui_->loading_label->setVisible(loading);
|
|
|
|
ui_->loading_label->set_text(message);
|
2010-12-21 14:42:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 12:11:33 +01:00
|
|
|
QList<EditTagDialog::Data> EditTagDialog::LoadData(
|
|
|
|
const SongList& songs) const {
|
2010-12-21 14:42:06 +01:00
|
|
|
QList<Data> ret;
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Song& song : songs) {
|
2010-09-02 21:12:09 +02:00
|
|
|
if (song.IsEditable()) {
|
|
|
|
// Try reloading the tags from file
|
|
|
|
Song copy(song);
|
2014-02-07 16:34:20 +01:00
|
|
|
TagReaderClient::Instance()->ReadFileBlocking(copy.url().toLocalFile(),
|
|
|
|
©);
|
2010-09-02 21:12:09 +02:00
|
|
|
|
2012-12-25 14:48:16 +01:00
|
|
|
if (copy.is_valid()) {
|
|
|
|
copy.MergeUserSetData(song);
|
2010-12-21 14:42:06 +01:00
|
|
|
ret << Data(copy);
|
2012-12-25 14:48:16 +01:00
|
|
|
}
|
2010-09-02 21:12:09 +02:00
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2010-12-21 14:42:06 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::SetSongs(const SongList& s, const PlaylistItemList& items) {
|
|
|
|
// Show the loading indicator
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!SetLoading(tr("Loading tracks") + "...")) return;
|
2010-12-21 14:42:06 +01:00
|
|
|
|
|
|
|
data_.clear();
|
|
|
|
playlist_items_ = items;
|
|
|
|
ui_->song_list->clear();
|
|
|
|
|
|
|
|
// Reload tags in the background
|
2015-01-17 12:11:33 +01:00
|
|
|
QFuture<QList<Data>> future =
|
2014-02-07 16:34:20 +01:00
|
|
|
QtConcurrent::run(this, &EditTagDialog::LoadData, s);
|
2015-11-27 15:22:59 +01:00
|
|
|
NewClosure(future, this,
|
|
|
|
SLOT(SetSongsFinished(QFuture<QList<EditTagDialog::Data>>)),
|
|
|
|
future);
|
2010-12-21 14:42:06 +01:00
|
|
|
}
|
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
void EditTagDialog::SetSongsFinished(QFuture<QList<Data>> future) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!SetLoading(QString())) return;
|
2010-12-21 14:42:06 +01:00
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
data_ = future.result();
|
2012-01-29 19:44:00 +01:00
|
|
|
if (data_.count() == 0) {
|
|
|
|
// If there were no valid songs, disable everything
|
|
|
|
ui_->song_list->setEnabled(false);
|
|
|
|
ui_->tab_widget->setEnabled(false);
|
|
|
|
|
|
|
|
// Show a summary with empty information
|
|
|
|
UpdateSummaryTab(Song());
|
|
|
|
ui_->tab_widget->setCurrentWidget(ui_->summary_tab);
|
|
|
|
|
|
|
|
SetSongListVisibility(false);
|
2010-12-21 14:42:06 +01:00
|
|
|
return;
|
2012-01-29 19:44:00 +01:00
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
// Add the filenames to the list
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const Data& data : data_) {
|
2010-12-20 00:40:36 +01:00
|
|
|
ui_->song_list->addItem(data.current_.basefilename());
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
// Select all
|
2011-03-05 20:24:44 +01:00
|
|
|
ui_->song_list->setCurrentRow(0);
|
2010-12-20 00:40:36 +01:00
|
|
|
ui_->song_list->selectAll();
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
// Hide the list if there's only one song in it
|
2012-01-29 19:44:00 +01:00
|
|
|
SetSongListVisibility(data_.count() != 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::SetSongListVisibility(bool visible) {
|
|
|
|
ui_->song_list->setVisible(visible);
|
|
|
|
previous_button_->setEnabled(visible);
|
|
|
|
next_button_->setEnabled(visible);
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
QVariant EditTagDialog::Data::value(const Song& song, const QString& id) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (id == "title") return song.title();
|
|
|
|
if (id == "artist") return song.artist();
|
|
|
|
if (id == "album") return song.album();
|
2010-12-20 00:40:36 +01:00
|
|
|
if (id == "albumartist") return song.albumartist();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (id == "composer") return song.composer();
|
|
|
|
if (id == "performer") return song.performer();
|
|
|
|
if (id == "grouping") return song.grouping();
|
|
|
|
if (id == "genre") return song.genre();
|
|
|
|
if (id == "comment") return song.comment();
|
2015-06-10 21:23:40 +02:00
|
|
|
if (id == "lyrics") return song.lyrics();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (id == "track") return song.track();
|
|
|
|
if (id == "disc") return song.disc();
|
|
|
|
if (id == "year") return song.year();
|
2011-04-22 18:50:29 +02:00
|
|
|
qLog(Warning) << "Unknown ID" << id;
|
2010-12-20 00:40:36 +01:00
|
|
|
return QVariant();
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
void EditTagDialog::Data::set_value(const QString& id, const QVariant& value) {
|
2015-01-17 12:11:33 +01:00
|
|
|
if (id == "title")
|
|
|
|
current_.set_title(value.toString());
|
|
|
|
else if (id == "artist")
|
|
|
|
current_.set_artist(value.toString());
|
|
|
|
else if (id == "album")
|
|
|
|
current_.set_album(value.toString());
|
|
|
|
else if (id == "albumartist")
|
|
|
|
current_.set_albumartist(value.toString());
|
|
|
|
else if (id == "composer")
|
|
|
|
current_.set_composer(value.toString());
|
|
|
|
else if (id == "performer")
|
|
|
|
current_.set_performer(value.toString());
|
|
|
|
else if (id == "grouping")
|
|
|
|
current_.set_grouping(value.toString());
|
|
|
|
else if (id == "genre")
|
|
|
|
current_.set_genre(value.toString());
|
|
|
|
else if (id == "comment")
|
|
|
|
current_.set_comment(value.toString());
|
2015-06-10 21:23:40 +02:00
|
|
|
else if (id == "lyrics")
|
|
|
|
current_.set_lyrics(value.toString());
|
2015-01-17 12:11:33 +01:00
|
|
|
else if (id == "track")
|
|
|
|
current_.set_track(value.toInt());
|
|
|
|
else if (id == "disc")
|
|
|
|
current_.set_disc(value.toInt());
|
|
|
|
else if (id == "year")
|
|
|
|
current_.set_year(value.toInt());
|
|
|
|
else
|
|
|
|
qLog(Warning) << "Unknown ID" << id;
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EditTagDialog::DoesValueVary(const QModelIndexList& sel,
|
|
|
|
const QString& id) const {
|
2010-12-20 00:40:36 +01:00
|
|
|
QVariant value = data_[sel.first().row()].current_value(id);
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 1; i < sel.count(); ++i) {
|
|
|
|
if (value != data_[sel[i].row()].current_value(id)) return true;
|
2010-12-20 00:40:36 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool EditTagDialog::IsValueModified(const QModelIndexList& sel,
|
|
|
|
const QString& id) const {
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& i : sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
if (data_[i.row()].original_value(id) != data_[i.row()].current_value(id))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::InitFieldValue(const FieldData& field,
|
|
|
|
const QModelIndexList& sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
const bool varies = DoesValueVary(sel, field.id_);
|
|
|
|
|
|
|
|
if (ExtendedEditor* editor = dynamic_cast<ExtendedEditor*>(field.editor_)) {
|
|
|
|
editor->clear();
|
|
|
|
editor->clear_hint();
|
|
|
|
if (varies) {
|
2014-02-07 17:10:53 +01:00
|
|
|
editor->set_hint(tr(EditTagDialog::kHintText));
|
2010-12-20 00:40:36 +01:00
|
|
|
} else {
|
|
|
|
editor->set_text(data_[sel[0].row()].current_value(field.id_).toString());
|
|
|
|
}
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2016-01-04 18:56:28 +01:00
|
|
|
UpdateModifiedField(field, sel);
|
2010-12-20 00:40:36 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::UpdateFieldValue(const FieldData& field,
|
|
|
|
const QModelIndexList& sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
// Get the value from the field
|
|
|
|
QVariant value;
|
|
|
|
if (ExtendedEditor* editor = dynamic_cast<ExtendedEditor*>(field.editor_)) {
|
|
|
|
value = editor->text();
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
// Did we get it?
|
|
|
|
if (!value.isValid()) {
|
|
|
|
return;
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
2010-12-20 00:40:36 +01:00
|
|
|
|
|
|
|
// Set it in each selected song
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& i : sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
data_[i.row()].set_value(field.id_, value);
|
|
|
|
}
|
|
|
|
|
2016-01-04 18:56:28 +01:00
|
|
|
UpdateModifiedField(field, sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::UpdateModifiedField(const FieldData& field, const QModelIndexList& sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
const bool modified = IsValueModified(sel, field.id_);
|
|
|
|
|
2016-01-04 18:56:28 +01:00
|
|
|
// Update the boldness
|
2010-12-20 00:40:36 +01:00
|
|
|
QFont new_font(font());
|
|
|
|
new_font.setBold(modified);
|
|
|
|
field.label_->setFont(new_font);
|
|
|
|
field.editor_->setFont(new_font);
|
2010-08-02 17:07:26 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::ResetFieldValue(const FieldData& field,
|
|
|
|
const QModelIndexList& sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
// Reset each selected song
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& i : sel) {
|
2010-12-20 00:40:36 +01:00
|
|
|
Data& data = data_[i.row()];
|
|
|
|
data.set_value(field.id_, data.original_value(field.id_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the field
|
|
|
|
InitFieldValue(field, sel);
|
2010-08-02 17:07:26 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
void EditTagDialog::SelectionChanged() {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return;
|
2010-12-20 00:40:36 +01:00
|
|
|
|
2010-12-20 15:12:40 +01:00
|
|
|
// Set the editable fields
|
2016-02-09 21:56:22 +01:00
|
|
|
UpdateUI(sel);
|
2010-12-20 15:12:40 +01:00
|
|
|
|
|
|
|
// If we're editing multiple songs then we have to disable certain tabs
|
|
|
|
const bool multiple = sel.count() > 1;
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->tab_widget->setTabEnabled(ui_->tab_widget->indexOf(ui_->summary_tab),
|
|
|
|
!multiple);
|
2010-12-20 15:12:40 +01:00
|
|
|
|
|
|
|
if (!multiple) {
|
|
|
|
const Song& song = data_[sel.first().row()].original_;
|
|
|
|
UpdateSummaryTab(song);
|
|
|
|
UpdateStatisticsTab(song);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-09 21:56:22 +01:00
|
|
|
void EditTagDialog::UpdateUI(const QModelIndexList& sel){
|
|
|
|
ignore_edits_ = true;
|
|
|
|
for (const FieldData& field : fields_) {
|
|
|
|
InitFieldValue(field, sel);
|
|
|
|
}
|
|
|
|
ignore_edits_ = false;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
static void SetText(QLabel* label, int value, const QString& suffix,
|
|
|
|
const QString& def = QString()) {
|
2010-12-20 15:12:40 +01:00
|
|
|
label->setText(value <= 0 ? def : (QString::number(value) + " " + suffix));
|
|
|
|
}
|
|
|
|
|
2012-01-29 19:44:00 +01:00
|
|
|
static void SetDate(QLabel* label, uint time) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (time == std::numeric_limits<uint>::max()) { // -1
|
2012-01-29 19:44:00 +01:00
|
|
|
label->setText(QObject::tr("Unknown"));
|
|
|
|
} else {
|
|
|
|
label->setText(QDateTime::fromTime_t(time).toString(
|
|
|
|
QLocale::system().dateTimeFormat(QLocale::LongFormat)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 15:12:40 +01:00
|
|
|
void EditTagDialog::UpdateSummaryTab(const Song& song) {
|
2014-02-07 16:34:20 +01:00
|
|
|
cover_art_id_ =
|
|
|
|
app_->album_cover_loader()->LoadImageAsync(cover_options_, song);
|
2010-12-20 15:12:40 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QString summary =
|
|
|
|
"<b>" + Qt::escape(song.PrettyTitleWithArtist()) + "</b><br/>";
|
2010-12-20 15:12:40 +01:00
|
|
|
|
2010-12-20 16:46:38 +01:00
|
|
|
bool art_is_set = true;
|
2011-02-02 22:01:08 +01:00
|
|
|
if (song.has_manually_unset_cover()) {
|
2010-12-20 15:12:40 +01:00
|
|
|
summary += Qt::escape(tr("Cover art manually unset"));
|
2010-12-20 16:46:38 +01:00
|
|
|
art_is_set = false;
|
2010-12-20 15:12:40 +01:00
|
|
|
} else if (!song.art_manual().isEmpty()) {
|
|
|
|
summary += Qt::escape(tr("Cover art set from %1").arg(song.art_manual()));
|
2011-02-02 22:01:08 +01:00
|
|
|
} else if (song.has_embedded_cover()) {
|
2010-12-20 15:12:40 +01:00
|
|
|
summary += Qt::escape(tr("Cover art from embedded image"));
|
|
|
|
} else if (!song.art_automatic().isEmpty()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
summary += Qt::escape(
|
|
|
|
tr("Cover art loaded automatically from %1").arg(song.art_automatic()));
|
2010-12-20 15:12:40 +01:00
|
|
|
} else {
|
|
|
|
summary += Qt::escape(tr("Cover art not set"));
|
2010-12-20 16:46:38 +01:00
|
|
|
art_is_set = false;
|
2010-12-20 15:12:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_->summary->setText(summary);
|
|
|
|
|
2011-01-26 00:33:27 +01:00
|
|
|
album_cover_choice_controller_->unset_cover_action()->setEnabled(art_is_set);
|
|
|
|
album_cover_choice_controller_->show_cover_action()->setEnabled(art_is_set);
|
2010-12-20 16:46:38 +01:00
|
|
|
ui_->summary_art_button->setEnabled(song.id() != -1);
|
|
|
|
|
2011-02-13 19:34:30 +01:00
|
|
|
ui_->length->setText(Utilities::PrettyTimeNanosec(song.length_nanosec()));
|
2010-12-20 15:12:40 +01:00
|
|
|
SetText(ui_->bpm, song.bpm(), tr("bpm"));
|
|
|
|
SetText(ui_->samplerate, song.samplerate(), "Hz");
|
|
|
|
SetText(ui_->bitrate, song.bitrate(), tr("kbps"));
|
2012-01-29 19:44:00 +01:00
|
|
|
SetDate(ui_->mtime, song.mtime());
|
|
|
|
SetDate(ui_->ctime, song.ctime());
|
|
|
|
|
|
|
|
if (song.filesize() == -1) {
|
|
|
|
ui_->filesize->setText(tr("Unknown"));
|
|
|
|
} else {
|
|
|
|
ui_->filesize->setText(Utilities::PrettySize(song.filesize()));
|
|
|
|
}
|
|
|
|
|
2010-12-25 00:22:09 +01:00
|
|
|
ui_->filetype->setText(song.TextForFiletype());
|
2011-04-28 14:27:53 +02:00
|
|
|
|
|
|
|
if (song.url().scheme() == "file")
|
|
|
|
ui_->filename->setText(QDir::toNativeSeparators(song.url().toLocalFile()));
|
|
|
|
else
|
|
|
|
ui_->filename->setText(song.url().toString());
|
2011-04-27 21:10:37 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
album_cover_choice_controller_->search_for_cover_action()->setEnabled(
|
2014-02-07 16:34:20 +01:00
|
|
|
app_->cover_providers()->HasAnyProviders());
|
2010-12-20 15:12:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::UpdateStatisticsTab(const Song& song) {
|
|
|
|
ui_->playcount->setText(QString::number(qMax(0, song.playcount())));
|
|
|
|
ui_->skipcount->setText(QString::number(qMax(0, song.skipcount())));
|
|
|
|
ui_->score->setText(QString::number(qMax(0, song.score())));
|
|
|
|
ui_->rating->set_rating(song.rating());
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->lastplayed->setText(
|
|
|
|
song.lastplayed() <= 0
|
|
|
|
? tr("Never")
|
|
|
|
: QDateTime::fromTime_t(song.lastplayed()).toString(
|
|
|
|
QLocale::system().dateTimeFormat(QLocale::LongFormat)));
|
2010-12-20 15:12:40 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::ArtLoaded(quint64 id, const QImage& scaled,
|
|
|
|
const QImage& original) {
|
2010-12-20 15:12:40 +01:00
|
|
|
if (id == cover_art_id_) {
|
2011-02-02 17:22:04 +01:00
|
|
|
ui_->art->setPixmap(QPixmap::fromImage(scaled));
|
|
|
|
original_ = original;
|
2010-12-20 15:12:40 +01:00
|
|
|
}
|
2010-12-20 00:40:36 +01:00
|
|
|
}
|
2010-08-02 17:07:26 +02:00
|
|
|
|
2010-12-20 00:40:36 +01:00
|
|
|
void EditTagDialog::FieldValueEdited() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (ignore_edits_) return;
|
2010-12-20 00:40:36 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return;
|
2010-12-20 00:40:36 +01:00
|
|
|
|
|
|
|
QWidget* w = qobject_cast<QWidget*>(sender());
|
|
|
|
|
|
|
|
// Find the field
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const FieldData& field : fields_) {
|
2010-12-20 00:40:36 +01:00
|
|
|
if (field.editor_ == w) {
|
|
|
|
UpdateFieldValue(field, sel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::ResetField() {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return;
|
2010-12-20 00:40:36 +01:00
|
|
|
|
|
|
|
QWidget* w = qobject_cast<QWidget*>(sender());
|
|
|
|
|
|
|
|
// Find the field
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const FieldData& field : fields_) {
|
2010-12-20 00:40:36 +01:00
|
|
|
if (field.editor_ == w) {
|
|
|
|
ignore_edits_ = true;
|
|
|
|
ResetFieldValue(field, sel);
|
|
|
|
ignore_edits_ = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* EditTagDialog::GetFirstSelected() {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return nullptr;
|
2011-01-24 18:53:31 +01:00
|
|
|
return &data_[sel.first().row()].original_;
|
2011-01-24 01:09:57 +01:00
|
|
|
}
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2011-01-24 01:09:57 +01:00
|
|
|
void EditTagDialog::LoadCoverFromFile() {
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) return;
|
2011-01-24 18:53:31 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2011-01-24 01:09:57 +01:00
|
|
|
QString cover = album_cover_choice_controller_->LoadCoverFromFile(song);
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!cover.isEmpty()) UpdateCoverOf(*song, sel, cover);
|
2010-12-20 16:46:38 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 17:22:04 +01:00
|
|
|
void EditTagDialog::SaveCoverToFile() {
|
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) return;
|
2011-02-02 17:22:04 +01:00
|
|
|
|
|
|
|
album_cover_choice_controller_->SaveCoverToFile(*song, original_);
|
|
|
|
}
|
|
|
|
|
2011-01-23 21:24:17 +01:00
|
|
|
void EditTagDialog::LoadCoverFromURL() {
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) return;
|
2011-01-23 21:24:17 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2011-01-23 21:24:17 +01:00
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
QString cover = album_cover_choice_controller_->LoadCoverFromURL(song);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!cover.isEmpty()) UpdateCoverOf(*song, sel, cover);
|
2011-01-23 21:24:17 +01:00
|
|
|
}
|
|
|
|
|
2011-01-24 01:09:57 +01:00
|
|
|
void EditTagDialog::SearchForCover() {
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) return;
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2011-01-24 18:53:31 +01:00
|
|
|
|
|
|
|
QString cover = album_cover_choice_controller_->SearchForCover(song);
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!cover.isEmpty()) UpdateCoverOf(*song, sel, cover);
|
2010-12-20 16:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::UnsetCover() {
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) return;
|
2011-01-24 18:53:31 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2011-01-24 18:53:31 +01:00
|
|
|
|
|
|
|
QString cover = album_cover_choice_controller_->UnsetCover(song);
|
|
|
|
UpdateCoverOf(*song, sel, cover);
|
2010-12-20 16:46:38 +01:00
|
|
|
}
|
|
|
|
|
2011-01-24 01:09:57 +01:00
|
|
|
void EditTagDialog::ShowCover() {
|
2011-01-24 18:53:31 +01:00
|
|
|
Song* song = GetFirstSelected();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song) {
|
2010-12-20 16:46:38 +01:00
|
|
|
return;
|
2011-01-24 01:09:57 +01:00
|
|
|
}
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
album_cover_choice_controller_->ShowCover(*song);
|
2010-12-20 16:46:38 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::UpdateCoverOf(const Song& selected,
|
|
|
|
const QModelIndexList& sel,
|
2011-01-24 18:53:31 +01:00
|
|
|
const QString& cover) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!selected.is_valid() || selected.id() == -1) return;
|
2010-12-20 16:46:38 +01:00
|
|
|
|
2011-01-24 18:53:31 +01:00
|
|
|
UpdateSummaryTab(selected);
|
2010-12-25 01:15:05 +01:00
|
|
|
|
|
|
|
// Now check if we have any other songs cached that share that artist and
|
|
|
|
// album (and would therefore be changed as well)
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < data_.count(); ++i) {
|
|
|
|
if (i == sel.first().row()) // Already changed this one
|
2010-12-25 01:15:05 +01:00
|
|
|
continue;
|
|
|
|
|
2010-12-25 01:43:55 +01:00
|
|
|
Song* other_song = &data_[i].original_;
|
2011-01-24 18:53:31 +01:00
|
|
|
if (selected.artist() == other_song->artist() &&
|
2014-02-07 16:34:20 +01:00
|
|
|
selected.album() == other_song->album()) {
|
2011-01-24 18:53:31 +01:00
|
|
|
other_song->set_art_manual(cover);
|
2010-12-25 01:15:05 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 16:46:38 +01:00
|
|
|
}
|
2010-12-20 17:36:16 +01:00
|
|
|
|
|
|
|
void EditTagDialog::NextSong() {
|
2012-01-29 19:44:00 +01:00
|
|
|
if (ui_->song_list->count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-20 17:36:16 +01:00
|
|
|
int row = (ui_->song_list->currentRow() + 1) % ui_->song_list->count();
|
|
|
|
ui_->song_list->setCurrentRow(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::PreviousSong() {
|
2012-01-29 19:44:00 +01:00
|
|
|
if (ui_->song_list->count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int row = (ui_->song_list->currentRow() - 1 + ui_->song_list->count()) %
|
|
|
|
ui_->song_list->count();
|
2010-12-20 17:36:16 +01:00
|
|
|
ui_->song_list->setCurrentRow(row);
|
|
|
|
}
|
2010-12-21 14:42:06 +01:00
|
|
|
|
|
|
|
void EditTagDialog::ButtonClicked(QAbstractButton* button) {
|
|
|
|
if (button == ui_->button_box->button(QDialogButtonBox::Discard)) {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::SaveData(const QList<Data>& data) {
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < data.count(); ++i) {
|
2010-12-21 14:42:06 +01:00
|
|
|
const Data& ref = data[i];
|
2014-02-07 16:34:20 +01:00
|
|
|
if (ref.current_.IsMetadataEqual(ref.original_)) continue;
|
2010-12-21 14:42:06 +01:00
|
|
|
|
2012-01-06 22:27:02 +01:00
|
|
|
if (!TagReaderClient::Instance()->SaveFileBlocking(
|
2015-01-17 12:11:33 +01:00
|
|
|
ref.current_.url().toLocalFile(), ref.current_)) {
|
2014-02-07 16:34:20 +01:00
|
|
|
emit Error(tr("An error occurred writing metadata to '%1'")
|
|
|
|
.arg(ref.current_.url().toLocalFile()));
|
2010-12-21 14:42:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::accept() {
|
|
|
|
// Show the loading indicator
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!SetLoading(tr("Saving tracks") + "...")) return;
|
2010-12-21 14:42:06 +01:00
|
|
|
|
2010-12-25 01:15:05 +01:00
|
|
|
// Save tags in the background
|
2014-02-07 16:34:20 +01:00
|
|
|
QFuture<void> future =
|
|
|
|
QtConcurrent::run(this, &EditTagDialog::SaveData, data_);
|
2015-11-27 15:22:59 +01:00
|
|
|
NewClosure(future, this, SLOT(AcceptFinished()));
|
2010-12-21 14:42:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditTagDialog::AcceptFinished() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!SetLoading(QString())) return;
|
2010-12-21 14:42:06 +01:00
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
2010-12-25 00:22:09 +01:00
|
|
|
|
|
|
|
bool EditTagDialog::eventFilter(QObject* o, QEvent* e) {
|
2011-03-14 21:01:27 +01:00
|
|
|
if (o == ui_->art) {
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
cover_menu_->popup(static_cast<QMouseEvent*>(e)->globalPos());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::DragEnter: {
|
|
|
|
QDragEnterEvent* event = static_cast<QDragEnterEvent*>(e);
|
|
|
|
if (AlbumCoverChoiceController::CanAcceptDrag(event)) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QEvent::Drop: {
|
|
|
|
const QDropEvent* event = static_cast<QDropEvent*>(e);
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2011-03-14 21:01:27 +01:00
|
|
|
Song* song = GetFirstSelected();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
const QString cover =
|
|
|
|
album_cover_choice_controller_->SaveCover(song, event);
|
2011-03-14 21:01:27 +01:00
|
|
|
if (!cover.isEmpty()) {
|
|
|
|
UpdateCoverOf(*song, sel, cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-12-25 00:22:09 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-25 01:15:05 +01:00
|
|
|
|
|
|
|
void EditTagDialog::showEvent(QShowEvent* e) {
|
|
|
|
// Set the dialog's height to the smallest possible
|
|
|
|
resize(width(), sizeHint().height());
|
|
|
|
|
2011-11-27 21:36:54 +01:00
|
|
|
// Restore the tab that was current last time.
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
ui_->tab_widget->setCurrentIndex(s.value("current_tab").toInt());
|
|
|
|
|
2010-12-25 01:15:05 +01:00
|
|
|
QDialog::showEvent(e);
|
|
|
|
}
|
2010-12-25 01:33:53 +01:00
|
|
|
|
2011-11-27 21:36:54 +01:00
|
|
|
void EditTagDialog::hideEvent(QHideEvent* e) {
|
|
|
|
// Save the current tab
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
s.setValue("current_tab", ui_->tab_widget->currentIndex());
|
|
|
|
|
|
|
|
QDialog::hideEvent(e);
|
|
|
|
}
|
|
|
|
|
2010-12-25 01:33:53 +01:00
|
|
|
void EditTagDialog::SongRated(float rating) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return;
|
2010-12-25 01:43:55 +01:00
|
|
|
Song* song = &data_[sel.first().row()].original_;
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song->is_valid() || song->id() == -1) return;
|
2010-12-25 01:33:53 +01:00
|
|
|
|
2010-12-25 01:43:55 +01:00
|
|
|
song->set_rating(rating);
|
2012-03-04 14:19:18 +01:00
|
|
|
app_->library_backend()->UpdateSongRatingAsync(song->id(), rating);
|
2010-12-25 01:33:53 +01:00
|
|
|
}
|
2010-12-25 12:54:21 +01:00
|
|
|
|
|
|
|
void EditTagDialog::ResetPlayCounts() {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
|
|
|
if (sel.isEmpty()) return;
|
2010-12-25 12:54:21 +01:00
|
|
|
Song* song = &data_[sel.first().row()].original_;
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!song->is_valid() || song->id() == -1) return;
|
2010-12-25 12:54:21 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (QMessageBox::question(
|
|
|
|
this, tr("Reset play counts"),
|
|
|
|
tr("Are you sure you want to reset this song's statistics?"),
|
|
|
|
QMessageBox::Reset, QMessageBox::Cancel) != QMessageBox::Reset) {
|
2010-12-25 12:54:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
song->set_playcount(0);
|
|
|
|
song->set_skipcount(0);
|
|
|
|
song->set_lastplayed(-1);
|
|
|
|
song->set_score(0);
|
2012-03-04 14:19:18 +01:00
|
|
|
app_->library_backend()->ResetStatisticsAsync(song->id());
|
2010-12-25 12:54:21 +01:00
|
|
|
UpdateStatisticsTab(*song);
|
|
|
|
}
|
2011-01-15 21:00:39 +01:00
|
|
|
|
|
|
|
void EditTagDialog::FetchTag() {
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList sel =
|
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2011-01-15 21:00:39 +01:00
|
|
|
|
2011-03-05 20:24:44 +01:00
|
|
|
SongList songs;
|
2011-01-21 00:42:28 +01:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : sel) {
|
2011-03-05 20:24:44 +01:00
|
|
|
Song song = data_[index.row()].original_;
|
|
|
|
if (!song.is_valid()) {
|
|
|
|
continue;
|
2011-01-21 00:42:28 +01:00
|
|
|
}
|
2011-03-05 20:24:44 +01:00
|
|
|
|
|
|
|
songs << song;
|
2011-01-15 21:00:39 +01:00
|
|
|
}
|
2011-03-05 20:24:44 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (songs.isEmpty()) return;
|
2011-03-05 20:24:44 +01:00
|
|
|
|
|
|
|
results_dialog_->Init(songs);
|
2011-03-12 22:19:41 +01:00
|
|
|
tag_fetcher_->StartFetch(songs);
|
|
|
|
|
2011-03-05 20:24:44 +01:00
|
|
|
results_dialog_->show();
|
2011-01-15 21:00:39 +01:00
|
|
|
}
|
2011-01-21 00:42:28 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void EditTagDialog::FetchTagSongChosen(const Song& original_song,
|
|
|
|
const Song& new_metadata) {
|
2011-04-28 14:27:53 +02:00
|
|
|
const QString filename = original_song.url().toLocalFile();
|
2011-01-21 00:42:28 +01:00
|
|
|
|
2011-03-05 20:24:44 +01:00
|
|
|
// Find the song with this filename
|
2015-10-30 15:13:26 +01:00
|
|
|
auto data_it =
|
|
|
|
std::find_if(data_.begin(), data_.end(), [&filename](const Data& d) {
|
|
|
|
return d.original_.url().toLocalFile() == filename;
|
|
|
|
});
|
|
|
|
if (data_it == data_.end()) {
|
2015-10-30 12:44:12 +01:00
|
|
|
qLog(Warning) << "Could not find song to filename: " << filename;
|
|
|
|
return;
|
|
|
|
}
|
2015-10-30 15:13:26 +01:00
|
|
|
|
2016-01-04 17:09:24 +01:00
|
|
|
// Update song data
|
2015-10-30 15:13:26 +01:00
|
|
|
data_it->current_.set_title(new_metadata.title());
|
|
|
|
data_it->current_.set_artist(new_metadata.artist());
|
|
|
|
data_it->current_.set_album(new_metadata.album());
|
|
|
|
data_it->current_.set_track(new_metadata.track());
|
|
|
|
data_it->current_.set_year(new_metadata.year());
|
|
|
|
|
2016-01-04 17:09:24 +01:00
|
|
|
// Is it currently being displayed in the UI?
|
2016-02-11 16:09:38 +01:00
|
|
|
if (ui_->song_list->currentRow() == std::distance(data_.begin(), data_it)) {
|
2016-01-04 17:09:24 +01:00
|
|
|
// Yes! Additionally update UI
|
2016-01-04 18:56:28 +01:00
|
|
|
const QModelIndexList sel =
|
2016-02-11 16:09:38 +01:00
|
|
|
ui_->song_list->selectionModel()->selectedIndexes();
|
2016-02-09 21:56:22 +01:00
|
|
|
UpdateUI(sel);
|
2011-03-05 20:24:44 +01:00
|
|
|
}
|
2015-10-30 15:17:23 +01:00
|
|
|
}
|