rosteritem.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "rosteritem.h"
00016 #include "rosteritemdata.h"
00017 #include "util.h"
00018
00019 namespace gloox
00020 {
00021
00022 RosterItem::RosterItem( const std::string& jid, const std::string& name )
00023 : m_data( new RosterItemData( jid, name, StringList() ) )
00024 {
00025 }
00026
00027 RosterItem::RosterItem( const RosterItemData& data )
00028 : m_data( new RosterItemData( data ) )
00029 {
00030 }
00031
00032 RosterItem::~RosterItem()
00033 {
00034 delete m_data;
00035 util::clearMap( m_resources );
00036 }
00037
00038 void RosterItem::setName( const std::string& name )
00039 {
00040 if( m_data )
00041 m_data->setName( name );
00042 }
00043
00044 const std::string& RosterItem::name() const
00045 {
00046 if( m_data )
00047 return m_data->name();
00048 else
00049 return EmptyString;
00050 }
00051
00052 const std::string& RosterItem::jid() const
00053 {
00054 if( m_data )
00055 return m_data->jid();
00056 else
00057 return EmptyString;
00058 }
00059
00060 void RosterItem::setSubscription( const std::string& subscription, const std::string& ask )
00061 {
00062 if( m_data )
00063 m_data->setSubscription( subscription, ask );
00064 }
00065
00066 SubscriptionType RosterItem::subscription() const
00067 {
00068 if( m_data )
00069 return m_data->subscription();
00070 else
00071 return S10nNone;
00072 }
00073
00074 void RosterItem::setGroups( const StringList& groups )
00075 {
00076 if( m_data )
00077 m_data->setGroups( groups );
00078 }
00079
00080 const StringList RosterItem::groups() const
00081 {
00082 if( m_data )
00083 return m_data->groups();
00084 else
00085 return StringList();
00086 }
00087
00088 bool RosterItem::changed() const
00089 {
00090 if( m_data )
00091 return m_data->changed();
00092 else
00093 return false;
00094 }
00095
00096 void RosterItem::setSynchronized()
00097 {
00098 if( m_data )
00099 m_data->setSynchronized();
00100 }
00101
00102 void RosterItem::setPresence( const std::string& resource, Presence::PresenceType presence )
00103 {
00104 if( m_resources.find( resource ) == m_resources.end() )
00105 m_resources[resource] = new Resource( 0, EmptyString, presence );
00106 else
00107 m_resources[resource]->setStatus( presence );
00108 }
00109
00110 void RosterItem::setStatus( const std::string& resource, const std::string& msg )
00111 {
00112 if( m_resources.find( resource ) == m_resources.end() )
00113 m_resources[resource] = new Resource( 0, msg, Presence::Unavailable );
00114 else
00115 m_resources[resource]->setMessage( msg );
00116 }
00117
00118 void RosterItem::setPriority( const std::string& resource, int priority )
00119 {
00120 if( m_resources.find( resource ) == m_resources.end() )
00121 m_resources[resource] = new Resource( priority, EmptyString, Presence::Unavailable );
00122 else
00123 m_resources[resource]->setPriority( priority );
00124 }
00125
00126 const Resource* RosterItem::highestResource() const
00127 {
00128 int highestPriority = -255;
00129 Resource* highestResource = 0;
00130 ResourceMap::const_iterator it = m_resources.begin();
00131 for( ; it != m_resources.end() ; ++it )
00132 {
00133 if( (*it).second->priority() > highestPriority )
00134 {
00135 highestPriority = (*it).second->priority();
00136 highestResource = (*it).second;
00137 }
00138 }
00139 return highestResource;
00140 }
00141
00142 void RosterItem::setExtensions( const std::string& resource, const StanzaExtensionList& exts )
00143 {
00144 if( m_resources.find( resource ) == m_resources.end() )
00145 m_resources[resource] = new Resource( 0, EmptyString, Presence::Unavailable );
00146
00147 m_resources[resource]->setExtensions( exts );
00148 }
00149
00150 void RosterItem::removeResource( const std::string& resource )
00151 {
00152 ResourceMap::iterator it = m_resources.find( resource );
00153 if( it != m_resources.end() )
00154 {
00155 delete (*it).second;
00156 m_resources.erase( it );
00157 }
00158 }
00159
00160 bool RosterItem::online() const
00161 {
00162 return !m_resources.empty();
00163 }
00164
00165 const Resource* RosterItem::resource( const std::string& res ) const
00166 {
00167 ResourceMap::const_iterator it = m_resources.find( res );
00168 return it != m_resources.end() ? (*it).second : 0;
00169 }
00170
00171 void RosterItem::setData( const RosterItemData& rid )
00172 {
00173 delete m_data;
00174 m_data = new RosterItemData( rid );
00175 }
00176
00177 }