From kde-devel Tue May 29 13:09:50 2007 From: Ryan Zeigler Date: Tue, 29 May 2007 13:09:50 +0000 To: kde-devel Subject: patch: kdesu "--comment" override Message-Id: <200705290909.51071.zeiglerr () gmail ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=118044447700389 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_fYCXGkBwdWM0ajt" --Boundary-00=_fYCXGkBwdWM0ajt Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_fYCXGkBwdWM0ajt Content-Type: text/x-diff; charset="us-ascii"; name="kdesu_friendlierUI.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kdesu_friendlierUI.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 +#include #include #include #include @@ -66,6 +67,7 @@ { "noignorebutton", I18N_NOOP("Do not display ignore button"), 0 }, { "i ", 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 ", 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 #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("%1 needs administrative privileges. Please enter your password." ); + QString defaultRootComment = i18n("%1 needs root privileges. Please enter root's password below or click ignore to continue with your current privileges."); + QString defaultUserComment = i18n("%1 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__ --Boundary-00=_fYCXGkBwdWM0ajt Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --Boundary-00=_fYCXGkBwdWM0ajt--