[PC-BSD Commits] r17960 - in pcbsd-projects/PCDM: . images

svn at pcbsd.org svn at pcbsd.org
Thu Jul 26 11:24:09 PDT 2012


Author: kenmoore
Date: 2012-07-26 18:24:09 +0000 (Thu, 26 Jul 2012)
New Revision: 17960

Added:
   pcbsd-projects/PCDM/images/fluxbox.png
   pcbsd-projects/PCDM/images/gnome.png
   pcbsd-projects/PCDM/images/kde.png
   pcbsd-projects/PCDM/images/lxde.png
   pcbsd-projects/PCDM/images/nodesktop.png
   pcbsd-projects/PCDM/images/xfce.png
Modified:
   pcbsd-projects/PCDM/PCDM.qrc
   pcbsd-projects/PCDM/images/desktop.png
   pcbsd-projects/PCDM/pcdm-backend.cpp
   pcbsd-projects/PCDM/pcdm-backend.h
   pcbsd-projects/PCDM/pcdm-gui.cpp
Log:
Add the backend functionality to check for available xsession environments into PCDM. It appears to work well, but still getting a couple false positives where both the exec= and tryexec= files exist but are not usable.



Modified: pcbsd-projects/PCDM/PCDM.qrc
===================================================================
--- pcbsd-projects/PCDM/PCDM.qrc	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/PCDM.qrc	2012-07-26 18:24:09 UTC (rev 17960)
@@ -17,5 +17,11 @@
     <file>images/down.png</file>
     <file>images/left.png</file>
     <file>images/right.png</file>
+    <file>images/gnome.png</file>
+    <file>images/kde.png</file>
+    <file>images/xfce.png</file>
+    <file>images/lxde.png</file>
+    <file>images/fluxbox.png</file>
+    <file>images/nodesktop.png</file>
   </qresource>
 </RCC>

Modified: pcbsd-projects/PCDM/images/desktop.png
===================================================================
(Binary files differ)

Index: pcbsd-projects/PCDM/images/fluxbox.png
===================================================================
--- pcbsd-projects/PCDM/images/fluxbox.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/fluxbox.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/fluxbox.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: pcbsd-projects/PCDM/images/gnome.png
===================================================================
--- pcbsd-projects/PCDM/images/gnome.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/gnome.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/gnome.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: pcbsd-projects/PCDM/images/kde.png
===================================================================
--- pcbsd-projects/PCDM/images/kde.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/kde.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/kde.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: pcbsd-projects/PCDM/images/lxde.png
===================================================================
--- pcbsd-projects/PCDM/images/lxde.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/lxde.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/lxde.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: pcbsd-projects/PCDM/images/nodesktop.png
===================================================================
--- pcbsd-projects/PCDM/images/nodesktop.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/nodesktop.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/nodesktop.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Index: pcbsd-projects/PCDM/images/xfce.png
===================================================================
--- pcbsd-projects/PCDM/images/xfce.png	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/images/xfce.png	2012-07-26 18:24:09 UTC (rev 17960)

Property changes on: pcbsd-projects/PCDM/images/xfce.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
Modified: pcbsd-projects/PCDM/pcdm-backend.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.cpp	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/pcdm-backend.cpp	2012-07-26 18:24:09 UTC (rev 17960)
@@ -1,13 +1,36 @@
 #include "pcdm-backend.h"
+#include "pcdm-config.h"
 #include "pcbsd-utils.h"
 
-QStringList usernameList, displaynameList;
+QStringList displaynameList,usernameList,instXNameList,instXBinList,instXCommentList,instXIconList;
 
-QStringList Backend::getAvailableDesktops(){
-  qDebug() << "PCDM: Scanning for available desktop environments is not integrated yet";
-  return QStringList("");
+QStringList Backend::getAvailableDesktops(){  
+  if(instXNameList.isEmpty()){ loadXSessionsData(); }
+  QStringList out = instXNameList;
+  return out;
 }
 
+QString Backend::getDesktopComment(QString xName){
+  if(instXNameList.isEmpty()){ loadXSessionsData(); }
+  int index = instXNameList.indexOf(xName);
+  if(index == -1){ qDebug() << "PCDM: Invalid Desktop Name:" << xName; return ""; }
+  return instXCommentList[index];
+}
+
+QString Backend::getDesktopIcon(QString xName){
+  if(instXNameList.isEmpty()){ loadXSessionsData(); }
+  int index = instXNameList.indexOf(xName);
+  if(index == -1){ qDebug() << "PCDM: Invalid Desktop Name:" << xName; return ""; }
+  return instXIconList[index];
+}
+
+QString Backend::getDesktopBinary(QString xName){
+  if(instXNameList.isEmpty()){ loadXSessionsData(); }
+  int index = instXNameList.indexOf(xName);
+  if(index == -1){ qDebug() << "PCDM: Invalid Desktop Name:" << xName; return ""; }
+  return instXBinList[index];
+}
+
 QStringList Backend::getSystemUsers(){
   if(usernameList.isEmpty()){
     usernameList.clear(); displaynameList.clear(); //make sure the lists are empty
@@ -36,7 +59,101 @@
   return displaynameList;
 }
 
-QString getUsernameFromDisplayname(QString dspname){
+//****** PRIVATE FUNCTIONS ******
+QString Backend::getUsernameFromDisplayname(QString dspname){
   int i = displaynameList.indexOf(dspname);
   return usernameList[i];
 }
+
+void Backend::loadXSessionsData(){
+  //Clear the current variables
+  instXNameList.clear(); instXBinList.clear(); 
+  instXCommentList.clear(); instXIconList.clear();
+  //Load the default paths/locale
+  QString xDir = Config::xSessionsDir();
+  if(!xDir.endsWith("/")){ xDir.append("/"); }
+  QString xIconDir = Config::xSessionsImageDir();
+  if(!xIconDir.endsWith("/")){ xIconDir.append("/"); }
+  QString localeCode = QLocale().name(); //gets the current locale code
+  //Find all *.desktop files
+  QDir dir(xDir);
+  QStringList deFiles = dir.entryList(QDir::Files);
+  deFiles = deFiles.filter(".desktop"); //only get *.desktop files
+  //Read each file to see if that desktop is installed
+  for(int i=0; i<deFiles.length(); i++){
+    QStringList tmp = readXSessionsFile(xDir+deFiles[i],localeCode);
+    if(!tmp.isEmpty()){
+      //Complete file paths if necessary
+      if(!tmp[0].startsWith("/")){ tmp[0] = "/usr/local/bin/"+tmp[0]; }
+      if(tmp[3].isEmpty()){ tmp[3] = Theme::objectIconPath("desktop"); }
+      if(!tmp[3].startsWith("/")&&!tmp[3].startsWith(":")){ tmp[3] = xIconDir+tmp[3]; }
+      if(!tmp[4].startsWith("/")){ tmp[4] = "/usr/local/bin/"+tmp[4]; }
+      //Check for valid DE
+      if(QFile::exists(tmp[0]) && QFile::exists(tmp[4])){
+        //Add the DE to list of installed xsessions
+	instXBinList << tmp[0];
+	instXNameList << tmp[1];
+	instXCommentList << tmp[2];
+	//Check to make sure we have a valid icon
+	if( !QFile::exists(tmp[3]) ){
+          //Use the default Theme icon otherwise
+	  tmp[3] = Theme::objectIconPath("desktop");
+	}
+	instXIconList << tmp[3];
+	qDebug() << "PCDM: Found xsession:" << tmp;
+      }
+    }
+  }
+  if(instXNameList.isEmpty()){
+    //Create an entry so that we know this function has been run already
+    instXNameList << "None";
+    instXBinList << "none";
+    instXCommentList << "No xSession Environments available in" << xDir;
+    instXIconList << ":images/nodesktop.png";
+  }
+}
+
+QStringList Backend::readXSessionsFile(QString filePath, QString locale){
+//output: [Exec, Localized Name, Localized Comment, Icon, TryExec]
+  QString name, lname, comm, lcomm, icon, exec, tryexec;
+  QStringList output;
+  QString lna = "Name["+locale+"]"; //variable to look at for localized name
+  QString lco = "Comment["+locale+"]"; //variable to look at for localized comment
+  QFile file(filePath);
+  if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
+    QTextStream in(&file);
+    while (!in.atEnd()){
+      QString line = in.readLine().simplified();
+      QString var = line.section("=",0,0,QString::SectionSkipEmpty).simplified();
+      QString val = line.section("=",1,50,QString::SectionSkipEmpty).simplified();
+      if(var.toLower()=="exec"){ exec = val; }
+      else if(var.toLower()=="tryexec"){ tryexec = val; }
+      else if(var.toLower()=="icon"){ icon = val; }
+      else if(var.toLower()=="name"){ name = val; }
+      else if(var.toLower()=="comment"){ comm = val; }
+      else if(var==lna){ lname = val; }
+      else if(var==lco){ lcomm = val; }
+      else{} //do nothing with other lines
+
+    }
+  }
+  //Use the unlocalized name/comment if localized values not detected
+  if(lname.isEmpty()){ lname = name; }
+  if(lcomm.isEmpty()){ lcomm = comm; }
+  //Make sure that we have a name/exec for the session, otherwise invalid file
+  if(lname.isEmpty() || exec.isEmpty() || tryexec.isEmpty()){ return output; }
+  //Check that there is an icon given
+  if(icon.isEmpty()){
+    //Try to use a built in icon if a known DE
+    if(name.toLower().contains("gnome")){icon = ":images/gnome.png"; }
+    if(name.toLower().contains("kde")){icon = ":images/kde.png"; }
+    if(name.toLower().contains("xfce")){icon = ":images/xfce.png"; }
+    if(name.toLower().contains("lxde")){icon = ":images/lxde.png"; }
+    if(name.toLower().contains("fluxbox")){icon = ":images/fluxbox.png"; }
+  }
+  //Format the results into the output list
+  output.clear();
+  output << exec << lname << lcomm << icon << tryexec;
+  return output;
+
+}

Modified: pcbsd-projects/PCDM/pcdm-backend.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.h	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/pcdm-backend.h	2012-07-26 18:24:09 UTC (rev 17960)
@@ -8,14 +8,20 @@
 
 #include "pcdm-config.h"
 #include "pcbsd-utils.h"
+#include "pcdm-themes.h"
 
 class Backend {
 public:
     static QStringList getAvailableDesktops();
+    static QString getDesktopComment(QString);
+    static QString getDesktopIcon(QString);
+    static QString getDesktopBinary(QString);
     static QStringList getSystemUsers();
 
 private:
     static QString getUsernameFromDisplayname(QString);
+    static void loadXSessionsData();
+    static QStringList readXSessionsFile(QString, QString);
 
 };
 

Modified: pcbsd-projects/PCDM/pcdm-gui.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.cpp	2012-07-26 13:39:40 UTC (rev 17959)
+++ pcbsd-projects/PCDM/pcdm-gui.cpp	2012-07-26 18:24:09 UTC (rev 17960)
@@ -165,24 +165,21 @@
                       Theme::objectLocationColumnSpan("login"), Qt::AlignCenter); 
 
     //----Desktop Environment Switcher
-    //Get the available DE's
-    QStringList deList = Backend::getAvailableDesktops();
-    QStringList it, it2;
-    deList.clear();
-    deList << "kde" << "kde3";
-    it << "/home/kenmoore/Downloads/kde.png"<<"/home/kenmoore/Downloads/kde.png";
-    it2 << "KDE Desktop Environment" << "";
     //Create the switcher
     bool horizontalDE = TRUE;
     if(Theme::objectIconStyle("desktop") == "vertical"){ horizontalDE = FALSE; }
     deSwitcher = new FancySwitcher(this,horizontalDE);
-    deSwitcher->setIconSize(64);
+    QSize deSize = Theme::objectIconSize("desktop");
+    deSwitcher->setIconSize(deSize.height());
     deSwitcher->setStyleSheet(Theme::objectStyleSheet("desktop"));
     //Add the available desktops to the switcher
-    deSwitcher->addItems(deList,it,it2);
+    QStringList deList = Backend::getAvailableDesktops();
+    for(int i=0; i<deList.length(); i++){
+      deSwitcher->addItem( deList[i], Backend::getDesktopIcon(deList[i]), Backend::getDesktopComment(deList[i]) );
+    }
     //Set the switcher to the last used desktop environment
-    deSwitcher->setCurrentItem("kde3"); 
-    deSwitcher->changeButtonIcon("forward","/home/kenmoore/Downloads/kde.png");
+    //deSwitcher->setCurrentItem("kde3"); 
+    //deSwitcher->changeButtonIcon("forward","/home/kenmoore/Downloads/kde.png");
     grid->addWidget( deSwitcher, Theme::objectLocationRow("desktop"), \
                       Theme::objectLocationColumn("desktop"), \
                       Theme::objectLocationRowSpan("desktop"), \



More information about the Commits mailing list