Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

[Updated] Implements #132: Pasting images into room #180

Merged
merged 8 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(SRC_FILES
# Dialogs
src/dialogs/CreateRoom.cc
src/dialogs/ImageOverlay.cc
src/dialogs/PreviewImageOverlay.cc
src/dialogs/InviteUsers.cc
src/dialogs/JoinRoom.cc
src/dialogs/LeaveRoom.cc
Expand Down Expand Up @@ -224,6 +225,7 @@ qt5_wrap_cpp(MOC_HEADERS
# Dialogs
include/dialogs/CreateRoom.h
include/dialogs/ImageOverlay.h
include/dialogs/PreviewImageOverlay.h
include/dialogs/InviteUsers.h
include/dialogs/JoinRoom.h
include/dialogs/LeaveRoom.h
Expand Down
19 changes: 14 additions & 5 deletions include/MatrixClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ class MatrixClient : public QNetworkAccessManager
void downloadImage(const QString &event_id, const QUrl &url);
void downloadFile(const QString &event_id, const QUrl &url);
void messages(const QString &room_id, const QString &from_token, int limit = 30) noexcept;
void uploadImage(const QString &roomid, const QString &filename);
void uploadFile(const QString &roomid, const QString &filename);
void uploadAudio(const QString &roomid, const QString &filename);
void uploadImage(const QString &roomid,
const QSharedPointer<QIODevice> data,
const QString &filename);
void uploadFile(const QString &roomid,
const QSharedPointer<QIODevice> data,
const QString &filename);
void uploadAudio(const QString &roomid,
const QSharedPointer<QIODevice> data,
const QString &filename);
void joinRoom(const QString &roomIdOrAlias);
void leaveRoom(const QString &roomId);
void sendTypingNotification(const QString &roomid, int timeoutInMillis = 20000);
Expand Down Expand Up @@ -94,7 +100,10 @@ public slots:
const QString &homeserver,
const QString &token);
void versionSuccess();
void imageUploaded(const QString &roomid, const QString &filename, const QString &url);
void imageUploaded(const QString &roomid,
const QSharedPointer<QIODevice> data,
const QString &filename,
const QString &url);
void fileUploaded(const QString &roomid, const QString &filename, const QString &url);
void audioUploaded(const QString &roomid, const QString &filename, const QString &url);

Expand Down Expand Up @@ -123,7 +132,7 @@ public slots:
void roomCreationFailed(const QString &msg);

private:
QNetworkReply *makeUploadRequest(const QString &filename);
QNetworkReply *makeUploadRequest(QSharedPointer<QIODevice> iodev);

// Client API prefix.
QString clientApiUrl_;
Expand Down
18 changes: 15 additions & 3 deletions include/TextInputWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
#include "FlatButton.h"
#include "LoadingIndicator.h"

#include "dialogs/PreviewImageOverlay.h"

#include "emoji/PickButton.h"

namespace dialogs {
class PreviewImageOverlay;
}

class FilteredTextEdit : public QTextEdit
{
Q_OBJECT
Expand All @@ -48,16 +54,22 @@ class FilteredTextEdit : public QTextEdit
void stoppedTyping();
void message(QString);
void command(QString name, QString args);
void image(const QSharedPointer<QIODevice> iodev, const QString &img_name);

protected:
void keyPressEvent(QKeyEvent *event) override;
bool canInsertFromMimeData(const QMimeData *source) const override;
void insertFromMimeData(const QMimeData *source) override;

private:
std::deque<QString> true_history_, working_history_;
size_t history_index_;
QTimer *typingTimer_;

dialogs::PreviewImageOverlay previewDialog_;

void textChanged();
void receiveImage(const QByteArray img, const QString &img_name);
void afterCompletion(int);
};

Expand All @@ -83,9 +95,9 @@ private slots:
void sendTextMessage(QString msg);
void sendEmoteMessage(QString msg);

void uploadImage(QString filename);
void uploadFile(QString filename);
void uploadAudio(QString filename);
void uploadImage(QSharedPointer<QIODevice> data, const QString &filename);
void uploadFile(QSharedPointer<QIODevice> data, const QString &filename);
void uploadAudio(QSharedPointer<QIODevice> data, const QString &filename);

void sendJoinRoomRequest(const QString &room);

Expand Down
57 changes: 57 additions & 0 deletions include/dialogs/PreviewImageOverlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QLabel>
#include <QLineEdit>
#include <QPixmap>
#include <QWidget>

#include "FlatButton.h"

class QMimeData;

namespace dialogs {

class PreviewImageOverlay : public QWidget
{
Q_OBJECT
public:
PreviewImageOverlay(QWidget *parent = nullptr);

void setImageAndCreate(const QByteArray data, const QString &type);
void setImageAndCreate(const QString &path);

signals:
void confirmImageUpload(const QByteArray data, const QString &img_name);

private:
void init();

QPixmap image_;
QByteArray imageData_;
QString imagePath_;

QLabel titleLabel_;
QLabel imageLabel_;
QLineEdit imageName_;

FlatButton upload_;
FlatButton cancel_;
};
} // dialogs
10 changes: 7 additions & 3 deletions include/timeline/TimelineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class TimelineView : public QWidget
void addUserMessage(mtx::events::MessageType ty, const QString &msg);

template<class Widget, mtx::events::MessageType MsgType>
void addUserMessage(const QString &url, const QString &filename);
void addUserMessage(const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename);
void updatePendingMessage(int txn_id, QString event_id);
void scrollDown();
void addDateSeparator(QDateTime datetime, int position);
Expand Down Expand Up @@ -216,11 +218,13 @@ private slots:

template<class Widget, mtx::events::MessageType MsgType>
void
TimelineView::addUserMessage(const QString &url, const QString &filename)
TimelineView::addUserMessage(const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename)
{
auto with_sender = lastSender_ != local_user_;

auto widget = new Widget(client_, url, filename, this);
auto widget = new Widget(client_, url, data, filename, this);

TimelineItem *view_item =
new TimelineItem(widget, local_user_, with_sender, scroll_widget_);
Expand Down
7 changes: 6 additions & 1 deletion include/timeline/TimelineViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <mtx.hpp>

class QFile;

class MatrixClient;
class RoomInfoListItem;
class TimelineView;
Expand Down Expand Up @@ -64,7 +66,10 @@ public slots:
void setHistoryView(const QString &room_id);
void queueTextMessage(const QString &msg);
void queueEmoteMessage(const QString &msg);
void queueImageMessage(const QString &roomid, const QString &filename, const QString &url);
void queueImageMessage(const QString &roomid,
const QSharedPointer<QIODevice> data,
const QString &filename,
const QString &url);
void queueFileMessage(const QString &roomid, const QString &filename, const QString &url);
void queueAudioMessage(const QString &roomid, const QString &filename, const QString &url);

Expand Down
1 change: 1 addition & 0 deletions include/timeline/widgets/AudioItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AudioItem : public QWidget

AudioItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
QWidget *parent = nullptr);

Expand Down
1 change: 1 addition & 0 deletions include/timeline/widgets/FileItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FileItem : public QWidget

FileItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Unlike with image/audio/video, I'm not sure we can/should do much in the client with the data of an arbitrary opaque file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because TimelineView::addUserMessage takes in a generic type Widget, which happens to be one of the four FileItem, ImageItem, AudioItem, and VideoItem. Therefore, we need those types to have the same interface (parameters to the constructor).

Copy link
Contributor

@Ralith Ralith Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly happy about having never-used arguments making things confusing on both ends for the sake of convenience to a template. That said, any refactoring of addUserMessage is probably best done separately from this PR.

const QString &filename,
QWidget *parent = nullptr);

Expand Down
1 change: 1 addition & 0 deletions include/timeline/widgets/ImageItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ImageItem : public QWidget

ImageItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
QWidget *parent = nullptr);

Expand Down
1 change: 1 addition & 0 deletions include/timeline/widgets/VideoItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class VideoItem : public QWidget

VideoItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
QWidget *parent = nullptr);

Expand Down
9 changes: 3 additions & 6 deletions resources/styles/nheko-dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,13 @@ dialogs--LeaveRoom,
dialogs--CreateRoom,
dialogs--InviteUsers,
dialogs--ReadReceipts,
dialogs--JoinRoom {
background-color: #383c4a;
color: #caccd1;
}

QListWidget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this line deleted?

Copy link
Contributor Author

@christarazi christarazi Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops that was accidental. It probably slipped in when I was doing a rebase onto upstream from my previous PR. It has been fixed. Thanks for catching this.

dialogs--JoinRoom,
dialogs--PreviewImageOverlay {
background-color: #383c4a;
color: #caccd1;
}

QListWidget,
WelcomePage,
LoginPage,
RegisterPage {
Expand Down
7 changes: 2 additions & 5 deletions resources/styles/nheko.qss
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ dialogs--LeaveRoom,
dialogs--CreateRoom,
dialogs--InviteUsers,
dialogs--ReadReceipts,
dialogs--JoinRoom {
background-color: white;
color: #333;
}

dialogs--JoinRoom,
dialogs--PreviewImageOverlay,
QListWidget {
background-color: white;
color: #333;
Expand Down
31 changes: 20 additions & 11 deletions src/ChatPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,36 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
client_.data(),
&MatrixClient::joinRoom);

connect(text_input_, &TextInputWidget::uploadImage, this, [=](QString filename) {
client_->uploadImage(current_room_, filename);
});
connect(text_input_,
&TextInputWidget::uploadImage,
this,
[=](QSharedPointer<QIODevice> data, const QString &fn) {
client_->uploadImage(current_room_, data, fn);
});

connect(text_input_, &TextInputWidget::uploadFile, this, [=](QString filename) {
client_->uploadFile(current_room_, filename);
});
connect(text_input_,
&TextInputWidget::uploadFile,
this,
[=](QSharedPointer<QIODevice> data, const QString &fn) {
client_->uploadFile(current_room_, data, fn);
});

connect(text_input_, &TextInputWidget::uploadAudio, this, [=](QString filename) {
client_->uploadAudio(current_room_, filename);
});
connect(text_input_,
&TextInputWidget::uploadAudio,
this,
[=](QSharedPointer<QIODevice> data, const QString &fn) {
client_->uploadAudio(current_room_, data, fn);
});

connect(
client_.data(), &MatrixClient::roomCreationFailed, this, &ChatPage::showNotification);
connect(client_.data(), &MatrixClient::joinFailed, this, &ChatPage::showNotification);
connect(client_.data(),
&MatrixClient::imageUploaded,
this,
[=](QString roomid, QString filename, QString url) {
[=](QString roomid, QSharedPointer<QIODevice> data, QString filename, QString url) {
text_input_->hideUploadSpinner();
view_manager_->queueImageMessage(roomid, filename, url);
view_manager_->queueImageMessage(roomid, data, filename, url);
});
connect(client_.data(),
&MatrixClient::fileUploaded,
Expand Down
Loading