/* * genshortcutents.cpp - Copyright 2005 Frerich Raabe * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "kaboutdata.h" #include "kcomponentdata.h" #include "kcmdlineargs.h" #include "klocale.h" #include "kstandardshortcut.h" #include #include #include #include #include static QString keyAsMarkup( const QString &key ) { if ( key == "Alt" || key == "Ctrl" || key == "Enter" || key == "Esc" || key == "Shift" || key == "Tab" ) { return QString('&' + key + ';'); } if ( key == "Left" || key == "Right" || key == "Up" || key == "Down" ) { return QString("" + key + " Arrow"); } if ( key == "Backspace" || key == "Menu" ) { return QString("" + key + ""); } if ( key == "Plus" ) { return QString("+"); } if ( key == "Minus" ) { return QString("-"); } return QString("" + key + ""); } static QString entityForAccel( KStandardShortcut::StandardShortcut accel ) { QString markup = ""; foreach( const QString &key, keys ) { if ( key.startsWith( QLatin1String("XF86") ) ) { continue; } markup += keyAsMarkup( key ); } markup += ""; } markup += "\">"; return markup; } int main( int argc, char **argv ) { KCmdLineOptions cmdLineOptions; cmdLineOptions.add("o"); cmdLineOptions.add("output ", ki18n("Output file"), "kde-standard-accels.entities"); KAboutData aboutData( "genshortcutents", 0, ki18n("genshortcutents"), "1.0", ki18n( "Generates DocBook entities for key shortcuts of standard actions" )); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( cmdLineOptions ); KComponentData componentData( &aboutData ); QCoreApplication app( KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv() ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); const QString outputFileName = args->getOption( "output" ); QFile outputFile( outputFileName ); if ( !outputFile.open( QIODevice::WriteOnly ) ) { qDebug( "Failed to open %s for writing.", qPrintable( outputFileName ) ); return 1; } QTextStream stream( &outputFile ); stream << "\n"; stream << "\n"; for ( unsigned int i = 0; i < KStandardShortcut::StandardShortcutCount; ++i ) { stream << entityForAccel( static_cast(i) ) << "\n"; } }