QXmppStreamInitiationIq.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "QXmppStreamInitiationIq_p.h"
  26. #include "QXmppUtils.h"
  27. QXmppDataForm QXmppStreamInitiationIq::featureForm() const
  28. {
  29. return m_featureForm;
  30. }
  31. void QXmppStreamInitiationIq::setFeatureForm(const QXmppDataForm &form)
  32. {
  33. m_featureForm = form;
  34. }
  35. QXmppTransferFileInfo QXmppStreamInitiationIq::fileInfo() const
  36. {
  37. return m_fileInfo;
  38. }
  39. void QXmppStreamInitiationIq::setFileInfo(const QXmppTransferFileInfo &fileInfo)
  40. {
  41. m_fileInfo = fileInfo;
  42. }
  43. QString QXmppStreamInitiationIq::mimeType() const
  44. {
  45. return m_mimeType;
  46. }
  47. void QXmppStreamInitiationIq::setMimeType(const QString &mimeType)
  48. {
  49. m_mimeType = mimeType;
  50. }
  51. QXmppStreamInitiationIq::Profile QXmppStreamInitiationIq::profile() const
  52. {
  53. return m_profile;
  54. }
  55. void QXmppStreamInitiationIq::setProfile(QXmppStreamInitiationIq::Profile profile)
  56. {
  57. m_profile = profile;
  58. }
  59. QString QXmppStreamInitiationIq::siId() const
  60. {
  61. return m_siId;
  62. }
  63. void QXmppStreamInitiationIq::setSiId(const QString &id)
  64. {
  65. m_siId = id;
  66. }
  67. /// \cond
  68. bool QXmppStreamInitiationIq::isStreamInitiationIq(const QDomElement &element)
  69. {
  70. QDomElement siElement = element.firstChildElement("si");
  71. return (siElement.namespaceURI() == ns_stream_initiation);
  72. }
  73. void QXmppStreamInitiationIq::parseElementFromChild(const QDomElement &element)
  74. {
  75. QDomElement siElement = element.firstChildElement("si");
  76. m_siId = siElement.attribute("id");
  77. m_mimeType = siElement.attribute("mime-type");
  78. if (siElement.attribute("profile") == ns_stream_initiation_file_transfer)
  79. m_profile = FileTransfer;
  80. else
  81. m_profile = None;
  82. QDomElement itemElement = siElement.firstChildElement();
  83. while (!itemElement.isNull())
  84. {
  85. if (itemElement.tagName() == "feature" && itemElement.namespaceURI() == ns_feature_negotiation) {
  86. m_featureForm.parse(itemElement.firstChildElement());
  87. } else if (itemElement.tagName() == "file" && itemElement.namespaceURI() == ns_stream_initiation_file_transfer) {
  88. m_fileInfo.parse(itemElement);
  89. }
  90. itemElement = itemElement.nextSiblingElement();
  91. }
  92. }
  93. void QXmppStreamInitiationIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  94. {
  95. writer->writeStartElement("si");
  96. writer->writeAttribute("xmlns", ns_stream_initiation);
  97. helperToXmlAddAttribute(writer, "id", m_siId);
  98. helperToXmlAddAttribute(writer, "mime-type", m_mimeType);
  99. if (m_profile == FileTransfer)
  100. helperToXmlAddAttribute(writer, "profile", ns_stream_initiation_file_transfer);
  101. if (!m_fileInfo.isNull())
  102. m_fileInfo.toXml(writer);
  103. if (!m_featureForm.isNull()) {
  104. writer->writeStartElement("feature");
  105. writer->writeAttribute("xmlns", ns_feature_negotiation);
  106. m_featureForm.toXml(writer);
  107. writer->writeEndElement();
  108. }
  109. writer->writeEndElement();
  110. }
  111. /// \endcond