main.cpp 3.15 KB
Newer Older
Stefan Majewsky's avatar
Stefan Majewsky committed
1
/***************************************************************************
2
 *   Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
Stefan Majewsky's avatar
Stefan Majewsky committed
3 4 5 6 7 8 9 10 11 12 13 14
 *
 *   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
15
 *   along with this program; if not, write to the Free Software
Stefan Majewsky's avatar
Stefan Majewsky committed
16 17 18
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/

19
#include "importhelper.h"
20
#include "window/mainwindow.h"
21
#include "palapeli_version.h"
22

Stefan Majewsky's avatar
Stefan Majewsky committed
23
#include <ctime>
24
#include <KAboutData>
Frederik Schwarzer's avatar
Frederik Schwarzer committed
25
#include <KCrash>
26 27 28 29 30

#include <QApplication>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QCommandLineOption>
Stefan Majewsky's avatar
Stefan Majewsky committed
31 32 33

int main(int argc, char** argv)
{
34 35
    // Fixes blurry icons with fractional scaling
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
36 37 38 39
    QApplication app(argc, argv);

    KLocalizedString::setApplicationDomain("palapeli");

40
    KAboutData about(QStringLiteral("palapeli"), i18nc("The application's name", "Palapeli"), PALAPELI_VERSION_STRING, i18n("KDE Jigsaw Puzzle Game"), KAboutLicense::GPL, i18n("Copyright 2009, 2010, Stefan Majewsky"));
41
    about.addAuthor(i18n("Stefan Majewsky"), QString(), QStringLiteral("majewsky@gmx.net"), QStringLiteral("https://majewsky.wordpress.com/"));
Frederik Schwarzer's avatar
Frederik Schwarzer committed
42 43
    about.addCredit (i18n ("Johannes Loehnert"),
            i18n ("The option to preview the completed puzzle"),
Laurent Montel's avatar
Laurent Montel committed
44
            QStringLiteral("loehnert.kde@gmx.de"));
45 46
    QCommandLineParser parser;
    KAboutData::setApplicationData(about);
Frederik Schwarzer's avatar
Frederik Schwarzer committed
47
    KCrash::initialize();
Laurent Montel's avatar
Laurent Montel committed
48
        parser.addPositionalArgument(QStringLiteral("puzzlefile"), i18n("Path to puzzle file (will be opened if -i is not given)"));
49
        parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("i") << QStringLiteral("import"), i18n("Import the given puzzle file into the local collection (does nothing if no puzzle file is given). The main window will not be shown after importing the given puzzle.")));
Stefan Majewsky's avatar
Stefan Majewsky committed
50

51 52 53
    about.setupCommandLine(&parser);
    parser.process(app);
    about.processCommandLine(&parser);
54

Stefan Majewsky's avatar
Stefan Majewsky committed
55

Frederik Schwarzer's avatar
Frederik Schwarzer committed
56
    //NOTE: Syntax errors are reported on stderr, while file errors are presented to the user.
Laurent Montel's avatar
Laurent Montel committed
57
    if (parser.isSet(QStringLiteral("import")))
Frederik Schwarzer's avatar
Frederik Schwarzer committed
58
        //perform import request
Laurent Montel's avatar
Laurent Montel committed
59
        new Palapeli::ImportHelper(parser.value(QStringLiteral("import")));
60 61 62 63 64 65
    else {
        const QStringList args = parser.positionalArguments();
        QString path;
        if (args.count()>1) {
            path = args.at(1);
        }
Frederik Schwarzer's avatar
Frederik Schwarzer committed
66
        //no import request, show main window
67 68
        (new Palapeli::MainWindow(path))->show();
    }
Frederik Schwarzer's avatar
Frederik Schwarzer committed
69
    app.setWindowIcon(QIcon::fromTheme(QStringLiteral("palapeli")));
Frederik Schwarzer's avatar
Frederik Schwarzer committed
70
    return app.exec();
Stefan Majewsky's avatar
Stefan Majewsky committed
71
}