2019-04-08 21:40:49 +00:00
|
|
|
/*
|
2019-08-14 14:54:46 +00:00
|
|
|
* Squawk messenger.
|
2019-04-08 21:40:49 +00:00
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-11-09 22:36:30 +00:00
|
|
|
#pragma once
|
2019-04-08 21:40:49 +00:00
|
|
|
|
|
|
|
#include <QWidget>
|
2023-11-06 23:57:08 +00:00
|
|
|
#include <QObject>
|
2019-04-08 21:40:49 +00:00
|
|
|
#include <QScopedPointer>
|
2020-02-08 11:44:15 +00:00
|
|
|
#include <QMap>
|
2020-04-14 16:30:33 +00:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QFileInfo>
|
2021-05-03 11:23:41 +00:00
|
|
|
#include <QGraphicsOpacityEffect>
|
2021-05-04 14:09:41 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QDesktopServices>
|
2020-02-08 11:44:15 +00:00
|
|
|
|
2023-11-09 22:36:30 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/message.h"
|
2021-05-15 22:07:49 +00:00
|
|
|
|
2020-02-08 11:44:15 +00:00
|
|
|
#include "ui/models/account.h"
|
2020-04-11 20:00:15 +00:00
|
|
|
#include "ui/models/roster.h"
|
2021-05-15 22:07:49 +00:00
|
|
|
|
2020-02-08 11:44:15 +00:00
|
|
|
#include "ui/utils/flowlayout.h"
|
|
|
|
#include "ui/utils/badge.h"
|
2021-05-03 00:35:43 +00:00
|
|
|
#include "ui/utils/shadowoverlay.h"
|
2021-05-15 22:07:49 +00:00
|
|
|
|
|
|
|
#include "ui/widgets/messageline/feedview.h"
|
|
|
|
#include "ui/widgets/messageline/messagedelegate.h"
|
2019-04-08 21:40:49 +00:00
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
namespace Ui {
|
2019-04-08 21:40:49 +00:00
|
|
|
class Conversation;
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
class KeyEnterReceiver : public QObject {
|
2019-04-09 22:01:25 +00:00
|
|
|
Q_OBJECT
|
2019-04-10 15:22:52 +00:00
|
|
|
public:
|
|
|
|
KeyEnterReceiver(QObject* parent = 0);
|
2019-04-09 22:01:25 +00:00
|
|
|
protected:
|
2019-04-10 15:22:52 +00:00
|
|
|
bool ownEvent;
|
2019-04-09 22:01:25 +00:00
|
|
|
bool eventFilter(QObject* obj, QEvent* event);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void enterPressed();
|
2021-10-06 15:09:18 +00:00
|
|
|
void imagePasted();
|
2019-04-09 22:01:25 +00:00
|
|
|
};
|
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
class Conversation : public QWidget {
|
2019-04-08 21:40:49 +00:00
|
|
|
Q_OBJECT
|
2019-04-09 15:04:08 +00:00
|
|
|
public:
|
2020-08-12 16:55:01 +00:00
|
|
|
Conversation(bool muc, Models::Account* acc, Models::Element* el, const QString pJid, const QString pRes, QWidget* parent = 0);
|
2019-04-09 15:04:08 +00:00
|
|
|
~Conversation();
|
|
|
|
|
|
|
|
QString getJid() const;
|
|
|
|
QString getAccount() const;
|
2019-04-12 15:22:10 +00:00
|
|
|
QString getPalResource() const;
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Roster::ElId getId() const;
|
2019-04-09 15:04:08 +00:00
|
|
|
|
2019-04-12 15:22:10 +00:00
|
|
|
void setPalResource(const QString& res);
|
2019-12-23 06:28:23 +00:00
|
|
|
virtual void setAvatar(const QString& path);
|
2020-04-11 20:00:15 +00:00
|
|
|
void setFeedFrames(bool top, bool right, bool bottom, bool left);
|
2021-10-06 15:09:18 +00:00
|
|
|
static bool checkClipboardImage();
|
2019-04-12 15:22:10 +00:00
|
|
|
|
2019-04-10 20:53:42 +00:00
|
|
|
signals:
|
2019-04-11 14:58:59 +00:00
|
|
|
void sendMessage(const Shared::Message& message);
|
2022-03-28 20:25:33 +00:00
|
|
|
void replaceMessage(const QString& originalId, const Shared::Message& message);
|
2021-05-22 22:03:14 +00:00
|
|
|
void resendMessage(const QString& id);
|
2019-05-15 17:36:37 +00:00
|
|
|
void requestArchive(const QString& before);
|
2019-06-18 15:08:03 +00:00
|
|
|
void shown();
|
2019-09-12 20:54:44 +00:00
|
|
|
void requestLocalFile(const QString& messageId, const QString& url);
|
|
|
|
void downloadFile(const QString& messageId, const QString& url);
|
2021-04-27 19:29:15 +00:00
|
|
|
void notifyableMessage(const QString& account, const Shared::Message& msg);
|
2023-11-05 01:12:15 +00:00
|
|
|
void setEncryption(Shared::EncryptionProtocol value);
|
2019-04-10 20:53:42 +00:00
|
|
|
|
2019-04-09 15:04:08 +00:00
|
|
|
protected:
|
2019-08-28 11:40:55 +00:00
|
|
|
virtual void setName(const QString& name);
|
2020-04-15 13:48:49 +00:00
|
|
|
virtual Shared::Message createMessage() const;
|
2019-09-03 20:28:58 +00:00
|
|
|
void setStatus(const QString& status);
|
2019-09-19 14:31:27 +00:00
|
|
|
void addAttachedFile(const QString& path);
|
2023-11-09 22:36:30 +00:00
|
|
|
void removeAttachedFile(const QString& id);
|
2019-09-19 14:31:27 +00:00
|
|
|
void clearAttachedFiles();
|
2020-04-14 16:30:33 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
|
|
|
void dropEvent(QDropEvent* event) override;
|
2021-05-03 00:35:43 +00:00
|
|
|
void initializeOverlay();
|
2021-04-27 19:29:15 +00:00
|
|
|
virtual void onMessage(const Shared::Message& msg);
|
2022-03-29 16:05:24 +00:00
|
|
|
virtual void showEvent(QShowEvent * event) override;
|
2023-11-09 22:36:30 +00:00
|
|
|
|
|
|
|
void createFeed();
|
|
|
|
void createUI();
|
|
|
|
void subscribeEvents();
|
2019-04-09 15:04:08 +00:00
|
|
|
|
|
|
|
protected slots:
|
2022-03-28 20:25:33 +00:00
|
|
|
void initiateMessageSending();
|
|
|
|
void initiateMessageSending(const Shared::Message& msg);
|
2021-10-06 15:09:18 +00:00
|
|
|
void onImagePasted();
|
2019-06-21 19:33:38 +00:00
|
|
|
void onAttach();
|
|
|
|
void onFileSelected();
|
2019-09-19 14:31:27 +00:00
|
|
|
void onBadgeClose();
|
2022-03-28 20:25:33 +00:00
|
|
|
void clear();
|
2020-03-30 21:17:10 +00:00
|
|
|
void onTextEditDocSizeChanged(const QSizeF& size);
|
2020-08-07 23:33:03 +00:00
|
|
|
void onAccountChanged(Models::Item* item, int row, int col);
|
2021-04-27 19:29:15 +00:00
|
|
|
void onFeedMessage(const Shared::Message& msg);
|
2021-05-03 00:35:43 +00:00
|
|
|
void positionShadow();
|
2021-05-04 14:09:41 +00:00
|
|
|
void onFeedContext(const QPoint &pos);
|
2021-10-13 12:06:13 +00:00
|
|
|
void onMessageEditorContext(const QPoint &pos);
|
2022-03-27 19:05:31 +00:00
|
|
|
void onMessageEditRequested(const QString& id);
|
2023-11-05 19:29:44 +00:00
|
|
|
virtual void onEncryptionButtonClicked();
|
2019-04-09 15:04:08 +00:00
|
|
|
|
2019-08-29 14:19:35 +00:00
|
|
|
public:
|
|
|
|
const bool isMuc;
|
|
|
|
|
2019-08-23 09:51:33 +00:00
|
|
|
protected:
|
2022-02-20 19:10:09 +00:00
|
|
|
enum class CurrentAction {
|
|
|
|
none,
|
|
|
|
edit
|
|
|
|
};
|
|
|
|
|
2019-12-20 15:41:20 +00:00
|
|
|
Models::Account* account;
|
2020-08-12 16:55:01 +00:00
|
|
|
Models::Element* element;
|
2019-08-23 09:51:33 +00:00
|
|
|
QString palJid;
|
|
|
|
QString activePalResource;
|
2023-11-06 23:57:08 +00:00
|
|
|
Ui::Conversation* m_ui;
|
2019-04-09 22:01:25 +00:00
|
|
|
KeyEnterReceiver ker;
|
2019-04-12 15:22:10 +00:00
|
|
|
QString thread;
|
2019-08-23 09:51:33 +00:00
|
|
|
QLabel* statusIcon;
|
|
|
|
QLabel* statusLabel;
|
2019-09-19 14:31:27 +00:00
|
|
|
FlowLayout* filesLayout;
|
2020-04-14 16:30:33 +00:00
|
|
|
QWidget* overlay;
|
2023-11-09 22:36:30 +00:00
|
|
|
std::vector<Badge*> filesToAttach;
|
2020-08-15 21:48:28 +00:00
|
|
|
FeedView* feed;
|
2020-08-20 21:32:30 +00:00
|
|
|
MessageDelegate* delegate;
|
2019-04-14 20:37:02 +00:00
|
|
|
bool manualSliderChange;
|
2020-02-04 15:14:51 +00:00
|
|
|
bool tsb; //transient scroll bars
|
2021-05-03 00:35:43 +00:00
|
|
|
|
2021-10-06 15:09:18 +00:00
|
|
|
QAction* pasteImageAction;
|
|
|
|
|
2021-05-03 00:35:43 +00:00
|
|
|
ShadowOverlay shadow;
|
2021-05-04 14:09:41 +00:00
|
|
|
QMenu* contextMenu;
|
2022-02-20 19:10:09 +00:00
|
|
|
CurrentAction currentAction;
|
2022-03-28 20:25:33 +00:00
|
|
|
QString currentMessageId;
|
2022-01-08 22:28:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool painterInitialized;
|
|
|
|
static QPainterPath* avatarMask;
|
|
|
|
static QPixmap* avatarPixmap;
|
|
|
|
static QPainter* avatarPainter;
|
2019-04-08 21:40:49 +00:00
|
|
|
};
|