Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

nowplaying.h 4.11 KB
Newer Older
1
/***************************************************************************
2 3 4
    begin                : Tue Nov 9 2004
    copyright            : (C) 2004 by Scott Wheeler
    email                : wheeler@kde.org
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 ***************************************************************************/

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

19
#include <kactivelabel.h>
20

21 22
#include <qhbox.h>
#include <qlabel.h>
23
#include <qguardedptr.h>
24

25
#include "filehandle.h"
26
#include "playlist.h"
27

28 29
class QTimer;

30
class NowPlayingItem;
31
class PlaylistCollection;
32
class Playlist;
33 34 35 36 37 38 39

/**
 * This is the widget that holds all of the other items and handles updating them
 * when the playing item changes.
 */

class NowPlaying : public QHBox
40 41 42 43
{
    Q_OBJECT

public:
44 45
    NowPlaying(QWidget *parent, PlaylistCollection *collection,
               const char *name = 0);
46
    void addItem(NowPlayingItem *item);
47
    PlaylistCollection *collection() const;
48 49

private slots:
50
    void slotUpdate();
51 52

private:
53 54 55 56 57 58 59 60 61 62 63
    struct Observer : public PlaylistObserver
    {
        Observer(NowPlaying *parent, PlaylistInterface *playlist) :
            PlaylistObserver(playlist),
            m_parent(parent) {}
        virtual void updateCurrent() {}
        virtual void updateData() { m_parent->slotUpdate(); }
        NowPlaying *m_parent;
    };

    Observer m_observer;
64
    PlaylistCollection *m_collection;
65 66
    QValueList<NowPlayingItem *> m_items;
};
67

68 69 70
/**
 * Abstract base for the other NowPlaying items.
 */
71

72 73 74 75
class NowPlayingItem
{
public:
    virtual void update(const FileHandle &file) = 0;
76
    NowPlaying *parent() const { return m_parent; }
77
protected:
78 79 80
    NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
private:
    NowPlaying *m_parent;
81 82 83 84 85 86 87 88 89 90 91 92
};

/**
 * Displays the cover of the currently playing file if available, or hides
 * itself if not.
 */

class CoverItem : public QLabel, public NowPlayingItem
{
public:
    CoverItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
93
    virtual void mouseReleaseEvent(QMouseEvent *event);
94

95 96 97 98
protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);

99 100
private:
    FileHandle m_file;
101 102
};

103 104 105 106 107 108 109 110 111 112 113
/**
 * A link label that doesn't automatically open Konqueror.
 */

class LinkLabel : public KActiveLabel
{
public:
    LinkLabel(QWidget *parent, const char *name = 0) : KActiveLabel(parent, name) {}
    virtual void openLink(const QString &) {}
};

114 115 116 117 118 119 120
/**
 * Show the text information on the current track and provides links to the
 * album and artist of the currently playing item.
 */

class TrackItem : public QWidget, public NowPlayingItem
{
121 122
    Q_OBJECT

123 124 125 126
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

127 128
private slots:
    void slotOpenLink(const QString &link);
129
    void slotUpdate();
130

131
private:
132
    FileHandle m_file;
133
    LinkLabel *m_label;
134 135 136 137 138 139
};

/**
 * Shows up to 10 items of history and links to those items.
 */

140
class HistoryItem : public LinkLabel, public NowPlayingItem
141
{
142 143
    Q_OBJECT

144 145 146
public:
    HistoryItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
147
    virtual void openLink(const QString &link);
148

149 150 151
private slots:
    void slotAddPlaying();

152
private:
153 154 155 156 157 158 159 160 161 162 163 164
    struct Item
    {
        Item() {}
        Item(const QString &a, const FileHandle &f, Playlist *p)
            : anchor(a), file(f), playlist(p) {}

        QString anchor;
        FileHandle file;
        QGuardedPtr<Playlist> playlist;
    };

    QValueList<Item> m_history;
165
    LinkLabel *m_label;
166 167
    QTimer *m_timer;
    FileHandle m_file;
168 169 170
};

#endif