/*
 * tasks.h - basic tasks
 * Copyright (C) 2001, 2002  Justin Karneges
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef JABBER_TASKS_H
#define JABBER_TASKS_H

#include<qstring.h>
#include<qdom.h>

#include"client.h"
#include"jid.h"
#include"message.h"
#include"vcard.h"

namespace Jabber
{
	class Roster;
	class Status;

	class JT_Auth : public Task
	{
		Q_OBJECT
	public:
		JT_Auth(Task *parent);
		~JT_Auth();

		void plain(const QString &user, const QString &pass, const QString &resource);
		void digest(const QString &user, const QString &pass, const QString &resource);

		void onGo();
		bool take(const QDomElement &);

	private:
		QDomElement iq;
		Jid to;

		class Private;
		Private *d;
	};

	class JT_Register : public Task
	{
		Q_OBJECT
	public:
		JT_Register(Task *parent);
		~JT_Register();

		void reg(const QString &user, const QString &pass);
		void changepw(const QString &pass);
		void unreg(const Jid &j="");

		void onGo();
		bool take(const QDomElement &);

	private:
		QDomElement iq;
		Jid to;

		class Private;
		Private *d;
	};

	class JT_Roster : public Task
	{
		Q_OBJECT
	public:
		JT_Roster(Task *parent);
		~JT_Roster();

		void get();
		void set(const Jid &, const QString &name, const QStringList &groups);
		void remove(const Jid &);

		const Roster & roster() const;

		QString toString() const;
		bool fromString(const QString &);

		void onGo();
		bool take(const QDomElement &x);

	private:
		int type;
		QDomElement iq;
		Jid to;

		class Private;
		Private *d;
	};

	class JT_PushRoster : public Task
	{
		Q_OBJECT
	public:
		JT_PushRoster(Task *parent);
		~JT_PushRoster();

		bool take(const QDomElement &);

	signals:
		void roster(const Roster &);

	private:
		class Private;
		Private *d;
	};

	class JT_Presence : public Task
	{
		Q_OBJECT
	public:
		JT_Presence(Task *parent);
		~JT_Presence();

		void pres(const Status &);
		void pres(const Jid &, const Status &);
		void sub(const Jid &, const QString &subType);

		void onGo();

	private:
		QDomElement tag;
		int type;

		class Private;
		Private *d;
	};

	class JT_PushPresence : public Task
	{
		Q_OBJECT
	public:
		JT_PushPresence(Task *parent);
		~JT_PushPresence();

		bool take(const QDomElement &);

	signals:
		void presence(const Jid &, const Status &);
		void subscription(const Jid &, const QString &);

	private:
		class Private;
		Private *d;
	};

	class JT_Message : public Task
	{
		Q_OBJECT
	public:
		JT_Message(Task *parent, const Message &);
		~JT_Message();

		void onGo();

	private:
		Message m;

		class Private;
		Private *d;
	};

	class JT_PushMessage : public Task
	{
		Q_OBJECT
	public:
		JT_PushMessage(Task *parent);
		~JT_PushMessage();

		bool take(const QDomElement &);

	signals:
		void message(const Message &);

	private:
		class Private;
		Private *d;
	};

	// this will issue a bunch of Tasks one by one in sequence
	/*class JT_Queue : public Task
	{
		Q_OBJECT
	public:
		JT_Queue(Task *parent);

		void addTask(Task *);
		int count();

		void done(Task *);
		bool isClearable() { return FALSE; }

		void go();
		void stop();
		QString toString();
		bool fromString(const QString &);

	signals:
		void countChanged();
		void itemDone(Task *);

	private slots:
		void afterDone();

	private:
		void doNext();
		Task *active;
		QPtrList<Task> list;
		bool going;
	};

	class JT_GetServices : public Task
	{
		Q_OBJECT
	public:
		JT_GetServices(Task *parent, const QString &host);

		void go();

		bool take(const QDomElement &x);

		Roster services;

	private:
		QDomElement iq;
	};
*/
	class JT_VCard : public Task
	{
		Q_OBJECT
	public:
		JT_VCard(Task *parent);
		~JT_VCard();

		void get(const Jid &);
		void set(VCard &);

		const Jid &jid() const;
		const VCard  &vcard() const;
		
		void onGo();

		bool take(const QDomElement &x);

	private:
		int type;

		class Private;
		Private *d;
	};
/*
	class JT_RegForm : public Task
	{
		Q_OBJECT
	public:
		JT_RegForm(Task *parent);

		void get(const QString &);
		void set(const JabForm &);

		void go();

		bool take(const QDomElement &x);

		QString jid;
		JabForm form;
		int type;

	private:
		QDomElement iq;
	};

	class JT_Search : public Task
	{
		Q_OBJECT
	public:
		JT_Search(Task *parent);

		void get(const QString &);
		void set(const JabForm &);

		void go();

		bool take(const QDomElement &x);

		QString jid;
		JabForm form;
		Roster roster;
		int type;

	private:
		QDomElement iq;
	};

	class JT_ClientVersion : public Task
	{
		Q_OBJECT
	public:
		JT_ClientVersion(Task *, const Jid &);

		void go();
		bool take(const QDomElement &);

		Jid j;
		QString name, version, os;

	private:
		QDomElement iq;
	};

	class JT_ClientTime : public Task
	{
		Q_OBJECT
	public:
		JT_ClientTime(Task *, const Jid &);

		void go();
		bool take(const QDomElement &);

		Jid j;
		QDateTime utc;
		QString timezone, display;

	private:
		QDomElement iq;
	};

	class JT_ServInfo : public Task
	{
		Q_OBJECT
	public:
		JT_ServInfo(Task *parent);

		bool isDaemon() { return TRUE; }
		bool take(const QDomElement &);
	};

	class JT_Gateway : public Task
	{
		Q_OBJECT
	public:
		JT_Gateway(Task *parent);

		void get(const QString &service);
		void set(const QString &service, const QString &prompt);

		void go();

		bool take(const QDomElement &x);

		QString jid, prompt, desc;
		int type;

	private:
		QDomElement iq;
	};*/
}

#endif
