Desktop Qt based XMPP messenger https://macaw.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.5 KiB

  1. /*
  2. * Squawk messenger.
  3. * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
  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 3 of the License, or
  8. * (at your option) any later version.
  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, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef CONVERSATION_H
  19. #define CONVERSATION_H
  20. #include <QWidget>
  21. #include <QScopedPointer>
  22. #include <QMap>
  23. #include <QMimeData>
  24. #include <QFileInfo>
  25. #include "shared/message.h"
  26. #include "order.h"
  27. #include "ui/models/account.h"
  28. #include "ui/models/roster.h"
  29. #include "ui/utils/messageline.h"
  30. #include "ui/utils/resizer.h"
  31. #include "ui/utils/flowlayout.h"
  32. #include "ui/utils/badge.h"
  33. #include "shared/icons.h"
  34. #include "shared/utils.h"
  35. namespace Ui
  36. {
  37. class Conversation;
  38. }
  39. class KeyEnterReceiver : public QObject
  40. {
  41. Q_OBJECT
  42. public:
  43. KeyEnterReceiver(QObject* parent = 0);
  44. protected:
  45. bool ownEvent;
  46. bool eventFilter(QObject* obj, QEvent* event);
  47. signals:
  48. void enterPressed();
  49. };
  50. class VisibilityCatcher : public QObject {
  51. Q_OBJECT
  52. public:
  53. VisibilityCatcher(QWidget* parent = nullptr);
  54. protected:
  55. bool eventFilter(QObject* obj, QEvent* event) override;
  56. signals:
  57. void hidden();
  58. void shown();
  59. };
  60. class Conversation : public QWidget
  61. {
  62. Q_OBJECT
  63. public:
  64. Conversation(bool muc, Models::Account* acc, const QString pJid, const QString pRes, QWidget* parent = 0);
  65. ~Conversation();
  66. QString getJid() const;
  67. QString getAccount() const;
  68. QString getPalResource() const;
  69. Models::Roster::ElId getId() const;
  70. virtual void addMessage(const Shared::Message& data);
  71. void setPalResource(const QString& res);
  72. void responseArchive(const std::list<Shared::Message> list);
  73. void showEvent(QShowEvent * event) override;
  74. void responseLocalFile(const QString& messageId, const QString& path);
  75. void fileError(const QString& messageId, const QString& error);
  76. void responseFileProgress(const QString& messageId, qreal progress);
  77. virtual void setAvatar(const QString& path);
  78. void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
  79. void setFeedFrames(bool top, bool right, bool bottom, bool left);
  80. virtual void appendMessageWithUpload(const Shared::Message& data, const QString& path);
  81. signals:
  82. void sendMessage(const Shared::Message& message);
  83. void sendMessage(const Shared::Message& message, const QString& path);
  84. void requestArchive(const QString& before);
  85. void shown();
  86. void requestLocalFile(const QString& messageId, const QString& url);
  87. void downloadFile(const QString& messageId, const QString& url);
  88. protected:
  89. virtual void setName(const QString& name);
  90. void applyVisualEffects();
  91. virtual Shared::Message createMessage() const;
  92. void setStatus(const QString& status);
  93. void addAttachedFile(const QString& path);
  94. void removeAttachedFile(Badge* badge);
  95. void clearAttachedFiles();
  96. void dragEnterEvent(QDragEnterEvent* event) override;
  97. void dragLeaveEvent(QDragLeaveEvent* event) override;
  98. void dropEvent(QDropEvent* event) override;
  99. protected slots:
  100. void onEnterPressed();
  101. void onMessagesResize(int amount);
  102. void onSliderValueChanged(int value);
  103. void onAttach();
  104. void onFileSelected();
  105. void onScrollResize();
  106. void onBadgeClose();
  107. void onClearButton();
  108. void onTextEditDocSizeChanged(const QSizeF& size);
  109. void onAccountChanged(Models::Item* item, int row, int col);
  110. public:
  111. const bool isMuc;
  112. protected:
  113. enum Scroll {
  114. nothing,
  115. keep,
  116. down
  117. };
  118. Models::Account* account;
  119. QString palJid;
  120. QString activePalResource;
  121. MessageLine* line;
  122. QScopedPointer<Ui::Conversation> m_ui;
  123. KeyEnterReceiver ker;
  124. Resizer scrollResizeCatcher;
  125. VisibilityCatcher vis;
  126. QString thread;
  127. QLabel* statusIcon;
  128. QLabel* statusLabel;
  129. FlowLayout* filesLayout;
  130. QWidget* overlay;
  131. W::Order<Badge*, Badge::Comparator> filesToAttach;
  132. Scroll scroll;
  133. bool manualSliderChange;
  134. bool requestingHistory;
  135. bool everShown;
  136. bool tsb; //transient scroll bars
  137. };
  138. #endif // CONVERSATION_H