some fixes about uploading, some error handling
This commit is contained in:
parent
166a7ac83a
commit
326eef864b
11 changed files with 200 additions and 56 deletions
|
@ -109,7 +109,7 @@ void Message::setSender(const QString& p_sender)
|
|||
sender->setText(p_sender);
|
||||
}
|
||||
|
||||
void Message::addButton(const QIcon& icon, const QString& buttonText)
|
||||
void Message::addButton(const QIcon& icon, const QString& buttonText, const QString& tooltip)
|
||||
{
|
||||
hideFile();
|
||||
hideProgress();
|
||||
|
@ -120,7 +120,7 @@ void Message::addButton(const QIcon& icon, const QString& buttonText)
|
|||
text->hide();
|
||||
}
|
||||
button = new QPushButton(icon, buttonText);
|
||||
button->setToolTip("<a href=\"" + msg.getOutOfBandUrl() + "\">" + msg.getOutOfBandUrl() + "</a>");
|
||||
button->setToolTip(tooltip);
|
||||
connect(button, &QPushButton::clicked, this, &Message::buttonClicked);
|
||||
bodyLayout->insertWidget(2, button);
|
||||
hasButton = true;
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
QString getFileUrl() const;
|
||||
const Shared::Message& getMessage() const;
|
||||
|
||||
void addButton(const QIcon& icon, const QString& buttonText);
|
||||
void addButton(const QIcon& icon, const QString& buttonText, const QString& tooltip = "");
|
||||
void showComment(const QString& comment, bool wordWrap = false);
|
||||
void hideComment();
|
||||
void showFile(const QString& path);
|
||||
|
|
|
@ -253,8 +253,9 @@ void MessageLine::responseLocalFile(const QString& messageId, const QString& pat
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (uItr != uploading.end()) {
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"));
|
||||
if (uItr == uploading.end()) {
|
||||
const Shared::Message& msg = itr->second->getMessage();
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"), "<a href=\"" + msg.getOutOfBandUrl() + "\">" + msg.getOutOfBandUrl() + "</a>");
|
||||
itr->second->showComment(tr("Push the button to daownload the file"));
|
||||
} else {
|
||||
qDebug() << "An unhandled state for file uploading - empty path";
|
||||
|
@ -319,7 +320,8 @@ void MessageLine::fileError(const QString& messageId, const QString& error)
|
|||
itr->second->addButton(QIcon::fromTheme("upload"), tr("Upload"));
|
||||
}
|
||||
} else {
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"));
|
||||
const Shared::Message& msg = itr->second->getMessage();
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"), "<a href=\"" + msg.getOutOfBandUrl() + "\">" + msg.getOutOfBandUrl() + "</a>");
|
||||
itr->second->showComment(tr("Error downloading file: %1\nYou can try again").arg(QCoreApplication::translate("NetworkErrors", error.toLatin1())), true);
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +333,7 @@ void MessageLine::appendMessageWithUpload(const Shared::Message& msg, const QStr
|
|||
Message* ui = messageIndex.find(id)->second;
|
||||
connect(ui, &Message::buttonClicked, this, &MessageLine::onUpload); //this is in case of retry;
|
||||
ui->setProgress(0);
|
||||
ui->showComment("Uploading...");
|
||||
ui->showComment(tr("Uploading..."));
|
||||
uploading.insert(std::make_pair(id, ui));
|
||||
uploadPaths.insert(std::make_pair(id, path));
|
||||
emit uploadFile(msg, path);
|
||||
|
|
|
@ -27,7 +27,8 @@ QObject(parent)
|
|||
bool Resizer::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::Resize) {
|
||||
emit resized();
|
||||
QResizeEvent* ev = static_cast<QResizeEvent*>(event);
|
||||
emit resized(ev->oldSize(), ev->size());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QEvent>
|
||||
#include <QResizeEvent>
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
|
@ -35,7 +36,7 @@ protected:
|
|||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
signals:
|
||||
void resized();
|
||||
void resized(const QSize& oldSize, const QSize& newSize);
|
||||
};
|
||||
|
||||
#endif // RESIZER_H
|
||||
|
|
|
@ -36,7 +36,8 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co
|
|||
line(new MessageLine(muc)),
|
||||
m_ui(new Ui::Conversation()),
|
||||
ker(),
|
||||
res(),
|
||||
scrollResizeCatcher(),
|
||||
attachResizeCatcher(),
|
||||
vis(),
|
||||
thread(),
|
||||
statusIcon(0),
|
||||
|
@ -60,7 +61,8 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co
|
|||
statusLabel = m_ui->statusLabel;
|
||||
|
||||
connect(&ker, &KeyEnterReceiver::enterPressed, this, &Conversation::onEnterPressed);
|
||||
connect(&res, &Resizer::resized, this, &Conversation::onScrollResize);
|
||||
connect(&scrollResizeCatcher, &Resizer::resized, this, &Conversation::onScrollResize);
|
||||
connect(&attachResizeCatcher, &Resizer::resized, this, &Conversation::onAttachResize);
|
||||
connect(&vis, &VisibilityCatcher::shown, this, &Conversation::onScrollResize);
|
||||
connect(&vis, &VisibilityCatcher::hidden, this, &Conversation::onScrollResize);
|
||||
connect(m_ui->sendButton, &QPushButton::clicked, this, &Conversation::onEnterPressed);
|
||||
|
@ -69,6 +71,7 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co
|
|||
connect(line, &MessageLine::uploadFile, this, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage));
|
||||
connect(line, &MessageLine::requestLocalFile, this, &Conversation::requestLocalFile);
|
||||
connect(m_ui->attachButton, &QPushButton::clicked, this, &Conversation::onAttach);
|
||||
connect(m_ui->clearButton, &QPushButton::clicked, this, &Conversation::onClearButton);
|
||||
|
||||
m_ui->messageEditor->installEventFilter(&ker);
|
||||
|
||||
|
@ -78,7 +81,8 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co
|
|||
vs->setBackgroundRole(QPalette::Base);
|
||||
vs->setAutoFillBackground(true);
|
||||
connect(vs, &QScrollBar::valueChanged, this, &Conversation::onSliderValueChanged);
|
||||
m_ui->scrollArea->installEventFilter(&res);
|
||||
m_ui->scrollArea->installEventFilter(&scrollResizeCatcher);
|
||||
m_ui->filesPanel->installEventFilter(&attachResizeCatcher);
|
||||
|
||||
applyVisualEffects();
|
||||
}
|
||||
|
@ -181,6 +185,10 @@ void Conversation::onEnterPressed()
|
|||
{
|
||||
QString body(m_ui->messageEditor->toPlainText());
|
||||
|
||||
if (body.size() > 0) {
|
||||
m_ui->messageEditor->clear();
|
||||
handleSendMessage(body);
|
||||
}
|
||||
if (filesToAttach.size() > 0) {
|
||||
for (Badge* badge : filesToAttach) {
|
||||
Shared::Message msg;
|
||||
|
@ -196,17 +204,9 @@ void Conversation::onEnterPressed()
|
|||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
if (body.size() > 0) {
|
||||
msg.setBody(body);
|
||||
}
|
||||
line->appendMessageWithUpload(msg, badge->id);
|
||||
}
|
||||
clearAttachedFiles();
|
||||
} else {
|
||||
if (body.size() > 0) {
|
||||
m_ui->messageEditor->clear();
|
||||
handleSendMessage(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,6 +376,30 @@ void Conversation::clearAttachedFiles()
|
|||
filesLayout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Conversation::onClearButton()
|
||||
{
|
||||
clearAttachedFiles();
|
||||
m_ui->messageEditor->clear();
|
||||
}
|
||||
|
||||
void Conversation::onAttachResize(const QSize& oldSize, const QSize& newSize)
|
||||
{
|
||||
int oh = oldSize.height();
|
||||
int nh = newSize.height();
|
||||
|
||||
int d = oh - nh;
|
||||
|
||||
if (d != 0) {
|
||||
QList<int> cs = m_ui->splitter->sizes();
|
||||
cs.first() += d;
|
||||
cs.last() -=d;
|
||||
|
||||
m_ui->splitter->setSizes(cs);
|
||||
m_ui->scrollArea->verticalScrollBar()->setValue(m_ui->scrollArea->verticalScrollBar()->maximum());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool VisibilityCatcher::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::Show) {
|
||||
|
|
|
@ -102,7 +102,9 @@ protected slots:
|
|||
void onAttach();
|
||||
void onFileSelected();
|
||||
void onScrollResize();
|
||||
void onAttachResize(const QSize& oldSize, const QSize& newSize);
|
||||
void onBadgeClose();
|
||||
void onClearButton();
|
||||
|
||||
public:
|
||||
const bool isMuc;
|
||||
|
@ -121,7 +123,8 @@ protected:
|
|||
MessageLine* line;
|
||||
QScopedPointer<Ui::Conversation> m_ui;
|
||||
KeyEnterReceiver ker;
|
||||
Resizer res;
|
||||
Resizer scrollResizeCatcher;
|
||||
Resizer attachResizeCatcher;
|
||||
VisibilityCatcher vis;
|
||||
QString thread;
|
||||
QLabel* statusIcon;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue