playlist.h 7.52 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 39
class Playlist : public KListView
{
    Q_OBJECT
40

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

48 49 50 51
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::openPlaylist().
     */
52
    Playlist(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
    virtual void saveAs();
    virtual void refresh();
64
    virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
65
    virtual void clearItems(const PlaylistItemList &items);
66

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

72
    /** 
73
     * Returns a list of all of the items in the playlist.
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
    /** 
     * Allow duplicate files in the playlist. 
     */
85 86
    void setAllowDuplicates(bool allow);

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

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

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

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

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

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

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

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

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

126
public slots:
127
    /**
128 129
     * Remove the currently selected items from the playlist and disk.
     */ 
130
    void slotDeleteSelectedItems() { deleteFromDisk(selectedItems()); };
131
    virtual void slotSetNext() { emit signalSetNext(selectedItems().getFirst()); }
132 133 134 135 136
    
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
137
    virtual void cut() { copy(); clear(); }
138
    virtual void copy();
139
    virtual void paste();
140
    virtual void clear();
141
    virtual void selectAll() { KListView::selectAll(true); }
142

143
protected:
144 145 146 147 148 149
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
    void deleteFromDisk(const PlaylistItemList &items);

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

161
signals:
162 163 164 165
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
166
    void signalDataChanged();
167

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

184 185 186 187
    /**
     * This signal is emitted just before a playlist item is removed from the 
     * list.
     */
188
    void signalAboutToRemove(PlaylistItem *item);
189 190
    void signalFilesDropped(const QStringList &files, Playlist *);
    void signalSetNext(PlaylistItem *item);    
191

192 193
private:
    void setup();
194
    void applyTag(QListViewItem *item, const QString &text, int column);
195
    int leftMostVisibleColumn() const;
196

197 198 199 200 201 202
    /**
     * 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;

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
    void slotToggleColumnVisible(int column);
211 212

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

219
    QString m_playlistFileName;
220 221 222 223 224

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

231 232
    int m_rmbPasteID;
    int m_rmbEditID;
233 234 235

    PlaylistItem *m_playingItem;
    int m_leftColumn;
236 237
};

238 239 240
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);

241
#endif