Changeset View
Standalone View
src/global.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "dolphin_generalsettings.h" | 22 | #include "dolphin_generalsettings.h" | ||
23 | #include "dolphindebug.h" | 23 | #include "dolphindebug.h" | ||
24 | 24 | | |||
25 | #include <KRun> | 25 | #include <KRun> | ||
26 | 26 | | |||
27 | #include <QApplication> | 27 | #include <QApplication> | ||
28 | #include <QIcon> | 28 | #include <QIcon> | ||
29 | #include <QDBusInterface> | ||||
30 | #include <QDBusConnectionInterface> | ||||
29 | 31 | | |||
30 | QList<QUrl> Dolphin::validateUris(const QStringList& uriList) | 32 | QList<QUrl> Dolphin::validateUris(const QStringList& uriList) | ||
31 | { | 33 | { | ||
32 | const QString currentDir = QDir::currentPath(); | 34 | const QString currentDir = QDir::currentPath(); | ||
33 | QList<QUrl> urls; | 35 | QList<QUrl> urls; | ||
34 | foreach (const QString& str, uriList) { | 36 | foreach (const QString& str, uriList) { | ||
35 | const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile); | 37 | const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile); | ||
36 | if (url.isValid()) { | 38 | if (url.isValid()) { | ||
37 | urls.append(url); | 39 | urls.append(url); | ||
38 | } else { | 40 | } else { | ||
39 | qCWarning(DolphinDebug) << "Invalid URL: " << str; | 41 | qCWarning(DolphinDebug) << "Invalid URL: " << str; | ||
40 | } | 42 | } | ||
41 | } | 43 | } | ||
42 | return urls; | 44 | return urls; | ||
43 | } | 45 | } | ||
44 | 46 | | |||
45 | QUrl Dolphin::homeUrl() | 47 | QUrl Dolphin::homeUrl() | ||
46 | { | 48 | { | ||
47 | return QUrl::fromUserInput(GeneralSettings::homeUrl(), QString(), QUrl::AssumeLocalFile); | 49 | return QUrl::fromUserInput(GeneralSettings::homeUrl(), QString(), QUrl::AssumeLocalFile); | ||
48 | } | 50 | } | ||
49 | 51 | | |||
50 | void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const OpenNewWindowFlags &flags) | 52 | void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const OpenNewWindowFlags &flags) | ||
51 | { | 53 | { | ||
52 | QString command = QStringLiteral("dolphin"); | 54 | QString command = QStringLiteral("dolphin"); | ||
55 | command.append(QLatin1String(" --new-window")); | ||||
53 | 56 | | |||
elvisangelaccio: Please use `QStringLiteral("dolphin --new-window")` to save a string concatenation. | |||||
54 | if (flags.testFlag(OpenNewWindowFlag::Select)) { | 57 | if (flags.testFlag(OpenNewWindowFlag::Select)) { | ||
55 | command.append(QLatin1String(" --select")); | 58 | command.append(QLatin1String(" --select")); | ||
56 | } | 59 | } | ||
57 | 60 | | |||
58 | if (!urls.isEmpty()) { | 61 | if (!urls.isEmpty()) { | ||
59 | command.append(QLatin1String(" %U")); | 62 | command.append(QLatin1String(" %U")); | ||
60 | } | 63 | } | ||
61 | 64 | | |||
62 | KRun::run(command, urls, window, qApp->applicationDisplayName(), qApp->windowIcon().name()); | 65 | KRun::run(command, urls, window, qApp->applicationDisplayName(), qApp->windowIcon().name()); | ||
63 | } | 66 | } | ||
67 | | ||||
68 | bool Dolphin::attachToExistingInstance(const QStringList urls, bool openFiles, bool splitView) | ||||
69 | { | ||||
As Wayland and X11 clients can be part of the same session and thus the same DBus, it would be more accurate to ask the running dolphin whether it's using Wayland or XCB. It would require a new DBus call though, so probably too complex and not worth it though. fvogt: As Wayland and X11 clients can be part of the same session and thus the same DBus, it would be… | |||||
70 | const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); | ||||
71 | | ||||
72 | // Don't match the service without trailing "-" (unique instance) | ||||
73 | const QString pattern = QStringLiteral("org.kde.dolphin-"); | ||||
74 | const QString myPid = QString::number(qApp->applicationPid()); | ||||
elvisangelaccio: `QCoreApplication::applicationPid()` | |||||
75 | QScopedPointer<QDBusInterface> bestService; | ||||
76 | | ||||
fvogt: `!preferredService.isEmpty()` | |||||
77 | // Select the first instance that isn't us | ||||
78 | for (const QString& service: services) | ||||
79 | { | ||||
elvisangelaccio: Brace should start at the end of the previous line | |||||
80 | if (service.startsWith(pattern) && !service.endsWith(myPid)) | ||||
81 | { | ||||
elvisangelaccio: Brace should start at the end of the previous line | |||||
82 | // Check if instance can handle our URLs | ||||
83 | bestService.reset(new QDBusInterface(service, QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("org.kde.dolphin.MainWindow"))); | ||||
84 | if(!bestService->isValid()) | ||||
Prepend '-' to myPid so it does not accidentally skip pid {1123, 2123, ...} when the applicationPid is 123. (service.endsWith(myPid) on line 99) thomasp: Prepend '-' to myPid so it does not accidentally skip pid {1123, 2123, ...} when the… | |||||
85 | break; | ||||
86 | | ||||
elvisangelaccio: Missing braces | |||||
87 | bestService->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), urls, splitView); | ||||
88 | bestService->call(QStringLiteral("tryRaise")); | ||||
89 | return true; | ||||
elvisangelaccio: Coding style: missing space before the colon. | |||||
90 | } | ||||
91 | } | ||||
92 | return false; | ||||
93 | } | ||||
IMO this function should take a const QList<QUrl> &urls parameter and only convert it to a QStringList here for the call. fvogt: IMO this function should take a `const QList<QUrl> &urls` parameter and only convert it to a… | |||||
fvogt: `if (isUrlOpen.isValid() && isUrlOpen.value()) {` | |||||
This might be dangerous? The wording of the docs doesn't make it too clear: https://doc.qt.io/qt-5/qdbusreply.html#value feverfew: This might be dangerous? The wording of the docs doesn't make it too clear: https://doc.qt. | |||||
Even though isUrlOpen.value() may give an "undefined" value, it doesn't matter as isUrlOpen.isValid() will be false. feverfew: Even though `isUrlOpen.value()` may give an "undefined" value, it doesn't matter as `isUrlOpen. | |||||
elvisangelaccio: Why not use `QPair` instead of defining this struct ? |
Please use QStringLiteral("dolphin --new-window") to save a string concatenation.