GNUMessenger::Contact Class Reference
[XML]

#include <contact.h>

Inheritance diagram for GNUMessenger::Contact:

Inheritance graph
[legend]
Collaboration diagram for GNUMessenger::Contact:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Status {
  Offline, Online, Away, Occupied,
  DND, NA, FFC, Error,
  Custom
}
 Contact status is associated with each Protocol that the object is associated with. More...

Public Member Functions

 Contact ()
 Default. Initialized to a new, empty node.
 Contact (const Contact &contact)
 Copy constructor.
 Contact (const XMLNode &config)
 XMLNode constructor.
virtual ~Contact ()
 Virtual destructor.
bool isOK () const
 Returns true if the contact is valid and without error.
void Destroy ()
bool isOnline () const
 Checks to see if the Contact object is registered as Online.
void addProtocol (const string &proto)
 Add a protocol to the contact, never throws.
void removeProtocol (const string &proto)
 Removes a protocol, never throws.
virtual XMLNodesetName (const string &name)
 Sets the "real name" of the contact.
virtual const string & name () const
 Returns the "name" of the Contact.
virtual const string type () const
 Type ID of this node.
string getProtocol () const
 Gets whatever protocol is online, or nothing.
bool hasProtocol (const string &str) const
 Do I have this protocol.
void setServerId (const string &proto, const string &id)
 Sets the contact's server ID for specified protocol.
string getServerId (const string &proto) const
 Returns the server id for the contact for specified protocol.
void setStatus (const string &proto, Status state)
 Sets a protocol status.
Status getStatus (const string &proto) const
 Returns the status of a specified protocol.
Status getOverallStatus () const
Contactoperator= (const Contact &other)
 Assignment operator, shallow copy.

Friends

bool operator!= (const Contact &lhs, const Contact &rhs)
 Not-equal binary operator.
bool operator== (const Contact &lhs, const Contact &rhs)
 Equality binary operator.
bool operator< (const Contact &lhs, const Contact &c2)
 Less-than binary operator.

Detailed Description

The Contact class stores information about a single contact. Each contact may have an *unlimited* amount of information such as networks, personal data, and keys associated with it.
Author:
Henrik Abelsson

Jesse Lovelace

Definition at line 21 of file contact.h.


Member Enumeration Documentation

enum GNUMessenger::Contact::Status
 

Contact status is associated with each Protocol that the object is associated with.

Enumeration values:
Offline  The Contact is not online.
Online  The Contact is online.
Away  The Contact is away.
Occupied  The Contact is occupied.
DND  The Contact wishes to not be disturbed.
NA  The Contact is not available at this time.
FFC  The Contact is free for chat.
Error  There is an error with this protocol.
Definition at line 51 of file contact.h.

Referenced by getOverallStatus(), and getStatus().

00051 { 00052 Offline, 00053 Online, 00054 Away, 00055 Occupied, 00056 DND, 00057 NA, 00058 FFC, 00059 Error, 00060 Custom 00061 };


Constructor & Destructor Documentation

GNUMessenger::Contact::Contact const Contact contact  ) 
 

Copy constructor.

Parameters:
contact The contact object to copy. Note all Contacts are internally reference counted, there are no "deep copys" made.
Definition at line 35 of file contact.cpp.

References m_session.

00035 : 00036 XMLNode(other) 00037 { 00038 m_session = other.m_session; 00039 }

GNUMessenger::Contact::Contact const XMLNode config  ) 
 

XMLNode constructor.

Parameters:
config The XMLNode is linked to the Contact via an internal reference. See XMLNode and XMLNode::XMLNodeData.
Exceptions:
Contact::ContactError Raises exception <==> the "name" does not equal "contact"
Definition at line 47 of file contact.cpp.
00047 : 00048 XMLNode(config) 00049 { 00050 00051 }


Member Function Documentation

void GNUMessenger::Contact::addProtocol const string &  proto  ) 
 

Add a protocol to the contact, never throws.

Parameters:
proto The Protocol name to add.
Definition at line 182 of file contact.cpp.

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

00183 { 00184 if (child("protocols").hasChild(proto)) 00185 return; 00186 00187 child("protocols").addChild(proto); 00188 }

Here is the call graph for this function:

Contact::Status GNUMessenger::Contact::getOverallStatus  )  const
 

Definition at line 88 of file contact.cpp.

References GNUMessenger::XMLNode::child(), GNUMessenger::XMLNode::const_children(), Error, GNUMessenger::XMLNode::hasChild(), Offline, Online, and Status.

00089 { 00090 if (!hasChild("protocols")) 00091 return Error; 00092 00093 Status bestSoFar = Offline; 00094 00095 vector<XMLNode> xml = child("protocols").const_children(); 00096 for (unsigned int i = 0; i < xml.size(); i++) { 00097 Status temp = (Status)xml[i].intProperty("status"); 00098 00099 if (temp == Online) 00100 return Online; 00101 else 00102 if (temp > bestSoFar) 00103 return temp; 00104 } 00105 00106 return Error; 00107 }

Here is the call graph for this function:

string GNUMessenger::Contact::getProtocol  )  const
 

Gets whatever protocol is online, or nothing.

Returns:
std::string of the name of a non-offline protocol.
Note:
The function tries to find a protocol listed as Contact::Online but will fall-back to a non Contact::Offline protocol if none is found.
Definition at line 211 of file contact.cpp.

References GNUMessenger::XMLNode::child(), GNUMessenger::XMLNode::const_children(), GNUMessenger::XMLNode::hasChild(), Offline, and Online.

Referenced by GNUMessenger::ProtocolManager::sendMessage().

00212 { 00213 if (!hasChild("protocols")) 00214 return ""; 00215 00216 vector<XMLNode> xml = child("protocols").const_children(); 00217 00218 // try first searching for online protocol 00219 for (unsigned int i = 0; i < xml.size(); i++) { 00220 if (xml[i].intProperty("status") == Online) 00221 return xml[i].name(); 00222 } 00223 00224 // then search for any non-offline protocol 00225 for (unsigned int i = 0; i < xml.size(); i++) { 00226 if (xml[i].intProperty("status") != Offline) 00227 return xml[i].name(); 00228 } 00229 00230 return ""; 00231 00232 }

Here is the call graph for this function:

string GNUMessenger::Contact::getServerId const string &  proto  )  const
 

Returns the server id for the contact for specified protocol.

Parameters:
proto The protocol identifier string.
Returns:
std::string of the associated login-id.
Definition at line 53 of file contact.cpp.

References GNUMessenger::XMLNode::child(), GNUMessenger::XMLNode::hasChild(), and GNUMessenger::XMLNode::property().

Referenced by GNUMessenger::TocProtocol::addContact(), GNUMessenger::TocProtocol::delContact(), GNUMessenger::ProtocolManager::getInfo(), and GNUMessenger::TocProtocol::sendMessage().

00054 { 00055 00056 try { 00057 if (child("protocols").hasChild(proto)) 00058 return child("protocols").child(proto).property("login"); 00059 } catch (XMLNode::InvalidChild &e) { 00060 LOG_DEBUG("No protocols group"); 00061 } 00062 00063 return ""; 00064 }

Here is the call graph for this function:

Contact::Status GNUMessenger::Contact::getStatus const string &  proto  )  const
 

Returns the status of a specified protocol.

Parameters:
proto The protocol identifier string
Returns:
The enumberated States value.
Definition at line 76 of file contact.cpp.

References GNUMessenger::XMLNode::child(), Error, GNUMessenger::XMLNode::hasChild(), GNUMessenger::XMLNode::intProperty(), and Status.

00077 { 00078 if (child("protocols").hasChild(proto)) { 00079 int status = child("protocols").child(proto).intProperty("status"); 00080 return Status(status); 00081 } else { 00082 LOG_THROW("Contact::getStatus: invalid protocol", XMLNode::InvalidChild); 00083 } 00084 00085 return Error; 00086 }

Here is the call graph for this function:

bool GNUMessenger::Contact::isOK  )  const
 

Returns true if the contact is valid and without error.

Returns:
Boolean value, true iif Contact object valid.
Definition at line 190 of file contact.cpp.

References GNUMessenger::XMLNode::property().

00190 { 00191 if (property("destroyed") == "true") 00192 return false; 00193 return true; 00194 }

Here is the call graph for this function:

bool GNUMessenger::Contact::isOnline  )  const
 

Checks to see if the Contact object is registered as Online.

Returns:
Boolean, true iff Contact object has a non Offline protocol.

virtual const string& GNUMessenger::Contact::name  )  const [inline, virtual]
 

Returns the "name" of the Contact.

Returns:
Constant std::string object.

Reimplemented from GNUMessenger::XMLNode.

Definition at line 87 of file contact.h.

References GNUMessenger::XMLNode::property().

Referenced by GNUMessenger::ProtocolManager::addContact().

00087 { m_name = property("name"); return m_name; }

Here is the call graph for this function:

Contact & GNUMessenger::Contact::operator= const Contact other  ) 
 

Assignment operator, shallow copy.

Parameters:
other The Contact object to reference this object to.
Definition at line 234 of file contact.cpp.

References m_session, and GNUMessenger::XMLNode::m_xmlData.

00235 { 00236 other.m_xmlData->ref(); 00237 00238 if (m_xmlData && m_xmlData->deref()) { 00239 delete m_xmlData; 00240 m_xmlData=0; 00241 } 00242 00243 m_xmlData=other.m_xmlData; 00244 00245 m_session = other.m_session; 00246 00247 return *this; 00248 }

void GNUMessenger::Contact::removeProtocol const string &  proto  ) 
 

Removes a protocol, never throws.

Parameters:
proto The Protocol name to remove.

virtual XMLNode& GNUMessenger::Contact::setName const string &  name  )  [inline, virtual]
 

Sets the "real name" of the contact.

Never throws.

Parameters:
name Sets the name of the Contact object to the value.

Reimplemented from GNUMessenger::XMLNode.

Definition at line 83 of file contact.h.

References GNUMessenger::XMLNode::setProperty().

00083 { setProperty("name",name); return *this; }

Here is the call graph for this function:

void GNUMessenger::Contact::setServerId const string &  proto,
const string &  id
 

Sets the contact's server ID for specified protocol.

Parameters:
id The std::string login ID of this Contact.
proto The std::string protocol name to associate with id.
Exceptions:
XMLNode::InvalidNode Raises exception if the Protocol name is invalid
Definition at line 110 of file contact.cpp.

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

00111 { 00112 if (proto.length() == 0){ 00113 LOG_ERROR("PROTO LENGTH ZERO!"); 00114 return; 00115 } 00116 00117 LOG_DEBUG("Contact::setServerId: " << proto << " " << id); 00118 // set the server Id for a specified protocol 00119 if (!child("protocols").hasChild(proto)) 00120 child("protocols").addChild(proto); 00121 00122 child("protocols").child(proto).setProperty("login", id); 00123 }

Here is the call graph for this function:

void GNUMessenger::Contact::setStatus const string &  proto,
Status  state
 

Sets a protocol status.

Parameters:
proto The protocol identifier string
state The enumberated Status value corresponding the protocols status.
Definition at line 66 of file contact.cpp.

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

00067 { 00068 if (child("protocols").hasChild(proto)) { 00069 child("protocols").child(proto).setProperty("status",state); 00070 } else { 00071 LOG_THROW("Contact::setStatus: invalid protocol", XMLNode::InvalidChild); 00072 } 00073 00074 }

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:49 2004 for GNU Messenger by doxygen 1.3.8