summaryrefslogtreecommitdiffstats
path: root/kopete/kopete/config/identity/globalidentitiesmanager.h
blob: e7ee06c0bd95604784f8b22f6f2a7cc188674ea5 (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
139
140
141
142
143
144
/*
    globalidentitiesmanager.h  -  Kopete Global identities manager.

    Copyright (c) 2005      by Michaël Larouche       <michael.larouche@kdemail.net>

    Kopete    (c) 2003-2005 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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 GLOBALIDENTITIESMANAGER_H
#define GLOBALIDENTITIESMANAGER_H

#include <tqobject.h>
#include <tqmap.h>

namespace Kopete
{
	class MetaContact;
}
class TQDomDocument;

/**
 * This singleton class handle the loading, saving and manipulating of all the global identities from a XML file. 
 * It also hold the pointer list of metacontacts.
 * Use this class with GlobalIdentitiesManager::self()
 *
 * @author Michaël Larouche <michael.larouche@kdemail.net>
*/
class GlobalIdentitiesManager : public TQObject
{
    Q_OBJECT
  
public:
	/**
	 * @brief Return the single instance of GlobalIdentitiesManager class	
	 *
	 * The global identities manager is a singleton class of which only
	 * a single instance will exist. If no manager exists yet, this method
	 * create one for you.
	 *
	 * @return The single instance of GlobalIdentitiesManager class.
	 * FIXME: Should I remove the singleton pattern ?
	 */
	static GlobalIdentitiesManager* self();
	~GlobalIdentitiesManager();

	/**
	 * @brief Create a new identity and add it to the internal list.
	 */	
	void createNewIdentity(const TQString &identityName);

	/**
	 * @brief Copy a identity
	 *
	 * @param copyIdentityName Name for the copy identity.
	 * @param sourceIdentity Name of the source identity.
	 */
	void copyIdentity(const TQString &copyIdentityName, const TQString &sourceIdentity);

	/**
	 * @brief Rename a identity
	 *
	 * @param oldName Identity to rename.
	 * @param newName New identity name.
	 */
	void renameIdentity(const TQString &oldName, const TQString &newName);

	/**
	 * @brief Delete identity
	 *
	 * @param removedIdentity Identity name to remove.
	 */
	void removeIdentity(const TQString &removedIdentity);

	/**
	 * @brief Update the specified identity using the source MetaContact
	 *
	 * @param updatedIdentity Identity to update.
	 * @param sourceMetaContact Source of data.
	 */
	void updateIdentity(const TQString &updatedIdentity, Kopete::MetaContact *sourceMetaContact);

	/**
	 * @brief Check if the specified identityName exists.
	 * 
	 * This is a helper method to avoid duplicated entries.
	 * @return if the identityName is in the internal list.
	 */
	bool isIdentityPresent(const TQString &identityName);

	/**
	 * @brief Return the specified identity.
	 *
	 * @param identityName Identity to retrive.
	 * @return Identity data as Kopete::MetaContact.
	 */
	Kopete::MetaContact *getIdentity(const TQString &identityName);

	/**
	 * @brief Load the XML file where global identities metacontacts are stored.
	 */
	void loadXML();

	/**
	 * @brief Save the global identities metacontacts to XML file.
	 */
	void saveXML();

	/**
	 * @brief Return the list of global identities metacontact.
	 * @return The pointer list of metacontact as TQValueList
	 */
	TQMap<TQString, Kopete::MetaContact*> getGlobalIdentitiesList();

private:
	GlobalIdentitiesManager(TQObject *parent = 0, const char *name = 0);

	/**
	 * @brief Return a XML representation of the global identities list.
	 * 
	 * @return the XML represention as TQDomDocument.
	 */
	const TQDomDocument toXML();

	Kopete::MetaContact *createNewMetaContact();
	Kopete::MetaContact *createCopyMetaContact(Kopete::MetaContact *source);
	void copyMetaContact(Kopete::MetaContact *destination, Kopete::MetaContact *source);

private:
	static GlobalIdentitiesManager *s_self;
	class Private;
	Private *d;

};

#endif