Commit cc0e905a authored by scuq's avatar scuq

upload prototype

parent c4c279fe
Pipeline #398 failed with stage
in 5 minutes and 45 seconds
......@@ -36,6 +36,9 @@ dialogChat::dialogChat(QWidget *parent, ImSession *session, manipulator *manipul
this->layout()->setSpacing(2);
this->layout()->setMargin(2);
this->ui->wAttachment->setChannelid(this->contact->getDirectChannelId());
this->ui->wAttachment->setVisible(false);
......@@ -69,9 +72,11 @@ void dialogChat::loadMessageHistrory()
void dialogChat::sendMessage(QString message)
{
if ( this->session->newChannelPost(this->contact->getDirectChannelId(),message) == false ) {
if ( this->session->newChannelPost(this->contact->getDirectChannelId(),message,this->getAttachmentIds()) == false ) {
QMessageBox::warning(this, appname, "Unable to send message!", QMessageBox::Ok);
}
this->resetAttachmentIds();
}
......@@ -97,6 +102,15 @@ void dialogChat::setupSignals()
this, SLOT (slChannelUnreadCountReceived(const int, const QString))
);
connect( this->session, SIGNAL (siUploadFileIdListReady(const QStringList, const QString)),
this, SLOT (slAttachmentIdsReceived(const QStringList, const QString))
);
connect( this->session, SIGNAL (siOnProgressChanged(int, const QString)),
this->ui->wAttachment, SLOT (slOnProgressChanged(int, const QString))
);
//slChannelUnreadCountReceived
}
......@@ -280,11 +294,23 @@ bool dialogChat::eventFilter(QObject *obj, QEvent *event)
}
return true; // do not process this event further
}
if(ke->key() == Qt::Key_Up) {
qDebug() << this->getAttachmentIds().count();
if (this->getAttachmentIds().count() > 0) {
this->sendMessage(this->ui->plainTextEditChatInput->toPlainText());
}
return true; // do not process this event further
}
}
}
}
if(event->type() == QKeyEvent::KeyPress) {
QKeyEvent * ke = static_cast<QKeyEvent*>(event);
if (ke->matches(QKeySequence::Paste)) {
......@@ -292,14 +318,24 @@ bool dialogChat::eventFilter(QObject *obj, QEvent *event)
qDebug() << "clip:";
qDebug() << this->clip->mimeData();
qDebug() << this->clip->text();
if (this->clip->image().sizeInBytes() > 0)
{
QByteArray arr;
//QByteArray arr = QByteArray::fromRawData((const char*)this->clip->image().bits(), this->clip->image().byteCount());
QBuffer buffer(&arr);
buffer.open(QIODevice::WriteOnly);
this->clip->image().save(&buffer);
this->clip->image().save(&buffer, "PNG");
qDebug() << "#################";
qDebug() << arr.size();
//qDebug() << buffer.size();
this->session->uploadFile(this->contact->getDirectChannelId(),"test",arr);
//slOnProgressChanged
this->session->uploadFile(this->contact->getDirectChannelId(),"test.png",arr);
this->ui->wAttachment->setPreviewImage(this->clip->image());
this->ui->wAttachment->setHidden(false);
this->ui->plainTextEditChatInput->setPlaceholderText("Hit Alt-Enter to send attachment without text!");
}
......@@ -806,7 +842,36 @@ void dialogChat::slUploadFile()
{
qDebug() << "slUploadFile";
//this->session->uploadFile(this->contact->getDirectChannelId(),"test");
if (this->ui->wAttachment->isHidden() == true) {
this->ui->wAttachment->setVisible(true);
} else {
this->ui->wAttachment->setVisible(false);
}
}
void dialogChat::slAttachmentIdsReceived(const QStringList &fileids, const QString &channelid)
{
if (channelid == this->contact->getDirectChannelId()) {
this->setAttachmentIds(fileids);
}
}
QStringList dialogChat::getAttachmentIds() const
{
return m_attachmentIds;
}
void dialogChat::setAttachmentIds(const QStringList &attachmentIds)
{
m_attachmentIds = attachmentIds;
}
void dialogChat::resetAttachmentIds()
{
this->m_attachmentIds.empty();
}
QColor dialogChat::getColorChatNick() const
......
......@@ -17,6 +17,7 @@
#include "dialogfileviewer.h"
#include "manipulator.h"
namespace Ui {
class dialogChat;
}
......@@ -60,6 +61,10 @@ public:
QColor getColorChatNick() const;
void setColorChatNick(const QColor &colorchatnick);
QStringList getAttachmentIds() const;
void setAttachmentIds(const QStringList &attachmentIds);
void resetAttachmentIds();
private slots:
void on_plainTextEditChatInput_textChanged();
//void slChannelPostsReceived(const QJsonDocument &replyJson, const QString &channelid);
......@@ -76,6 +81,7 @@ private slots:
void slOnBlinkTimerRefresh();
void slUploadFile();
void slAttachmentIdsReceived( const QStringList &fileids, const QString &channelid);
signals:
void siOnRead(QString channelid);
......@@ -95,6 +101,7 @@ private:
QMap<QString, ImContact*> m_contacts;
QShortcut *m_UploadFile;
QClipboard *clip;
QStringList m_attachmentIds;
void setChatDetails();
void initShortcuts();
void loadMessageHistrory();
......
......@@ -67,45 +67,84 @@
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEditChatInput">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
<item>
<widget class="QPlainTextEdit" name="plainTextEditChatInput">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="widgetAttachment" name="wAttachment" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>widgetAttachment</class>
<extends>QWidget</extends>
<header location="global">widgetattachment.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>plainTextEditChatInput</tabstop>
<tabstop>textBrowserChatOutput</tabstop>
</tabstops>
<resources>
......
......@@ -275,7 +275,7 @@ void ImSession::getChannelPosts(QString channelid)
}
}
bool ImSession::newChannelPost(QString channelid, QString message)
bool ImSession::newChannelPost(QString channelid, QString message, QStringList fileids)
{
if ( (this->getNetworkConnection()) && this->isAuthenticated() ) {
......@@ -285,10 +285,29 @@ bool ImSession::newChannelPost(QString channelid, QString message)
QNetworkRequest req ( url );
qDebug() << "sendMessagesendMessagesendMessagesendMessagesendMessage";
qDebug() << fileids;
QJsonObject messageJson;
messageJson["channel_id"] = channelid;
messageJson["message"] = message;
qDebug() << "------------------------------------------------";
if (fileids.count() > 0) {
QJsonArray _fileids = QJsonArray::fromStringList(fileids);
qDebug() << _fileids;
messageJson.insert("file_ids",_fileids);
}
qDebug() << QJsonDocument(messageJson).toJson();
qDebug() << "------------------------------------------------";
req.setRawHeader("Content-Type", "application/json");
req.setRawHeader("X-Requested-With", "XMLHttpRequest");
......@@ -321,14 +340,17 @@ bool ImSession::uploadFile(QString channelid, QString filename, QByteArray conte
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"files\"; filename=\"%1\"").arg(filename)));
QBuffer *contentbuffer = new QBuffer();
//QBuffer *contentbuffer = new QBuffer(content);
//QBuffer *contentbuffer = new QBuffer(&content);
contentbuffer->setData(content);
contentbuffer->open(QIODevice::ReadOnly);
//contentbuffer->setData(content);
//contentbuffer->open(QIODevice::ReadOnly);
filePart.setBody(content);
filePart.setBodyDevice(contentbuffer);
contentbuffer->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
//filePart.setBodyDevice(contentbuffer);
//contentbuffer->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
multiPart->append(textPart);
......@@ -339,6 +361,15 @@ bool ImSession::uploadFile(QString channelid, QString filename, QByteArray conte
qDebug() << QString("Uploading file %1 to %2 for channel %3").arg(filename, url.toString(), channelid);
QNetworkReply *reply = m_WebCtrlProgress.post(req,multiPart);
reply->setProperty("channel_id",channelid);
reply->setProperty("filename",filename);
connect( reply, SIGNAL (uploadProgress(qint64, qint64)),
this, SLOT (slUploadProgress(qint64, qint64))
);
multiPart->setParent(reply);
netReplies[reply] = QString("mmapi::uploadFile__%1").arg( channelid );
......@@ -474,9 +505,6 @@ void ImSession::setupSignals()
connect( &m_WebCtrlProgress, SIGNAL (finished(QNetworkReply*)),
this, SLOT (parseNetworkResponse(QNetworkReply*))
);
connect( &m_WebCtrlProgress, SIGNAL (uploadProgress(qint64, qint64)),
this, SLOT (slUploadProgress(qint64, qint64))
);
connect( this, SIGNAL (siMmAuthenticationSuccessful(const QJsonDocument)),
this, SLOT (slOnMmAuthenticationSuccessful(const QJsonDocument))
......@@ -502,6 +530,10 @@ void ImSession::setupSignals()
this, SLOT (slReplyChannelListReceived(const QJsonDocument))
);
connect( this, SIGNAL (siFileUploaded(const QJsonDocument, const QString)),
this, SLOT (slFileUploaded(const QJsonDocument, const QString))
);
connect( idled, SIGNAL (siIdle()),
this, SLOT (slOnIdle())
);
......@@ -816,10 +848,9 @@ void ImSession::parseNetworkResponse(QNetworkReply *pReply)
emit siChannelPosted( QJsonDocument::fromJson(pReply->readAll()), _channelid );
}
if (callingFuncName.startsWith( "mmapi::uploadFile" )) {
qDebug() << "mmapi::uploadFile response!!!";
QString _channelid = callingFuncName.split("__")[1];
qDebug().noquote() << "getChannelPosts: " << QJsonDocument::fromJson( pReply->readAll() ).toJson(QJsonDocument::Indented);
//emit siChannelPosted( QJsonDocument::fromJson(pReply->readAll()), _channelid );
emit siFileUploaded( QJsonDocument::fromJson(pReply->readAll()), _channelid );
//qDebug().noquote() << "getChannelPosts: " << QJsonDocument::fromJson( pReply->readAll() ).toJson(QJsonDocument::Indented);
}
if (callingFuncName.startsWith( "mmapi::requestUnreadCount" )) {
//qDebug().noquote() << "getChannelPosts: " << QJsonDocument::fromJson( pReply->readAll() ).toJson(QJsonDocument::Indented);
......@@ -1038,7 +1069,29 @@ void ImSession::slReplyChannelListReceived(const QJsonDocument &replyJson)
this->requestUnreadCount();
qDebug() << QString("%1: channel list received.").arg(this->metaObject()->className());
qDebug() << QString("%1: channel list received.").arg(this->metaObject()->className());
}
void ImSession::slFileUploaded(const QJsonDocument &replyJson, const QString &channelid)
{
QStringList _uploaded_fileids;
QJsonObject uploaded_response = replyJson.object();
if (uploaded_response.keys().contains("file_infos")) {
QJsonArray _files = uploaded_response["file_infos"].toArray();
foreach (const QJsonValue & v,_files) {
qDebug() << v.toObject();
_uploaded_fileids << v.toObject()["id"].toString();
}
}
emit (siUploadFileIdListReady( _uploaded_fileids, channelid ) );
}
void ImSession::slReplyUserStatusReceived(const QJsonDocument &replyJson)
......@@ -1245,6 +1298,17 @@ void ImSession::slOnDisconnected()
void ImSession::slUploadProgress(qint64 read, qint64 total)
{
qDebug() << read << " " << total;
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
int pp = 0;
if (total > 0) {
pp = 100*read/total;
}
if (pp > 0) {
emit ( siOnProgressChanged(pp, reply->property("channel_id").toString()) );
}
}
......@@ -45,7 +45,7 @@ public:
void getRemoteTeams();
void getChannelsForUser();
void getChannelPosts(QString channelid);
bool newChannelPost(QString channelid, QString message);
bool newChannelPost(QString channelid, QString message, QStringList fileids);
bool uploadFile(QString channelid, QString filename, QByteArray content);
void requestRemoteViewChannel(QString channelid);
void getRemoteFile(QString fileid, bool preview);
......@@ -125,6 +125,9 @@ signals:
void siUserStatusReceived( const QJsonDocument &replyJson );
void siChannelPostsHistoryReceived( QDateTime timestamp, QString message, bool hasAttachment, bool hasImage, QMap<QString, QVariant> imageProperties, QString channelid, QString sendername, bool historic, int msgcounthint, int longestsendernamelen );
void siChannelPosted( const QJsonDocument &replyJson, const QString &channelid );
void siFileUploaded( const QJsonDocument &replyJson, const QString &channelid );
void siUploadFileIdListReady( const QStringList &fileids, const QString &channelid);
void siOnProgressChanged(int progress, const QString &channelid);
void siChannelUnreadCountReceived( const int &unreadcount, const QString &channelid );
void siFileDownloaded( const QString &fileid, QByteArray filedata );
void siMessageReceived(QDateTime timestamp, QString message, bool hasAttachment, bool hasImage, QMap<QString, QVariant> imageProperties, QString channelid, QString sendername, bool historic, int msgcounthint, int longestsendernamelen);
......@@ -143,6 +146,7 @@ private slots:
void slReplyUserListReceived(const QJsonDocument &replyJson);
void slReplyTeamListReceived(const QJsonDocument &replyJson);
void slReplyChannelListReceived(const QJsonDocument &replyJson);
void slFileUploaded( const QJsonDocument &replyJson, const QString &channelid );
void slReplyUserStatusReceived(const QJsonDocument &replyJson);
void slOnMmAuthenticationFail(const QJsonDocument &replyJson);
void slOnTimeoutTimerStatusRefresh();
......
......@@ -51,7 +51,8 @@ SOURCES += \
dialogfileviewer.cpp \
qclicklabel.cpp \
aictrayicon.cpp \
statuslabel.cpp
statuslabel.cpp \
widgetattachment.cpp
HEADERS += \
qmmainwindow.h \
......@@ -77,7 +78,8 @@ HEADERS += \
dialogfileviewer.h \
qclicklabel.h \
aictrayicon.h \
statuslabel.h
statuslabel.h \
widgetattachment.h
FORMS += \
qmmainwindow.ui \
......@@ -86,7 +88,8 @@ FORMS += \
dialogpreferences.ui \
dialogaccountdetail.ui \
dialogchat.ui \
dialogfileviewer.ui
dialogfileviewer.ui \
widgetattachment.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
......
#include "widgetattachment.h"
#include "ui_widgetattachment.h"
widgetAttachment::widgetAttachment(QWidget *parent) :
QWidget(parent),
ui(new Ui::widgetAttachment)
{
ui->setupUi(this);
this->ui->progressBarUpload->setMinimum(0);
this->ui->progressBarUpload->setMaximum(100);
this->resetProgress();
}
widgetAttachment::~widgetAttachment()
{
delete ui;
}
QImage widgetAttachment::getPreviewImage() const
{
return m_PreviewImage;
}
void widgetAttachment::setPreviewImage(const QImage &PreviewImage)
{
m_PreviewImage = PreviewImage;
QPixmap _pxmp;
_pxmp.convertFromImage(PreviewImage);
this->ui->labelPreview->setPixmap(_pxmp);
}
int widgetAttachment::getProgress() const
{
return m_progress;
}
void widgetAttachment::setProgress(int progress)
{
m_progress = progress;
this->ui->progressBarUpload->setValue(progress);
}
void widgetAttachment::resetProgress()
{
this->ui->progressBarUpload->setValue(0);
}
void widgetAttachment::slOnProgressChanged(int progress, const QString &channelid)
{
if (this->getChannelid() == channelid) {
qDebug() << "progress: " << progress;
if (progress > this->getProgress()) {
this->setProgress(progress);
}
}
}
QString widgetAttachment::getChannelid() const
{
return m_channelid;
}
void widgetAttachment::setChannelid(const QString &channelid)
{
m_channelid = channelid;
}
#ifndef WIDGETATTACHMENT_H
#define WIDGETATTACHMENT_H
#include <QWidget>
#include <QDebug>
namespace Ui {
class widgetAttachment;
}
class widgetAttachment : public QWidget
{
Q_OBJECT
public:
explicit widgetAttachment(QWidget *parent = nullptr);
~widgetAttachment();
QImage getPreviewImage() const;
void setPreviewImage(const QImage &PreviewImage);
int getProgress() const;
void setProgress(int progress);
void resetProgress();
QString getChannelid() const;
void setChannelid(const QString &channelid);
public slots:
void slOnProgressChanged(int progress, const QString &channelid);
private:
Ui::widgetAttachment *ui;
QImage m_PreviewImage;
int m_progress;
QString m_channelid;
};
#endif // WIDGETATTACHMENT_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>widgetAttachment</class>
<widget class="QWidget" name="widgetAttachment">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<height>221</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>