GNUMessenger::ContactManager Class Reference

The ContactManager class controls the loading and storing of Contacts within the GNU Messenger framework. More...

#include <contact_manager.h>

Collaboration diagram for GNUMessenger::ContactManager:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Type {
  FOLDER, BASEFOLDER, CONTACT, CONTACTBASE,
  PROTOCOL
}
 The type of search, deprecated?

Public Member Functions

 ContactManager (XMLNode &xml)
bool addContact (const string &contactname, const string &folder="")
 Adds a Contact to the Folder.
bool addContact (const Contact &contact, const string &folder="")
 Adds a Contact to the Folder.
bool deleteContact (const string &contactname)
 Deletes a Contact from the Folder.
bool moveContact (const string &name, const string &newbase)
 Moves a Contact to a new Folder.
bool renameContact (const string &oldname, const string &newname)
 Rename the Contact.
Contact getContact (const string &contactname)
 Returns a contact in the tree.
vector< ContactgetAllContacts ()
 Returns a vector of contacts.
bool setInfo (const string &username, const string &infoname, const string &data, const string &childof="")
 Sets info of type infoname to the given user.
bool deleteInfo (const string &username, const string &infoname)
 Delete an info tage.
string getAvailableName () const
string getInfo (const string &username, const string &infoname)
map< string, string > getAllInfo (const string &username)
bool addNet (const string &username, const string &netname, const string &login)
bool deleteNet (const string &username, const string &netname)
bool renameFolder (const string &oldname, const string &newname)
bool addFolder (const string &folder_name, const string &base="")
bool deleteFolder (const string &folder_name)
bool moveFolder (const string &name, const string &newbase)
bool folderExists (const string &name) const
bool contactExists (const string &name) const
Folder getFolder (const string &name="")
 gets the folder named name, or the root if no name given
void getContactsOfProtocol (const string &protocol, vector< Contact > &contacts)
void deleteAllNets (const string &contactname)
 Deletes all net tags in XML, may trhow InvalidUserName and InvalidNode.
void deleteAllInfo (const string &contactname)
 Deletes all info tags.
unsigned long getCount ()
 Returns the number of contacts in the tree.
string getPublicKey (const string &contactname)
 Returns the public key for the given contact.
bool getInfoXML (const string &username, XMLNode &xml)
bool setInfoXML (const string &username, const XMLNode &xml)
XMLNode getXML (const string &name)
 Debuging.
XMLNode getFolderXML (const string &name)

Detailed Description

The ContactManager class controls the loading and storing of Contacts within the GNU Messenger framework.

The Contact Manager is able to add and remove Contacts from a session.

Author:
Jesse Lovelace

Definition at line 43 of file contact_manager.h.


Member Function Documentation

bool GNUMessenger::ContactManager::addContact const Contact contact,
const string &  folder = ""
 

Adds a Contact to the Folder.

Parameters:
contact The Contact object to add
folder The Folder to add the Contact to if left empty will be the root folder
Returns:
True if the Contact was added
Definition at line 194 of file contact_manager.cpp.

References GNUMessenger::XMLNode::addChild(), and GNUMessenger::XMLNode::child().

00195 { 00196 XMLNode searcher; 00197 00198 if (folder == "") 00199 searcher = m_xml.child("contacts").child("folder"); 00200 else 00201 if (!XMLManager::search(folder, "folder", m_xml.child("contacts").child("folder"), searcher)) 00202 return false; 00203 00204 XMLNode newnode(c); 00205 00206 searcher.addChild(newnode); 00207 00208 return true; 00209 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::addContact const string &  contactname,
const string &  folder = ""
 

Adds a Contact to the Folder.

Parameters:
contactname The name of the Contact to add
folder The Folder to add the Contact to if left empty will be the root folder
Returns:
True if the Contact was added
Definition at line 179 of file contact_manager.cpp.

References GNUMessenger::XMLNode::addChild(), GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::setProperty().

00180 { 00181 XMLNode searcher; 00182 00183 if (folder == "") 00184 searcher = m_xml.child("contacts").child("folder"); 00185 else 00186 if (!XMLManager::search(folder, "folder", m_xml.child("contacts").child("folder"), searcher)) 00187 return false; 00188 00189 searcher.addChild("contact").setProperty("name", contactname); 00190 return true; 00191 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::deleteContact const string &  contactname  ) 
 

Deletes a Contact from the Folder.

Parameters:
contactname The Contact name to delete
Returns:
True if the contactname is valid
Definition at line 212 of file contact_manager.cpp.

References GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::delChild().

00213 { 00214 unsigned int num; 00215 XMLNode baseSearch; 00216 00217 if (!XMLManager::baseSearch(contactname, "contact", m_xml.child("contacts").child("folder"), baseSearch, num)) 00218 return false; 00219 00220 Contact(baseSearch.child("contact", num)).Destroy(); 00221 baseSearch.delChild("contact", num); 00222 return true; 00223 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::deleteFolder const string &  folder_name  ) 
 

Definition at line 440 of file contact_manager.cpp.

References GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::delChild().

00441 { 00442 unsigned int num; 00443 XMLNode base; 00444 00445 LOG_DEBUG("WARNING THIS DOESNT 'DESTROY' CHILDREN"); 00447 00448 if (!XMLManager::baseSearch(folder_name, "folder", m_xml.child("contacts").child("folder"), base, num)) 00449 { 00450 LOG_DEBUG("deleteFolder: InvalidFolder"); 00451 return false; 00452 } 00453 00454 base.delChild("folder", num); 00455 return true; 00456 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::deleteInfo const string &  username,
const string &  infoname
 

Delete an info tage.

Parameters:
username The Contact name to access
infoname The name of the information tag to delete
Returns:
True if user-name and info-name are valid
Definition at line 292 of file contact_manager.cpp.

References GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::delChild().

00293 { 00294 XMLNode contact; 00295 00296 if (!XMLManager::search(username, "contact", m_xml.child("contacts").child("folder"), contact)) 00297 return false; 00298 00299 unsigned int num; 00300 00301 XMLNode info; 00302 00303 if (!XMLManager::baseSearch(infoname, "item", contact.child("info"), info, num)) 00304 return false; 00305 00306 info.delChild("item", num); 00307 return true; 00308 }

Here is the call graph for this function:

vector< Contact > GNUMessenger::ContactManager::getAllContacts  ) 
 

Returns a vector of contacts.

Returns:
A vector of all the contacts in the tree
Definition at line 387 of file contact_manager.cpp.

References GNUMessenger::XMLNode::child().

00388 { 00389 vector<Contact> ret; 00390 vector<XMLNode> allContacts; 00391 XMLManager::getAllTags("contact", m_xml.child("contacts").child("folder"), allContacts); 00392 00393 for (unsigned int i = 0; i < allContacts.size(); i++) 00394 { 00395 ret.push_back(Contact(allContacts[i])); 00396 } 00397 00398 return ret; 00399 }

Here is the call graph for this function:

Contact GNUMessenger::ContactManager::getContact const string &  contactname  ) 
 

Returns a contact in the tree.

Parameters:
contactname The name of the Contact to extract
Returns:
The Contact object
Todo:
Determin exception handling
Definition at line 162 of file contact_manager.cpp.

References getXML().

00163 { 00164 return Contact(getXML(username)); 00165 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::moveContact const string &  name,
const string &  newbase
 

Moves a Contact to a new Folder.

Parameters:
name The name of the Contact to move
newbase The name of the Folder to move to
Returns:
True of the name and new base are valid
Definition at line 226 of file contact_manager.cpp.

References GNUMessenger::XMLNode::addChild(), GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::delChild().

00227 { 00228 XMLNode searcher; 00229 if (!XMLManager::search(name, "contact", m_xml.child("contacts").child("folder"), searcher)) 00230 return false; 00231 00232 unsigned int num; 00233 XMLNode oldBase; 00234 00235 if (!XMLManager::baseSearch(name, "contact", m_xml.child("contacts").child("folder"), oldBase, num)) 00236 return false; 00237 00238 XMLNode newBase; 00239 00240 if (newbase == "") 00241 newBase = m_xml.child("contacts").child("folder"); 00242 else 00243 if (!XMLManager::search(newbase, "folder", m_xml.child("contacts").child("folder"), newBase)) 00244 return false; 00245 00246 newBase.addChild(searcher); 00247 oldBase.delChild("contact", num); 00248 00249 return true; 00250 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::renameContact const string &  oldname,
const string &  newname
 

Rename the Contact.

Parameters:
oldname The name of the Contact to rename
newname The new name of the Contact
Returns:
True if the old-name is valid and the new-name isn't taken.
Definition at line 110 of file contact_manager.cpp.

References GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::setProperty().

00111 { 00112 XMLNode searcher; 00113 00114 if (!XMLManager::search(oldname, "contact", m_xml.child("contacts").child("folder"), searcher)) 00115 return false; 00116 00117 if (contactExists(newname)) 00118 return false; 00119 00120 searcher.setProperty("name", newname); 00121 00122 return true; 00123 }

Here is the call graph for this function:

bool GNUMessenger::ContactManager::setInfo const string &  username,
const string &  infoname,
const string &  data,
const string &  childof = ""
 

Sets info of type infoname to the given user.

Parameters:
username The user to set the info for
infoname The information tag name
data The information to store
childof The parent to add the info to
Todo:
Clarify this interface
Definition at line 253 of file contact_manager.cpp.

References GNUMessenger::XMLNode::addChild(), GNUMessenger::XMLNode::child(), and GNUMessenger::XMLNode::setProperty().

00254 { 00255 // see if this contact exists 00256 XMLNode user; 00257 00258 if (!XMLManager::search(username, "contact", m_xml.child("contacts").child("folder"), user)) 00259 return false; 00260 00261 XMLNode item; 00262 00263 // see if the item exists 00264 if (XMLManager::search(infoname, "item", user.child("info"), item)) 00265 { 00266 item.setProperty("data",data); 00267 return true; 00268 } 00269 00270 // otherwise, see if a parent node was specified 00271 if (childof != "") 00272 { 00273 XMLNode childOfNode; 00274 00275 if (!XMLManager::search(childof, "item", user.child("info"), childOfNode)) 00276 return false; 00277 // the parent node specified does not exist, return false 00278 00279 // the parent node does exist, add this new child and return true 00280 childOfNode.addChild("item").setProperty("name", infoname).setProperty("data",data); 00281 00282 return true; 00283 } 00284 00285 // no parent node specified, just add to base <info/> tag 00286 user.child("info").addChild("item").setProperty("name", infoname).setProperty("data",data); 00287 00288 return true; 00289 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 14:41:50 2004 for GNU Messenger by doxygen 1.3.8