Commit 051fa950 authored by scuq's avatar scuq

file upload via drag&drop on chatinput

parent f47c9e2c
Pipeline #401 failed with stage
in 1 minute and 3 seconds
......@@ -110,6 +110,12 @@ void dialogChat::setupSignals()
this->ui->wAttachment, SLOT (slOnProgressChanged(int, const QString))
);
connect( this->ui->plainTextEditChatInput, SIGNAL (siFileDropped(const QString)),
this, SLOT (slFileDropped(const QString))
);
//slChannelUnreadCountReceived
......@@ -860,6 +866,30 @@ this->ui->wAttachment->setVisible(false);
}
void dialogChat::slFileDropped(const QString &filepath)
{
QFile file(filepath);
QFileInfo fileInfo(file.fileName());
QString filename(fileInfo.fileName());
if (file.exists()) {
file.open(QFile::ReadOnly);
QByteArray ba = file.readAll();
qDebug() << "dropped file";
qDebug() << ba.size();
this->session->uploadFile(this->contact->getDirectChannelId(),filename,ba);
this->ui->wAttachment->setPreviewImage(QImage::fromData(ba));
this->ui->wAttachment->setHidden(false);
this->ui->plainTextEditChatInput->setPlaceholderText("Hit Alt-Up (Cursor) to send attachment without text!");
}
}
void dialogChat::slAttachmentIdsReceived(const QStringList &fileids, const QString &channelid)
{
......
......@@ -13,6 +13,7 @@
#include <QClipboard>
#include <QShortcut>
#include "imsession.h"
#include "imcontact.h"
#include "dialogfileviewer.h"
#include "manipulator.h"
......@@ -81,6 +82,7 @@ private slots:
void slOnBlinkTimerRefresh();
void slUploadFile();
void slFileDropped(const QString &filepath);
void slAttachmentIdsReceived( const QStringList &fileids, const QString &channelid);
signals:
......
......@@ -7,5 +7,19 @@ QPlainChatEdit::QPlainChatEdit(QObject *parent)
void QPlainChatEdit::dropEvent(QDropEvent *e)
{
qDebug() << "drop event";
QStringList accepted_types;
accepted_types << "jpeg" << "jpg" << "png";
foreach(const QUrl & url, e->mimeData()->urls())
{
QString fname = url.toLocalFile();
QFileInfo info(fname);
if (info.exists())
{
if (accepted_types.contains(info.suffix().trimmed(), Qt::CaseInsensitive))
// do whatever you need to do with fname variable
emit ( siFileDropped(fname) );
}
}
}
......@@ -3,15 +3,23 @@
#include <QObject>
#include <QPlainTextEdit>
#include <QFileInfo>
#include <QUrl>
#include <QMimeData>
#include <QDebug>
class QPlainChatEdit : public QPlainTextEdit
{
Q_OBJECT
public:
QPlainChatEdit(QObject *parent);
protected:
void dropEvent(QDropEvent *e);
signals:
void siFileDropped(const QString filepath);
};
#endif // QPLAINCHATEDIT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment