File indexing completed on 2024-05-05 04:48:27
0001 /**************************************************************************************** 0002 * Copyright (c) 2004 Mark Kretschmann <kretschmann@kde.org> * 0003 * Copyright (c) 2004 Pierpaolo Di Panfilo <pippo_dp@libero.it> * 0004 * Copyright (c) 2005 Alexandre Pereira de Oliveira <aleprj@gmail.com> * 0005 * Copyright (c) 2008 Leo Franchi <lfranchi@kde.org> * 0006 * Copyright (c) 2011 Ralf Engels <ralf-engels@gmx.de> * 0007 * * 0008 * This program is free software; you can redistribute it and/or modify it under * 0009 * the terms of the GNU General Public License as published by the Free Software * 0010 * Foundation; either version 2 of the License, or (at your option) any later * 0011 * version. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0014 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0015 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License along with * 0018 * this program. If not, see <http://www.gnu.org/licenses/>. * 0019 ****************************************************************************************/ 0020 0021 #ifndef AMAROK_TAGDIALOG_H 0022 #define AMAROK_TAGDIALOG_H 0023 0024 #include <config.h> 0025 0026 #include "amarok_export.h" 0027 #include "playlist/PlaylistItem.h" 0028 #include "LabelListModel.h" 0029 0030 #include "core/meta/Observer.h" 0031 #include "core/collections/MetaQueryMaker.h" 0032 0033 #include <QDialog> 0034 0035 #include <QDateTime> 0036 #include <QLabel> 0037 #include <QListIterator> 0038 #include <QMap> 0039 #include <QSet> 0040 #include <QVariant> 0041 #include <QWidget> 0042 0043 namespace Ui 0044 { 0045 class TagDialogBase; 0046 } 0047 0048 class QComboBox; 0049 0050 class AMAROK_EXPORT TagDialog : public QDialog, public Meta::Observer 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 0056 enum Tabs { SUMMARYTAB, TAGSTAB, LYRICSTAB, LABELSTAB }; 0057 0058 explicit TagDialog( const Meta::TrackList &tracks, QWidget *parent = nullptr ); 0059 explicit TagDialog( Meta::TrackPtr track, QWidget *parent = nullptr ); 0060 explicit TagDialog( Collections::QueryMaker *qm ); 0061 ~TagDialog() override; 0062 0063 // inherited from Meta::Observer 0064 using Observer::metadataChanged; 0065 void metadataChanged( const Meta::AlbumPtr &album ) override; 0066 0067 private Q_SLOTS: 0068 void accept() override; 0069 void cancelPressed(); 0070 void openPressed(); 0071 void previousTrack(); 0072 void nextTrack(); 0073 void perTrack( bool ); 0074 void checkChanged(); 0075 0076 /** 0077 * removes selected label from list 0078 */ 0079 void removeLabelPressed(); 0080 0081 /** 0082 * adds label to list 0083 */ 0084 void addLabelPressed(); 0085 0086 void showCoverMenu( const QPoint &pos ); 0087 0088 /** 0089 * Shows FileNameLayoutDialog to guess tags from filename 0090 */ 0091 void guessFromFilename(); 0092 0093 void musicbrainzTagger(); 0094 void musicbrainzTaggerResult( const QMap<Meta::TrackPtr, QVariantMap > &result ); 0095 0096 /** Safely adds a track to m_tracks. 0097 Ensures that tracks are not added twice. 0098 */ 0099 void addTrack( Meta::TrackPtr &track ); 0100 0101 void tracksReady( const Meta::TrackList &tracks ); 0102 void queryDone(); 0103 0104 void albumsReady( const Meta::AlbumList &albums ); 0105 void artistsReady( const Meta::ArtistList &artists ); 0106 void composersReady( const Meta::ComposerList &composers ); 0107 void genresReady( const Meta::GenreList &genres ); 0108 /** 0109 * Updates global label list by querying all collections for all existing labels. 0110 */ 0111 void labelsReady( const Meta::LabelList &labels ); 0112 void dataQueryDone(); 0113 0114 /** 0115 * Updates Add label button 0116 */ 0117 void labelModified(); 0118 0119 /** 0120 * Updates Remove label button 0121 */ 0122 void labelSelected(); 0123 0124 private: 0125 /** Sets some further properties and connects all the signals */ 0126 void initUi(); 0127 0128 /** Set's the current track to the number. 0129 Will check against invalid numbers, so the caller does not have to do that. 0130 */ 0131 void setCurrentTrack( int num ); 0132 0133 /** Start a query maker for the given query type */ 0134 void startDataQuery( Collections::QueryMaker::QueryType type, const QMetaMethod &signal, const QMetaMethod &slot ); 0135 0136 /** Start queries for artists, albums, composers, genres and labels to fill out the combo boxes */ 0137 void startDataQueries(); 0138 0139 /** Sets the tags in the UI, cleaning unset tags */ 0140 void setTagsToUi( const QVariantMap &tags ); 0141 0142 /** Sets the tags in the UI, cleaning unset tags depending on m_perTrack */ 0143 void setTagsToUi(); 0144 0145 /** Gets the changed tags from the UI */ 0146 QVariantMap getTagsFromUi( const QVariantMap &tags ) const; 0147 0148 /** Gets all the needed tags (just the one that we display or edit) from the track */ 0149 QVariantMap getTagsFromTrack( const Meta::TrackPtr &track ) const; 0150 0151 /** Gets a summary of all the tags from m_tracks */ 0152 QVariantMap getTagsFromMultipleTracks() const; 0153 0154 /** Overwrites all values in the stored tags with the new ones. Tags not in "tags" map are left unchanged. */ 0155 void setTagsToTrack( const Meta::TrackPtr &track, const QVariantMap &tags ); 0156 0157 /** Overwrites all values in the stored tags with the new ones. 0158 Tags not in "tags" map are left unchanged. 0159 Exception are labels which are not set. 0160 */ 0161 void setTagsToMultipleTracks( QVariantMap tags ); 0162 0163 /** Smartly writes back tags data depending on m_perTrack */ 0164 void setTagsToTrack(); 0165 0166 /** Sets the UI to edit either one or the complete list of tracks. 0167 Don't forget to save the old ui values and set the new tags afterwards. 0168 */ 0169 void setPerTrack( bool isEnabled ); 0170 0171 void updateButtons(); 0172 void updateCover(); 0173 void setControlsAccessability(); 0174 0175 /** Writes all the tags to all the tracks. 0176 This finally updates the Meta::Tracks 0177 */ 0178 void saveTags(); 0179 0180 /** 0181 * Returns "Unknown" if the value is null or not known 0182 * Otherwise returns the string 0183 */ 0184 const QString unknownSafe( const QString &s ) const; 0185 const QString unknownSafe( int i ) const; 0186 0187 const QStringList filenameSchemes(); 0188 0189 void selectOrInsertText( const QString &text, QComboBox *comboBox ); 0190 0191 QString m_path; // the directory of the current track/tracks 0192 0193 LabelListModel *m_labelModel; //!< Model MVC Class for Track label list 0194 0195 bool m_perTrack; 0196 Meta::TrackList m_tracks; 0197 Meta::TrackPtr m_currentTrack; 0198 Meta::AlbumPtr m_currentAlbum; 0199 int m_currentTrackNum; 0200 0201 /** True if m_storedTags contains changed. 0202 The pushButton_ok will be activated if this one is true and the UI 0203 has further changes 0204 */ 0205 bool m_changed; 0206 0207 /** The tags for the tracks. 0208 If the tags are edited then this structure is updated when switching 0209 between single and multiple mode or when pressing the save button. 0210 */ 0211 QMap<Meta::TrackPtr, QVariantMap > m_storedTags; 0212 0213 // the query maker to get the tracks to be edited 0214 Collections::QueryMaker *m_queryMaker; 0215 0216 QSet<QString> m_artists; 0217 QSet<QString> m_albums; 0218 QSet<QString> m_albumArtists; 0219 QSet<QString> m_composers; 0220 QSet<QString> m_genres; 0221 QSet<QString> m_allLabels; //! all labels known to currently active collections, used for autocompletion 0222 0223 Ui::TagDialogBase *ui; 0224 }; 0225 0226 0227 #endif /*AMAROK_TAGDIALOG_H*/ 0228