treeviewitemplaylist.cpp 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2004 Michael Pyne <mpyne@kde.org>
 *
 * This program 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 2 of the License, or (at your option) any later
 * version.
 *
 * This program 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
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16

17 18
#include "treeviewitemplaylist.h"

19 20
#include <kapplication.h>
#include <kdebug.h>
21 22
#include <kmessagebox.h>
#include <klocale.h>
23

24
#include <QStringList>
25 26 27 28 29

#include "collectionlist.h"
#include "tag.h"
#include "playlistitem.h"
#include "playlistsearch.h"
30
#include "tagtransactionmanager.h"
31 32 33

TreeViewItemPlaylist::TreeViewItemPlaylist(PlaylistCollection *collection,
                                           const PlaylistSearch &search,
34 35
                                           const QString &name) :
    SearchPlaylist(collection, search, name, false)
36 37 38 39 40
{
    PlaylistSearch::Component component = *(search.components().begin());
    m_columnType = static_cast<PlaylistItem::ColumnType>(*(component.columns().begin()));
}

Scott Wheeler's avatar
Scott Wheeler committed
41
void TreeViewItemPlaylist::retag(const QStringList &files, Playlist *)
42 43 44 45
{
    CollectionList *collection = CollectionList::instance();

    if(files.isEmpty())
Scott Wheeler's avatar
Scott Wheeler committed
46
        return;
47

48 49 50
    QString changedTag = i18n("artist");
    if(m_columnType == PlaylistItem::GenreColumn)
        changedTag = i18n("genre");
51
    else if(m_columnType == PlaylistItem::AlbumColumn)
52 53 54 55
        changedTag = i18n("album");

    if(KMessageBox::warningContinueCancelList(
           this,
56
           i18n("You are about to change the %1 on these files.", changedTag),
57
           files,
58
           i18n("Changing Track Tags"),
Aaron J. Seigo's avatar
build  
Aaron J. Seigo committed
59
           KStandardGuiItem::cont(),
60
           KStandardGuiItem::cancel(),
61 62 63 64 65 66
           "dragDropRetagWarn"
       ) == KMessageBox::Cancel)
    {
        return;
    }

67 68 69 70 71 72
    QStringList::ConstIterator it;
    for(it = files.begin(); it != files.end(); ++it) {
        CollectionListItem *item = collection->lookup(*it);
        if(!item)
            continue;

73
        Tag *tag = TagTransactionManager::duplicateTag(item->file().tag());
74 75 76 77
        switch(m_columnType) {
        case PlaylistItem::ArtistColumn:
            tag->setArtist(name());
            break;
78

79 80 81 82 83 84 85 86 87
        case PlaylistItem::AlbumColumn:
            tag->setAlbum(name());
            break;

        case PlaylistItem::GenreColumn:
            tag->setGenre(name());
            break;

        default:
88
            kDebug() << "Unhandled column type editing " << *it;
89 90
        }

91
        TagTransactionManager::instance()->changeTagOnItem(item, tag);
92 93 94
    }
}

95
// vim: set et sw=4 tw=0 sta: