00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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 AnnotationsHandler::AnnotationsList& aList )
00033 {
00034 Tag *s = new Tag( "storage" );
00035 s->addAttribute( "xmlns", XMLNS_ANNOTATIONS );
00036
00037 if( aList.size() )
00038 {
00039 AnnotationsHandler::AnnotationsList::const_iterator it = aList.begin();
00040 for( ; it != aList.end(); ++it )
00041 {
00042 Tag *n = new Tag( s, "note", (*it).note );
00043 n->addAttribute( "jid", (*it).jid );
00044 n->addAttribute( "cdate", (*it).cdate );
00045 n->addAttribute( "mdate", (*it).mdate );
00046 }
00047 }
00048
00049 storeXML( s, this );
00050 }
00051
00052 void Annotations::requestAnnotations()
00053 {
00054 requestXML( "storage", XMLNS_ANNOTATIONS, this );
00055 }
00056
00057 void Annotations::handlePrivateXML( const std::string& , Tag *xml )
00058 {
00059 AnnotationsHandler::AnnotationsList aList;
00060 const Tag::TagList l = xml->children();
00061 Tag::TagList::const_iterator it = l.begin();
00062 for( ; it != l.end(); ++it )
00063 {
00064 if( (*it)->name() == "note" )
00065 {
00066 const std::string jid = (*it)->findAttribute( "jid" );
00067 const std::string mdate = (*it)->findAttribute( "mdate" );
00068 const std::string cdate = (*it)->findAttribute( "cdate" );
00069 const std::string note = (*it)->cdata();
00070
00071 if( !jid.empty() && !note.empty() )
00072 {
00073 AnnotationsHandler::annotationsListItem item;
00074 item.jid = jid;
00075 item.note = note;
00076 item.mdate = mdate;
00077 item.cdate = cdate;
00078 aList.push_back( item );
00079 }
00080 }
00081 }
00082
00083 if( m_annotationsHandler )
00084 m_annotationsHandler->handleAnnotations( aList );
00085 }
00086
00087 void Annotations::handlePrivateXMLResult( const std::string& , PrivateXMLResult )
00088 {
00089 }
00090
00091 void Annotations::registerAnnotationsHandler( AnnotationsHandler *ah )
00092 {
00093 m_annotationsHandler = ah;
00094 }
00095
00096 void Annotations::removeAnnotationsHandler()
00097 {
00098 m_annotationsHandler = 0;
00099 }
00100
00101 }