rosteritem.cpp
/*
Copyright (c) 2004-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "rosteritem.h"
#include "rosteritemdata.h"
#include "util.h"
namespace gloox
{
JID EmptyJID();
RosterItem::RosterItem( const std::string& jid, const std::string& name )
: m_data( new RosterItemData( JID( jid ), name, StringList() ) )
{
}
RosterItem::RosterItem( const RosterItemData& data )
: m_data( new RosterItemData( data ) )
{
}
RosterItem::~RosterItem()
{
delete m_data;
util::clearMap( m_resources );
}
void RosterItem::setName( const std::string& name )
{
if( m_data )
m_data->setName( name );
}
const std::string& RosterItem::name() const
{
if( m_data )
return m_data->name();
else
return EmptyString;
}
const JID& RosterItem::jidJID() const
{
if( m_data )
return m_data->jidJID();
else
return EmptyJID;
}
const std::string& RosterItem::jid() const
{
if( m_data )
return m_data->jid();
else
return EmptyString;
}
void RosterItem::setSubscription( const std::string& subscription, const std::string& ask )
{
if( m_data )
m_data->setSubscription( subscription, ask );
}
SubscriptionType RosterItem::subscription() const
{
if( m_data )
return m_data->subscription();
else
return S10nNone;
}
void RosterItem::setGroups( const StringList& groups )
{
if( m_data )
m_data->setGroups( groups );
}
const StringList RosterItem::groups() const
{
if( m_data )
return m_data->groups();
else
return StringList();
}
bool RosterItem::changed() const
{
if( m_data )
return m_data->changed();
else
return false;
}
void RosterItem::setSynchronized()
{
if( m_data )
m_data->setSynchronized();
}
void RosterItem::setPresence( const std::string& resource, Presence::PresenceType presence )
{
if( m_resources.find( resource ) == m_resources.end() )
m_resources[resource] = new Resource( 0, EmptyString, presence );
else
m_resources[resource]->setStatus( presence );
}
void RosterItem::setStatus( const std::string& resource, const std::string& msg )
{
if( m_resources.find( resource ) == m_resources.end() )
m_resources[resource] = new Resource( 0, msg, Presence::Unavailable );
else
m_resources[resource]->setMessage( msg );
}
void RosterItem::setPriority( const std::string& resource, int priority )
{
if( m_resources.find( resource ) == m_resources.end() )
m_resources[resource] = new Resource( priority, EmptyString, Presence::Unavailable );
else
m_resources[resource]->setPriority( priority );
}
const Resource* RosterItem::highestResource() const
{
int highestPriority = -255;
Resource* highestResource = 0;
ResourceMap::const_iterator it = m_resources.begin();
for( ; it != m_resources.end() ; ++it )
{
if( (*it).second->priority() > highestPriority )
{
highestPriority = (*it).second->priority();
highestResource = (*it).second;
}
}
return highestResource;
}
void RosterItem::setExtensions( const std::string& resource, const StanzaExtensionList& exts )
{
if( m_resources.find( resource ) == m_resources.end() )
m_resources[resource] = new Resource( 0, EmptyString, Presence::Unavailable );
m_resources[resource]->setExtensions( exts );
}
void RosterItem::removeResource( const std::string& resource )
{
ResourceMap::iterator it = m_resources.find( resource );
if( it != m_resources.end() )
{
delete (*it).second;
m_resources.erase( it );
}
}
bool RosterItem::online() const
{
return !m_resources.empty();
}
const Resource* RosterItem::resource( const std::string& res ) const
{
ResourceMap::const_iterator it = m_resources.find( res );
return it != m_resources.end() ? (*it).second : 0;
}
void RosterItem::setData( const RosterItemData& rid )
{
delete m_data;
m_data = new RosterItemData( rid );
}
}
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::Presence::PresenceType
PresenceType
Definition presence.h:43
gloox::Presence::Unavailable
@ Unavailable
Definition presence.h:49
gloox::Resource
Holds resource attributes.
Definition resource.h:36
gloox::RosterItemData
A class holding roster item data.
Definition rosteritemdata.h:37
gloox::RosterItem::EmptyJID
const JID EmptyJID
Definition rosteritem.h:53
gloox::RosterItem::RosterItem
RosterItem(const std::string &jid, const std::string &name=EmptyString)
Definition rosteritem.cpp:24
gloox::RosterItem::changed
bool changed() const
Definition rosteritem.cpp:98
gloox::RosterItem::setGroups
void setGroups(const StringList &groups)
Definition rosteritem.cpp:84
gloox::RosterItem::name
const std::string & name() const
Definition rosteritem.cpp:46
gloox::RosterItem::setSynchronized
void setSynchronized()
Definition rosteritem.cpp:106
gloox::RosterItem::subscription
SubscriptionType subscription() const
Definition rosteritem.cpp:76
gloox::RosterItem::highestResource
const Resource * highestResource() const
Definition rosteritem.cpp:136
gloox::RosterItem::setPriority
void setPriority(const std::string &resource, int priority)
Definition rosteritem.cpp:128
gloox::RosterItem::setData
void setData(const RosterItemData &rid)
Definition rosteritem.cpp:181
gloox::RosterItem::setSubscription
void setSubscription(const std::string &subscription, const std::string &ask)
Definition rosteritem.cpp:70
gloox::RosterItem::~RosterItem
virtual ~RosterItem()
Definition rosteritem.cpp:34
gloox::RosterItem::jidJID
const JID & jidJID() const
Definition rosteritem.cpp:54
gloox::RosterItem::setName
void setName(const std::string &name)
Definition rosteritem.cpp:40
gloox::RosterItem::resource
const Resource * resource(const std::string &res) const
Definition rosteritem.cpp:175
gloox::RosterItem::online
bool online() const
Definition rosteritem.cpp:170
gloox::RosterItem::groups
const StringList groups() const
Definition rosteritem.cpp:90
gloox::RosterItem::removeResource
void removeResource(const std::string &resource)
Definition rosteritem.cpp:160
gloox::RosterItem::setStatus
void setStatus(const std::string &resource, const std::string &msg)
Definition rosteritem.cpp:120
gloox::RosterItem::jid
GLOOX_DEPRECATED const std::string & jid() const
Definition rosteritem.cpp:62
gloox::RosterItem::setExtensions
void setExtensions(const std::string &resource, const StanzaExtensionList &exts)
Definition rosteritem.cpp:152
gloox::RosterItem::setPresence
void setPresence(const std::string &resource, Presence::PresenceType presence)
Definition rosteritem.cpp:112
gloox::util::clearMap
void clearMap(std::map< Key, T * > &M)
Definition util.h:169
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StanzaExtensionList
std::list< const StanzaExtension * > StanzaExtensionList
Definition gloox.h:1272
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::SubscriptionType
SubscriptionType
Definition gloox.h:1224
gloox::S10nNone
@ S10nNone
Definition gloox.h:1225