//=========================================== // Lumina-DE source code // Copyright (c) 2013, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "LuminaUtils.h" #include #include #include #include #include #include #include #include #include //============= // LUtils Functions //============= QString LUtils::LuminaDesktopVersion(){ return "0.8.1"; } int LUtils::runCmd(QString cmd, QStringList args){ QProcess *proc = new QProcess; proc->setProcessChannelMode(QProcess::MergedChannels); if(args.isEmpty()){ proc->start(cmd); }else{ proc->start(cmd, args); } while(!proc->waitForFinished(300)){ QCoreApplication::processEvents(); } int ret = proc->exitCode(); delete proc; return ret; } QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ QProcess *proc = new QProcess; proc->setProcessChannelMode(QProcess::MergedChannels); if(args.isEmpty()){ proc->start(cmd); }else{ proc->start(cmd,args); } while(!proc->waitForFinished(300)){ QCoreApplication::processEvents(); } QStringList out = QString(proc->readAllStandardOutput()).split("\n"); delete proc; return out; } QStringList LUtils::readFile(QString filepath){ QStringList out; QFile file(filepath); if(file.open(QIODevice::Text | QIODevice::ReadOnly)){ QTextStream in(&file); while(!in.atEnd()){ out << in.readLine(); } file.close(); } return out; } bool LUtils::writeFile(QString filepath, QStringList contents, bool overwrite){ QFile file(filepath); if(file.exists() && !overwrite){ return false; } bool ok = false; if( file.open(QIODevice::WriteOnly | QIODevice::Truncate) ){ QTextStream out(&file); out << contents.join("\n"); file.close(); ok = true; } return ok; } bool LUtils::isValidBinary(QString bin){ if(!bin.startsWith("/")){ //Relative path: search for it on the current "PATH" settings QStringList paths = QString(qgetenv("PATH")).split(":"); for(int i=0; iload( appname+QString("_") + langCode, LOS::LuminaShare()+"i18n/" ); app->installTranslator( CurTranslator ); }else{ //Only going to set the encoding since no application given qDebug() << "Loading System Encoding:" << langEnc; } //Load current encoding for this locale QTextCodec::setCodecForLocale( QTextCodec::codecForName(langEnc.toUtf8()) ); } void LUtils::LoadSystemDefaults(bool skipOS){ //Will create the Lumina configuration files based on the current system template (if any) QStringList sysDefaults; if(!skipOS){ sysDefaults = LUtils::readFile(LOS::AppPrefix()+"etc/luminaDesktop.conf"); } if(sysDefaults.isEmpty() && !skipOS){ sysDefaults = LUtils::readFile(LOS::AppPrefix()+"etc/luminaDesktop.conf.dist"); } if(sysDefaults.isEmpty() && !skipOS) { sysDefaults = LUtils::readFile(LOS::SysPrefix()+"etc/luminaDesktop.conf"); } if(sysDefaults.isEmpty() && !skipOS){ sysDefaults = LUtils::readFile(LOS::SysPrefix()+"etc/luminaDesktop.conf.dist"); } if(sysDefaults.isEmpty() && !skipOS) { sysDefaults = LUtils::readFile("/etc/luminaDesktop.conf"); } if(sysDefaults.isEmpty() && !skipOS){ sysDefaults = LUtils::readFile("/etc/luminaDesktop.conf.dist"); } if(sysDefaults.isEmpty()){ sysDefaults = LUtils::readFile(LOS::LuminaShare()+"luminaDesktop.conf"); } //Find the number of the left-most desktop screen QString screen = "0"; QDesktopWidget *desk =QApplication::desktop(); for(int i=0; iscreenCount(); i++){ if(desk->screenGeometry(i).x()==0){ screen = QString::number(i); break; } } //Now setup the default "desktopsettings.conf" and "sessionsettings.conf" files QStringList deskset, sesset; //First start with any session settings QStringList tmp = sysDefaults.filter("session."); sesset << "[General]"; //everything is in this section sesset << "DesktopVersion="+LUtils::LuminaDesktopVersion(); for(int i=0; i