global shortcut configuration for all applets =)

svn path=/trunk/KDE/kdelibs/; revision=884810
This commit is contained in:
Aaron J. Seigo 2008-11-15 21:23:56 +00:00
parent 720c589cc4
commit 34ab711509
2 changed files with 41 additions and 4 deletions

View File

@ -40,22 +40,24 @@
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QTextDocument> #include <QTextDocument>
#include <QUiLoader> #include <QUiLoader>
#include <QVBoxLayout>
#include <QWidget> #include <QWidget>
#include <kaction.h> #include <kaction.h>
#include <kicon.h> #include <kactioncollection.h>
#include <kauthorized.h>
#include <kcolorscheme.h> #include <kcolorscheme.h>
#include <kconfigdialog.h> #include <kconfigdialog.h>
#include <kdialog.h> #include <kdialog.h>
#include <kicon.h>
#include <kiconloader.h> #include <kiconloader.h>
#include <kkeysequencewidget.h>
#include <kplugininfo.h> #include <kplugininfo.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include <kservice.h> #include <kservice.h>
#include <kservicetypetrader.h> #include <kservicetypetrader.h>
#include <kshortcut.h> #include <kshortcut.h>
#include <kwindowsystem.h> #include <kwindowsystem.h>
#include <kactioncollection.h>
#include <kauthorized.h>
#include <solid/powermanagement.h> #include <solid/powermanagement.h>
@ -1366,8 +1368,12 @@ void Applet::showConfigurationInterface()
f.close(); f.close();
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name())); dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
d->addGlobalShortcutsPage(dialog);
connect(dialog, SIGNAL(applyClicked()), this, SLOT(configChanged()));
connect(dialog, SIGNAL(okClicked()), this, SLOT(configChanged()));
dialog->show(); dialog->show();
} else if (d->script) { } else if (d->script) {
//FIXME: global shorcuts?
d->script->showConfigurationInterface(); d->script->showConfigurationInterface();
} else { } else {
KConfigSkeleton *nullManager = new KConfigSkeleton(0); KConfigSkeleton *nullManager = new KConfigSkeleton(0);
@ -1376,7 +1382,7 @@ void Applet::showConfigurationInterface()
dialog->setWindowTitle(windowTitle); dialog->setWindowTitle(windowTitle);
dialog->setAttribute(Qt::WA_DeleteOnClose, true); dialog->setAttribute(Qt::WA_DeleteOnClose, true);
createConfigurationInterface(dialog); createConfigurationInterface(dialog);
//TODO: would be nice to not show dialog if there are no pages added? d->addGlobalShortcutsPage(dialog);
connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater())); connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
//TODO: Apply button does not correctly work for now, so do not show it //TODO: Apply button does not correctly work for now, so do not show it
dialog->showButton(KDialog::Apply, false); dialog->showButton(KDialog::Apply, false);
@ -1388,11 +1394,37 @@ void Applet::showConfigurationInterface()
emit releaseVisualFocus(); emit releaseVisualFocus();
} }
void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog)
{
QWidget *page = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(page);
if (!shortcutEditor) {
shortcutEditor = new KKeySequenceWidget(page);
}
shortcutEditor->setKeySequence(q->globalShortcut().primary());
layout->addWidget(shortcutEditor);
layout->addStretch();
dialog->addPage(page, i18n("Keyboard Shortcut"), "preferences-desktop-keyboard");
}
void Applet::configChanged() void Applet::configChanged()
{ {
if (d->script) { if (d->script) {
d->script->configChanged(); d->script->configChanged();
} }
if (d->shortcutEditor) {
QKeySequence sequence = d->shortcutEditor->keySequence();
if (sequence != globalShortcut().primary()) {
setGlobalShortcut(KShortcut(sequence));
emit configNeedsSaving();
}
delete d->shortcutEditor;
d->shortcutEditor = 0;
}
} }
void Applet::createConfigurationInterface(KConfigDialog *parent) void Applet::createConfigurationInterface(KConfigDialog *parent)
@ -1730,6 +1762,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet
immutability(Mutable), immutability(Mutable),
actions(applet), actions(applet),
activationAction(0), activationAction(0),
shortcutEditor(0),
constraintsTimerId(0), constraintsTimerId(0),
modificationsTimerId(-1), modificationsTimerId(-1),
hasConfigurationInterface(false), hasConfigurationInterface(false),

View File

@ -24,6 +24,8 @@
#include <kactioncollection.h> #include <kactioncollection.h>
class KKeySequenceWidget;
namespace Plasma namespace Plasma
{ {
@ -73,6 +75,7 @@ public:
void cleanUpAndDelete(); void cleanUpAndDelete();
void createMessageOverlay(); void createMessageOverlay();
void destroyMessageOverlay(); void destroyMessageOverlay();
void addGlobalShortcutsPage(KConfigDialog *dialog);
static uint s_maxAppletId; static uint s_maxAppletId;
static uint s_maxZValue; static uint s_maxZValue;
@ -101,6 +104,7 @@ public:
ImmutabilityType immutability; ImmutabilityType immutability;
KActionCollection actions; KActionCollection actions;
KAction *activationAction; KAction *activationAction;
KKeySequenceWidget *shortcutEditor; //TODO: subclass KConfigDialog and encapsulate this in there
int constraintsTimerId; int constraintsTimerId;
int modificationsTimerId; int modificationsTimerId;
bool hasConfigurationInterface : 1; bool hasConfigurationInterface : 1;