playlist.h 7.97 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 30 31
class KPopupMenu;

class KPopupMenu;
32
class KActionMenu;
33 34

class QEvent;
35

36 37 38
class Playlist : public KListView
{
    Q_OBJECT
39

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

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

53 54
    virtual ~Playlist();

55 56 57
    /**
     * 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
58
     * name.  
59
     */
60
    virtual void save();
61 62
    virtual void saveAs();
    virtual void refresh();
63
    virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
64
    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
    PlaylistItemList items() const;
75 76 77 78
    
    /**
     * Returns a list of the currently selected items.
     */
79
    PlaylistItemList selectedItems() const;
80
    
81 82 83
    /** 
     * Allow duplicate files in the playlist. 
     */
84 85
    void setAllowDuplicates(bool allow);

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

93 94
    QString fileName() const { return m_playlistFileName; }
    void setFileName(const QString &n) { m_playlistFileName = n; }
95

96 97 98 99
    void hideColumn(int c);
    void showColumn(int c);
    bool isColumnVisible(int c) const;

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

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

112
    int count() const { return childCount(); }
113 114

    /** 
115 116
     * 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.
117
     */
118 119
    PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
    PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
120

121
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
122

123 124
    void setPlaying(PlaylistItem *item, bool playing = true);

125
public slots:
126
    /**
127 128
     * Remove the currently selected items from the playlist and disk.
     */ 
129
    void slotDeleteSelectedItems() { deleteFromDisk(selectedItems()); };
130
    virtual void slotSetNext() { emit signalSetNext(selectedItems().getFirst()); }
131 132 133 134 135
    
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
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:
Scott Wheeler's avatar
Scott Wheeler committed
143 144 145 146 147 148
    /**
     * 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;

149 150 151 152 153 154
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
    void deleteFromDisk(const PlaylistItemList &items);

155
    virtual bool eventFilter(QObject* watched, QEvent* e);
156
    virtual QDragObject *dragObject(QWidget *parent);
157
    virtual QDragObject *dragObject() { return dragObject(this); }
158
    virtual bool canDecode(QMimeSource *s);
159
    virtual void decode(QMimeSource *s);
160 161
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
162
    virtual void showEvent(QShowEvent *e);
163 164
    
    static QString resolveSymLinks(const QFileInfo &file);
Scott Wheeler's avatar
Scott Wheeler committed
165

166
signals:
167 168 169 170
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
171
    void signalDataChanged();
172

173 174 175 176
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
177
    void signalSelectionChanged(const PlaylistItemList &selection);
178 179
    
    /**
180
     * This is connected to the PlaylistBox::Item to let it know when the 
181 182
     * playlist's name has changed.
     */
183
    void signalNameChanged(const QString &fileName);
184
    
185
    void signalNumberOfItemsChanged(Playlist *);
186
    
187
    void signalDoubleClicked();
188

189 190 191 192
    /**
     * This signal is emitted just before a playlist item is removed from the 
     * list.
     */
193
    void signalAboutToRemove(PlaylistItem *item);
194
    void signalToggleColumnVisible(int column);
195 196
    void signalFilesDropped(const QStringList &files, Playlist *);
    void signalSetNext(PlaylistItem *item);    
197

198 199
private:
    void setup();
200
    void applyTag(QListViewItem *item, const QString &text, int column);
201
    int leftMostVisibleColumn() const;
202 203

private slots:
204 205 206
    void slotEmitSelected() { emit signalSelectionChanged(selectedItems()); }
    void slotEmitDoubleClicked(QListViewItem *) { emit signalDoubleClicked(); }
    void slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column);
207
    void slotApplyModification(QListViewItem *item, const QString &text, int column);
208
    void slotRenameTag();
209
    void slotColumnOrderChanged(int, int from, int to);
210 211

private:
212 213 214 215
    int m_currentColumn;
    SortedStringList m_members;
    int m_processed;
    bool m_allowDuplicates;
216
    QPtrStack<PlaylistItem> m_history;
217

218
    QString m_playlistFileName;
219 220 221 222 223

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
224
    QString m_playlistName;
225
   
226 227 228
    KPopupMenu *m_rmbMenu;
    KPopupMenu *m_headerMenu;
    KActionMenu *m_columnVisibleAction;
229

230 231
    int m_rmbPasteID;
    int m_rmbEditID;
232 233 234

    PlaylistItem *m_playingItem;
    int m_leftColumn;
235 236
};

Scott Wheeler's avatar
Scott Wheeler committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
class Playlist::SharedSettings
{
public:
    static SharedSettings *instance();
    /**
     * Sets the default column order to that of Playlist @param p.
     */
    void setColumnOrder(const Playlist *p);
    /**
     * Sets the columns of @param p to match the stored settings.
     */
    void restoreColumnOrder(const Playlist *p);

protected:
    SharedSettings();
    ~SharedSettings() {}

private:
    static SharedSettings *m_instance;
    QValueList<int> m_columnOrder;
};

259 260 261
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

262
#endif