#ifndef __KDIALOGD_H__
#define __KDIALOGD_H__

#include <kfile.h>
#include <kfiledialog.h>
#include <kfiledialog.h>
#include <kdirselectdialog.h>
#include "common.h"
#include "config.h"

#ifdef KDIALOGD_APP
class TQTimer;
#else
#include <kdedmodule.h>
#endif
class KDialogBase;
class KConfig;

class KDialogDFileDialog : public KFileDialog
{
    Q_OBJECT
  TQ_OBJECT

    public:

    KDialogDFileDialog(TQString &an, Operation op, const TQString& startDir, const TQString& filter,
                       bool confirmOw);
    virtual ~KDialogDFileDialog();

    public slots:

    void accept();
    void slotOk();

    signals:

    void ok(const TQStringList &items);

    private:

    bool    itsConfirmOw;
    TQString &itsAppName;
};

class KDialogDDirSelectDialog : public KDirSelectDialog
{
    Q_OBJECT
  TQ_OBJECT

    public:

    KDialogDDirSelectDialog(TQString &an, const TQString &startDir = TQString(),
                            bool localOnly = false,
                            TQWidget *tqparent = 0L,
                            const char *name = 0, bool modal = false);
    virtual ~KDialogDDirSelectDialog();

    public slots:

    void slotOk();

    signals:

    void ok(const TQStringList &items);

    private:

    TQString &itsAppName;
};

class KDialogDClient : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

    public:

    KDialogDClient(int sock, const TQString &an, TQObject *tqparent);
    virtual ~KDialogDClient();

    public slots:

    void read();
    void close();
    void ok(const TQStringList &items);
    void finished();

    signals:

    void error(KDialogDClient *);

    private:

    void cancel();
    bool readData(TQCString &buffer, int size);
    bool readData(char *buffer, int size)        { return readBlock(itsFd, buffer, size); }
    bool writeData(const char *buffer, int size) { return writeBlock(itsFd, buffer, size); }
    bool readString(TQString &str);
    bool writeString(const TQString &str);
    void initDialog(const TQString &caption, KDialogBase *d, unsigned int xid);

    private:

    int          itsFd;
    KDialogBase  *itsDlg;
    bool         itsAccepted;
    TQString      itsAppName;
};

class KDialogD : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

    public:

    KDialogD(TQObject *tqparent=0L);
    virtual ~KDialogD();

    public slots:

    void newConnection();
    void deleteConnection(KDialogDClient *client);
    void timeout();

    static KConfig * config() { return theirConfig; }

    private:

#ifdef KDIALOGD_APP
    TQTimer *itsTimer;
    int    itsTimeoutVal;
#endif
    int    itsFd,
           itsNumConnections;

    static KConfig *theirConfig;
};

#ifndef KDIALOGD_APP
class KDialogDKDED : public KDEDModule
{
    public:

    KDialogDKDED(const TQCString &obj);
};
#endif

#endif