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)