dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
commandsfile.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "commandsfile.h"
29 #include "shortcutsettings.h"
30 #include "command_p.h"
31 
33 
34 #include <QtCore/QFile>
35 #include <QtXml/QDomDocument>
36 
37 using namespace Core;
38 using namespace Core::Internal;
39 
49 CommandsFile::CommandsFile(const QString &filename)
50  : m_filename(filename)
51 {
52 }
53 
57 QMap<QString, QKeySequence> CommandsFile::importCommands() const
58 {
59  QMap<QString, QKeySequence> result;
60 
61  QFile file(m_filename);
62  if (!file.open(QIODevice::ReadOnly))
63  return result;
64 
65  QDomDocument doc("KeyboardMappingScheme");
66  if (!doc.setContent(&file))
67  return result;
68 
69  QDomElement root = doc.documentElement();
70  if (root.nodeName() != QLatin1String("mapping"))
71  return result;
72 
73  QDomElement ks = root.firstChildElement();
74  for (; !ks.isNull(); ks = ks.nextSiblingElement()) {
75  if (ks.nodeName() == QLatin1String("shortcut")) {
76  QString id = ks.attribute(QLatin1String("id"));
77  QKeySequence shortcutkey;
78  QDomElement keyelem = ks.firstChildElement("key");
79  if (!keyelem.isNull())
80  shortcutkey = QKeySequence(keyelem.attribute("value"));
81  result.insert(id, shortcutkey);
82  }
83  }
84 
85  file.close();
86  return result;
87 }
88 
93 {
95 
96  QFile file(m_filename);
97  if (!file.open(QIODevice::WriteOnly))
98  return false;
99 
100  QDomDocument doc("KeyboardMappingScheme");
101  QDomElement root = doc.createElement("mapping");
102  doc.appendChild(root);
103 
104  foreach (const ShortcutItem *item, items) {
105  QDomElement ctag = doc.createElement("shortcut");
106  ctag.setAttribute(QLatin1String("id"),
107  idmanager->stringForUniqueIdentifier(item->m_cmd->id()));
108  root.appendChild(ctag);
109 
110  QDomElement ktag = doc.createElement("key");
111  ktag.setAttribute(QLatin1String("value"), item->m_key.toString());
112  ctag.appendChild(ktag);
113  }
114 
115  file.write(doc.toByteArray());
116  file.close();
117  return true;
118 }
static UniqueIDManager * instance()
QMap< QString, QKeySequence > importCommands() const
Parse log file
QString stringForUniqueIdentifier(int uid)
CommandsFile(const QString &filename)
Definition: icore.h:39
virtual int id() const =0
bool exportCommands(const QList< ShortcutItem * > &items)