From c5dde9da6859da55ec4f33ffb9da75f4f1d67796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Thu, 11 May 2017 11:26:23 +0200 Subject: [PATCH] make klipper launch mimetype-handling apps normally using KRun Launching .desktop files using KProcess skips handling that should be done when launching apps. E.g. opening an URL with Firefox will make the new window open in background if Firefox is already running, because startup notification hasn't been handled at all. And KProcess is useless in this case anyway, as Klipper doesn't care about stdout of Firefox. --- klipper/CMakeLists.txt | 1 + klipper/urlgrabber.cpp | 35 ++++++++++++++++++----------------- klipper/urlgrabber.h | 6 +++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/klipper/CMakeLists.txt b/klipper/CMakeLists.txt index cf4b5c972..3cf37cd49 100644 --- a/klipper/CMakeLists.txt +++ b/klipper/CMakeLists.txt @@ -46,6 +46,7 @@ target_link_libraries(kdeinit_klipper KF5::DBusAddons KF5::GlobalAccel KF5::IconThemes + KF5::KIOWidgets KF5::Notifications KF5::Service KF5::TextWidgets diff --git a/klipper/urlgrabber.cpp b/klipper/urlgrabber.cpp index 5cdf76b66..6a7a30fb9 100644 --- a/klipper/urlgrabber.cpp +++ b/klipper/urlgrabber.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include "klippersettings.h" @@ -149,14 +149,8 @@ void URLGrabber::matchingMimeActions(const QString& clipData) if ( !lst.isEmpty() ) { ClipAction* action = new ClipAction( QString(), mimetype.comment() ); foreach( const KService::Ptr &service, lst ) { - QHash map; - map.insert( 'i', "--icon " + service->icon() ); - map.insert( 'c', service->name() ); - - QString exec = service->exec(); - exec = KMacroExpander::expandMacros( exec, map ).trimmed(); - - action->addCommand( ClipCommand( exec, service->name(), true, service->icon() ) ); + action->addCommand( ClipCommand( QString(), service->name(), true, service->icon(), + ClipCommand::IGNORE, service->storageId() ) ); } m_myMatches.append( action ); } @@ -299,12 +293,17 @@ void URLGrabber::execute( const ClipAction* action, int cmdIdx ) const if (m_stripWhiteSpace) { text = text.trimmed(); } - ClipCommandProcess* proc = new ClipCommandProcess(*action, command, text, m_history, m_myClipItem); - if (proc->program().isEmpty()) { - delete proc; - proc = 0L; + if( !command.serviceStorageId.isEmpty()) { + KService::Ptr service = KService::serviceByStorageId( command.serviceStorageId ); + KRun::runApplication( *service, QList< QUrl >() << QUrl( text ), nullptr ); } else { - proc->start(); + ClipCommandProcess* proc = new ClipCommandProcess(*action, command, text, m_history, m_myClipItem); + if (proc->program().isEmpty()) { + delete proc; + proc = 0L; + } else { + proc->start(); + } } } } @@ -377,11 +376,13 @@ void URLGrabber::slotKillPopupMenu() //////// ClipCommand::ClipCommand(const QString&_command, const QString& _description, - bool _isEnabled, const QString& _icon, Output _output) + bool _isEnabled, const QString& _icon, Output _output, + const QString& _serviceStorageId) : command(_command), description(_description), isEnabled(_isEnabled), - output(_output) + output(_output), + serviceStorageId( _serviceStorageId) { if (!_icon.isEmpty()) @@ -441,7 +442,7 @@ ClipAction::~ClipAction() void ClipAction::addCommand( const ClipCommand& cmd ) { - if ( cmd.command.isEmpty() ) + if ( cmd.command.isEmpty() && cmd.serviceStorageId.isEmpty() ) return; m_myCommands.append( cmd ); diff --git a/klipper/urlgrabber.h b/klipper/urlgrabber.h index da51017b5..05cbfa958 100644 --- a/klipper/urlgrabber.h +++ b/klipper/urlgrabber.h @@ -115,13 +115,17 @@ struct ClipCommand const QString& _description, bool enabled=true, const QString& _icon=QString(), - Output _output=IGNORE); + Output _output=IGNORE, + const QString& serviceStorageId = QString()); QString command; QString description; bool isEnabled; QString icon; Output output; + // If this is set, it's an app to handle a mimetype, and will be launched normally using KRun. + // StorageId is used instead of KService::Ptr, because the latter disallows operator=. + QString serviceStorageId; }; Q_DECLARE_METATYPE(ClipCommand::Output)