source: calamares/trunk/fuentes/src/calamares/main.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 17 months ago

sync with github

File size: 3.8 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#include "CalamaresApplication.h"
22
23#include "CalamaresConfig.h"
24#include "kdsingleapplicationguard/kdsingleapplicationguard.h"
25#include "utils/CalamaresUtils.h"
26#include "utils/Logger.h"
27#include "CalamaresConfig.h"
28
29#ifdef WITH_KCRASH
30#include <KF5/KCrash/KCrash>
31#include <KF5/KCoreAddons/KAboutData>
32#endif
33
34#include <QCommandLineParser>
35#include <QDebug>
36#include <QDir>
37
38static void
39handle_args( CalamaresApplication& a )
40{
41    QCommandLineOption debugOption( QStringList{ "d", "debug"},
42                                    "Also look in current directory for configuration. Implies -D8." );
43    QCommandLineOption debugLevelOption( QStringLiteral("D"),
44                                          "Verbose output for debugging purposes (0-8).", "level" );
45    QCommandLineOption configOption( QStringList{ "c", "config"},
46                                     "Configuration directory to use, for testing purposes.", "config" );
47
48    QCommandLineParser parser;
49    parser.setApplicationDescription( "Distribution-independent installer framework" );
50    parser.addHelpOption();
51    parser.addVersionOption();
52
53    parser.addOption( debugOption );
54    parser.addOption( debugLevelOption );
55    parser.addOption( configOption );
56
57    parser.process( a );
58
59    a.setDebug( parser.isSet( debugOption ) );
60    if ( parser.isSet( debugOption ) )
61        Logger::setupLogLevel( Logger::LOGVERBOSE );
62    else if ( parser.isSet( debugLevelOption ) )
63    {
64        bool ok = true;
65        int l = parser.value( debugLevelOption ).toInt( &ok );
66        unsigned int dlevel = 0;
67        if ( !ok || ( l < 0 ) )
68            dlevel = Logger::LOGVERBOSE;
69        else
70            dlevel = l;
71        Logger::setupLogLevel( dlevel );
72    }
73    if ( parser.isSet( configOption ) )
74        CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
75}
76
77int
78main( int argc, char* argv[] )
79{
80    CalamaresApplication a( argc, argv );
81
82#ifdef WITH_KCRASH
83    KAboutData aboutData( "calamares",
84                          "Calamares",
85                          a.applicationVersion(),
86                          "The universal system installer",
87                          KAboutLicense::GPL_V3,
88                          QString(),
89                          QString(),
90                          "https://calamares.io",
91                          "https://github.com/calamares/calamares/issues" );
92    KAboutData::setApplicationData( aboutData );
93    KCrash::initialize();
94    // KCrash::setCrashHandler();
95    KCrash::setDrKonqiEnabled( true );
96    KCrash::setFlags( KCrash::SaferDialog | KCrash::AlwaysDirectly );
97    // TODO: umount anything in /tmp/calamares-... as an emergency save function
98    a.setApplicationDisplayName( QString() );
99#endif
100
101    handle_args( a );
102    KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
103
104    int returnCode = 0;
105    if ( guard.isPrimaryInstance() )
106    {
107        a.init();
108        returnCode = a.exec();
109    }
110    else
111        qDebug() << "Calamares is already running, shutting down.";
112
113    return returnCode;
114}
Note: See TracBrowser for help on using the repository browser.