~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/splitplaylist/playlist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "playlist.h"
 
2
#include "view.h"
 
3
#include <player.h>
 
4
 
 
5
#include <krandomsequence.h>
 
6
 
 
7
SplitPlaylist *SplitPlaylist::Self=0;
 
8
 
 
9
SplitPlaylist::SplitPlaylist()
 
10
        : Playlist(0, "SplitPlaylist"), Plugin(), nextItem(0), currentItem(0), previousItem(0)
 
11
{
 
12
        Self=this;
 
13
}
 
14
 
 
15
void SplitPlaylist::init()
 
16
{
 
17
        view=new View(this); // 195
 
18
        connect(view->listView(), SIGNAL(doubleClicked(QListViewItem*)), SLOT(listItemSelected(QListViewItem*)));
 
19
        connect(view, SIGNAL(shown()), SIGNAL(listShown()));
 
20
        connect(view, SIGNAL(hidden()), SIGNAL(listHidden()));
 
21
        
 
22
        view->init(); // 1000
 
23
}
 
24
 
 
25
SplitPlaylist::~SplitPlaylist()
 
26
{
 
27
        delete view;
 
28
}
 
29
 
 
30
void SplitPlaylist::reset()
 
31
{
 
32
        previousItem=0;
 
33
        SafeListViewItem *i;
 
34
        setCurrent(i=static_cast<SafeListViewItem*>(view->listView()->firstChild()));
 
35
        if (i && !i->isOn())
 
36
                next();
 
37
}
 
38
        
 
39
PlaylistItem *SplitPlaylist::next()
 
40
{
 
41
        if (!nextItem) return 0;
 
42
        setCurrent(nextItem);
 
43
        if (currentItem)
 
44
                if (!static_cast<SafeListViewItem*>(currentItem)->isOn())
 
45
                        return next();
 
46
        
 
47
        return currentItem;
 
48
}
 
49
 
 
50
PlaylistItem *SplitPlaylist::current()
 
51
{
 
52
        return currentItem;
 
53
}
 
54
 
 
55
PlaylistItem *SplitPlaylist::previous()
 
56
{
 
57
        if (!previousItem) return 0;
 
58
        setCurrent(previousItem);
 
59
        
 
60
        if (currentItem)
 
61
                if (!static_cast<SafeListViewItem*>(currentItem)->isOn())
 
62
                        return previous();
 
63
 
 
64
        return currentItem;
 
65
}
 
66
 
 
67
PlaylistItem *SplitPlaylist::getFirst() const
 
68
{
 
69
        return static_cast<SafeListViewItem*>(view->listView()->firstChild());
 
70
}
 
71
 
 
72
PlaylistItem *SplitPlaylist::getAfter(const PlaylistItem *item) const
 
73
{
 
74
        if (item)
 
75
                return static_cast<SafeListViewItem*>(static_cast<const SafeListViewItem*>(item)->nextSibling());
 
76
        return 0;
 
77
}
 
78
        
 
79
bool SplitPlaylist::listVisible() const
 
80
{
 
81
        return view->isVisible();
 
82
}
 
83
 
 
84
void SplitPlaylist::showList()
 
85
{
 
86
        view->show();
 
87
}
 
88
 
 
89
void SplitPlaylist::hideList()
 
90
{
 
91
        view->hide();
 
92
}
 
93
 
 
94
void SplitPlaylist::clear()
 
95
{
 
96
        view->listView()->clear();
 
97
}
 
98
 
 
99
void SplitPlaylist::addFile(const KURL &file, bool play)
 
100
{
 
101
        view->addFile(file, play);
 
102
}
 
103
 
 
104
void SplitPlaylist::setNext(PlaylistItem *i)
 
105
{
 
106
        nextItem=i;
 
107
}
 
108
 
 
109
void SplitPlaylist::setCurrent(PlaylistItem *i)
 
110
{
 
111
        bool emitC=currentItem==0;
 
112
        if (!i)
 
113
        {
 
114
                currentItem=0;
 
115
                return;
 
116
        }
 
117
 
 
118
        QRect rect(view->listView()->itemRect(static_cast<SafeListViewItem*>(current())));
 
119
        rect.setWidth(view->listView()->viewport()->width());
 
120
        currentItem=i;  
 
121
        view->listView()->viewport()->repaint(rect,true);
 
122
 
 
123
        view->listView()->ensureItemVisible(static_cast<SafeListViewItem*>(current()));
 
124
        QRect currentRect= view->listView()->itemRect(static_cast<SafeListViewItem*>(current()));
 
125
        view->listView()->viewport()->repaint(currentRect);
 
126
        
 
127
        setNext(static_cast<PlaylistItem*>(static_cast<SafeListViewItem*>(static_cast<SafeListViewItem*>(current())->itemBelow())));
 
128
        setPrevious(static_cast<PlaylistItem*>(static_cast<SafeListViewItem*>(static_cast<SafeListViewItem*>(current())->itemAbove())));
 
129
        
 
130
        if (emitC && i->playable())
 
131
                emit newCurrent();
 
132
}
 
133
 
 
134
void SplitPlaylist::setPrevious(PlaylistItem *i)
 
135
{
 
136
        previousItem=i;
 
137
}
 
138
 
 
139
void SplitPlaylist::remove(PlaylistItem *i)
 
140
{
 
141
        delete i;
 
142
}
 
143
 
 
144
void SplitPlaylist::listItemSelected(QListViewItem *i)
 
145
{
 
146
        setCurrent(static_cast<PlaylistItem*>(static_cast<SafeListViewItem*>(i)));
 
147
        emit playCurrent();
 
148
}
 
149
 
 
150
void SplitPlaylist::randomize()
 
151
{
 
152
        // turning off sorting is necessary
 
153
        // otherwise, the list will get randomized and promptly sorted again
 
154
        view->setSorting(false);
 
155
        List *lview = view->listView();
 
156
        // eeeeevil :)
 
157
        QList<void> list;
 
158
        QList<QListViewItem> items;
 
159
        for ( int i = 0; i < lview->childCount(); i++ )
 
160
        {
 
161
                list.append( (void*) i );
 
162
                items.append( lview->itemAtIndex( i ) );
 
163
        }
 
164
 
 
165
        KRandomSequence seq;
 
166
        seq.randomize( &list );
 
167
 
 
168
        for ( int i = 0; i < lview->childCount(); i++ )
 
169
        {
 
170
                lview->moveItem( items.take(), 0L,
 
171
                                 lview->itemAtIndex( (int) list.take() ) );
 
172
        }
 
173
        
 
174
        setCurrent( currentItem );
 
175
}
 
176
 
 
177
void SplitPlaylist::sort()
 
178
{
 
179
        view->setSorting(true);
 
180
        setCurrent(currentItem);
 
181
}
 
182
 
 
183
#include "playlist.moc"