From kde-commits Fri Feb 29 23:45:12 2008 From: Michael Jansen Date: Fri, 29 Feb 2008 23:45:12 +0000 To: kde-commits Subject: KDE/kdelibs/kdeui/dialogs Message-Id: <1204328712.856059.20978.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120432872418426 SVN commit 780779 by mjansen: - Copyrights - Add the possibility for KShortcutEditor to import / export configurations. In contrast to saving it's settings these take into account global shortcuts. M +1 -0 kshortcutsdialog.cpp M +2 -0 kshortcutsdialog.h M +2 -0 kshortcutsdialog_p.h M +60 -5 kshortcutseditor.cpp M +53 -0 kshortcutseditor.h M +1 -0 kshortcutseditordelegate.cpp M +8 -0 kshortcutseditoritem.cpp --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutsdialog.cpp #780778:780779 @@ -5,6 +5,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutsdialog.h #780778:780779 @@ -4,6 +4,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -45,6 +46,7 @@ * * @author Nicolas Hadacek * @author Hamish Rodda (KDE 4 porting) + * @author Michael Jansen */ class KDEUI_EXPORT KShortcutsDialog : public KDialog { --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutsdialog_p.h #780778:780779 @@ -1,5 +1,6 @@ /* This file is part of the KDE libraries Copyright (C) 2006,2007 Andreas Hartmetz (ahartmetz@gmail.com) + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -194,6 +195,7 @@ void setRockerGesture(const KRockerGesture &gst); bool isModified(uint column) const; + bool isModified() const; void setNameBold(bool flag) { m_isNameBold = flag; } --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutseditor.cpp #780778:780779 @@ -5,6 +5,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -63,6 +64,20 @@ delete d; } + +bool KShortcutsEditor::isModified() const +{ + for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) { + if ((*it)->childCount()) + continue; + + if (static_cast(*it)->isModified()) { + return true; + } + } + return false; +} + void KShortcutsEditor::clearCollections() { d->delegate->clear(); @@ -84,7 +99,6 @@ foreach (QAction *action, collection->actions()) { QString name = action->text().remove('&'); - // kDebug(125) << "Adding Key: " << name; if (name.startsWith(QLatin1String("Program:"))) l = Program; @@ -95,7 +109,6 @@ if ((kact = qobject_cast(action)) && kact->isShortcutConfigurable()) { // If the shortcut is not configurable skip it if (!kact->isShortcutConfigurable()) { - kDebug(125) << "Not configurable " << kact->text(); continue; } // Create the editor @@ -118,7 +131,51 @@ QTimer::singleShot(0, this, SLOT(resizeColumns())); } +void KShortcutsEditor::importConfiguration( KConfig *config) +{ + if (d->actionTypes & KShortcutsEditor::GlobalAction) { + QString groupName = "Global Shortcuts"; + KConfigGroup group( config, groupName ); + foreach (KActionCollection* collection, d->actionCollections) { + collection->readGlobalSettings( &group ); + } + } + if (d->actionTypes & !KShortcutsEditor::GlobalAction) { + QString groupName = "Local Shortcuts"; + KConfigGroup group( config, groupName ); + foreach (KActionCollection* collection, d->actionCollections) { + collection->readSettings( &group ); + } + } +} +void KShortcutsEditor::exportConfiguration( KConfig *config) const +{ + if (d->actionTypes & KShortcutsEditor::GlobalAction) { + QString groupName = "Global Shortcuts"; + KConfigGroup group( config, groupName ); + foreach (KActionCollection* collection, d->actionCollections) { + collection->writeGlobalSettings( &group, true ); + } + } + if (d->actionTypes & !KShortcutsEditor::GlobalAction) { + QString groupName = "Local Shortcuts"; + KConfigGroup group( config, groupName ); + foreach (KActionCollection* collection, d->actionCollections) { + collection->writeSettings( &group, true ); + } + } +} + + +void KShortcutsEditor::writeConfiguration( KConfigGroup *config) const +{ + foreach (KActionCollection* collection, d->actionCollections) { + collection->writeSettings(config); + } +} + + //slot void KShortcutsEditor::resizeColumns() { @@ -139,9 +196,7 @@ static_cast(*it)->commit(); } - // Now write the ActionCollection to the file - foreach (KActionCollection* collection, d->actionCollections) - collection->writeSettings(); + writeConfiguration(); } // KDE5 : rename to undo() --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutseditor.h #780778:780779 @@ -4,6 +4,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -28,6 +29,8 @@ #include "kgesture.h" class KActionCollection; +class KConfig; +class KConfigGroup; class KGlobalAccel; class KShortcut; class KShortcutsEditorPrivate; @@ -51,6 +54,7 @@ * @see KShortcutsDialog * @author Nicolas Hadacek * @author Hamish Rodda (KDE 4 porting) + * @author Michael Jansen */ class KDEUI_EXPORT KShortcutsEditor : public QWidget { @@ -107,6 +111,11 @@ /// Destructor virtual ~KShortcutsEditor(); + /** + * Are the unsaved changes? + */ + bool isModified() const; + /** * Removes all action collections from the editor */ @@ -119,6 +128,14 @@ */ void addCollection(KActionCollection *, const QString &title = QString()); + + /** + * Load the shortcuts from the \p config object. + * + * The current active shortcuts are deleted. + */ + void readConfig( KConfig* ); + /** * Undo all change made since the last save(). */ @@ -137,6 +154,42 @@ */ void save(); + /** + * Write the current settings to the \p config object. + * + * This does not initialize the \p config object. It adds the + * configuration. + * + * @note this will not save the global configuration! globalaccel holds + * that part of the configuration. + * @see writeGlobalConfig() + * + * @param config Config object to save to or, or null to use the + * applications config object + * + */ + void writeConfiguration( KConfigGroup* config = 0 ) const; + + /** + * Export the current setting to configuration @p config. + * + * This initializes the configuration object. This will export the global + * configuration too. + * + * @param config Config object + */ + void exportConfiguration( KConfig *config) const; + + /** + * Import the settings from configuration @p config. + * + * This will remove all current setting before importing. All shortcuts + * are set to KShortcut() prior to importing from @p config! + * + * @param config Config object + */ + void importConfiguration( KConfig *config); + /** * Checks whether the given shortcut conflicts with global keyboard shortcuts. * If yes, and the warnUser argument is true, warns the user and gives them a chance --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutseditordelegate.cpp #780778:780779 @@ -5,6 +5,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public --- trunk/KDE/kdelibs/kdeui/dialogs/kshortcutseditoritem.cpp #780778:780779 @@ -5,6 +5,7 @@ Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz + Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -48,6 +49,12 @@ } +bool KShortcutsEditorItem::isModified() const +{ + return m_oldLocalShortcut || m_oldGlobalShortcut || m_oldShapeGesture || m_oldRockerGesture; +} + + QVariant KShortcutsEditorItem::data(int column, int role) const { switch (role) { @@ -268,6 +275,7 @@ } + void KShortcutsEditorItem::undo() { #ifndef NDEBUG