From a91ec41cc69036bc69d72cfbd89c65f680a58637 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 12 May 2024 03:22:20 +0300 Subject: [PATCH] generic: adjust to KRun changes Signed-off-by: Ivailo Monev --- ark/app/batchextract.cpp | 4 ++-- ark/part/arkviewer.cpp | 14 ++++--------- ark/part/part.cpp | 7 ++----- filelight/src/part/radialMap/widgetEvents.cpp | 21 +++++++------------ gwenview/app/fileopscontextmanageritem.cpp | 6 +++--- gwenview/importer/importdialog.cpp | 10 ++------- .../applets/bookmarks/bookmarkowner.h | 4 ++-- kdeplasma-addons/applets/frame/frame.cpp | 4 ++-- .../konsoleprofiles/konsoleprofiles.cpp | 6 +----- kdeplasma-addons/applets/timer/timer.cpp | 2 +- .../runners/katesessions/katesessions.cpp | 2 +- .../konsolesessions/konsolesessions.cpp | 2 +- ksnapshot/ksnapshot.cpp | 19 +++++++++-------- okular/core/document.cpp | 7 ++----- okular/ui/pageview.cpp | 5 ++--- .../src/gui/applyprogressdialog.cpp | 10 ++------- 16 files changed, 45 insertions(+), 78 deletions(-) diff --git a/ark/app/batchextract.cpp b/ark/app/batchextract.cpp index 1f70cdd3..e8a21db4 100644 --- a/ark/app/batchextract.cpp +++ b/ark/app/batchextract.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include @@ -181,7 +181,7 @@ void BatchExtract::slotResult(KJob *job) if (openDestinationAfterExtraction()) { KUrl destination(destinationFolder()); destination.cleanPath(); - KRun::runUrl(destination, QLatin1String( "inode/directory" ), 0); + KToolInvocation::self()->startServiceForUrl(destination.url()); } kDebug() << "Finished, emitting the result"; diff --git a/ark/part/arkviewer.cpp b/ark/part/arkviewer.cpp index cad95af6..279faea9 100644 --- a/ark/part/arkviewer.cpp +++ b/ark/part/arkviewer.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -88,22 +88,16 @@ void ArkViewer::dialogClosed() void ArkViewer::view(const QString& fileName, QWidget *parent) { - const KUrl fileNameUrl = KUrl(fileName); - KMimeType::Ptr mimeType = KMimeType::findByUrl(fileNameUrl); + KMimeType::Ptr mimeType = KMimeType::findByUrl(KUrl(fileName)); kDebug() << "MIME type" << mimeType->name(); KService::Ptr viewer = ArkViewer::getViewer(mimeType); const bool needsExternalViewer = (!viewer.isNull() && !viewer->hasServiceType(QLatin1String("KParts/ReadOnlyPart"))); if (needsExternalViewer) { - // We have already resolved the MIME type and the service above. - // So there is no point in using KRun::runUrl() which would need - // to do the same again. - - const KUrl::List fileUrlList = fileNameUrl; - // The last argument (tempFiles) set to true means that the temporary + // The last argument (temp) set to true means that the temporary // file will be removed when the viewer application exits. - KRun::run(*viewer, fileUrlList, parent, true); + KToolInvocation::self()->startServiceByStorageId(viewer->entryPath(), QStringList() << fileName, parent, true); return; } diff --git a/ark/part/part.cpp b/ark/part/part.cpp index 02805261..86bd62d8 100644 --- a/ark/part/part.cpp +++ b/ark/part/part.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -754,11 +755,7 @@ void Part::slotExtractionDone(KJob* job) } if (ArkSettings::openDestinationFolderAfterExtraction()) { - - KUrl destinationDirectory(extractJob->destinationDirectory()); - destinationDirectory.cleanPath(); - - KRun::runUrl(destinationDirectory, QLatin1String("inode/directory"), widget()); + KToolInvocation::self()->startServiceForUrl(extractJob->destinationDirectory(), widget()); } if (ArkSettings::closeAfterExtraction()) { diff --git a/filelight/src/part/radialMap/widgetEvents.cpp b/filelight/src/part/radialMap/widgetEvents.cpp index a5e150ac..937589fb 100644 --- a/filelight/src/part/radialMap/widgetEvents.cpp +++ b/filelight/src/part/radialMap/widgetEvents.cpp @@ -25,26 +25,21 @@ #include "widget.h" #include -#include //::mousePressEvent() +#include #include -#include //::mousePressEvent() +#include #include #include #include -#include //::mousePressEvent() -#include //::mousePressEvent() -#include //::mousePressEvent() +#include +#include #include #include -#include //QApplication::setOverrideCursor() +#include #include #include -#include //::resizeEvent() - - - - +#include #include #include @@ -239,7 +234,7 @@ void RadialMap::Widget::mousePressEvent(QMouseEvent *e) QAction* clicked = popup.exec(e->globalPos(), 0); if (openFileManager && clicked == openFileManager) { - KRun::runUrl(url.url(),QLatin1String( "inode/directory" ), this); + KToolInvocation::self()->startServiceForUrl(url.url(), this); } else if (openTerminal && clicked == openTerminal) { KToolInvocation::self()->invokeTerminal(QString(), url.path()); } else if (centerMap && clicked == centerMap) { @@ -279,7 +274,7 @@ section_two: if (!isDir || e->button() == Qt::MiddleButton) { // KIconEffect::visualActivate(this, rect); // TODO: recreate this - new KRun(url, this, true); //FIXME see above + KToolInvocation::self()->startServiceForUrl(url.url(), this); //FIXME see above } else if (m_focus->file() != m_tree) { // is left click // KIconEffect::visualActivate(this, rect); // TODO: recreate this diff --git a/gwenview/app/fileopscontextmanageritem.cpp b/gwenview/app/fileopscontextmanageritem.cpp index 714d3215..b9304a0f 100644 --- a/gwenview/app/fileopscontextmanageritem.cpp +++ b/gwenview/app/fileopscontextmanageritem.cpp @@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include -#include +#include #include #include @@ -441,7 +441,7 @@ void FileOpsContextManagerItem::openWith(QAction* action) if (!service) { // User entered a custom command Q_ASSERT(!dlg.text().isEmpty()); - KRun::run(dlg.text(), list, d->mGroup); + KToolInvocation::self()->startProgram(dlg.text(), list.toStringList(), d->mGroup); return; } } else { @@ -449,7 +449,7 @@ void FileOpsContextManagerItem::openWith(QAction* action) } Q_ASSERT(service); - KRun::run(*service, list, d->mGroup); + KToolInvocation::self()->startServiceByStorageId(service->entryPath(), list.toStringList(), d->mGroup); } } // namespace diff --git a/gwenview/importer/importdialog.cpp b/gwenview/importer/importdialog.cpp index ee11161e..cc70f0dd 100644 --- a/gwenview/importer/importdialog.cpp +++ b/gwenview/importer/importdialog.cpp @@ -34,8 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA #include #include #include -#include -#include +#include #include #include @@ -143,12 +142,7 @@ public: void startGwenview() { - KService::Ptr service = KService::serviceByDesktopName("gwenview"); - if (!service) { - kError() << "Could not find gwenview"; - } else { - KRun::run(*service, KUrl::List() << mThumbnailPage->destinationUrl(), 0 /* window */); - } + KToolInvocation::self()->startServiceByStorageId("gwenview", QStringList() << mThumbnailPage->destinationUrl().url()); } void showWhatNext() diff --git a/kdeplasma-addons/applets/bookmarks/bookmarkowner.h b/kdeplasma-addons/applets/bookmarks/bookmarkowner.h index 298a00f6..1ce01df4 100644 --- a/kdeplasma-addons/applets/bookmarks/bookmarkowner.h +++ b/kdeplasma-addons/applets/bookmarks/bookmarkowner.h @@ -25,7 +25,7 @@ // KDE #include -#include +#include class BookmarkOwner : public KBookmarkOwner @@ -47,7 +47,7 @@ inline bool BookmarkOwner::enableOption(BookmarkOption) const } inline void BookmarkOwner::openBookmark(const KBookmark& bookmark, Qt::MouseButtons, Qt::KeyboardModifiers) { - new KRun(bookmark.url(), (QWidget*)0); + KToolInvocation::self()->startServiceForUrl(bookmark.url().url()); } #endif diff --git a/kdeplasma-addons/applets/frame/frame.cpp b/kdeplasma-addons/applets/frame/frame.cpp index 4ac0a8e9..c862e99e 100644 --- a/kdeplasma-addons/applets/frame/frame.cpp +++ b/kdeplasma-addons/applets/frame/frame.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -213,7 +213,7 @@ void Frame::slotOpenPicture() } if (!url.path().isEmpty()) { - new KRun(url, 0); + KToolInvocation::self()->startServiceForUrl(url.url()); } } diff --git a/kdeplasma-addons/applets/konsoleprofiles/konsoleprofiles.cpp b/kdeplasma-addons/applets/konsoleprofiles/konsoleprofiles.cpp index 6e189581..0245f28c 100644 --- a/kdeplasma-addons/applets/konsoleprofiles/konsoleprofiles.cpp +++ b/kdeplasma-addons/applets/konsoleprofiles/konsoleprofiles.cpp @@ -163,11 +163,7 @@ void KonsoleProfilesWidget::slotProfileClicked() Q_ASSERT(!profilename.isEmpty()); const QStringList konsoleargs = QStringList() << "--profile" << profilename; - QString invocationerror; - const int invocationresult = KToolInvocation::self()->kdeinitExec("konsole", konsoleargs, &invocationerror); - if (invocationresult != 0) { - m_konsoleprofiles->showMessage(KIcon("dialog-error"), invocationerror, Plasma::ButtonOk); - } + KToolInvocation::self()->startProgram("konsole", konsoleargs); } KonsoleProfilesApplet::KonsoleProfilesApplet(QObject *parent, const QVariantList &args) diff --git a/kdeplasma-addons/applets/timer/timer.cpp b/kdeplasma-addons/applets/timer/timer.cpp index dbf239c0..7f7e9abb 100644 --- a/kdeplasma-addons/applets/timer/timer.cpp +++ b/kdeplasma-addons/applets/timer/timer.cpp @@ -367,7 +367,7 @@ void Timer::slotCountDone() QStringList args = KShell::splitArgs(m_command); QString command = args[0]; args.removeFirst(); - KToolInvocation::self()->kdeinitExec(command, args); + KToolInvocation::self()->startProgram(command, args); } } diff --git a/kdeplasma-addons/runners/katesessions/katesessions.cpp b/kdeplasma-addons/runners/katesessions/katesessions.cpp index ff415eea..6480b184 100644 --- a/kdeplasma-addons/runners/katesessions/katesessions.cpp +++ b/kdeplasma-addons/runners/katesessions/katesessions.cpp @@ -133,7 +133,7 @@ void KateSessions::run(const Plasma::QueryMatch &match) if (!session.isEmpty()) { QStringList args; args << QLatin1String("--start") << session << QLatin1String("-n"); - KToolInvocation::self()->kdeinitExec(QLatin1String("kate"), args); + KToolInvocation::self()->startProgram(QLatin1String("kate"), args); } } diff --git a/kdeplasma-addons/runners/konsolesessions/konsolesessions.cpp b/kdeplasma-addons/runners/konsolesessions/konsolesessions.cpp index 19102a6c..7d35a3a0 100644 --- a/kdeplasma-addons/runners/konsolesessions/konsolesessions.cpp +++ b/kdeplasma-addons/runners/konsolesessions/konsolesessions.cpp @@ -130,7 +130,7 @@ void KonsoleSessions::run(const Plasma::QueryMatch &match) args << QLatin1String( "--profile" ); args << session; kDebug() << "=== START: konsole" << args; - KToolInvocation::self()->kdeinitExec(QLatin1String("konsole"), args); + KToolInvocation::self()->startProgram(QLatin1String("konsole"), args); } } diff --git a/ksnapshot/ksnapshot.cpp b/ksnapshot/ksnapshot.cpp index da1cbef3..7d970d3b 100644 --- a/ksnapshot/ksnapshot.cpp +++ b/ksnapshot/ksnapshot.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include #include #include @@ -421,9 +421,7 @@ void KSnapshot::slotOpen(const QString& application) return; } - KUrl::List list; - list.append(url); - KRun::run(application, list, this); + KToolInvocation::self()->startServiceByStorageId(application, QStringList() << url.url(), this); } void KSnapshot::slotOpen(QAction* action) @@ -460,15 +458,18 @@ void KSnapshot::slotOpen(QAction* action) if (!service && !dlg->text().isEmpty()) { - KRun::run(dlg->text(), list, this); - delete dlg; - return; + KToolInvocation::self()->startProgram(dlg->text(), list.toStringList(), this, true); + delete dlg; + return; } - delete dlg; + delete dlg; } + if (!service) { + return; + } // we have an action with a service, run it! - KRun::run(*service, list, this, isTempfile); + KToolInvocation::self()->startServiceByStorageId(service->entryPath(), list.toStringList(), this, true); } void KSnapshot::slotPopulateOpenMenu() diff --git a/okular/core/document.cpp b/okular/core/document.cpp index d029c24f..91b06925 100644 --- a/okular/core/document.cpp +++ b/okular/core/document.cpp @@ -3424,9 +3424,7 @@ void Document::processAction( const Action * action ) KService::Ptr ptr = KMimeTypeTrader::self()->preferredService( mime->name(), "Application" ); if ( ptr ) { - KUrl::List lst; - lst.append( fileName ); - KRun::run( *ptr, lst, 0 ); + KToolInvocation::self()->startServiceByStorageId( ptr->entryPath(), QStringList() << fileName ); } else { @@ -3512,8 +3510,7 @@ void Document::processAction( const Action * action ) realUrl = KUrl( d->m_url.upUrl(), url ); } - // Albert: this is not a leak! - new KRun( realUrl, d->m_widget ); + KToolInvocation::self()->startServiceForUrl( realUrl.url(), d->m_widget ); } break; } diff --git a/okular/ui/pageview.cpp b/okular/ui/pageview.cpp index 4088e951..e75b9d1d 100644 --- a/okular/ui/pageview.cpp +++ b/okular/ui/pageview.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include // system includes @@ -2731,7 +2730,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e ) if ( choice == textToClipboard ) copyTextSelection(); else if ( choice == httpLink ) - new KRun( url, this ); + KToolInvocation::self()->startServiceForUrl( url.url(), this ); } } } @@ -4385,7 +4384,7 @@ void PageView::slotHandleWebShortcutAction() void PageView::slotConfigureWebShortcuts() { - KToolInvocation::self()->kdeinitExec( "kcmshell4", QStringList() << "ebrowsing" ); + KToolInvocation::self()->startProgram( "kcmshell4", QStringList() << "ebrowsing" ); } void PageView::slotZoom() diff --git a/partitionmanager/src/gui/applyprogressdialog.cpp b/partitionmanager/src/gui/applyprogressdialog.cpp index a605c633..6f8ae4b5 100644 --- a/partitionmanager/src/gui/applyprogressdialog.cpp +++ b/partitionmanager/src/gui/applyprogressdialog.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -417,8 +417,6 @@ void ApplyProgressDialog::browserReport() { KTemporaryFile file; - // Make sure the temp file is created somewhere another user can read it: KRun::runUrl() will open - // the file as the logged in user, not as the user running our application. file.setFileTemplate("/tmp/" + KGlobal::mainComponent().aboutData()->appName() + "-XXXXXX.html"); file.setAutoRemove(false); @@ -432,11 +430,7 @@ void ApplyProgressDialog::browserReport() << report().toHtml() << html.footer(); - // set the temp file's permission for everyone to read it. - file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); - - if (!KRun::runUrl(file.fileName(), "text/html", this, true)) - KMessageBox::sorry(this, i18nc("@info", "The configured external browser could not be run. Please check your settings."), i18nc("@title:window", "Could Not Launch Browser.")); + KToolInvocation::self()->startServiceForUrl(file.fileName(), this, true); } else KMessageBox::sorry(this, i18nc("@info", "Could not create temporary file %1 for writing.", file.fileName()), i18nc("@title:window", "Could Not Launch Browser."));