Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/krun.cpp
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 171 | if (runExecutables) { | |||
---|---|---|---|---|---|
172 | flags |= KRun::RunExecutables; | 172 | flags |= KRun::RunExecutables; | ||
173 | } | 173 | } | ||
174 | 174 | | |||
175 | return runUrl(url, mimetype, window, flags, suggestedFileName, asn); | 175 | return runUrl(url, mimetype, window, flags, suggestedFileName, asn); | ||
176 | } | 176 | } | ||
177 | #endif | 177 | #endif | ||
178 | 178 | | |||
179 | // This is called by foundMimeType, since it knows the mimetype of the URL | 179 | // This is called by foundMimeType, since it knows the mimetype of the URL | ||
180 | bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn) | 180 | bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn, unsigned cursorRow, unsigned cursorColumn) | ||
181 | { | 181 | { | ||
182 | const bool runExecutables = flags.testFlag(KRun::RunExecutables); | 182 | const bool runExecutables = flags.testFlag(KRun::RunExecutables); | ||
183 | const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles); | 183 | const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles); | ||
184 | bool noRun = false; | 184 | bool noRun = false; | ||
185 | bool noAuth = false; | 185 | bool noAuth = false; | ||
186 | if (_mimetype == QLatin1String("inode/directory-locked")) { | 186 | if (_mimetype == QLatin1String("inode/directory-locked")) { | ||
187 | KMessageBox::error(window, | 187 | KMessageBox::error(window, | ||
188 | i18n("<qt>Unable to enter <b>%1</b>.\nYou do not have access rights to this location.</qt>", u.toDisplayString().toHtmlEscaped())); | 188 | i18n("<qt>Unable to enter <b>%1</b>.\nYou do not have access rights to this location.</qt>", u.toDisplayString().toHtmlEscaped())); | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
238 | #else | 238 | #else | ||
239 | // Open-with dialog | 239 | // Open-with dialog | ||
240 | // TODO : pass the mimetype as a parameter, to show it (comment field) in the dialog ! | 240 | // TODO : pass the mimetype as a parameter, to show it (comment field) in the dialog ! | ||
241 | // Hmm, in fact KOpenWithDialog::setServiceType already guesses the mimetype from the first URL of the list... | 241 | // Hmm, in fact KOpenWithDialog::setServiceType already guesses the mimetype from the first URL of the list... | ||
242 | return displayOpenWithDialog(lst, window, tempFile, suggestedFileName, asn); | 242 | return displayOpenWithDialog(lst, window, tempFile, suggestedFileName, asn); | ||
243 | #endif | 243 | #endif | ||
244 | } | 244 | } | ||
245 | 245 | | |||
246 | return KRun::runService(*offer, lst, window, tempFile, suggestedFileName, asn); | 246 | return KRun::runService(*offer, lst, window, tempFile, suggestedFileName, asn, cursorRow, cursorColumn); | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | bool KRun::displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles, | 249 | bool KRun::displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles, | ||
250 | const QString &suggestedFileName, const QByteArray &asn) | 250 | const QString &suggestedFileName, const QByteArray &asn) | ||
251 | { | 251 | { | ||
252 | if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { | 252 | if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { | ||
253 | KMessageBox::sorry(window, | 253 | KMessageBox::sorry(window, | ||
254 | i18n("You are not authorized to select an application to open this file.")); | 254 | i18n("You are not authorized to select an application to open this file.")); | ||
▲ Show 20 Lines • Show All 506 Lines • ▼ Show 20 Line(s) | 760 | for (const QUrl &url : urls) { | |||
761 | KRecentDocument::add(url, service.desktopEntryName()); | 761 | KRecentDocument::add(url, service.desktopEntryName()); | ||
762 | } | 762 | } | ||
763 | } | 763 | } | ||
764 | 764 | | |||
765 | return runApplicationImpl(service, urls, window, flags, suggestedFileName, asn); | 765 | return runApplicationImpl(service, urls, window, flags, suggestedFileName, asn); | ||
766 | } | 766 | } | ||
767 | 767 | | |||
768 | qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | 768 | qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window, | ||
769 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) | 769 | bool tempFiles, const QString &suggestedFileName, const QByteArray &asn, | ||
770 | unsigned cursorRow, unsigned cursorColumn) | ||||
770 | { | 771 | { | ||
771 | if (!_service.entryPath().isEmpty() && | 772 | if (!_service.entryPath().isEmpty() && | ||
772 | !KDesktopFile::isAuthorizedDesktopFile(_service.entryPath()) && | 773 | !KDesktopFile::isAuthorizedDesktopFile(_service.entryPath()) && | ||
773 | !::makeServiceExecutable(_service, window)) { | 774 | !::makeServiceExecutable(_service, window)) { | ||
774 | return 0; | 775 | return 0; | ||
775 | } | 776 | } | ||
776 | 777 | | |||
777 | if (!tempFiles) { | 778 | if (!tempFiles) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 818 | if (myasn != "0") { | |||
823 | // its parent window instead | 824 | // its parent window instead | ||
824 | if (window->window()) { | 825 | if (window->window()) { | ||
825 | data.setLaunchedBy(window->window()->winId()); | 826 | data.setLaunchedBy(window->window()->winId()); | ||
826 | } | 827 | } | ||
827 | KStartupInfo::sendChange(id, data); | 828 | KStartupInfo::sendChange(id, data); | ||
828 | } | 829 | } | ||
829 | } | 830 | } | ||
830 | 831 | | |||
832 | QStringList args = QUrl::toStringList(urls); | ||||
833 | // factor into KService::supportsPassingCursorInformation() ? | ||||
834 | if(_service.name() == QStringLiteral("KWrite") || _service.name() == QStringLiteral("Kate")) { | ||||
835 | args << QStringLiteral("--line") << QString::number(cursorRow == 0 ? 1 : cursorRow); // Kate counts lines/cols from 1 | ||||
836 | args << QStringLiteral("--column") << QString::number(cursorColumn == 0 ? 1 : cursorColumn); | ||||
837 | } | ||||
838 | | ||||
831 | int i = KToolInvocation::startServiceByDesktopPath( | 839 | int i = KToolInvocation::startServiceByDesktopPath( | ||
832 | _service.entryPath(), QUrl::toStringList(urls), &error, nullptr, &pid, myasn | 840 | _service.entryPath(), args, &error, nullptr, &pid, myasn | ||
833 | ); | 841 | ); | ||
834 | 842 | | |||
835 | if (i != 0) { | 843 | if (i != 0) { | ||
836 | //qDebug() << error; | 844 | //qDebug() << error; | ||
837 | KMessageBox::sorry(window, error); | 845 | KMessageBox::sorry(window, error); | ||
838 | return 0; | 846 | return 0; | ||
839 | } | 847 | } | ||
840 | 848 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 912 | { | |||
908 | m_bFinished = false; | 916 | m_bFinished = false; | ||
909 | m_job = nullptr; | 917 | m_job = nullptr; | ||
910 | m_strURL = url; | 918 | m_strURL = url; | ||
911 | m_bScanFile = false; | 919 | m_bScanFile = false; | ||
912 | m_bIsDirectory = false; | 920 | m_bIsDirectory = false; | ||
913 | m_runExecutables = true; | 921 | m_runExecutables = true; | ||
914 | m_window = window; | 922 | m_window = window; | ||
915 | m_asn = asn; | 923 | m_asn = asn; | ||
924 | m_cursorRow = 0; | ||||
925 | m_cursorColumn = 0; | ||||
916 | q->setEnableExternalBrowser(true); | 926 | q->setEnableExternalBrowser(true); | ||
917 | 927 | | |||
918 | // Start the timer. This means we will return to the event | 928 | // Start the timer. This means we will return to the event | ||
919 | // loop and do initialization afterwards. | 929 | // loop and do initialization afterwards. | ||
920 | // Reason: We must complete the constructor before we do anything else. | 930 | // Reason: We must complete the constructor before we do anything else. | ||
921 | m_bCheckPrompt = false; | 931 | m_bCheckPrompt = false; | ||
922 | m_bInit = true; | 932 | m_bInit = true; | ||
923 | q->connect(m_timer, &QTimer::timeout, q, &KRun::slotTimeout); | 933 | q->connect(m_timer, &QTimer::timeout, q, &KRun::slotTimeout); | ||
▲ Show 20 Lines • Show All 424 Lines • ▼ Show 20 Line(s) | 1319 | { | |||
1348 | } else if (mime.inherits(QStringLiteral("application/x-desktop")) && !d->m_localPath.isEmpty()) { | 1358 | } else if (mime.inherits(QStringLiteral("application/x-desktop")) && !d->m_localPath.isEmpty()) { | ||
1349 | d->m_strURL = QUrl::fromLocalFile(d->m_localPath); | 1359 | d->m_strURL = QUrl::fromLocalFile(d->m_localPath); | ||
1350 | } | 1360 | } | ||
1351 | 1361 | | |||
1352 | KRun::RunFlags runFlags; | 1362 | KRun::RunFlags runFlags; | ||
1353 | if (d->m_runExecutables) { | 1363 | if (d->m_runExecutables) { | ||
1354 | runFlags |= KRun::RunExecutables; | 1364 | runFlags |= KRun::RunExecutables; | ||
1355 | } | 1365 | } | ||
1356 | if (!KRun::runUrl(d->m_strURL, type, d->m_window, runFlags, d->m_suggestedFileName, d->m_asn)) { | 1366 | if (!KRun::runUrl(d->m_strURL, type, d->m_window, runFlags, d->m_suggestedFileName, d->m_asn, d->m_cursorRow, d->m_cursorColumn)) { | ||
1357 | d->m_bFault = true; | 1367 | d->m_bFault = true; | ||
1358 | } | 1368 | } | ||
1359 | setFinished(true); | 1369 | setFinished(true); | ||
1360 | } | 1370 | } | ||
1361 | 1371 | | |||
1362 | void KRun::killJob() | 1372 | void KRun::killJob() | ||
1363 | { | 1373 | { | ||
1364 | if (d->m_job) { | 1374 | if (d->m_job) { | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 1460 | { | |||
1451 | d->m_suggestedFileName = fileName; | 1461 | d->m_suggestedFileName = fileName; | ||
1452 | } | 1462 | } | ||
1453 | 1463 | | |||
1454 | void KRun::setShowScriptExecutionPrompt(bool showPrompt) | 1464 | void KRun::setShowScriptExecutionPrompt(bool showPrompt) | ||
1455 | { | 1465 | { | ||
1456 | d->m_bCheckPrompt = showPrompt; | 1466 | d->m_bCheckPrompt = showPrompt; | ||
1457 | } | 1467 | } | ||
1458 | 1468 | | |||
1469 | void KRun::setCursorInformation(unsigned row, unsigned column) | ||||
1470 | { | ||||
1471 | d->m_cursorRow = row; | ||||
1472 | d->m_cursorColumn = column; | ||||
1473 | } | ||||
1474 | | ||||
1459 | QString KRun::suggestedFileName() const | 1475 | QString KRun::suggestedFileName() const | ||
1460 | { | 1476 | { | ||
1461 | return d->m_suggestedFileName; | 1477 | return d->m_suggestedFileName; | ||
1462 | } | 1478 | } | ||
1463 | 1479 | | |||
1464 | bool KRun::isExecutable(const QString &serviceType) | 1480 | bool KRun::isExecutable(const QString &serviceType) | ||
1465 | { | 1481 | { | ||
1466 | return (serviceType == QLatin1String("application/x-desktop") || | 1482 | return (serviceType == QLatin1String("application/x-desktop") || | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |