annotations.cpp

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

Generated on Mon Jan 16 16:19:54 2006 for gloox by  doxygen 1.4.6