Changeset 3b71e5d


Ignore:
Timestamp:
01/27/14 14:12:39 (15 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2
Children:
9d2fc702
Parents:
2a1b10d
Message:

If the ~/.xprofile exists, create and run a simple script file to ensure that the QProcess runs the commands in sequence. Fall back on the old seperate QProcess commands if it could not create the script file.

Location:
src-qt4/PCDM/src
Files:
3 edited

Legend:

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

    r9a6b8ef r3b71e5d  
    316316    } 
    317317} 
     318 
     319bool Backend::writeFile(QString fileName, QStringList contents){ 
     320  //Open the file with .tmp extension 
     321  QFile file(fileName+".tmp"); 
     322  if( !file.open(QIODevice::WriteOnly | QIODevice::Text) ){ 
     323    qDebug() << fileName+".tmp: Failure -- Could not open file"; 
     324    return false; 
     325  } 
     326  //Write the file 
     327  QTextStream ofile(&file); //start the output stream 
     328  for(int i=0; i<contents.length(); i++){ 
     329    ofile << contents[i]; 
     330    ofile << "\n"; 
     331  } 
     332  //Close the File 
     333  file.close(); 
     334  //Remove any existing file with the final name/location 
     335  if( QFile::exists(fileName) ){ 
     336    if( !QFile::remove(fileName) ){ 
     337      qDebug() << fileName+": Error -- Could not overwrite existing file"; 
     338      QFile::remove(fileName+".tmp"); 
     339      return false; 
     340    } 
     341  } 
     342  //Move the temporary file into its final location 
     343  if( !file.rename(fileName) ){ 
     344    qDebug() << fileName+": Error: Could not rename "+fileName+".tmp as "+fileName; 
     345    return false; 
     346  } 
     347  //Return success 
     348  QString extra = QDir::homePath(); //remove this from the filename display 
     349  qDebug() << "Saved:" << fileName.replace(extra,"~"); 
     350  return true;;  
     351} 
     352 
    318353 
    319354//****** PRIVATE FUNCTIONS ****** 
     
    509544  } 
    510545} 
     546 
     547 
  • src-qt4/PCDM/src/pcdm-backend.h

    r9a6b8ef r3b71e5d  
    1414#include <QProcess> 
    1515#include <QFile> 
     16#include <QTextStream> 
    1617 
    1718#include "pcdm-config.h" 
     
    5960    static void saveDefaultSysEnvironment(QString lang, QString keymodel, QString keylayout, QString keyvariant); 
    6061     
     62    static bool writeFile(QString fileName, QStringList contents); 
     63     
    6164private:         
    6265    static void loadXSessionsData(); 
  • src-qt4/PCDM/src/pcdm-xprocess.cpp

    r2a1b10d r3b71e5d  
    143143  Backend::log("Starting session:"); 
    144144  if(QFile::exists(xhome+"/.xprofile")){ 
    145     Backend::log(" --Run user ~/.xprofile"); 
    146     //cmd.prepend("sh "+xhome+"/.xprofile; "); 
    147     QString xpro = "sh "+xhome+"/.xprofile"; 
    148     //Make sure it has executable permissions 
    149     //QFile::setPermissions(xhome+"/.xprofile", QFile::permissions(xhome+"/.xprofile") | QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther); 
    150     this->start(xpro); 
    151     this->waitForFinished(3000); 
     145    //Need to run a couple commands in sequence: so put them in a script file 
     146    QStringList contents; 
     147    contents << "sh "+xhome+"/.xprofile"; 
     148    contents << cmd; //end with the actual command for the DE 
     149    if( Backend::writeFile(xhome+"/.pcdmsessionstart", contents) ){ 
     150      //script created fine, change the command to just run it 
     151      cmd = "sh "+xhome+"/.pcdmsessionstart"; 
     152    }else{ 
     153      //Could not create script file, fallback on running them seperately 
     154      Backend::log(" --Run user ~/.xprofile"); 
     155      QString xpro = "sh "+xhome+"/.xprofile"; 
     156      this->start(xpro); 
     157      this->waitForFinished(3000); 
     158    } 
    152159  } 
    153160  connect( this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotCleanup()) ); 
    154   Backend::log(" --CMD: "+cmd); 
    155161  this->start(cmd); 
    156162  return TRUE; 
Note: See TracChangeset for help on using the changeset viewer.