yet not working button to download offered files
This commit is contained in:
parent
1df49583fb
commit
59f539c460
10 changed files with 199 additions and 8 deletions
|
@ -29,13 +29,6 @@ Chat::Chat(Models::Contact* p_contact, QWidget* parent):
|
|||
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
|
||||
|
||||
line->setMyName(p_contact->getAccountName());
|
||||
|
||||
Models::Contact::Messages deque;
|
||||
contact->getMessages(deque);
|
||||
|
||||
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
|
||||
addMessage(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
Chat::~Chat()
|
||||
|
|
|
@ -58,6 +58,8 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co
|
|||
connect(&vis, SIGNAL(hidden()), this, SLOT(onScrollResize()));
|
||||
connect(m_ui->sendButton, SIGNAL(clicked(bool)), this, SLOT(onEnterPressed()));
|
||||
connect(line, SIGNAL(resize(int)), this, SLOT(onMessagesResize(int)));
|
||||
connect(line, SIGNAL(downloadFile(const QString&, const QString&)), this, SIGNAL(downloadFile(const QString&, const QString&)));
|
||||
connect(line, SIGNAL(requestLocalFile(const QString&, const QString&)), this, SIGNAL(requestLocalFile(const QString&, const QString&)));
|
||||
//connect(m_ui->attachButton, SIGNAL(clicked(bool)), this, SLOT(onAttach()));
|
||||
|
||||
m_ui->messageEditor->installEventFilter(&ker);
|
||||
|
@ -283,6 +285,16 @@ void Conversation::onScrollResize()
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::responseDownloadProgress(const QString& messageId, qreal progress)
|
||||
{
|
||||
line->responseDownloadProgress(messageId, progress);
|
||||
}
|
||||
|
||||
void Conversation::responseLocalFile(const QString& messageId, const QString& path)
|
||||
{
|
||||
line->responseLocalFile(messageId, path);
|
||||
}
|
||||
|
||||
Resizer::Resizer(QWidget* parent):
|
||||
QObject(parent)
|
||||
{
|
||||
|
|
|
@ -82,11 +82,15 @@ public:
|
|||
void setPalResource(const QString& res);
|
||||
void responseArchive(const std::list<Shared::Message> list);
|
||||
void showEvent(QShowEvent * event) override;
|
||||
void responseLocalFile(const QString& messageId, const QString& path);
|
||||
void responseDownloadProgress(const QString& messageId, qreal progress);
|
||||
|
||||
signals:
|
||||
void sendMessage(const Shared::Message& message);
|
||||
void requestArchive(const QString& before);
|
||||
void shown();
|
||||
void requestLocalFile(const QString& messageId, const QString& url);
|
||||
void downloadFile(const QString& messageId, const QString& url);
|
||||
|
||||
protected:
|
||||
virtual void setName(const QString& name);
|
||||
|
|
|
@ -30,7 +30,13 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
|
|||
date(new QLabel(msg.getTime().toLocalTime().toString())),
|
||||
sender(new QLabel(p_sender)),
|
||||
text(new QLabel()),
|
||||
shadow(new QGraphicsDropShadowEffect())
|
||||
shadow(new QGraphicsDropShadowEffect()),
|
||||
downloadButton(0),
|
||||
file(0),
|
||||
progress(0),
|
||||
hasDownloadButton(false),
|
||||
hasProgress(false),
|
||||
hasFile(false)
|
||||
{
|
||||
body->setBackgroundRole(QPalette::AlternateBase);
|
||||
body->setAutoFillBackground(true);
|
||||
|
@ -42,6 +48,9 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
|
|||
text->setTextInteractionFlags(text->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||
text->setWordWrap(true);
|
||||
text->setOpenExternalLinks(true);
|
||||
if (bd.size() == 0) {
|
||||
text->hide();
|
||||
}
|
||||
|
||||
QFont dFont = date->font();
|
||||
dFont.setItalic(true);
|
||||
|
@ -87,3 +96,66 @@ void Message::setSender(const QString& p_sender)
|
|||
{
|
||||
sender->setText(p_sender);
|
||||
}
|
||||
|
||||
void Message::addDownloadDialog()
|
||||
{
|
||||
if (hasFile) {
|
||||
file->deleteLater();
|
||||
file = 0;
|
||||
hasFile = false;
|
||||
}
|
||||
if (hasProgress) {
|
||||
progress->deleteLater();
|
||||
progress = 0;
|
||||
hasProgress = false;;
|
||||
}
|
||||
if (!hasDownloadButton) {
|
||||
downloadButton = new QPushButton(QIcon::fromTheme("download"), "Download");
|
||||
connect(downloadButton, SIGNAL(clicked()), this, SLOT(onDownload()));
|
||||
bodyLayout->insertWidget(2, downloadButton);
|
||||
hasDownloadButton = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Message::onDownload()
|
||||
{
|
||||
emit downloadFile(msg.getId(), msg.getOutOfBandUrl());
|
||||
}
|
||||
|
||||
void Message::setProgress(qreal value)
|
||||
{
|
||||
if (hasFile) {
|
||||
file->deleteLater();
|
||||
file = 0;
|
||||
hasFile = false;
|
||||
}
|
||||
if (hasDownloadButton) {
|
||||
downloadButton->deleteLater();
|
||||
downloadButton = 0;
|
||||
hasDownloadButton = false;
|
||||
}
|
||||
if (!hasProgress) {
|
||||
progress = new QLabel(std::to_string(value).c_str());
|
||||
bodyLayout->insertWidget(2, progress);
|
||||
hasProgress = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Message::showFile(const QString& path)
|
||||
{
|
||||
if (hasDownloadButton) {
|
||||
downloadButton->deleteLater();
|
||||
downloadButton = 0;
|
||||
hasDownloadButton = false;
|
||||
}
|
||||
if (hasProgress) {
|
||||
progress->deleteLater();
|
||||
progress = 0;
|
||||
hasProgress = false;;
|
||||
}
|
||||
if (!hasFile) {
|
||||
file = new QLabel(path);
|
||||
bodyLayout->insertWidget(2, file);
|
||||
hasFile = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "../../global.h"
|
||||
|
||||
|
@ -40,6 +41,13 @@ public:
|
|||
void setSender(const QString& sender);
|
||||
QString getId() const;
|
||||
|
||||
void addDownloadDialog();
|
||||
void showFile(const QString& path);
|
||||
void setProgress(qreal value);
|
||||
|
||||
signals:
|
||||
void downloadFile(const QString& messageId, const QString& url);
|
||||
|
||||
private:
|
||||
Shared::Message msg;
|
||||
QWidget* body;
|
||||
|
@ -48,6 +56,16 @@ private:
|
|||
QLabel* sender;
|
||||
QLabel* text;
|
||||
QGraphicsDropShadowEffect* shadow;
|
||||
QPushButton* downloadButton;
|
||||
QLabel* file;
|
||||
QLabel* progress;
|
||||
bool hasDownloadButton;
|
||||
bool hasProgress;
|
||||
bool hasFile;
|
||||
|
||||
private slots:
|
||||
void onDownload();
|
||||
|
||||
};
|
||||
|
||||
#endif // MESSAGE_H
|
||||
|
|
|
@ -149,6 +149,11 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
|
|||
layout->insertLayout(index, message);
|
||||
}
|
||||
|
||||
if (msg.hasOutOfBandUrl()) {\
|
||||
emit requestLocalFile(msg.getId(), msg.getOutOfBandUrl());
|
||||
connect(message, SIGNAL(downloadFile(const QString&, const QString&)), this, SIGNAL(downloadFile(const QString&, const QString&)));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -217,3 +222,27 @@ void MessageLine::onAnimationValueChanged(const QVariant& value)
|
|||
{
|
||||
busyPixmap->setRotation(value.toReal());
|
||||
}
|
||||
|
||||
void MessageLine::responseDownloadProgress(const QString& messageId, qreal progress)
|
||||
{
|
||||
Index::const_iterator itr = messageIndex.find(messageId);
|
||||
if (itr == messageIndex.end()) {
|
||||
|
||||
} else {
|
||||
itr->second->setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLine::responseLocalFile(const QString& messageId, const QString& path)
|
||||
{
|
||||
Index::const_iterator itr = messageIndex.find(messageId);
|
||||
if (itr == messageIndex.end()) {
|
||||
|
||||
} else {
|
||||
if (path.size() > 0) {
|
||||
itr->second->showFile(path);
|
||||
} else {
|
||||
itr->second->addDownloadDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,13 @@ public:
|
|||
QString firstMessageId() const;
|
||||
void showBusyIndicator();
|
||||
void hideBusyIndicator();
|
||||
void responseLocalFile(const QString& messageId, const QString& path);
|
||||
void responseDownloadProgress(const QString& messageId, qreal progress);
|
||||
|
||||
signals:
|
||||
void resize(int amount);
|
||||
void downloadFile(const QString& messageId, const QString& url);
|
||||
void requestLocalFile(const QString& messageId, const QString& url);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue