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

#include "folderplaylist.h"
18
#include "playlistcollection.h"
19
#include "juk-exception.h"
20

21
#include <QTimer>
22 23 24 25 26 27 28

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

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

FolderPlaylist::~FolderPlaylist()
{

}

41 42 43 44 45 46 47 48
QString FolderPlaylist::folder() const
{
    return m_folder;
}

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

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

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

////////////////////////////////////////////////////////////////////////////////
// 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;

80 81 82
    if(folder.isEmpty() || name.isEmpty())
        throw BICStreamException();

83 84 85 86 87
    p.setFolder(folder);
    p.setName(name);
    return s;
}

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