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