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::GlobalAccel
KF5::IconThemes
KF5::KIOWidgets
KF5::Notifications
KF5::Service
KF5::TextWidgets

@ -33,7 +33,7 @@
#include <KIconLoader>
#include <KStringHandler>
#include <KMimeTypeTrader>
#include <KMacroExpander>
#include <KRun>
#include <KWindowSystem>
#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<QChar,QString> 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 );

@ -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)

Loading…
Cancel
Save