gloox  1.0
bookmarkstorage.cpp
1 /*
2  Copyright (c) 2005-2009 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 "bookmarkstorage.h"
16 #include "clientbase.h"
17 
18 
19 namespace gloox
20 {
21 
23  : PrivateXML( parent ),
24  m_bookmarkHandler( 0 )
25  {
26  }
27 
29  {
30  }
31 
32  void BookmarkStorage::storeBookmarks( const BookmarkList& bList, const ConferenceList& cList )
33  {
34  Tag* s = new Tag( "storage" );
36 
37  BookmarkList::const_iterator itb = bList.begin();
38  for( ; itb != bList.end(); ++itb )
39  {
40  Tag* i = new Tag( s, "url", "name", (*itb).name );
41  i->addAttribute( "url", (*itb).url );
42  }
43 
44  ConferenceList::const_iterator itc = cList.begin();
45  for( ; itc != cList.end(); ++itc )
46  {
47  Tag* i = new Tag( s, "conference", "name", (*itc).name );
48  i->addAttribute( "jid", (*itc).jid );
49  i->addAttribute( "autojoin", (*itc).autojoin ? "true" : "false" );
50 
51  new Tag( i, "nick", (*itc).nick );
52  new Tag( i, "password", (*itc).password );
53  }
54 
55  storeXML( s, this );
56  }
57 
59  {
60  requestXML( "storage", XMLNS_BOOKMARKS, this );
61  }
62 
64  {
65  if( !xml )
66  return;
67 
68  BookmarkList bList;
69  ConferenceList cList;
70  const TagList& l = xml->children();
71  TagList::const_iterator it = l.begin();
72  for( ; it != l.end(); ++it )
73  {
74  if( (*it)->name() == "url" )
75  {
76  const std::string& url = (*it)->findAttribute( "url" );
77  const std::string& name = (*it)->findAttribute( "name" );
78 
79  if( !url.empty() && !name.empty() )
80  {
81  BookmarkListItem item;
82  item.url = url;
83  item.name = name;
84  bList.push_back( item );
85  }
86  }
87  else if( (*it)->name() == "conference" )
88  {
89  const std::string& jid = (*it)->findAttribute( "jid" );
90  const std::string& name = (*it)->findAttribute( "name" );
91 
92  if( !jid.empty() && !name.empty() )
93  {
94  const std::string& join = (*it)->findAttribute( "autojoin" );
95  ConferenceListItem item;
96  item.jid = jid;
97  item.name = name;
98  const Tag* nick = (*it)->findChild( "nick" );
99  if( nick )
100  item.nick = nick->cdata();
101  const Tag* pwd = (*it)->findChild( "password" );
102  if( pwd )
103  item.password = pwd->cdata();
104  item.autojoin = ( join == "true" || join == "1" );
105  cList.push_back( item );
106  }
107  }
108  }
109 
110  if( m_bookmarkHandler )
111  m_bookmarkHandler->handleBookmarks( bList, cList );
112  }
113 
114  void BookmarkStorage::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
115  {
116  }
117 
118 }