mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Better image overlay handling when downloading
- hides the overlay when prompting for download location - cancel re-shows the dialog - success closes the overlay - would be nice to have a return code from the download fn in mtxclient. Closes #140
This commit is contained in:
parent
b41e2e6f18
commit
d0a1e81f43
3 changed files with 20 additions and 6 deletions
|
@ -1271,7 +1271,7 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event)
|
||||||
emit nextPendingMessage();
|
emit nextPendingMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
TimelineModel::saveMedia(QString eventId) const
|
TimelineModel::saveMedia(QString eventId) const
|
||||||
{
|
{
|
||||||
mtx::events::collections::TimelineEvents event = events.value(eventId);
|
mtx::events::collections::TimelineEvents event = events.value(eventId);
|
||||||
|
@ -1309,7 +1309,7 @@ TimelineModel::saveMedia(QString eventId) const
|
||||||
manager_->getWidget(), dialogTitle, openLocation, filterString);
|
manager_->getWidget(), dialogTitle, openLocation, filterString);
|
||||||
|
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
const auto url = mxcUrl.toStdString();
|
const auto url = mxcUrl.toStdString();
|
||||||
|
|
||||||
|
@ -1340,10 +1340,13 @@ TimelineModel::saveMedia(QString eventId) const
|
||||||
|
|
||||||
file.write(QByteArray(temp.data(), (int)temp.size()));
|
file.write(QByteArray(temp.data(), (int)temp.size()));
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
return;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
nhlog::ui()->warn("Error while saving file to: {}", e.what());
|
nhlog::ui()->warn("Error while saving file to: {}", e.what());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -186,7 +186,7 @@ public:
|
||||||
Q_INVOKABLE int idToIndex(QString id) const;
|
Q_INVOKABLE int idToIndex(QString id) const;
|
||||||
Q_INVOKABLE QString indexToId(int index) const;
|
Q_INVOKABLE QString indexToId(int index) const;
|
||||||
Q_INVOKABLE void cacheMedia(QString eventId);
|
Q_INVOKABLE void cacheMedia(QString eventId);
|
||||||
Q_INVOKABLE void saveMedia(QString eventId) const;
|
Q_INVOKABLE bool saveMedia(QString eventId) const;
|
||||||
|
|
||||||
void addEvents(const mtx::responses::Timeline &events);
|
void addEvents(const mtx::responses::Timeline &events);
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
@ -175,9 +175,20 @@ TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const
|
||||||
|
|
||||||
auto imgDialog = new dialogs::ImageOverlay(pixmap);
|
auto imgDialog = new dialogs::ImageOverlay(pixmap);
|
||||||
imgDialog->showFullScreen();
|
imgDialog->showFullScreen();
|
||||||
connect(imgDialog, &dialogs::ImageOverlay::saving, timeline_, [this, eventId]() {
|
connect(imgDialog,
|
||||||
timeline_->saveMedia(eventId);
|
&dialogs::ImageOverlay::saving,
|
||||||
});
|
timeline_,
|
||||||
|
[this, eventId, imgDialog]() {
|
||||||
|
// hide the overlay while presenting the save dialog for better
|
||||||
|
// cross platform support.
|
||||||
|
imgDialog->hide();
|
||||||
|
|
||||||
|
if (!timeline_->saveMedia(eventId)) {
|
||||||
|
imgDialog->show();
|
||||||
|
} else {
|
||||||
|
imgDialog->close();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue