Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

playlist.h 6.73 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 31 32
class KPopupMenu;

class KPopupMenu;
33
class KActionMenu;
34 35

class QEvent;
36

37 38 39
class Playlist : public KListView
{
    Q_OBJECT
40

41
public:
42 43 44 45 46
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::createPlaylist().
     */
    Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name = QString::null);
47

48 49 50 51 52
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::openPlaylist().
     */
    Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
53

54 55
    virtual ~Playlist();

56 57 58
    /**
     * 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
59
     * name.  
60
     */
61
    virtual void save();
62 63 64
    virtual void saveAs();
    virtual void refresh();
    virtual void clearItems(const PlaylistItemList &items);
65

66 67 68
    /** 
     * All of the (media) files in the list. 
     */
69
    QStringList files() const;
70

71
    /** 
72
     * Returns a list of all of the items in the playlist.
73
     */
74

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

88 89 90
    /** 
     * Allow duplicate files in the playlist. 
     */
91 92
    void setAllowDuplicates(bool allow);

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

100
    QString fileName() const { return playlistFileName; }
101
    void setFileName(const QString &n) { playlistFileName = n; }
102

103 104 105 106
    void hideColumn(int c);
    void showColumn(int c);
    bool isColumnVisible(int c) const;

107 108 109 110 111
    /**
     * 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.
     */
112
    QString name() const;
113

114 115 116
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */ 
117
    void setName(const QString &n);
118

119
    int count() const { return childCount(); }
120 121

    /** 
122 123
     * 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.
124
     */
125 126
    PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
    PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
127

128 129
    KActionMenu *columnVisibleAction() const { return _columnVisibleAction; }

130
public slots:
131
    /**
132 133 134 135
     * Remove the currently selected items from the playlist and disk.
     */ 
    void removeSelectedItems() { remove(selectedItems()); };

136
    virtual void cut() { copy(); clear(); }
137
    virtual void copy();
138
    virtual void paste();
139
    virtual void clear();
140
    virtual void selectAll() { KListView::selectAll(true); }
141

142
protected:
143
    virtual bool eventFilter(QObject* watched, QEvent* e);
144
    virtual QDragObject *dragObject(QWidget *parent);
145
    virtual QDragObject *dragObject();
146
    virtual bool canDecode(QMimeSource *s);
147
    virtual void decode(QMimeSource *s);
148 149
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
150
    PlaylistSplitter *playlistSplitter() const { return splitter; }
151

152
signals:
153 154 155 156
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
157
    void dataChanged();
158 159 160 161 162
    /** 
     * 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. 
     */
163
    void collectionChanged();
164

165 166 167 168
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
169
    void selectionChanged(const PlaylistItemList &selection);
170 171
    
    /**
172
     * This is connected to the PlaylistBox::Item to let it know when the 
173 174
     * playlist's name has changed.
     */
175
    void nameChanged(const QString &fileName);
176 177
    
    void numberOfItemsChanged(Playlist *);
178 179 180
    
    void doubleClicked();

181 182 183 184 185 186
    /**
     * This signal is emitted just before a playlist item is removed from the 
     * list.
     */
    void aboutToRemove(PlaylistItem *item);

187 188
    void signalToggleColumnVisible(int column);

189 190 191 192 193
private:
    void setup();
    QPtrStack<PlaylistItem> history;

private slots:
194 195
    void emitSelected() {  emit(selectionChanged(selectedItems())); }
    void emitDoubleClicked(QListViewItem *) { emit(doubleClicked()); }
196 197 198
    void showRMBMenu(QListViewItem *item, const QPoint &point, int column);
    void applyTags(QListViewItem *item, const QString &text, int column);
    void renameTag();
199 200

private:
201
    int currentColumn;
202
    SortedStringList members;
203 204 205 206 207 208 209 210 211 212 213
    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;
214
   
215 216
    KPopupMenu *rmbMenu;
    KPopupMenu *headerMenu;
217
    KActionMenu *_columnVisibleAction;
218

219
    int rmbPasteID;
220
    int rmbEditID;
221 222
};

223 224 225
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

226
#endif