Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

rosteritemdata.h

00001 /*
00002   Copyright (c) 2004-2008 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 
00159       Tag* tag() const
00160       {
00161         Tag* i = new Tag( "item" );
00162         i->addAttribute( "jid", m_jid );
00163         if( m_remove )
00164           i->addAttribute( "subscription", "remove" );
00165         else
00166         {
00167           i->addAttribute( "name", m_name );
00168           StringList::const_iterator it = m_groups.begin();
00169           for( ; it != m_groups.end(); ++it )
00170             new Tag( i, "group", (*it) );
00171           i->addAttribute( "subscription", m_sub );
00172           i->addAttribute( "ask", m_ask );
00173         }
00174         return i;
00175       }
00176 
00177     protected:
00178       std::string m_jid;
00179       std::string m_name;
00180       StringList m_groups;
00181       SubscriptionType m_subscription;
00182       std::string m_sub;
00183       std::string m_ask;
00184       bool m_changed;
00185       bool m_remove;
00186 
00187   };
00188 
00189 }
00190 
00191 #endif // ROSTERITEMBASE_H__

Generated on Mon Nov 17 02:45:12 2008 for gloox by  doxygen 1.4.1