Blob Blame History Raw
diff -ur kdebase-workspace-4.0.72/systemsettings/mainwindow.cpp kdebase-workspace-4.0.72-rootprivs/systemsettings/mainwindow.cpp
--- kdebase-workspace-4.0.72/systemsettings/mainwindow.cpp	2008-04-30 15:58:34.000000000 +0200
+++ kdebase-workspace-4.0.72-rootprivs/systemsettings/mainwindow.cpp	2008-05-07 01:05:14.000000000 +0200
@@ -27,6 +27,7 @@
 
 #include <QLayout>
 #include <QStackedWidget>
+#include <QProcess>
 
 #include <KAction>
 #include <KActionCollection>
@@ -42,6 +43,7 @@
 #include <KStandardAction>
 #include <KTabWidget>
 #include <kcategorizedsortfilterproxymodel.h>
+#include <KStandardDirs>
 #include <kcategorizedview.h>
 #include <kcategorydrawer.h>
 #include <kiconloader.h>
@@ -297,9 +299,13 @@
         return;
 
     MenuItem * mItem = selected.data( Qt::UserRole ).value<MenuItem*>();
+    bool needsRootPrivs = false;
     if ( mItem ) {
         kDebug() << "Selected item: " << mItem->service->name();
         kDebug() << "Comment:       " << mItem->service->comment();
+
+        needsRootPrivs = mItem->service->property( "X-KDE-RootOnly", QVariant::Bool ).toBool();
+        kDebug() << "Needs root privs:" << needsRootPrivs;
     } else {
         kDebug() << ":'( Got dud pointer from " << selected.data( Qt::DisplayRole ).toString();
         Q_ASSERT(mItem); // Would core dump below. Do it now
@@ -311,6 +317,35 @@
     if ( groupWidget )
         return;
 
+    if ( needsRootPrivs )
+    {
+        QString kdesu = KStandardDirs::findExe( "kdesu" );
+        //kDebug() << "kdesu path:" << kdesu;
+
+        QString cmd = mItem->service->exec().trimmed();
+
+        /* Prepare the process to run the kcmshell */
+        if ( cmd.left(5) == "kdesu" )
+        {
+            cmd = cmd.remove(0,5).trimmed();
+
+            /* Remove all kdesu switches */
+            while ( cmd.length() > 1 && cmd[ 0 ] == '-' )
+                cmd = cmd.remove( 0, cmd.indexOf( ' ' ) ).trimmed();
+        }
+
+        if ( cmd.left(9) == "kcmshell4" )
+            cmd = cmd.remove(0,9).trimmed();
+
+        QStringList args;
+        args << "-c" << QString( "%1 %2 --lang %3" ).arg( KStandardDirs::locate("exe", "kcmshell4") ).arg( cmd ).arg( KGlobal::locale()->language() );
+
+        kDebug() << "Starting root module: " << args;
+        QProcess::execute( kdesu, args );
+
+        return;
+    }
+
     groupWidget = moduleItemToWidgetDict[mItem->service];
 
     if( !groupWidget ) {