summaryrefslogtreecommitdiffstats
path: root/juk/playlistbox.h
blob: 27f48f4541196788f4b47ea0967cf297f6804d6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/***************************************************************************
    begin                : Thu Sep 12 2002
    copyright            : (C) 2002 - 2004 by Scott Wheeler
    email                : wheeler@kde.org
 ***************************************************************************/

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

#include "playlistcollection.h"

#include <klistview.h>

#include <tqptrdict.h>

class Playlist;
class PlaylistItem;
class ViewMode;
class PlaylistSearch;
class SearchPlaylist;

class KPopupMenu;
class KSelectAction;

typedef TQValueList<Playlist *> PlaylistList;

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

class PlaylistBox : public KListView, public PlaylistCollection
{
    Q_OBJECT
  TQ_OBJECT

public: 
    class Item;
    typedef TQValueList<Item *> ItemList;

    friend class Item;

    PlaylistBox(TQWidget *tqparent, TQWidgetStack *playlistStack,
		const char *name = 0);

    virtual ~PlaylistBox();

    virtual void raise(Playlist *playlist);
    virtual void duplicate();
    virtual void remove();

    /**
     * For view modes that have dynamic playlists, this freezes them from
     * removing playlists.
     */
    virtual void setDynamicListsFrozen(bool frozen);

    Item *dropItem() const { return m_dropItem; }

    void setupPlaylist(Playlist *playlist, const TQString &iconName, Item *parentItem = 0);

public slots:
    void paste();
    void clear() {}

    void slotFreezePlaylists();
    void slotUnfreezePlaylists();

protected:
    virtual void setupPlaylist(Playlist *playlist, const TQString &iconName);
    virtual void removePlaylist(Playlist *playlist);

signals:
    void signalPlaylistDestroyed(Playlist *);

private:
    void readConfig();
    void saveConfig();

    virtual void decode(TQMimeSource *s, Item *item);
    virtual void contentsDropEvent(TQDropEvent *e);
    virtual void contentsDragMoveEvent(TQDragMoveEvent *e);
    virtual void contentsDragLeaveEvent(TQDragLeaveEvent *e);
    virtual void contentsMousePressEvent(TQMouseEvent *e);
    virtual void contentsMouseReleaseEvent(TQMouseEvent *e);
    virtual void keyPressEvent(TQKeyEvent *e);
    virtual void keyReleaseEvent(TQKeyEvent *e);

    TQValueList<Item *> selectedItems() const;
    void setSingleItem(TQListViewItem *item);

    void setupItem(Item *item);
    void setupUpcomingPlaylist();
    int viewModeIndex() const { return m_viewModeIndex; }
    ViewMode *viewMode() const { return m_viewModes[m_viewModeIndex]; }

private slots:
    /** 
     * Catches TQListBox::currentChanged(TQListBoxItem *), does a cast and then re-emits
     * the signal as currentChanged(Item *). 
     */
    void slotPlaylistChanged();
    void slotDoubleClicked();
    void slotShowContextMenu(TQListViewItem *, const TQPoint &point, int);
    void slotSetViewMode(int index);
    void slotSavePlaylists();
    void slotShowDropTarget();

    void slotPlaylistItemsDropped(Playlist *p);

    void slotAddItem(const TQString &tag, unsigned column);
    void slotRemoveItem(const TQString &tag, unsigned column);

private:
    KPopupMenu *m_contextMenu;
    TQPtrDict<Item> m_playlistDict;
    int m_viewModeIndex;
    TQValueList<ViewMode *> m_viewModes;
    KAction *m_k3bAction;
    bool m_hasSelection;
    bool m_doingMultiSelect;
    Item *m_dropItem;
    TQTimer *m_showTimer;
};



class PlaylistBox::Item : public TQObject, public KListViewItem
{
    friend class PlaylistBox;
    friend class ViewMode;
    friend class CompactViewMode;
    friend class TreeViewMode;

    Q_OBJECT
  TQ_OBJECT

    // tqmoc won't let me create private TQObject subclasses and TQt won't let me
    // make the destructor protected, so here's the closest hack that will
    // compile.

public:
    virtual ~Item();
    
protected:
    Item(PlaylistBox *listBox, const TQString &icon, const TQString &text, Playlist *l = 0);
    Item(Item *tqparent, const TQString &icon, const TQString &text, Playlist *l = 0);

    Playlist *playlist() const { return m_playlist; }
    PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
    TQString iconName() const { return m_iconName; }
    TQString text() const { return m_text; }
    void setSortedFirst(bool first = true) { m_sortedFirst = first; }

    virtual int compare(TQListViewItem *i, int col, bool) const;
    virtual void paintCell(TQPainter *p, const TQColorGroup &tqcolorGroup, int column, int width, int align);
    virtual void paintFocus(TQPainter *, const TQColorGroup &, const TQRect &) {}
    virtual void setText(int column, const TQString &text);

    virtual TQString text(int column) const { return KListViewItem::text(column); }

    virtual void setup();

    static Item *collectionItem() { return m_collectionItem; }
    static void setCollectionItem(Item *item) { m_collectionItem = item; }


protected slots:
    void slotSetName(const TQString &name);

private:
    // setup() was already taken.
    void init();

    Playlist *m_playlist;
    TQString m_text;
    TQString m_iconName;
    bool m_sortedFirst;
    static Item *m_collectionItem;
};

#endif