Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / kopetecontact.h
blob5861f3ce7acb0927311fa90b081ba2284c63a8a1
1 /*
2 kopetecontact.h - Kopete Contact
4 Copyright (c) 2002-2004 by Duncan Mac-Vicar Prett <duncan@kde.org>
5 Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
6 Copyright (c) 2002-2004 by Olivier Goffart <ogoffart@kde.org>
8 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
10 *************************************************************************
11 * *
12 * This library is free software; you can redistribute it and/or *
13 * modify it under the terms of the GNU Lesser General Public *
14 * License as published by the Free Software Foundation; either *
15 * version 2 of the License, or (at your option) any later version. *
16 * *
17 *************************************************************************
20 #ifndef KOPETECONTACT_H
21 #define KOPETECONTACT_H
23 #include "kopetecontactlistelement.h"
24 #include "kopetepropertycontainer.h"
26 #include <kurl.h>
27 #include <kdemacros.h>
28 #include "kopeteglobal.h"
30 #include "kopete_export.h"
32 class KMenu;
33 class KAction;
35 namespace Kopete
38 class Group;
39 class MetaContact;
40 class ChatSession;
41 class OnlineStatus;
42 class Plugin;
43 class Protocol;
44 class Account;
45 class StatusMessage;
47 typedef QList<Group *> GroupList;
49 /**
50 * @author Duncan Mac-Vicar P. <duncan@kde.org>
51 * @author Martijn Klingens <klingens@kde.org>
52 * @author Olivier Goffart <ogoffart@kde.org>
54 * This class abstracts a generic contact
55 * Use it for inserting contacts in the contact list for example.
57 class KOPETE_EXPORT Contact
58 : public ContactListElement
60 Q_OBJECT
62 Q_ENUMS( CanCreateFlags )
63 Q_PROPERTY( QString formattedName READ formattedName )
64 Q_PROPERTY( QString formattedIdleTime READ formattedIdleTime )
65 Q_PROPERTY( bool isOnline READ isOnline )
66 Q_PROPERTY( bool fileCapable READ isFileCapable WRITE setFileCapable )
67 Q_PROPERTY( bool canAcceptFiles READ canAcceptFiles )
68 //Q_PROPERTY( bool isReachable READ isReachable )
69 Q_PROPERTY( QString contactId READ contactId )
70 Q_PROPERTY( QString icon READ icon WRITE setIcon )
71 Q_PROPERTY( QString toolTip READ toolTip )
72 Q_PROPERTY( QString nickName READ nickName WRITE setNickName )
73 //Q_PROPERTY( unsigned long idleTime READ idleTime WRITE setIdleTime )
75 public:
76 /**
77 * used in @ref sync()
79 enum Changed{ MovedBetweenGroup = 0x01, ///< the contact has been moved between groups
80 DisplayNameChanged = 0x02 ///< the displayname of the contact changed
83 /**
84 * \brief Create new contact.
86 * <b>The parent MetaContact must not be NULL</b>
88 * \note id is required to be unique per protocol and per account.
89 * Across those boundaries ids may occur multiple times.
90 * The id is solely for comparing items safely (using pointers is
91 * more crash-prone). DO NOT assume anything regarding the id's
92 * value! Even if it may look like an ICQ UIN or an MSN passport,
93 * this is undefined and may change at any time!
95 * @param account is the parent account. this constructor automatically register the contact to the account
96 * @param id is the Contact's unique Id (mostly the user's login)
97 * @param parent is the parent @ref MetaContact this Contact is part of
98 * @param icon is an optional icon
100 Contact( Account *account, const QString &id, MetaContact *parent,
101 const QString &icon = QString() );
103 ~Contact();
106 * \brief Get the metacontact for this contact
107 * @return The MetaContact object for this contact
109 MetaContact *metaContact() const;
113 * \brief Get the unique id that identifies a contact.
115 * \note Id is required to be unique per protocol and per account.
116 * Across those boundaries ids may occur multiple times.
117 * The id is solely for comparing items safely (using pointers is
118 * more crash-prone). DO NOT assume anything regarding the id's
119 * value! Even if it may look like an ICQ UIN or an MSN passport,
120 * this is undefined and may change at any time!
122 * @return The unique id of the contact
124 QString contactId() const;
127 * \brief Get the protocol that the contact belongs to.
129 * simply return account()->protocol()
131 * @return the contact's protocol
133 Protocol* protocol() const;
136 * \brief Get the account that this contact belongs to
138 * @return the Account object for this contact
140 Account* account() const;
143 * \brief Move this contact to a new MetaContact.
144 * This basically reparents the contact and updates the internal
145 * data structures.
146 * If the old contact is going to be empty, the old contact will be removed.
148 * @param m The new MetaContact to move this contact to
150 void setMetaContact(MetaContact *m);
153 * @brief Get whether this contact is online.
154 * @return @c true if the contact is online, @c false otherwise.
156 bool isOnline() const;
159 * \brief Get whether this contact can receive messages
161 * Used in determining if the contact is able to
162 * receive messages. This function must be defined by child classes
164 * @return true if the contact can be reached
165 * @return false if the contact cannot be reached
167 // FIXME: After KDE 3.2 we should split this into a public, NON-virtual
168 // isReachable() accessor that checks for account->isConnected()
169 // and then calls a new virtual method that does the
170 // protocol-specific work, like 'doIsUnreachable' or so - Martijn
172 //FIXME: Can this be made const please? - JK
173 virtual bool isReachable();
176 * @brief Serialize the contact for storage in the contact list.
178 * The provided serializedData contain the contact id in the field
179 * "contactId". If you don't like this, or don't want to
180 * store these fields at all,
181 * you are free to remove them from the list.
183 * Most plugins don't need more than these fields, so they only need
184 * to set the address book fields themselves. If you have nothing to
185 * save at all you can clear the QMap, an empty map is treated as
186 * 'nothing to save'.
188 * The provided addressBookFields QMap contains the index field as
189 * marked with @ref Plugin::addAddressBookField() with the
190 * contact id as value. If no index field is available the QMap is
191 * simply passed as an empty map.
193 * @sa Protocol::deserializeContact
195 virtual void serialize( QMap<QString, QString> &serializedData, QMap<QString, QString> &addressBookData );
198 * @brief Get the online status of the contact
199 * @return the online status of the contact
201 OnlineStatus onlineStatus() const;
204 * \brief Set the contact's online status
206 void setOnlineStatus(const OnlineStatus &status);
209 * @brief Get the current status message of the contact.
210 * @return the status in a Kopete::StatusMessage.
212 Kopete::StatusMessage statusMessage() const;
214 * @brief Set the contact's status message.
215 * It sets also the "awayMessage" property so you don't need to do it.
217 void setStatusMessage(const Kopete::StatusMessage &statusMessage);
220 * \brief Get the set of custom menu items for this contact
222 * Returns a set of custom menu items for the context menu
223 * which is displayed in showContextMenu (private). Protocols
224 * should use this to add protocol-specific actions to the
225 * popup menu. Kopete take care of the deletion of the action collection.
226 * Actions should have the collection as parent.
228 * @return Collection of menu items to be show on the context menu
229 * @todo if possible, try to use KXMLGUI
231 virtual QList<KAction *> *customContextMenuActions();
234 * @todo What is this function for ?
236 virtual QList<KAction *> *customContextMenuActions( ChatSession *manager );
239 * @brief Get the Context Menu for this contact
241 * This menu includes generic actions common to each protocol, and action defined in
242 * @ref customContextMenuActions()
244 KMenu *popupMenu( ChatSession *manager = 0L );
247 * \brief Get whether or not this contact is capable of file transfers
250 * \see setFileCapable()
251 * \return true if the protocol for this contact is capable of file transfers
252 * \return false if the protocol for this contact is not capable of file transfers
254 * @todo have a capabilioties. or move to protocol capabilities
256 bool isFileCapable() const;
259 * \brief Set the file transfer capability of this contact
261 * \param filecap The new file transfer capability setting
262 * @todo have a capabilioties. or move to protocol capabilities
264 void setFileCapable( bool filecap );
267 * \brief Get whether or not this contact can accept file transfers
269 * This function checks to make sure that the contact is online as well as
270 * capable of sending files.
271 * \see isReachable()
272 * @return true if this contact is online and is capable of receiving files
273 * @todo have a capabilioties. or move to protocol capabilities
275 bool canAcceptFiles() const;
277 enum CanCreateFlags { CannotCreate=false , CanCreate=true };
280 * Returns the primary message manager affiliated with this contact
281 * Although a contact can have more than one active message manager
282 * (as is the case with MSN at least), only one message manager will
283 * ever be the contacts "primary" message manager.. aka the 1 on 1 chat.
284 * This function should always return that instance.
286 * @param canCreate If a new message manager can be created in addition
287 * to any existing managers. Currently, this is only set to true when
288 * a chat is initiated by the user by clicking the contact list.
290 virtual ChatSession * manager( CanCreateFlags canCreate = CannotCreate ) =0;
293 * Returns the name of the icon to use for this contact
294 * If null, the protocol icon need to be used.
295 * The icon is not colored, nor has the status icon overloaded
297 QString& icon() const;
300 * @brief Change the icon to use for this contact
301 * If you don't want to have the protocol icon as icon for this contact, you may set
302 * another icon. The icon doesn't need to be colored with the account icon as this operation
303 * will be performed later.
305 * if you want to go back to the protocol icon, set a null string.
307 void setIcon( const QString& icon );
310 * \brief Get the time (in seconds) this contact has been idle
311 * It will return the time set in @ref setIdleTime() with an addition of the time
312 * since you set this last time
313 * @return time this contact has been idle for, in seconds
315 // FIXME: Can we make this just 'unsigned long' ? QT Properties can't handle
316 // 'unsigned long int'
318 virtual unsigned long int idleTime() const;
321 * \brief Set the current idle time in seconds.
322 * Kopete will automatically calculate the time in @ref idleTime
323 * except if you set 0.
325 // FIXME: Can we make this just 'unsigned long' ? QT Properties can't handle
326 // 'unsigned long int'
328 void setIdleTime(unsigned long int);
331 * \brief Convenience method to set the nickName property to the specified value
332 * @param name The nickname to set
334 void setNickName( const QString &name );
337 * \brief Convenience method to retrieve the nickName property.
339 * This method will return the contactId if there has been no nickName property set
341 QString nickName() const;
344 * \brief Get the tooltip for this contact
345 * Makes use of formattedName() and formattedIdleTime().
346 * \return an RTF tooltip depending on Kopete::AppearanceSettings settings
348 QString toolTip() const;
351 * Returns a formatted string of "firstName" and/or "lastName" properties
352 * if present.
353 * Suitable for GUI display
355 QString formattedName() const;
358 * Returns a formatted string of idleTime().
359 * Suitable for GUI display
361 QString formattedIdleTime() const;
364 * @brief Convience method to set the photo property
365 * @param photoPath Local path to the photo
367 void setPhoto(const QString &photoPath);
369 public slots:
371 * This should typically pop up a KopeteChatWindow
373 void startChat();
376 * Pops up an email type window
378 void sendMessage();
381 * The user clicked on the contact, do the default action
383 void execute();
386 * Changes the MetaContact that this contact is a part of. This function
387 * is called by the KAction changeMetaContact that is part of the context
388 * menu.
390 void changeMetaContact();
392 * Method to retrieve user information. Should be implemented by
393 * the protocols, and popup some sort of dialog box
395 * reimplement it to show the informlation
396 * @todo rename and make it pure virtual
398 virtual void slotUserInfo() {}
401 * @brief Syncronise the server and the metacontact.
402 * Protocols with server-side contact lists can implement this to
403 * sync the server groups with the metaContact groups. Or the server alias if any.
405 * This method is called every time the metacontact has been moved or renamed.
407 * default implementation does nothing
409 * @param changed is a bitmask of the @ref Changed enum which say why the call to this function is done.
411 virtual void sync(unsigned int changed = 0xFF);
414 * @deprecated Use DeleteContactTask instead.
415 * Method to delete a contact from the contact list,
416 * should be implemented by protocol plugin to handle
417 * protocol-specific actions required to delete a contact
418 * (ie. messages to the server, etc)
419 * the default implementation simply call deleteLater()
421 virtual KDE_DEPRECATED void deleteContact();
424 * This is the Contact level slot for sending files. It should be
425 * implemented by all contacts which have the setFileCapable() flag set to
426 * true. If the function is called through the GUI, no parameters are sent
427 * and they take on default values (the file is chosen with a file open dialog)
429 * @param sourceURL The actual KUrl of the file you are sending
430 * @param fileName (Optional) An alternate name for the file - what the
431 * receiver will see
432 * @param fileSize (Optional) Size of the file being sent. Used when sending
433 * a nondeterminate
434 * file size (such as over asocket
436 virtual void sendFile( const KUrl &sourceURL = KUrl(),
437 const QString &fileName = QString(), uint fileSize = 0L );
438 private slots:
440 * This add the contact totally in the list if it was a temporary contact
442 void slotAddContact();
445 * slot called when the action "delete" is called.
447 void slotDelete();
450 * slot called when the action "block" is called.
452 void slotBlock();
455 * slot called when the action "unblock" is called.
457 void slotUnblock();
460 * The account's isConnected has changed.
462 void slotAccountIsConnectedChanged();
463 signals:
465 * The contact's online status changed
467 void onlineStatusChanged( Kopete::Contact *contact,
468 const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus );
471 * The contact is about to be destroyed.
472 * Called when entering the destructor. Useful for cleanup, since
473 * metaContact() is still accessible at this point.
475 * @warning this signal is emit in the Contact destructor, so all
476 * virtual method are not available
478 void contactDestroyed( Kopete::Contact *contact );
481 * The contact's idle state changed.
482 * You need to emit this signal to update the view.
483 * That mean when activity has been noticed
485 void idleStateChanged( Kopete::Contact *contact );
488 * \brief Emitted when the file transfer capability of this contact has changed
490 void canAcceptFilesChanged();
492 private:
493 class Private;
494 Private * const d;
500 } //END namespace Kopete
502 #endif