• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • shortcuts
kshortcutschemeshelper.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19#include "kshortcutschemeshelper_p.h"
20
21#include <QFile>
22#include <QTextStream>
23#include <QDomDocument>
24
25#include <kconfiggroup.h>
26#include <kaction.h>
27#include <kstandarddirs.h>
28#include <kactioncollection.h>
29#include <kxmlguiclient.h>
30#include <kdebug.h>
31
32bool KShortcutSchemesHelper::exportActionCollection(KActionCollection *collection,
33 const QString &schemeName, const QString dir)
34{
35 const KXMLGUIClient *client = collection->parentGUIClient();
36 if (!client)
37 return false;
38
39 QString schemeFileName;
40 if (!dir.isEmpty())
41 schemeFileName = dir + client->componentData().componentName() + schemeName + "shortcuts.rc";
42 else
43 schemeFileName = shortcutSchemeFileName(client, schemeName);
44
45 QFile schemeFile(schemeFileName);
46 if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate))
47 {
48 kDebug() << "COULD NOT WRITE" << schemeFileName;
49 return false;
50 }
51
52 QDomDocument doc;
53 QDomElement docElem = doc.createElement("kpartgui");
54 docElem.setAttribute("version", "1");
55 docElem.setAttribute("name", client->componentData().componentName());
56 doc.appendChild(docElem);
57 QDomElement elem = doc.createElement("ActionProperties");
58 docElem.appendChild(elem);
59
60 // now, iterate through our actions
61 foreach (QAction *action, collection->actions()) {
62 KAction *kaction = qobject_cast<KAction*>(action);
63 if (!kaction)
64 continue;
65
66 QString actionName = kaction->objectName();
67 QString shortcut = kaction->shortcut(KAction::ActiveShortcut).toString();
68 if (!shortcut.isEmpty())
69 {
70 QDomElement act_elem = doc.createElement("Action");
71 act_elem.setAttribute( "name", actionName );
72 act_elem.setAttribute( "shortcut", shortcut );
73 elem.appendChild(act_elem);
74 }
75 }
76
77 QTextStream out(&schemeFile);
78 out << doc.toString(2);
79 return true;
80}
81
82QString KShortcutSchemesHelper::currentShortcutSchemeName()
83{
84 return KGlobal::config()->group( "Shortcut Schemes" ).readEntry("Current Scheme", "Default");
85}
86
87QString KShortcutSchemesHelper::shortcutSchemeFileName(const KXMLGUIClient *client, const QString &schemeName)
88{
89 return KStandardDirs::locateLocal("data",
90 client->componentData().componentName() + '/' +
91 client->componentData().componentName() + schemeName + "shortcuts.rc" );
92}
93
94QString KShortcutSchemesHelper::applicationShortcutSchemeFileName(const QString &schemeName)
95{
96 return KGlobal::dirs()->locateLocal("appdata",
97 KGlobal::mainComponent().componentName() + schemeName + "shortcuts.rc");
98}
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:57
KActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, or null if not available.
Definition: kactioncollection.cpp:181
KActionCollection::actions
QList< QAction * > actions() const
Returns the list of KActions which belong to this action collection.
Definition: kactioncollection.cpp:186
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KAction::shortcut
KShortcut shortcut
Definition: kaction.h:220
KAction::ActiveShortcut
@ ActiveShortcut
The shortcut will immediately become active but may be reset to "default".
Definition: kaction.h:235
KComponentData::componentName
QString componentName() const
KShortcut::toString
QString toString() const
Returns a description of the shortcut as a semicolon-separated list of key sequences,...
Definition: kshortcut.cpp:249
KShortcut::isEmpty
bool isEmpty() const
Returns whether this shortcut contains any nonempty key sequences.
Definition: kshortcut.cpp:144
KStandardDirs::locateLocal
static QString locateLocal(const char *type, const QString &filename, bool createDir, const KComponentData &cData=KGlobal::mainComponent())
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
Definition: kxmlguiclient.h:47
KXMLGUIClient::componentData
virtual KComponentData componentData() const
Definition: kxmlguiclient.cpp:144
QAction
kDebug
#define kDebug
kaction.h
kactioncollection.h
kconfiggroup.h
kdebug.h
kstandarddirs.h
kxmlguiclient.h
KGlobal::mainComponent
const KComponentData & mainComponent()
KGlobal::dirs
KStandardDirs * dirs()
KGlobal::config
KSharedConfigPtr config()
KStandardShortcut::shortcut
const KShortcut & shortcut(StandardShortcut id)
Returns the keybinding for accel.
Definition: kstandardshortcut.cpp:285
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal