playlist.h 5.59 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

31 32 33
class Playlist : public KListView
{
    Q_OBJECT
34

35
public:
36 37 38 39 40 41 42 43 44 45
    /** 
     * 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);
46 47
    virtual ~Playlist();

48 49 50 51 52 53 54
    /**
     * 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);
55 56 57
    virtual void saveAs();
    virtual void refresh();
    virtual void clearItems(const PlaylistItemList &items);
58

59 60 61
    /** 
     * All of the (media) files in the list. 
     */
62
    QStringList files() const;
63 64 65
    /** 
     * All of the items in the list.
     */
66 67
    PlaylistItemList items() const;
    PlaylistItemList selectedItems() const;
68 69

    void remove();
70
    void remove(const PlaylistItemList &items);
71

72 73 74
    /** 
     * Allow duplicate files in the playlist. 
     */
75 76
    void setAllowDuplicates(bool allow);

77 78
    /** 
     * This is being used as a mini-factory of sorts to make the construction
79 80
     * of PlaylistItems virtual.  In this case it allows for the creation of
     * both PlaylistItems and CollectionListItems.
81 82
     */
    virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *after = 0);
83

84 85 86 87
    /**
     * 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.
     */
88
    bool isInternalFile() const;
89
    void setInternal(bool internal);
90
    QString fileName() const;
91
    void setFileName(const QString &n);
92 93 94 95 96 97

    /**
     * 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.
     */
98
    QString name() const;
99 100 101
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */ 
102
    void setName(const QString &n);
103

104 105 106
    PlaylistBoxItem *playlistBoxItem() const;
    void setPlaylistBoxItem(PlaylistBoxItem *item);

107 108 109
    // static methods

    /** 
110 111
     * 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.
112 113
     */
    static PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
114
    static PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
115

116
protected:
117 118 119
    virtual QDragObject *dragObject();
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
120
    PlaylistSplitter *playlistSplitter() const;
121

122 123 124 125 126
private:
    void setup();

    QStringList members;
    int processed;
127
    bool allowDuplicates;
128

129 130 131 132 133 134
    /**
     * 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.
     */
135
    bool internalFile;
136
    QString playlistFileName;
137 138 139 140 141

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
142 143
    QString playlistName;
    PlaylistSplitter *splitter;
144
    PlaylistBoxItem *boxItem;
145 146
    
    QPtrStack<PlaylistItem> history;
147

148 149 150 151
private slots:
    void emitSelected();

signals:
152 153 154 155
    /** 
     * This signal is connected to PlaylistItem::refreshed() in the 
     * PlaylistItem class. 
     */
156
    void dataChanged();
157 158 159 160 161
    /** 
     * 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. 
     */
162
    void collectionChanged();
163

164 165 166 167
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
168
    void selectionChanged(const PlaylistItemList &selection);
169 170 171 172 173
    
    /**
     * This is connected to the PlaylistBoxItem to let it know when the 
     * playlist's name has changed.
     */
174
    void nameChanged(const QString &fileName);
175 176 177
};

#endif