Changeset View
Changeset View
Standalone View
Standalone View
src/global.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
72 | 72 | | |||
73 | bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService) | 73 | bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService) | ||
74 | { | 74 | { | ||
75 | // TODO: once Wayland clients can raise or activate themselves remove check from conditional | 75 | // TODO: once Wayland clients can raise or activate themselves remove check from conditional | ||
76 | if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { | 76 | if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { | ||
77 | return false; | 77 | return false; | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices = dolphinInstanceData(preferredService); | ||||
81 | if (dolphinServices.isEmpty()) { | ||||
82 | return false; | ||||
83 | } | ||||
84 | | ||||
85 | QStringList newUrls; | ||||
86 | | ||||
87 | // check to see if any instances already have any of the given URLs open | ||||
88 | const auto urls = QUrl::toStringList(inputUrls); | ||||
89 | for (const QString& url : urls) { | ||||
90 | bool urlFound = false; | ||||
91 | for (auto& service: dolphinServices) { | ||||
92 | QDBusReply<bool> isUrlOpen = service.first->call(QStringLiteral("isUrlOpen"), url); | ||||
93 | if (isUrlOpen.isValid() && isUrlOpen.value()) { | ||||
94 | service.second.append(url); | ||||
95 | urlFound = true; | ||||
96 | break; | ||||
97 | } | ||||
98 | } | ||||
99 | if (!urlFound) { | ||||
100 | newUrls.append(url); | ||||
101 | } | ||||
102 | } | ||||
103 | dolphinServices.front().second << newUrls; | ||||
104 | | ||||
105 | for (const auto& service: dolphinServices) { | ||||
meven: qAsConst | |||||
106 | if (!service.second.isEmpty()) { | ||||
107 | service.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), service.second, splitView); | ||||
108 | service.first->call(QStringLiteral("activateWindow")); | ||||
109 | } | ||||
110 | } | ||||
111 | return true; | ||||
112 | } | ||||
113 | | ||||
114 | QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> Dolphin::dolphinInstanceData(const QString& preferredService) | ||||
115 | { | ||||
80 | QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices; | 116 | QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices; | ||
81 | if (!preferredService.isEmpty()) { | 117 | if (!preferredService.isEmpty()) { | ||
82 | QSharedPointer<QDBusInterface> preferred( | 118 | QSharedPointer<QDBusInterface> preferred( | ||
83 | new QDBusInterface(preferredService, | 119 | new QDBusInterface(preferredService, | ||
84 | QStringLiteral("/dolphin/Dolphin_1"), | 120 | QStringLiteral("/dolphin/Dolphin_1"), | ||
85 | QStringLiteral("org.kde.dolphin.MainWindow")) | 121 | QStringLiteral("org.kde.dolphin.MainWindow")) | ||
86 | ); | 122 | ); | ||
87 | if (preferred->isValid() && !preferred->lastError().isValid()) { | 123 | if (preferred->isValid() && !preferred->lastError().isValid()) { | ||
Show All 15 Lines | 137 | QSharedPointer<QDBusInterface> instance( | |||
103 | QStringLiteral("/dolphin/Dolphin_1"), | 139 | QStringLiteral("/dolphin/Dolphin_1"), | ||
104 | QStringLiteral("org.kde.dolphin.MainWindow")) | 140 | QStringLiteral("org.kde.dolphin.MainWindow")) | ||
105 | ); | 141 | ); | ||
106 | if (instance->isValid() && !instance->lastError().isValid()) { | 142 | if (instance->isValid() && !instance->lastError().isValid()) { | ||
107 | dolphinServices.append(qMakePair(instance, QStringList())); | 143 | dolphinServices.append(qMakePair(instance, QStringList())); | ||
108 | } | 144 | } | ||
109 | } | 145 | } | ||
110 | } | 146 | } | ||
111 | 147 | | |||
elvisangelaccio: Please use `auto`. | |||||
112 | if (dolphinServices.isEmpty()) { | 148 | if (dolphinServices.isEmpty()) { | ||
113 | return false; | 149 | return QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>>(); | ||
114 | } | 150 | } | ||
115 | 151 | return dolphinServices; | |||
116 | QStringList newUrls; | | |||
117 | | ||||
118 | // check to see if any instances already have any of the given URLs open | | |||
119 | const auto urls = QUrl::toStringList(inputUrls); | | |||
120 | for (const QString& url : urls) { | | |||
121 | bool urlFound = false; | | |||
122 | for (auto& service: dolphinServices) { | | |||
123 | QDBusReply<bool> isUrlOpen = service.first->call(QStringLiteral("isUrlOpen"), url); | | |||
124 | if (isUrlOpen.isValid() && isUrlOpen.value()) { | | |||
125 | service.second.append(url); | | |||
126 | urlFound = true; | | |||
127 | break; | | |||
128 | } | | |||
129 | } | | |||
130 | if (!urlFound) { | | |||
131 | newUrls.append(url); | | |||
132 | } | | |||
133 | } | | |||
134 | dolphinServices.front().second << newUrls; | | |||
135 | | ||||
136 | for (const auto& service: dolphinServices) { | | |||
137 | if (!service.second.isEmpty()) { | | |||
138 | service.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), service.second, splitView); | | |||
139 | service.first->call(QStringLiteral("activateWindow")); | | |||
140 | } | | |||
141 | } | | |||
142 | return true; | | |||
143 | } | 152 | } |
qAsConst