diff --git a/src/main.cpp b/src/main.cpp index 29dd0c3..17585cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,50 +1,70 @@ /*************************************************************************** * Copyright (C) 2011 by Matteo Agostinelli * * agostinelli@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include -#include -#include +#include +#include +#include +#include #include "cirkuitconfig.h" #include "mainwindow.h" int main (int argc, char *argv[]) { - K4AboutData aboutData( "cirkuit", "cirkuit", ki18n("Cirkuit"), VERSION, ki18n("An application to generate publication-ready figures. It is a KDE frontend for Circuit Macros by J. D. Aplevich, TikZ and Gnuplot.

Visit the Circuit Macros and TikZ websites for further information."), K4AboutData::License_GPL, ki18n("(c) 2011 Matteo Agostinelli")); - aboutData.addAuthor(ki18n("Matteo Agostinelli"), ki18n("Maintainer"), "matteo@agostinelli.me", "http://agostinelli.me"); - aboutData.setHomepage("http://projects.kde.org/cirkuit"); - KCmdLineArgs::init( argc, argv, &aboutData ); + QApplication app(argc, argv); // must be created first for translation to work - KCmdLineOptions options; - options.add("+[file]", ki18n("Document to open")); - KCmdLineArgs::addCmdLineOptions( options ); + /* setup localization */ + KLocalizedString::setApplicationDomain("cirkuit"); /* connect to translation catalog */ - KApplication app; - MainWindow* window = new MainWindow(); + /* setup application's about-data */ + KAboutData aboutData(QStringLiteral("cirkuit"), i18n("Cirkuit"), QStringLiteral(VERSION), + i18n("An application to generate publication-ready figures. " + "It is a KDE frontend for Circuit Macros by J. D. Aplevich, TikZ and Gnuplot."), + KAboutLicense::GPL, i18n("(c) 2011 Matteo Agostinelli"), + i18n("Visit the Circuit Macros and " + "TikZ websites for further information.") + ); + aboutData.addAuthor(i18n("Matteo Agostinelli"), i18n("Maintainer"), + QStringLiteral("matteo@agostinelli.me"), QStringLiteral("http://agostinelli.me") + ); + aboutData.setHomepage(QStringLiteral("http://projects.kde.org/cirkuit")); + KAboutData::setApplicationData(aboutData); /* install data in already created QApplication instance */ - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->count()) { - window->loadFile(args->url(0).url()); - } + /* create KDE-typical commandline parser with optional 'file' argument */ + QCommandLineParser parser; + aboutData.setupCommandLine(&parser); /* add description and standard options like version, author, etc. */ + parser.addPositionalArgument(QStringLiteral("file"), i18n("Document to open."), i18n("[file]")); /* add 'file' arg */ + + /* parse the command line */ + parser.process(app); + aboutData.processCommandLine(&parser); /* handle all standard KDE options */ + const QStringList args = parser.positionalArguments(); /* get all passed optional arguments */ + /* create and show the gui */ + MainWindow* window = new MainWindow(); + if (!args.isEmpty()) { + /* 'file' argument */ + const QString fileArg = args.at(0); /* only the first one is used, others are ignored */ + window->loadFile(QUrl::fromLocalFile(fileArg)); /* open passed file and trigger preview generation */ + } window->show(); return app.exec(); }