main.cpp 3.31 KB
Newer Older
1
/* This file is part of KCachegrind.
Josef Weidendorfer's avatar
Josef Weidendorfer committed
2
   Copyright (C) 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3
4
5
6
7
8
9
10
11
12
13
14

   KCachegrind 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, version 2.

   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; see the file COPYING.  If not, write to
15
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Dirk Mueller's avatar
Dirk Mueller committed
16
   Boston, MA 02110-1301, USA.
17
18
19
20
21
22
*/

/*
 * KCachegrind startup
 */

Josef Weidendorfer's avatar
Josef Weidendorfer committed
23
24
// for KCACHEGRIND_VERSION
#include "../version.h"
25

26

27
28
29
30
31
#include <QApplication>
#include <QCommandLineParser>
#include <KAboutData>
#include <KLocalizedString>
#include <KSharedConfig>
32

33
#include "kdeconfig.h"
34
35
36
37
38
39
#include "toplevel.h"
#include "tracedata.h"
#include "loader.h"

int main( int argc, char ** argv )
{
40
41
42
43
44
45
46
47
48
49
50
51
    QApplication a(argc, argv);
    KLocalizedString::setApplicationDomain("kcachegrind");
    KAboutData aboutData(QStringLiteral("kcachegrind"),
                         i18n("KCachegrind"),
                         KCACHEGRIND_VERSION,
                         i18n("KDE Frontend for Callgrind/Cachegrind"),
                         KAboutLicense::GPL,
                         i18n("(C) 2002 - 2016"), QString(),
                         QStringLiteral("https://kcachegrind.github.io"));
    aboutData.addAuthor(i18n("Josef Weidendorfer"),
                        i18n("Author/Maintainer"),
                        QStringLiteral("Josef.Weidendorfer@gmx.de"));
52
    aboutData.setDesktopFileName(QStringLiteral("org.kde.kcachegrind"));
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

    KAboutData::setApplicationData(aboutData);

    //   KGlobal::locale()->insertCatalog("kcachegrind_qt");
    Loader::initLoaders();

    KConfig* kc = KSharedConfig::openConfig().data();
    ConfigStorage::setStorage(new KDEConfigStorage(kc));

    if (a.isSessionRestored()){
        int n = 1;
        while (KMainWindow::canBeRestored(n)){
            (new TopLevel())->restore(n);
            n++;
        }
68
69
    }
    else {
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        TopLevel* t;

        QCommandLineParser parser;
        parser.addPositionalArgument(QStringLiteral("trace"), i18n("Show information of this trace"), i18n("[trace...]"));
        parser.addVersionOption();
        parser.addHelpOption();
        aboutData.setupCommandLine(&parser);
        parser.process(a);
        aboutData.processCommandLine(&parser);

        int nbArgs = parser.positionalArguments().count();
        if (nbArgs>0) {
            t = new TopLevel();
            t->show();
            foreach(const QString &arg, parser.positionalArguments()) {
                t->loadDelayed(arg);
            }
        }
        else {
            // load trace in current dir
            t = new TopLevel();
            t->show();
            t->loadDelayed(QStringLiteral("."));
        }
94
95
    }

96
97
    a.connect( &a, &QGuiApplication::lastWindowClosed, &a, &QCoreApplication::quit );
    int res = a.exec();
Josef Weidendorfer's avatar
Josef Weidendorfer committed
98

99
100
101
102
    // to make leak checking in valgrind happy...
    Loader::deleteLoaders();
    ProfileContext::cleanup();
    ConfigStorage::cleanup();
Josef Weidendorfer's avatar
Josef Weidendorfer committed
103

104
    return res;
105
}