gloox  1.0.16
vcardupdate.cpp
1 /*
2  Copyright (c) 2006-2015 by Jakob Schröter <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 ), m_hasPhoto( false )
23  {
24  }
25 
26  VCardUpdate::VCardUpdate( const std::string& hash )
28  m_hash( hash ), m_notReady( false ), m_noImage( false ), m_valid( true ), m_hasPhoto( false )
29  {
30  if( m_hash.empty() )
31  m_noImage = true;
32  }
33 
36  m_notReady( true ), m_noImage( true ), m_valid( false ), m_hasPhoto( false )
37  {
38  if( tag && tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_VCARD_UPDATE ) )
39  {
40  m_valid = true;
41  if( tag->hasChild( "photo" ) )
42  {
43  m_notReady = false;
44  if( tag->hasChild( "photo" ) )
45  m_hasPhoto = true;
46 
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 }
const std::string XMLNS
Definition: gloox.cpp:121
virtual const std::string & filterString() const
Definition: vcardupdate.cpp:58
bool setCData(const std::string &cdata)
Definition: tag.cpp:446
Tag * tag() const
Definition: vcardupdate.cpp:64
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
Definition: tag.cpp:601
const std::string cdata() const
Definition: tag.cpp:496
const std::string XMLNS_X_VCARD_UPDATE
Definition: gloox.cpp:57
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
Definition: tag.cpp:614
const std::string & name() const
Definition: tag.h:394
virtual ~VCardUpdate()
Definition: vcardupdate.cpp:54
Tag * findChild(const std::string &name) const
Definition: tag.cpp:623
This is an abstraction of an XML element.
Definition: tag.h:46