mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-28 03:20:57 +00:00
Use Glib::MainLoop instead of QEventLoop in glib code
This commit is contained in:
parent
0e25ef7524
commit
8d75078a42
@ -578,20 +578,23 @@ int XDPFileDialog::exec() {
|
||||
|
||||
// HACK we have to avoid returning until we emit
|
||||
// that the dialog was accepted or rejected
|
||||
QEventLoop loop;
|
||||
const auto context = Glib::MainContext::create();
|
||||
const auto loop = Glib::MainLoop::create(context);
|
||||
g_main_context_push_thread_default(context->gobj());
|
||||
rpl::lifetime lifetime;
|
||||
|
||||
accepted(
|
||||
) | rpl::start_with_next([&] {
|
||||
loop.quit();
|
||||
loop->quit();
|
||||
}, lifetime);
|
||||
|
||||
rejected(
|
||||
) | rpl::start_with_next([&] {
|
||||
loop.quit();
|
||||
loop->quit();
|
||||
}, lifetime);
|
||||
|
||||
loop.exec();
|
||||
loop->run();
|
||||
g_main_context_pop_thread_default(context->gobj());
|
||||
|
||||
if (guard.isNull()) {
|
||||
return QDialog::Rejected;
|
||||
|
@ -33,19 +33,9 @@ constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_c
|
||||
constexpr auto kXDGDesktopPortalOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs;
|
||||
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
|
||||
|
||||
class XDPOpenWithDialog : public QWindow {
|
||||
public:
|
||||
XDPOpenWithDialog(const QString &filepath)
|
||||
: _filepath(filepath.toStdString()) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool exec();
|
||||
|
||||
private:
|
||||
Glib::ustring _filepath;
|
||||
};
|
||||
|
||||
bool XDPOpenWithDialog::exec() {
|
||||
bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||
try {
|
||||
const auto connection = Gio::DBus::Connection::get_sync(
|
||||
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||
@ -69,8 +59,10 @@ bool XDPOpenWithDialog::exec() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto filepathUtf8 = filepath.toUtf8();
|
||||
|
||||
const auto fd = open(
|
||||
_filepath.c_str(),
|
||||
filepathUtf8.constData(),
|
||||
O_RDONLY);
|
||||
|
||||
if (fd == -1) {
|
||||
@ -113,7 +105,9 @@ bool XDPOpenWithDialog::exec() {
|
||||
+ '/'
|
||||
+ handleToken;
|
||||
|
||||
QEventLoop loop;
|
||||
const auto context = Glib::MainContext::create();
|
||||
const auto loop = Glib::MainLoop::create(context);
|
||||
g_main_context_push_thread_default(context->gobj());
|
||||
|
||||
const auto signalId = connection->signal_subscribe(
|
||||
[&](
|
||||
@ -123,7 +117,7 @@ bool XDPOpenWithDialog::exec() {
|
||||
const Glib::ustring &interface_name,
|
||||
const Glib::ustring &signal_name,
|
||||
const Glib::VariantContainerBase ¶meters) {
|
||||
loop.quit();
|
||||
loop->quit();
|
||||
},
|
||||
std::string(kXDGDesktopPortalService),
|
||||
"org.freedesktop.portal.Request",
|
||||
@ -166,9 +160,11 @@ bool XDPOpenWithDialog::exec() {
|
||||
std::string(kXDGDesktopPortalService));
|
||||
|
||||
if (signalId != 0) {
|
||||
QGuiApplicationPrivate::showModalWindow(this);
|
||||
loop.exec();
|
||||
QGuiApplicationPrivate::hideModalWindow(this);
|
||||
QWindow window;
|
||||
QGuiApplicationPrivate::showModalWindow(&window);
|
||||
loop->run();
|
||||
g_main_context_pop_thread_default(context->gobj());
|
||||
QGuiApplicationPrivate::hideModalWindow(&window);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -178,12 +174,6 @@ bool XDPOpenWithDialog::exec() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||
return XDPOpenWithDialog(filepath).exec();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace File
|
||||
} // namespace Platform
|
||||
|
@ -85,12 +85,7 @@ constexpr auto kSnapcraftSettingsInterface = kSnapcraftSettingsService;
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
std::unique_ptr<internal::NotificationServiceWatcher> NSWInstance;
|
||||
|
||||
class PortalAutostart : public QWindow {
|
||||
public:
|
||||
PortalAutostart(bool start, bool silent = false);
|
||||
};
|
||||
|
||||
PortalAutostart::PortalAutostart(bool start, bool silent) {
|
||||
void PortalAutostart(bool start, bool silent) {
|
||||
if (cExeName().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -149,7 +144,9 @@ PortalAutostart::PortalAutostart(bool start, bool silent) {
|
||||
+ '/'
|
||||
+ handleToken;
|
||||
|
||||
QEventLoop loop;
|
||||
const auto context = Glib::MainContext::create();
|
||||
const auto loop = Glib::MainLoop::create(context);
|
||||
g_main_context_push_thread_default(context->gobj());
|
||||
|
||||
const auto signalId = connection->signal_subscribe(
|
||||
[&](
|
||||
@ -175,7 +172,7 @@ PortalAutostart::PortalAutostart(bool start, bool silent) {
|
||||
}
|
||||
}
|
||||
|
||||
loop.quit();
|
||||
loop->quit();
|
||||
},
|
||||
std::string(kXDGDesktopPortalService),
|
||||
"org.freedesktop.portal.Request",
|
||||
@ -199,9 +196,11 @@ PortalAutostart::PortalAutostart(bool start, bool silent) {
|
||||
std::string(kXDGDesktopPortalService));
|
||||
|
||||
if (signalId != 0) {
|
||||
QGuiApplicationPrivate::showModalWindow(this);
|
||||
loop.exec();
|
||||
QGuiApplicationPrivate::hideModalWindow(this);
|
||||
QWindow window;
|
||||
QGuiApplicationPrivate::showModalWindow(&window);
|
||||
loop->run();
|
||||
g_main_context_pop_thread_default(context->gobj());
|
||||
QGuiApplicationPrivate::hideModalWindow(&window);
|
||||
}
|
||||
} catch (const Glib::Error &e) {
|
||||
if (!silent) {
|
||||
@ -211,12 +210,7 @@ PortalAutostart::PortalAutostart(bool start, bool silent) {
|
||||
}
|
||||
}
|
||||
|
||||
class SnapDefaultHandler : public QWindow {
|
||||
public:
|
||||
SnapDefaultHandler(const QString &protocol);
|
||||
};
|
||||
|
||||
SnapDefaultHandler::SnapDefaultHandler(const QString &protocol) {
|
||||
void SnapDefaultHandler(const QString &protocol) {
|
||||
try {
|
||||
const auto connection = Gio::DBus::Connection::get_sync(
|
||||
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||
@ -241,7 +235,9 @@ SnapDefaultHandler::SnapDefaultHandler(const QString &protocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
const auto context = Glib::MainContext::create();
|
||||
const auto loop = Glib::MainLoop::create(context);
|
||||
g_main_context_push_thread_default(context->gobj());
|
||||
|
||||
connection->call(
|
||||
std::string(kSnapcraftSettingsObjectPath),
|
||||
@ -260,13 +256,15 @@ SnapDefaultHandler::SnapDefaultHandler(const QString &protocol) {
|
||||
QString::fromStdString(e.what())));
|
||||
}
|
||||
|
||||
loop.quit();
|
||||
loop->quit();
|
||||
},
|
||||
std::string(kSnapcraftSettingsService));
|
||||
|
||||
QGuiApplicationPrivate::showModalWindow(this);
|
||||
loop.exec();
|
||||
QGuiApplicationPrivate::hideModalWindow(this);
|
||||
QWindow window;
|
||||
QGuiApplicationPrivate::showModalWindow(&window);
|
||||
loop->run();
|
||||
g_main_context_pop_thread_default(context->gobj());
|
||||
QGuiApplicationPrivate::hideModalWindow(&window);
|
||||
} catch (const Glib::Error &e) {
|
||||
LOG(("Snap Default Handler Error: %1").arg(
|
||||
QString::fromStdString(e.what())));
|
||||
|
Loading…
Reference in New Issue
Block a user