gloox  1.0.1
vcardupdate.cpp
1 /*
2  Copyright (c) 2006-2012 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 #include "vcardupdate.h"
15 #include "tag.h"
16 
17 namespace gloox
18 {
19 
22  m_notReady( true ), m_noImage( true ), m_valid( true )
23  {
24  }
25 
26  VCardUpdate::VCardUpdate( const std::string& hash )
28  m_hash( hash ), m_notReady( false ), m_noImage( false ), m_valid( true )
29  {
30  if( m_hash.empty() )
31  {
32  m_noImage = true;
33  m_valid = false;
34  }
35  }
36 
39  m_notReady( true ), m_noImage( true ), m_valid( false )
40  {
41  if( tag && tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_VCARD_UPDATE ) )
42  {
43  m_valid = true;
44  if( tag->hasChild( "photo" ) )
45  {
46  m_notReady = false;
47  m_hash = tag->findChild( "photo" )->cdata();
48  if( !m_hash.empty() )
49  m_noImage = false;
50  }
51  }
52  }
53 
55  {
56  }
57 
58  const std::string& VCardUpdate::filterString() const
59  {
60  static const std::string filter = "/presence/x[@xmlns='" + XMLNS_X_VCARD_UPDATE + "']";
61  return filter;
62  }
63 
65  {
66  if( !m_valid )
67  return 0;
68 
69  Tag* x = new Tag( "x", XMLNS, XMLNS_X_VCARD_UPDATE );
70  if( !m_notReady )
71  {
72  Tag* p = new Tag( x, "photo" );
73  if( !m_noImage )
74  p->setCData( m_hash );
75  }
76  return x;
77  }
78 
79 }