[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: patch: kdesu "--comment" override
From: Ryan Zeigler <zeiglerr () gmail ! com>
Date: 2007-05-29 13:09:50
Message-ID: 200705290909.51071.zeiglerr () gmail ! com
[Download RAW message or body]
Hello all,
This is my first post to the list, but I was just messing around in kdebase
and I felt that this might be useful for kdesu. It adds a comment argument to
the kdesu program that can override what is displayed in the dialog box. I
hope this is useful. Sincerely,
Ryan Zeigler
["kdesu_friendlierUI.diff" (text/x-diff)]
diff -Naur kdebase-3.5.6orig/kdesu/kdesu/kdesu.cpp \
kdebase-3.5.6/kdesu/kdesu/kdesu.cpp
--- kdebase-3.5.6orig/kdesu/kdesu/kdesu.cpp 2006-05-22 14:13:07.000000000 -0400
+++ kdebase-3.5.6/kdesu/kdesu/kdesu.cpp 2007-05-28 20:17:41.000000000 -0400
@@ -20,6 +20,7 @@
#endif
#include <qstring.h>
+#include <qtextcodec.h>
#include <qfileinfo.h>
#include <qglobal.h>
#include <qfile.h>
@@ -66,6 +67,7 @@
{ "noignorebutton", I18N_NOOP("Do not display ignore button"), 0 },
{ "i <icon name>", I18N_NOOP("Specify icon to use in the password dialog"), 0},
{ "d", I18N_NOOP("Do not show the command to be run in the dialog"), 0},
+ { "comment <dialog text>", I18N_NOOP("The comment that should be displayed in \
the dialog"), 0}, KCmdLineLastOption
};
@@ -114,7 +116,7 @@
KApplication app;
// but propagate it to the started app
setenv( "SESSION_MANAGER", session_manager.data(), 1 );
-
+
{
KStartupInfoId id;
id.initId( kapp->startupId());
@@ -154,7 +156,7 @@
QString icon;
if ( args->isSet("i"))
- icon = args->getOption("i");
+ icon = args->getOption("i");
bool prompt = true;
if ( args->isSet("d"))
@@ -225,7 +227,7 @@
command += QFile::encodeName(arg);
}
}
- else
+ else
{
if( args->count() == 0 )
{
@@ -274,20 +276,20 @@
bool terminal = args->isSet("t");
bool new_dcop = args->isSet("newdcop");
bool withIgnoreButton = args->isSet("ignorebutton");
-
+
QCStringList env;
QCString options;
env << ( "DESKTOP_STARTUP_ID=" + kapp->startupId());
-
+
if (pw->pw_uid)
{
// Only propagate KDEHOME for non-root users,
// root uses KDEROOTHOME
-
+
// Translate the KDEHOME of this user to the new user.
QString kdeHome = KGlobal::dirs()->relativeLocation("home", \
KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/')
- kdeHome.prepend("~/");
+ kdeHome.prepend("~/");
else
kdeHome=QString::null; // Use default
@@ -296,7 +298,7 @@
KUser u;
env << (QCString) ("KDESU_USER=" + u.loginName().local8Bit());
-
+
if (!new_dcop)
{
QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("cache", \
"ksycoca")); @@ -357,7 +359,13 @@
KStartupInfoData data;
data.setSilent( KStartupInfoData::Yes );
KStartupInfo::sendChange( id, data );
- KDEsuDialog dlg(user, auth_user, keep && !terminal,icon, withIgnoreButton);
+
+ /* Get the comment out of cli args */
+ QByteArray commentBytes = args->getOption("comment");
+ QTextCodec* tCodecConv = QTextCodec::codecForLocale();
+ QString commentArg = tCodecConv->toUnicode(commentBytes, \
commentBytes.size()); + KDEsuDialog dlg(user, auth_user, keep && !terminal, \
icon, withIgnoreButton, command, commentArg); +
if (prompt)
dlg.addLine(i18n("Command:"), command);
if ((priority != 50) || (scheduler != SuProcess::SchedNormal))
diff -Naur kdebase-3.5.6orig/kdesu/kdesu/sudlg.cpp \
kdebase-3.5.6/kdesu/kdesu/sudlg.cpp
--- kdebase-3.5.6orig/kdesu/kdesu/sudlg.cpp 2006-10-05 12:25:15.000000000 -0400
+++ kdebase-3.5.6/kdesu/kdesu/sudlg.cpp 2007-05-28 19:01:12.000000000 -0400
@@ -14,7 +14,7 @@
#include <kdesu/su.h>
#include "sudlg.h"
-KDEsuDialog::KDEsuDialog(QCString user, QCString auth_user, bool enableKeep,const \
QString& icon, bool withIgnoreButton) +KDEsuDialog::KDEsuDialog(QCString user, \
QCString auth_user, bool enableKeep, const QString& icon, bool withIgnoreButton, \
const QString& command, const QString& comment)
: KPasswordDialog(Password, enableKeep, (withIgnoreButton ? User1:NoDefault), \
icon) {
KConfig* config = KGlobal::config();
@@ -28,19 +28,36 @@
m_User = auth_user;
setCaption(i18n("Run as %1").arg(user));
+ QString defaultSudoComment = i18n("<b>%1</b> needs administrative privileges. \
Please enter your password." ); + QString defaultRootComment = i18n("<b>%1</b> \
needs root privileges. Please enter root's password below or click ignore to continue \
with your current privileges."); + QString defaultUserComment = i18n("<b>%1</b> \
needs additional privileges. Please enter %2's password below or click ignore to \
continue with your current privileges."); +
QString prompt;
+ QString strippedCommand = command;
+ int i;
+ if((i = strippedCommand.find(' ')) > 0) {
+ strippedCommand.truncate(i + 1);
+ }
if (superUserCommand == "sudo" && m_User == "root") {
- prompt = i18n("Please enter your password." );
+ if(comment.isEmpty()) {
+ prompt = defaultSudoComment.arg(strippedCommand);
+ } else {
+ prompt = comment;
+ }
} else {
if (m_User == "root") {
- prompt = i18n("The action you requested needs root privileges. "
- "Please enter root's password below or click "
- "Ignore to continue with your current privileges.");
+ if(comment.isEmpty()) {
+ prompt = defaultRootComment.arg(strippedCommand);
+ } else {
+ prompt = comment;
+ }
} else {
- prompt = i18n("The action you requested needs additional privileges. "
- "Please enter the password for \"%1\" below or click "
- "Ignore to continue with your current privileges.").arg(m_User);
- }
+ if(comment.isEmpty()) {
+ prompt = defaultUserComment.arg(strippedCommand).arg(m_User);
+ } else {
+ prompt = comment;
+ }
+ }
}
setPrompt(prompt);
diff -Naur kdebase-3.5.6orig/kdesu/kdesu/sudlg.h kdebase-3.5.6/kdesu/kdesu/sudlg.h
--- kdebase-3.5.6orig/kdesu/kdesu/sudlg.h 2006-05-22 14:13:07.000000000 -0400
+++ kdebase-3.5.6/kdesu/kdesu/sudlg.h 2007-05-28 18:54:26.000000000 -0400
@@ -15,18 +15,18 @@
Q_OBJECT
public:
- KDEsuDialog(QCString user, QCString auth_user, bool enableKeep, const QString& \
icon , bool withIgnoreButton=false); + KDEsuDialog(QCString user, QCString \
auth_user, bool enableKeep, const QString& icon , bool withIgnoreButton=false, const \
QString& command = "", const QString& comment = ""); ~KDEsuDialog();
enum ResultCodes { AsUser = 10 };
-
+
protected:
bool checkPassword(const char *password);
void slotUser1();
-
+
private:
QCString m_User;
};
-
+
#endif // __SuDlg_h_Included__
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic