2014-11-13 01:04:59 +02:00
|
|
|
/* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
|
|
|
|
Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
|
|
|
|
Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
|
|
|
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
|
|
|
|
Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
|
|
|
|
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
|
|
|
|
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
|
|
|
|
Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
|
|
|
|
Copyright (C) 2009 Chani Armitage <chani@kde.org>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kshortcutsdialog.h"
|
|
|
|
|
|
|
|
#include "kdebug.h"
|
|
|
|
#include "klocale.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2015-08-11 05:56:07 +03:00
|
|
|
#include <QtXml/qdom.h>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <kxmlguiclient.h>
|
|
|
|
#include <kxmlguifactory.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* KShortcutsDialog */
|
|
|
|
/* */
|
|
|
|
/* Originally by Nicolas Hadacek <hadacek@via.ecp.fr> */
|
|
|
|
/* */
|
|
|
|
/* Substantially revised by Mark Donohoe <donohoe@kde.org> */
|
|
|
|
/* */
|
|
|
|
/* And by Espen Sand <espen@kde.org> 1999-10-19 */
|
|
|
|
/* (by using KDialog there is almost no code left ;) */
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
class KShortcutsDialog::KShortcutsDialogPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
KShortcutsDialogPrivate(KShortcutsDialog *q)
|
2024-04-24 09:24:13 +03:00
|
|
|
: q(q), m_keyChooser(0)
|
2023-08-27 07:08:35 +03:00
|
|
|
{
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
QList<KActionCollection*> m_collections;
|
|
|
|
|
|
|
|
void save()
|
|
|
|
{
|
2024-04-24 21:40:13 +03:00
|
|
|
m_keyChooser->exportConfiguration();
|
2014-11-13 01:04:59 +02:00
|
|
|
emit q->saved();
|
|
|
|
}
|
|
|
|
|
|
|
|
KShortcutsDialog *q;
|
2024-04-24 09:24:13 +03:00
|
|
|
KShortcutsEditor* m_keyChooser;
|
2014-11-13 01:04:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-04-24 13:41:29 +03:00
|
|
|
KShortcutsDialog::KShortcutsDialog(KShortcutsEditor::ActionTypes types,
|
|
|
|
KShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent)
|
|
|
|
: KDialog(parent),
|
|
|
|
d(new KShortcutsDialogPrivate(this))
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
setCaption(i18n("Configure Shortcuts"));
|
2024-04-30 23:02:11 +03:00
|
|
|
setButtons(KDialog::Reset | KDialog::Ok | KDialog::Cancel);
|
2014-11-13 01:04:59 +02:00
|
|
|
setModal(true);
|
2023-08-27 07:08:35 +03:00
|
|
|
d->m_keyChooser = new KShortcutsEditor(this, types, allowLetterShortcuts);
|
2024-04-30 23:02:11 +03:00
|
|
|
setMainWidget(d->m_keyChooser);
|
|
|
|
setButtonText(Reset, i18n("Reset to Defaults"));
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
connect(this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()));
|
2024-04-24 21:40:13 +03:00
|
|
|
connect(this, SIGNAL(okClicked()), this, SLOT(save()));
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
|
2024-04-30 23:02:11 +03:00
|
|
|
resize(group.readEntry("Dialog Size", sizeHint()));
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KShortcutsDialog::~KShortcutsDialog()
|
|
|
|
{
|
2023-08-27 07:08:35 +03:00
|
|
|
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
|
2024-04-30 23:02:11 +03:00
|
|
|
group.writeEntry("Dialog Size", size(), KConfigGroup::Persistent | KConfigGroup::Global);
|
2014-11-13 01:04:59 +02:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
|
|
|
|
{
|
|
|
|
d->m_keyChooser->addCollection(collection, title);
|
2024-04-30 23:02:11 +03:00
|
|
|
d->m_keyChooser->importConfiguration();
|
2014-11-13 01:04:59 +02:00
|
|
|
d->m_collections << collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<KActionCollection*> KShortcutsDialog::actionCollections() const
|
|
|
|
{
|
|
|
|
return d->m_collections;
|
|
|
|
}
|
|
|
|
|
2024-04-24 21:40:13 +03:00
|
|
|
bool KShortcutsDialog::configure()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
if (isModal()) {
|
|
|
|
int retcode = exec();
|
|
|
|
return retcode;
|
|
|
|
}
|
2024-04-24 21:40:13 +03:00
|
|
|
show();
|
|
|
|
return false;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize KShortcutsDialog::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(600, 480);
|
|
|
|
}
|
|
|
|
|
2024-04-24 13:41:29 +03:00
|
|
|
int KShortcutsDialog::configure(KActionCollection *collection,
|
|
|
|
KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
|
2024-04-24 21:40:13 +03:00
|
|
|
QWidget *parent)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-24 21:40:13 +03:00
|
|
|
kDebug(125) << "KShortcutsDialog::configure()" << collection;
|
2014-11-13 01:04:59 +02:00
|
|
|
KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
|
2024-04-30 23:02:11 +03:00
|
|
|
dlg.addCollection(collection);
|
2024-04-24 21:40:13 +03:00
|
|
|
return dlg.configure();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 07:40:26 +00:00
|
|
|
#include "moc_kshortcutsdialog.cpp"
|