treeviewitemplaylist.cpp 2.9 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
#include <kmessagebox.h>
Michael Pyne's avatar
Michael Pyne committed
20
#include <KLocalizedString>
21

22
#include <QStringList>
23 24 25 26 27

#include "collectionlist.h"
#include "tag.h"
#include "playlistitem.h"
#include "playlistsearch.h"
28
#include "tagtransactionmanager.h"
Michael Pyne's avatar
Michael Pyne committed
29
#include "juk_debug.h"
30 31 32

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

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

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

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

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

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

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

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

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

        default:
Michael Pyne's avatar
Michael Pyne committed
87
            qCDebug(JUK_LOG) << "Unhandled column type editing " << *it;
88 89
        }

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

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