searchplaylist.cpp 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2003-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 "searchplaylist.h"
18
#include "juk-exception.h"
19 20

#include <QHash>
21

22
#include "playlistitem.h"
23
#include "collectionlist.h"
Michael Pyne's avatar
Michael Pyne committed
24
#include "juk_debug.h"
25 26 27 28 29

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

30 31
SearchPlaylist::SearchPlaylist(PlaylistCollection *collection,
                               const PlaylistSearch &search,
32
                               const QString &name,
33 34
                               bool setupPlaylist,
                               bool synchronizePlaying) :
35
    DynamicPlaylist(search.playlists(), collection, name, "edit-find",
36
                    setupPlaylist, synchronizePlaying),
37
    m_search(search)
38 39
{

40 41
}

42 43 44 45
void SearchPlaylist::setPlaylistSearch(const PlaylistSearch &s, bool update)
{
    m_search = s;
    if(update)
46
        setPlaylists(s.playlists());
47 48
}

49
////////////////////////////////////////////////////////////////////////////////
50
// protected methods
51 52
////////////////////////////////////////////////////////////////////////////////

53
void SearchPlaylist::updateItems()
54
{
55 56
    // Here we don't simply use "clear" since that would involve a call to
    // items() which would in turn call this method...
57

58
    m_search.search();
59
    synchronizeItemsTo(m_search.matchedItems());
60 61

    if(synchronizePlaying()) {
Michael Pyne's avatar
Michael Pyne committed
62
        qCDebug(JUK_LOG) << "synchronizing playing";
63 64
        synchronizePlayingItems(m_search.playlists(), true);
    }
65
}
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

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

QDataStream &operator<<(QDataStream &s, const SearchPlaylist &p)
{
    s << p.name()
      << p.playlistSearch();

    return s;
}

QDataStream &operator>>(QDataStream &s, SearchPlaylist &p)
{
    QString name;
    PlaylistSearch search;

    s >> name
      >> search;

88 89 90
    if(name.isEmpty())
        throw BICStreamException();

91
    p.setName(name);
92
    p.setPlaylistSearch(search, false);
93 94 95 96

    return s;
}

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