playlist.h 6.42 KB
Newer Older
1 2 3 4 5
/***************************************************************************
                          playlist.h  -  description
                             -------------------
    begin                : Sat Feb 16 2002
    copyright            : (C) 2002 by Scott Wheeler
6
    email                : wheeler@kde.org
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PLAYLIST_H
#define PLAYLIST_H

#include <klistview.h>

#include <qstringlist.h>
24
#include <qptrstack.h>
25 26

#include "playlistitem.h"
27
#include "sortedstringlist.h"
28

29
class PlaylistSplitter;
30
class PlaylistBoxItem;
31
class QPopupMenu;
32

33 34 35
class Playlist : public KListView
{
    Q_OBJECT
36

37
public:
38 39 40 41 42
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::createPlaylist().
     */
    Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name = QString::null);
43

44 45 46 47 48
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::openPlaylist().
     */
    Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
49

50 51
    virtual ~Playlist();

52 53 54
    /**
     * Saves the file to the currently set file name.  If there is no filename
     * currently set, the default behavior is to prompt the user for a file
55
     * name.  
56
     */
57
    virtual void save();
58 59 60
    virtual void saveAs();
    virtual void refresh();
    virtual void clearItems(const PlaylistItemList &items);
61

62 63 64
    /** 
     * All of the (media) files in the list. 
     */
65
    QStringList files() const;
66

67
    /** 
68
     * Returns a list of all of the items in the playlist.
69
     */
70

71
    PlaylistItemList items() const;
72 73 74 75
    
    /**
     * Returns a list of the currently selected items.
     */
76
    PlaylistItemList selectedItems() const;
77 78
    
    /**
79 80
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
81
     */
82
    void remove(const PlaylistItemList &items);
83

84 85 86
    /** 
     * Allow duplicate files in the playlist. 
     */
87 88
    void setAllowDuplicates(bool allow);

89 90
    /** 
     * This is being used as a mini-factory of sorts to make the construction
91 92
     * of PlaylistItems virtual.  In this case it allows for the creation of
     * both PlaylistItems and CollectionListItems.
93 94
     */
    virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *after = 0);
95

96
    QString fileName() const { return playlistFileName; }
97
    void setFileName(const QString &n) { playlistFileName = n; }
98 99 100 101 102 103

    /**
     * If playlistName has no value -- i.e. the name has not been set to 
     * something other than the filename, this returns the filename less the
     * extension.  If playlistName does have a value, this returns that.
     */
104
    QString name() const;
105

106 107 108
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */ 
109
    void setName(const QString &n);
110

111
    PlaylistBoxItem *playlistBoxItem() const { return boxItem; }
112
    void setPlaylistBoxItem(PlaylistBoxItem *item) { boxItem = item; }
113

114
    int count() const { return childCount(); }
115 116

    /** 
117 118
     * This gets the next item to be played.  This is static because often we 
     * know about the playing item, but not to which list it belongs.
119
     */
120 121
    PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
    PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
122

123 124 125 126 127 128
public slots:
    /**
     * Remove the currently selected items from the playlist and disk.
     */ 
    void removeSelectedItems() { remove(selectedItems()); };

129 130 131 132 133 134
    void copy();
    void clear();
    void cut() { copy(); clear(); }
    void paste();
    void selectAll() { KListView::selectAll(true); }

135
protected:
136
    virtual QDragObject *dragObject(QWidget *parent);
137
    virtual QDragObject *dragObject();
138
    virtual void decode(QMimeSource *s);
139 140
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
141
    PlaylistSplitter *playlistSplitter() const { return splitter; }
142

143
signals:
144 145 146 147
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
148
    void dataChanged();
149 150 151 152 153
    /** 
     * This signal is emitted when items are added to the collection list.  
     * This happens in the createItem() method when items are added to the 
     * collection. 
     */
154
    void collectionChanged();
155

156 157 158 159
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
160
    void selectionChanged(const PlaylistItemList &selection);
161 162 163 164 165
    
    /**
     * This is connected to the PlaylistBoxItem to let it know when the 
     * playlist's name has changed.
     */
166
    void nameChanged(const QString &fileName);
167 168
    
    void numberOfItemsChanged(Playlist *);
169 170 171
    
    void doubleClicked();

172 173 174 175 176 177
    /**
     * This signal is emitted just before a playlist item is removed from the 
     * list.
     */
    void aboutToRemove(PlaylistItem *item);

178 179 180 181 182
private:
    void setup();
    QPtrStack<PlaylistItem> history;

private slots:
183 184
    void emitSelected() {  emit(selectionChanged(selectedItems())); }
    void emitDoubleClicked(QListViewItem *) { emit(doubleClicked()); }
185 186 187
    void showRMBMenu(QListViewItem *item, const QPoint &point, int column);
    void applyTags(QListViewItem *item, const QString &text, int column);
    void renameTag();
188 189

private:
190 191 192
    QPopupMenu *rmbMenu;
    int currentColumn;

193
    SortedStringList members;
194 195 196 197 198 199 200 201 202 203 204 205
    int processed;
    bool allowDuplicates;

    QString playlistFileName;

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
    QString playlistName;
    PlaylistSplitter *splitter;
    PlaylistBoxItem *boxItem;
206 207

    int rmbEditID;
208 209
};

210 211 212
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

213
#endif