rosteritemdata.h
/*
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.
*/
#ifndef ROSTERITEMBASE_H__
#define ROSTERITEMBASE_H__
#include "gloox.h"
#include "jid.h"
#include "tag.h"
#include <string>
#include <list>
namespace gloox
{
class GLOOX_API RosterItemData
{
public:
RosterItemData( const JID& jid, const std::string& name,
const StringList& groups )
: m_jid( jid.full() ), m_jidJID( jid ), m_name( name ), m_groups( groups ),
m_subscription( S10nNone ), m_changed( false ), m_remove( false )
{}
RosterItemData( const JID& jid )
: m_jid( jid.full() ), m_jidJID( jid ), m_subscription( S10nNone ), m_changed( false ),
m_remove( true )
{}
RosterItemData( const RosterItemData& right )
: m_jid( right.m_jid ), m_jidJID( right.m_jidJID ), m_name( right.m_name ),
m_groups( right.m_groups ), m_subscription( right.m_subscription ),
m_changed( right.m_changed ), m_remove( right.m_remove )
{}
GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid, const std::string& name,
const StringList& groups )
: m_jid( jid ), m_jidJID( jid), m_name( name ), m_groups( groups ),
m_subscription( S10nNone ), m_changed( false ), m_remove( false )
{}
GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid )
: m_jid( jid ), m_jidJID( jid), m_subscription( S10nNone ), m_changed( false ),
m_remove( true )
{}
virtual ~RosterItemData() {}
GLOOX_DEPRECATED const std::string& jid() const { return m_jid; }
const JID& jidJID() const { return m_jidJID; }
void setName( const std::string& name )
{
m_name = name;
m_changed = true;
}
const std::string& name() const { return m_name; }
void setSubscription( const std::string& subscription, const std::string& ask )
{
m_sub = subscription.empty() ? "none" : subscription;
m_ask = ask;
if( m_sub == "from" && ask.empty() )
m_subscription = S10nFrom;
else if( m_sub == "from" && !ask.empty() )
m_subscription = S10nFromOut;
else if( m_sub == "to" && ask.empty() )
m_subscription = S10nTo;
else if( m_sub == "to" && !ask.empty() )
m_subscription = S10nToIn;
else if( m_sub == "none" && ask.empty() )
m_subscription = S10nNone;
else if( m_sub == "none" && !ask.empty() )
m_subscription = S10nNoneOut;
else if( m_sub == "both" )
m_subscription = S10nBoth;
}
SubscriptionType subscription() const { return m_subscription; }
void setGroups( const StringList& groups )
{
m_groups = groups;
m_changed = true;
}
const StringList& groups() const { return m_groups; }
bool changed() const { return m_changed; }
bool remove() const { return m_remove; }
void setSynchronized() { m_changed = false; }
Tag* tag() const
{
Tag* i = new Tag( "item" );
i->addAttribute( "jid", m_jidJID.full() );
if( m_remove )
i->addAttribute( "subscription", "remove" );
else
{
i->addAttribute( "name", m_name );
StringList::const_iterator it = m_groups.begin();
for( ; it != m_groups.end(); ++it )
new Tag( i, "group", (*it) );
i->addAttribute( "subscription", m_sub );
i->addAttribute( "ask", m_ask );
}
return i;
}
protected:
GLOOX_DEPRECATED std::string m_jid;
JID m_jidJID;
std::string m_name;
StringList m_groups;
SubscriptionType m_subscription;
std::string m_sub;
std::string m_ask;
bool m_changed;
bool m_remove;
};
}
#endif // ROSTERITEMBASE_H__
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::RosterItemData::RosterItemData
RosterItemData(const JID &jid)
Definition rosteritemdata.h:56
gloox::RosterItemData::m_jid
GLOOX_DEPRECATED std::string m_jid
Definition rosteritemdata.h:218
gloox::RosterItemData::RosterItemData
RosterItemData(const JID &jid, const std::string &name, const StringList &groups)
Definition rosteritemdata.h:46
gloox::RosterItemData::changed
bool changed() const
Definition rosteritemdata.h:181
gloox::RosterItemData::setGroups
void setGroups(const StringList &groups)
Definition rosteritemdata.h:165
gloox::RosterItemData::name
const std::string & name() const
Definition rosteritemdata.h:127
gloox::RosterItemData::setSynchronized
void setSynchronized()
Definition rosteritemdata.h:193
gloox::RosterItemData::subscription
SubscriptionType subscription() const
Definition rosteritemdata.h:159
gloox::RosterItemData::jid
GLOOX_DEPRECATED const std::string & jid() const
Definition rosteritemdata.h:104
gloox::RosterItemData::RosterItemData
RosterItemData(const RosterItemData &right)
Definition rosteritemdata.h:65
gloox::RosterItemData::setSubscription
void setSubscription(const std::string &subscription, const std::string &ask)
Definition rosteritemdata.h:134
gloox::RosterItemData::jidJID
const JID & jidJID() const
Definition rosteritemdata.h:111
gloox::RosterItemData::setName
void setName(const std::string &name)
Definition rosteritemdata.h:117
gloox::RosterItemData::m_jidJID
JID m_jidJID
Definition rosteritemdata.h:219
gloox::RosterItemData::~RosterItemData
virtual ~RosterItemData()
Definition rosteritemdata.h:97
gloox::RosterItemData::RosterItemData
GLOOX_DEPRECATED_CTOR RosterItemData(const std::string &jid, const std::string &name, const StringList &groups)
Definition rosteritemdata.h:78
gloox::RosterItemData::remove
bool remove() const
Definition rosteritemdata.h:188
gloox::RosterItemData::RosterItemData
GLOOX_DEPRECATED_CTOR RosterItemData(const std::string &jid)
Definition rosteritemdata.h:89
gloox::RosterItemData::tag
Tag * tag() const
Definition rosteritemdata.h:199
gloox::RosterItemData::groups
const StringList & groups() const
Definition rosteritemdata.h:175
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::SubscriptionType
SubscriptionType
Definition gloox.h:1224
gloox::S10nFromOut
@ S10nFromOut
Definition gloox.h:1243
gloox::S10nNone
@ S10nNone
Definition gloox.h:1225
gloox::S10nToIn
@ S10nToIn
Definition gloox.h:1240
gloox::S10nFrom
@ S10nFrom
Definition gloox.h:1242
gloox::S10nBoth
@ S10nBoth
Definition gloox.h:1245
gloox::S10nNoneOut
@ S10nNoneOut
Definition gloox.h:1227
gloox::S10nTo
@ S10nTo
Definition gloox.h:1239