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.45 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
    /**
     * Before creating a playlist directly, please see
46 47
     * PlaylistSplitter::createPlaylist().
     */
48
    Playlist(QWidget *parent, const QString &name = QString::null);
49

50 51
    /**
     * Before creating a playlist directly, please see
52 53
     * 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
    /**
     * All of the (media) files in the list.
71
     */
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

    /**
     * Allow duplicate files in the playlist.
91
     */
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 100
    virtual PlaylistItem *createItem(const QFileInfo &file,
				     const QString &absFilePath = QString::null,
101 102
				     QListViewItem *after = 0);

103 104
    void createItems(const PlaylistItemList &siblings);

105 106
    QString fileName() const { return m_fileName; }
    void setFileName(const QString &n) { m_fileName = n; }
107

108 109 110 111
    void hideColumn(int c);
    void showColumn(int c);
    bool isColumnVisible(int c) const;

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

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

124
    int count() const { return childCount(); }
125

126 127
    /**
     * This gets the next item to be played.  This is static because often we
128
     * know about the playing item, but not to which list it belongs.
129
     */
130 131
    PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
    PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
132

133
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
134

135
    void setPlaying(PlaylistItem *item, bool playing = true);
136

Scott Wheeler's avatar
Scott Wheeler committed
137 138 139
    /**
     * This forces an update of the left most visible column, but does not save
     * the settings for this.
140
     */
Scott Wheeler's avatar
Scott Wheeler committed
141
    void updateLeftColumn();
142

143 144
    static void setItemsVisible(const PlaylistItemList &items, bool visible = true);

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

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

162
    void slotGuessTagInfo();
163 164
    void slotRenameFile();

165 166 167 168
    /**
     * Reload the playlist contents from the m3u file.
     */
    void slotReload();
169

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

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

186 187 188 189
    /**
     * Though it's somewhat obvious, this function will stat the file, so only use it when
     * you're out of a performance critical loop.
     */
190
    static QString resolveSymLinks(const QFileInfo &file);
Scott Wheeler's avatar
Scott Wheeler committed
191

192 193 194
    KPopupMenu *rmbMenu() { return m_rmbMenu; }
    const KPopupMenu *rmbMenu() const { return m_rmbMenu; }

195
signals:
196 197 198
    /**
     * This signal is connected to PlaylistItem::refreshed() in the
     * PlaylistItem class.
199
     */
200
    void signalDataChanged();
201

202
    /**
203
     * This is emitted when the playlist selection is changed.  This is used
204
     * primarily to notify the TagEditor of the new data.
205
     */
206
    void signalSelectionChanged(const PlaylistItemList &selection);
207

208
    /**
209
     * This is connected to the PlaylistBox::Item to let it know when the
210 211
     * playlist's name has changed.
     */
212
    void signalNameChanged(const QString &fileName);
213

214
    void signalNumberOfItemsChanged(Playlist *);
215

216
    void signalDoubleClicked();
217

218
    /**
219
     * This signal is emitted just before a playlist item is removed from the
220 221
     * list.
     */
222
    void signalAboutToRemove(PlaylistItem *item);
223
    void signalFilesDropped(const QStringList &files, Playlist *);
224
    void signalSetNext(PlaylistItem *item);
225
    void signalVisibleColumnsChanged();
226

227 228
private:
    void setup();
229
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
230
    void applyTag(QListViewItem *item, const QString &text, int column);
231
    int leftMostVisibleColumn() const;
232

233 234 235 236 237 238
    /**
     * 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;

239
private slots:
240 241 242
    void slotEmitSelected() { emit signalSelectionChanged(selectedItems()); }
    void slotEmitDoubleClicked(QListViewItem *) { emit signalDoubleClicked(); }
    void slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column);
243
    void slotApplyModification(QListViewItem *item, const QString &text, int column);
244
    void slotRenameTag();
245
    void slotColumnOrderChanged(int, int from, int to);
246
    void slotToggleColumnVisible(int column);
247 248

private:
249 250 251 252
    int m_currentColumn;
    SortedStringList m_members;
    int m_processed;
    bool m_allowDuplicates;
253
    QPtrStack<PlaylistItem> m_history;
254

255
    QString m_fileName;
256 257 258 259 260

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
261
    QString m_playlistName;
262

263 264 265
    KPopupMenu *m_rmbMenu;
    KPopupMenu *m_headerMenu;
    KActionMenu *m_columnVisibleAction;
266

267 268
    int m_rmbPasteID;
    int m_rmbEditID;
269 270 271

    PlaylistItem *m_playingItem;
    int m_leftColumn;
272 273

    PlaylistItemList m_randomList;
274 275
};

276 277 278
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

279
#endif