Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

rosteritem.cpp

00001 /*
00002   Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
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     // FIXME
00037     ResourceMap::iterator it = m_resources.begin();
00038     ResourceMap::iterator it2;
00039     while( it != m_resources.end() )
00040     {
00041       it2 = it++;
00042       delete (*it2).second;
00043       m_resources.erase( it2 );
00044     }
00045     // ~
00046   }
00047 
00048   void RosterItem::setName( const std::string& name )
00049   {
00050     if( m_data )
00051       m_data->setName( name );
00052   }
00053 
00054   const std::string& RosterItem::name() const
00055   {
00056     if( m_data )
00057       return m_data->name();
00058     else
00059       return EmptyString;
00060   }
00061 
00062   const std::string& RosterItem::jid() const
00063   {
00064     if( m_data )
00065       return m_data->jid();
00066     else
00067       return EmptyString;
00068   }
00069 
00070   void RosterItem::setSubscription( const std::string& subscription, const std::string& ask )
00071   {
00072     if( m_data )
00073       m_data->setSubscription( subscription, ask );
00074   }
00075 
00076   SubscriptionType RosterItem::subscription() const
00077   {
00078     if( m_data )
00079       return m_data->subscription();
00080     else
00081       return S10nNone;
00082   }
00083 
00084   void RosterItem::setGroups( const StringList& groups )
00085   {
00086     if( m_data )
00087       m_data->setGroups( groups );
00088   }
00089 
00090   const StringList RosterItem::groups() const
00091   {
00092     if( m_data )
00093       return m_data->groups();
00094     else
00095       return StringList();
00096   }
00097 
00098   bool RosterItem::changed() const
00099   {
00100     if( m_data )
00101       return m_data->changed();
00102     else
00103       return false;
00104   }
00105 
00106   void RosterItem::setSynchronized()
00107   {
00108     if( m_data )
00109       m_data->setSynchronized();
00110   }
00111 
00112   void RosterItem::setPresence( const std::string& resource, Presence::PresenceType presence )
00113   {
00114     if( m_resources.find( resource ) == m_resources.end() )
00115       m_resources[resource] = new Resource( 0, EmptyString, presence );
00116     else
00117       m_resources[resource]->setStatus( presence );
00118   }
00119 
00120   void RosterItem::setStatus( const std::string& resource, const std::string& msg )
00121   {
00122     if( m_resources.find( resource ) == m_resources.end() )
00123       m_resources[resource] = new Resource( 0, msg, Presence::Unavailable );
00124     else
00125       m_resources[resource]->setMessage( msg );
00126   }
00127 
00128   void RosterItem::setPriority( const std::string& resource, int priority )
00129   {
00130     if( m_resources.find( resource ) == m_resources.end() )
00131       m_resources[resource] = new Resource( priority, EmptyString, Presence::Unavailable );
00132     else
00133       m_resources[resource]->setPriority( priority );
00134   }
00135 
00136   void RosterItem::setExtensions( const std::string& resource, const StanzaExtensionList& exts )
00137   {
00138     if( m_resources.find( resource ) == m_resources.end() )
00139       m_resources[resource] = new Resource( 0, EmptyString, Presence::Unavailable );
00140 
00141     m_resources[resource]->setExtensions( exts );
00142   }
00143 
00144   void RosterItem::removeResource( const std::string& resource )
00145   {
00146     ResourceMap::iterator it = m_resources.find( resource );
00147     if( it != m_resources.end() )
00148     {
00149       delete (*it).second;
00150       m_resources.erase( it );
00151     }
00152   }
00153 
00154   bool RosterItem::online() const
00155   {
00156     return !m_resources.empty();
00157   }
00158 
00159   const Resource* RosterItem::resource( const std::string& res ) const
00160   {
00161     ResourceMap::const_iterator it = m_resources.find( res );
00162     return it != m_resources.end() ? (*it).second : 0;
00163   }
00164 
00165   void RosterItem::setData( const RosterItemData& rid )
00166   {
00167     delete m_data;
00168     m_data = new RosterItemData( rid );
00169   }
00170 
00171 }

Generated on Mon Nov 17 02:45:12 2008 for gloox by  doxygen 1.4.1