Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/krun.cpp
Show First 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | 159 | { | |||
---|---|---|---|---|---|
160 | Q_ASSERT(job); | 160 | Q_ASSERT(job); | ||
161 | if (job) { | 161 | if (job) { | ||
162 | d->m_showingDialog = true; | 162 | d->m_showingDialog = true; | ||
163 | job->uiDelegate()->showErrorMessage(); | 163 | job->uiDelegate()->showErrorMessage(); | ||
164 | d->m_showingDialog = false; | 164 | d->m_showingDialog = false; | ||
165 | } | 165 | } | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 31) | ||||
168 | bool KRun::runUrl(const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile, bool runExecutables, const QString &suggestedFileName, const QByteArray &asn) | 169 | bool KRun::runUrl(const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile, bool runExecutables, const QString &suggestedFileName, const QByteArray &asn) | ||
169 | { | 170 | { | ||
170 | RunFlags flags = tempFile ? KRun::DeleteTemporaryFiles : RunFlags(); | 171 | RunFlags flags = tempFile ? KRun::DeleteTemporaryFiles : RunFlags(); | ||
171 | if (runExecutables) { | 172 | if (runExecutables) { | ||
172 | flags |= KRun::RunExecutables; | 173 | flags |= KRun::RunExecutables; | ||
173 | } | 174 | } | ||
174 | 175 | | |||
175 | return runUrl(url, mimetype, window, flags, suggestedFileName, asn); | 176 | return runUrl(url, mimetype, window, flags, suggestedFileName, asn); | ||
176 | } | 177 | } | ||
178 | #endif | ||||
177 | 179 | | |||
180 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
178 | // This is called by foundMimeType, since it knows the mimetype of the URL | 181 | // This is called by foundMimeType, since it knows the mimetype of the URL | ||
179 | bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn) | 182 | bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn) | ||
180 | { | 183 | { | ||
181 | const bool runExecutables = flags.testFlag(KRun::RunExecutables); | 184 | const bool runExecutables = flags.testFlag(KRun::RunExecutables); | ||
182 | const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles); | 185 | const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles); | ||
183 | 186 | | |||
184 | KIO::OpenUrlJob *job = new KIO::OpenUrlJob(u, _mimetype); | 187 | KIO::OpenUrlJob *job = new KIO::OpenUrlJob(u, _mimetype); | ||
185 | job->setSuggestedFileName(suggestedFileName); | 188 | job->setSuggestedFileName(suggestedFileName); | ||
186 | job->setStartupId(asn); | 189 | job->setStartupId(asn); | ||
187 | job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window)); | 190 | job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window)); | ||
188 | job->setDeleteTemporaryFile(tempFile); | 191 | job->setDeleteTemporaryFile(tempFile); | ||
189 | job->setRunExecutables(runExecutables); | 192 | job->setRunExecutables(runExecutables); | ||
190 | job->start(); | 193 | job->start(); | ||
191 | return true; | 194 | return true; | ||
192 | } | 195 | } | ||
196 | #endif | ||||
193 | 197 | | |||
194 | bool KRun::displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles, | 198 | bool KRun::displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles, | ||
195 | const QString &suggestedFileName, const QByteArray &asn) | 199 | const QString &suggestedFileName, const QByteArray &asn) | ||
196 | { | 200 | { | ||
197 | if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { | 201 | if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { | ||
198 | KMessageBox::sorry(window, | 202 | KMessageBox::sorry(window, | ||
199 | i18n("You are not authorized to select an application to open this file.")); | 203 | i18n("You are not authorized to select an application to open this file.")); | ||
200 | return false; | 204 | return false; | ||
Show All 18 Lines | 221 | if (!service) { | |||
219 | service = KService::Ptr(new KService(QString() /*name*/, dialog.text(), QString() /*icon*/)); | 223 | service = KService::Ptr(new KService(QString() /*name*/, dialog.text(), QString() /*icon*/)); | ||
220 | } | 224 | } | ||
221 | const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags(); | 225 | const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags(); | ||
222 | return KRun::runApplication(*service, lst, window, flags, suggestedFileName, asn); | 226 | return KRun::runApplication(*service, lst, window, flags, suggestedFileName, asn); | ||
223 | } | 227 | } | ||
224 | return false; | 228 | return false; | ||
225 | } | 229 | } | ||
226 | 230 | | |||
231 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 0) | ||||
227 | void KRun::shellQuote(QString &_str) | 232 | void KRun::shellQuote(QString &_str) | ||
228 | { | 233 | { | ||
229 | // Credits to Walter, says Bernd G. :) | 234 | // Credits to Walter, says Bernd G. :) | ||
230 | if (_str.isEmpty()) { // Don't create an explicit empty parameter | 235 | if (_str.isEmpty()) { // Don't create an explicit empty parameter | ||
231 | return; | 236 | return; | ||
232 | } | 237 | } | ||
233 | const QChar q = QLatin1Char('\''); | 238 | const QChar q = QLatin1Char('\''); | ||
234 | _str.replace(q, QLatin1String("'\\''")).prepend(q).append(q); | 239 | _str.replace(q, QLatin1String("'\\''")).prepend(q).append(q); | ||
235 | } | 240 | } | ||
241 | #endif | ||||
236 | 242 | | |||
243 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 0) | ||||
237 | QStringList KRun::processDesktopExec(const KService &_service, const QList<QUrl> &_urls, bool tempFiles, const QString &suggestedFileName) | 244 | QStringList KRun::processDesktopExec(const KService &_service, const QList<QUrl> &_urls, bool tempFiles, const QString &suggestedFileName) | ||
238 | { | 245 | { | ||
239 | KIO::DesktopExecParser parser(_service, _urls); | 246 | KIO::DesktopExecParser parser(_service, _urls); | ||
240 | parser.setUrlsAreTempFiles(tempFiles); | 247 | parser.setUrlsAreTempFiles(tempFiles); | ||
241 | parser.setSuggestedFileName(suggestedFileName); | 248 | parser.setSuggestedFileName(suggestedFileName); | ||
242 | return parser.resultingArguments(); | 249 | return parser.resultingArguments(); | ||
243 | } | 250 | } | ||
251 | #endif | ||||
244 | 252 | | |||
253 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 0) | ||||
245 | QString KRun::binaryName(const QString &execLine, bool removePath) | 254 | QString KRun::binaryName(const QString &execLine, bool removePath) | ||
246 | { | 255 | { | ||
247 | return removePath ? KIO::DesktopExecParser::executableName(execLine) : KIO::DesktopExecParser::executablePath(execLine); | 256 | return removePath ? KIO::DesktopExecParser::executableName(execLine) : KIO::DesktopExecParser::executablePath(execLine); | ||
248 | } | 257 | } | ||
258 | #endif | ||||
249 | 259 | | |||
250 | // This code is also used in klauncher. | 260 | // This code is also used in klauncher. | ||
251 | // TODO: port klauncher to KIOGuiPrivate::checkStartupNotify once this lands | 261 | // TODO: port klauncher to KIOGuiPrivate::checkStartupNotify once this lands | ||
252 | // TODO: then deprecate this method, and remove in KF6 | 262 | // TODO: then deprecate this method, and remove in KF6 | ||
253 | bool KRun::checkStartupNotify(const QString & /*binName*/, const KService *service, bool *silent_arg, QByteArray *wmclass_arg) | 263 | bool KRun::checkStartupNotify(const QString & /*binName*/, const KService *service, bool *silent_arg, QByteArray *wmclass_arg) | ||
254 | { | 264 | { | ||
255 | return KIOGuiPrivate::checkStartupNotify(service, silent_arg, wmclass_arg); | 265 | return KIOGuiPrivate::checkStartupNotify(service, silent_arg, wmclass_arg); | ||
256 | } | 266 | } | ||
257 | 267 | | |||
268 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 6) | ||||
258 | bool KRun::run(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | 269 | bool KRun::run(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | ||
259 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) | 270 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) | ||
260 | { | 271 | { | ||
261 | const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags(); | 272 | const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags(); | ||
262 | return runApplication(_service, _urls, window, flags, suggestedFileName, asn) != 0; | 273 | return runApplication(_service, _urls, window, flags, suggestedFileName, asn) != 0; | ||
263 | } | 274 | } | ||
275 | #endif | ||||
264 | 276 | | |||
277 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
265 | qint64 KRun::runApplication(const KService &service, const QList<QUrl> &urls, QWidget *window, | 278 | qint64 KRun::runApplication(const KService &service, const QList<QUrl> &urls, QWidget *window, | ||
266 | RunFlags flags, const QString &suggestedFileName, | 279 | RunFlags flags, const QString &suggestedFileName, | ||
267 | const QByteArray &asn) | 280 | const QByteArray &asn) | ||
268 | { | 281 | { | ||
269 | KService::Ptr servicePtr(new KService(service)); // clone | 282 | KService::Ptr servicePtr(new KService(service)); // clone | ||
270 | // QTBUG-59017 Calling winId() on an embedded widget will break interaction | 283 | // QTBUG-59017 Calling winId() on an embedded widget will break interaction | ||
271 | // with it on high-dpi multi-screen setups (cf. also Bug 363548), hence using | 284 | // with it on high-dpi multi-screen setups (cf. also Bug 363548), hence using | ||
272 | // its parent window instead | 285 | // its parent window instead | ||
273 | if (window) { | 286 | if (window) { | ||
274 | window = window->window(); | 287 | window = window->window(); | ||
275 | } | 288 | } | ||
276 | 289 | | |||
277 | KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(servicePtr); | 290 | KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(servicePtr); | ||
278 | job->setUrls(urls); | 291 | job->setUrls(urls); | ||
279 | if (flags & DeleteTemporaryFiles) { | 292 | if (flags & DeleteTemporaryFiles) { | ||
280 | job->setRunFlags(KIO::ApplicationLauncherJob::DeleteTemporaryFiles); | 293 | job->setRunFlags(KIO::ApplicationLauncherJob::DeleteTemporaryFiles); | ||
281 | } | 294 | } | ||
282 | job->setSuggestedFileName(suggestedFileName); | 295 | job->setSuggestedFileName(suggestedFileName); | ||
283 | job->setStartupId(asn); | 296 | job->setStartupId(asn); | ||
284 | job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window)); | 297 | job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window)); | ||
285 | job->start(); | 298 | job->start(); | ||
286 | job->waitForStarted(); | 299 | job->waitForStarted(); | ||
287 | return job->error() ? 0 : job->pid(); | 300 | return job->error() ? 0 : job->pid(); | ||
288 | } | 301 | } | ||
302 | #endif | ||||
289 | 303 | | |||
304 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
290 | qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | 305 | qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | ||
291 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) | 306 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) | ||
292 | { | 307 | { | ||
293 | return runApplication(_service, | 308 | return runApplication(_service, | ||
294 | _urls, | 309 | _urls, | ||
295 | window, | 310 | window, | ||
296 | tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(), | 311 | tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(), | ||
297 | suggestedFileName, | 312 | suggestedFileName, | ||
298 | asn); | 313 | asn); | ||
299 | } | 314 | } | ||
315 | #endif | ||||
300 | 316 | | |||
317 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
301 | bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name, | 318 | bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name, | ||
302 | const QString &_icon, const QByteArray &asn) | 319 | const QString &_icon, const QByteArray &asn) | ||
303 | { | 320 | { | ||
304 | KService::Ptr service(new KService(_name, _exec, _icon)); | 321 | KService::Ptr service(new KService(_name, _exec, _icon)); | ||
305 | 322 | | |||
306 | return runApplication(*service, _urls, window, RunFlags{}, QString(), asn); | 323 | return runApplication(*service, _urls, window, RunFlags{}, QString(), asn); | ||
307 | } | 324 | } | ||
325 | #endif | ||||
308 | 326 | | |||
327 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
309 | bool KRun::runCommand(const QString &cmd, QWidget *window, const QString &workingDirectory) | 328 | bool KRun::runCommand(const QString &cmd, QWidget *window, const QString &workingDirectory) | ||
310 | { | 329 | { | ||
311 | if (cmd.isEmpty()) { | 330 | if (cmd.isEmpty()) { | ||
312 | qCWarning(KIO_WIDGETS) << "Command was empty, nothing to run"; | 331 | qCWarning(KIO_WIDGETS) << "Command was empty, nothing to run"; | ||
313 | return false; | 332 | return false; | ||
314 | } | 333 | } | ||
315 | 334 | | |||
316 | const QStringList args = KShell::splitArgs(cmd); | 335 | const QStringList args = KShell::splitArgs(cmd); | ||
317 | if (args.isEmpty()) { | 336 | if (args.isEmpty()) { | ||
318 | qCWarning(KIO_WIDGETS) << "Command could not be parsed."; | 337 | qCWarning(KIO_WIDGETS) << "Command could not be parsed."; | ||
319 | return false; | 338 | return false; | ||
320 | } | 339 | } | ||
321 | 340 | | |||
322 | const QString &bin = args.first(); | 341 | const QString &bin = args.first(); | ||
323 | return KRun::runCommand(cmd, bin, bin /*iconName*/, window, QByteArray(), workingDirectory); | 342 | return KRun::runCommand(cmd, bin, bin /*iconName*/, window, QByteArray(), workingDirectory); | ||
324 | } | 343 | } | ||
344 | #endif | ||||
325 | 345 | | |||
346 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
326 | bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, QWidget *window, const QByteArray &asn) | 347 | bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, QWidget *window, const QByteArray &asn) | ||
327 | { | 348 | { | ||
328 | return runCommand(cmd, execName, iconName, window, asn, QString()); | 349 | return runCommand(cmd, execName, iconName, window, asn, QString()); | ||
329 | } | 350 | } | ||
351 | #endif | ||||
330 | 352 | | |||
353 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71) | ||||
331 | bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, | 354 | bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, | ||
332 | QWidget *window, const QByteArray &asn, const QString &workingDirectory) | 355 | QWidget *window, const QByteArray &asn, const QString &workingDirectory) | ||
333 | { | 356 | { | ||
334 | auto *job = new KIO::CommandLauncherJob(cmd); | 357 | auto *job = new KIO::CommandLauncherJob(cmd); | ||
335 | job->setExecutable(execName); | 358 | job->setExecutable(execName); | ||
336 | job->setIcon(iconName); | 359 | job->setIcon(iconName); | ||
337 | job->setStartupId(asn); | 360 | job->setStartupId(asn); | ||
338 | job->setWorkingDirectory(workingDirectory); | 361 | job->setWorkingDirectory(workingDirectory); | ||
339 | 362 | | |||
340 | if (window) { | 363 | if (window) { | ||
341 | window = window->window(); | 364 | window = window->window(); | ||
342 | } | 365 | } | ||
343 | return KRunPrivate::runCommandLauncherJob(job, window); | 366 | return KRunPrivate::runCommandLauncherJob(job, window); | ||
344 | } | 367 | } | ||
368 | #endif | ||||
345 | 369 | | |||
346 | KRun::KRun(const QUrl &url, QWidget *window, | 370 | KRun::KRun(const QUrl &url, QWidget *window, | ||
347 | bool showProgressInfo, const QByteArray &asn) | 371 | bool showProgressInfo, const QByteArray &asn) | ||
348 | : d(new KRunPrivate(this)) | 372 | : d(new KRunPrivate(this)) | ||
349 | { | 373 | { | ||
350 | d->m_timer = new QTimer(this); | 374 | d->m_timer = new QTimer(this); | ||
351 | d->m_timer->setObjectName(QStringLiteral("KRun::timer")); | 375 | d->m_timer->setObjectName(QStringLiteral("KRun::timer")); | ||
352 | d->m_timer->setSingleShot(true); | 376 | d->m_timer->setSingleShot(true); | ||
▲ Show 20 Lines • Show All 652 Lines • ▼ Show 20 Line(s) | 1028 | { | |||
1005 | d->m_job = job; | 1029 | d->m_job = job; | ||
1006 | } | 1030 | } | ||
1007 | 1031 | | |||
1008 | KIO::Job *KRun::job() | 1032 | KIO::Job *KRun::job() | ||
1009 | { | 1033 | { | ||
1010 | return d->m_job; | 1034 | return d->m_job; | ||
1011 | } | 1035 | } | ||
1012 | 1036 | | |||
1037 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 4) | ||||
1013 | QTimer &KRun::timer() | 1038 | QTimer &KRun::timer() | ||
1014 | { | 1039 | { | ||
1015 | return *d->m_timer; | 1040 | return *d->m_timer; | ||
1016 | } | 1041 | } | ||
1042 | #endif | ||||
1017 | 1043 | | |||
1044 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1) | ||||
1018 | void KRun::setDoScanFile(bool scanFile) | 1045 | void KRun::setDoScanFile(bool scanFile) | ||
1019 | { | 1046 | { | ||
1020 | d->m_bScanFile = scanFile; | 1047 | d->m_bScanFile = scanFile; | ||
1021 | } | 1048 | } | ||
1049 | #endif | ||||
1022 | 1050 | | |||
1051 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1) | ||||
1023 | bool KRun::doScanFile() const | 1052 | bool KRun::doScanFile() const | ||
1024 | { | 1053 | { | ||
1025 | return d->m_bScanFile; | 1054 | return d->m_bScanFile; | ||
1026 | } | 1055 | } | ||
1056 | #endif | ||||
1027 | 1057 | | |||
1058 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1) | ||||
1028 | void KRun::setIsDirecory(bool isDirectory) | 1059 | void KRun::setIsDirecory(bool isDirectory) | ||
1029 | { | 1060 | { | ||
1030 | d->m_bIsDirectory = isDirectory; | 1061 | d->m_bIsDirectory = isDirectory; | ||
1031 | } | 1062 | } | ||
1063 | #endif | ||||
1032 | 1064 | | |||
1033 | bool KRun::isDirectory() const | 1065 | bool KRun::isDirectory() const | ||
1034 | { | 1066 | { | ||
1035 | return d->m_bIsDirectory; | 1067 | return d->m_bIsDirectory; | ||
1036 | } | 1068 | } | ||
1037 | 1069 | | |||
1070 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1) | ||||
1038 | void KRun::setInitializeNextAction(bool initialize) | 1071 | void KRun::setInitializeNextAction(bool initialize) | ||
1039 | { | 1072 | { | ||
1040 | d->m_bInit = initialize; | 1073 | d->m_bInit = initialize; | ||
1041 | } | 1074 | } | ||
1075 | #endif | ||||
1042 | 1076 | | |||
1077 | #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1) | ||||
1043 | bool KRun::initializeNextAction() const | 1078 | bool KRun::initializeNextAction() const | ||
1044 | { | 1079 | { | ||
1045 | return d->m_bInit; | 1080 | return d->m_bInit; | ||
1046 | } | 1081 | } | ||
1082 | #endif | ||||
1047 | 1083 | | |||
1048 | bool KRun::isLocalFile() const | 1084 | bool KRun::isLocalFile() const | ||
1049 | { | 1085 | { | ||
1050 | return d->m_strURL.isLocalFile(); | 1086 | return d->m_strURL.isLocalFile(); | ||
1051 | } | 1087 | } | ||
1052 | 1088 | | |||
1053 | #include "moc_krun.cpp" | 1089 | #include "moc_krun.cpp" | ||
1054 | #include "moc_krun_p.cpp" | 1090 | #include "moc_krun_p.cpp" |