folderplaylist.cpp 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/***************************************************************************
    copyright            : (C) 2004 by Scott Wheeler
    email                : wheeler@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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "folderplaylist.h"
16
#include "playlistcollection.h"
17
#include "juk-exception.h"
18

19
#include <QTimer>
20 21 22 23 24 25 26

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

FolderPlaylist::FolderPlaylist(PlaylistCollection *collection, const QString &folder,
                               const QString &name) :
27
    Playlist(collection, name, "folder"),
28 29
    m_folder(folder)
{
30
    QTimer::singleShot(0, this, SLOT(slotReload()));
31 32 33 34 35 36 37
}

FolderPlaylist::~FolderPlaylist()
{

}

38 39 40 41 42 43 44 45
QString FolderPlaylist::folder() const
{
    return m_folder;
}

void FolderPlaylist::setFolder(const QString &s)
{
    m_folder = s;
46
    QTimer::singleShot(0, this, SLOT(slotReload()));
47 48 49 50 51 52
}

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

53
void FolderPlaylist::slotReload()
54
{
55
    if(!m_folder.isEmpty())
56
        addFiles(QStringList(m_folder));
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
}

////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////

QDataStream &operator<<(QDataStream &s, const FolderPlaylist &p)
{
    s << p.name()
      << p.folder();
    return s;
}

QDataStream &operator>>(QDataStream &s, FolderPlaylist &p)
{
    QString name;
    QString folder;
    s >> name
      >> folder;

77 78 79
    if(folder.isEmpty() || name.isEmpty())
        throw BICStreamException();

80 81 82 83 84
    p.setFolder(folder);
    p.setName(name);
    return s;
}

85
#include "folderplaylist.moc"
86 87

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