Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / kopetemetacontact.h
blob4304405ed1d6f329b48f97854750b4078f0930b8
1 /*
2 kopetemetacontact.h - Kopete Meta Contact
4 Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
5 Copyright (c) 2002-2005 by Duncan Mac-Vicar Prett <duncan@kde.org>
6 Copyright (c) 2002-2005 by Olivier Goffart <ogoffart@kde.org>
7 Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
9 Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
11 *************************************************************************
12 * *
13 * This library is free software; you can redistribute it and/or *
14 * modify it under the terms of the GNU Lesser General Public *
15 * License as published by the Free Software Foundation; either *
16 * version 2 of the License, or (at your option) any later version. *
17 * *
18 *************************************************************************
21 #ifndef kopetemetacontact_h__
22 #define kopetemetacontact_h__
24 #include "kopetecontactlistelement.h"
26 #include <QtCore/QList>
28 #include <kdemacros.h>
29 #include <kurl.h>
30 #include "kopete_export.h"
32 #include "kopeteonlinestatus.h"
34 namespace Kopete {
37 class Plugin;
38 class Group;
39 class Picture;
41 /**
42 * @author Will Stephenson <will@stevello.free-online.co.uk>
43 * @author Martijn Klingens <klingens@kde.org>
44 * @author Duncan Mac-Vicar Prett <duncan@kde.org>
45 * @author Olivier Goffart <ogoffart@kde.org>
47 * A metacontact represent a person. This is a kind of entry to
48 * the contact list. All information of a contact is contained in
49 * the metacontact. Plugins can store data in it with all
50 * @ref ContactListElement methods
52 class KOPETE_EXPORT MetaContact : public ContactListElement
54 Q_OBJECT
56 Q_PROPERTY( QString displayName READ displayName WRITE setDisplayName )
57 Q_PROPERTY( QString statusString READ statusString )
58 Q_PROPERTY( QString statusIcon READ statusIcon )
59 Q_PROPERTY( bool isOnline READ isOnline )
60 Q_PROPERTY( bool isReachable READ isReachable )
61 Q_PROPERTY( bool isTemporary READ isTemporary )
62 Q_PROPERTY( bool canAcceptFiles READ canAcceptFiles )
63 //Q_PROPERTY( ulong idleTime READ idleTime )
64 Q_PROPERTY( QString metaContactId READ metaContactId WRITE setMetaContactId )
65 Q_PROPERTY( bool photoSyncedWithKABC READ isPhotoSyncedWithKABC WRITE setPhotoSyncedWithKABC )
67 public:
68 typedef QList<MetaContact *> List;
69 /**
70 * Enumeration of possible sources for a property (which may be
71 * photos, see setPhotoSource() for instance).
73 enum PropertySource {
74 SourceContact /**< Data comes from the contact itself. */,
75 SourceKABC /**< Data comes from KABC (addressbook). */,
76 SourceCustom /**< Data comes from somewhere else. */
79 /**
80 * constructor
82 MetaContact();
83 /**
84 * destructor
86 ~MetaContact();
88 /**
89 * @brief Returns this metacontact's ID.
91 * Every metacontact has a unique id, set by when creating the contact, or reading the contact list
92 * TODO: make it real
94 QString metaContactId() const;
96 /**
97 * @brief Add or change the link to a KDE addressbook (KABC) Addressee.
98 * FIXME: Use with care. You could create 1 to many relationships with the current implementation
100 void setMetaContactId( const QString& newMetaContactId );
103 * @brief Retrieve the list of contacts that are part of the meta contact
105 QList<Contact *> contacts() const;
108 * @brief The groups the contact is stored in
110 QList<Group *> groups() const;
113 * Find the Contact to a given contact. If contact
114 * is not found, a null pointer is returned.
115 * if @p protocolId or @p accountId are null, it is searched over all protocols/accounts
117 Contact *findContact( const QString &protocolId, const QString &accountId, const QString &contactId );
120 * @brief Set the source of metacontact displayName
122 * This method selects the display name source for one
123 * of the sources defined in @ref PropertySource
125 * @see PropertySource
127 void setDisplayNameSource(PropertySource source);
129 void setDisplayNameSource( const QString &nameSourcePID, const QString &nameSourceAID, const QString &nameSourceCID );
132 * @brief get the source of metacontact display name
134 * This method obtains the current name source for one
135 * of the sources defined in @ref PropertySource
137 * @see PropertySource
139 PropertySource displayNameSource() const;
142 * @brief Set the source of metacontact photo
144 * This method selects the photo source for one
145 * of the sources defined in @ref PropertySource
147 * @see PropertySource
149 void setPhotoSource(PropertySource source);
151 void setPhotoSource( const QString &photoSourcePID, const QString &photoSourceAID, const QString &photoSourceCID );
154 * @brief get the source of metacontact photo
156 * This method obtains the current photo source for one
157 * of the sources defined in @ref PropertySource
159 * @see PropertySource
161 PropertySource photoSource() const;
164 * @brief the display name showed in the contact list window
166 * The displayname is the name which should be shown almost everywere to
167 * represent the metacontact. (in the contact list, in the chatwindow, ...)
169 * This is a kind of alias, set by the kopete user, as opposed to a nickname
170 * set by the contact itself.
172 * If the protocol support alias serverside, the metacontact displayname
173 * should probably be synchronized with the alias on the server.
175 * This displayName is obtained from the source set with @ref setDisplayNameSource
177 QString displayName() const;
180 * @brief the photo showed in the contact list window
182 * Returns a image for the metacontact. If the metacontact photo source is
183 * the KDE addressbook. it will return the picture stored in the addressbook
184 * It can also use a subcontact as the photo source.
186 * This photo is obtained from the source set with @ref setPhotoSource
187 * @deprecated Use picture().image() instead.
189 KDE_DEPRECATED QImage photo() const;
192 * Return the correct Kopete::Picture object depending of the metacontact photo source.
194 * This photo is obtained from the source set with @ref setPhotoSource
196 * KDE4 TODO: Rename this to photo() and use the new object.
198 Picture &picture() const;
201 * @brief Set the custom displayName.
203 * This display name is used when name source is Custom
204 * this metohd may emit @ref displayNameChanged signal.
205 * And will call @ref Kopete::Contact::sync
207 * @see displayName()
208 * @see displayNameSource()
210 void setDisplayName( const QString &name );
213 * @brief Returns the custom display name
215 * @see displayName()
216 * @see displayNameSource()
218 QString customDisplayName() const;
221 * @brief Returns the custom display photo
223 * @see photo()
224 * @see photoSource()
226 KUrl customPhoto() const;
230 * @brief Set the custom photo.
232 * This photo is used when photo source is set toCustom
233 * this metohd may emit @ref photoChanged signal.
235 * @see photo()
236 * @see photoSource()
238 void setPhoto( const KUrl &url );
241 * @brief get the subcontact being tracked for its displayname (null if not set)
243 * The MetaContact will adjust its displayName() every time the
244 * "nameSource" changes its nickname property.
246 Contact *displayNameSourceContact() const;
249 * @brief set the subcontact whose name is to be tracked (set to null to disable tracking)
250 * @see nameSource
252 void setDisplayNameSourceContact( Contact* contact );
255 * @brief get the subcontact being tracked for its photo
257 Contact *photoSourceContact() const;
260 * @brief set the subcontact to use for SourceContact source
262 void setPhotoSourceContact( Contact* contact );
265 * @return true if when a subcontact change his photo, the photo will be set to the kabc contact.
267 bool isPhotoSyncedWithKABC() const;
270 * Set if the photo should be synced with the adressbook when the photosource change his photo
272 * If \p b is true, the photo will be synced immediately if possible
274 void setPhotoSyncedWithKABC(bool b);
278 * Temporary contacts will not be serialized.
279 * If they are added to the contact list, they appears in a special "Not in your contact list" group.
280 * (the @ref Group::temporary group)
282 bool isTemporary() const;
285 * @brief Add a contact which has just been deserialised to the meta contact
286 * @param c The Contact being added
288 void addContact( Contact *c );
291 * @brief remove the contact from this metacontact
293 * set 'deleted' to true if the Contact is already deleted
295 * @param c is the contact to remove
296 * @param deleted : if it is false, it will disconnect the old contact, and call some method.
298 void removeContact( Contact *c , bool deleted = false );
301 * @return the preferred child Contact for communication, or 0 if none is suitable (all unreachable).
303 Contact *preferredContact();
306 * @brief The name of the icon associated with the contact's status
307 * @todo improve with OnlineStatus
309 QString statusIcon() const;
312 * @brief The status string of the contact
314 * @see @ref status()
315 * @todo improve with OnlineStatus
317 QString statusString() const;
320 * Returns whether this contact can be reached online for at least one
321 * FIXME: Make that an enum, because status can be unknown for certain
322 * protocols
324 bool isOnline() const;
327 * Returns whether this contact can accept files
328 * @return True if the user is online with a file capable protocol, false otherwise
330 bool canAcceptFiles() const;
333 * Return a more fine-grained status.
334 * Online means at least one sub-contact is online, away means at least
335 * one is away, but nobody is online and offline speaks for itself
337 OnlineStatus::StatusType status() const;
340 * Like isOnline, but returns true even if the contact is not online, but
341 * can be reached trough offline-messages.
342 * it it return false, you are unable to open a chatwindow
343 * @todo : Here too, use preference order, not append order!
344 * @todo : Here too an enum.
346 bool isReachable() const;
349 * return the time in second the contact is idle.
351 unsigned long int idleTime() const;
354 * Get or set a field for the KDE address book backend. Fields not
355 * registered during the call to Plugin::addressBookFields()
356 * cannot be altered!
358 * @param p The Plugin by which uses this field
359 * @param app refers to the application id in the libkabc database.
360 * This should be a standardized format to make sense in the address
361 * book in the first place - if you could use "" as application
362 * then probably you should use the plugin data API instead of the
363 * address book fields.
364 * @param key The name of the address book field to get or set
366 * @todo: In the code the requirement that fields are registered first
367 * is already lifted, but the API needs some review before we
368 * can remove it here too.
369 * Probably it requires once more some rewrites to get it working
370 * properly :( - Martijn
372 QString addressBookField( Plugin *p, const QString &app, const QString &key ) const;
375 * @brief set an address book field
377 * @see also @ref addressBookField()
378 * @param p The Plugin by which uses this field
379 * @param app The application ID in the KABC database
380 * @param key The name of the address book field to set
381 * @param value The value of the address book field to set
383 void setAddressBookField( Plugin *p, const QString &app, const QString &key, const QString &value );
385 public slots:
388 * @brief Send a file to this metacontact
390 * This is the MetaContact level slot for sending files. It may be called through the
391 * "Send File" entry in the GUI, or over DCOP. If the function is called through the GUI,
392 * no parameters are sent and they assume default values. This slot calls the slotSendFile
393 * with identical params of the highest ranked contact capable of sending files (if any)
395 * @param sourceURL The actual KUrl of the file you are sending
396 * @param altFileName (Optional) An alternate name for the file - what the receiver will see
397 * @param fileSize (Optional) Size of the file being sent. Used when sending a nondeterminate
398 * file size (such as over a socket)
401 void sendFile( const KUrl &sourceURL, const QString &altFileName = QString(),
402 unsigned long fileSize = 0L );
405 * Emit aboutToSave signal to notify plugins that this metaContact is going to be saved
407 void emitAboutToSave();
409 signals:
411 * This metaContact is going to be saved to the contact list. Plugins should
412 * connect to this signal to update data with setPluginData()
414 void aboutToSave( Kopete::MetaContact *metaContact );
417 * One of the subcontacts' idle status has changed. As with online status,
418 * this can occur without the metacontact changing idle state
420 void contactIdleStateChanged( Kopete::Contact *contact );
423 public slots:
426 * @brief Move a contact from one group to another.
428 void moveToGroup( Kopete::Group *from, Kopete::Group *to );
431 * @brief Remove a contact from one group
433 void removeFromGroup( Kopete::Group *from );
436 * @brief Add a contact to another group.
438 void addToGroup( Kopete::Group *to );
441 * @brief Set if this is a temporary contact. (see @ref isTemporary)
443 * @param b if the contact is or not temporary
444 * @param group if the contact was temporary and b is false, then the contact will be moved to this group.
445 * if group is null, it will be moved to top-level
447 void setTemporary( bool b = true, Kopete::Group *group = 0L );
450 * @brief Contact another user.
452 * Depending on the config settings, call sendMessage() or
453 * startChat()
455 * returns the Contact that was chosen as the preferred
457 Contact *execute();
460 * @brief Send a single message, classic ICQ style.
462 * The actual sending is done by the Contact, but the meta contact
463 * does the GUI side of things.
464 * This is a slot to allow being called easily from e.g. a GUI.
466 * returns the Contact that was chosen as the preferred
468 Contact *sendMessage();
471 * @brief Start a chat in a persistent chat window
473 * Like sendMessage, but this time a full-blown chat will be opened.
474 * Most protocols can't distinguish between the two and are either
475 * completely session based like MSN or completely message based like
476 * ICQ the only true difference is the GUI shown to the user.
478 * returns the Contact that was chosen as the preferred
480 Contact *startChat();
483 * When all the plugins are loaded, set the Contact Source.
485 void slotAllPluginsLoaded();
488 * If a plugin is loaded, maybe data about this plugin are already cached in the metacontact
490 void slotPluginLoaded( Kopete::Plugin *plugin );
492 signals:
494 * @brief The MetaContact online status changed
496 void onlineStatusChanged( Kopete::MetaContact *contact, Kopete::OnlineStatus::StatusType status );
499 * @brief A contact's online status changed
501 * this signal differs from @ref onlineStatusChanged because a contact can
502 * change his status without changing MetaContact status. It is mainly used to update the small icons
503 * in the contact list
505 void contactStatusChanged( Kopete::Contact *contact, const Kopete::OnlineStatus &status );
508 * @brief The meta contact's display name changed
510 void displayNameChanged( const QString &oldName, const QString &newName );
513 * @brief The meta contact's photo changed
515 void photoChanged();
518 * @brief The contact was moved
520 void movedToGroup( Kopete::MetaContact *contact, Kopete::Group *from, Kopete::Group *to );
523 * @brief The contact was removed from group
525 void removedFromGroup( Kopete::MetaContact *contact, Kopete::Group *group );
528 * @brief The contact was added to another group
530 void addedToGroup( Kopete::MetaContact *contact, Kopete::Group *to );
533 * @brief a contact has been added into this metacontact
535 * This signal is emitted when a contact is added to this metacontact
537 void contactAdded( Kopete::Contact *c );
540 * @brief a contact has been removed from this metacontact
542 * This signal is emitted when a contact is removed from this metacontact
544 void contactRemoved( Kopete::Contact *c );
547 * Some part of this object's persistent data (as returned by toXML) has changed.
549 void persistentDataChanged( );
551 private slots:
553 * Update the contact's online status and emit onlineStatusChanged
554 * when appropriate
556 void updateOnlineStatus();
559 * One of the child contact's online status changed
561 void slotContactStatusChanged( Kopete::Contact *c, const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus );
564 * One of the child contact's property changed
566 void slotPropertyChanged( Kopete::PropertyContainer *contact, const QString &key, const QVariant &oldValue, const QVariant &newValue );
569 * A child contact was deleted, remove it from the list, if it's still
570 * there
572 void slotContactDestroyed( Kopete::Contact* );
575 * Update the KABC Picture when the addressbook is changed.
577 void slotUpdateAddressBookPicture();
579 protected:
580 //QImage photoFromContact( Kopete::Contact *c) const;
581 //QImage photoFromKABC( const QString &id ) const;
582 QImage photoFromCustom() const;
583 //QString nameFromContact( Kopete::Contact *c) const;
584 //QString nameFromKABC( const QString &id ) const;
586 private:
587 class Private;
588 Private * const d;
591 // util functions shared with metacontact property dialog
592 KOPETE_EXPORT QImage photoFromContact( Kopete::Contact *c) /*const*/;
593 KOPETE_EXPORT QImage photoFromKABC( const QString &id ) /*const*/;
594 KOPETE_EXPORT QString nameFromContact( Kopete::Contact *c) /*const*/;
595 KOPETE_EXPORT QString nameFromKABC( const QString &id ) /*const*/;
597 } //END namespace Kopete
600 #endif
602 // vim: set noet ts=4 sts=4 sw=4: