vcardupdate.cpp

00001 /*
00002   Copyright (c) 2006-2009 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 #include "vcardupdate.h"
00015 #include "tag.h"
00016 
00017 namespace gloox
00018 {
00019 
00020   VCardUpdate::VCardUpdate()
00021     : StanzaExtension( ExtVCardUpdate ),
00022       m_notReady( true ), m_noImage( true ), m_valid( true )
00023   {
00024   }
00025 
00026   VCardUpdate::VCardUpdate( const std::string& hash )
00027     : StanzaExtension( ExtVCardUpdate ),
00028       m_hash( hash ), m_notReady( false ), m_noImage( false ), m_valid( true )
00029   {
00030     if( m_hash.empty() )
00031     {
00032       m_noImage = true;
00033       m_valid = false;
00034     }
00035   }
00036 
00037   VCardUpdate::VCardUpdate( const Tag* tag )
00038     : StanzaExtension( ExtVCardUpdate ),
00039       m_notReady( true ), m_noImage( true ), m_valid( false )
00040   {
00041     if( tag && tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_VCARD_UPDATE ) )
00042     {
00043       m_valid = true;
00044       if( tag->hasChild( "photo" ) )
00045       {
00046         m_notReady = false;
00047         m_hash = tag->findChild( "photo" )->cdata();
00048         if( !m_hash.empty() )
00049           m_noImage = false;
00050       }
00051     }
00052   }
00053 
00054   VCardUpdate::~VCardUpdate()
00055   {
00056   }
00057 
00058   const std::string& VCardUpdate::filterString() const
00059   {
00060     static const std::string filter = "/presence/x[@xmlns='" + XMLNS_X_VCARD_UPDATE + "']";
00061     return filter;
00062   }
00063 
00064   Tag* VCardUpdate::tag() const
00065   {
00066     if( !m_valid )
00067       return 0;
00068 
00069     Tag* x = new Tag( "x", XMLNS, XMLNS_X_VCARD_UPDATE );
00070     if( !m_notReady )
00071     {
00072       Tag* p = new Tag( x, "photo" );
00073       if( !m_noImage )
00074         p->setCData( m_hash );
00075     }
00076     return x;
00077   }
00078 
00079 }

Generated by  doxygen 1.6.2