QXmppVCardManager.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Manjeet Dahiya
  6. *
  7. * Source:
  8. * http://code.google.com/p/qxmpp
  9. *
  10. * This file is a part of QXmpp library.
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. */
  23. #include "QXmppClient.h"
  24. #include "QXmppConstants.h"
  25. #include "QXmppUtils.h"
  26. #include "QXmppVCardIq.h"
  27. #include "QXmppVCardManager.h"
  28. class QXmppVCardManagerPrivate
  29. {
  30. public:
  31. QXmppVCardIq clientVCard;
  32. bool isClientVCardReceived;
  33. };
  34. QXmppVCardManager::QXmppVCardManager()
  35. : d(new QXmppVCardManagerPrivate)
  36. {
  37. d->isClientVCardReceived = false;
  38. }
  39. QXmppVCardManager::~QXmppVCardManager()
  40. {
  41. delete d;
  42. }
  43. /// This function requests the server for vCard of the specified jid.
  44. /// Once received the signal vCardReceived() is emitted.
  45. ///
  46. /// \param jid Jid of the specific entry in the roster
  47. ///
  48. QString QXmppVCardManager::requestVCard(const QString& jid)
  49. {
  50. QXmppVCardIq request(jid);
  51. if(client()->sendPacket(request))
  52. return request.id();
  53. else
  54. return QString();
  55. }
  56. /// Returns the vCard of the connected client.
  57. ///
  58. /// \return QXmppVCard
  59. ///
  60. const QXmppVCardIq& QXmppVCardManager::clientVCard() const
  61. {
  62. return d->clientVCard;
  63. }
  64. /// Sets the vCard of the connected client.
  65. ///
  66. /// \param clientVCard QXmppVCard
  67. ///
  68. void QXmppVCardManager::setClientVCard(const QXmppVCardIq& clientVCard)
  69. {
  70. d->clientVCard = clientVCard;
  71. d->clientVCard.setTo("");
  72. d->clientVCard.setFrom("");
  73. d->clientVCard.setType(QXmppIq::Set);
  74. client()->sendPacket(d->clientVCard);
  75. }
  76. /// This function requests the server for vCard of the connected user itself.
  77. /// Once received the signal clientVCardReceived() is emitted. Received vCard
  78. /// can be get using clientVCard().
  79. QString QXmppVCardManager::requestClientVCard()
  80. {
  81. return requestVCard();
  82. }
  83. /// Returns true if vCard of the connected client has been
  84. /// received else false.
  85. ///
  86. /// \return bool
  87. ///
  88. bool QXmppVCardManager::isClientVCardReceived() const
  89. {
  90. return d->isClientVCardReceived;
  91. }
  92. /// \cond
  93. QStringList QXmppVCardManager::discoveryFeatures() const
  94. {
  95. // XEP-0054: vcard-temp
  96. return QStringList() << ns_vcard;
  97. }
  98. bool QXmppVCardManager::handleStanza(const QDomElement &element)
  99. {
  100. if(element.tagName() == "iq" && QXmppVCardIq::isVCard(element))
  101. {
  102. QXmppVCardIq vCardIq;
  103. vCardIq.parse(element);
  104. if (vCardIq.from().isEmpty()) {
  105. d->clientVCard = vCardIq;
  106. d->isClientVCardReceived = true;
  107. emit clientVCardReceived();
  108. }
  109. emit vCardReceived(vCardIq);
  110. return true;
  111. }
  112. return false;
  113. }
  114. /// \endcond