Bonjour nick name is in Latin1 encoding
[kdenetwork.git] / kopete / protocols / bonjour / bonjouraccount.h
blob525ead226180a4d7605a72bf7360564a91a885f8
1 /*
2 bonjouraccount.h - Kopete Bonjour Protocol
4 Copyright (c) 2007 by Tejas Dinkar <tejas@gja.in>
5 Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
9 * *
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
14 * *
15 *************************************************************************
18 #ifndef BONJOURACCOUNT_H
19 #define BONJOURACCOUNT_H
21 #include <QByteArray>
22 #include <QTcpServer>
23 #include <QList>
25 #include <kopeteaccount.h>
27 #include <dnssd/publicservice.h>
28 #include <dnssd/servicebrowser.h>
30 #include "bonjourcontact.h"
31 #include "bonjourcontactconnection.h"
33 class KActionMenu;
34 namespace Kopete
36 class Contact;
37 class MetaContact;
38 class StatusMessage;
41 class BonjourProtocol;
43 /**
44 * @brief This Class Represents a Bonjour Account
46 * This represents a single Account that broadcasts via the bonjour protocol
47 * This has a number of important functions, including:
48 * \li running a @ref localServer that listens for incoming connections
49 * \li maintaining a list of @ref unknownConnections which are TCP connections where the remote user is unknown
50 * \li running a @ref browser that scans for contacts coming online and offline
51 * \li publishing our presence via the @ref service
53 * @author Tejas Dinkar <tejas\@gja.in>
55 class BonjourAccount : public Kopete::Account
57 Q_OBJECT
59 public:
60 /**
61 * @param parent The Parent Protocol
62 * @param accountID A Unique String Identifying this account
64 BonjourAccount( BonjourProtocol *parent, const QString& accountID );
65 ~BonjourAccount();
67 /**
68 * @brief Parse The Config File
70 * This Function parses the appropriate group in the kopeterc
71 * It sets come internally used constants like @ref username, @ref emailAddress
73 void parseConfig();
75 /**
76 * @brief Verifies a connection is from a claimed user, and return the contact
78 * This verifies a user by checking that the remote IP address of the connection
79 * is the same as the user's IP address.
81 * @param conn The Connection that just discovered it's associated user
82 * @param user A String uniquely identifying the user (username@hotname)
83 * @return The contact if there is a match, or @c NULL otherwise
85 BonjourContact *verifyUser(BonjourContactConnection *conn, const QString &user);
87 /**
88 * @brief Get all Contacts at a given Address
90 * This queries all contacts and returns a list of contacts at a given host address
91 * Usually, there should only be one contact at each address
92 * @param addr The Address to find online contacts at
93 * @return A List of Contacts
95 QList <BonjourContact *> getContactsByAddress(const QHostAddress &addr);
97 /**
98 * Construct the context menu used for the status bar icon
100 //virtual KActionMenu* actionMenu();
103 * @brief Create a New Contact
105 * Creates a protocol specific Kopete::Contact subclass and adds it to the supplied
106 * Kopete::MetaContact
107 * This is called internally only, as contacts cannot be added manually
109 * @return @c true if the contact is created, @c false otherwise
111 virtual bool createContact(const QString& contactId, Kopete::MetaContact* parentContact);
114 * @brief Called when Kopete is set globally away
116 * @todo FIXME: This Doesn't Do Anything Right Now
118 virtual void setAway(bool away, const QString& reason);
121 * @brief Called when Kopete status is changed globally
123 * @todo FIXME: This Only Makes us go online or offline, we cannot go away
125 virtual void setOnlineStatus(const Kopete::OnlineStatus& status , const Kopete::StatusMessage &reason = Kopete::StatusMessage(),
126 const OnlineStatusOptions& options = None);
127 virtual void setStatusMessage(const Kopete::StatusMessage& statusMessage);
130 * @brief 'Connect' to the bonjour service.
132 * This the one stop call to do everything, like starting server, publishing, discovery, etc
133 * This will clear the contact list in the beginning, and start re populating it
134 * @todo Do something with initialStatus
136 * @param initialStatus FIXME: This is pretty much ignored
138 virtual void connect( const Kopete::OnlineStatus& initialStatus = Kopete::OnlineStatus::OnlineStatus() );
141 * @brief Disconnect from the service.
143 * This will disconnect from the service. It will stop everything started in connect
144 * It cleans out the contact list after it is finished
146 virtual void disconnect();
149 * Set Properties Such As username, firstName, emailAddress, lastName
151 Q_PROPERTY(QByteArray username READ getusername WRITE setusername)
152 Q_PROPERTY(QByteArray firstName READ getfirstName WRITE setfirstName)
153 Q_PROPERTY(QByteArray lastName READ getlastName WRITE setlastName)
154 Q_PROPERTY(QByteArray emailAddress READ getemailAddress WRITE setemailAddress)
156 void setusername(const QByteArray &nusername);
157 void setfirstName(const QByteArray &nfirstName);
158 void setlastName(const QByteArray &nlastName);
159 void setemailAddress(const QByteArray &nemailAddress);
161 const QByteArray getusername() const;
162 const QByteArray getfirstName() const;
163 const QByteArray getlastName() const;
164 const QByteArray getemailAddress() const;
167 public slots:
170 * @brief This is going to be removed soon
172 * @todo Remove this function
173 * This is an old function left over from the Testbed protocol
175 void receivedMessage( const QString &message );
178 * @brief Slots Called When a Contact Comes Online
180 * This is Called when A contact Comes online
181 * This is connected to signals from the @ref browser
183 * @param pointer A RemoteService Pointer to the Service.
185 void comingOnline(DNSSD::RemoteService::Ptr pointer);
188 * @brief Slots Called When a Contact Goes Offline
190 * This is Called when A contact goes offline
191 * This is Connected to signals from the @ref browser
193 * @param pointer A RemoteService Pointer to the Service.
195 void goingOffline(DNSSD::RemoteService::Ptr pointer);
198 * @brief A Slot Called when a connection discovers it's username
200 * This is called when a contact connection receives information on who it is connected to
201 * If We don't get this signal (or we can't find a match), then we can try our luck with @ref usernameNotInStream()
202 * Usually, the connection receives the username in a <stream:stream from="username@hostaname"...>
203 * @todo Add A Backup plan
205 * @param conn The Connection
206 * @param user The User Claimed By the Connection
208 void discoveredUserName(BonjourContactConnection *conn, const QString &user);
211 * @brief A Slot Called if the connection doesn't get it's username in the stream
213 * Some IM clients are not decent enough to tell us who they are in the stream (ex: Miranda)
214 * The Expect a lookup of know clients v/s their IP addresses
216 * @param conn The Connection
218 void usernameNotInStream(BonjourContactConnection *conn);
221 * @brief This Slot is called when we finish publishing our service
223 * @param success This is set to true if we successfully started the publish. Else it's an error
225 void published(bool success);
227 private:
229 /**
230 * The Following Details are Set When An Account is Created
232 QByteArray username;
233 QByteArray firstName;
234 QByteArray emailAddress;
235 QByteArray lastName;
239 * The Connection to Avahi Which Keeps Scanning For Contacts Coming Online Or Offline
241 DNSSD::PublicService *service;
244 * The local Server which waits for people to talk to it :D
245 * The Port it listens on is stored in @ref listeningPort
247 QTcpServer *localServer;
250 * The port on which @ref localServer is listening
252 int listeningPort;
255 * The Bonjour Group of The Contact List
257 Kopete::Group *bonjourGroup;
260 * The Service Browser Which Keeps Scanning For New People
262 DNSSD::ServiceBrowser *browser;
265 * Big List of Open Connections, who we don't know is at the other end
267 QList <BonjourContactConnection *> unknownConnections;
270 * @brief The Function To Start the Local Server
272 * This Start the Local Server. A low numbered port is chosen between 5298 and 5305
273 * The Value of listeningPort is set appropriatly
274 * Remember to set your local firewall to allow us to listen on this port
276 * @return @c true if the server is now listening, @c false otherwise
278 bool startLocalServer();
281 * @brief The Function To Start the mDNS Discovery
283 * This Starts Browsing for broadcasts of _presence._tcp
284 * All contacts are deleted in the function
286 void startBrowse();
289 * @brief The Function To Start Advertising the Local Server
291 * This starts publishing about our @ref localServer
292 * This has an avahi dependency to get our local hostname
293 * @todo FIXME: Remove Avahi Dependency
295 void startPublish();
298 * @brief This Deletes all the Contacts connected to this account
300 * This Calls @ref wipeOutContact() internally
302 void wipeOutAllContacts();
305 * @brief This Deletes a Single Contact
307 * This deletes a contact. If that is the only contact in the metacontact, it removes that as well
308 * @param c The Contact To Be Deleted
310 void wipeOutContact(Kopete::Contact *c);
313 protected slots:
315 * @brief Change the account's status. Called by KActions and internally.
317 void slotGoOnline();
319 * @brief Change the account's status. Called by KActions and internally.
321 * @todo FIXME: This Does Nothing Useful
323 void slotGoAway();
326 * @brief Change the account's status. Called by KActions and internally.
328 void slotGoOffline();
331 * @brief This slot is called if a new incoming connection is made
333 * This is connected to the new connection signal from @ref localServer
335 void newIncomingConnection();
339 #endif