PageRenderTime 875ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/quassel-0.7.3/src/client/backlogrequester.h

#
C Header | 114 lines | 65 code | 21 blank | 28 comment | 0 complexity | 2655c03a6a6a37e517d3aed373de7b5a MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-09 by the Quassel Project *
  3. * devel@quassel-irc.org *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) version 3. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifndef BACKLOGREQUESTER_H
  21. #define BACKLOGREQUESTER_H
  22. #include <QList>
  23. #include "client.h"
  24. #include "message.h"
  25. #include "networkmodel.h"
  26. #include "types.h"
  27. class ClientBacklogManager;
  28. class BacklogRequester {
  29. public:
  30. enum RequesterType {
  31. InvalidRequester = 0,
  32. PerBufferFixed,
  33. PerBufferUnread,
  34. GlobalUnread
  35. };
  36. BacklogRequester(bool buffering, RequesterType requesterType, ClientBacklogManager *backlogManger);
  37. virtual inline ~BacklogRequester() {}
  38. inline bool isBuffering() { return _isBuffering; }
  39. inline RequesterType type() { return _requesterType; }
  40. inline const QList<Message> &bufferedMessages() { return _bufferedMessages; }
  41. inline int buffersWaiting() const { return _buffersWaiting.count(); }
  42. inline int totalBuffers() const { return _totalBuffers; }
  43. bool buffer(BufferId bufferId, const MessageList &messages); //! returns false if it was the last missing backlogpart
  44. virtual void requestBacklog(const BufferIdList &bufferIds) = 0;
  45. virtual inline void requestInitialBacklog() { requestBacklog(allBufferIds()); }
  46. virtual void flushBuffer();
  47. protected:
  48. BufferIdList allBufferIds() const;
  49. inline void setWaitingBuffers(const QList<BufferId> &buffers) { setWaitingBuffers(buffers.toSet()); }
  50. void setWaitingBuffers(const QSet<BufferId> &buffers);
  51. void addWaitingBuffer(BufferId buffer);
  52. ClientBacklogManager *backlogManager;
  53. private:
  54. bool _isBuffering;
  55. RequesterType _requesterType;
  56. MessageList _bufferedMessages;
  57. int _totalBuffers;
  58. QSet<BufferId> _buffersWaiting;
  59. };
  60. // ========================================
  61. // FIXED BACKLOG REQUESTER
  62. // ========================================
  63. class FixedBacklogRequester : public BacklogRequester {
  64. public:
  65. FixedBacklogRequester(ClientBacklogManager *backlogManager);
  66. virtual void requestBacklog(const BufferIdList &bufferIds);
  67. private:
  68. int _backlogCount;
  69. };
  70. // ========================================
  71. // GLOBAL UNREAD BACKLOG REQUESTER
  72. // ========================================
  73. class GlobalUnreadBacklogRequester : public BacklogRequester {
  74. public:
  75. GlobalUnreadBacklogRequester(ClientBacklogManager *backlogManager);
  76. virtual void requestInitialBacklog();
  77. virtual void requestBacklog(const BufferIdList &) {}
  78. private:
  79. int _limit;
  80. int _additional;
  81. };
  82. // ========================================
  83. // PER BUFFER UNREAD BACKLOG REQUESTER
  84. // ========================================
  85. class PerBufferUnreadBacklogRequester : public BacklogRequester {
  86. public:
  87. PerBufferUnreadBacklogRequester(ClientBacklogManager *backlogManager);
  88. virtual void requestBacklog(const BufferIdList &bufferIds);
  89. private:
  90. int _limit;
  91. int _additional;
  92. };
  93. #endif //BACKLOGREQUESTER_H