2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-07 01:55:12 +00:00

Move glib usage to glibmm

This commit is contained in:
Ilya Fedin
2021-02-28 06:34:41 +04:00
committed by John Preston
parent b38d6667c4
commit 8042a83fd2
22 changed files with 594 additions and 642 deletions

View File

@@ -16,11 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QDesktopServices>
extern "C" {
#undef signals
#include <gio/gio.h>
#define signals public
} // extern "C"
#include <glibmm.h>
#include <giomm.h>
using Platform::internal::GtkIntegration;
@@ -28,12 +25,15 @@ namespace Platform {
namespace File {
void UnsafeOpenUrl(const QString &url) {
if (!g_app_info_launch_default_for_uri(
url.toUtf8().constData(),
nullptr,
nullptr)) {
QDesktopServices::openUrl(url);
try {
if (Gio::AppInfo::launch_default_for_uri(url.toStdString())) {
return;
}
} catch (const Glib::Error &e) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
}
QDesktopServices::openUrl(url);
}
void UnsafeOpenEmailLink(const QString &email) {
@@ -46,27 +46,27 @@ bool UnsafeShowOpenWith(const QString &filepath) {
}
if (const auto integration = GtkIntegration::Instance()) {
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
return integration->showOpenWithDialog(absolutePath);
return integration->showOpenWithDialog(filepath);
}
return false;
}
void UnsafeLaunch(const QString &filepath) {
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
if (!g_app_info_launch_default_for_uri(
g_filename_to_uri(
absolutePath.toUtf8().constData(),
nullptr,
nullptr),
nullptr,
nullptr)) {
if (!UnsafeShowOpenWith(filepath)) {
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
try {
if (Gio::AppInfo::launch_default_for_uri(
Glib::filename_to_uri(filepath.toStdString()))) {
return;
}
} catch (const Glib::Error &e) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
}
if (UnsafeShowOpenWith(filepath)) {
return;
}
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
}
} // namespace File