diff --git a/utils.cpp b/utils.cpp
index a983b37e43..9f57b9cf28 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -34,6 +34,7 @@ along with this program. If not, see .
#include
#include
#include
+#include
#include
#include
@@ -41,6 +42,7 @@ along with this program. If not, see .
#include
#include
#include
+#include
#include
@@ -408,9 +410,21 @@ bool isLocalMachine( const QByteArray& host )
#ifndef KCMRULES
ShortcutDialog::ShortcutDialog( const QKeySequence& cut )
: widget( new KKeySequenceWidget( this ))
+ ,_shortcut(cut)
{
widget->setKeySequence( cut );
+
+ // To not check for conflicting shortcuts. The widget would use a message
+ // box which brings down kwin.
+ widget->setCheckForConflictsAgainst(KKeySequenceWidget::None);
+
+ // Listen to changed shortcuts
+ connect(
+ widget, SIGNAL(keySequenceChanged(const QKeySequence&)),
+ SLOT(keySequenceChanged(const QKeySequence&)));
+
setMainWidget( widget );
+
// make it a popup, so that it has the grab
XSetWindowAttributes attrs;
attrs.override_redirect = True;
@@ -445,9 +459,20 @@ void ShortcutDialog::done( int r )
emit dialogDone( r == Accepted );
}
+void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
+ {
+ // Check if the key sequence is used currently
+ QStringList conflicting = KGlobalAccel::findActionNameSystemwide(seq);
+ if (!conflicting.isEmpty()) {
+ // TODO: Inform the user somehow instead of just ignoring his wish
+ widget->setKeySequence(shortcut());
+ }
+ _shortcut = seq;
+ }
+
QKeySequence ShortcutDialog::shortcut() const
{
- return widget->keySequence();
+ return _shortcut;
}
#endif //KCMRULES
diff --git a/utils.h b/utils.h
index 88dc38fbf4..8e0cdd9a8e 100644
--- a/utils.h
+++ b/utils.h
@@ -326,12 +326,15 @@ class ShortcutDialog
ShortcutDialog( const QKeySequence& cut );
virtual void accept();
QKeySequence shortcut() const;
+ public Q_SLOTS:
+ void keySequenceChanged(const QKeySequence &seq);
signals:
void dialogDone( bool ok );
protected:
virtual void done( int r );
private:
KKeySequenceWidget* widget;
+ QKeySequence _shortcut;
};
#endif //KCMRULES