~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to juk/dynamicplaylist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    begin                : Mon May 5 2003
 
3
    copyright            : (C) 2003 - 2004 by Scott Wheeler
 
4
    email                : wheeler@kde.org
 
5
***************************************************************************/
 
6
 
 
7
/***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
 
15
 
 
16
#include <kdebug.h>
 
17
 
 
18
#include "dynamicplaylist.h"
 
19
#include "collectionlist.h"
 
20
#include "playlistcollection.h"
 
21
#include "tracksequencemanager.h"
 
22
 
 
23
class PlaylistDirtyObserver : public PlaylistObserver
 
24
{
 
25
public:
 
26
    PlaylistDirtyObserver(DynamicPlaylist *parent, Playlist *playlist) :
 
27
        PlaylistObserver(playlist),
 
28
        m_parent(parent) 
 
29
    {
 
30
 
 
31
    }
 
32
    virtual void updateData() { m_parent->slotSetDirty(); }
 
33
    virtual void updateCurrent() {}
 
34
 
 
35
private:
 
36
    DynamicPlaylist *m_parent;
 
37
};
 
38
 
 
39
////////////////////////////////////////////////////////////////////////////////
 
40
// public methods
 
41
////////////////////////////////////////////////////////////////////////////////
 
42
 
 
43
DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists,
 
44
                                 PlaylistCollection *collection,
 
45
                                 const QString &name,
 
46
                                 const QString &iconName,
 
47
                                 bool setupPlaylist,
 
48
                                 bool synchronizePlaying) :
 
49
    Playlist(collection, true),
 
50
    m_playlists(playlists),
 
51
    m_dirty(true),
 
52
    m_synchronizePlaying(synchronizePlaying)
 
53
{
 
54
    if(setupPlaylist)
 
55
        collection->setupPlaylist(this, iconName);
 
56
    setName(name);
 
57
 
 
58
    setSorting(columns() + 1);
 
59
 
 
60
    for(PlaylistList::ConstIterator it = playlists.begin(); it != playlists.end(); ++it)
 
61
        m_observers.append(new PlaylistDirtyObserver(this, *it));
 
62
 
 
63
    connect(CollectionList::instance(), SIGNAL(signalCollectionChanged()), this, SLOT(slotSetDirty()));
 
64
}
 
65
 
 
66
DynamicPlaylist::~DynamicPlaylist()
 
67
{
 
68
    lower();
 
69
 
 
70
    for(QValueList<PlaylistObserver *>::ConstIterator it = m_observers.begin();
 
71
        it != m_observers.end();
 
72
        ++it)
 
73
    {
 
74
        delete *it;
 
75
    }
 
76
}
 
77
 
 
78
void DynamicPlaylist::setPlaylists(const PlaylistList &playlists)
 
79
{
 
80
    m_playlists = playlists;
 
81
    updateItems();
 
82
}
 
83
 
 
84
////////////////////////////////////////////////////////////////////////////////
 
85
// public slots
 
86
////////////////////////////////////////////////////////////////////////////////
 
87
 
 
88
void DynamicPlaylist::slotReload()
 
89
{
 
90
    for(PlaylistList::Iterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
 
91
        (*it)->slotReload();
 
92
 
 
93
    checkUpdateItems();
 
94
}
 
95
 
 
96
void DynamicPlaylist::lower(QWidget *top)
 
97
{
 
98
    if(top == this)
 
99
        return;
 
100
 
 
101
    if(playing()) {
 
102
        PlaylistList l;
 
103
        l.append(this);
 
104
        for(PlaylistList::Iterator it = m_playlists.begin();
 
105
            it != m_playlists.end(); ++it)
 
106
        {
 
107
            (*it)->synchronizePlayingItems(l, true);
 
108
        }
 
109
    }
 
110
 
 
111
    PlaylistItemList list = PlaylistItem::playingItems();
 
112
    for(PlaylistItemList::Iterator it = list.begin(); it != list.end(); ++it) {
 
113
        if((*it)->playlist() == this) {
 
114
            list.remove(it);
 
115
            break;
 
116
        }
 
117
    }
 
118
 
 
119
    if(!list.isEmpty())
 
120
        TrackSequenceManager::instance()->setCurrentPlaylist(list.front()->playlist());
 
121
}
 
122
 
 
123
////////////////////////////////////////////////////////////////////////////////
 
124
// protected methods
 
125
////////////////////////////////////////////////////////////////////////////////
 
126
 
 
127
PlaylistItemList DynamicPlaylist::items()
 
128
{
 
129
    checkUpdateItems();
 
130
    return Playlist::items();
 
131
}
 
132
 
 
133
void DynamicPlaylist::showEvent(QShowEvent *e)
 
134
{
 
135
    checkUpdateItems();
 
136
    Playlist::showEvent(e);
 
137
}
 
138
 
 
139
void DynamicPlaylist::paintEvent(QPaintEvent *e)
 
140
{
 
141
    checkUpdateItems();
 
142
    Playlist::paintEvent(e);
 
143
}
 
144
 
 
145
void DynamicPlaylist::updateItems()
 
146
{
 
147
    PlaylistItemList siblings;
 
148
 
 
149
    for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
 
150
        siblings += (*it)->items();
 
151
 
 
152
 
 
153
    PlaylistItemList newSiblings = siblings;
 
154
    if(m_siblings != newSiblings) {
 
155
        m_siblings = newSiblings;
 
156
        QTimer::singleShot(0, this, SLOT(slotUpdateItems()));
 
157
    }
 
158
}
 
159
 
 
160
bool DynamicPlaylist::synchronizePlaying() const
 
161
{
 
162
    return m_synchronizePlaying;
 
163
}
 
164
 
 
165
////////////////////////////////////////////////////////////////////////////////
 
166
// private methods
 
167
////////////////////////////////////////////////////////////////////////////////
 
168
 
 
169
void DynamicPlaylist::checkUpdateItems()
 
170
{
 
171
    if(!m_dirty)
 
172
        return;
 
173
 
 
174
    updateItems();
 
175
 
 
176
    m_dirty = false;
 
177
}
 
178
 
 
179
////////////////////////////////////////////////////////////////////////////////
 
180
// private slots
 
181
////////////////////////////////////////////////////////////////////////////////
 
182
 
 
183
void DynamicPlaylist::slotUpdateItems()
 
184
{
 
185
    // This should be optimized to check to see which items are already in the
 
186
    // list and just adding those and removing the ones that aren't.
 
187
 
 
188
    clear();
 
189
    createItems(m_siblings);
 
190
    if(m_synchronizePlaying)
 
191
        synchronizePlayingItems(m_playlists, true);
 
192
}
 
193
 
 
194
#include "dynamicplaylist.moc"