summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jabbertransport.h
blob: b26fd9c0ca41a017dfa10ed173f8fe148504f194 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 /*

    Copyright (c) 2006      by Olivier Goffart  <ogoffart at kde.org>

    Kopete    (c) 2006 by the Kopete developers <[email protected]>


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

#ifndef JABBERTRANSPORT_H
#define JABBERTRANSPORT_H

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


#include <kopeteaccount.h>


namespace XMPP { 
	class Jid;
	class RosterItem;
}
class JabberAccount;
class JabberProtocol;

/**
 * this class handle a jabber gateway
 * @author Olivier Goffart */

class JabberTransport : public Kopete::Account
{
	Q_OBJECT

public:
	/**
	 * constructor called when the transport is created by info from server  (i.e not when loading kopete)
	 * @param parentAccount is the parent jabber account.
	 * @param item is the roster item of the gateway
	 * @param gateway_type eg: "msn" or "icq"  only used when the account is not loaded from config file for determining the icon
	 */
	JabberTransport (JabberAccount * parentAccount, const XMPP::RosterItem &item, const QString& gateway_type=QString());
	
	/**
	 * constructor called when the transport is loaded from config
	 * @param parentAccount is the parent jabber account.
	 * @param accountId is the accountId
	 */
	JabberTransport (JabberAccount * parentAccount, const QString &accountId );

	~JabberTransport ();

	/** Returns the action menu for this account. */
	virtual KActionMenu *actionMenu ();
	
	/** the parent account */
	JabberAccount *account() const 
	{ return m_account; }

	/* to get the protocol from the account */
	JabberProtocol *protocol () const;

	void connect( const Kopete::OnlineStatus& ) {}
	virtual void disconnect( ) {}
	
	/** 
	 * called when the account is removed in the config ui
	 * will remove the subscription
	 */
	virtual bool removeAccount();
	

	enum TransportStatus { Normal , Creating, Removing , AccountRemoved };
	TransportStatus transportStatus() { return m_status; };
	
	/**
	 * return the legacyId conrresponding to the jid
	 *  example:  jhon%[email protected]  ->  [email protected]
	 */
	QString legacyId( const XMPP::Jid &jid );
	
public slots:

	/* Reimplemented from Kopete::Account */
	void setOnlineStatus( const Kopete::OnlineStatus& status , const QString &reason = QString::null);
	
	/**
	 * the account has been unregistered.
	 * loop over all contact and remove them
	 */
	void removeAllContacts();
	
	/**
	 * the JabberAccount has been removed from Kopete,  remove this account also
	 */
	void jabberAccountRemoved();

	/**
	 *  "eat" all contact in the account that have the same domain as us.
	 */
	void eatContacts();

protected:
	/**
	 * Create a new contact in the specified metacontact
	 *
	 * You shouldn't ever call this method yourself, For adding contacts see @ref addContact()
	 *
	 * This method is called by @ref Kopete::Account::addContact() in this method, you should
	 * simply create the new custom @ref Kopete::Contact in the given metacontact. You should
	 * NOT add the contact to the server here as this method gets only called when synchronizing
	 * the contact list on disk with the one in memory. As such, all created contacts from this
	 * method should have the "dirty" flag set.
	 *
	 * This method should simply be used to intantiate the new contact, everything else
	 * (updating the GUI, parenting to meta contact, etc.) is being taken care of.
	 *
	 * @param contactId The unique ID for this protocol
	 * @param parentContact The metacontact to add this contact to
	 */
	virtual bool createContact (const QString & contactID, Kopete::MetaContact * parentContact);

private:
	JabberAccount *m_account;
	TransportStatus m_status;

};

#endif