File indexing completed on 2023-05-30 11:30:53
0001 /** 0002 * Copyright (C) 2004 Michael Pyne <mpyne@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify it under 0005 * the terms of the GNU General Public License as published by the Free Software 0006 * Foundation; either version 2 of the License, or (at your option) any later 0007 * version. 0008 * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU General Public License along with 0014 * this program. If not, see <http://www.gnu.org/licenses/>. 0015 */ 0016 0017 #include "treeviewitemplaylist.h" 0018 0019 #include <kmessagebox.h> 0020 #include <KLocalizedString> 0021 0022 #include <QStringList> 0023 0024 #include "collectionlist.h" 0025 #include "juktag.h" 0026 #include "playlistitem.h" 0027 #include "playlistsearch.h" 0028 #include "tagtransactionmanager.h" 0029 #include "juk_debug.h" 0030 0031 TreeViewItemPlaylist::TreeViewItemPlaylist(PlaylistCollection *collection, 0032 PlaylistSearch &search, 0033 const QString &name) : 0034 SearchPlaylist(collection, search, name, false) 0035 { 0036 const PlaylistSearch::ComponentList components(search.components()); 0037 const PlaylistSearch::Component component = components.first(); 0038 m_columnType = static_cast<PlaylistItem::ColumnType>(component.columns().constFirst()); 0039 } 0040 0041 void TreeViewItemPlaylist::retag(const QStringList &files, Playlist *) 0042 { 0043 CollectionList *collection = CollectionList::instance(); 0044 0045 if(files.isEmpty()) 0046 return; 0047 0048 QString changedTag = i18n("artist"); 0049 if(m_columnType == PlaylistItem::GenreColumn) 0050 changedTag = i18n("genre"); 0051 else if(m_columnType == PlaylistItem::AlbumColumn) 0052 changedTag = i18n("album"); 0053 0054 if(KMessageBox::warningContinueCancelList( 0055 this, 0056 i18n("You are about to change the %1 on these files.", changedTag), 0057 files, 0058 i18n("Changing Track Tags"), 0059 KStandardGuiItem::cont(), 0060 KStandardGuiItem::cancel(), 0061 "dragDropRetagWarn" 0062 ) == KMessageBox::Cancel) 0063 { 0064 return; 0065 } 0066 0067 QStringList::ConstIterator it; 0068 for(it = files.begin(); it != files.end(); ++it) { 0069 CollectionListItem *item = collection->lookup(*it); 0070 if(!item) 0071 continue; 0072 0073 Tag *tag = TagTransactionManager::duplicateTag(item->file().tag()); 0074 switch(m_columnType) { 0075 case PlaylistItem::ArtistColumn: 0076 tag->setArtist(name()); 0077 break; 0078 0079 case PlaylistItem::AlbumColumn: 0080 tag->setAlbum(name()); 0081 break; 0082 0083 case PlaylistItem::GenreColumn: 0084 tag->setGenre(name()); 0085 break; 0086 0087 default: 0088 qCDebug(JUK_LOG) << "Unhandled column type editing " << *it; 0089 } 0090 0091 TagTransactionManager::instance()->changeTagOnItem(item, tag); 0092 } 0093 } 0094 0095 // vim: set et sw=4 tw=0 sta: