gloox  0.9.9.12
annotations.cpp
1 /*
2  Copyright (c) 2005-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #include "annotations.h"
16 #include "clientbase.h"
17 
18 
19 namespace gloox
20 {
21 
23  : PrivateXML( parent ),
24  m_annotationsHandler( 0 )
25  {
26  }
27 
29  {
30  }
31 
33  {
34  Tag *s = new Tag( "storage" );
35  s->addAttribute( "xmlns", XMLNS_ANNOTATIONS );
36 
37  if( aList.size() )
38  {
39  AnnotationsList::const_iterator it = aList.begin();
40  for( ; it != aList.end(); ++it )
41  {
42  Tag *n = new Tag( s, "note", (*it).note );
43  n->addAttribute( "jid", (*it).jid );
44  n->addAttribute( "cdate", (*it).cdate );
45  n->addAttribute( "mdate", (*it).mdate );
46  }
47  }
48 
49  storeXML( s, this );
50  }
51 
53  {
54  requestXML( "storage", XMLNS_ANNOTATIONS, this );
55  }
56 
57  void Annotations::handlePrivateXML( const std::string& /*tag*/, Tag *xml )
58  {
59  AnnotationsList aList;
60  const Tag::TagList& l = xml->children();
61  Tag::TagList::const_iterator it = l.begin();
62  for( ; it != l.end(); ++it )
63  {
64  if( (*it)->name() == "note" )
65  {
66  const std::string& jid = (*it)->findAttribute( "jid" );
67  const std::string& note = (*it)->cdata();
68 
69  if( !jid.empty() && !note.empty() )
70  {
71  const std::string& cdate = (*it)->findAttribute( "cdate" );
72  const std::string& mdate = (*it)->findAttribute( "mdate" );
74  item.jid = jid;
75  item.cdate = cdate;
76  item.mdate = mdate;
77  item.note = note;
78  aList.push_back( item );
79  }
80  }
81  }
82 
83  if( m_annotationsHandler )
84  m_annotationsHandler->handleAnnotations( aList );
85  }
86 
87  void Annotations::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
88  {
89  }
90 
92  {
93  m_annotationsHandler = ah;
94  }
95 
97  {
98  m_annotationsHandler = 0;
99  }
100 
101 }