gloox  1.0.9
rosteritemdata.h
1 /*
2  Copyright (c) 2004-2013 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef ROSTERITEMBASE_H__
15 #define ROSTERITEMBASE_H__
16 
17 #include "gloox.h"
18 #include "jid.h"
19 #include "tag.h"
20 
21 #include <string>
22 #include <list>
23 
24 
25 namespace gloox
26 {
27 
36  class GLOOX_API RosterItemData
37  {
38 
39  public:
46  RosterItemData( const JID& jid, const std::string& name,
47  const StringList& groups )
48  : m_jid( jid.full() ), m_jidJID( jid ), m_name( name ), m_groups( groups ),
49  m_subscription( S10nNone ), m_changed( false ), m_remove( false )
50  {}
51 
56  RosterItemData( const JID& jid )
57  : m_jid( jid.full() ), m_jidJID( jid ), m_subscription( S10nNone ), m_changed( false ),
58  m_remove( true )
59  {}
60 
66  : m_jid( right.m_jid ), m_jidJID( right.m_jidJID ), m_name( right.m_name ),
67  m_groups( right.m_groups ), m_subscription( right.m_subscription ),
68  m_changed( right.m_changed ), m_remove( right.m_remove )
69  {}
70 
78  GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid, const std::string& name,
79  const StringList& groups )
80  : m_jid( jid ), m_jidJID( jid), m_name( name ), m_groups( groups ),
81  m_subscription( S10nNone ), m_changed( false ), m_remove( false )
82  {}
83 
89  GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid )
90  : m_jid( jid ), m_jidJID( jid), m_subscription( S10nNone ), m_changed( false ),
91  m_remove( true )
92  {}
93 
97  virtual ~RosterItemData() {}
98 
104  GLOOX_DEPRECATED const std::string& jid() const { return m_jid; }
105 
111  const JID& jidJID() const { return m_jidJID; }
112 
117  void setName( const std::string& name )
118  {
119  m_name = name;
120  m_changed = true;
121  }
122 
127  const std::string& name() const { return m_name; }
128 
134  void setSubscription( const std::string& subscription, const std::string& ask )
135  {
136  m_sub = subscription;
137  m_ask = ask;
138 
139  if( subscription == "from" && ask.empty() )
140  m_subscription = S10nFrom;
141  else if( subscription == "from" && !ask.empty() )
142  m_subscription = S10nFromOut;
143  else if( subscription == "to" && ask.empty() )
144  m_subscription = S10nTo;
145  else if( subscription == "to" && !ask.empty() )
146  m_subscription = S10nToIn;
147  else if( subscription == "none" && ask.empty() )
148  m_subscription = S10nNone;
149  else if( subscription == "none" && !ask.empty() )
150  m_subscription = S10nNoneOut;
151  else if( subscription == "both" )
152  m_subscription = S10nBoth;
153  }
154 
159  SubscriptionType subscription() const { return m_subscription; }
160 
165  void setGroups( const StringList& groups )
166  {
167  m_groups = groups;
168  m_changed = true;
169  }
170 
175  const StringList& groups() const { return m_groups; }
176 
181  bool changed() const { return m_changed; }
182 
188  bool remove() const { return m_remove; }
189 
193  void setSynchronized() { m_changed = false; }
194 
199  Tag* tag() const
200  {
201  Tag* i = new Tag( "item" );
202  i->addAttribute( "jid", m_jidJID.full() );
203  if( m_remove )
204  i->addAttribute( "subscription", "remove" );
205  else
206  {
207  i->addAttribute( "name", m_name );
208  StringList::const_iterator it = m_groups.begin();
209  for( ; it != m_groups.end(); ++it )
210  new Tag( i, "group", (*it) );
211  i->addAttribute( "subscription", m_sub );
212  i->addAttribute( "ask", m_ask );
213  }
214  return i;
215  }
216 
217  protected:
218  GLOOX_DEPRECATED std::string m_jid;
220  std::string m_name;
221  StringList m_groups;
222  SubscriptionType m_subscription;
223  std::string m_sub;
224  std::string m_ask;
225  bool m_changed;
226  bool m_remove;
227 
228  };
229 
230 }
231 
232 #endif // ROSTERITEMBASE_H__