QXmppArchiveManager.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "QXmppArchiveIq.h"
  25. #include "QXmppArchiveManager.h"
  26. #include "QXmppClient.h"
  27. #include "QXmppConstants.h"
  28. /// \cond
  29. QStringList QXmppArchiveManager::discoveryFeatures() const
  30. {
  31. // XEP-0036: Message Archiving
  32. return QStringList() << ns_archive;
  33. }
  34. bool QXmppArchiveManager::handleStanza(const QDomElement &element)
  35. {
  36. if (element.tagName() != "iq")
  37. return false;
  38. // XEP-0136: Message Archiving
  39. if(QXmppArchiveChatIq::isArchiveChatIq(element))
  40. {
  41. QXmppArchiveChatIq archiveIq;
  42. archiveIq.parse(element);
  43. emit archiveChatReceived(archiveIq.chat(), archiveIq.resultSetReply());
  44. return true;
  45. }
  46. else if(QXmppArchiveListIq::isArchiveListIq(element))
  47. {
  48. QXmppArchiveListIq archiveIq;
  49. archiveIq.parse(element);
  50. emit archiveListReceived(archiveIq.chats(), archiveIq.resultSetReply());
  51. return true;
  52. }
  53. else if(QXmppArchivePrefIq::isArchivePrefIq(element))
  54. {
  55. // TODO: handle preference iq
  56. QXmppArchivePrefIq archiveIq;
  57. archiveIq.parse(element);
  58. return true;
  59. }
  60. return false;
  61. }
  62. /// \endcond
  63. /// Retrieves the list of available collections. Once the results are
  64. /// received, the archiveListReceived() signal will be emitted.
  65. ///
  66. /// \param jid JID you want conversations with.
  67. /// \param start Optional start time.
  68. /// \param end Optional end time.
  69. /// \param rsm Optional Result Set Management query
  70. ///
  71. void QXmppArchiveManager::listCollections(const QString& jid, const QDateTime& start,
  72. const QDateTime& end, const QXmppResultSetQuery &rsm)
  73. {
  74. QXmppArchiveListIq packet;
  75. packet.setResultSetQuery(rsm);
  76. packet.setWith(jid);
  77. packet.setStart(start);
  78. packet.setEnd(end);
  79. client()->sendPacket(packet);
  80. }
  81. /// \overload
  82. /// Retrieves the list of available collections. Once the results are
  83. /// received, the archiveListReceived() signal will be emitted.
  84. ///
  85. /// \param jid JID you want conversations with.
  86. /// \param start Start time.
  87. /// \param end End time.
  88. /// \param max Maximum number of collections to list.
  89. ///
  90. void QXmppArchiveManager::listCollections(const QString &jid, const QDateTime &start, const QDateTime &end, int max)
  91. {
  92. QXmppResultSetQuery rsm;
  93. rsm.setMax(max);
  94. listCollections(jid, start, end, rsm);
  95. }
  96. /// Removes the specified collection(s).
  97. ///
  98. /// \param jid The JID of the collection
  99. /// \param start Optional start time.
  100. /// \param end Optional end time.
  101. ///
  102. void QXmppArchiveManager::removeCollections(const QString &jid, const QDateTime &start, const QDateTime &end)
  103. {
  104. QXmppArchiveRemoveIq packet;
  105. packet.setType(QXmppIq::Set);
  106. packet.setWith(jid);
  107. packet.setStart(start);
  108. packet.setEnd(end);
  109. client()->sendPacket(packet);
  110. }
  111. /// Retrieves the specified collection. Once the results are received,
  112. /// the archiveChatReceived() will be emitted.
  113. ///
  114. /// \param jid The JID of the collection
  115. /// \param start The start time of the collection.
  116. /// \param rsm Optional Result Set Management query
  117. ///
  118. void QXmppArchiveManager::retrieveCollection(const QString &jid, const QDateTime &start, const QXmppResultSetQuery &rsm)
  119. {
  120. QXmppArchiveRetrieveIq packet;
  121. packet.setResultSetQuery(rsm);
  122. packet.setStart(start);
  123. packet.setWith(jid);
  124. client()->sendPacket(packet);
  125. }
  126. /// \overload
  127. /// Retrieves the specified collection. Once the results are received,
  128. /// the archiveChatReceived() will be emitted.
  129. ///
  130. /// \param jid The JID of the collection
  131. /// \param start The start time of the collection.
  132. /// \param max Maximum number of messages to retrieve.
  133. ///
  134. void QXmppArchiveManager::retrieveCollection(const QString &jid, const QDateTime &start, int max)
  135. {
  136. QXmppResultSetQuery rsm;
  137. rsm.setMax(max);
  138. retrieveCollection(jid, start, rsm);
  139. }
  140. #if 0
  141. void QXmppArchiveManager::getPreferences()
  142. {
  143. QXmppArchivePrefIq packet;
  144. client()->sendPacket(packet);
  145. }
  146. #endif