QXmppEntityTimeIq.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "QXmppEntityTimeIq.h"
  24. #include <QDomElement>
  25. #include "QXmppConstants.h"
  26. #include "QXmppUtils.h"
  27. /// Returns the timezone offset in seconds.
  28. ///
  29. int QXmppEntityTimeIq::tzo() const
  30. {
  31. return m_tzo;
  32. }
  33. /// Sets the timezone offset in seconds.
  34. ///
  35. /// \param tzo
  36. void QXmppEntityTimeIq::setTzo(int tzo)
  37. {
  38. m_tzo = tzo;
  39. }
  40. /// Returns the date/time in Coordinated Universal Time (UTC).
  41. ///
  42. QDateTime QXmppEntityTimeIq::utc() const
  43. {
  44. return m_utc;
  45. }
  46. /// Sets the date/time in Coordinated Universal Time (UTC).
  47. ///
  48. /// \param utc
  49. void QXmppEntityTimeIq::setUtc(const QDateTime &utc)
  50. {
  51. m_utc = utc;
  52. }
  53. /// \cond
  54. bool QXmppEntityTimeIq::isEntityTimeIq(const QDomElement &element)
  55. {
  56. QDomElement timeElement = element.firstChildElement("time");
  57. return timeElement.namespaceURI() == ns_entity_time;
  58. }
  59. void QXmppEntityTimeIq::parseElementFromChild(const QDomElement &element)
  60. {
  61. QDomElement timeElement = element.firstChildElement("time");
  62. m_tzo = QXmppUtils::timezoneOffsetFromString(timeElement.firstChildElement("tzo").text());
  63. m_utc = QXmppUtils::datetimeFromString(timeElement.firstChildElement("utc").text());
  64. }
  65. void QXmppEntityTimeIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  66. {
  67. writer->writeStartElement("time");
  68. writer->writeAttribute("xmlns", ns_entity_time);
  69. if(m_utc.isValid())
  70. {
  71. helperToXmlAddTextElement(writer, "tzo", QXmppUtils::timezoneOffsetToString(m_tzo));
  72. helperToXmlAddTextElement(writer, "utc", QXmppUtils::datetimeToString(m_utc));
  73. }
  74. writer->writeEndElement();
  75. }
  76. /// \endcond