rosteritem.cpp

00001 /*
00002   Copyright (c) 2004-2006 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 
00017 namespace gloox
00018 {
00019 
00020   RosterItem::RosterItem( const JID& jid, const std::string& name )
00021     : m_subscription( S10N_NONE ), m_name( name ), m_jid( jid.bare() ), m_changed( false )
00022   {
00023   }
00024 
00025   RosterItem::~RosterItem()
00026   {
00027     ResourceMap::iterator it = m_resources.begin();
00028     for( ; it != m_resources.end(); ++it )
00029     {
00030       delete (*it).second;
00031       (*it).second = 0;
00032     }
00033   }
00034 
00035   void RosterItem::setName( const std::string& name )
00036   {
00037     m_name = name;
00038     m_changed = true;
00039   }
00040 
00041   void RosterItem::setStatus( const std::string& resource, Presence status )
00042   {
00043     if( m_resources.find( resource ) == m_resources.end() )
00044     {
00045       m_resources[resource] = new Resource( 0, std::string(),  status );
00046     }
00047     else
00048       m_resources[resource]->setStatus( status );
00049   }
00050 
00051   void RosterItem::setStatusMsg( const std::string& resource, const std::string& msg )
00052   {
00053     if( m_resources.find( resource ) == m_resources.end() )
00054     {
00055       m_resources[resource] = new Resource( 0, msg, PresenceUnavailable );
00056     }
00057     else
00058       m_resources[resource]->setMessage( msg );
00059   }
00060 
00061   void RosterItem::setPriority( const std::string& resource, int priority )
00062   {
00063     if( m_resources.find( resource ) == m_resources.end() )
00064     {
00065       m_resources[resource] = new Resource( priority, std::string(), PresenceUnavailable );
00066     }
00067     else
00068       m_resources[resource]->setPriority( priority );
00069   }
00070 
00071   void RosterItem::setSubscription( const std::string& subscription, bool ask )
00072   {
00073     if( subscription == "from" && !ask )
00074       m_subscription = S10N_FROM;
00075     else if( subscription == "from" && ask )
00076       m_subscription = S10N_FROM_OUT;
00077     else if( subscription == "to" && !ask )
00078       m_subscription = S10N_TO;
00079     else if( subscription == "to" && ask )
00080       m_subscription = S10N_TO_IN;
00081     else if( subscription == "none" && !ask )
00082       m_subscription = S10N_NONE;
00083     else if( subscription == "none" && ask )
00084       m_subscription = S10N_NONE_OUT;
00085     else if( subscription == "both" )
00086       m_subscription = S10N_BOTH;
00087   }
00088 
00089   void RosterItem::setGroups( const StringList& groups )
00090   {
00091     m_groups = groups;
00092     m_changed = true;
00093   }
00094 
00095   void RosterItem::removeResource( const std::string& resource )
00096   {
00097     ResourceMap::iterator it = m_resources.find( resource );
00098     if( it != m_resources.end() )
00099     {
00100       delete (*it).second;
00101       m_resources.erase( it );
00102     }
00103   }
00104 
00105   bool RosterItem::online() const
00106   {
00107     if( m_resources.size() )
00108       return true;
00109     else
00110       return false;
00111   }
00112 }

Generated on Tue May 1 14:20:20 2007 for gloox by  doxygen 1.5.1