File indexing completed on 2023-05-30 11:30:47

0001 /**
0002  * Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or modify it under
0005  * the terms of the GNU General Public License as published by the Free Software
0006  * Foundation; either version 2 of the License, or (at your option) any later
0007  * version.
0008  *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012  *
0013  * You should have received a copy of the GNU General Public License along with
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.
0015  */
0016 
0017 #include "folderplaylist.h"
0018 #include "playlistcollection.h"
0019 #include "juk-exception.h"
0020 
0021 #include <QTimer>
0022 
0023 ////////////////////////////////////////////////////////////////////////////////
0024 // public methods
0025 ////////////////////////////////////////////////////////////////////////////////
0026 
0027 FolderPlaylist::FolderPlaylist(PlaylistCollection *collection, const QString &folder,
0028                                const QString &name) :
0029     Playlist(collection, name, "folder"),
0030     m_folder(folder)
0031 {
0032     setAllowDuplicates(false);
0033     QTimer::singleShot(0, this, SLOT(slotReload()));
0034 }
0035 
0036 FolderPlaylist::~FolderPlaylist()
0037 {
0038 
0039 }
0040 
0041 QString FolderPlaylist::folder() const
0042 {
0043     return m_folder;
0044 }
0045 
0046 void FolderPlaylist::setFolder(const QString &s)
0047 {
0048     m_folder = s;
0049     QTimer::singleShot(0, this, SLOT(slotReload()));
0050 }
0051 
0052 ////////////////////////////////////////////////////////////////////////////////
0053 // private slots
0054 ////////////////////////////////////////////////////////////////////////////////
0055 
0056 void FolderPlaylist::slotReload()
0057 {
0058     if(!m_folder.isEmpty())
0059         addFiles(QStringList(m_folder));
0060 }
0061 
0062 ////////////////////////////////////////////////////////////////////////////////
0063 // helper functions
0064 ////////////////////////////////////////////////////////////////////////////////
0065 
0066 QDataStream &operator<<(QDataStream &s, const FolderPlaylist &p)
0067 {
0068     s << p.name()
0069       << p.folder();
0070     return s;
0071 }
0072 
0073 QDataStream &operator>>(QDataStream &s, FolderPlaylist &p)
0074 {
0075     QString name;
0076     QString folder;
0077     s >> name
0078       >> folder;
0079 
0080     if(folder.isEmpty() || name.isEmpty())
0081         throw BICStreamException();
0082 
0083     p.setFolder(folder);
0084     p.setName(name);
0085     return s;
0086 }
0087 
0088 // vim: set et sw=4 tw=0 sta: