playlistbox.h 6.14 KB
Newer Older
1 2 3 4
/***************************************************************************
                          playlistbox.h  -  description
                             -------------------
    begin                : Thu Sep 12 2002
5
    copyright            : (C) 2002, 2003 by Scott Wheeler
6
    email                : wheeler@kde.org
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 PLAYLISTBOX_H
#define PLAYLISTBOX_H

21
#include <klistview.h>
22

23
#include <qptrdict.h>
24

25
class Playlist;
26
class PlaylistItem;
27
class PlaylistSplitter;
28
class ViewMode;
29 30
class PlaylistSearch;
class SearchPlaylist;
31

Nadeem Hasan's avatar
Nadeem Hasan committed
32
class KPopupMenu;
33
class KSelectAction;
Nadeem Hasan's avatar
Nadeem Hasan committed
34

35 36
typedef QValueList<Playlist *> PlaylistList;

37
/** 
38
 * This is the play list selection box that is by default on the right side of
39 40
 * JuK's main widget (PlaylistSplitter). 
 */
41

42
class PlaylistBox : public KListView
43 44
{
    Q_OBJECT
45

46
public: 
47
    PlaylistBox(PlaylistSplitter *parent = 0, const QString &name = QString::null);
48 49
    virtual ~PlaylistBox();

50 51
    void createItem(Playlist *playlist, const char *icon = 0,
		    bool raise = false, bool sortedFirst = false);
52

53 54
    void createSearchItem(SearchPlaylist *playlist, const QString &searchCategory);

55
    void raise(Playlist *playlist);
56
    QStringList names() const { return m_names; }
57 58 59 60 61

    /**
     * A list of all of the playlists in the PlaylistBox, not counting dynamic
     * playlists.
     */
62
    PlaylistList playlists();
63

64
    // All of the methods use the selected item.
65 66 67 68
    void save();
    void saveAs();
    void rename();
    void duplicate();
69 70 71 72 73

    /**
     * Delete the item associated with \a playlist.
     */
    void deleteItem(Playlist *playlist);
74
    void deleteItems() { deleteItems(selectedItems()); }
75

76
    bool hasSelection() const  { return m_hasSelection; }
77

78
    ViewMode *viewMode()       { return m_viewModes[m_viewModeIndex]; }
79
    int viewModeIndex() const  { return m_viewModeIndex; }
80
    void ensureCurrentVisible() { ensureItemVisible(currentItem()); }
81

82 83
    class Item;
    friend class Item;
84
    typedef QValueList<Item *> ItemList;
85 86

public slots:
87
    void paste();
88
    void clear() {} // override the (destructive) default
89

90
signals:
91
    void signalCurrentChanged(const PlaylistList &);
92
    void signalDoubleClicked();
93
    void signalCreatePlaylist(const QStringList &files);
94 95 96
    void signalCreateSearchList(const PlaylistSearch &search,
				const QString &searchCategory,
				const QString &name);
97
    void signalCollectionInitialized();
98

99
private:
100 101 102
    void readConfig();
    void saveConfig();

103 104 105 106
    void save(Item *item);
    void saveAs(Item *item);
    void rename(Item *item);
    void duplicate(Item *item);
107
    void deleteItems(const QValueList<Item *> &items, bool confirm = true);
108 109

    virtual void decode(QMimeSource *s, Item *item);
110 111
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
112 113
    virtual void contentsMousePressEvent(QMouseEvent *e);
    virtual void contentsMouseReleaseEvent(QMouseEvent *e);
114 115
    virtual void keyPressEvent(QKeyEvent *e);
    virtual void keyReleaseEvent(QKeyEvent *e);
116

117 118
    /** 
     * This is used by PlaylistItemBox (a friend class) to add names to the name
119
     * list returned by names(). 
120
     */
121
    void addName(const QString &name) { m_names.append(name); }
122

123
    QValueList<Item *> selectedItems();
124

125
    void setSingleItem(QListViewItem *item);
126 127
    void setupItem(Item *item, Playlist *playlist);

128
private slots:
129 130 131 132
    /** 
     * Catches QListBox::currentChanged(QListBoxItem *), does a cast and then re-emits
     * the signal as currentChanged(Item *). 
     */
133
    void slotPlaylistChanged();
134
    void slotDoubleClicked(QListViewItem *);
135
    void slotShowContextMenu(QListViewItem *, const QPoint &point, int);
136
    void slotSetViewMode(int index);
137

138
private:
139 140
    PlaylistSplitter *m_splitter;
    QStringList m_names;
141
    KPopupMenu *m_contextMenu;
142 143
    bool m_updatePlaylistStack;
    QPtrDict<Item> m_playlistDict;
144
    int m_viewModeIndex;
145
    QValueList<ViewMode *> m_viewModes;
146
    KSelectAction *m_viewModeAction;
147
    bool m_hasSelection;
148
    bool m_doingMultiSelect;
149 150
};

151 152


153
class PlaylistBox::Item : public QObject, public KListViewItem
154
{
155
    friend class PlaylistBox;
156 157
    friend class ViewMode;
    friend class CompactViewMode;
158
    friend class TreeViewMode;
159

160 161
    Q_OBJECT

162 163 164 165
    // moc won't let me create private QObject subclasses and Qt won't let me
    // make the destructor protected, so here's the closest hack that will
    // compile.

166
public:
167
    virtual ~Item();
168
    
169
protected:
170
    Item(PlaylistBox *listBox, const char *icon, const QString &text, Playlist *l = 0);
171
    Item(Item *parent, const char *icon, const QString &text, Playlist *l = 0);
172

173
    Playlist *playlist() const { return m_list; }
174
    PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
175
    const char *iconName() const { return m_iconName; }
176
    QString text() const { return m_text; }
177
    void setSortedFirst(bool first) { m_sortedFirst = first; }
178 179

    virtual int compare(QListViewItem *i, int col, bool) const;
180 181
    virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align);
    virtual void setText(int column, const QString &text);
182

183 184
    virtual QString text(int column) const { return KListViewItem::text(column); }

185 186
    static Item *collectionItem() { return m_collectionItem; }

187 188 189
protected slots:
    void slotSetName(const QString &name);

190
private:
191 192 193
    // setup() was already taken.
    void init();

194
    Playlist *m_list;
195
    QString m_text;
196
    const char *m_iconName;
197
    bool m_sortedFirst;
198
    static Item *m_collectionItem;
199 200 201
};

#endif