File indexing completed on 2022-12-06 18:50:19

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #include "cantor.h"
0007 #include <config-cantor.h>
0008 #include <QApplication>
0009 #include <KAboutData>
0010 #include <KCrash>
0011 #include <Kdelibs4ConfigMigrator>
0012 #include <KLocalizedString>
0013 #include <KConfigGroup>
0014 #include <KMessageBox>
0015 #include <QCommandLineParser>
0016 #include <QUrl>
0017 #include <QFileInfo>
0018 #include <QDir>
0019 #include <QDebug>
0020 #include <QtWebEngine>
0021 
0022 
0023 int main(int argc, char **argv)
0024 {
0025     QtWebEngine::initialize();
0026     // Register custom scheme handler for qthelp:// scheme
0027     QWebEngineUrlScheme qthelp("qthelp");
0028     QWebEngineUrlScheme::registerScheme(qthelp);
0029 
0030     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0031     QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0032     QApplication app(argc, argv);
0033 
0034     // Add our custom plugins path, where we install our plugins, if it isn't default path
0035     const QString& path = QString::fromLocal8Bit(PATH_TO_CANTOR_PLUGINS);
0036     qDebug() << "Adding additional application library path for Cantor plugins loading" << path;
0037     if (!QCoreApplication::libraryPaths().contains(path))
0038         QCoreApplication::addLibraryPath(path);
0039 
0040     KCrash::initialize();
0041 
0042     // Migrating configuration from 4.x applications to KF5-based applications
0043     QStringList configFiles;
0044     QStringList rcFiles;
0045 
0046     configFiles << QLatin1String("cantorrc");
0047     rcFiles << QLatin1String("cantor_part.rc") << QLatin1String("cantor_scripteditor.rc")
0048             << QLatin1String("cantor_shell.rc") << QLatin1String("cantor_advancedplot_assistant.rc")
0049             << QLatin1String("cantor_differentiate_assistant.rc") << QLatin1String("cantor_import_package_assistant.rc")
0050             << QLatin1String("cantor_integrate_assistant.rc") << QLatin1String("cantor_create_matrix_assistant.rc")
0051             << QLatin1String("cantor_eigenvalues_assistant.rc") << QLatin1String("cantor_eigenvectors_assistant.rc")
0052             << QLatin1String("cantor_invert_matrix_assistant.rc") << QLatin1String("cantor_plot2d_assistant.rc")
0053             << QLatin1String("cantor_plot3d_assistant.rc") << QLatin1String("cantor_runscript_assistant.rc")
0054             << QLatin1String("cantor_solve_assistant.rc") << QLatin1String("cantor_qalculateplotassistant.rc");
0055 
0056     Kdelibs4ConfigMigrator migrator(QLatin1String("cantor"));
0057 
0058     migrator.setConfigFiles(configFiles);
0059     migrator.setUiFiles(rcFiles);
0060     migrator.migrate();
0061     //**********************************
0062 
0063     KLocalizedString::setApplicationDomain("cantor");
0064     app.setApplicationName(QLatin1String("cantor"));
0065     app.setOrganizationDomain(QLatin1String("kde.org"));
0066     app.setApplicationDisplayName(i18n("Cantor"));
0067     app.setWindowIcon(QIcon::fromTheme(QLatin1String("cantor")));
0068 
0069     KAboutData about(QLatin1String("cantor"),
0070                      QLatin1String("Cantor"),
0071                      QLatin1String(CANTOR_VERSION),
0072                      i18n("KDE Frontend to mathematical applications"),
0073                      KAboutLicense::GPL,
0074                      i18n("(C) 2016 Filipe Saraiva<br/>(C) 2009-2015 Alexander Rieder"),
0075                      QString(),
0076                      QLatin1String("https://cantor.kde.org/"));
0077 
0078     about.addAuthor( i18n("Filipe Saraiva"), i18n("Maintainer<br/>Qt5/KF5 port, Scilab and Python backends"), QLatin1String("filipe@kde.org"), QLatin1String("http://filipesaraiva.info/") );
0079     about.addAuthor( i18n("Nikita Sirgienko"), i18nc("@info:credit", "Developer"), QLatin1String("warquark@gmail.com>"));
0080     about.addAuthor( i18n("Alexander Semke"), i18nc("@info:credit", "Developer"), QLatin1String("alexander.semke@web.de"));
0081     about.addAuthor( i18n("Alexander Rieder"), i18n("Original author<br/>Maintainer (2009 - 2015)"), QLatin1String("alexanderrieder@gmail.com") );
0082     about.addAuthor( i18n("Aleix Pol Gonzalez"), i18n("KAlgebra backend"), QLatin1String("aleixpol@kde.org") );
0083     about.addAuthor( i18n("Miha Čančula"), i18n("Octave backend"), QLatin1String("miha.cancula@gmail.com") );
0084     about.addAuthor( i18n("Martin Küttler"), i18n("Interface"), QLatin1String("martin.kuettler@gmail.com") );
0085 
0086     about.addCredit(QLatin1String("Andreas Kainz"), i18n("Cantor icon"), QLatin1String("kainz.a@gmail.com"));
0087     about.addCredit(QLatin1String("Uri Herrera"), i18n("Cantor icon"), QLatin1String("kaisergreymon99@gmail.com"), QLatin1String("http://nitrux.in/"));
0088 
0089     QCommandLineParser parser;
0090     KAboutData::setApplicationData(about);
0091 
0092     const QCommandLineOption backendOption(QStringList()<<QLatin1String("b")<<QLatin1String("backend"), i18n("Use  backend <backend>"), QLatin1String("backend"));
0093     parser.addOption(backendOption);
0094 
0095     parser.addPositionalArgument(QStringLiteral("files"),  i18n("Documents to open."),  QStringLiteral("[files...]"));
0096 
0097 
0098     about.setupCommandLine(&parser);
0099     parser.process(app);
0100     about.processCommandLine(&parser);
0101 
0102     // see if we are starting with session management
0103     if (app.isSessionRestored())
0104         RESTORE(CantorShell)
0105     else
0106     {
0107         // no session.. just start up normally
0108 
0109         CantorShell *widget = new CantorShell();
0110         if ( parser.positionalArguments().count() == 0 )
0111         {
0112             if(parser.isSet(QLatin1String("backend")))
0113             {
0114                 widget->addWorksheet(parser.value(QLatin1String("backend")));
0115             }
0116             else
0117             {
0118                 widget->addWorksheet();
0119             }
0120         }
0121         else
0122         {
0123             const QStringList& args=parser.positionalArguments();
0124             for (const QString& filename : args)
0125             {
0126                 const QUrl url = QUrl::fromUserInput(filename, QDir::currentPath(), QUrl::AssumeLocalFile);
0127                 if (url.isValid())
0128                 {
0129                     if (url.isLocalFile() && !QFileInfo(url.toLocalFile()).exists())
0130                         KMessageBox::error(widget, i18n("Couldn't open the file %1", filename), i18n("Cantor"));
0131                     else
0132                     {
0133                         widget->load(url);
0134                     }
0135                 }
0136             }
0137         }
0138         widget->show();
0139     }
0140 
0141     return app.exec();
0142 }
0143