[PC-BSD Commits] r19553 - pcbsd-projects/PCDM

svn at pcbsd.org svn at pcbsd.org
Thu Sep 27 08:48:47 PDT 2012


Author: kenmoore
Date: 2012-09-27 15:48:47 +0000 (Thu, 27 Sep 2012)
New Revision: 19553

Modified:
   pcbsd-projects/PCDM/main.cpp
   pcbsd-projects/PCDM/pcdm-backend.cpp
   pcbsd-projects/PCDM/pcdm-backend.h
   pcbsd-projects/PCDM/pcdm-xprocess.cpp
Log:
Switch over the autologin process to the new XProcess class to test it out.



Modified: pcbsd-projects/PCDM/main.cpp
===================================================================
--- pcbsd-projects/PCDM/main.cpp	2012-09-27 15:21:53 UTC (rev 19552)
+++ pcbsd-projects/PCDM/main.cpp	2012-09-27 15:48:47 UTC (rev 19553)
@@ -16,7 +16,7 @@
 
 int main(int argc, char *argv[])
 {
-  int returnCode;  
+  int returnCode = 0;  
   Backend::checkLocalDirs();  // Create and fill "/usr/local/share/PCDM" if needed
   Backend::openLogFile("/usr/local/share/PCDM/PCDM.log");  
   //Check for the flag to try and auto-login
@@ -40,15 +40,31 @@
   splash.show();
 
   //Initialize the xprocess
-  //XProcess desktop;
+  XProcess desktop;
   
   //*** STARTUP THE PROGRAM ***
+  bool goodAL = FALSE; //Flag for whether the autologin was successful
   
+  // Start the autologin procedure if applicable
   if( ALtriggered && Config::useAutoLogin() ){
     //Setup the Auto Login
-    Backend::startAutoLogin();
-    splash.close();
-  }else{
+    QString user = Backend::getALUsername();
+    QString dcmd = Backend::getALDesktopCmd();
+    if( user.isEmpty() || dcmd.isEmpty() ){
+	    
+    }else{
+	desktop.setXUsername(user);
+	desktop.setXCommand(dcmd);
+	desktop.setXHomeDir( Backend::getUserHomeDir(user) );
+	desktop.startXSession();
+	splash.close();
+	goodAL=TRUE; //flag this as a good login to skip the GUI
+    }
+    //Backend::startAutoLogin();
+    //splash.close();
+  }
+  
+  if(!goodAL){
     // ------START THE PCDM GUI-------
     
     // Check what directory our app is in
@@ -95,6 +111,7 @@
     w.show();
     splash.finish(&w);
     returnCode = a.exec();
+    Backend::startXSession();
   }  // end of PCDM GUI running
   
       /*
@@ -111,8 +128,8 @@
         break;
       }
       */
-  // Startup the desktop environment if possible
-  Backend::startXSession();
-  //desktop.waitForFinished();
+  //Wait for the desktop session to finish before exiting
+  desktop.waitForFinished();
+  
   return returnCode;
 }

Modified: pcbsd-projects/PCDM/pcdm-backend.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.cpp	2012-09-27 15:21:53 UTC (rev 19552)
+++ pcbsd-projects/PCDM/pcdm-backend.cpp	2012-09-27 15:48:47 UTC (rev 19553)
@@ -59,6 +59,46 @@
   return allowed;
 }
 
+QString Backend::getALUsername(){
+  //Make sure the requested user is valid
+  readSystemUsers(); //first read the available users on this system
+  QString ruser = Config::autoLoginUsername();
+  int index = usernameList.indexOf(ruser);
+  if(index == -1){ //invalid username
+    //Check if a display name was given instead
+    index = displaynameList.indexOf(ruser);
+    if(index == -1){ //invalid display name
+      log("Invalid Auto-Login user requested - skipping....");
+      ruser.clear();
+    }else{
+      //use the valid username for the given display name
+      ruser = usernameList[index]; 
+    }
+  }
+  return ruser;
+}
+
+QString Backend::getALDesktopCmd(){
+   // Make sure the desired desktop is valid
+  QString rdesktop = Config::autoLoginDesktop();
+  if(!QFile::exists(rdesktop)){ //requested file does not exist
+    log("Invalid Auto-Login desktop requested - skipping....");
+    return "";
+  }
+  QStringList result = readXSessionsFile(rdesktop,"");
+  if(result.isEmpty()){  //requested file is not a valid xsessions file
+    log("Invalid Auto-Login desktop requested - skipping....");
+    return "";  	  
+  }
+  if(!result[0].startsWith("/")){ result[0] = "/usr/local/bin/"+result[0]; }
+  rdesktop = result[0]; //(absolute path) executable
+  if(!QFile::exists(rdesktop)){  //requested desktop is not currently installed
+    log("Invalid Auto-Login desktop requested - skipping....");
+    return "";    	  
+  }
+  return rdesktop;
+}
+
 void Backend::startAutoLogin(){
   //Make sure the requested user is valid
   readSystemUsers(); //first read the available users on this system

Modified: pcbsd-projects/PCDM/pcdm-backend.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.h	2012-09-27 15:21:53 UTC (rev 19552)
+++ pcbsd-projects/PCDM/pcdm-backend.h	2012-09-27 15:48:47 UTC (rev 19553)
@@ -45,6 +45,9 @@
     static void startXSession();  
     static QString getUserHomeDir(QString);
     static void checkLocalDirs();
+
+    static QString getALUsername();
+    static QString getALDesktopCmd();
     
 private:	
     static void loadXSessionsData();

Modified: pcbsd-projects/PCDM/pcdm-xprocess.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-xprocess.cpp	2012-09-27 15:21:53 UTC (rev 19552)
+++ pcbsd-projects/PCDM/pcdm-xprocess.cpp	2012-09-27 15:48:47 UTC (rev 19553)
@@ -12,7 +12,7 @@
 }
 
 XProcess::~XProcess(){
-  if(session->isRunning()){
+  if( session->state() != QProcess::NotRunning){
     session->terminate();
   }
   session->close();
@@ -35,7 +35,7 @@
   if( xuser.isEmpty() || xcmd.isEmpty() || xhome.isEmpty() ){
     return;
   }
-  Backend::log("Starting up Desktop environment ("+xcmd+") as user ("+xuser+")");
+  //Backend::log("Starting up Desktop environment ("+xcmd+") as user ("+xuser+")");
 
   // Use the saved information
   QString cmd = "su "+xuser+" -c \""; //switch user command to start process properly
@@ -74,7 +74,7 @@
 void XProcess::waitForFinished(){
   // CAUTION!! 
   // This function will pause the calling program to wait for the session to end!
-  if( session->isRunning() ){
+  if( session->state() != QProcess::NotRunning ){
     session->waitForFinished(-1);
   }
 }



More information about the Commits mailing list