annotations.cpp

00001 /*
00002   Copyright (c) 2005-2007 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" );
00035     s->addAttribute( "xmlns", XMLNS_ANNOTATIONS );
00036 
00037     if( aList.size() )
00038     {
00039       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*/, Tag *xml )
00058   {
00059     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& note = (*it)->cdata();
00068 
00069         if( !jid.empty() && !note.empty() )
00070         {
00071           const std::string& cdate = (*it)->findAttribute( "cdate" );
00072           const std::string& mdate = (*it)->findAttribute( "mdate" );
00073           AnnotationsListItem item;
00074           item.jid = jid;
00075           item.cdate = cdate;
00076           item.mdate = mdate;
00077           item.note = note;
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& /*uid*/, PrivateXMLResult /*result*/ )
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 }

Generated on Sat Nov 10 08:50:26 2007 for gloox by  doxygen 1.5.3-20071008