1 /*
2 	Kopete Oscar Protocol
3 
4 	Copyright ( c ) 2004 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
5 	Copyright ( c ) 2004 Matt Rogers <mattr@kde.org>
6 
7 	Kopete ( c ) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
8 
9 	based on ssidata.h and ssidata.cpp ( c ) 2002 Tom Linsky <twl6@po.cwru.edu>
10 
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 	*************************************************************************
19 */
20 
21 #ifndef CONTACTMANAGER_H
22 #define CONTACTMANAGER_H
23 
24 #include <qobject.h>
25 #include <QList>
26 
27 #include "oscartypes.h"
28 #include "oscartypeclasses.h"
29 #include "contact.h"
30 
31 using namespace Oscar;
32 
33 class ContactManagerPrivate;
34 
35 /**
36 Contact management
37 
38 @author Gustavo Pichorim Boiko
39 @author Matt Rogers
40 */
41 class LIBOSCAR_EXPORT ContactManager : public QObject
42 {
43         Q_OBJECT
44 public:
45 	ContactManager( QObject* parent = nullptr );
46 
47 	~ContactManager();
48 
49 	/** Clear the internal Contact list */
50 	void clear();
51 
52 	/** Get the next buddy id for an Contact item */
53 	Oscar::WORD nextContactId();
54 
55 	/** Get the next group id for an Contact item */
56 	Oscar::WORD nextGroupId();
57 
58 	/** Get the number of items in the Contact list. */
59 	Oscar::WORD numberOfItems() const;
60 
61 	/** Get the timestamp the list was last modified */
62 	Oscar::DWORD lastModificationTime() const;
63 
64 	/** Set the timestamp of the last modification time */
65 	void setLastModificationTime( Oscar::DWORD lastTime );
66 
67 	/** Set the parameters we should use for Contact */
68 	void setParameters( Oscar::WORD maxContacts, Oscar::WORD maxGroups, Oscar::WORD maxVisible,
69 	                    Oscar::WORD maxInvisible, Oscar::WORD maxIgnore );
70 
71 	/**
72 	 * Load an existing list from Contact objects.
73 	 * The current Contact list will be overwritten and it's contents
74 	 * replaced with the data from the new list
75 	 */
76 	void loadFromExisting( const QList<OContact*>& newList );
77 
78 	bool hasItem( const OContact& item ) const;
79 
80 	OContact findGroup( const QString& group ) const;
81 	OContact findGroup( int groupId ) const;
82 
83 	OContact findContact( const QString& contact, const QString& group ) const;
84 	OContact findContact( const QString& contact ) const;
85 	OContact findContact( int contactId ) const;
86 
87 	OContact findItemForIcon( QByteArray iconHash ) const;
88 	OContact findItemForIconByRef( int ) const;
89 
90 	OContact findItem( const QString &contact, int type ) const;
91 
92 	QList<OContact> groupList() const;
93 	QList<OContact> contactList() const;
94 	QList<OContact> visibleList() const;
95 	QList<OContact> invisibleList() const;
96 	QList<OContact> ignoreList() const;
97 	QList<OContact> contactsFromGroup( const QString& group ) const;
98 	QList<OContact> contactsFromGroup( int groupId ) const;
99 
100 	OContact visibilityItem() const;
101 
102 	void setListComplete( bool complete );
103 	bool listComplete() const;
104 
105 public Q_SLOTS:
106 	bool newGroup( const OContact& group );
107 	bool updateGroup( const OContact& group );
108 	bool removeGroup( const OContact& group );
109 	bool removeGroup( const QString& group );
110 
111 	bool newContact( const OContact& contact );
112 	bool updateContact( const OContact& contact );
113 	bool removeContact( const OContact& contact );
114 	bool removeContact( const QString& contact );
115 
116 	bool newItem( const OContact& item );
117 	bool updateItem( const OContact& item );
118 	bool removeItem( const OContact& item );
119 
120 	void addID( const OContact& item );
121 	void removeID( const OContact& item );
122 
123 Q_SIGNALS:
124 
125 	//! Emitted when we've added a new contact to the list
126 	void contactAdded( const OContact& );
127 
128 	//! Emitted when we've updated a contact in the list
129 	void contactUpdated( const OContact& );
130 
131 	//! Emitted when we've removed a contact from the list
132 	void contactRemoved( const QString& contactName );
133 
134 	//! Emitted when we've added a new group to the list
135 	void groupAdded( const OContact& );
136 
137 	//! Emitted when we've updated a group in the list
138 	void groupUpdated( const OContact& );
139 
140 	//! Emitted when we've removed a group from the ssi list
141 	void groupRemoved( const QString& groupName );
142 
143 	void modifyError( const QString& error );
144 
145 private:
146 	Oscar::WORD findFreeId( const QSet<Oscar::WORD>& idSet, Oscar::WORD fromId ) const;
147 
148 	ContactManagerPrivate* d;
149 	OContact m_dummyItem;
150 };
151 
152 #endif
153 
154