File indexing completed on 2024-02-18 05:27:41

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 #include <KWindowSystem>
0013 #include <kdbusservice.h>
0014 
0015 #include "kmenuedit.h"
0016 #include <QApplication>
0017 #include <QCommandLineParser>
0018 
0019 class KMenuApplication : public QApplication
0020 {
0021 public:
0022     KMenuApplication(int &argc, char **argv)
0023         : QApplication(argc, argv)
0024     {
0025         QCoreApplication::setApplicationName(QStringLiteral("kmenuedit"));
0026         QCoreApplication::setApplicationVersion(QStringLiteral(PROJECT_VERSION));
0027         QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0028         QApplication::setApplicationDisplayName(i18n("KDE Menu Editor"));
0029     }
0030 };
0031 
0032 int main(int argc, char **argv)
0033 {
0034     KMenuApplication app(argc, argv);
0035     KLocalizedString::setApplicationDomain(QByteArrayLiteral("kmenuedit"));
0036 
0037     KAboutData aboutData(QStringLiteral("kmenuedit"),
0038                          i18n("KDE Menu Editor"),
0039                          QStringLiteral(PROJECT_VERSION),
0040                          i18n("KDE menu editor"),
0041                          KAboutLicense::GPL,
0042                          i18n("(C) 2000-2003, Waldo Bastian, Raffaele Sandrini, Matthias Elter"));
0043     aboutData.addAuthor(i18n("Waldo Bastian"), i18n("Maintainer"), QStringLiteral("bastian@kde.org"));
0044     aboutData.addAuthor(i18n("Raffaele Sandrini"), i18n("Previous Maintainer"), QStringLiteral("sandrini@kde.org"));
0045     aboutData.addAuthor(i18n("Matthias Elter"), i18n("Original Author"), QStringLiteral("elter@kde.org"));
0046     aboutData.addAuthor(i18n("Montel Laurent"), QString(), QStringLiteral("montel@kde.org"));
0047     KAboutData::setApplicationData(aboutData);
0048 
0049     KDBusService service(KDBusService::Unique);
0050 
0051     QCommandLineParser parser;
0052     parser.setApplicationDescription(i18n("KDE Menu Editor"));
0053     parser.addPositionalArgument(QStringLiteral("menu"), i18n("Sub menu to pre-select"), QStringLiteral("[menu]"));
0054     parser.addPositionalArgument(QStringLiteral("menu-id"), i18n("Menu entry to pre-select"), QStringLiteral("[menu-id]"));
0055     aboutData.setupCommandLine(&parser);
0056     parser.process(app);
0057     aboutData.processCommandLine(&parser);
0058 
0059     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kmenuedit")));
0060     auto *menuEdit = new KMenuEdit();
0061 
0062     auto useArgs = [menuEdit](const QCommandLineParser &parser) {
0063         const QStringList args = parser.positionalArguments();
0064         if (!args.isEmpty()) {
0065             menuEdit->selectMenu(args.at(0));
0066             if (args.count() > 1) {
0067                 menuEdit->selectMenuEntry(args.at(1));
0068             }
0069         }
0070     };
0071 
0072     useArgs(parser);
0073 
0074     QObject::connect(&service, &KDBusService::activateRequested, menuEdit, [useArgs, &parser, menuEdit](const QStringList &args, const QString & /*workDir*/) {
0075         parser.parse(args);
0076         useArgs(parser);
0077 
0078         KWindowSystem::updateStartupId(menuEdit->windowHandle());
0079         KWindowSystem::activateWindow(menuEdit->windowHandle());
0080     });
0081 
0082     menuEdit->show();
0083 
0084     return app.exec();
0085 }