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.
wilder-5.14
Luboš Luňák 9 years ago
parent 9122ab0a67
commit c5dde9da68
  1. 1
      klipper/CMakeLists.txt
  2. 35
      klipper/urlgrabber.cpp
  3. 6
      klipper/urlgrabber.h

@ -46,6 +46,7 @@ target_link_libraries(kdeinit_klipper
KF5::DBusAddons KF5::DBusAddons
KF5::GlobalAccel KF5::GlobalAccel
KF5::IconThemes KF5::IconThemes
KF5::KIOWidgets
KF5::Notifications KF5::Notifications
KF5::Service KF5::Service
KF5::TextWidgets KF5::TextWidgets

@ -33,7 +33,7 @@
#include <KIconLoader> #include <KIconLoader>
#include <KStringHandler> #include <KStringHandler>
#include <KMimeTypeTrader> #include <KMimeTypeTrader>
#include <KMacroExpander> #include <KRun>
#include <KWindowSystem> #include <KWindowSystem>
#include "klippersettings.h" #include "klippersettings.h"
@ -149,14 +149,8 @@ void URLGrabber::matchingMimeActions(const QString& clipData)
if ( !lst.isEmpty() ) { if ( !lst.isEmpty() ) {
ClipAction* action = new ClipAction( QString(), mimetype.comment() ); ClipAction* action = new ClipAction( QString(), mimetype.comment() );
foreach( const KService::Ptr &service, lst ) { foreach( const KService::Ptr &service, lst ) {
QHash<QChar,QString> map; action->addCommand( ClipCommand( QString(), service->name(), true, service->icon(),
map.insert( 'i', "--icon " + service->icon() ); ClipCommand::IGNORE, service->storageId() ) );
map.insert( 'c', service->name() );
QString exec = service->exec();
exec = KMacroExpander::expandMacros( exec, map ).trimmed();
action->addCommand( ClipCommand( exec, service->name(), true, service->icon() ) );
} }
m_myMatches.append( action ); m_myMatches.append( action );
} }
@ -299,12 +293,17 @@ void URLGrabber::execute( const ClipAction* action, int cmdIdx ) const
if (m_stripWhiteSpace) { if (m_stripWhiteSpace) {
text = text.trimmed(); text = text.trimmed();
} }
ClipCommandProcess* proc = new ClipCommandProcess(*action, command, text, m_history, m_myClipItem); if( !command.serviceStorageId.isEmpty()) {
if (proc->program().isEmpty()) { KService::Ptr service = KService::serviceByStorageId( command.serviceStorageId );
delete proc; KRun::runApplication( *service, QList< QUrl >() << QUrl( text ), nullptr );
proc = 0L;
} else { } 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, 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), : command(_command),
description(_description), description(_description),
isEnabled(_isEnabled), isEnabled(_isEnabled),
output(_output) output(_output),
serviceStorageId( _serviceStorageId)
{ {
if (!_icon.isEmpty()) if (!_icon.isEmpty())
@ -441,7 +442,7 @@ ClipAction::~ClipAction()
void ClipAction::addCommand( const ClipCommand& cmd ) void ClipAction::addCommand( const ClipCommand& cmd )
{ {
if ( cmd.command.isEmpty() ) if ( cmd.command.isEmpty() && cmd.serviceStorageId.isEmpty() )
return; return;
m_myCommands.append( cmd ); m_myCommands.append( cmd );

@ -115,13 +115,17 @@ struct ClipCommand
const QString& _description, const QString& _description,
bool enabled=true, bool enabled=true,
const QString& _icon=QString(), const QString& _icon=QString(),
Output _output=IGNORE); Output _output=IGNORE,
const QString& serviceStorageId = QString());
QString command; QString command;
QString description; QString description;
bool isEnabled; bool isEnabled;
QString icon; QString icon;
Output output; 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) Q_DECLARE_METATYPE(ClipCommand::Output)

Loading…
Cancel
Save