~ubuntu-branches/ubuntu/vivid/kdesudo/vivid

« back to all changes in this revision

Viewing changes to kdesudo/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2008-07-16 17:08:30 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20080716170830-bem298ajm207fua9
Tags: 3.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
                          kdesudo.cpp  -  description
3
3
                             -------------------
4
4
    begin                : Sam Feb 15 15:42:12 CET 2003
5
 
    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
 
5
    copyright            : (C) 2003 by Robert Gruber 
 
6
                                       <rgruber@users.sourceforge.net>
6
7
                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
7
8
                                       Anthony Mercatante <tonio@kubuntu.org>
8
 
                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
 
9
                                       Canonical Ltd (Jonathan Riddell 
 
10
                                                      <jriddell@ubuntu.com>)
9
11
 
10
12
 ***************************************************************************/
11
13
 
18
20
 *                                                                         *
19
21
 ***************************************************************************/
20
22
 
21
 
#include <kcmdlineargs.h>
22
 
#include <kaboutdata.h>
23
 
#include <klocale.h>
 
23
#include <KCmdLineArgs>
 
24
#include <KAboutData>
 
25
#include <KLocale>
 
26
#include <KMessageBox>
 
27
#include <KDesktopFile>
 
28
#include <KIconLoader>
 
29
#include <KIconTheme>
 
30
#include <KGlobal>
 
31
#include <KStandardDirs>
 
32
#include <KProcess>
 
33
#include <KDebug>
 
34
#include <KApplication>
24
35
 
25
36
#include "kdesudo.h"
26
 
#include <kmessagebox.h>
27
 
#include <kdesktopfile.h>
28
 
#include <kiconloader.h>
29
 
#include <kicontheme.h>
30
 
#include <kglobal.h>
31
 
#include <kstandarddirs.h>
32
 
#include <kprocess.h>
33
 
#include <kdebug.h>
34
 
#include <qfile.h>
35
 
#include <qfileinfo.h>
36
 
 
37
 
static const char *description =
38
 
        I18N_NOOP("KdeSudo");
39
 
// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
40
 
        
41
 
        
42
 
static KCmdLineOptions options[] =
43
 
{
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 },
58
 
        KCmdLineLastOption
59
 
};
60
37
 
61
38
int main(int argc, char **argv)
62
39
{
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.
 
40
        KAboutData about(
 
41
                "kdesudo", 0, ki18n("KdeSudo"),
 
42
                "3.1", ki18n("Sudo frontend for KDE"),
 
43
                KAboutData::License_GPL,
 
44
                ki18n("(C) 2007 - 2008 Anthony Mercatante"),
 
45
                KLocalizedString(),
 
46
                "https://code.launchpad.net/kdesudo/");
 
47
 
 
48
        about.addAuthor(ki18n("Robert Gruber"), KLocalizedString(), 
 
49
                "rgruber@users.sourceforge.net","http://test.com" );
 
50
        about.addAuthor(ki18n("Anthony Mercatante"), KLocalizedString(), 
 
51
                "tonio@ubuntu.com");
 
52
        about.addAuthor(ki18n("Martin Böhm"), KLocalizedString(),
 
53
                "martin.bohm@kubuntu.org");
 
54
        about.addAuthor(ki18n("Jonathan Riddell"), KLocalizedString(),
 
55
                "jriddell@ubuntu.com");
 
56
 
 
57
        KCmdLineArgs::init(argc, argv, &about);
 
58
 
 
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"
 
64
                                       " dialog"));
 
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 );
70
78
 
71
79
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
72
80
 
79
87
        QStringList commandlist;
80
88
        QString icon;
81
89
 
82
 
        bool withIgnoreButton = args->isSet("ignorebutton");
83
 
 
84
90
        if (args->isSet("c"))
85
91
                executable = args->getOption("c");
86
92
 
 
93
 
87
94
        if (args->count())
88
95
        {
89
96
                if (executable.isEmpty())
90
97
                {
91
98
                        command = args->arg(0);
92
 
                        commandlist = QStringList::split(QChar(' '), command);
 
99
                        commandlist = command.split(" ");
93
100
                        executable = commandlist[0];
94
101
                }
95
102
        }
96
103
 
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];
100
107
 
101
 
        executableList = QStringList::split("/", executable);
 
108
        executableList = executable.split("/");
102
109
        int i = executableList.count() - 1;
103
110
        executable = executableList[i];
104
111
 
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");
108
 
 
109
 
        QString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
110
 
        KDesktopFile desktopFile(deskFilePath,true);
 
116
        KGlobal::dirs()->addResourceDir("apps","/usr/share/applnk");
 
117
 
 
118
        QString path = getenv("PATH");
 
119
        QStringList pathList = path.split(":");
 
120
        for (int i = 0; i < pathList.count(); i++)
 
121
        {
 
122
                executable.remove(pathList[i]);
 
123
        }
 
124
 
 
125
        QString deskFilePath = KGlobal::dirs()->findResource("apps", executable + ".desktop");
 
126
 
 
127
        KDesktopFile desktopFile(deskFilePath);
111
128
 
112
129
        /* icon parsing */
113
130
        if (args->isSet("i"))
115
132
        else
116
133
        {
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);
119
138
        }
120
139
 
121
140
        /* generic name parsing */
122
141
        QString name = desktopFile.readName();
123
 
        QString genericName = desktopFile.readGenericName();
124
 
 
125
 
        if (!name.isEmpty())
126
 
        {
127
 
                if (!genericName.isEmpty())
128
 
                name += " - " + genericName;
129
 
        }
130
 
        else if (!genericName.isEmpty())
131
 
                name = genericName;
132
 
 
133
 
        KdeSudo *kdesudo = new KdeSudo(0,0,icon,name,withIgnoreButton);
134
 
 
135
 
        a.setMainWidget(kdesudo);
136
 
        args->clear();
137
 
 
 
142
 
 
143
        a.setQuitOnLastWindowClosed( false );
 
144
        KdeSudo kdesudo(icon,name);
138
145
        return a.exec();
139
146
}