[PC-BSD Commits] r13027 - in pcbsd/current/src-qt4/pc-controlpanel: . images

svn at pcbsd.org svn at pcbsd.org
Wed Sep 28 09:40:28 PDT 2011


Author: yurkis
Date: 2011-09-28 09:40:28 -0700 (Wed, 28 Sep 2011)
New Revision: 13027

Added:
   pcbsd/current/src-qt4/pc-controlpanel/images/object-locked.png
   pcbsd/current/src-qt4/pc-controlpanel/images/security-medium.png
Modified:
   pcbsd/current/src-qt4/pc-controlpanel/controlpanel.qrc
   pcbsd/current/src-qt4/pc-controlpanel/grouplist.cpp
   pcbsd/current/src-qt4/pc-controlpanel/grouplist.h
   pcbsd/current/src-qt4/pc-controlpanel/item.cpp
   pcbsd/current/src-qt4/pc-controlpanel/item.h
   pcbsd/current/src-qt4/pc-controlpanel/mainwnd.cpp
   pcbsd/current/src-qt4/pc-controlpanel/mainwnd.h
Log:
Some improvments to controlpanel (merge from assembla repo):
1. Detect items that need sudo or pc-su
2. Dont display items that requires sudo or pc-su if user is not in 'wheel' or 'operator' group
3. Visual mark items that requires root password to run
4. Force icons to 64x64 size

Modified: pcbsd/current/src-qt4/pc-controlpanel/controlpanel.qrc
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/controlpanel.qrc	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/controlpanel.qrc	2011-09-28 16:40:28 UTC (rev 13027)
@@ -9,5 +9,7 @@
         <file>images/xfce.png</file>
         <file>images/all_desktops.png</file>
         <file>images/unsupported_de.png</file>
+        <file>images/security-medium.png</file>
+        <file>images/object-locked.png</file>
     </qresource>
 </RCC>

Modified: pcbsd/current/src-qt4/pc-controlpanel/grouplist.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/grouplist.cpp	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/grouplist.cpp	2011-09-28 16:40:28 UTC (rev 13027)
@@ -27,11 +27,18 @@
 #include <QDir>
 #include <QSizePolicy>
 #include <QLayout>
+#include <QPainter>
 
+#include <iostream>
+
+const int ICON_DIM = 64;
+const char* const ROOT_PICTURE = ":/images/images/security-medium.png";
+//const char* const ROOT_IMAGE[] = ":/images/images/object-locked.png";
+
 QGroupList::QGroupList(QWidget *parent) :
     QAutoExpandList(parent)
 {
-	setIconSize(QSize(64, 64));
+        setIconSize(QSize(ICON_DIM, ICON_DIM));
 	setViewMode(QListView::IconMode);
 	setWordWrap(true);
 	setFrameStyle(QFrame::NoFrame);
@@ -39,7 +46,7 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-int QGroupList::read(QString Path, const QVector<QString>& vEnabledDE)
+int QGroupList::read(QString Path, const QVector<QString>& vEnabledDE, bool EnableSudo, bool EnableSu)
 {
 	clear();
 	QDir dir(Path);
@@ -52,7 +59,18 @@
 		QCPItem* anItem = new QCPItem;
 
                 if (anItem->read(dir.absoluteFilePath(DirList[i]), vEnabledDE))
-			addItem(anItem);
+                {
+                    if ((anItem->isSudoRequired() && (!EnableSudo))
+                      ||(anItem->isRootRequired() && (!EnableSu)))
+                    {
+                        delete anItem;
+                    }
+                    else
+                    {
+                        makeIcon(anItem);
+                        addItem(anItem);
+                    }
+                }
 		else
 			delete anItem;
 	}// for all files in dir
@@ -65,6 +83,29 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+void QGroupList::makeIcon(QCPItem* anItem)
+{
+
+    QPixmap orig(ICON_DIM, ICON_DIM);
+
+    QPixmap pix;
+    orig.fill(Qt::transparent);
+
+    QPainter painter(&orig);
+
+    painter.drawPixmap(0, 0, ICON_DIM, ICON_DIM, anItem->icon().pixmap(ICON_DIM));
+
+    if ( anItem->isRootRequired() && pix.load(ROOT_PICTURE) )
+    {
+
+        painter.drawPixmap(orig.width() - pix.width(), 0 , pix);
+        anItem->setIcon(QIcon(orig));
+    }
+
+    anItem->setIcon(QIcon(orig));
+}
+
+///////////////////////////////////////////////////////////////////////////////
 void QGroupList::focusOutEvent ( QFocusEvent * event )
 {
 	QListWidget::focusOutEvent( event);

Modified: pcbsd/current/src-qt4/pc-controlpanel/grouplist.h
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/grouplist.h	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/grouplist.h	2011-09-28 16:40:28 UTC (rev 13027)
@@ -36,7 +36,8 @@
     explicit QGroupList(QWidget *parent = 0);
 
 	//! Read category list
-        int read(QString Path, const QVector<QString>& vEnabledDE);
+        int read(QString Path, const QVector<QString>& vEnabledDE,
+                 bool EnableSudo=true, bool EnableSu=true);
 
 	//! Set name filter string
         bool setFilter(const QString& filetrString);
@@ -45,6 +46,7 @@
 
 protected:
 	virtual void focusOutEvent ( QFocusEvent * event );
+        void makeIcon(QCPItem* anItem);
 
 signals:
 


Property changes on: pcbsd/current/src-qt4/pc-controlpanel/images/object-locked.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream


Property changes on: pcbsd/current/src-qt4/pc-controlpanel/images/security-medium.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: pcbsd/current/src-qt4/pc-controlpanel/item.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/item.cpp	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/item.cpp	2011-09-28 16:40:28 UTC (rev 13027)
@@ -49,7 +49,10 @@
 const QString DEFAULT_ICON_LOCATION = PREFIX + "/share/pcbsd/pc-controlpanel/icons/";
 const char* const DEFAULT_ICON = "preferences-other.png";
 
-QCPItem::QCPItem():misValid(false), misMsgBox(false)
+const QString SU_NAMES[] = {QString("pc-su "), QString("kdesu "), QString("gtksu ")};
+const QString SUDO_COMMAND("sudo ");
+
+QCPItem::QCPItem():misValid(false), misMsgBox(false), isRequireRoot(false),isSudo(false)
 {
 }
 
@@ -234,6 +237,23 @@
         misMsgBox= false;
     }
 
+    // Check if item require root access
+    isRequireRoot = false;
+    QString tmp = mExecCommand.trimmed();
+
+    for (unsigned int i=0; i<sizeof(SU_NAMES)/sizeof(QString); i++ )
+    {
+        if (tmp.left(SU_NAMES[i].size()) == SU_NAMES[i])
+        {
+            isRequireRoot = true;
+            break;
+        }
+    }
+
+    isSudo = false;
+    if (tmp.left(SUDO_COMMAND.size()) == SUDO_COMMAND)
+        isSudo = true;
+
     misValid= true;
     mFileName= FileName;
 

Modified: pcbsd/current/src-qt4/pc-controlpanel/item.h
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/item.h	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/item.h	2011-09-28 16:40:28 UTC (rev 13027)
@@ -77,6 +77,11 @@
           */
         QString itemOriginalName() {return mOriginalName;};
 
+
+        bool isSudoRequired() {return isSudo;}
+
+        bool isRootRequired() {return isRequireRoot;}
+
 protected:
         QString mName;
         QString mOriginalName;
@@ -92,7 +97,9 @@
 	bool    misXDGLaunch;
         QString mRequiredDE;
 	bool    misSubstFound;
-        QVector<QString> mvEnabledDE;        
+        QVector<QString> mvEnabledDE;
+        bool isRequireRoot;
+        bool isSudo;
 
 	bool getLocalizedField(const QSettings& Reader,
                                const QString& FieldName,

Modified: pcbsd/current/src-qt4/pc-controlpanel/mainwnd.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/mainwnd.cpp	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/mainwnd.cpp	2011-09-28 16:40:28 UTC (rev 13027)
@@ -27,7 +27,9 @@
 #include "deinfo.h"
 #include "../config.h"
 
+#include <QFile>
 
+
 #define ITEMS_PREFIX   PREFIX + "/share/pcbsd/pc-controlpanel/items/"
 #define SOFTWARE_DIR   ITEMS_PREFIX + "software"
 #define SYSTEM_DIR     ITEMS_PREFIX + "system"
@@ -46,6 +48,10 @@
     ui(new Ui::MainWnd)
 {
     ui->setupUi(this);
+
+    misWheelGroup= checkUserGroup("wheel");
+    misOperatorGroup = checkUserGroup("operator");
+
     setupGroups();
 
     InstalledDEList.refresh();
@@ -96,12 +102,13 @@
 ///////////////////////////////////////////////////////////////////////////////
 void MainWnd::setupGroups()
 {
-	setupGroup(&SoftwareList, ui->SoftwareGBox);
-	setupGroup(&SystemList, ui->SystemGBox);
-	setupGroup(&HardwareList, ui->HardwareGBox);
-	setupGroup(&NetworkingList, ui->NetworkingGBox);
-	setupGroup(&ToolsList, ui->ToolsGBox);
-	setupGroup(&DEList, ui->DEGBox);
+
+    setupGroup(&SoftwareList, ui->SoftwareGBox);
+    setupGroup(&SystemList, ui->SystemGBox);
+    setupGroup(&HardwareList, ui->HardwareGBox);
+    setupGroup(&NetworkingList, ui->NetworkingGBox);
+    setupGroup(&ToolsList, ui->ToolsGBox);
+    setupGroup(&DEList, ui->DEGBox);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -123,30 +130,32 @@
         ui->statusBar->showMessage(tr("Reading items..."));
         QApplication::processEvents();
 
+        bool isSu = misWheelGroup || misOperatorGroup;
+        bool isSudo = misWheelGroup || misOperatorGroup;
 
         InstalledPBIs.refresh();        
 
-        isVisible = (bool)SoftwareList->read(SOFTWARE_DIR, mvEnabledDE);
+        isVisible = (bool)SoftwareList->read(SOFTWARE_DIR, mvEnabledDE, isSudo, isSu);
 	ui->SoftwareGBox->setVisible(isVisible);
 	ui->SoftwareLine->setVisible(isVisible);
 
-        isVisible = (bool)SystemList->read(SYSTEM_DIR, mvEnabledDE);
+        isVisible = (bool)SystemList->read(SYSTEM_DIR, mvEnabledDE, isSudo, isSu);
 	ui->SystemGBox->setVisible(isVisible);
 	ui->SystemLine->setVisible(isVisible);
 
-        isVisible = (bool)HardwareList->read(HARDWARE_DIR, mvEnabledDE);
+        isVisible = (bool)HardwareList->read(HARDWARE_DIR, mvEnabledDE, isSudo, isSu);
 	ui->HardwareGBox->setVisible(isVisible);
 	ui->HardwareLine->setVisible(isVisible);
 
-        isVisible = (bool)NetworkingList->read(NETWORKING_DIR, mvEnabledDE);
+        isVisible = (bool)NetworkingList->read(NETWORKING_DIR, mvEnabledDE, isSudo, isSu);
 	ui->NetworkingGBox->setVisible(isVisible);
 	ui->NetworkingLine->setVisible(isVisible);
 
-        isVisible = (bool)ToolsList->read(TOOLS_DIR, mvEnabledDE);
+        isVisible = (bool)ToolsList->read(TOOLS_DIR, mvEnabledDE, isSudo, isSu);
 	ui->ToolsGBox->setVisible(isVisible);
 	ui->ToolsLine->setVisible(isVisible);
 
-        isVisible = (bool)DEList->read(DE_DIR, mvEnabledDE);
+        isVisible = (bool)DEList->read(DE_DIR, mvEnabledDE, isSudo, isSu);
         ui->DEGBox->setVisible(isVisible);
         ui->DELine->setVisible(isVisible);
 
@@ -389,3 +398,32 @@
     //Refresh if items or installed pbis dir was changed
     on_toolButton_2_clicked();
 }
+
+///////////////////////////////////////////////////////////////////////////////
+bool MainWnd::checkUserGroup(QString groupName)
+{
+   QString loginName = getlogin();
+   QStringList gNames;
+   if ( loginName == "root" )
+     return true;
+
+   QString tmp;
+   QFile iFile("/etc/group");
+   if ( ! iFile.open(QIODevice::ReadOnly | QIODevice::Text))
+     return true; //or FALSE?
+                
+   while ( !iFile.atEnd() ) {
+     tmp = iFile.readLine().simplified();
+     if ( tmp.indexOf(groupName) == 0 ) {
+	gNames = tmp.section(":", 3, 3).split(",");
+	break;
+     }
+   }
+   iFile.close();
+        
+   for ( int i = 0; i < gNames.size(); ++i )
+      if ( gNames.at(i).indexOf(loginName) == 0 )
+            return true;
+
+   return false;
+}

Modified: pcbsd/current/src-qt4/pc-controlpanel/mainwnd.h
===================================================================
--- pcbsd/current/src-qt4/pc-controlpanel/mainwnd.h	2011-09-28 15:38:38 UTC (rev 13026)
+++ pcbsd/current/src-qt4/pc-controlpanel/mainwnd.h	2011-09-28 16:40:28 UTC (rev 13027)
@@ -65,6 +65,8 @@
 	void fillGroups();
         void setupDEChooser();
 
+        bool checkUserGroup(QString groupName);
+
         //CDEList mDEList;
         QMenu* DEChoiseMenu;
 
@@ -72,6 +74,9 @@
         CDEInfo          mCurrentDE;
         bool             misDisplayDEName;
 
+        bool             misWheelGroup;
+        bool             misOperatorGroup;
+
 private slots:
         void on_actionUnsupported_triggered();
         void on_actionXFCE_triggered();



More information about the Commits mailing list