make designMode property available from js
[kdelibs.git] / kdoctools / genshortcutents.cpp
blobb62f9611e4970d7102fcd487cdb8ea964d57b160
1 /*
2 * genshortcutents.cpp - Copyright 2005 Frerich Raabe <raabe@kde.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "kaboutdata.h"
26 #include "kcomponentdata.h"
27 #include "kcmdlineargs.h"
28 #include "klocale.h"
29 #include "kstandardshortcut.h"
31 #include <QtCore/QDate>
32 #include <QtCore/QFile>
33 #include <QtCore/QCoreApplication>
34 #include <QtCore/QTextStream>
35 #include <QtCore/QStringList>
37 static QString keyAsMarkup( const QString &key )
39 if ( key == "Alt" || key == "Ctrl" || key == "Enter" || key == "Esc" ||
40 key == "Shift" || key == "Tab" ) {
41 return QString('&' + key + ';');
43 if ( key == "Left" || key == "Right" || key == "Up" || key == "Down" ) {
44 return QString("<keysym>" + key + " Arrow</keysym>");
46 if ( key == "Backspace" || key == "Menu" ) {
47 return QString("<keysym>" + key + "</keysym>");
49 if ( key == "Plus" ) {
50 return QString("<keycap>+</keycap>");
52 if ( key == "Minus" ) {
53 return QString("<keycap>-</keycap>");
55 return QString("<keycap>" + key + "</keycap>");
58 static QString entityForAccel( KStandardShortcut::StandardShortcut accel )
60 QString markup = "<!ENTITY KeyCombo_";
62 /* We use a switch so that the compiler gives us warning messages in
63 * case KStandardShortcut::StandardShortcut gets extended (which means we have to
64 * extend this code, too).
66 switch ( accel ) {
67 case KStandardShortcut::AccelNone:
68 break;
69 case KStandardShortcut::Open:
70 markup += "Open";
71 break;
72 case KStandardShortcut::New:
73 markup += "New";
74 break;
75 case KStandardShortcut::Close:
76 markup += "Close";
77 break;
78 case KStandardShortcut::Save:
79 markup += "Save";
80 break;
81 case KStandardShortcut::Print:
82 markup += "Print";
83 break;
84 case KStandardShortcut::Quit:
85 markup += "Quit";
86 break;
87 case KStandardShortcut::Undo:
88 markup += "Undo";
89 break;
90 case KStandardShortcut::Redo:
91 markup += "Redo";
92 break;
93 case KStandardShortcut::Cut:
94 markup += "Cut";
95 break;
96 case KStandardShortcut::Copy:
97 markup += "Copy";
98 break;
99 case KStandardShortcut::Paste:
100 markup += "Paste";
101 break;
102 case KStandardShortcut::SelectAll:
103 markup += "SelectAll";
104 break;
105 case KStandardShortcut::Deselect:
106 markup += "Deselect";
107 break;
108 case KStandardShortcut::DeleteWordBack:
109 markup += "DeleteWordBack";
110 break;
111 case KStandardShortcut::DeleteWordForward:
112 markup += "DeleteWordForward";
113 break;
114 case KStandardShortcut::Find:
115 markup += "Find";
116 break;
117 case KStandardShortcut::FindNext:
118 markup += "FindNext";
119 break;
120 case KStandardShortcut::FindPrev:
121 markup += "FindPrev";
122 break;
123 case KStandardShortcut::Replace:
124 markup += "Replace";
125 break;
126 case KStandardShortcut::Home:
127 markup += "Home";
128 break;
129 case KStandardShortcut::Begin:
130 markup += "Begin";
131 break;
132 case KStandardShortcut::End:
133 markup += "End";
134 break;
135 case KStandardShortcut::Prior:
136 markup += "Prior";
137 break;
138 case KStandardShortcut::Next:
139 markup += "Next";
140 break;
141 case KStandardShortcut::GotoLine:
142 markup += "GotoLine";
143 break;
144 case KStandardShortcut::AddBookmark:
145 markup += "AddBookmark";
146 break;
147 case KStandardShortcut::ZoomIn:
148 markup += "ZoomIn";
149 break;
150 case KStandardShortcut::ZoomOut:
151 markup += "ZoomOut";
152 break;
153 case KStandardShortcut::Up:
154 markup += "Up";
155 break;
156 case KStandardShortcut::Back:
157 markup += "Back";
158 break;
159 case KStandardShortcut::Forward:
160 markup += "Forward";
161 break;
162 case KStandardShortcut::Reload:
163 markup += "Reload";
164 break;
165 case KStandardShortcut::ShowMenubar:
166 markup += "ShowMenubar";
167 break;
168 case KStandardShortcut::Help:
169 markup += "Help";
170 break;
171 case KStandardShortcut::WhatsThis:
172 markup += "WhatsThis";
173 break;
174 case KStandardShortcut::TextCompletion:
175 markup += "TextCompletion";
176 break;
177 case KStandardShortcut::PrevCompletion:
178 markup += "PrevCompletion";
179 break;
180 case KStandardShortcut::NextCompletion:
181 markup += "NextCompletion";
182 break;
183 case KStandardShortcut::SubstringCompletion:
184 markup += "SubstringCompletion";
185 break;
186 case KStandardShortcut::RotateUp:
187 markup += "RotateUp";
188 break;
189 case KStandardShortcut::RotateDown:
190 markup += "RotateDown";
191 break;
192 case KStandardShortcut::TabNext:
193 markup += "TabNext";
194 break;
195 case KStandardShortcut::TabPrev:
196 markup += "TabPrev";
197 break;
198 case KStandardShortcut::FullScreen:
199 markup += "FullScreen";
200 break;
201 case KStandardShortcut::BackwardWord:
202 markup += "BackwardWord";
203 break;
204 case KStandardShortcut::ForwardWord:
205 markup += "ForwardWord";
206 break;
207 case KStandardShortcut::BeginningOfLine:
208 markup += "BeginningOfLine";
209 break;
210 case KStandardShortcut::EndOfLine:
211 markup += "EndOfLine";
212 break;
213 case KStandardShortcut::PasteSelection:
214 markup += "PastSelection";
215 break;
216 case KStandardShortcut::StandardShortcutCount:
217 break;
220 markup += "\t\"";
222 QString internalStr = KStandardShortcut::shortcut( accel ).toString();
223 QString firstSequence = internalStr.left( internalStr.indexOf( ';' ) );
224 const QStringList keys = firstSequence.split( '+',QString::SkipEmptyParts );
225 if ( keys.empty() ) {
226 return QString();
229 if ( keys.count() == 1 ) {
230 if ( keys.first().startsWith( "XF86" ) ) {
231 return QString();
233 markup += keyAsMarkup( keys.first() );
234 } else {
235 markup += "<keycombo action=\"Simul\">";
236 foreach( const QString &key, keys ) {
237 if ( key.startsWith( "XF86" ) ) {
238 continue;
240 markup += keyAsMarkup( key );
242 markup += "</keycombo>";
244 markup += "\">";
245 return markup;
248 int main( int argc, char **argv )
250 KCmdLineOptions cmdLineOptions;
251 cmdLineOptions.add("o");
252 cmdLineOptions.add("output <file>", ki18n("Output file"), "kde-standard-accels.entities");
254 KAboutData aboutData( "genshortcutents", 0, ki18n("genshortcutents"), "1.0",
255 ki18n( "Generates DocBook entities for key shortcuts of standard actions" ));
257 KCmdLineArgs::init( argc, argv, &aboutData );
258 KCmdLineArgs::addCmdLineOptions( cmdLineOptions );
260 KComponentData componentData( &aboutData );
261 QCoreApplication app( KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv() );
263 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
265 const QString outputFileName = args->getOption( "output" );
266 QFile outputFile( outputFileName );
267 if ( !outputFile.open( QIODevice::WriteOnly ) ) {
268 qDebug( "Failed to open %s for writing.", qPrintable( outputFileName ) );
269 return 1;
272 QTextStream stream( &outputFile );
273 stream << "<!-- Generated by "
274 << aboutData.programName() + ' '
275 << aboutData.version() + " on "
276 << QDateTime::currentDateTime().toString() + ".\n";
277 stream << " Do not bother to fiddle with this, your modifications will be\n"
278 << " overwritten as soon as the file is regenerated. -->\n";
279 stream << "\n";
281 for ( unsigned int i = 0; i < KStandardShortcut::StandardShortcutCount; ++i ) {
282 stream << entityForAccel( static_cast<KStandardShortcut::StandardShortcut>(i) ) << "\n";