Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

bookmarkstorage.cpp

00001 /*
00002   Copyright (c) 2005-2008 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 "bookmarkstorage.h"
00016 #include "clientbase.h"
00017 
00018 
00019 namespace gloox
00020 {
00021 
00022   BookmarkStorage::BookmarkStorage( ClientBase* parent )
00023     : PrivateXML( parent ),
00024       m_bookmarkHandler( 0 )
00025   {
00026   }
00027 
00028   BookmarkStorage::~BookmarkStorage()
00029   {
00030   }
00031 
00032   void BookmarkStorage::storeBookmarks( const BookmarkList& bList, const ConferenceList& cList )
00033   {
00034     Tag* s = new Tag( "storage" );
00035     s->addAttribute( XMLNS, XMLNS_BOOKMARKS );
00036 
00037     BookmarkList::const_iterator itb = bList.begin();
00038     for( ; itb != bList.end(); ++itb )
00039     {
00040       Tag* i = new Tag( s, "url", "name", (*itb).name );
00041       i->addAttribute( "url", (*itb).url );
00042     }
00043 
00044     ConferenceList::const_iterator itc = cList.begin();
00045     for( ; itc != cList.end(); ++itc )
00046     {
00047       Tag* i = new Tag( s, "conference", "name", (*itc).name );
00048       i->addAttribute( "jid", (*itc).jid );
00049       i->addAttribute( "autojoin", (*itc).autojoin ? "true" : "false" );
00050 
00051       new Tag( i, "nick", (*itc).nick );
00052       new Tag( i, "password", (*itc).password );
00053     }
00054 
00055     storeXML( s, this );
00056   }
00057 
00058   void BookmarkStorage::requestBookmarks()
00059   {
00060     requestXML( "storage", XMLNS_BOOKMARKS, this );
00061   }
00062 
00063   void BookmarkStorage::handlePrivateXML( const Tag* xml )
00064   {
00065     BookmarkList bList;
00066     ConferenceList cList;
00067     const TagList& l = xml->children();
00068     TagList::const_iterator it = l.begin();
00069     for( ; it != l.end(); ++it )
00070     {
00071       if( (*it)->name() == "url" )
00072       {
00073         const std::string& url = (*it)->findAttribute( "url" );
00074         const std::string& name = (*it)->findAttribute( "name" );
00075 
00076         if( !url.empty() && !name.empty() )
00077         {
00078           BookmarkListItem item;
00079           item.url = url;
00080           item.name = name;
00081           bList.push_back( item );
00082         }
00083       }
00084       else if( (*it)->name() == "conference" )
00085       {
00086         const std::string& jid = (*it)->findAttribute( "jid" );
00087         const std::string& name = (*it)->findAttribute( "name" );
00088 
00089         if( !jid.empty() && !name.empty() )
00090         {
00091           const std::string& join = (*it)->findAttribute( "autojoin" );
00092           ConferenceListItem item;
00093           item.jid = jid;
00094           item.name = name;
00095           const Tag* nick = (*it)->findChild( "nick" );
00096           if( nick )
00097             item.nick = nick->cdata();
00098           const Tag* pwd = (*it)->findChild( "password" );
00099           if( pwd )
00100             item.password = pwd->cdata();
00101           item.autojoin = ( join == "true" || join == "1" );
00102           cList.push_back( item );
00103         }
00104       }
00105     }
00106 
00107     if( m_bookmarkHandler )
00108       m_bookmarkHandler->handleBookmarks( bList, cList );
00109   }
00110 
00111   void BookmarkStorage::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
00112   {
00113   }
00114 
00115 }

Generated on Mon Oct 13 10:45:10 2008 for gloox by  doxygen 1.4.1