strawberry-audio-player-win.../src/dialogs/edittagdialog.h

214 lines
6.0 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef EDITTAGDIALOG_H
#define EDITTAGDIALOG_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
2020-02-09 02:29:35 +01:00
#include <QAbstractItemModel>
2018-02-27 18:06:05 +01:00
#include <QDialog>
#include <QVariant>
#include <QString>
2020-02-09 02:29:35 +01:00
#include <QUrl>
#include <QList>
#include <QMap>
#include <QImage>
2018-02-27 18:06:05 +01:00
#include "core/song.h"
#include "core/tagreaderclient.h"
2018-02-27 18:06:05 +01:00
#include "playlist/playlistitem.h"
#include "covermanager/albumcoverloaderoptions.h"
#include "covermanager/albumcoverloaderresult.h"
#include "covermanager/albumcoverimageresult.h"
2020-02-09 02:29:35 +01:00
class QWidget;
class QMenu;
class QLabel;
class QAbstractButton;
class QPushButton;
class QEvent;
class QShowEvent;
class QHideEvent;
2018-02-27 18:06:05 +01:00
class Application;
class AlbumCoverChoiceController;
class Ui_EditTagDialog;
#ifdef HAVE_MUSICBRAINZ
class TrackSelectionDialog;
2018-07-16 07:23:37 +02:00
class TagFetcher;
#endif
2018-02-27 18:06:05 +01:00
class EditTagDialog : public QDialog {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit EditTagDialog(Application *app, QWidget *parent = nullptr);
2020-06-15 21:55:05 +02:00
~EditTagDialog() override;
2018-02-27 18:06:05 +01:00
static const char *kSettingsGroup;
static const char *kTagsDifferentHintText;
static const char *kArtDifferentHintText;
2018-02-27 18:06:05 +01:00
void SetSongs(const SongList &songs, const PlaylistItemList &items = PlaylistItemList());
PlaylistItemList playlist_items() const { return playlist_items_; }
2020-06-15 21:55:05 +02:00
void accept() override;
2018-02-27 18:06:05 +01:00
signals:
2021-01-26 16:48:04 +01:00
void Error(QString message);
2018-02-27 18:06:05 +01:00
protected:
2020-06-15 21:55:05 +02:00
bool eventFilter(QObject *o, QEvent *e) override;
void showEvent(QShowEvent *e) override;
void hideEvent(QHideEvent *e) override;
2018-02-27 18:06:05 +01:00
private:
enum UpdateCoverAction {
UpdateCoverAction_None = 0,
UpdateCoverAction_Clear,
UpdateCoverAction_Unset,
UpdateCoverAction_Delete,
UpdateCoverAction_New,
};
2018-02-27 18:06:05 +01:00
struct Data {
explicit Data(const Song &song = Song()) : original_(song), current_(song), cover_action_(UpdateCoverAction_None) {}
2018-02-27 18:06:05 +01:00
static QVariant value(const Song &song, const QString &id);
QVariant original_value(const QString &id) const { return value(original_, id); }
QVariant current_value(const QString &id) const { return value(current_, id); }
2018-02-27 18:06:05 +01:00
void set_value(const QString &id, const QVariant &value);
Song original_;
Song current_;
UpdateCoverAction cover_action_;
AlbumCoverImageResult cover_result_;
2018-02-27 18:06:05 +01:00
};
private slots:
2021-01-30 21:53:53 +01:00
void SetSongsFinished();
2018-02-27 18:06:05 +01:00
void AcceptFinished();
void SelectionChanged();
void FieldValueEdited();
void ResetField();
void ButtonClicked(QAbstractButton *button);
void ResetPlayCounts();
void FetchTag();
void FetchTagSongChosen(const Song &original_song, const Song &new_metadata);
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
2018-02-27 18:06:05 +01:00
void LoadCoverFromFile();
void SaveCoverToFile();
void LoadCoverFromURL();
void SearchForCover();
void UnsetCover();
void ClearCover();
void DeleteCover();
2018-02-27 18:06:05 +01:00
void ShowCover();
void PreviousSong();
void NextSong();
void SongSaveTagsComplete(TagReaderReply *reply, const QString &filename, Song song);
2021-03-21 04:47:11 +01:00
void SongSaveArtComplete(TagReaderReply *reply, const QString &filename, Song song, const EditTagDialog::UpdateCoverAction cover_action);
2018-02-27 18:06:05 +01:00
private:
struct FieldData {
2020-06-26 22:41:38 +02:00
explicit FieldData(QLabel *label = nullptr, QWidget *editor = nullptr, const QString &id = QString())
2018-02-27 18:06:05 +01:00
: label_(label), editor_(editor), id_(id) {}
QLabel *label_;
QWidget *editor_;
QString id_;
};
Song *GetFirstSelected();
void UpdateCover(const UpdateCoverAction action, const AlbumCoverImageResult &result = AlbumCoverImageResult());
2018-02-27 18:06:05 +01:00
bool DoesValueVary(const QModelIndexList &sel, const QString &id) const;
bool IsValueModified(const QModelIndexList &sel, const QString &id) const;
void InitFieldValue(const FieldData &field, const QModelIndexList &sel);
void UpdateFieldValue(const FieldData &field, const QModelIndexList &sel);
void UpdateModifiedField(const FieldData &field, const QModelIndexList &sel);
void ResetFieldValue(const FieldData &field, const QModelIndexList &sel);
void UpdateSummaryTab(const Song &song, const UpdateCoverAction cover_action);
2018-02-27 18:06:05 +01:00
void UpdateStatisticsTab(const Song &song);
QString GetArtSummary(const Song &song, const UpdateCoverAction cover_action);
void UpdateUI(const QModelIndexList &indexes);
2018-02-27 18:06:05 +01:00
bool SetLoading(const QString &message);
void SetSongListVisibility(bool visible);
// Called by QtConcurrentRun
QList<Data> LoadData(const SongList &songs) const;
void SaveData();
static void SetText(QLabel *label, const int value, const QString &suffix, const QString &def = QString());
static void SetDate(QLabel *label, const uint time);
2018-02-27 18:06:05 +01:00
private:
2018-02-27 18:06:05 +01:00
Ui_EditTagDialog *ui_;
Application *app_;
AlbumCoverChoiceController *album_cover_choice_controller_;
#ifdef HAVE_MUSICBRAINZ
TagFetcher *tag_fetcher_;
TrackSelectionDialog *results_dialog_;
#endif
const QImage image_no_cover_thumbnail_;
2018-02-27 18:06:05 +01:00
bool loading_;
PlaylistItemList playlist_items_;
QList<Data> data_;
QList<FieldData> fields_;
bool ignore_edits_;
AlbumCoverLoaderOptions cover_options_;
quint64 summary_cover_art_id_;
quint64 tags_cover_art_id_;
2018-02-27 18:06:05 +01:00
bool cover_art_is_set_;
QMenu *cover_menu_;
QPushButton *previous_button_;
QPushButton *next_button_;
int save_tag_pending_;
int save_art_pending_;
QMap<int, Song> collection_songs_;
2018-02-27 18:06:05 +01:00
};
#endif // EDITTAGDIALOG_H