/* This file is part of the KMPlayer application
   Copyright (C) 2004 Koos Vriezen <koos.vriezen@xs4all.nl>

   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.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KMPLAYER_VDR_SOURCE_H
#define KMPLAYER_VDR_SOURCE_H

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

#include <tqframe.h>

#include <kurl.h>

#include "kmplayerappsource.h"
#include "kmplayerconfig.h"
#include "kmplayerprocess.h"


class KMPlayerApp;
class VDRCommand;
class KURLRequester;
class TQButtonGroup;
class TQMenuItem;
class TQCheckBox;
class TQLineEdit;
class TDEAction;
class TQSocket;
class TQTimerEvent;
class TDEListView;

/*
 * Preference page for VDR
 */
class KMPLAYER_NO_EXPORT KMPlayerPrefSourcePageVDR : public TQFrame {
    TQ_OBJECT
  
public:
    KMPlayerPrefSourcePageVDR (TQWidget * parent, KMPlayer::PartBase * player);
    ~KMPlayerPrefSourcePageVDR ();
    KURLRequester * vcddevice;
    TDEListView * xv_port;
    TQLineEdit * tcp_port;
    TQButtonGroup * scale;
protected:
    void showEvent (TQShowEvent *);
private:
    KMPlayer::PartBase * m_player;
};


/*
 * Source from VDR (XVideo actually) and socket connection
 */
class KMPLAYER_NO_EXPORT KMPlayerVDRSource : public KMPlayer::Source, public KMPlayer::PreferencesPage {
    TQ_OBJECT
  
public:
    KMPlayerVDRSource (KMPlayerApp * app);
    virtual ~KMPlayerVDRSource ();
    virtual bool hasLength ();
    virtual bool isSeekable ();
    virtual TQString prettyName ();
    virtual void write (TDEConfig *);
    virtual void read (TDEConfig *);
    virtual void sync (bool);
    virtual void prefLocation (TQString & item, TQString & icon, TQString & tab);
    virtual TQFrame * prefPage (TQWidget * parent);
    virtual bool requestPlayURL (KMPlayer::NodePtr mrl);
    virtual void stateElementChanged (KMPlayer::Node * node, KMPlayer::Node::State os, KMPlayer::Node::State ns);
    void waitForConnectionClose ();
public slots:
    void activate ();
    void deactivate ();
    void jump (KMPlayer::NodePtr e);
    void forward ();
    void backward ();
    void playCurrent ();
    void toggleConnected ();
    void volumeChanged (int);
private slots:
    void keyUp ();
    void keyDown ();
    void keyBack ();
    void keyOk ();
    void keySetup ();
    void keyChannels ();
    void keyMenu ();
    void key0 ();
    void key1 ();
    void key2 ();
    void key3 ();
    void key4 ();
    void key5 ();
    void key6 ();
    void key7 ();
    void key8 ();
    void key9 ();
    void keyRed ();
    void keyGreen ();
    void keyYellow ();
    void keyBlue ();
    void customCmd ();
    void connected ();
    void disconnected ();
    void readyRead ();
    void socketError (int);
    void processStopped ();
    void processStarted ();
    void configReceived ();
protected:
    void timerEvent (TQTimerEvent *);
private:
    enum {
        act_up = 0, act_down, act_back, act_ok,
        act_setup, act_channels, act_menu,
        act_red, act_green, act_yellow, act_blue,
        act_0, act_1, act_2, act_3, act_4, act_5, act_6, act_7, act_8, act_9,
        act_custom,
        act_last
    };
    void queueCommand (const char * cmd);
    void queueCommand (const char * cmd, int repeat_ms);
    void sendCommand ();
    void deleteCommands ();
    void jump (const TQString & channel);
    KMPlayerApp * m_app;
    KMPlayerPrefSourcePageVDR * m_configpage;
    TDEAction * m_actions [act_last];
    TDEAction * m_fullscreen_actions [act_last];
    TQSocket * m_socket;
    VDRCommand * commands;
    TQString m_request_jump;
    KMPlayer::NodePtrW m_last_channel;
    int channel_timer;
    int timeout_timer;
    int finish_timer;
    int tcp_port;
    int m_stored_volume;
    int scale;
    int last_channel;
};

class XVideo : public KMPlayer::CallbackProcess {
    TQ_OBJECT
  
public:
    XVideo (TQObject * parent, KMPlayer::Settings * settings);
    ~XVideo ();
public slots:
    virtual bool ready (KMPlayer::Viewer *);
};

#endif // KMPLAYER_VDR_SOURCE_H
