File indexing completed on 2024-05-05 05:52:23
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2001-2022 Christoph Cullmann <cullmann@kde.org> 0003 SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org> 0004 SPDX-FileCopyrightText: 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "kateapp.h" 0010 0011 #include <KAboutData> 0012 #include <KDBusService> 0013 #include <KLocalizedString> 0014 0015 #include <QApplication> 0016 #include <QCommandLineParser> 0017 #include <QIcon> 0018 #include <QStandardPaths> 0019 0020 extern "C" Q_DECL_EXPORT int main(int argc, char **argv) 0021 { 0022 /** 0023 * Do all needed pre-application init steps, shared between Kate and KWrite 0024 */ 0025 KateApp::initPreApplicationCreation(false /* never detach */); 0026 0027 /** 0028 * Create application first 0029 * Enforce application name even if the executable is renamed 0030 */ 0031 QApplication app(argc, argv); 0032 app.setApplicationName(QStringLiteral("kwrite")); 0033 0034 /** 0035 * Connect application with translation catalogs, Kate & KWrite share the same one 0036 */ 0037 KLocalizedString::setApplicationDomain(QByteArrayLiteral("kate")); 0038 0039 /** 0040 * then use i18n and co 0041 */ 0042 KAboutData aboutData(QStringLiteral("kwrite"), 0043 i18n("KWrite"), 0044 QStringLiteral(KATE_VERSION), 0045 i18n("KWrite - Text Editor"), 0046 KAboutLicense::LGPL_V2, 0047 i18n("(c) 2000-2022 The Kate Authors"), 0048 // use the other text field to get our mascot into the about dialog 0049 QStringLiteral("<img height=\"362\" width=\"512\" src=\":/kate/mascot.png\"/>"), 0050 QStringLiteral("https://kate-editor.org")); 0051 0052 /** 0053 * right dbus prefix == org.kde. 0054 */ 0055 aboutData.setOrganizationDomain(QByteArray("kde.org")); 0056 0057 /** 0058 * desktop file association to make application icon work (e.g. in Wayland window decoration) 0059 */ 0060 aboutData.setDesktopFileName(QStringLiteral("org.kde.kwrite")); 0061 0062 /** 0063 * authors & co. 0064 * add yourself there, if you helped to work on Kate or KWrite 0065 */ 0066 KateApp::fillAuthorsAndCredits(aboutData); 0067 0068 /** 0069 * set proper KWrite icon for our about dialog 0070 */ 0071 aboutData.setProgramLogo(QIcon(QStringLiteral(":/kwrite/kwrite.svg"))); 0072 0073 /** 0074 * bugzilla 0075 */ 0076 aboutData.setProductName(QByteArray("kate/kwrite")); 0077 0078 /** 0079 * set and register app about data 0080 */ 0081 KAboutData::setApplicationData(aboutData); 0082 0083 /** 0084 * set the program icon 0085 */ 0086 #ifndef Q_OS_MACOS // skip this on macOS to have proper mime-type icon visible 0087 QApplication::setWindowIcon(QIcon(QStringLiteral(":/kwrite/kwrite.svg"))); 0088 #endif 0089 0090 /** 0091 * Create command line parser and feed it with known options 0092 */ 0093 QCommandLineParser parser; 0094 aboutData.setupCommandLine(&parser); 0095 0096 // -e/--encoding option 0097 const QCommandLineOption useEncoding(QStringList() << QStringLiteral("e") << QStringLiteral("encoding"), 0098 i18n("Set encoding for the file to open."), 0099 i18n("encoding")); 0100 parser.addOption(useEncoding); 0101 0102 // -l/--line option 0103 const QCommandLineOption gotoLine(QStringList() << QStringLiteral("l") << QStringLiteral("line"), i18n("Navigate to this line."), i18n("line")); 0104 parser.addOption(gotoLine); 0105 0106 // -c/--column option 0107 const QCommandLineOption gotoColumn(QStringList() << QStringLiteral("c") << QStringLiteral("column"), i18n("Navigate to this column."), i18n("column")); 0108 parser.addOption(gotoColumn); 0109 0110 // -i/--stdin option 0111 const QCommandLineOption readStdIn(QStringList() << QStringLiteral("i") << QStringLiteral("stdin"), i18n("Read the contents of stdin.")); 0112 parser.addOption(readStdIn); 0113 0114 // --tempfile option 0115 const QCommandLineOption tempfile(QStringList() << QStringLiteral("tempfile"), i18n("The files/URLs opened by the application will be deleted after use")); 0116 parser.addOption(tempfile); 0117 0118 // urls to open 0119 parser.addPositionalArgument(QStringLiteral("urls"), i18n("Documents to open."), i18n("[urls...]")); 0120 0121 /** 0122 * do the command line parsing 0123 */ 0124 parser.process(app); 0125 0126 /** 0127 * handle standard options 0128 */ 0129 aboutData.processCommandLine(&parser); 0130 0131 /** 0132 * construct the real kate app object ;) 0133 * behaves like a singleton, one unique instance 0134 * we are passing our local command line parser to it 0135 */ 0136 KateApp kateApp(parser, 0137 KateApp::ApplicationKWrite, 0138 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kwrite/sessions")); 0139 0140 /** 0141 * init kate 0142 * if this returns false, we shall exit 0143 * else we may enter the main event loop 0144 */ 0145 if (!kateApp.init()) { 0146 return 0; 0147 } 0148 0149 /** 0150 * finally register this kwrite instance for dbus, don't die if no dbus is around! 0151 */ 0152 const KDBusService dbusService(KDBusService::Multiple | KDBusService::NoExitOnFailure); 0153 0154 /** 0155 * Run the event loop 0156 */ 0157 return app.exec(); 0158 }