vcardupdate.cpp

00001 /*
00002   Copyright (c) 2006-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 #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( 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   Tag* VCardUpdate::tag() const
00059   {
00060     if( !m_valid )
00061       return 0;
00062 
00063     Tag *x = new Tag( "x" );
00064     x->addAttribute( "xmlns", XMLNS_X_VCARD_UPDATE );
00065     if( m_notReady )
00066       return x;
00067 
00068     Tag *p = new Tag( x, "photo" );
00069     if( m_noImage )
00070       return x;
00071 
00072     p->setCData( m_hash );
00073 
00074     return x;
00075   }
00076 
00077 }

Generated on Sun Apr 27 11:08:14 2008 for gloox by  doxygen 1.5.5