Check whether portal dialog is failed to open

This commit is contained in:
Ilya Fedin 2021-04-30 06:56:19 +04:00 committed by John Preston
parent 0d96657c33
commit 896eee9841
3 changed files with 48 additions and 4 deletions

View file

@ -172,7 +172,7 @@ bool Get(
} }
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
if (XDP::Use(type)) { if (XDP::Use(type)) {
return XDP::Get( const auto result = XDP::Get(
parent, parent,
files, files,
remoteContent, remoteContent,
@ -180,6 +180,10 @@ bool Get(
filter, filter,
type, type,
startFile); startFile);
if (result.has_value()) {
return *result;
}
} }
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
if (const auto integration = GtkIntegration::Instance()) { if (const auto integration = GtkIntegration::Instance()) {

View file

@ -180,6 +180,10 @@ public:
int exec() override; int exec() override;
bool failedToOpen() {
return _failedToOpen;
}
private: private:
void openPortal(); void openPortal();
void gotResponse( void gotResponse(
@ -219,6 +223,7 @@ private:
Glib::ustring _selectedMimeTypeFilter; Glib::ustring _selectedMimeTypeFilter;
Glib::ustring _selectedNameFilter; Glib::ustring _selectedNameFilter;
std::vector<Glib::ustring> _selectedFiles; std::vector<Glib::ustring> _selectedFiles;
bool _failedToOpen = false;
rpl::event_stream<> _accept; rpl::event_stream<> _accept;
rpl::event_stream<> _reject; rpl::event_stream<> _reject;
@ -432,12 +437,40 @@ void XDPFileDialog::openPortal() {
}), }),
[=](const Glib::RefPtr<Gio::AsyncResult> &result) { [=](const Glib::RefPtr<Gio::AsyncResult> &result) {
try { try {
_dbusConnection->call_finish(result); auto reply = _dbusConnection->call_finish(result);
const auto handle = base::Platform::GlibVariantCast<
Glib::ustring>(reply.get_child(0));
if (handle != requestPath) {
crl::on_main([=] {
_failedToOpen = true;
_reject.fire({});
});
}
} catch (const Glib::Error &e) { } catch (const Glib::Error &e) {
static const auto NotSupportedErrors = {
"org.freedesktop.DBus.Error.ServiceUnknown",
};
const auto errorName =
Gio::DBus::ErrorUtils::get_remote_error(e);
if (!ranges::contains(NotSupportedErrors, errorName)) {
LOG(("XDP File Dialog Error: %1").arg(
QString::fromStdString(e.what())));
}
crl::on_main([=] {
_failedToOpen = true;
_reject.fire({});
});
} catch (const std::exception &e) {
LOG(("XDP File Dialog Error: %1").arg( LOG(("XDP File Dialog Error: %1").arg(
QString::fromStdString(e.what()))); QString::fromStdString(e.what())));
crl::on_main([=] { crl::on_main([=] {
_failedToOpen = true;
_reject.fire({}); _reject.fire({});
}); });
} }
@ -445,6 +478,7 @@ void XDPFileDialog::openPortal() {
_cancellable, _cancellable,
std::string(kXDGDesktopPortalService)); std::string(kXDGDesktopPortalService));
} catch (...) { } catch (...) {
_failedToOpen = true;
_reject.fire({}); _reject.fire({});
} }
} }
@ -502,6 +536,9 @@ int XDPFileDialog::exec() {
setResult(0); setResult(0);
show(); show();
if (failedToOpen()) {
return result();
}
QPointer<QDialog> guard = this; QPointer<QDialog> guard = this;
@ -651,7 +688,7 @@ bool Use(Type type) {
&& (type != Type::ReadFolder || *Version >= 3); && (type != Type::ReadFolder || *Version >= 3);
} }
bool Get( std::optional<bool> Get(
QPointer<QWidget> parent, QPointer<QWidget> parent,
QStringList &files, QStringList &files,
QByteArray &remoteContent, QByteArray &remoteContent,
@ -688,6 +725,9 @@ bool Get(
dialog.selectFile(startFile); dialog.selectFile(startFile);
const auto res = dialog.exec(); const auto res = dialog.exec();
if (dialog.failedToOpen()) {
return std::nullopt;
}
if (type != Type::ReadFolder) { if (type != Type::ReadFolder) {
// Save last used directory for all queries except directory choosing. // Save last used directory for all queries except directory choosing.

View file

@ -16,7 +16,7 @@ namespace XDP {
using Type = ::FileDialog::internal::Type; using Type = ::FileDialog::internal::Type;
bool Use(Type type = Type::ReadFile); bool Use(Type type = Type::ReadFile);
bool Get( std::optional<bool> Get(
QPointer<QWidget> parent, QPointer<QWidget> parent,
QStringList &files, QStringList &files,
QByteArray &remoteContent, QByteArray &remoteContent,