Merge pull request #736 from Thulinma/smallFixes

Fixes for images and commandline options
This commit is contained in:
DeepBlueV7.X 2021-09-28 00:52:40 +00:00 committed by GitHub
commit 48ac01ffe1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 15 deletions

View file

@ -158,6 +158,8 @@ PreviewUploadOverlay::setPreview(const QImage &src, const QString &mime)
void void
PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime) PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime)
{ {
nhlog::ui()->info("Pasting {} bytes of data, mimetype {}", data.size(), mime.toStdString());
auto const &split = mime.split('/'); auto const &split = mime.split('/');
auto const &type = split[1]; auto const &type = split[1];
@ -166,6 +168,11 @@ PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime)
filePath_ = "clipboard." + type; filePath_ = "clipboard." + type;
isImage_ = false; isImage_ = false;
if (mime == "image/svg+xml") {
isImage_ = true;
image_.loadFromData(data_, mediaType_.toStdString().c_str());
}
setLabels(type, mime, data_.size()); setLabels(type, mime, data_.size());
init(); init();
} }

View file

@ -176,12 +176,6 @@ main(int argc, char *argv[])
100, 100,
userdata); userdata);
if (app.isSecondary()) {
// open uri in main instance
app.sendMessage(matrixUri.toUtf8());
return 0;
}
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
@ -202,6 +196,15 @@ main(int argc, char *argv[])
parser.process(app); parser.process(app);
// This check needs to happen _after_ process(), so that we actually print help for --help when
// Nheko is already running.
if (app.isSecondary()) {
nhlog::ui()->info("Sending Matrix URL to main application: {}", matrixUri.toStdString());
// open uri in main instance
app.sendMessage(matrixUri.toUtf8());
return 0;
}
app.setWindowIcon(QIcon::fromTheme("nheko", QIcon{":/logos/nheko.png"})); app.setWindowIcon(QIcon::fromTheme("nheko", QIcon{":/logos/nheko.png"}));
http::init(); http::init();

View file

@ -45,10 +45,8 @@ InputBar::paste(bool fromMouse)
{ {
const QMimeData *md = nullptr; const QMimeData *md = nullptr;
if (fromMouse) { if (fromMouse && QGuiApplication::clipboard()->supportsSelection()) {
if (QGuiApplication::clipboard()->supportsSelection()) {
md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection); md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection);
}
} else { } else {
md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard); md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard);
} }
@ -69,8 +67,12 @@ InputBar::insertMimeData(const QMimeData *md)
const auto audio = formats.filter("audio/", Qt::CaseInsensitive); const auto audio = formats.filter("audio/", Qt::CaseInsensitive);
const auto video = formats.filter("video/", Qt::CaseInsensitive); const auto video = formats.filter("video/", Qt::CaseInsensitive);
if (!image.empty() && md->hasImage()) { if (md->hasImage()) {
if (formats.contains("image/svg+xml", Qt::CaseInsensitive)) {
showPreview(*md, "", QStringList("image/svg+xml"));
} else {
showPreview(*md, "", image); showPreview(*md, "", image);
}
} else if (!audio.empty()) { } else if (!audio.empty()) {
showPreview(*md, "", audio); showPreview(*md, "", audio);
} else if (!video.empty()) { } else if (!video.empty()) {
@ -653,9 +655,16 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
new dialogs::PreviewUploadOverlay(ChatPage::instance()); new dialogs::PreviewUploadOverlay(ChatPage::instance());
previewDialog_->setAttribute(Qt::WA_DeleteOnClose); previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
if (source.hasImage()) // Force SVG to _not_ be handled as an image, but as raw data
if (source.hasImage() && (!formats.size() || formats.front() != "image/svg+xml")) {
if (formats.size() && formats.front().startsWith("image/")) {
// known format, keep as-is
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front()); previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
else if (!path.isEmpty()) } else {
// unknown image format, default to image/png
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), "image/png");
}
} else if (!path.isEmpty())
previewDialog_->setPreview(path); previewDialog_->setPreview(path);
else if (!formats.isEmpty()) { else if (!formats.isEmpty()) {
auto mime = formats.first(); auto mime = formats.first();
@ -675,6 +684,12 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
&dialogs::PreviewUploadOverlay::confirmUpload, &dialogs::PreviewUploadOverlay::confirmUpload,
this, this,
[this](const QByteArray data, const QString &mime, const QString &fn) { [this](const QByteArray data, const QString &mime, const QString &fn) {
if (!data.size()) {
nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}",
mime.toStdString(),
fn.toStdString());
return;
}
setUploading(true); setUploading(true);
setText(""); setText("");