File indexing completed on 2024-09-08 13:16:59
0001 /* 0002 * SPDX-FileCopyrightText: 2000 Matthias Elter <elter@kde.org> 0003 * SPDX-FileCopyrightText: 2001-2002 Raffaele Sandrini <sandrini@kde.org> 0004 * SPDX-FileCopyrightText: 2008 Montel Laurent <montel@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 * 0008 */ 0009 0010 #include <KAboutData> 0011 #include <KLocalizedString> 0012 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0013 #include <Kdelibs4ConfigMigrator> 0014 #endif 0015 #include <KWindowSystem> 0016 #include <kdbusservice.h> 0017 0018 #include "kmenuedit.h" 0019 #include <QApplication> 0020 #include <QCommandLineParser> 0021 0022 class KMenuApplication : public QApplication 0023 { 0024 public: 0025 KMenuApplication(int &argc, char **argv) 0026 : QApplication(argc, argv) 0027 { 0028 QCoreApplication::setApplicationName(QStringLiteral("kmenuedit")); 0029 QCoreApplication::setApplicationVersion(QStringLiteral(PROJECT_VERSION)); 0030 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); 0031 QApplication::setApplicationDisplayName(i18n("KDE Menu Editor")); 0032 } 0033 }; 0034 0035 int main(int argc, char **argv) 0036 { 0037 KMenuApplication app(argc, argv); 0038 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0039 Kdelibs4ConfigMigrator migrate(QStringLiteral("kmenuedit")); 0040 migrate.setConfigFiles(QStringList() << QStringLiteral("kmenueditrc")); 0041 migrate.setUiFiles(QStringList() << QStringLiteral("kmenueditui.rc")); 0042 migrate.migrate(); 0043 QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0044 #endif 0045 KLocalizedString::setApplicationDomain("kmenuedit"); 0046 0047 KAboutData aboutData(QStringLiteral("kmenuedit"), 0048 i18n("KDE Menu Editor"), 0049 QStringLiteral(PROJECT_VERSION), 0050 i18n("KDE menu editor"), 0051 KAboutLicense::GPL, 0052 i18n("(C) 2000-2003, Waldo Bastian, Raffaele Sandrini, Matthias Elter")); 0053 aboutData.addAuthor(i18n("Waldo Bastian"), i18n("Maintainer"), QStringLiteral("bastian@kde.org")); 0054 aboutData.addAuthor(i18n("Raffaele Sandrini"), i18n("Previous Maintainer"), QStringLiteral("sandrini@kde.org")); 0055 aboutData.addAuthor(i18n("Matthias Elter"), i18n("Original Author"), QStringLiteral("elter@kde.org")); 0056 aboutData.addAuthor(i18n("Montel Laurent"), QString(), QStringLiteral("montel@kde.org")); 0057 KAboutData::setApplicationData(aboutData); 0058 0059 KDBusService service(KDBusService::Unique); 0060 0061 QCommandLineParser parser; 0062 parser.setApplicationDescription(i18n("KDE Menu Editor")); 0063 parser.addPositionalArgument(QStringLiteral("menu"), i18n("Sub menu to pre-select"), QStringLiteral("[menu]")); 0064 parser.addPositionalArgument(QStringLiteral("menu-id"), i18n("Menu entry to pre-select"), QStringLiteral("[menu-id]")); 0065 aboutData.setupCommandLine(&parser); 0066 parser.process(app); 0067 aboutData.processCommandLine(&parser); 0068 0069 auto *menuEdit = new KMenuEdit(); 0070 0071 auto useArgs = [menuEdit](const QCommandLineParser &parser) { 0072 const QStringList args = parser.positionalArguments(); 0073 if (!args.isEmpty()) { 0074 menuEdit->selectMenu(args.at(0)); 0075 if (args.count() > 1) { 0076 menuEdit->selectMenuEntry(args.at(1)); 0077 } 0078 } 0079 }; 0080 0081 useArgs(parser); 0082 0083 QObject::connect(&service, &KDBusService::activateRequested, menuEdit, [useArgs, &parser, menuEdit](const QStringList &args, const QString & /*workDir*/) { 0084 parser.parse(args); 0085 useArgs(parser); 0086 0087 KWindowSystem::updateStartupId(menuEdit->windowHandle()); 0088 KWindowSystem::activateWindow(menuEdit->windowHandle()); 0089 }); 0090 0091 menuEdit->show(); 0092 0093 return app.exec(); 0094 }