-
Notifications
You must be signed in to change notification settings - Fork 65
Implement #132: Support pasting images into room #138
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the other issues I highlighted, I don't see any graceful handling for the case where a user attempts to enter both text and imagery in the same message. It looks like text entered alongside an image is accepted and then silently discarded, which is a bad user experience.
src/TextInputWidget.cc
Outdated
@@ -93,12 +97,50 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event) | |||
} | |||
break; | |||
} | |||
case Qt::Key_V: { | |||
if (event->modifiers() == Qt::ControlModifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding this is incorrect. You cannot make assumptions about what keybind any given system uses to express "paste." Try using QKeySequence::Copy
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further review, given that Qt handles MIME clipboards in the first place, it's actually not obvious to me that handling pasting by hand like this is even necessary at all, given the other changes in this PR. If it truly is, some comments explaining why Qt's default behavior is inadequate would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure of what you mean. If you mean, that Qt has built in support out-of-the-box for pasting images into a QTextEdit, then I have not seen any document which suggests that. The fact that QTextEdit::insertFromMimeData
and QTextEdit::canInsertFromMimeData
exist suggest that it does not have built in support. However, this is just an educated guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to guess. What happens if you disable this hardcoding but retain the overrides to those methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I removed the explicit call to insertFromMimeData()
(the entire case in the switch statement), and kept just the overrides. It still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/TextInputWidget.cc
Outdated
QImage img = qvariant_cast<QImage>(source->imageData()); | ||
pastedImagePath_ = QDir::tempPath() + '/' + "nheko_pasted_img.png"; | ||
|
||
// Save image into temporary path to be loaded later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason for this to hit disk, and doing so introduces a number of bugs. Leave the image in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I write to disk is because MatrixClient::uploadImage()
takes in a QString
that represents a file path to an image. This means I would have to overload uploadImage
or create a new function which accepts an image from memory. If you think that is worth doing, I will implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably refactor uploadImage
to accept data from arbitrary sources, e.g. by taking a QIODevice
. This change to the PR is necessary for a number of reasons; most immediately, the current code introduces system-global state, which makes it unsafe to have multiple instances of the class even in entirely different processes. It is also poor behavior to silently re-encode submitted images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create a new pull request with the requested changes.
Another concern is the handling of pastes that include both image(s) and text concatenated in a single piece of MIME data, along with a possible alternative plaintext representation. It's worth note that Matrix can support this type of mixed-content message by placing the alternative plaintext in |
@Ralith On my local branch, I made the change to allow both images and text in the same message. I did this by checking if Edit: Fixed in |
How exactly I can use this feature? If I copy-paste an image into the text field I just get the file path of that image and nothing happens when I hit enter. |
Didn't realize that X11 treats copying files differently in regards to setting the MIME type. I was testing my implementation by right-clicking an image in my browser and hitting "Copy image". This is now fixed in |
Now that I think of it, we might as well handle all files that are pasted in the text box. The commit in |
This also doesn't work on macOS. Instead of the actual image a generic image placeholder is sent. Another issue is that the image is rendered in the text field and only a thin slice of it is visible which makes it a bad user experience. It would be better to show a confirmation popup to send the image or file (like Telegram does). I'm against mixing images and text in the same messages cause it would be quite difficult to implement and it doesn't have any real benefit in my opinion. |
Interesting, seems like handling MIME data was more convoluted than I thought. I will look into it.
You can scroll using the mouse wheel to see the image, but I agree, this can be improved.
Alright, I can revert that commit if that's what you'd prefer.
…On November 28, 2017 4:26:25 AM PST, mujx ***@***.***> wrote:
This also doesn't work on macOS. Instead of the actual image a generic
image placeholder is sent.
Another issue is that the image is rendered in the text field and only
a thin slice of it is visible which makes it a bad user experience. It
would be better to show a confirmation popup to send the image or file
(like Telegram does).
I'm against mixing images and text in the same messages cause it would
be quite difficult to implement and it doesn't have any real benefit in
my opinion.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#138 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Do you know of a method to test macOS binaries on Linux? I do not own a Mac.
…On November 28, 2017 4:26:25 AM PST, mujx ***@***.***> wrote:
This also doesn't work on macOS. Instead of the actual image a generic
image placeholder is sent.
Another issue is that the image is rendered in the text field and only
a thin slice of it is visible which makes it a bad user experience. It
would be better to show a confirmation popup to send the image or file
(like Telegram does).
I'm against mixing images and text in the same messages cause it would
be quite difficult to implement and it doesn't have any real benefit in
my opinion.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#138 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
@christarazi I could find a fix for mac later, it's not super critical. The important part is to have that popup when a pasted file or image is detected and possibly allow the user to edit the name of the file before sending it, so nothing would be pasted into the text field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mujx that (opening a dialog for) sending pasted (or dropped) files immediately makes more sense than handling them as if they were part of the input text, at least so long as nheko doesn't have advanced formatting capabilities.
@@ -229,6 +280,9 @@ TextInputWidget::TextInputWidget(QWidget *parent) | |||
connect(sendFileBtn_, SIGNAL(clicked()), this, SLOT(openFileSelection())); | |||
connect(input_, &FilteredTextEdit::message, this, &TextInputWidget::sendTextMessage); | |||
connect(input_, &FilteredTextEdit::command, this, &TextInputWidget::command); | |||
connect(input_, &FilteredTextEdit::image, this, [=](QString name) { | |||
emit uploadImage(name); | |||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can be written connect(input_, &FilteredTextEdit::image, this, uploadImage)
I've created a new PR (#180) which adds a preview dialog for pasting images and also modifies the |
Implements #132 to allow pasting of images using ctrl-v.