Changeset View
Changeset View
Standalone View
Standalone View
src/global.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
73 | { | 73 | { | ||
74 | bool attached = false; | 74 | bool attached = false; | ||
75 | 75 | | |||
76 | // TODO: once Wayland clients can raise or activate themselves remove check from conditional | 76 | // TODO: once Wayland clients can raise or activate themselves remove check from conditional | ||
77 | if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { | 77 | if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { | ||
78 | return false; | 78 | return false; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces; | 81 | auto dolphinInterfaces = dolphinGuiInstances(preferredService); | ||
elvisangelaccio: Please use `auto`. | |||||
82 | if (!preferredService.isEmpty()) { | | |||
83 | QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface( | | |||
84 | new OrgKdeDolphinMainWindowInterface(preferredService, | | |||
85 | QStringLiteral("/dolphin/Dolphin_1"), | | |||
86 | QDBusConnection::sessionBus())); | | |||
87 | if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { | | |||
88 | dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); | | |||
89 | } | | |||
90 | } | | |||
91 | | ||||
92 | // Look for dolphin instances among all available dbus services. | | |||
93 | const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); | | |||
94 | // Don't match the service without trailing "-" (unique instance) | | |||
95 | const QString pattern = QStringLiteral("org.kde.dolphin-"); | | |||
96 | // Don't match the pid without leading "-" | | |||
97 | const QString myPid = QLatin1Char('-') + QString::number(QCoreApplication::applicationPid()); | | |||
98 | for (const QString& service : dbusServices) { | | |||
99 | if (service.startsWith(pattern) && !service.endsWith(myPid)) { | | |||
100 | // Check if instance can handle our URLs | | |||
101 | QSharedPointer<OrgKdeDolphinMainWindowInterface> interface( | | |||
102 | new OrgKdeDolphinMainWindowInterface(service, | | |||
103 | QStringLiteral("/dolphin/Dolphin_1"), | | |||
104 | QDBusConnection::sessionBus())); | | |||
105 | if (interface->isValid() && !interface->lastError().isValid()) { | | |||
106 | dolphinInterfaces.append(qMakePair(interface, QStringList())); | | |||
107 | } | | |||
108 | } | | |||
109 | } | | |||
110 | | ||||
111 | if (dolphinInterfaces.isEmpty()) { | 82 | if (dolphinInterfaces.isEmpty()) { | ||
112 | return false; | 83 | return false; | ||
113 | } | 84 | } | ||
114 | 85 | | |||
115 | QStringList newUrls; | 86 | QStringList newUrls; | ||
116 | 87 | | |||
117 | // check to see if any instances already have any of the given URLs open | 88 | // check to see if any instances already have any of the given URLs open | ||
118 | const auto urls = QUrl::toStringList(inputUrls); | 89 | const auto urls = QUrl::toStringList(inputUrls); | ||
119 | for (const QString& url : urls) { | 90 | for (const QString& url : urls) { | ||
120 | bool urlFound = false; | 91 | bool urlFound = false; | ||
121 | for (auto& interface: dolphinInterfaces) { | 92 | for (auto& interface: dolphinInterfaces) { | ||
122 | auto isUrlOpenReply = interface.first->isUrlOpen(url); | 93 | auto isUrlOpenReply = interface.first->isUrlOpen(url); | ||
123 | isUrlOpenReply.waitForFinished(); | 94 | isUrlOpenReply.waitForFinished(); | ||
124 | if (!isUrlOpenReply.isError() && isUrlOpenReply.value()) { | 95 | if (!isUrlOpenReply.isError() && isUrlOpenReply.value()) { | ||
125 | interface.second.append(url); | 96 | interface.second.append(url); | ||
126 | urlFound = true; | 97 | urlFound = true; | ||
127 | break; | 98 | break; | ||
128 | } | 99 | } | ||
129 | } | 100 | } | ||
130 | if (!urlFound) { | 101 | if (!urlFound) { | ||
131 | newUrls.append(url); | 102 | newUrls.append(url); | ||
132 | } | 103 | } | ||
133 | } | 104 | } | ||
134 | dolphinInterfaces.front().second << newUrls; | 105 | dolphinInterfaces.front().second << newUrls; | ||
135 | 106 | | |||
meven: qAsConst | |||||
136 | for (const auto& interface: dolphinInterfaces) { | 107 | for (const auto& interface: dolphinInterfaces) { | ||
137 | if (!interface.second.isEmpty()) { | 108 | if (!interface.second.isEmpty()) { | ||
138 | auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView); | 109 | auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView); | ||
139 | reply.waitForFinished(); | 110 | reply.waitForFinished(); | ||
140 | if (!reply.isError()) { | 111 | if (!reply.isError()) { | ||
141 | interface.first->activateWindow(); | 112 | interface.first->activateWindow(); | ||
142 | attached = true; | 113 | attached = true; | ||
143 | } | 114 | } | ||
144 | } | 115 | } | ||
145 | } | 116 | } | ||
146 | return attached; | 117 | return attached; | ||
147 | } | 118 | } | ||
119 | | ||||
120 | QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> Dolphin::dolphinGuiInstances(const QString& preferredService) | ||||
121 | { | ||||
122 | QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces; | ||||
123 | if (!preferredService.isEmpty()) { | ||||
124 | QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface( | ||||
125 | new OrgKdeDolphinMainWindowInterface(preferredService, | ||||
126 | QStringLiteral("/dolphin/Dolphin_1"), | ||||
127 | QDBusConnection::sessionBus())); | ||||
128 | if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { | ||||
129 | dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); | ||||
130 | } | ||||
131 | } | ||||
132 | | ||||
133 | // Look for dolphin instances among all available dbus services. | ||||
134 | const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); | ||||
135 | // Don't match the service without trailing "-" (unique instance) | ||||
136 | const QString pattern = QStringLiteral("org.kde.dolphin-"); | ||||
137 | // Don't match the pid without leading "-" | ||||
138 | const QString myPid = QLatin1Char('-') + QString::number(QCoreApplication::applicationPid()); | ||||
139 | for (const QString& service : dbusServices) { | ||||
140 | if (service.startsWith(pattern) && !service.endsWith(myPid)) { | ||||
141 | // Check if instance can handle our URLs | ||||
142 | QSharedPointer<OrgKdeDolphinMainWindowInterface> interface( | ||||
143 | new OrgKdeDolphinMainWindowInterface(service, | ||||
144 | QStringLiteral("/dolphin/Dolphin_1"), | ||||
145 | QDBusConnection::sessionBus())); | ||||
146 | if (interface->isValid() && !interface->lastError().isValid()) { | ||||
147 | dolphinInterfaces.append(qMakePair(interface, QStringList())); | ||||
148 | } | ||||
149 | } | ||||
150 | } | ||||
151 | | ||||
152 | return dolphinInterfaces; | ||||
153 | } |
Please use auto.