Skip to content

Commit

Permalink
Don't link glib with DESKTOP_APP_DISABLE_DBUS_INTEGRATION
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Sep 11, 2021
1 parent 69613a8 commit 50d2d31
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ if (DESKTOP_APP_DISABLE_DBUS_INTEGRATION)
remove_target_sources(lib_base ${src_loc}
base/platform/linux/base_linux_dbus_utilities.cpp
base/platform/linux/base_linux_dbus_utilities.h
base/platform/linux/base_linux_glibmm_helper.h
base/platform/linux/base_linux_xdp_utilities.cpp
base/platform/linux/base_linux_xdp_utilities.h
base/platform/linux/base_system_media_controls_linux.cpp
Expand Down Expand Up @@ -224,11 +225,13 @@ PUBLIC
if (WIN32)
nuget_add_winrt(lib_base)
elseif (LINUX)
target_link_libraries(lib_base
PUBLIC
desktop-app::external_glibmm
desktop-app::external_glib
)
if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION)
target_link_libraries(lib_base
PUBLIC
desktop-app::external_glibmm
desktop-app::external_glib
)
endif()

if (NOT DESKTOP_APP_DISABLE_X11_INTEGRATION)
target_link_libraries(lib_base
Expand Down
18 changes: 11 additions & 7 deletions base/platform/linux/base_file_utilities_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include <QtCore/QDir>
#include <QtGui/QDesktopServices>

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <glibmm.h>
#include <giomm.h>
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -92,7 +94,6 @@ bool DBusShowInFolder(const QString &filepath) {

return false;
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

bool ProcessShowInFolder(const QString &filepath) {
const auto fileManager = [] {
Expand Down Expand Up @@ -137,6 +138,7 @@ bool ProcessShowInFolder(const QString &filepath) {

return false;
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

} // namespace

Expand All @@ -149,27 +151,29 @@ bool ShowInFolder(const QString &filepath) {
if (PortalShowInFolder(filepath)) {
return true;
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

if (ProcessShowInFolder(filepath)) {
return true;
}

const auto folder = QFileInfo(filepath).absolutePath();
try {
if (Gio::AppInfo::launch_default_for_uri(
Glib::filename_to_uri(folder.toStdString()))) {
Glib::filename_to_uri(
Glib::path_get_dirname(filepath.toStdString())))) {
return true;
}
} catch (...) {
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

const auto folder = QUrl::fromLocalFile(
QFileInfo(filepath).absolutePath());

const auto qUrlFolder = QUrl::fromLocalFile(folder);
if (QDesktopServices::openUrl(qUrlFolder)) {
if (QDesktopServices::openUrl(folder)) {
return true;
}

if (QProcess::startDetached("xdg-open", { qUrlFolder.toEncoded() })) {
if (QProcess::startDetached("xdg-open", { folder.toEncoded() })) {
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions base/platform/linux/base_network_reachability_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
//
#include "base/platform/linux/base_network_reachability_linux.h"

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <gio/gio.h>
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

namespace base::Platform {

// glib is better on linux due to portal support
std::optional<bool> NetworkAvailable() {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
// crashes on 2.46.0...2.60.0, but not on >=2.56.3, >=2.58.1 (fix backported)
if ((!glib_check_version(2, 56, 0) && glib_check_version(2, 56, 3))
|| (!glib_check_version(2, 58, 0) && glib_check_version(2, 58, 1))
Expand All @@ -33,6 +36,9 @@ std::optional<bool> NetworkAvailable() {

return g_network_monitor_get_network_available(
g_network_monitor_get_default());
#else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
return std::nullopt;
#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
}

} // namespace base::Platform
18 changes: 14 additions & 4 deletions base/platform/linux/base_url_scheme_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@
//
#include "base/platform/linux/base_url_scheme_linux.h"

#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/const_string.h"
#include "base/debug_log.h"

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include "base/platform/linux/base_linux_glibmm_helper.h"
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

#include <QtCore/QFile>
#include <QtCore/QProcess>
#include <QtGui/QWindow>

#include <private/qguiapplication_p.h>

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <gio/gio.h>
#include <glibmm.h>
#include <giomm.h>
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

namespace base::Platform {
namespace {

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
constexpr auto kSnapcraftSettingsService = "io.snapcraft.Settings"_cs;
constexpr auto kSnapcraftSettingsObjectPath = "/io/snapcraft/Settings"_cs;
constexpr auto kSnapcraftSettingsInterface = kSnapcraftSettingsService;
Expand Down Expand Up @@ -52,7 +59,6 @@ constexpr auto kSnapcraftSettingsInterface = kSnapcraftSettingsService;
return result;
}

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void SnapDefaultHandler(const QString &protocol) {
try {
const auto connection = Gio::DBus::Connection::get_sync(
Expand Down Expand Up @@ -118,6 +124,7 @@ void SnapDefaultHandler(const QString &protocol) {
} // namespace

bool CheckUrlScheme(const UrlSchemeDescriptor &descriptor) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
try {
const auto handlerType = QString("x-scheme-handler/%1")
.arg(descriptor.protocol);
Expand All @@ -144,18 +151,18 @@ bool CheckUrlScheme(const UrlSchemeDescriptor &descriptor) {
}
} catch (...) {
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

return false;
}

void RegisterUrlScheme(const UrlSchemeDescriptor &descriptor) {
try {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
try {
if (qEnvironmentVariableIsSet("SNAP")) {
SnapDefaultHandler(descriptor.protocol);
return;
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

if (CheckUrlScheme(descriptor)) {
return;
Expand Down Expand Up @@ -186,9 +193,11 @@ void RegisterUrlScheme(const UrlSchemeDescriptor &descriptor) {
} catch (const Glib::Error &e) {
LOG(("Register Url Scheme Error: %1").arg(QString::fromStdString(e.what())));
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
}

void UnregisterUrlScheme(const UrlSchemeDescriptor &descriptor) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
const auto handlerType = QString("x-scheme-handler/%1")
.arg(descriptor.protocol);

Expand Down Expand Up @@ -224,6 +233,7 @@ void UnregisterUrlScheme(const UrlSchemeDescriptor &descriptor) {
if (registeredAppInfoList) {
g_list_free_full(registeredAppInfoList, g_object_unref);
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
}

} // namespace base::Platform

0 comments on commit 50d2d31

Please sign in to comment.