Ignore:
Timestamp:
07/11/13 14:28:19 (17 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1
Children:
ed51bc3
Parents:
8679296
Message:

Completely revamp how PCDM uses the previous login information. Now you no longer need to specify which desktop to auto-login to if you have auto-login selected. It will first try to check for previous login information for that user, then fall back on the last login for the system in order to try and auto login. Also fix the PCDMd script a bit so that autologins work properly when triggered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/PCDM/src/pcdm-backend.cpp

    r1620346 r90dc161  
    1414QStringList displaynameList,usernameList,homedirList,instXNameList,instXBinList,instXCommentList,instXIconList; 
    1515QString logFile; 
    16 QString saveX,saveUsername; 
     16QString saveX,saveUsername, lastUser, lastDE; 
    1717 
    1818QStringList Backend::getAvailableDesktops(){   
     
    6969} 
    7070 
    71 QString Backend::getALDesktopCmd(){ 
    72    // Make sure the desired desktop is valid 
    73   QString rdesktop = Config::autoLoginDesktop(); 
    74   if(!QFile::exists(rdesktop)){ //requested file does not exist 
    75     log("Invalid Auto-Login desktop requested - skipping...."); 
    76     return ""; 
    77   } 
    78   QStringList result = readXSessionsFile(rdesktop,""); 
    79   if(result.isEmpty()){  //requested file is not a valid xsessions file 
    80     log("Invalid Auto-Login desktop requested - skipping...."); 
    81     return "";             
    82   } 
    83   if(!result[0].startsWith("/")){ result[0] = "/usr/local/bin/"+result[0]; } 
    84   rdesktop = result[0]; //(absolute path) executable 
    85   if(!QFile::exists(rdesktop)){  //requested desktop is not currently installed 
    86     log("Invalid Auto-Login desktop requested - skipping...."); 
    87     return "";             
    88   } 
    89   return rdesktop; 
    90 } 
    91  
    9271QString Backend::getALPassword(){ 
    9372  QString rpassword = Config::autoLoginPassword(); 
     
    9978  return usernameList[i]; 
    10079} 
     80 
     81QString Backend::getDisplayNameFromUsername(QString username){ 
     82  int i = usernameList.indexOf(username); 
     83  return displaynameList[i];   
     84} 
     85 
    10186QString Backend::getUserHomeDir(QString username){ 
    10287  int i = usernameList.indexOf(username); 
     
    234219  if(!mainDir.exists("themes")){ mainDir.mkdir("themes"); } 
    235220  //Check for sample files 
    236   if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); } 
    237   //if(!mainDir.exists("pcdm.theme.sample")){ QFile::copy(":samples/themes/default/default.theme",base+"/pcdm.theme.sample"); } 
     221  if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); }  
     222} 
     223 
     224QString Backend::getLastUser(){ 
     225  //Load the file if necessary 
     226  if(lastUser.isEmpty()){ 
     227    readSystemLastLogin();   
     228  } 
     229  //return the value 
     230  return lastUser; 
     231} 
     232 
     233QString Backend::getLastDE(QString user){ 
     234  if(lastDE.isEmpty()){ 
     235    readSystemLastLogin(); 
     236  } 
     237  QString de = readUserLastDesktop(user); 
     238  if(de.isEmpty()){ return lastDE; } 
     239  else{ return de; } 
    238240   
     241} 
     242 
     243void Backend::saveLoginInfo(QString user, QString desktop){ 
     244  writeSystemLastLogin(user,desktop); //save the system file (/usr/local/share/PCDM/.lastlogin) 
     245  writeUserLastDesktop(user,desktop); //save the user file (~/.lastlogin) 
    239246} 
    240247 
     
    360367   
    361368} 
     369 
     370void Backend::readSystemLastLogin(){ 
     371    if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){ 
     372      lastUser.clear(); 
     373      Backend::log("PCDM: No previous login data found"); 
     374    }else{ 
     375      //Load the previous login data 
     376      QFile file("/usr/local/share/PCDM/.lastlogin"); 
     377      if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
     378        Backend::log("PCDM: Unable to open previous login data file");     
     379      }else{ 
     380        QTextStream in(&file); 
     381        lastUser= in.readLine(); 
     382        lastDE= in.readLine(); 
     383        file.close(); 
     384      } 
     385    }   
     386} 
     387 
     388void Backend::writeSystemLastLogin(QString user, QString desktop){ 
     389  QFile file1("/usr/local/share/PCDM/.lastlogin"); 
     390  if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
     391    Backend::log("PCDM: Unable to save last login data to system directory");      
     392  }else{ 
     393    QTextStream out(&file1); 
     394    out << user << "\n" << desktop; 
     395    file1.close(); 
     396  } 
     397 
     398} 
     399 
     400QString Backend::readUserLastDesktop(QString user){ 
     401  QString desktop; 
     402  QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin"; 
     403  if(!QFile::exists(LLpath)){ 
     404    Backend::log("PCDM: No previous user login data found for user: "+user); 
     405  }else{ 
     406    //Load the previous login data 
     407    QFile file(LLpath); 
     408    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
     409      Backend::log("PCDM: Unable to open previous user login file: "+user);     
     410    }else{ 
     411      QTextStream in(&file); 
     412      desktop = in.readLine(); 
     413      file.close(); 
     414    } 
     415  } 
     416  return desktop; 
     417} 
     418 
     419void Backend::writeUserLastDesktop(QString user, QString desktop){ 
     420  QFile file2( Backend::getUserHomeDir(user) + "/.lastlogin" ); 
     421  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
     422    Backend::log("PCDM: Unable to save last login data for user:"+user);           
     423  }else{ 
     424    QTextStream out(&file2); 
     425    out << desktop; 
     426    file2.close(); 
     427  } 
     428} 
Note: See TracChangeset for help on using the changeset viewer.