main.cpp 3.46 KB
Newer Older
Matthias Elter's avatar
Matthias Elter committed
1
2
/*
 *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
Raffaele Sandrini's avatar
Raffaele Sandrini committed
3
 *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org)
4
 *   Copyright (C) 2008 Montel Laurent <montel@kde.org)
Matthias Elter's avatar
Matthias Elter committed
5
6
7
8
9
10
11
12
13
14
15
16
17
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
18
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Matthias Elter's avatar
Matthias Elter committed
19
20
21
 *
 */

Martin Flöser's avatar
Martin Flöser committed
22
#include <KLocalizedString>
Jekyll Wu's avatar
Jekyll Wu committed
23
#include <KAboutData>
24
25
#include <kdbusservice.h>
#include <kdemacros.h>
Matthias Elter's avatar
Matthias Elter committed
26

27
#include <QApplication>
28
#include <QtCore/QCommandLineParser>
Matthias Elter's avatar
Matthias Elter committed
29
#include "kmenuedit.h"
30
#ifndef Q_WS_WIN
31
#include "khotkeys.h"
32
#endif
Matthias Elter's avatar
Matthias Elter committed
33

34
static const char description[] = I18N_NOOP("KDE menu editor");
35
static const char version[] = "1.0";
36
37
38

static KMenuEdit *menuEdit = 0;

39
class KMenuApplication : public QApplication
40
41
{
public:
42
43
44
45
46
47
48
49
   KMenuApplication(int &argc, char **argv)
    : QApplication(argc, argv)
    {
        QCoreApplication::setApplicationName(QStringLiteral("kmenuedit"));
        QCoreApplication::setApplicationVersion(QString(version));
        QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
        QApplication::setApplicationDisplayName(i18n("KDE Menu Editor"));
    }
50
#ifdef WITH_HOTKEYS
51
   virtual ~KMenuApplication() { KHotKeys::cleanup(); }
52
#endif
53
54
};

Matthias Elter's avatar
Matthias Elter committed
55

56
extern "C" int Q_DECL_EXPORT kdemain( int argc, char **argv )
Matthias Elter's avatar
Matthias Elter committed
57
{
58
59
    KAboutData aboutData(QStringLiteral("kmenuedit"), i18n("KDE Menu Editor"),
                         QString(version), i18n(description), KAboutLicense::GPL,
Martin Flöser's avatar
Martin Flöser committed
60
61
62
63
64
                         i18n("(C) 2000-2003, Waldo Bastian, Raffaele Sandrini, Matthias Elter"));
    aboutData.addAuthor(i18n("Waldo Bastian"), i18n("Maintainer"), "bastian@kde.org");
    aboutData.addAuthor(i18n("Raffaele Sandrini"), i18n("Previous Maintainer"), QStringLiteral("sandrini@kde.org"));
    aboutData.addAuthor(i18n("Matthias Elter"), i18n("Original Author"), QStringLiteral("elter@kde.org"));
    aboutData.addAuthor(i18n("Montel Laurent"), QString(), QStringLiteral("montel@kde.org"));
65
    KAboutData::setApplicationData(aboutData);
Matthias Elter's avatar
Matthias Elter committed
66

67
    KMenuApplication app(argc, argv);
68

69
    KDBusService service(KDBusService::Unique);
Matthias Elter's avatar
Matthias Elter committed
70

71
72
73
74
75
76
77
78
79
80
    QCommandLineParser parser;
    parser.setApplicationDescription(i18n("KDE Menu Editor"));
    parser.addVersionOption();
    parser.addHelpOption();
    parser.addPositionalArgument(QStringLiteral("menu"),
                                 i18n("Sub menu to pre-select"),
                                 QStringLiteral("[menu]"));
    parser.addPositionalArgument(QStringLiteral("menu-id"),
                                 i18n("Menu entry to pre-select"),
                                 QStringLiteral("[menu-id]"));
Matthias Elter's avatar
Matthias Elter committed
81

82
83
    parser.process(app);
    const auto args = parser.positionalArguments();
Matthias Elter's avatar
Matthias Elter committed
84

85
    menuEdit = new KMenuEdit();
86
87
88
89
90
91
    if (!args.isEmpty()) {
        menuEdit->selectMenu(args.at(0));
        if (args.count() > 1) {
            menuEdit->selectMenuEntry(args.at(1));
        }
    }
Matthias Elter's avatar
Matthias Elter committed
92
93
94
    menuEdit->show();

    return  app.exec();
Matthias Elter's avatar
Matthias Elter committed
95
}