19
21
***************************************************************************/
21
#include <kcmdlineargs.h>
22
#include <kaboutdata.h>
23
#include <KCmdLineArgs>
26
#include <KMessageBox>
27
#include <KDesktopFile>
28
#include <KIconLoader>
31
#include <KStandardDirs>
34
#include <KApplication>
25
36
#include "kdesudo.h"
26
#include <kmessagebox.h>
27
#include <kdesktopfile.h>
28
#include <kiconloader.h>
29
#include <kicontheme.h>
31
#include <kstandarddirs.h>
35
#include <qfileinfo.h>
37
static const char *description =
39
// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
42
static KCmdLineOptions options[] =
44
{ "u <runas>", I18N_NOOP("sets a runas user"), 0 },
45
{ "c <command>", I18N_NOOP("The command to execute"), 0 },
46
{ "s", I18N_NOOP("Forget passwords"), 0 },
47
{ "i <icon name>", I18N_NOOP("Specify icon to use in the password dialog"), 0},
48
{ "d", I18N_NOOP("Do not show the command to be run in the dialog"), 0},
49
{ "p <priority>", I18N_NOOP("Process priority, between 0 and 100, 0 the lowest [50]"), 0},
50
{ "r", I18N_NOOP("Use realtime scheduling"), 0},
51
{ "f <file>", I18N_NOOP("Use target UID if <file> is not writeable"), 0},
52
{ "t", I18N_NOOP("Fake option for KDE's KdeSu compatibility"), 0 },
53
{ "n", I18N_NOOP("Do not keep password"), 0},
54
{ "nonewdcop", I18N_NOOP("Use existing DCOP server"), 0},
55
{ "comment <dialog text>", I18N_NOOP("The comment that should be displayed in the dialog"), 0},
56
{ "noignorebutton", I18N_NOOP("Do not display « ignore » button"), 0 },
57
{ "+command", I18N_NOOP("The command to execute"), 0 },
61
38
int main(int argc, char **argv)
63
KAboutData aboutData("kdesudo", I18N_NOOP("KdeSudo"),
64
VERSION, description, KAboutData::License_GPL,
65
"(c) 2007-2008, Anthony Mercatante", 0, 0, "tonio@ubuntu.com");
66
aboutData.addAuthor("Robert Gruber",0, "rgruber@users.sourceforge.net");
67
aboutData.addAuthor("Anthony Mercatante",0, "tonio@ubuntu.com");
68
KCmdLineArgs::init(argc, argv, &aboutData);
69
KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
41
"kdesudo", 0, ki18n("KdeSudo"),
42
"3.1", ki18n("Sudo frontend for KDE"),
43
KAboutData::License_GPL,
44
ki18n("(C) 2007 - 2008 Anthony Mercatante"),
46
"https://code.launchpad.net/kdesudo/");
48
about.addAuthor(ki18n("Robert Gruber"), KLocalizedString(),
49
"rgruber@users.sourceforge.net","http://test.com" );
50
about.addAuthor(ki18n("Anthony Mercatante"), KLocalizedString(),
52
about.addAuthor(ki18n("Martin Böhm"), KLocalizedString(),
53
"martin.bohm@kubuntu.org");
54
about.addAuthor(ki18n("Jonathan Riddell"), KLocalizedString(),
55
"jriddell@ubuntu.com");
57
KCmdLineArgs::init(argc, argv, &about);
59
KCmdLineOptions options;
60
options.add("u <runas>", ki18n("sets a runas user"));
61
options.add("c <command>", ki18n("The command to execute"));
62
options.add("s", ki18n("Forget passwords"));
63
options.add("i <icon name>", ki18n("Specify icon to use in the password"
65
options.add("d", ki18n("Do not show the command to be run in the dialog"));
66
options.add("p <priority>", ki18n("Process priority, between 0 and 100,"
67
" 0 the lowest [50]"));
68
options.add("r", ki18n("Use realtime scheduling"));
69
options.add("f <file>", ki18n("Use target UID if <file> is not writeable"));
70
options.add("t", ki18n("Fake option for KDE's KdeSu compatibility"));
71
options.add("n", ki18n("Do not keep password"));
72
options.add("nonewdcop", ki18n("Use existing DCOP server"));
73
options.add("comment <dialog text>", ki18n("The comment that should be "
74
"displayed in the dialog"));
75
options.add("noignorebutton", ki18n("Do not display « ignore » button"));
76
options.add("+command", ki18n("The command to execute"));
77
KCmdLineArgs::addCmdLineOptions( options );
71
79
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
79
87
QStringList commandlist;
82
bool withIgnoreButton = args->isSet("ignorebutton");
84
90
if (args->isSet("c"))
85
91
executable = args->getOption("c");
89
96
if (executable.isEmpty())
91
98
command = args->arg(0);
92
commandlist = QStringList::split(QChar(' '), command);
99
commandlist = command.split(" ");
93
100
executable = commandlist[0];
97
104
/* We have to make sure the executable is only the binary name */
98
executableList = QStringList::split(" ", executable);
105
executableList = executable.split(" ");
99
106
executable = executableList[0];
101
executableList = QStringList::split("/", executable);
108
executableList = executable.split("/");
102
109
int i = executableList.count() - 1;
103
110
executable = executableList[i];
105
112
/* Kubuntu has a bug in it - this is a workaround for it */
106
113
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde");
114
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde4");
107
115
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications");
109
QString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
110
KDesktopFile desktopFile(deskFilePath,true);
116
KGlobal::dirs()->addResourceDir("apps","/usr/share/applnk");
118
QString path = getenv("PATH");
119
QStringList pathList = path.split(":");
120
for (int i = 0; i < pathList.count(); i++)
122
executable.remove(pathList[i]);
125
QString deskFilePath = KGlobal::dirs()->findResource("apps", executable + ".desktop");
127
KDesktopFile desktopFile(deskFilePath);
112
129
/* icon parsing */
113
130
if (args->isSet("i"))
117
134
QString iconName = desktopFile.readIcon();
118
icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true);
135
KIconLoader *loader = KIconLoader::global();
136
icon = loader->iconPath(iconName, -1 * KIconLoader::StdSizes(
137
KIconLoader::SizeHuge), true);
121
140
/* generic name parsing */
122
141
QString name = desktopFile.readName();
123
QString genericName = desktopFile.readGenericName();
127
if (!genericName.isEmpty())
128
name += " - " + genericName;
130
else if (!genericName.isEmpty())
133
KdeSudo *kdesudo = new KdeSudo(0,0,icon,name,withIgnoreButton);
135
a.setMainWidget(kdesudo);
143
a.setQuitOnLastWindowClosed( false );
144
KdeSudo kdesudo(icon,name);