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

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

#include <qfileinfo.h>
#include <qobject.h>

#include "tag.h"
#include "audiodata.h"
28
#include "cache.h"
29 30

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

34 35
typedef QPtrList<PlaylistItem> PlaylistItemList;

36 37
class PlaylistItem : public QObject, public KListViewItem 
{
38 39
    friend class Playlist;

40 41 42 43 44
    Q_OBJECT
public:
    enum ColumnType { TrackColumn = 0, ArtistColumn = 1, AlbumColumn = 2, TrackNumberColumn = 3,
                      GenreColumn = 4, YearColumn = 5, LengthColumn = 6, FileNameColumn = 7 };

45 46
    // The constructors are in the protected secion.  See the note there.

47 48
    virtual ~PlaylistItem();

49
    // These can't be const members because they fetch the data "on demand".
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    Tag *getTag();
    AudioData *getAudioData();

    void setFile(const QString &file);

    // QFileInfo-ish methods

    QString fileName() const;
    QString filePath() const;
    QString absFilePath() const;
    QString dirPath(bool absPath = false) const;
    bool isWritable() const;

public slots:
65
    virtual void refresh();
66
    virtual void refreshFromDisk();
67 68

protected:
69 70 71 72
    /** 
     * Items should always be created using Playlist::createItem() or through a
     * subclss or friend class. 
     */
73
    PlaylistItem(CollectionListItem *item, Playlist *parent);
74
    PlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after);
75 76 77 78 79
    PlaylistItem(Playlist *parent);

    class Data;
    Data *getData();
    void setData(Data *d);
80 81

protected slots:
82
    void refreshImpl();
83 84 85 86 87

signals:
    void refreshed();

private:
88
    void setup(CollectionListItem *item, Playlist *parent);
89
    virtual int compare(QListViewItem *item, int column, bool ascending) const;
90 91 92 93 94
    int compare(PlaylistItem *firstItem, PlaylistItem *secondItem, int column, bool ascending) const;

    Data *data;
};

95 96 97 98 99 100 101
class PlaylistItem::Data : public QFileInfo
{
public:
    static Data *newUser(const QFileInfo &file);
    Data *newUser();
    void deleteUser();

102 103
    void refresh();

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    Tag *getTag();

    void setFile(const QString &file);

protected:
    // Because we're trying to use this as a shared item, we want all access
    // to be through pointers (so that it's safe to use delete this).  Thus
    // creation of the object should be done by the newUser methods above
    // and deletion should be handled by deleteUser.  Making the constructor
    // and destructor protected ensures this.

    Data(const QFileInfo &file);
    virtual ~Data();

private:
    int referenceCount;

    CacheItem *cache;
    Tag *tag;
};


126
#endif