gloox
1.0
|
00001 /* 00002 Copyright (c) 2005-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 00015 #include "annotations.h" 00016 #include "clientbase.h" 00017 00018 00019 namespace gloox 00020 { 00021 00022 Annotations::Annotations( ClientBase* parent ) 00023 : PrivateXML( parent ), 00024 m_annotationsHandler( 0 ) 00025 { 00026 } 00027 00028 Annotations::~Annotations() 00029 { 00030 } 00031 00032 void Annotations::storeAnnotations( const AnnotationsList& aList ) 00033 { 00034 Tag* s = new Tag( "storage", XMLNS, XMLNS_ANNOTATIONS ); 00035 00036 AnnotationsList::const_iterator it = aList.begin(); 00037 for( ; it != aList.end(); ++it ) 00038 { 00039 Tag* n = new Tag( s, "note", (*it).note ); 00040 n->addAttribute( "jid", (*it).jid ); 00041 n->addAttribute( "cdate", (*it).cdate ); 00042 n->addAttribute( "mdate", (*it).mdate ); 00043 } 00044 00045 storeXML( s, this ); 00046 } 00047 00048 void Annotations::requestAnnotations() 00049 { 00050 requestXML( "storage", XMLNS_ANNOTATIONS, this ); 00051 } 00052 00053 void Annotations::handlePrivateXML( const Tag* xml ) 00054 { 00055 if( !xml ) 00056 return; 00057 00058 AnnotationsList aList; 00059 const TagList& l = xml->children(); 00060 TagList::const_iterator it = l.begin(); 00061 for( ; it != l.end(); ++it ) 00062 { 00063 if( (*it)->name() == "note" ) 00064 { 00065 const std::string& jid = (*it)->findAttribute( "jid" ); 00066 const std::string& note = (*it)->cdata(); 00067 00068 if( !jid.empty() && !note.empty() ) 00069 { 00070 const std::string& cdate = (*it)->findAttribute( "cdate" ); 00071 const std::string& mdate = (*it)->findAttribute( "mdate" ); 00072 AnnotationsListItem item; 00073 item.jid = jid; 00074 item.cdate = cdate; 00075 item.mdate = mdate; 00076 item.note = note; 00077 aList.push_back( item ); 00078 } 00079 } 00080 } 00081 00082 if( m_annotationsHandler ) 00083 m_annotationsHandler->handleAnnotations( aList ); 00084 } 00085 00086 void Annotations::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ ) 00087 { 00088 } 00089 00090 }