gloox
1.0
|
00001 /* 00002 Copyright (c) 2004-2009 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 #ifndef ROSTERITEMBASE_H__ 00015 #define ROSTERITEMBASE_H__ 00016 00017 #include "gloox.h" 00018 #include "jid.h" 00019 #include "tag.h" 00020 00021 #include <string> 00022 #include <list> 00023 00024 00025 namespace gloox 00026 { 00027 00036 class GLOOX_API RosterItemData 00037 { 00038 00039 public: 00046 RosterItemData( const std::string& jid, const std::string& name, 00047 const StringList& groups ) 00048 : m_jid( jid ), m_name( name ), m_groups( groups ), 00049 m_subscription( S10nNone ), m_changed( false ), m_remove( false ) 00050 {} 00051 00056 RosterItemData( const std::string& jid ) 00057 : m_jid( jid ), m_subscription( S10nNone ), m_changed( false ), 00058 m_remove( true ) 00059 {} 00060 00064 virtual ~RosterItemData() {} 00065 00070 const std::string& jid() const { return m_jid; } 00071 00076 void setName( const std::string& name ) 00077 { 00078 m_name = name; 00079 m_changed = true; 00080 } 00081 00086 const std::string& name() const { return m_name; } 00087 00093 void setSubscription( const std::string& subscription, const std::string& ask ) 00094 { 00095 m_sub = subscription; 00096 m_ask = ask; 00097 00098 if( subscription == "from" && ask.empty() ) 00099 m_subscription = S10nFrom; 00100 else if( subscription == "from" && !ask.empty() ) 00101 m_subscription = S10nFromOut; 00102 else if( subscription == "to" && ask.empty() ) 00103 m_subscription = S10nTo; 00104 else if( subscription == "to" && !ask.empty() ) 00105 m_subscription = S10nToIn; 00106 else if( subscription == "none" && ask.empty() ) 00107 m_subscription = S10nNone; 00108 else if( subscription == "none" && !ask.empty() ) 00109 m_subscription = S10nNoneOut; 00110 else if( subscription == "both" ) 00111 m_subscription = S10nBoth; 00112 } 00113 00118 SubscriptionType subscription() const { return m_subscription; } 00119 00124 void setGroups( const StringList& groups ) 00125 { 00126 m_groups = groups; 00127 m_changed = true; 00128 } 00129 00134 const StringList& groups() const { return m_groups; } 00135 00140 bool changed() const { return m_changed; } 00141 00147 bool remove() const { return m_remove; } 00148 00152 void setSynchronized() { m_changed = false; } 00153 00158 Tag* tag() const 00159 { 00160 Tag* i = new Tag( "item" ); 00161 i->addAttribute( "jid", m_jid ); 00162 if( m_remove ) 00163 i->addAttribute( "subscription", "remove" ); 00164 else 00165 { 00166 i->addAttribute( "name", m_name ); 00167 StringList::const_iterator it = m_groups.begin(); 00168 for( ; it != m_groups.end(); ++it ) 00169 new Tag( i, "group", (*it) ); 00170 i->addAttribute( "subscription", m_sub ); 00171 i->addAttribute( "ask", m_ask ); 00172 } 00173 return i; 00174 } 00175 00176 protected: 00177 std::string m_jid; 00178 std::string m_name; 00179 StringList m_groups; 00180 SubscriptionType m_subscription; 00181 std::string m_sub; 00182 std::string m_ask; 00183 bool m_changed; 00184 bool m_remove; 00185 00186 }; 00187 00188 } 00189 00190 #endif // ROSTERITEMBASE_H__