2 * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QDBusInterface>
22 #include <KCmdLineArgs>
26 int main(int argc
, char* argv
[])
28 KAboutData
aboutData( "kquitapp", 0, ki18n("Command-line application quitter"),
29 "1.0", ki18n("Quit a D-Bus enabled application easily"), KAboutData::License_GPL
,
30 ki18n("(c) 2006, Aaron Seigo") );
31 aboutData
.addAuthor(ki18n("Aaron J. Seigo"), ki18n("Current maintainer"), "aseigo@kde.org");
32 KCmdLineArgs::init(argc
, argv
, &aboutData
);
34 KCmdLineOptions options
;
35 options
.add("service <service>", ki18n("Full service name, overrides application name provided"));
36 options
.add("path <path>", ki18n("Path in the D-Bus interface to use"), "/MainApplication");
37 options
.add("+application", ki18n("The name of the application to quit"));
38 KCmdLineArgs::addCmdLineOptions(options
);
39 KCmdLineArgs
* args
= KCmdLineArgs::parsedArgs();
41 if (args
->count() == 0)
47 if (args
->isSet("service"))
49 service
= args
->getOption("service");
53 service
= QString("org.kde.%1").arg(QString(args
->arg(0)));
56 QString
path("/MainApplication");
57 if (args
->isSet("path"))
59 path
= args
->getOption("path");
62 QDBusInterface
interface(service
, path
);
63 if (!interface
.isValid()) {
64 kError() << i18n("Application %1 could not be found using service %2 and path %3.",args
->arg(0),service
,path
);
67 interface
.call("quit");
68 QDBusError error
= interface
.lastError();
69 if (error
.type() != QDBusError::NoError
) {
70 kError() << i18n("Quitting application %1 failed. Error reported was:\n\n %2 : %3",args
->arg(0),error
.name(), error
.message());