summaryrefslogtreecommitdiffstats
path: root/kicker-applets/mediacontrol/mpdInterface.h
blob: 4ba2034675be3305532f4df763097d571d892b26 (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
/***************************************************************************
                   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 <tqtimer.h>
#include <klocale.h>
#include <tqsocket.h>
#include <tqmutex.h>

class MpdInterface
:   public PlayerInterface
{
    Q_OBJECT
  TQ_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(TQDragEnterEvent* event);
        virtual void dropEvent(TQDropEvent* event);
        virtual const TQString 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(TQTimerEvent* te);

    private:
        mutable TQSocket sock;
        mutable TQMutex sock_mutex;

        mutable TQMutex messagebox_mutex;

        TQString 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(TQString& res) const;
};

#endif   // MPDINTERFACE_H