QXmppVersionIq.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Jeremy Lainé
  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 <QDomElement>
  24. #include "QXmppConstants.h"
  25. #include "QXmppUtils.h"
  26. #include "QXmppVersionIq.h"
  27. /// Returns the name of the software.
  28. ///
  29. QString QXmppVersionIq::name() const
  30. {
  31. return m_name;
  32. }
  33. /// Sets the name of the software.
  34. ///
  35. /// \param name
  36. void QXmppVersionIq::setName(const QString &name)
  37. {
  38. m_name = name;
  39. }
  40. /// Returns the operating system.
  41. ///
  42. QString QXmppVersionIq::os() const
  43. {
  44. return m_os;
  45. }
  46. /// Sets the operating system.
  47. ///
  48. /// \param os
  49. void QXmppVersionIq::setOs(const QString &os)
  50. {
  51. m_os = os;
  52. }
  53. /// Returns the software version.
  54. ///
  55. QString QXmppVersionIq::version() const
  56. {
  57. return m_version;
  58. }
  59. /// Sets the software version.
  60. ///
  61. /// \param version
  62. void QXmppVersionIq::setVersion(const QString &version)
  63. {
  64. m_version = version;
  65. }
  66. /// \cond
  67. bool QXmppVersionIq::isVersionIq(const QDomElement &element)
  68. {
  69. QDomElement queryElement = element.firstChildElement("query");
  70. return queryElement.namespaceURI() == ns_version;
  71. }
  72. void QXmppVersionIq::parseElementFromChild(const QDomElement &element)
  73. {
  74. QDomElement queryElement = element.firstChildElement("query");
  75. m_name = queryElement.firstChildElement("name").text();
  76. m_os = queryElement.firstChildElement("os").text();
  77. m_version = queryElement.firstChildElement("version").text();
  78. }
  79. void QXmppVersionIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  80. {
  81. writer->writeStartElement("query");
  82. writer->writeAttribute("xmlns", ns_version);
  83. if (!m_name.isEmpty())
  84. helperToXmlAddTextElement(writer, "name", m_name);
  85. if (!m_os.isEmpty())
  86. helperToXmlAddTextElement(writer, "os", m_os);
  87. if (!m_version.isEmpty())
  88. helperToXmlAddTextElement(writer, "version", m_version);
  89. writer->writeEndElement();
  90. }
  91. /// \endcond