gloox 1.0
|
00001 /* 00002 Copyright (c) 2007-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 #include "chatstate.h" 00014 #include "tag.h" 00015 #include "util.h" 00016 00017 namespace gloox 00018 { 00019 00020 /* chat state type values */ 00021 static const char* stateValues [] = { 00022 "active", 00023 "composing", 00024 "paused", 00025 "inactive", 00026 "gone" 00027 }; 00028 00029 static inline ChatStateType chatStateType( const std::string& type ) 00030 { 00031 return (ChatStateType)util::lookup2( type, stateValues ); 00032 } 00033 00034 ChatState::ChatState( const Tag* tag ) 00035 : StanzaExtension( ExtChatState ) 00036 { 00037 if( tag ) 00038 m_state = chatStateType( tag->name() ); 00039 } 00040 00041 const std::string& ChatState::filterString() const 00042 { 00043 static const std::string filter = 00044 "/message/active[@xmlns='" + XMLNS_CHAT_STATES + "']" 00045 "|/message/composing[@xmlns='" + XMLNS_CHAT_STATES + "']" 00046 "|/message/paused[@xmlns='" + XMLNS_CHAT_STATES + "']" 00047 "|/message/inactive[@xmlns='" + XMLNS_CHAT_STATES + "']" 00048 "|/message/gone[@xmlns='" + XMLNS_CHAT_STATES + "']"; 00049 return filter; 00050 } 00051 00052 Tag* ChatState::tag() const 00053 { 00054 if( m_state == ChatStateInvalid ) 00055 return 0; 00056 00057 return new Tag( util::lookup2( m_state, stateValues ), XMLNS, XMLNS_CHAT_STATES ); 00058 } 00059 00060 }