playlist.h 4.81 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 24 25 26
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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>

#include "playlistitem.h"

27
class PlaylistSplitter;
28
class PlaylistBoxItem;
29

30 31 32
class Playlist : public KListView
{
    Q_OBJECT
33

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

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

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

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

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

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

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

94 95 96
    PlaylistBoxItem *playlistBoxItem() const;
    void setPlaylistBoxItem(PlaylistBoxItem *item);

97 98 99 100 101 102
    // static methods

    /** 
     * This gets the next item to be played in the specified playlist.
     */
    static PlaylistItem *nextItem(PlaylistItem *current, bool random = false);
103

104
protected:
105 106 107
    virtual QDragObject *dragObject();
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
108
    PlaylistSplitter *playlistSplitter() const;
109

110 111 112 113 114
private:
    void setup();

    QStringList members;
    int processed;
115
    bool allowDuplicates;
116

117 118 119 120 121 122
    /**
     * 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.
     */
123
    bool internalFile;
124
    QString playlistFileName;
125 126
    QString playlistName;
    PlaylistSplitter *splitter;
127
    PlaylistBoxItem *boxItem;
128

129 130 131 132
private slots:
    void emitSelected();

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

145 146 147 148
    /** 
     * This is emitted when the playlist selection is changed.  This is used
     * primarily to notify the TagEditor of the new data. 
     */
149
    void selectionChanged(const PlaylistItemList &selection);
150
    void nameChanged(const QString &fileName);
151 152 153
};

#endif