main.cpp 5.79 KB
Newer Older
Alexander Rieder's avatar
Alexander Rieder committed
1
/*
2
3
4
    SPDX-License-Identifier: GPL-2.0-or-later
    SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
*/
Alexander Rieder's avatar
Alexander Rieder committed
5

Alexander Rieder's avatar
Alexander Rieder committed
6
#include "cantor.h"
Yuri Chornoivan's avatar
Yuri Chornoivan committed
7
#include <config-cantor.h>
8
9
#include <QApplication>
#include <KAboutData>
10
#include <KCrash>
11
#include <Kdelibs4ConfigMigrator>
12
#include <KLocalizedString>
13
#include <KConfigGroup>
14
#include <KMessageBox>
15
#include <QCommandLineParser>
16
#include <QUrl>
17
18
#include <QFileInfo>
#include <QDir>
19
20
#include <QDebug>

21
static const char description[] =
22
    I18N_NOOP("KDE Frontend to mathematical applications");
23
24
25

int main(int argc, char **argv)
{
Laurent Montel's avatar
Laurent Montel committed
26
    QApplication app(argc, argv);
27
28

    // Add our custom plugins path, where we install our plugins, if it isn't default path
29
30
    const QString& path = QString::fromLocal8Bit(PATH_TO_CANTOR_PLUGINS);
    qDebug() << "Adding additional application library path for Cantor plugins loading" << path;
31
32
33
    if (!QCoreApplication::libraryPaths().contains(path))
        QCoreApplication::addLibraryPath(path);

34
    KCrash::initialize();
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    // Migrating configuration from 4.x applications to KF5-based applications
    QStringList configFiles;
    QStringList rcFiles;

    configFiles << QLatin1String("cantorrc");
    rcFiles << QLatin1String("cantor_part.rc") << QLatin1String("cantor_scripteditor.rc")
            << QLatin1String("cantor_shell.rc") << QLatin1String("cantor_advancedplot_assistant.rc")
            << QLatin1String("cantor_differentiate_assistant.rc") << QLatin1String("cantor_import_package_assistant.rc")
            << QLatin1String("cantor_integrate_assistant.rc") << QLatin1String("cantor_create_matrix_assistant.rc")
            << QLatin1String("cantor_eigenvalues_assistant.rc") << QLatin1String("cantor_eigenvectors_assistant.rc")
            << QLatin1String("cantor_invert_matrix_assistant.rc") << QLatin1String("cantor_plot2d_assistant.rc")
            << QLatin1String("cantor_plot3d_assistant.rc") << QLatin1String("cantor_runscript_assistant.rc")
            << QLatin1String("cantor_solve_assistant.rc") << QLatin1String("cantor_qalculateplotassistant.rc");

    Kdelibs4ConfigMigrator migrator(QLatin1String("cantor"));

    migrator.setConfigFiles(configFiles);
    migrator.setUiFiles(rcFiles);
    migrator.migrate();
    //**********************************

57
    KLocalizedString::setApplicationDomain("cantor");
58
59
60
    app.setApplicationName(QLatin1String("cantor"));
    app.setOrganizationDomain(QLatin1String("kde.org"));
    app.setApplicationDisplayName(i18n("Cantor"));
61
    app.setWindowIcon(QIcon::fromTheme(QLatin1String("cantor")));
62
63
64

    KAboutData about(QLatin1String("cantor"),
                     QLatin1String("Cantor"),
65
                     QLatin1String(CANTOR_VERSION),
66
67
                     i18n(description),
                     KAboutLicense::GPL,
68
                     i18n("(C) 2016 Filipe Saraiva<br/>(C) 2009-2015 Alexander Rieder"),
69
                     QString(),
Filipe Saraiva's avatar
Filipe Saraiva committed
70
                     QLatin1String("https://cantor.kde.org/"));
71

72
    about.addAuthor( i18n("Filipe Saraiva"), i18n("Maintainer<br/>Qt5/KF5 port, Scilab and Python backends"), QLatin1String("filipe@kde.org"), QLatin1String("http://filipesaraiva.info/") );
73
74
    about.addAuthor( i18n("Nikita Sirgienko"), i18nc("@info:credit", "Developer"), QLatin1String("warquark@gmail.com>"));
    about.addAuthor( i18n("Alexander Semke"), i18nc("@info:credit", "Developer"), QLatin1String("alexander.semke@web.de"));
75
    about.addAuthor( i18n("Alexander Rieder"), i18n("Original author<br/>Maintainer (2009 - 2015)"), QLatin1String("alexanderrieder@gmail.com") );
76
77
78
    about.addAuthor( i18n("Aleix Pol Gonzalez"), i18n("KAlgebra backend"), QLatin1String("aleixpol@kde.org") );
    about.addAuthor( i18n("Miha Čančula"), i18n("Octave backend"), QLatin1String("miha.cancula@gmail.com") );
    about.addAuthor( i18n("Martin Küttler"), i18n("Interface"), QLatin1String("martin.kuettler@gmail.com") );
79

80
    about.addCredit(QLatin1String("Andreas Kainz"), i18n("Cantor icon"), QLatin1String("kainz.a@gmail.com"));
81
    about.addCredit(QLatin1String("Uri Herrera"), i18n("Cantor icon"), QLatin1String("kaisergreymon99@gmail.com"), QLatin1String("http://nitrux.in/"));
82
83
84
85

    QCommandLineParser parser;
    KAboutData::setApplicationData(about);

Alexander Rieder's avatar
Alexander Rieder committed
86
87
88
89
    const QCommandLineOption backendOption(QStringList()<<QLatin1String("b")<<QLatin1String("backend"), i18n("Use  backend <backend>"), QLatin1String("backend"));
    parser.addOption(backendOption);

    parser.addPositionalArgument(QStringLiteral("files"),  i18n("Documents to open."),  QStringLiteral("[files...]"));
90
91
92
93
94


    about.setupCommandLine(&parser);
    parser.process(app);
    about.processCommandLine(&parser);
Alexander Rieder's avatar
Alexander Rieder committed
95

96
97
    // see if we are starting with session management
    if (app.isSessionRestored())
Alexander Rieder's avatar
Alexander Rieder committed
98
        RESTORE(CantorShell)
99
100
101
102
    else
    {
        // no session.. just start up normally

103
        CantorShell *widget = new CantorShell();
104
        if ( parser.positionalArguments().count() == 0 )
105
        {
106
            if(parser.isSet(QLatin1String("backend")))
107
            {
108
                widget->addWorksheet(parser.value(QLatin1String("backend")));
109
110
111
112
113
            }
            else
            {
                widget->addWorksheet();
            }
114
115
116
        }
        else
        {
117
            const QStringList& args=parser.positionalArguments();
118
            for (const QString& filename : args)
119
            {
120
121
122
123
124
125
126
127
128
129
                const QUrl url = QUrl::fromUserInput(filename, QDir::currentPath(), QUrl::AssumeLocalFile);
                if (url.isValid())
                {
                    if (url.isLocalFile() && !QFileInfo(url.toLocalFile()).exists())
                        KMessageBox::error(widget, i18n("Couldn't open the file %1", filename), i18n("Cantor"));
                    else
                    {
                        widget->load(url);
                    }
                }
130
131
            }
        }
132
        widget->show();
133
134
135
136
    }

    return app.exec();
}
137