Avoid crashing on startup if DBus isn't running

I am trying to run Dolphin on a minimal FreeBSD CHERI-RISC-V QEMU
instance and I haven't got DBus running. Without this change, I get
crashes because QDBusConnection::sessionBus().interface() returns NULL
if DBus isn't running.
This commit is contained in:
Alex Richardson 2021-07-09 09:30:58 +01:00 committed by Elvis Angelaccio
parent d284e22f87
commit 531de16cd0
3 changed files with 8 additions and 4 deletions

View file

@ -20,8 +20,10 @@ DBusInterface::DBusInterface() :
{
QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/freedesktop/FileManager1"), this,
QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
QDBusConnection::sessionBus().interface()->registerService(QStringLiteral("org.freedesktop.FileManager1"),
QDBusConnectionInterface::QueueService);
QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
if (sessionInterface) {
sessionInterface->registerService(QStringLiteral("org.freedesktop.FileManager1"), QDBusConnectionInterface::QueueService);
}
}
void DBusInterface::ShowFolders(const QStringList& uriList, const QString& startUpId)

View file

@ -1543,7 +1543,8 @@ void DolphinMainWindow::setupActions()
stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
stashSplit->setCheckable(false);
stashSplit->setVisible(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());

View file

@ -120,7 +120,8 @@ QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> Do
}
// Look for dolphin instances among all available dbus services.
const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
const QStringList dbusServices = sessionInterface ? sessionInterface->registeredServiceNames().value() : QStringList();
// Don't match the service without trailing "-" (unique instance)
const QString pattern = QStringLiteral("org.kde.dolphin-");
// Don't match the pid without leading "-"