gloox  1.0
rosteritemdata.h
1 /*
2  Copyright (c) 2004-2009 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 std::string& jid, const std::string& name,
47  const StringList& groups )
48  : m_jid( jid ), m_name( name ), m_groups( groups ),
49  m_subscription( S10nNone ), m_changed( false ), m_remove( false )
50  {}
51 
56  RosterItemData( const std::string& jid )
57  : m_jid( jid ), m_subscription( S10nNone ), m_changed( false ),
58  m_remove( true )
59  {}
60 
64  virtual ~RosterItemData() {}
65 
70  const std::string& jid() const { return m_jid; }
71 
76  void setName( const std::string& name )
77  {
78  m_name = name;
79  m_changed = true;
80  }
81 
86  const std::string& name() const { return m_name; }
87 
93  void setSubscription( const std::string& subscription, const std::string& ask )
94  {
95  m_sub = subscription;
96  m_ask = ask;
97 
98  if( subscription == "from" && ask.empty() )
99  m_subscription = S10nFrom;
100  else if( subscription == "from" && !ask.empty() )
101  m_subscription = S10nFromOut;
102  else if( subscription == "to" && ask.empty() )
103  m_subscription = S10nTo;
104  else if( subscription == "to" && !ask.empty() )
105  m_subscription = S10nToIn;
106  else if( subscription == "none" && ask.empty() )
107  m_subscription = S10nNone;
108  else if( subscription == "none" && !ask.empty() )
109  m_subscription = S10nNoneOut;
110  else if( subscription == "both" )
111  m_subscription = S10nBoth;
112  }
113 
118  SubscriptionType subscription() const { return m_subscription; }
119 
124  void setGroups( const StringList& groups )
125  {
126  m_groups = groups;
127  m_changed = true;
128  }
129 
134  const StringList& groups() const { return m_groups; }
135 
140  bool changed() const { return m_changed; }
141 
147  bool remove() const { return m_remove; }
148 
152  void setSynchronized() { m_changed = false; }
153 
158  Tag* tag() const
159  {
160  Tag* i = new Tag( "item" );
161  i->addAttribute( "jid", m_jid );
162  if( m_remove )
163  i->addAttribute( "subscription", "remove" );
164  else
165  {
166  i->addAttribute( "name", m_name );
167  StringList::const_iterator it = m_groups.begin();
168  for( ; it != m_groups.end(); ++it )
169  new Tag( i, "group", (*it) );
170  i->addAttribute( "subscription", m_sub );
171  i->addAttribute( "ask", m_ask );
172  }
173  return i;
174  }
175 
176  protected:
177  std::string m_jid;
178  std::string m_name;
179  StringList m_groups;
180  SubscriptionType m_subscription;
181  std::string m_sub;
182  std::string m_ask;
183  bool m_changed;
184  bool m_remove;
185 
186  };
187 
188 }
189 
190 #endif // ROSTERITEMBASE_H__