playlistitem.h 4.87 KB
Newer Older
1 2 3 4
/***************************************************************************
                          playlistitem.h  -  description
                             -------------------
    begin                : Sun Feb 17 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 21
***************************************************************************/

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

#include <klistview.h>
22
#include <ksharedptr.h>
23

24
#include <qvaluevector.h>
25
#include <qptrdict.h>
26

27
#include "tagguesser.h"
28
#include "filehandle.h"
Frerich Raabe's avatar
Frerich Raabe committed
29

30
class Playlist;
31
class PlaylistItem;
32
class CollectionListItem;
33

34
typedef QValueList<PlaylistItem *> PlaylistItemList;
35

36
/**
37
 * Items for the Playlist and the baseclass for CollectionListItem.
38 39 40 41 42 43
 * The constructors and destructor are protected and new items should be
 * created via Playlist::createItem().  Items should be removed by
 * Playlist::clear(), Playlist::deleteFromDisk(), Playlist::clearItem() or
 * Playlist::clearItem().
 */

44
class PlaylistItem : public KListViewItem
45
{
46
    friend class Playlist;
47
    friend class SearchPlaylist;
48
    friend class CollectionList;
49
    friend class CollectionListItem;
50
    friend class QPtrDict<PlaylistItem>;
51

52
public:
53 54 55 56 57 58 59
    enum ColumnType { TrackColumn       = 0,
		      ArtistColumn      = 1,
		      AlbumColumn       = 2,
		      TrackNumberColumn = 3,
		      GenreColumn       = 4,
		      YearColumn        = 5,
		      LengthColumn      = 6,
60 61 62
		      BitrateColumn     = 7,
		      CommentColumn     = 8,
		      FileNameColumn    = 9 };
63

Frerich Raabe's avatar
Frerich Raabe committed
64
    static int lastColumn() { return FileNameColumn; }
65

66 67
    void setFile(const FileHandle &file);
    FileHandle file() const;
68

69
    virtual QString text(int column) const;
70
    virtual void setText(int column, const QString &text);
71

72
    void setPlaying(bool playing = true) { m_playing = playing; }
73

74
    virtual void setSelected(bool selected);
75
    void guessTagInfo(TagGuesser::Type type);
76

77
    Playlist *playlist() const;
78

79 80 81 82 83 84
    /**
     * The widths of items are cached when they're updated for us in computations
     * in the "weighted" listview column width mode.
     */
    QValueVector<int> cachedWidths() const;

85
    /**
86
     * This just refreshes from the in memory data.  This may seem pointless at
87 88
     * first, but this data is shared between all of the list view items that are
     * based on the same file, so if another one of those items changes its data
89 90
     * it is important to refresh the others.
     */
91
    virtual void refresh();
92 93 94 95 96

    /**
     * This rereads the tag from disk.  This affects all PlaylistItems based on
     * the same file.
     */
97
    virtual void refreshFromDisk();
98

99 100 101
    /**
     * Asks the item's playlist to remove the item (which uses deleteLater()).
     */
102
    virtual void clear();
103

104
protected:
105
    /**
106
     * Items should always be created using Playlist::createItem() or through a
107
     * subclss or friend class.
108
     */
109
    PlaylistItem(CollectionListItem *item, Playlist *parent);
110
    PlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after);
111 112 113 114

    /**
     * This is the constructor that shold be used by subclasses.
     */
115
    PlaylistItem(CollectionList *parent);
116

117 118 119 120 121 122
    /**
     * See the class documentation for an explanation of construction and deletion
     * of PlaylistItems.
     */
    virtual ~PlaylistItem();

123
    virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
124
    virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}
125

126 127
    virtual int compare(QListViewItem *item, int column, bool ascending) const;
    int compare(const PlaylistItem *firstItem, const PlaylistItem *secondItem, int column, bool ascending) const;
128

129 130
    bool isValid() const;

131
    virtual CollectionListItem *collectionItem() const { return m_collectionItem; }
132

133 134 135 136 137
    struct Data : public KShared
    {
	Data() {}
	Data(const QFileInfo &info, const QString &path) : fileHandle(info, path) {}
	Data(const QString &path) : fileHandle(path) {}
138

139 140 141
	FileHandle fileHandle;
	QValueVector<QCString> local8Bit;
	QValueVector<int> cachedWidths;
142
	QCString shortFileName;
143
    };
144

145 146 147
    KSharedPtr<Data> data() const { return d; }

private:
148
    KSharedPtr<Data> d;
149

150
    void setup(CollectionListItem *item);
151 152
    CollectionListItem *m_collectionItem;
    bool m_playing;
153 154
};

155
#endif