playlistsplitter.cpp 6.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/***************************************************************************
                          playlistsplitter.cpp  -  description
                             -------------------
    begin                : Fri Sep 13 2002
    copyright            : (C) 2002 by Scott Wheeler
    email                : scott@slackorama.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kiconloader.h>
19
#include <klocale.h>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <kdebug.h>

#include "playlistsplitter.h"

////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////

PlaylistSplitter::PlaylistSplitter(QWidget *parent, const char *name) : QSplitter(Qt::Horizontal, parent, name)
{
    setupLayout();
    readConfig();
}

PlaylistSplitter::~PlaylistSplitter()
{

}

void PlaylistSplitter::createPlaylist(const QString &name)
{
    Playlist *p = new Playlist(playlistStack, name.latin1());
    (void) new PlaylistBoxItem(playlistBox, SmallIcon("midi", 32), name, p);
    connect(p, SIGNAL(selectionChanged(const QPtrList<PlaylistItem> &)), editor, SLOT(setItems(const QPtrList<PlaylistItem> &)));
    connect(p, SIGNAL(doubleClicked(QListViewItem *)), this, SIGNAL(playlistDoubleClicked(QListViewItem *)));
45
    connect(p, SIGNAL(collectionChanged()), editor, SLOT(updateCollection()));
46 47
}

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
QString PlaylistSplitter::uniquePlaylistName()
{
    if(!playlistBox)
	return(QString::null);

    QStringList names = playlistBox->names();

    QString newName = i18n("Playlist");
    int playlistNumber = 1;

    // while the list contains more than zero instances of the generated 
    // string...

    while(names.contains(newName + ' ' + QString::number(playlistNumber)) != 0)
	playlistNumber++;
    
    return(newName + " " + QString::number(playlistNumber));
}

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
QPtrList<PlaylistItem> PlaylistSplitter::playlistSelection() const
{
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    return(p->selectedItems());
}

PlaylistItem *PlaylistSplitter::playlistFirstItem() const
{
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    PlaylistItem *i = static_cast<PlaylistItem *>(p->firstChild());
    return(i);
}

////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////

void PlaylistSplitter::open(const QStringList &files)
{
86 87
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    p->append(files);
88 89 90 91
}

void PlaylistSplitter::open(const QString &file)
{
92 93 94
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    p->append(file);
}
95

96 97 98 99
void PlaylistSplitter::save()
{
    if(editor)
	editor->save();
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
}

void PlaylistSplitter::remove()
{
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    p->remove();
}

void PlaylistSplitter::setEditorVisible(bool visible)
{
    if(visible)
	editor->show();
    else
	editor->hide();
}

void PlaylistSplitter::clearSelectedItems()
{
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    p->clearItems(p->selectedItems()); 
}

void PlaylistSplitter::selectAll(bool select)
{
    Playlist *p = static_cast<Playlist *>(playlistStack->visibleWidget());
    p->selectAll(select);
}

////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

void PlaylistSplitter::setupLayout()
{
    setOpaqueResize();
135

136 137 138 139 140
    playlistBox = new PlaylistBox(this, "playlistBox");

    // Create a splitter to go between the playlists and the editor.

    QSplitter *editorSplitter = new QSplitter(Qt::Vertical, this, "editorSplitter");
141
    editorSplitter->setOpaqueResize();
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

    // Create the playlist and the editor.

    playlistStack = new QWidgetStack(editorSplitter, "playlistStack");
    editor = new TagEditor(editorSplitter, "tagEditor");

    // Make the editor as small as possible (or at least as small as recommended)

    editorSplitter->setResizeMode(editor, QSplitter::FollowSizeHint);

    // Make the connection that will update the selected playlist when a 
    // selection is made in the playlist box.

    connect(playlistBox, SIGNAL(currentChanged(PlaylistBoxItem *)), this, SLOT(changePlaylist(PlaylistBoxItem *)));

    // Create the collection list; this should always exist.  This has a 
    // slightly different creation process than normal playlists (since it in
    // fact is a subclass) so it is created here rather than by using 
    // createPlaylist().

162 163 164 165 166 167 168 169
    CollectionList::initialize(playlistStack);
    collection = CollectionList::instance();

    PlaylistBoxItem *collectionBoxItem = new PlaylistBoxItem(playlistBox, SmallIcon("folder_sound", 32), 
							     i18n("Music Collection"), collection);

    connect(collection, SIGNAL(selectionChanged(const QPtrList<PlaylistItem> &)), 
	    editor, SLOT(setItems(const QPtrList<PlaylistItem> &)));
170
    connect(collection, SIGNAL(doubleClicked(QListViewItem *)), this, SIGNAL(playlistDoubleClicked(QListViewItem *)));
171
    connect(collection, SIGNAL(collectionChanged()), editor, SLOT(updateCollection()));
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

    // Show the collection on startup.
    playlistBox->setSelected(collectionBoxItem, true);
}

void PlaylistSplitter::readConfig()
{

}

////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////

void PlaylistSplitter::changePlaylist(PlaylistBoxItem *item)
{
    if(item && item->playlist()) {
	playlistStack->raiseWidget(item->playlist());
	editor->setItems(playlistSelection());
    }
}

#include "playlistsplitter.moc"