1
0
forked from blue/squawk

yet not working button to download offered files

This commit is contained in:
Blue 2019-09-12 23:54:44 +03:00
parent 1df49583fb
commit 59f539c460
10 changed files with 199 additions and 8 deletions

View File

@ -87,6 +87,7 @@ int main(int argc, char *argv[])
squawk, SLOT(removeRoomRequest(const QString&, const QString&)));
QObject::connect(&w, SIGNAL(addRoomRequest(const QString&, const QString&, const QString&, const QString&, bool)),
squawk, SLOT(addRoomRequest(const QString&, const QString&, const QString&, const QString&, bool)));
QObject::connect(&w, SIGNAL(fileLocalPathRequest(const QString&, const QString&)), squawk, SLOT(fileLocalPathRequest(const QString&, const QString&)));
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
QObject::connect(squawk, SIGNAL(addContact(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)),
@ -119,6 +120,8 @@ int main(int argc, char *argv[])
&w, SLOT(changeRoomParticipant(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)));
QObject::connect(squawk, SIGNAL(removeRoomParticipant(const QString&, const QString&, const QString&)),
&w, SLOT(removeRoomParticipant(const QString&, const QString&, const QString&)));
QObject::connect(squawk, SIGNAL(fileLocalPathResponse(const QString&, const QString&)), &w, SLOT(fileLocalPathResponse(const QString&, const QString&)));
//qDebug() << QStandardPaths::writableLocation(QStandardPaths::CacheLocation);

View File

@ -262,14 +262,17 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
Conversations::const_iterator itr = conversations.find(*id);
Conversation* conv = 0;
bool created = false;
Models::Contact::Messages deque;
if (itr != conversations.end()) {
conv = itr->second;
} else if (contact != 0) {
created = true;
conv = new Chat(contact);
contact->getMessages(deque);
} else if (room != 0) {
created = true;
conv = new Room(room);
room->getMessages(deque);
if (!room->getJoined()) {
emit setRoomJoined(id->account, id->name, true);
@ -283,9 +286,17 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
connect(conv, SIGNAL(sendMessage(const Shared::Message&)), this, SLOT(onConversationMessage(const Shared::Message&)));
connect(conv, SIGNAL(requestArchive(const QString&)), this, SLOT(onConversationRequestArchive(const QString&)));
connect(conv, SIGNAL(requestLocalFile(const QString&, const QString&)), this, SLOT(onConversationRequestLocalFile(const QString&, const QString&)));
connect(conv, SIGNAL(downloadFile(const QString&, const QString&)), this, SLOT(onConversationDownloadFile(const QString&, const QString&)));
connect(conv, SIGNAL(shown()), this, SLOT(onConversationShown()));
conversations.insert(std::make_pair(*id, conv));
if (created) {
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
conv->addMessage(*itr);
}
}
}
conv->show();
@ -325,6 +336,45 @@ void Squawk::onConversationClosed(QObject* parent)
conversations.erase(itr);
}
void Squawk::onConversationDownloadFile(const QString& messageId, const QString& url)
{
}
void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path)
{
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
if (itr == requestedFiles.end()) {
qDebug() << "fileLocalPathResponse in UI Squawk but there is nobody waiting for that path, skipping";
return;
} else {
const std::set<Models::Roster::ElId>& convs = itr->second;
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
const Models::Roster::ElId& id = *cItr;
Conversations::const_iterator c = conversations.find(id);
if (c != conversations.end()) {
c->second->responseLocalFile(messageId, path);
}
}
requestedFiles.erase(itr);
}
}
void Squawk::onConversationRequestLocalFile(const QString& messageId, const QString& url)
{
Conversation* conv = static_cast<Conversation*>(sender());
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.find(messageId);
bool created = false;
if (itr == requestedFiles.end()) {
itr = requestedFiles.insert(std::make_pair(messageId, std::set<Models::Roster::ElId>())).first;
created = true;
}
itr->second.insert(Models::Roster::ElId(conv->getAccount(), conv->getJid()));
if (created) {
emit fileLocalPathRequest(messageId, url);
}
}
void Squawk::accountMessage(const QString& account, const Shared::Message& data)
{
const QString& from = data.getPenPalJid();

View File

@ -25,6 +25,7 @@
#include <QtDBus/QDBusInterface>
#include <deque>
#include <map>
#include <set>
#include <list>
#include "widgets/accounts.h"
@ -65,6 +66,7 @@ signals:
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);
void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin);
void removeRoomRequest(const QString& account, const QString& jid);
void fileLocalPathRequest(const QString& messageId, const QString& url);
public slots:
void newAccount(const QMap<QString, QVariant>& account);
@ -87,6 +89,7 @@ public slots:
void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
void fileLocalPathResponse(const QString& messageId, const QString& path);
private:
typedef std::map<Models::Roster::ElId, Conversation*> Conversations;
@ -97,6 +100,7 @@ private:
Conversations conversations;
QMenu* contextMenu;
QDBusInterface dbus;
std::map<QString, std::set<Models::Roster::ElId>> requestedFiles;
protected:
void closeEvent(QCloseEvent * event) override;
@ -117,6 +121,8 @@ private slots:
void onConversationRequestArchive(const QString& before);
void onRosterContextMenu(const QPoint& point);
void onConversationShown();
void onConversationRequestLocalFile(const QString& messageId, const QString& url);
void onConversationDownloadFile(const QString& messageId, const QString& url);
};

View File

@ -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()

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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

View File

@ -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();
}
}
}

View File

@ -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;