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 8.26 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 <qvaluevector.h>
25
#include <qptrstack.h>
26 27

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

30 31 32
class KPopupMenu;

class KPopupMenu;
33
class KActionMenu;
34 35

class QEvent;
36

37 38
typedef QValueList<Playlist *> PlaylistList;

39 40 41
class Playlist : public KListView
{
    Q_OBJECT
42

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

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

56 57
    virtual ~Playlist();

58 59 60
    /**
     * 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
61
     * name.  
62
     */
63
    virtual void save();
64 65
    virtual void saveAs();
    virtual void refresh();
66
    virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
67
    virtual void clearItems(const PlaylistItemList &items);
68

69 70 71
    /** 
     * All of the (media) files in the list. 
     */
72
    QStringList files() const;
73

74 75 76 77 78
    /** 
     * Returns a list of all of the \e visible items in the playlist.
     */
    PlaylistItemList items();

79
    /** 
80
     * Returns a list of all of the items in the playlist.
81
     */
82
    PlaylistItemList visibleItems() const;
83 84 85 86
    
    /**
     * Returns a list of the currently selected items.
     */
87
    PlaylistItemList selectedItems() const;
88
    
89 90 91
    /** 
     * Allow duplicate files in the playlist. 
     */
92 93
    void setAllowDuplicates(bool allow);

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

102 103
    QString fileName() const { return m_fileName; }
    void setFileName(const QString &n) { m_fileName = n; }
104

105 106 107 108
    void hideColumn(int c);
    void showColumn(int c);
    bool isColumnVisible(int c) const;

109
    /**
110
     * If m_playlistName has no value -- i.e. the name has not been set to 
111
     * something other than the filename, this returns the filename less the
112
     * extension.  If m_playlistName does have a value, this returns that.
113
     */
114
    QString name() const;
115

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

121
    int count() const { return childCount(); }
122 123

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

130
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
131

132
    void setPlaying(PlaylistItem *item, bool playing = true);
Scott Wheeler's avatar
Scott Wheeler committed
133 134 135 136 137 138
    
    /**
     * This forces an update of the left most visible column, but does not save
     * the settings for this.
     */ 
    void updateLeftColumn();
139

140 141
    static void setItemsVisible(const PlaylistItemList &items, bool visible = true);

142
public slots:
143
    /**
144 145
     * Remove the currently selected items from the playlist and disk.
     */ 
146
    void slotDeleteSelectedItems() { deleteFromDisk(selectedItems()); };
147 148
    void slotSetNext();

149 150 151 152
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
153
    virtual void cut() { copy(); clear(); }
154
    virtual void copy();
155
    virtual void paste();
156
    virtual void clear();
157
    virtual void selectAll() { KListView::selectAll(true); }
158

159
    void slotGuessTagInfo();
160 161
    void slotRenameFile();

162 163 164 165
    /**
     * Reload the playlist contents from the m3u file.
     */
    void slotReload();
166

167
protected:
168 169 170 171 172 173
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
    void deleteFromDisk(const PlaylistItemList &items);

174
    virtual bool eventFilter(QObject* watched, QEvent* e);
175
    virtual QDragObject *dragObject(QWidget *parent);
176
    virtual QDragObject *dragObject() { return dragObject(this); }
177
    virtual bool canDecode(QMimeSource *s);
178
    virtual void decode(QMimeSource *s);
179 180
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
181
    virtual void showEvent(QShowEvent *e);
182 183
    
    static QString resolveSymLinks(const QFileInfo &file);
Scott Wheeler's avatar
Scott Wheeler committed
184

185 186 187
    KPopupMenu *rmbMenu() { return m_rmbMenu; }
    const KPopupMenu *rmbMenu() const { return m_rmbMenu; }

188
signals:
189 190 191 192
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
193
    void signalDataChanged();
194

195 196 197 198
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
199
    void signalSelectionChanged(const PlaylistItemList &selection);
200 201
    
    /**
202
     * This is connected to the PlaylistBox::Item to let it know when the 
203 204
     * playlist's name has changed.
     */
205
    void signalNameChanged(const QString &fileName);
206
    
207
    void signalNumberOfItemsChanged(Playlist *);
208
    
209
    void signalDoubleClicked();
210

211 212 213 214
    /**
     * This signal is emitted just before a playlist item is removed from the 
     * list.
     */
215
    void signalAboutToRemove(PlaylistItem *item);
216 217
    void signalFilesDropped(const QStringList &files, Playlist *);
    void signalSetNext(PlaylistItem *item);    
218
    void signalVisibleColumnsChanged();
219

220 221
private:
    void setup();
222
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
223
    void applyTag(QListViewItem *item, const QString &text, int column);
224
    int leftMostVisibleColumn() const;
225

226 227 228 229 230 231
    /**
     * This class is used internally to store settings that are shared by all
     * of the playlists, such as column order.  It is implemented as a singleton.
     */
    class SharedSettings;

232
private slots:
233 234 235
    void slotEmitSelected() { emit signalSelectionChanged(selectedItems()); }
    void slotEmitDoubleClicked(QListViewItem *) { emit signalDoubleClicked(); }
    void slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column);
236
    void slotApplyModification(QListViewItem *item, const QString &text, int column);
237
    void slotRenameTag();
238
    void slotColumnOrderChanged(int, int from, int to);
239
    void slotToggleColumnVisible(int column);
240 241

private:
242 243 244 245
    int m_currentColumn;
    SortedStringList m_members;
    int m_processed;
    bool m_allowDuplicates;
246
    QPtrStack<PlaylistItem> m_history;
247

248
    QString m_fileName;
249 250 251 252 253

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
254
    QString m_playlistName;
255
   
256 257 258
    KPopupMenu *m_rmbMenu;
    KPopupMenu *m_headerMenu;
    KActionMenu *m_columnVisibleAction;
259

260 261
    int m_rmbPasteID;
    int m_rmbEditID;
262 263 264

    PlaylistItem *m_playingItem;
    int m_leftColumn;
265 266
};

267 268 269
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

270
#endif