summaryrefslogtreecommitdiffstats
path: root/kicker-applets/mediacontrol/mpdInterface.h
blob: d89158677e2f17cd5468e5030403838b07ada590 (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
/***************************************************************************
                   this is the class to access mpd from
                             -------------------
    begin                : Tue Apr 19 18:31:00 BST 2005
    copyright            : (C) 2005 by William Robinson
    email                : airbaggins@yahoo.co.uk
 ***************************************************************************/

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

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef  MPDINTERFACE_H
#define  MPDINTERFACE_H

#include "playerInterface.h"
#include <qtimer.h>
#include <klocale.h>
#include <qsocket.h>
#include <qmutex.h>

class MpdInterface
:   public PlayerInterface
{
    Q_OBJECT
    public:
        MpdInterface();
        ~MpdInterface();

    public slots:
        virtual void updateSlider();
        virtual void sliderStartDrag();
        virtual void sliderStopDrag();
        virtual void jumpToTime(int sec);
        virtual void playpause();
        virtual void stop();
        virtual void next();
        virtual void prev();
        virtual void volumeUp();
        virtual void volumeDown();
        virtual void dragEnterEvent(QDragEnterEvent* event);
        virtual void dropEvent(QDropEvent* event);
        virtual const QString getTrackTitle() const;
        virtual int playingStatus();

        void changeVolume(int delta);

        void connectionError(int e);
        void connected();

        void startSliderClock();
        void stopSliderClock();

        void startReconnectClock();
        void stopReconnectClock();


    protected:
        virtual void timerEvent(QTimerEvent* te);

    private:
        mutable QSocket sock;
        mutable QMutex sock_mutex;

        mutable QMutex messagebox_mutex;

        QString hostname;
        int port;

        static const int SLIDER_TIMER_INTERVAL = 500; // ms
        int slider_timer;

        static const int RECONNECT_TIMER_INTERVAL = 5000; // ms
        int reconnect_timer;

        /** starts connecting and returns, if not connected already. */
        void reconnect() const;

        /** this locks the sock sock_mutex. remember to unlock it. */
        bool dispatch(const char* cmd) const;

        /** fetches everything from the sock to the OK and unlocks the mutex.
            returns true if OK, false on anything else. */
        bool fetchOk() const;

        /** fetches a line and returns true, or false if OK or ACK (end of
            message). Will unlock the sock_mutex on the end of message. */
        bool fetchLine(QString& res) const;
};

#endif   // MPDINTERFACE_H