Warning, file /sdk/lokalize/src/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of Lokalize 0003 0004 SPDX-FileCopyrightText: 2007-2014 Nick Shaforostoff <shafff@ukr.net> 0005 SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0008 */ 0009 0010 0011 #include "lokalize_debug.h" 0012 0013 #include "project.h" 0014 #include "prefs.h" 0015 #include "prefs_lokalize.h" 0016 0017 #include "version.h" 0018 #include "projecttab.h" 0019 #include "projectmodel.h" 0020 0021 #include "lokalizemainwindow.h" 0022 #include "stemming.h" 0023 0024 #include "jobs.h" 0025 #include "catalogstring.h" 0026 #include "pos.h" 0027 0028 #include <QMetaType> 0029 #include <QString> 0030 #include <QFile> 0031 #include <QFileInfo> 0032 #include <QDesktopWidget> 0033 #include <QApplication> 0034 #include <QCommandLineParser> 0035 #include <QCommandLineOption> 0036 0037 #include <KCrash> 0038 #include <KDBusService> 0039 0040 #include <klocalizedstring.h> 0041 0042 #include <kaboutdata.h> 0043 #include "editortab.h" 0044 0045 int main(int argc, char **argv) 0046 { 0047 TM::threadPool()->setMaxThreadCount(1); 0048 TM::threadPool()->setExpiryTimeout(-1); 0049 QThreadPool::globalInstance()->setMaxThreadCount(1); 0050 // Fixes blurry icons with fractional scaling, see https://phabricator.kde.org/D29376 0051 QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0052 QApplication app(argc, argv); 0053 KCrash::initialize(); 0054 KLocalizedString::setApplicationDomain("lokalize"); 0055 QCommandLineParser parser; 0056 KAboutData about(QStringLiteral("lokalize"), i18nc("@title", "Lokalize"), QStringLiteral(LOKALIZE_VERSION)); 0057 about.setShortDescription(i18n("Computer-aided translation system.\nDo not translate what had already been translated.")); 0058 about.setLicense(KAboutLicense::GPL); 0059 about.setCopyrightStatement(i18nc("@info:credit", "(c) 2018-2019 Simon Depiets\n(c) 2007-2015 Nick Shaforostoff\n(c) 1999-2006 The KBabel developers")); 0060 about.addAuthor(i18n("Nick Shaforostoff"), QString(), QStringLiteral("shaforostoff@gmail.com")); 0061 about.addCredit(i18n("Google Inc."), i18n("sponsored development as part of Google Summer Of Code program"), QString(), QStringLiteral("https://google.com")); 0062 about.addCredit(i18n("NLNet Foundation"), i18n("sponsored XLIFF-related work"), QString(), QStringLiteral("https://nlnet.nl/")); 0063 about.addCredit(i18n("Translate-toolkit"), i18n("provided excellent cross-format converting scripts"), QString(), QStringLiteral("https://toolkit.translatehouse.org")); 0064 about.addCredit(i18n("LanguageTool"), i18n("grammar, style and spell checker"), QString(), QStringLiteral("https://toolkit.translatehouse.org")); 0065 about.addCredit(i18n("Viesturs Zarins"), i18n("project tree merging translation+templates"), QStringLiteral("https://languagetool.org"), QString()); 0066 about.addCredit(i18n("Stephan Johach"), i18n("bug fixing patches"), QStringLiteral("hunsum@gmx.de")); 0067 about.addCredit(i18n("Chusslove Illich"), i18n("bug fixing patches"), QStringLiteral("caslav.ilic@gmx.net")); 0068 about.addCredit(i18n("Jure Repinc"), i18n("testing and bug fixing"), QStringLiteral("jlp@holodeck1.com")); 0069 about.addCredit(i18n("Stefan Asserhall"), i18n("patches"), QStringLiteral("stefan.asserhall@comhem.se")); 0070 about.addCredit(i18n("Papp Laszlo"), i18n("bug fixing patches"), QStringLiteral("djszapi@archlinux.us")); 0071 about.addCredit(i18n("Albert Astals Cid"), i18n("XLIFF improvements"), QStringLiteral("aacid@kde.org")); 0072 about.addCredit(i18n("Simon Depiets"), i18n("bug fixing and improvements"), QStringLiteral("sdepiets@gmail.com")); 0073 KAboutData::setApplicationData(about); 0074 about.setupCommandLine(&parser); 0075 //parser.addOption(QCommandLineOption(QStringList() << QLatin1String("source"), i18n( "Source for the merge mode" ), QLatin1String("URL"))); 0076 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("noprojectscan"), i18n("Do not scan files of the project."))); 0077 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("project"), i18n("Load specified project."), QStringLiteral("filename"))); 0078 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[URL]"), i18n("Document to open"))); 0079 parser.process(app); 0080 about.processCommandLine(&parser); 0081 0082 //qCDebug(LOKALIZE_LOG) is important as it avoids compile 'optimization'. 0083 qCDebug(LOKALIZE_LOG) << qRegisterMetaType<DocPosition>(); 0084 qCDebug(LOKALIZE_LOG) << qRegisterMetaType<DocPos>(); 0085 qCDebug(LOKALIZE_LOG) << qRegisterMetaType<InlineTag>(); 0086 qCDebug(LOKALIZE_LOG) << qRegisterMetaType<CatalogString>(); 0087 qRegisterMetaTypeStreamOperators<InlineTag>("InlineTag"); 0088 qRegisterMetaTypeStreamOperators<CatalogString>("CatalogString"); 0089 qAddPostRoutine(&cleanupSpellers); 0090 0091 const KDBusService dbusService(KDBusService::Multiple); 0092 0093 // see if we are starting with session management 0094 if (app.isSessionRestored()) 0095 kRestoreMainWindows<LokalizeMainWindow>(); 0096 else { 0097 // no session.. just start up normally 0098 0099 QString projectFilePath = parser.value(QStringLiteral("project")); 0100 0101 QVector<QString> urls; 0102 const auto filePaths = parser.positionalArguments(); 0103 for (const QString& filePath : filePaths) 0104 if (filePath.endsWith(QLatin1String(".lokalize"))) 0105 projectFilePath = filePath; 0106 else if (QFileInfo::exists(filePath)) 0107 urls.append(filePath); 0108 0109 if (!projectFilePath.isEmpty()) { 0110 // load needs an absolute path 0111 // FIXME: I do not know how to handle urls here 0112 // bug 245546 regarding symlinks 0113 QFileInfo projectFileInfo(projectFilePath); 0114 projectFilePath = projectFileInfo.canonicalFilePath(); 0115 if (projectFilePath.isEmpty()) 0116 projectFilePath = projectFileInfo.absoluteFilePath(); 0117 Project::instance()->load(projectFilePath); 0118 } 0119 LokalizeMainWindow* lmw = new LokalizeMainWindow; 0120 SettingsController::instance()->setMainWindowPtr(lmw); 0121 lmw->show(); 0122 0123 if (urls.size()) 0124 new DelayedFileOpener(urls, lmw); 0125 0126 //Project::instance()->model()->setCompleteScan(parser.isSet("noprojectscan"));// TODO: negate check (and ensure nobody passes the no-op --noprojectscan argument) 0127 } 0128 int code = app.exec(); 0129 0130 QThreadPool::globalInstance()->clear(); 0131 TM::cancelAllJobs(); 0132 TM::threadPool()->clear(); 0133 TM::threadPool()->waitForDone(1000); 0134 Project::instance()->model()->threadPool()->clear(); 0135 0136 if (SettingsController::instance()->dirty) //for config changes done w/o config dialog 0137 Settings::self()->save(); 0138 0139 if (Project::instance()->isLoaded()) 0140 Project::instance()->save(); 0141 0142 qCDebug(LOKALIZE_LOG) << "Finishing Project jobs..."; 0143 qCDebug(LOKALIZE_LOG) << "Finishing TM jobs..."; 0144 int secs = 5; 0145 while (--secs >= 0) { 0146 Project::instance()->model()->threadPool()->waitForDone(1000); 0147 TM::threadPool()->waitForDone(1000); 0148 QThreadPool::globalInstance()->waitForDone(1000); 0149 //qCDebug(LOKALIZE_LOG)<<"QCoreApplication::processEvents()..."; 0150 QCoreApplication::processEvents(); 0151 QCoreApplication::sendPostedEvents(nullptr, 0); 0152 } 0153 return code; 0154 } 0155 0156