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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
32 bool 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 
82 QString KShortcutSchemesHelper::currentShortcutSchemeName()
83 {
84  return KGlobal::config()->group( "Shortcut Schemes" ).readEntry("Current Scheme", "Default");
85 }
86 
87 QString 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 
94 QString 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:56
kdebug.h
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:46
QDomNode::appendChild
QDomNode appendChild(const QDomNode &newChild)
QDomDocument::toString
QString toString(int indent) const
kactioncollection.h
KStandardShortcut::shortcut
const KShortcut & shortcut(StandardShortcut id)
Returns the keybinding for accel.
Definition: kstandardshortcut.cpp:285
KGlobal::dirs
KStandardDirs * dirs()
KConfig::group
KConfigGroup group(const QByteArray &group)
KAction::shortcut
KShortcut shortcut
Definition: kaction.h:220
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QFile
QTextStream
KGlobal::config
KSharedConfigPtr config()
KXMLGUIClient::componentData
virtual KComponentData componentData() const
Definition: kxmlguiclient.cpp:144
QDomElement::setAttribute
void setAttribute(const QString &name, const QString &value)
QObject::objectName
objectName
QString::isEmpty
bool isEmpty() const
KActionCollection::actions
QList< QAction * > actions() const
Returns the list of KActions which belong to this action collection.
Definition: kactioncollection.cpp:186
KComponentData::componentName
QString componentName() const
QString
kaction.h
QDomDocument
kxmlguiclient.h
KAction::ActiveShortcut
The shortcut will immediately become active but may be reset to "default".
Definition: kaction.h:235
KStandardDirs::locateLocal
static QString locateLocal(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
kstandarddirs.h
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KGlobal::mainComponent
const KComponentData & mainComponent()
QDomDocument::createElement
QDomElement createElement(const QString &tagName)
KActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, or null if not available.
Definition: kactioncollection.cpp:181
QDomElement
KShortcut::toString
QString toString() const
Returns a description of the shortcut as a semicolon-separated list of key sequences, as returned by QKeySequence::toString().
Definition: kshortcut.cpp:249
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
kconfiggroup.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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