~neon/juk/master

« back to all changes in this revision

Viewing changes to playlist.cpp

  • Committer: Scott Wheeler
  • Date: 2002-09-18 21:56:09 UTC
  • Revision ID: git-v1:de9543f4996e638ee4b93221d9716b7836a06b18
More updates including drag and drop support between playlists, from one
playlist to another, and from other KURL (i.e. Konq) drag sources.

svn path=/trunk/kdemultimedia/juk/; revision=178830

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 ***************************************************************************/
17
17
 
18
18
#include <kmessagebox.h>
 
19
#include <kurl.h>
 
20
#include <kurldrag.h>
 
21
#include <kiconloader.h>
19
22
#include <klocale.h>
20
23
#include <kdebug.h>
21
24
 
35
38
Playlist::Playlist(QWidget *parent, const char *name) : KListView(parent, name)
36
39
{
37
40
    setup();
 
41
    setAcceptDrops(true);
38
42
    allowDuplicates = false;
39
43
}
40
44
 
43
47
 
44
48
}
45
49
 
46
 
void Playlist::append(const QString &item)
 
50
void Playlist::append(const QString &item, bool sorted)
47
51
{
48
52
    collectionListChanged = false;
49
53
 
55
59
        emit(collectionChanged());
56
60
}
57
61
 
58
 
void Playlist::append(const QStringList &items)
 
62
void Playlist::append(const QStringList &items, bool sorted)
59
63
{
60
64
    collectionListChanged = false;
61
65
 
127
131
// protected members
128
132
////////////////////////////////////////////////////////////////////////////////
129
133
 
 
134
QDragObject *Playlist::dragObject()
 
135
{
 
136
    QPtrList<PlaylistItem> items = selectedItems();
 
137
    KURL::List urls;
 
138
    for(PlaylistItem *i = items.first(); i; i = items.next()) {
 
139
        KURL url;
 
140
        url.setPath(i->absFilePath());
 
141
        urls.append(url);
 
142
    }
 
143
    
 
144
    KURLDrag *drag = new KURLDrag(urls, this, "Playlist Items");
 
145
    drag->setPixmap(SmallIcon("sound"));
 
146
 
 
147
    return(drag);
 
148
}
 
149
 
 
150
void Playlist::contentsDropEvent(QDropEvent *e)
 
151
{
 
152
    QListViewItem *moveAfter = itemAt(e->pos());
 
153
    if(!moveAfter)
 
154
        moveAfter = lastItem();
 
155
 
 
156
    // This is slightly more efficient since it doesn't have to cast everything
 
157
    // to PlaylistItem.
 
158
 
 
159
    if(e->source() == this) {
 
160
        QPtrList<QListViewItem> items = KListView::selectedItems();
 
161
        
 
162
        for(QPtrListIterator<QListViewItem> it(items); it.current() != 0; ++it) {
 
163
            (*it)->moveItem(moveAfter);
 
164
            moveAfter = *it;
 
165
        }
 
166
    }
 
167
    else {
 
168
        KURL::List urls;
 
169
    
 
170
        if(KURLDrag::decode(e, urls) && !urls.isEmpty()) {
 
171
            
 
172
            QStringList files;
 
173
            
 
174
            for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
 
175
                files.append((*it).path());
 
176
            
 
177
            append(files);
 
178
        }
 
179
    }
 
180
}
 
181
 
 
182
void Playlist::contentsDragMoveEvent(QDragMoveEvent *e)
 
183
{
 
184
    if(KURLDrag::canDecode(e))
 
185
        e->accept(true);
 
186
    else
 
187
        e->accept(false);
 
188
}
 
189
 
130
190
PlaylistItem *Playlist::createItem(const QFileInfo &file)
131
191
{
132
192
    CollectionListItem *item = CollectionList::instance()->lookup(file.absFilePath());
142
202
        return(0);
143
203
}
144
204
 
145
 
void Playlist::appendImpl(const QString &item)
 
205
void Playlist::appendImpl(const QString &item, bool sorted)
146
206
{
147
207
    processEvents();
148
208
    QFileInfo file(QDir::cleanDirPath(item));
191
251
    setSorting(1);
192
252
 
193
253
    connect(this, SIGNAL(selectionChanged()), this, SLOT(emitSelected()));
 
254
 
 
255
    addColumn(QString::null);
 
256
    setResizeMode(QListView::LastColumn);
 
257
    // setFullWidth(true);
194
258
}
195
259
 
196
260
void Playlist::processEvents()