Skip to content

Sharedialog preview be more resilient #8939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions changelog/unreleased/8938
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: Make sharedialog preview be more resilient

We no longer enforce png thumbnails.
We no longer replace the file icon if the thumbnail is invalid.

https://github.com/owncloud/client/issues/8938
https://github.com/owncloud/client/pull/8939
17 changes: 9 additions & 8 deletions src/gui/sharedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ ShareDialog::ShareDialog(QPointer<AccountState> accountState,
// Set icon
QFileInfo f_info(_localPath);
QFileIconProvider icon_provider;
QIcon icon = icon_provider.icon(f_info);
auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
if (pixmap.width() > 0) {
const QIcon icon = icon_provider.icon(f_info);
if (!icon.isNull()) {
auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
_ui->label_icon->setPixmap(pixmap);
} else {
_ui->label_icon->hide();
Expand Down Expand Up @@ -213,16 +213,17 @@ QSize ShareDialog::minimumSizeHint() const
return ocApp()->gui()->settingsDialog()->sizeHintForChild();
}

void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QPixmap &reply)
{
if (statusCode != 200) {
qCWarning(lcSharing) << "Thumbnail status code: " << statusCode;
return;
}

QPixmap p;
p.loadFromData(reply, "PNG");
p = p.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
if (reply.isNull()) {
qCWarning(lcSharing) << "Invalid pixmap";
return;
}
const auto p = reply.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
_ui->label_icon->setPixmap(p);
_ui->label_icon->show();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/sharedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ShareDialog : public QDialog
private slots:
void slotPropfindReceived(const QMap<QString, QString> &result);
void slotPropfindError();
void slotThumbnailFetched(const int &statusCode, const QByteArray &reply);
void slotThumbnailFetched(const int &statusCode, const QPixmap &reply);
void slotAccountStateChanged(int state);

private:
Expand Down
10 changes: 9 additions & 1 deletion src/gui/thumbnailjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ void ThumbnailJob::start()

bool ThumbnailJob::finished()
{
emit jobFinished(reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), reply()->readAll());
const auto result = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QPixmap p;
if (result == 200) {
p.loadFromData(reply()->readAll());
if (p.isNull()) {
qWarning() << Q_FUNC_INFO << "Invalid thumbnail";
}
}
emit jobFinished(result, p);
return true;
}
}
7 changes: 3 additions & 4 deletions src/gui/thumbnailjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public slots:
* @param statusCode the HTTP status code
* @param reply the content of the reply
*
* Signal that the job is done. If the statusCode is 200 (success) reply
* will contain the image data in PNG. If the status code is different the content
* of reply is undefined.
* Signal that the job is done. If the statusCode is 200 (success).
* If the status code is different the content is invalid.
*/
void jobFinished(int statusCode, QByteArray reply);
void jobFinished(int statusCode, QPixmap reply);
private slots:
bool finished() override;
};
Expand Down