playlist.h 6.33 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 27

#include "playlistitem.h"

28
class PlaylistSplitter;
29
class PlaylistBoxItem;
30
class QPopupMenu;
31

32 33 34
class Playlist : public KListView
{
    Q_OBJECT
35

36
public:
37 38 39 40 41 42 43 44 45 46
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::createPlaylist().
     */
    Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name = QString::null);
    /** 
     * Before creating a playlist directly, please see 
     * PlaylistSplitter::openPlaylist().
     */
    Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
47 48
    virtual ~Playlist();

49 50 51 52 53 54 55
    /**
     * 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
     * name.  However, by setting autoGenerateFileName, you can tell save to 
     * pick a file name.
     */
    virtual void save(bool autoGenerateFileName = false);
56 57 58
    virtual void saveAs();
    virtual void refresh();
    virtual void clearItems(const PlaylistItemList &items);
59

60 61 62
    /** 
     * All of the (media) files in the list. 
     */
63
    QStringList files() const;
64
    /** 
65
     * Returns a list of all of the items in the playlist.
66
     */
67
    PlaylistItemList items() const;
68 69 70 71
    
    /**
     * Returns a list of the currently selected items.
     */
72
    PlaylistItemList selectedItems() const;
73 74
    
    /**
75 76
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
77
     */
78
    void remove(const PlaylistItemList &items);
79

80 81 82
    /** 
     * Allow duplicate files in the playlist. 
     */
83 84
    void setAllowDuplicates(bool allow);

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

92 93 94 95
    /**
     * Internal files are files which have not been saved by the user, but rather
     * are stored in JuK's data directory and are restored by session management.
     */
96
    bool isInternalFile() const;
97
    void setInternal(bool internal);
98
    QString fileName() const;
99
    void setFileName(const QString &n);
100 101 102 103 104 105

    /**
     * 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.
     */
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 114 115
    PlaylistBoxItem *playlistBoxItem() const;
    void setPlaylistBoxItem(PlaylistBoxItem *item);

116
    int count() const;
117 118

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

125 126 127 128 129 130
public slots:
    /**
     * Remove the currently selected items from the playlist and disk.
     */ 
    void removeSelectedItems() { remove(selectedItems()); };

131
protected:
132 133 134
    virtual QDragObject *dragObject();
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
135
    PlaylistSplitter *playlistSplitter() const;
136

137
signals:
138 139 140 141
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
142
    void dataChanged();
143 144 145 146 147
    /** 
     * 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. 
     */
148
    void collectionChanged();
149

150 151 152 153
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
154
    void selectionChanged(const PlaylistItemList &selection);
155 156 157 158 159
    
    /**
     * This is connected to the PlaylistBoxItem to let it know when the 
     * playlist's name has changed.
     */
160
    void nameChanged(const QString &fileName);
161 162
    
    void numberOfItemsChanged(Playlist *);
163 164 165 166 167 168 169 170 171 172
    
    void doubleClicked();

private:
    void setup();
    QPtrStack<PlaylistItem> history;

private slots:
    void emitSelected();
    void emitDoubleClicked(QListViewItem *);
173 174 175
    void showRMBMenu(QListViewItem *item, const QPoint &point, int column);
    void applyTags(QListViewItem *item, const QString &text, int column);
    void renameTag();
176 177

private:
178 179 180
    QPopupMenu *rmbMenu;
    int currentColumn;

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    QStringList members;
    int processed;
    bool allowDuplicates;

    /**
     * If a file is "internal" it is not one that the user has yet chosen to 
     * save.  However for the purposes of being able to restore a user's 
     * loaded playlists it will be saved "internally" in:
     * $KDEHOME/share/apps/juk/playlists.
     */
    bool internalFile;
    QString playlistFileName;

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
    QString playlistName;
    PlaylistSplitter *splitter;
    PlaylistBoxItem *boxItem;
201 202

    int rmbEditID;
203 204 205
};

#endif