Skip to content

Commit 0457100

Browse files
committed
Sharedialog preview be more resilient
Fixes: #8938
1 parent b997f1b commit 0457100

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

changelog/unreleased/8938

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Change: Make sharedialog preview be more resilient
2+
3+
We no longer enforce png thumbnails.
4+
We no longer replace the file icon if the thumbnail is invalid.
5+
6+
https://github.com/owncloud/client/issues/8938
7+
https://github.com/owncloud/client/pull/8939

src/gui/sharedialog.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ ShareDialog::ShareDialog(QPointer<AccountState> accountState,
7373
// Set icon
7474
QFileInfo f_info(_localPath);
7575
QFileIconProvider icon_provider;
76-
QIcon icon = icon_provider.icon(f_info);
77-
auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
78-
if (pixmap.width() > 0) {
76+
const QIcon icon = icon_provider.icon(f_info);
77+
if (!icon.isNull()) {
78+
auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
7979
_ui->label_icon->setPixmap(pixmap);
8080
} else {
8181
_ui->label_icon->hide();
@@ -213,16 +213,17 @@ QSize ShareDialog::minimumSizeHint() const
213213
return ocApp()->gui()->settingsDialog()->sizeHintForChild();
214214
}
215215

216-
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
216+
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QPixmap &reply)
217217
{
218218
if (statusCode != 200) {
219219
qCWarning(lcSharing) << "Thumbnail status code: " << statusCode;
220220
return;
221221
}
222-
223-
QPixmap p;
224-
p.loadFromData(reply, "PNG");
225-
p = p.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
222+
if (reply.isNull()) {
223+
qCWarning(lcSharing) << "Invalid pixmap";
224+
return;
225+
}
226+
const auto p = reply.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
226227
_ui->label_icon->setPixmap(p);
227228
_ui->label_icon->show();
228229
}

src/gui/sharedialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ShareDialog : public QDialog
5353
private slots:
5454
void slotPropfindReceived(const QMap<QString, QString> &result);
5555
void slotPropfindError();
56-
void slotThumbnailFetched(const int &statusCode, const QByteArray &reply);
56+
void slotThumbnailFetched(const int &statusCode, const QPixmap &reply);
5757
void slotAccountStateChanged(int state);
5858

5959
private:

src/gui/thumbnailjob.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ void ThumbnailJob::start()
3232

3333
bool ThumbnailJob::finished()
3434
{
35-
emit jobFinished(reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), reply()->readAll());
35+
const auto result = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
36+
QPixmap p;
37+
if (result == 200) {
38+
p.loadFromData(reply()->readAll());
39+
if (p.isNull()) {
40+
qWarning() << Q_FUNC_INFO << "Invalid thumbnail";
41+
}
42+
}
43+
emit jobFinished(result, p);
3644
return true;
3745
}
3846
}

src/gui/thumbnailjob.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ public slots:
3939
* @param statusCode the HTTP status code
4040
* @param reply the content of the reply
4141
*
42-
* Signal that the job is done. If the statusCode is 200 (success) reply
43-
* will contain the image data in PNG. If the status code is different the content
44-
* of reply is undefined.
42+
* Signal that the job is done. If the statusCode is 200 (success).
43+
* If the status code is different the content is invalid.
4544
*/
46-
void jobFinished(int statusCode, QByteArray reply);
45+
void jobFinished(int statusCode, QPixmap reply);
4746
private slots:
4847
bool finished() override;
4948
};

0 commit comments

Comments
 (0)