File indexing completed on 2024-05-19 05:05:52
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2023 Thomas Fischer <fischer@unix-ag.uni-kl.de> 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 0018 ***************************************************************************/ 0019 0020 #include <cstdlib> 0021 0022 #include <QtDebug> 0023 #include <QApplication> 0024 #include <QCommandLineParser> 0025 #include <QRegularExpression> 0026 0027 #include <KAboutData> 0028 #include <KPluginMetaData> 0029 #include <KLocalizedString> 0030 #include <KMessageBox> 0031 #include <KCrash> 0032 0033 #include "mainwindow.h" 0034 #include "kbibtex-version.h" 0035 #include "kbibtex-git-info.h" 0036 #include "logging_program.h" 0037 0038 int main(int argc, char *argv[]) 0039 { 0040 if (strlen(KBIBTEX_GIT_INFO_STRING) > 0) { 0041 /// In Git versions, enable debugging by default 0042 QLoggingCategory::setFilterRules(QStringLiteral("kbibtex.*.debug = true")); 0043 } 0044 0045 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 0046 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0047 #endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 0048 0049 QApplication programCore(argc, argv); 0050 0051 KCrash::initialize(); 0052 0053 KLocalizedString::setApplicationDomain("kbibtex"); 0054 0055 KAboutData aboutData(QStringLiteral("kbibtex"), i18n("KBibTeX"), strlen(KBIBTEX_GIT_INFO_STRING) > 0 ? QLatin1String(KBIBTEX_GIT_INFO_STRING ", near " KBIBTEX_VERSION_STRING) : QLatin1String(KBIBTEX_VERSION_STRING), i18n("A BibTeX editor by KDE"), KAboutLicense::GPL_V2, i18n("Copyright 2004-2019 Thomas Fischer"), QString(), QStringLiteral("https://userbase.kde.org/KBibTeX")); 0056 0057 aboutData.setOrganizationDomain(QByteArray("kde.org")); 0058 aboutData.setDesktopFileName(QStringLiteral("org.kde.kbibtex")); 0059 0060 aboutData.addAuthor(i18n("Thomas Fischer"), i18n("Maintainer"), QStringLiteral("fischer@unix-ag.uni-kl.de")); 0061 0062 KAboutData::setApplicationData(aboutData); 0063 0064 programCore.setApplicationName(aboutData.componentName()); 0065 programCore.setOrganizationDomain(aboutData.organizationDomain()); 0066 programCore.setApplicationVersion(aboutData.version()); 0067 programCore.setApplicationDisplayName(aboutData.displayName()); 0068 programCore.setWindowIcon(QIcon::fromTheme(QStringLiteral("kbibtex"))); 0069 0070 qCInfo(LOG_KBIBTEX_PROGRAM) << "Starting KBibTeX version" << aboutData.version(); 0071 0072 QCommandLineParser cmdLineParser; 0073 cmdLineParser.addHelpOption(); 0074 cmdLineParser.addVersionOption(); 0075 cmdLineParser.addPositionalArgument(QStringLiteral("urls"), i18n("File(s) to load."), QStringLiteral("[urls...]")); 0076 0077 cmdLineParser.process(programCore); 0078 aboutData.processCommandLine(&cmdLineParser); 0079 0080 KBibTeXMainWindow *mainWindow = new KBibTeXMainWindow(); 0081 0082 const QStringList urls = cmdLineParser.positionalArguments(); 0083 /// Process arguments 0084 if (!urls.isEmpty()) 0085 { 0086 static const QRegularExpression protocolCheckerRegExp(QStringLiteral("^[a-zA-Z]+:")); 0087 for (const QString &url : urls) { 0088 const QUrl u = protocolCheckerRegExp.match(url).hasMatch() ? QUrl::fromUserInput(url) : QUrl::fromLocalFile(url); 0089 mainWindow->openDocument(u); 0090 } 0091 } 0092 0093 mainWindow->show(); 0094 0095 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 0096 const KPluginMetaData service { 0097 KPluginMetaData(QStringLiteral("kbibtexpart")) 0098 }; 0099 #else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0100 const KPluginMetaData service {KPluginMetaData::findPluginById(QStringLiteral("kf6/parts"), QStringLiteral("kbibtexpart"))}; 0101 #endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 0102 if (!service.isValid()) { 0103 /// Dump some environment variables that may be helpful 0104 /// in tracing back why the part's .desktop file was not found 0105 qCDebug(LOG_KBIBTEX_PROGRAM) << "PATH=" << getenv("PATH"); 0106 qCDebug(LOG_KBIBTEX_PROGRAM) << "LD_LIBRARY_PATH=" << getenv("LD_LIBRARY_PATH"); 0107 qCDebug(LOG_KBIBTEX_PROGRAM) << "XDG_DATA_DIRS=" << getenv("XDG_DATA_DIRS"); 0108 qCDebug(LOG_KBIBTEX_PROGRAM) << "QT_PLUGIN_PATH=" << getenv("QT_PLUGIN_PATH"); 0109 qCDebug(LOG_KBIBTEX_PROGRAM) << "KDEDIRS=" << getenv("KDEDIRS"); 0110 qCDebug(LOG_KBIBTEX_PROGRAM) << "QCoreApplication::libraryPaths=" << programCore.libraryPaths().join(QLatin1Char(':')); 0111 KMessageBox::error(mainWindow, i18n("KBibTeX seems to be not installed completely. KBibTeX could not locate its own KPart.\n\nOnly limited functionality will be available."), i18n("Incomplete KBibTeX Installation")); 0112 } else { 0113 qCInfo(LOG_KBIBTEX_PROGRAM) << "Located KPart:" << service.pluginId() << "with description" << service.name() << ":" << service.description(); 0114 } 0115 0116 /* 0117 /// started by session management? 0118 if (programCore.isSessionRestored()) { 0119 RESTORE(KBibTeXMainWindow()); 0120 } else { 0121 /// no session.. just start up normally 0122 KBibTeXMainWindow *mainWindow = new KBibTeXMainWindow(); 0123 0124 KCmdLineArgs *arguments = KCmdLineArgs::parsedArgs(); 0125 0126 for (int i = 0; i < arguments->count(); ++i) { 0127 const QUrl url = arguments->url(i); 0128 if (url.isValid()) 0129 mainWindow->openDocument(url); 0130 } 0131 mainWindow->show(); 0132 0133 arguments->clear(); 0134 } 0135 */ 0136 0137 return programCore.exec(); 0138 }