Port global applet shortcut from KAction to QAction
- use QAction instead of KAction - use KGlobalAccel for global shortcut registration and query
This commit is contained in:
parent
e02925b7b5
commit
fc2afcb9a1
@ -38,6 +38,7 @@
|
||||
#include <kcolorscheme.h>
|
||||
#include <kdesktopfile.h>
|
||||
#include <kdebug.h>
|
||||
#include <kglobalaccel.h>
|
||||
#include <kplugininfo.h>
|
||||
#include <klocalizedstring.h>
|
||||
#include <kservice.h>
|
||||
@ -572,28 +573,27 @@ Containment *Applet::containment() const
|
||||
void Applet::setGlobalShortcut(const KShortcut &shortcut)
|
||||
{
|
||||
if (!d->activationAction) {
|
||||
d->activationAction = new KAction(this);
|
||||
d->activationAction = new QAction(this);
|
||||
d->activationAction->setText(i18n("Activate %1 Widget", title()));
|
||||
d->activationAction->setObjectName(QString("activate widget %1").arg(id())); // NO I18N
|
||||
connect(d->activationAction, SIGNAL(triggered()), this, SIGNAL(activate()));
|
||||
connect(d->activationAction, SIGNAL(globalShortcutChanged(QKeySequence)),
|
||||
this, SLOT(globalShortcutChanged()));
|
||||
} else if (d->activationAction->globalShortcut() == shortcut) {
|
||||
} else if (d->activationAction->shortcut() == shortcut.primary()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//kDebug() << "before" << shortcut.primary() << d->activationAction->globalShortcut().primary();
|
||||
d->activationAction->setGlobalShortcut(
|
||||
shortcut,
|
||||
KAction::ShortcutTypes(KAction::ActiveShortcut | KAction::DefaultShortcut),
|
||||
KAction::NoAutoloading);
|
||||
d->globalShortcutEnabled = true;
|
||||
QList<QKeySequence> seqs;
|
||||
seqs << shortcut.primary() << shortcut.alternate();
|
||||
KGlobalAccel::self()->setDefaultShortcut(d->activationAction, seqs, KGlobalAccel::NoAutoloading);
|
||||
d->globalShortcutChanged();
|
||||
}
|
||||
|
||||
KShortcut Applet::globalShortcut() const
|
||||
{
|
||||
if (d->activationAction) {
|
||||
return d->activationAction->globalShortcut();
|
||||
return KShortcut(d->activationAction->shortcut());
|
||||
}
|
||||
|
||||
return KShortcut();
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <QFile>
|
||||
#include <qstandardpaths.h>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kdebug.h>
|
||||
#include <kiconloader.h>
|
||||
#include <klocale.h>
|
||||
@ -36,6 +35,7 @@
|
||||
#include <kkeysequencewidget.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kglobal.h>
|
||||
#include <kglobalaccel.h>
|
||||
|
||||
#include "containment.h"
|
||||
#include "corona.h"
|
||||
@ -66,7 +66,8 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
|
||||
failed(false),
|
||||
transient(false),
|
||||
needsConfig(false),
|
||||
started(false)
|
||||
started(false),
|
||||
globalShortcutEnabled(false)
|
||||
{
|
||||
if (appletId == 0) {
|
||||
appletId = ++s_maxAppletId;
|
||||
@ -79,9 +80,9 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
|
||||
|
||||
AppletPrivate::~AppletPrivate()
|
||||
{
|
||||
if (activationAction && activationAction->isGlobalShortcutEnabled()) {
|
||||
//kDebug() << "reseting global action for" << q->title() << activationAction->objectName();
|
||||
activationAction->forgetGlobalShortcut();
|
||||
if (activationAction && globalShortcutEnabled) {
|
||||
//kDebug() << "resetting global action for" << q->title() << activationAction->objectName();
|
||||
KGlobalAccel::self()->removeAllShortcuts(activationAction);
|
||||
}
|
||||
|
||||
delete script;
|
||||
@ -187,7 +188,7 @@ void AppletPrivate::globalShortcutChanged()
|
||||
}
|
||||
|
||||
KConfigGroup shortcutConfig(mainConfigGroup(), "Shortcuts");
|
||||
shortcutConfig.writeEntry("global", activationAction->globalShortcut().toString());
|
||||
shortcutConfig.writeEntry("global", activationAction->shortcut().toString());
|
||||
scheduleModificationNotification();
|
||||
//kDebug() << "after" << shortcut.primary() << d->activationAction->globalShortcut().primary();
|
||||
}
|
||||
@ -249,7 +250,7 @@ void AppletPrivate::updateShortcuts()
|
||||
for (int i = 0; i < names.size(); ++i) {
|
||||
QAction *a = qactions.at(i);
|
||||
if (a) {
|
||||
actions->add<KAction>(names.at(i), a);
|
||||
actions->add<QAction>(names.at(i), a);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -22,9 +22,10 @@
|
||||
#ifndef PLASMA_APPLET_P_H
|
||||
#define PLASMA_APPLET_P_H
|
||||
|
||||
#include <QAction>
|
||||
#include <QBasicTimer>
|
||||
|
||||
#include <KAction>
|
||||
//#include <KAction>
|
||||
#include <kactioncollection.h>
|
||||
#include <kconfigskeleton.h>
|
||||
#include <kservice.h>
|
||||
@ -98,7 +99,7 @@ public:
|
||||
|
||||
// actions stuff; put activationAction into actions?
|
||||
KActionCollection *actions;
|
||||
KAction *activationAction;
|
||||
QAction *activationAction;
|
||||
|
||||
Types::ItemStatus itemStatus;
|
||||
|
||||
@ -113,6 +114,7 @@ public:
|
||||
bool transient : 1;
|
||||
bool needsConfig : 1;
|
||||
bool started : 1;
|
||||
bool globalShortcutEnabled : 1;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
Loading…
Reference in New Issue
Block a user