[PC-BSD Commits] r20151 - users/ken/EasyPBI2

svn at pcbsd.org svn at pcbsd.org
Fri Nov 9 10:46:23 PST 2012


Author: kenmoore
Date: 2012-11-09 18:46:23 +0000 (Fri, 09 Nov 2012)
New Revision: 20151

Modified:
   users/ken/EasyPBI2/EasyPBI.pro
   users/ken/EasyPBI2/config.cpp
   users/ken/EasyPBI2/config.h
   users/ken/EasyPBI2/mainGUI.cpp
   users/ken/EasyPBI2/mainGUI.h
Log:
Get the new configuration class working. Now I can tie it into the preferences dialog for editing the current configuration.



Modified: users/ken/EasyPBI2/EasyPBI.pro
===================================================================
--- users/ken/EasyPBI2/EasyPBI.pro	2012-11-09 17:28:38 UTC (rev 20150)
+++ users/ken/EasyPBI2/EasyPBI.pro	2012-11-09 18:46:23 UTC (rev 20151)
@@ -16,12 +16,14 @@
         mainGUI.cpp \
         modBuild.cpp \
 	backend.cpp \
-	newModuleDialog.cpp
+	newModuleDialog.cpp \
+	config.cpp
 
 HEADERS  += mainGUI.h \
             modBuild.h \
 	    backend.h \
-	    newModuleDialog.h
+	    newModuleDialog.h \
+	    config.h
 
 FORMS    += mainGUI.ui \
 	    newModuleDialog.ui

Modified: users/ken/EasyPBI2/config.cpp
===================================================================
--- users/ken/EasyPBI2/config.cpp	2012-11-09 17:28:38 UTC (rev 20150)
+++ users/ken/EasyPBI2/config.cpp	2012-11-09 18:46:23 UTC (rev 20151)
@@ -1,6 +1,6 @@
 #include "config.h"
 
-Config::Config(QWidget* parent) : QWidget(parent){
+Config::Config() {
     //Clear internal variables
     badPackages.clear(); exProgStruct.clear(); defaultSettings.clear();
     valueStruct.clear(); detStruct.clear(); TFstruct.clear();
@@ -16,12 +16,64 @@
     defaultSettings << "2.0" << tmp << tmp+"PBI/" << tmp+"Modules/" << tmp+".cache/" << tmp+"defaulticon.png" << tmp+".preferences" << QDir::homePath();
 	//TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
     TFstruct << FALSE << FALSE << FALSE << FALSE << FALSE << FALSE << FALSE << FALSE;
-	
   }
 
 Config::~Config(){
 }
 
+void Config::readMachineArch(){
+  //set the "is64bit" flag
+  TFstruct[0] = ( QProcessEnvironment::systemEnvironment().value("MACHTYPE") == "x86_64" );	
+}
+
+bool Config::checkDirectoryStructure(){
+ //Check for EasyPBI directory structure and create it if it is not there
+  if( !QDir(defaultSettings[1]).exists() ){
+    qDebug() << "Creating the EasyPBI directory in current user's home folder:" << defaultSettings[1];
+    QDir dir;
+    dir.root();
+    if( !dir.mkdir(defaultSettings[1]) ){ //Create the program directory
+      //Could not create the Program directory
+      qDebug() << " - Error with home directory permissions, could not create directory";
+      return FALSE;
+    }
+  }  
+  if( !QDir(defaultSettings[3]).exists() ){
+    QDir dir;
+    dir.root();
+    if( !dir.mkdir(defaultSettings[3]) ){ //module directory
+      qDebug() << " - Error with directory permissions, could not create directory" << defaultSettings[3];
+      return FALSE;
+    }
+  }  
+  if( !QDir(defaultSettings[2]).exists() ){
+    QDir dir;
+    dir.root();
+    if( !dir.mkdir(defaultSettings[2]) ){ // PBI output directory
+      qDebug() << " - Error with directory permissions, could not create directory" << defaultSettings[2];
+      return FALSE;
+    }
+  }  
+  if( !QDir(defaultSettings[4]).exists() ){
+    QDir dir;
+    dir.root();
+    if( !dir.mkdir(defaultSettings[4]) ){ // pkg cache
+      qDebug() << " - Error with directory permissions, could not create directory" << defaultSettings[4];
+      return FALSE;
+    }
+  }  
+
+  //Check for the defaulticons.png file
+  if( !QFile(defaultSettings[5]).exists() ){
+    //file does not exist, copy the included resource to the file
+    qDebug() << " - Copying the default icon to the EasyPBI directory";
+    QFile::copy(":/png/icons/defaulticon.png",defaultSettings[5]);
+    
+    QFile::setPermissions(defaultSettings[5],QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOwner | QFile::WriteOwner | QFile::ReadOther | QFile::WriteOther);
+  }
+  return TRUE;
+}
+
 void Config::loadSettingsFile(){
   //Make sure the preferences file exists, otherwise just load the defaults
   if( !QFile::exists(defaultSettings[6]) ){ returnToDefaults(); return; }
@@ -30,7 +82,7 @@
   //Open the file, otherwise use defaults
   if( !file.open(QIODevice::ReadOnly | QIODevice::Text) ){ 
     qDebug() << "Could not open preferences file for reading:" << defaultSettings[6];
-    returnDefaults();
+    returnToDefaults();
     return; 
   }
   QTextStream in(&file);
@@ -39,16 +91,16 @@
     //Now parse out the values
     QString savedversion;
     if( line.startsWith("<version>") ){ savedversion = readSavedValue("<version>",line); }
-    if( line.startsWith("<pbioutdir>") ){ valueStruct[0] = readSavedValue("<pbioutdir>",line); }
-    if( line.startsWith("<moduleoutdir>") ){ valueStruct[1] = readSavedValue("<moduleoutdir>",line); }
-    if( line.startsWith("<cachedir>") ){ valueStruct[2] = readSavedValue("<cachedir>",line); }
-    if( line.startsWith("<portstdir>") ){ valueStruct[3] = readSavedValue("<portsdir>",line); }
-    if( line.startsWith("<icondir>") ){ valueStruct[4] = readSavedValue("<icondir>",line); }
-    if( line.startsWith("<defaulticon>") ){ valueStruct[5] = readSavedValue("<defaulticon>",line); }
-    if( line.startsWith("<sigfile>") ){ valueStruct[6] = readSavedValue("<sigfile>",line); }
-    if( line.startsWith("<badpackages>") ){ badPackages = readSavedValue("<badpackages>",line).split(";",QString::SkipEmptyParts); }
-    if( line.startsWith("<usetmpfs>") ){ TFstruct[3] = (readSavedValue("<usetmpfs>",line).toLower() == "true"); }
-    if( line.startsWith("<usepkgcache>") ){ TFstruct[4] = (readSavedValue("<usepkgcache>",line).toLower() == "true"); }
+    else if( line.startsWith("<pbioutdir>") ){ valueStruct[0] = readSavedValue("<pbioutdir>",line); }
+    else if( line.startsWith("<moduleoutdir>") ){ valueStruct[1] = readSavedValue("<moduleoutdir>",line); }
+    else if( line.startsWith("<cachedir>") ){ valueStruct[2] = readSavedValue("<cachedir>",line); }
+    else if( line.startsWith("<portstdir>") ){ valueStruct[3] = readSavedValue("<portsdir>",line); }
+    else if( line.startsWith("<icondir>") ){ valueStruct[4] = readSavedValue("<icondir>",line); }
+    else if( line.startsWith("<defaulticon>") ){ valueStruct[5] = readSavedValue("<defaulticon>",line); }
+    else if( line.startsWith("<sigfile>") ){ valueStruct[6] = readSavedValue("<sigfile>",line); }
+    else if( line.startsWith("<badpackages>") ){ badPackages = readSavedValue("<badpackages>",line).split(";",QString::SkipEmptyParts); }
+    else if( line.startsWith("<usetmpfs>") ){ TFstruct[3] = (readSavedValue("<usetmpfs>",line).toLower() == "true"); }
+    else if( line.startsWith("<usepkgcache>") ){ TFstruct[4] = (readSavedValue("<usepkgcache>",line).toLower() == "true"); }
   }
   file.close();
   //Now update any missing values in the structures
@@ -69,7 +121,7 @@
   if(valueStruct[0]!=defaultSettings[2]){ out << "<pbioutdir>"+ valueStruct[0] + "</pbioutdir>\n"; }
   if(valueStruct[1]!=defaultSettings[3]){out << "<moduleoutdir>"+valueStruct[1]+"</moduleoutdir>\n"; }
   if(valueStruct[2]!=defaultSettings[4]){out << "<cachedir>"+valueStruct[2]+"</cachedir>\n"; }
-  if(valueStruct[3]!=detStruct[3]){out << "<portsdir>"+valueStruct[3]+"</portsdir>\n";
+  if(valueStruct[3]!=detStruct[3]){out << "<portsdir>"+valueStruct[3]+"</portsdir>\n"; }
   if(valueStruct[4]!=defaultSettings[7]){out << "<icondir>"+valueStruct[4]+"</icondir>\n"; }
   if(valueStruct[5]!=defaultSettings[5]){out << "<defaulticon>"+valueStruct[5]+"</defaulticon>\n"; }
   if(!valueStruct[6].isEmpty()){ out << "<sigfile>"+valueStruct[6]+"</sigfile>\n"; }
@@ -123,66 +175,118 @@
       }    	    
     }
   } // end loop over paths
-
+  
+  //Now search for the FreeBSD ports tree
+    QString ret;
+    QStringList portsLocations;
+    //Set the locations to search for the ports tree
+    portsLocations << "/usr/ports" << defaultSettings[1]+"ports";
+    //Search the locations
+    for(int i=0; i<portsLocations.size(); i++){
+      if( QDir(portsLocations[i]).exists() ){
+        if( QFile::exists(portsLocations[i]+"/COPYRIGHT") ){
+	  detStruct[3]=portsLocations[i];
+	}
+      }
+    }
+    
+  //Now Check the structures and set any internal flags
+  checkStructures();
 }
 
 void Config::returnToDefaults(){
     //Clear the structures
     for(int i=0; i<valueStruct.length(); i++){ valueStruct[i].clear(); }
     for(int i=0; i<exProgStruct.length(); i++){ exProgStruct[i].clear(); }
-    for(int i=1; i<TFstruct(); i++){ TFstruct[i] = FALSE; } //skip the 64-bit architecture flag
+    for(int i=1; i<TFstruct.length(); i++){ TFstruct[i] = FALSE; } //skip the 64-bit architecture flag
     //Now re-populate the structures from the defaults
     checkStructures();
 }
 
 QString Config::value(QString var){
-    //exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+//defaultSettings=[ current version#, programDir, pbiOutputDir, 
+	//moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
+    var = var.toLower();
+    if(var=="pbi_makeport"){ return exProgStruct[0]; }
+    else if(var=="pbi_create"){ return exProgStruct[1]; }
+    else if(var=="su_cmd"){ return exProgStruct[2]; }
+    else if(var=="pbidir"){ return valueStruct[0]; }
+    else if(var=="moduledir"){ return valueStruct[1]; }
+    else if(var=="cachedir"){ return valueStruct[2]; }
+    else if(var=="portsdir"){ return valueStruct[3]; }
+    else if(var=="icondir"){ return valueStruct[4]; }
+    else if(var=="defaulticon"){ return valueStruct[5]; }
+    else if(var=="sigfile"){ return valueStruct[6]; }
+    else if(var=="version"){ return defaultSettings[0]; }
+    else if(var=="progdir"){ return defaultSettings[1]; }
+    else{ 
+      qDebug() << "invalid value requested:" << var;
+      return ""; 
+    }
 }
 
 void Config::setValue(QString var, QString val){
-    //exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+    var = var.toLower();
+    if( !QFile::exists(val) ){ 
+      qDebug() << "WARNING! \""+var+"\" setting could not be changed: desired file does not exist:" + val;
+    }
+    else if(var=="pbi_makeport"){ exProgStruct[0]=val; }
+    else if(var=="pbi_create"){ exProgStruct[1]=val; }
+    else if(var=="su_cmd"){ exProgStruct[2]=val; }
+    else if(var=="pbidir"){ valueStruct[0]=val; }
+    else if(var=="moduledir"){ valueStruct[1]=val; }
+    else if(var=="cachedir"){ valueStruct[2]=val; }
+    else if(var=="portsdir"){ valueStruct[3]=val; }
+    else if(var=="icondir"){ valueStruct[4]=val; }
+    else if(var=="defaulticon"){ valueStruct[5]=val; }
+    else if(var=="sigfile"){ valueStruct[6]=val; }
+    else{ qDebug() << "invalid setvalue requested:" << var; }
+
 }
 
 QStringList Config::list(QString var){
-//exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+    var = var.toLower();
+    if(var=="skippkgs"){ return badPackages; }
+    else{ 
+      qDebug() << "invalid list requested:"<<var;
+      return QStringList();
+    }
 }
 
 void Config::setList(QString var, QStringList val){
-//exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+  var=var.toLower();
+  if(var=="skippkgs"){ badPackages = val; }
+  else{ qDebug() << "invalid setlist requested:"<<var; }
 }
 
 bool Config::check(QString var){
-//exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+  var = var.toLower();
+  if(var=="is64bit"){ return TFstruct[0]; }
+  else if(var=="isportsavailable"){ return TFstruct[1]; }
+  else if(var=="usesignature"){ return TFstruct[2]; }
+  else if(var=="usetmpfs"){ return TFstruct[3]; }
+  else if(var=="usecache"){ return TFstruct[4]; }
+  else if(var=="ismakeportavailable"){ return TFstruct[5]; }
+  else if(var=="iscreateavailable"){ return TFstruct[6]; }
+  else if(var=="issuavailable"){ return TFstruct[7]; }
+  else{ 
+    qDebug() << "invalid check requested:" << var;
+    return FALSE; 
+  }
 }
 
 void Config::setCheck(QString var, bool val){
-//exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
-    //valueStruct=[ pbiOutputDir, moduleOutputDir, pkgCacheDir, portsDir, iconDir, defaultIcon, sigFile ]
-    //detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
-    //defaultSettings=[ current version#, programDir, pbiOutputDir, moduleOutputDir, pkgCacheDir, iconFile, settingsFile, iconDir]
-    //TFstruct=[ is64-bitArch, portsAvailable, useDigitalSig, useTMPFS, usePkgCache, pbi_makeport_available, pbi_create_available, su_available ]
+  var = var.toLower();
+  if(var=="usesignature"){ TFstruct[2] = val; }
+  else if(var=="usetmpfs"){ TFstruct[3] = val; }
+  else if(var=="usecache"){ TFstruct[4] = val; }
+  else{ qDebug() << "invalid setcheck requested:" << var; }
 }
 
+// *********************************************************
+// -----------PRIVATE FUNCTIONS FOR INTERNAL USE-----------
+//**********************************************************
+
 QString Config::readSavedValue(QString var, QString line){
   //var = "<something>"
   //line = line with the value on it
@@ -205,7 +309,7 @@
   // -- Package Cache dir
   if( valueStruct[2].isEmpty() ){ valueStruct[2] = defaultSettings[4]; }
   // -- FreeBSD ports tree
-  if(valueStruct[3].isEmpty){ 
+  if( valueStruct[3].isEmpty() ){ 
     if(detStruct[3].isEmpty()){ TFstruct[1] = FALSE; }
     else{ valueStruct[3] = detStruct[3]; TFstruct[1]=TRUE; }
   }
@@ -213,26 +317,21 @@
   if( valueStruct[4].isEmpty() ){ valueStruct[4] = defaultSettings[7]; }
   // -- default icon file
   if( valueStruct[5].isEmpty() ){ valueStruct[5] = defaultSettings[5]; }
-  // -- Digital Signature file
-  if(valueStruct[6].isEmpty){ TFstruct[2]=FALSE; }
-  else if( !QFile::exists(valueStruct[6]) ){ TFstruct[2]=FALSE; qDebug() << "Ignoring non-existant signature file:"<< valueStruct[6]; }
-  else{ TFstruct[2]=TRUE; }
   
   //External utilities
   // -- pbi_makeport
-  if(exProgStruct[0].isEmpty){ 
+  if( exProgStruct[0].isEmpty() ){ 
     if(detStruct[0].isEmpty()){ TFstruct[5] = FALSE; }
     else{ exProgStruct[0] = detStruct[0]; TFstruct[5]=TRUE; }
   }
   // -- pbi_create
-  if(exProgStruct[1].isEmpty){ 
+  if( exProgStruct[1].isEmpty() ){ 
     if(detStruct[1].isEmpty()){ TFstruct[6] = FALSE; }
     else{ exProgStruct[1] = detStruct[1]; TFstruct[6]=TRUE; }
   }
   // -- graphical su utility
-  if(exProgStruct[2].isEmpty){ 
+  if( exProgStruct[2].isEmpty() ){ 
     if(detStruct[2].isEmpty()){ TFstruct[7] = FALSE; }
     else{ exProgStruct[2] = detStruct[2]; TFstruct[7]=TRUE; }
   }
-
-}
\ No newline at end of file
+}

Modified: users/ken/EasyPBI2/config.h
===================================================================
--- users/ken/EasyPBI2/config.h	2012-11-09 17:28:38 UTC (rev 20150)
+++ users/ken/EasyPBI2/config.h	2012-11-09 18:46:23 UTC (rev 20151)
@@ -1,14 +1,16 @@
-#ifndef _EASYPBI_CONFIG_H
-#define _EASYPBI_CONFIG_H
+#ifndef _CONFIG_H
+#define _CONFIG_H
 
 #include <QString>
 #include <QStringList>
 #include <QDebug>
 #include <QFile>
 #include <QDir>
+#include <QList>
+#include <QCoreApplication>
+#include <QProcessEnvironment>
 
 class Config{
-	Q_OBJECT
 	
 private:
   //Internal variables
@@ -16,13 +18,15 @@
   QList<bool> TFstruct;
  
   //Internal functions
-  QString readSavedValue(QString);
+  QString readSavedValue(QString,QString);
   void checkStructures();
 
 public:
-  Config(QWidget* parent =0);
+  Config();
   ~Config();
   // --Regular functions--
+  void readMachineArch();
+  bool checkDirectoryStructure();
   void loadSettingsFile();
   void saveSettingsFile();
   void scanForExternalUtilities();

Modified: users/ken/EasyPBI2/mainGUI.cpp
===================================================================
--- users/ken/EasyPBI2/mainGUI.cpp	2012-11-09 17:28:38 UTC (rev 20150)
+++ users/ken/EasyPBI2/mainGUI.cpp	2012-11-09 18:46:23 UTC (rev 20151)
@@ -13,8 +13,10 @@
 	
        //Setup Initial state of GUI objects and connect signal/slots
        ui->setupUi(this);  //load the mainGUI.ui file
-	// Create the module class necessary
+	// Create the module class as necessary
 	currentModule = new ModBuild();
+	// Create the config class
+	settings = new Config();
 	//Setup the Menu items
 	ui->actionExit->setIcon(Backend::icon(""));
 	//Setup the pushbutton menu lists
@@ -110,94 +112,33 @@
 }
 
 void MainGUI::SetupDefaults(){
+    qDebug() << "Starting up EasyPBI" << settings->value("version");	
     //Make sure that the program is not being started with root permissions
     QString id = QProcessEnvironment::systemEnvironment().toStringList().filter("HOME=").join(" ").simplified();
     if( id.contains("root") ){
       qDebug() << "EasyPBI should not be run with root permissions! exiting.....";
-      exit(0);
+      exit(1);
     }
 
-  PROGVERSION = "2.0";
-  PROG_DIR = QDir::homePath() + "/EasyPBI";
-  PBIOUT_DIR= PROG_DIR + "/PBI";
-  MODOUT_DIR= PROG_DIR + "/Modules";  
-  CACHE_DIR= PROG_DIR + "/.cache";
-  PBISETTINGS_FILE= PROG_DIR + "/.savedPBISettings.conf";
-  DEFAULTICON_FILE= PROG_DIR + "/defaulticon.png";
-  PORTS_DIR = "";
-  isSixtyFourBitOS= ( QProcessEnvironment::systemEnvironment().value("MACHTYPE") == "x86_64" );
-  
-  //Check for EasyPBI directory structure and create it if it is not there
-  if( !QDir(PROG_DIR).exists() ){
-    qDebug() << "Creating the EasyPBI directory in current user's home folder:" << PROG_DIR;
-    QDir dir;
-    dir.root();
-    if( !dir.mkdir(PROG_DIR) ){ //Create the program directory
-      //Could not create the Program directory
-      QMessageBox::warning(this, tr("Error: Permissions"), tr("Invalid permissions to create EasyPBI directory in home folder"));
-      return;
+    //Load the current configuration settings
+    settings->readMachineArch(); //set the 64-bit flag as appropriate
+    settings->loadSettingsFile(); //load the preferences file if available, otherwise use defaults
+    if( !settings->checkDirectoryStructure() ){ //create the EasyPBI directory structure if needed
+	QMessageBox::warning(this,tr("Permissions Error"), tr("There was an error trying to create the local EasyPBI directory structure. Please check the permissions for your home directory and restart EasyPBI.") );
+	exit(1);
     }
-  }  
-  if( !QDir(MODOUT_DIR).exists() ){
-    QDir dir;
-    dir.root();
-    if( !dir.mkdir(MODOUT_DIR) ){ //Create the program directory
-      //Could not create the Program directory
-      QMessageBox::warning(this, tr("Error: Permissions"), tr("Invalid permissions to create EasyPBI directory in home folder"));
-      return;
+    //Scan for the external utilities needed to build PBI's
+    settings->scanForExternalUtilities();
+    //Pop up a warning box if some external resources are not available
+    bool chkOK = (settings->check("isPortsAvailable") && settings->check("isMakeportAvailable") && settings->check("iscreateAvailable") && settings->check("isSUavailable") );
+    if( !chkOK ){
+	QMessageBox::warning(this, tr("Resources Unavailable"), tr("Some external resources could not be found, so the EasyPBI services that use these resources have been deactivated.")+"\n"+tr("Please open up the EasyPBI preferences to correct this deficiency.") );
     }
-  }  
-  if( !QDir(PBIOUT_DIR).exists() ){
-    QDir dir;
-    dir.root();
-    if( !dir.mkdir(PBIOUT_DIR) ){ //Create the program directory
-      //Could not create the Program directory
-      QMessageBox::warning(this, tr("Error: Permissions"), tr("Invalid permissions to create EasyPBI directory in home folder"));
-      return;
-    }
-  }  
-  if( !QDir(CACHE_DIR).exists() ){
-    QDir dir;
-    dir.root();
-    if( !dir.mkdir(CACHE_DIR) ){ //Create the program directory
-      //Could not create the Program directory
-      QMessageBox::warning(this, tr("Error: Permissions"), tr("Invalid permissions to create EasyPBI directory in home folder"));
-      return;
-    }
-  }  
-
-  //Check for the defaulticons.png file
-  if( !QFile(DEFAULTICON_FILE).exists() ){
-    //file does not exist, copy the included resource to the file
-    qDebug() << "Copying the default icon to the EasyPBI directory";
-    QFile::copy(":/png/icons/defaulticon.png",DEFAULTICON_FILE);
-    
-    QFile::setPermissions(DEFAULTICON_FILE,QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOwner | QFile::WriteOwner | QFile::ReadOther | QFile::WriteOther);
-  }
-
-  //Load the defaults for the PBI build settings
-  if( QFile(PBISETTINGS_FILE).exists() ){
-    qDebug() << "PBI Settings file detected at:"<< PBISETTINGS_FILE;
-    //loadPBISettings();
-  }else{
-    //ui->linePBIOutDir->setText(PBIOUT_DIR);
-  }
-  
-  //Scan for the external utilities needed to build PBI's
-  Backend::findExternalCommands(&SU_CMD, &PBIBUILD_CMD, &PBICREATE_CMD);
-  //Determine if the FreeBSD ports tree is available
-  PORTS_DIR = Backend::findPortsDir();
-  //Set a couple more internal flags
-  PBI_BUILDING_NOW.clear();
-  PBI_BUILD_TERMINATED=FALSE;
+    //Set a couple more internal flags
+    PBI_BUILDING_NOW.clear();
+    PBI_BUILD_TERMINATED=FALSE;
 }
 
-bool MainGUI::CheckForPorts(){
-  bool ok=FALSE;
-  if( !PORTS_DIR.isEmpty()  && QFile::exists(PORTS_DIR) ){ ok = TRUE; }
-  return ok;
-}
-
 bool MainGUI::isValidPort(QString pPath){
   bool ok = FALSE;
   if( QFile::exists(pPath) && QFile::exists(pPath+"/Makefile") && QFile::exists(pPath+"/distinfo") ){
@@ -360,7 +301,7 @@
   if( doall || (item == "pbibuild")){
     if(PBI_BUILDING_NOW.isEmpty()){
       //only change things if there is nothing building at the moment
-      ui->line_build_outputdir->setText(PBIOUT_DIR);
+      ui->line_build_outputdir->setText( settings->value("pbidir") );
       if(ui->text_build_log->toPlainText().isEmpty()){ ui->push_build_save->setEnabled(FALSE); }
       else{ ui->push_build_save->setEnabled(TRUE); }
     }
@@ -368,7 +309,7 @@
   //------OVERALL SETTINGS------
   if( doall || doeditor ){
     //Enable/disable the buttons that require the FreeBSD ports tree
-    if( CheckForPorts() ){
+    if( settings->check("isportsavailable") ){
       ui->push_change_makeport->setEnabled(TRUE);
       ui->push_addportbefore->setEnabled(TRUE);
       ui->push_addportafter->setEnabled(TRUE);
@@ -378,7 +319,7 @@
       ui->push_addportafter->setEnabled(FALSE);
     }
     //Check for a 64-bit system to enable the 32-bit build option
-    if(isSixtyFourBitOS){ ui->check_build_32->setVisible(TRUE); }
+    if( settings->check("is64bit") ){ ui->check_build_32->setVisible(TRUE); }
     else{ ui->check_build_32->setVisible(FALSE); ui->check_build_32->setChecked(FALSE); }
   }
 }
@@ -398,8 +339,8 @@
 void MainGUI::on_actionNew_Module_triggered(){
   qDebug() << "New Module triggered";
   //Create and run the new dialog
-  NewModuleDialog* dlg = new NewModuleDialog(this, PORTS_DIR);
-  dlg->setDefaultIconFile(DEFAULTICON_FILE);
+  NewModuleDialog* dlg = new NewModuleDialog(this, settings->value("portsdir"));
+  dlg->setDefaultIconFile(settings->value("defaulticon"));
   dlg->exec();
   //Determine if the action was cancelled
   if( dlg->isAccepted ){
@@ -408,7 +349,7 @@
     modType = dlg->moduleType;
     modBase = dlg->moduleData;
     oldIconPath = dlg->moduleIcon;
-    modPath = MODOUT_DIR+"/"+modBase.section("/",-1).toLower();
+    modPath = settings->value("moduledir")+"/"+modBase.section("/",-1).toLower();
 	  //modPath ->full path, modType->"local"or "port", modBase->makeport or packagedir
     bool ok = currentModule->createNewModule(modPath,modType,modBase);
     if(!ok){
@@ -422,8 +363,8 @@
       if(currentModule->isPortPBI){
         radio_module_port->toggle();
 	//Use the port info if possible
-	if( !PORTS_DIR.isEmpty() ){
-	  currentModule->readPortInformation(PORTS_DIR+"/"+modBase);
+	if( !settings->check("isportsAvailable") ){
+	  currentModule->readPortInformation(settings->value("portsdir")+"/"+modBase);
 	  //Now save the detected information into the module
 	  currentModule->writeValue("progname", currentModule->readValue("portname"));
 	  currentModule->writeValue("progweb", currentModule->readValue("portwebsite"));
@@ -443,7 +384,7 @@
 }
 
 void MainGUI::on_actionLoad_Module_triggered(){
-  QString modSel = QFileDialog::getExistingDirectory(this, tr("Select Module"), MODOUT_DIR);
+  QString modSel = QFileDialog::getExistingDirectory(this, tr("Select Module"), settings->value("moduledir"));
   if(modSel.isEmpty()){return;} //action cancelled or closed
   bool ok = currentModule->loadModule(modSel);
   if(ok){ 
@@ -452,8 +393,8 @@
     if(currentModule->isLocalPBI){ radio_module_local->toggle(); }
     else{ 
       radio_module_port->toggle(); //Port PBI
-      if( CheckForPorts() ){ 
-        currentModule->readPortInformation(PORTS_DIR+"/"+currentModule->readValue("makeport"));
+      if( settings->check("isportsavailable") ){ 
+        currentModule->readPortInformation(settings->value("portsdir")+"/"+currentModule->readValue("makeport"));
       }
     }
     refreshGUI("all");
@@ -488,13 +429,13 @@
   -----------------------------------
 */
 void MainGUI::on_push_change_makeport_clicked(){
-  if( !CheckForPorts() ){
+  if( !settings->check("isportsavailable") ){
     //No ports tree available
     QMessageBox::warning(this,tr("EasyPBI: No FreeBSD Ports"), tr("The FreeBSD Ports tree could not be found on your system. You may fetch the ports tree through the EasyPBI menu or manually set the path to the port tree in the EasyPBI preferences if it is installed in a non-standard location."));
     return;
   }
   //Prompt for a new port
-  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
+  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
   if(portSel.isEmpty()){return;} //action cancelled or closed	
   //Check if the port is valid
   if( !isValidPort(portSel) ){
@@ -502,7 +443,7 @@
     return;
   }
   //Save the port info to the GUI
-  ui->line_makeport->setText(portSel.remove(PORTS_DIR+"/"));
+  ui->line_makeport->setText(portSel.remove(settings->value("portsdir")+"/"));
 }
 
 void MainGUI::slotAddMakeOption(QAction* act){
@@ -556,12 +497,12 @@
 }
 
 void MainGUI::on_push_addportbefore_clicked(){
-  if( !CheckForPorts() ){
+  if( !settings->check("isportsavailable") ){
     //No ports tree available
     QMessageBox::warning(this,tr("EasyPBI: No FreeBSD Ports"), tr("The FreeBSD Ports tree could not be found on your system. You may fetch the ports tree through the EasyPBI menu or manually set the path to the port tree in the EasyPBI preferences if it is installed in a non-standard location."));
   }
   //Prompt for a new port
-  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
+  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
   if(portSel.isEmpty()){return;} //action cancelled or closed	
   //Check if the port is valid
   if( !isValidPort(portSel) ){
@@ -570,7 +511,7 @@
   }
   //Save the port info to the GUI
   if(ui->list_portbefore->count() == 1 && ui->list_portbefore->currentText().isEmpty() ){ ui->list_portbefore->clear(); }
-  ui->list_portbefore->addItem(portSel.remove(PORTS_DIR+"/"));
+  ui->list_portbefore->addItem(portSel.remove(settings->value("portsdir")+"/"));
 }
 
 void MainGUI::on_push_rmportbefore_clicked(){
@@ -581,12 +522,12 @@
 }
 
 void MainGUI::on_push_addportafter_clicked(){
-  if( !CheckForPorts() ){
+  if( !settings->check("isportsavailable") ){
     //No ports tree available
     QMessageBox::warning(this,tr("EasyPBI: No FreeBSD Ports"), tr("The FreeBSD Ports tree could not be found on your system. You may fetch the ports tree through the EasyPBI menu or manually set the path to the port tree in the EasyPBI preferences if it is installed in a non-standard location."));
   }
   //Prompt for a new port
-  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
+  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
   if(portSel.isEmpty()){return;} //action cancelled or closed	
   //Check if the port is valid
   if( !isValidPort(portSel) ){
@@ -595,7 +536,7 @@
   }
   //Save the port info to the GUI
   if(ui->list_portafter->count() == 1 && ui->list_portafter->currentText().isEmpty() ){ ui->list_portafter->clear(); }
-  ui->list_portafter->addItem(portSel.remove(PORTS_DIR+"/"));
+  ui->list_portafter->addItem(portSel.remove(settings->value("portsdir")+"/"));
 }
 
 void MainGUI::on_push_rmportafter_clicked(){
@@ -643,7 +584,7 @@
     QMessageBox::warning(this,tr("EasyPBI Error"), tr("The PBI configuration file could not be saved. Please check your file permissions before trying again."));
   }else if(newport){
     //Refresh the port information if the main port changed
-    currentModule->readPortInformation(PORTS_DIR+"/"+ui->line_makeport->text());
+    currentModule->readPortInformation(settings->value("portsdir")+"/"+ui->line_makeport->text());
     refreshGUI("pbiconf");
   }
 }
@@ -1290,26 +1231,26 @@
   // -- PBI from ports
   if(radio_module_port->isChecked()){
     //Check that the ports tree is available
-    if( !CheckForPorts() ){ 
+    if( !settings->check("isportsavailable") ){ 
       qDebug() << "Cannot build a PBI from ports without the FreeBSD ports tree available";
       return;
     }
     //Setup the pbi_makeport command from GUI settings
-    cmd = PBIBUILD_CMD;
+    cmd = settings->value("pbi_makeport");
     if(ui->check_build_32->isChecked()){ cmd += " -32"; }
     cmd += " -c " + modDir;
-    if(PORTS_DIR != "/usr/ports"){ cmd += " -d " + PORTS_DIR; }
+    if(settings->value("portsdir") != "/usr/ports"){ cmd += " -d " + settings->value("portsdir"); }
     cmd += " -o " + outdir;
     cmd += " --delbuild";
-    //if( ui->checkTMPFS->isChecked() ){ cmd += " --tmpfs"; }
-    /*if( ui->checkUseCache->isChecked() ){ 
-      cmd += " --pkgdir " + CACHE_DIR;
+    if( settings->check("usetmpfs") ){ cmd += " --tmpfs"; }
+    if( settings->check("usecache") ){ 
+      cmd += " --pkgdir " + settings->value("cachedir");
       //Remove known "bad" packages (ones that routinely cause failures)
-      QDir cDir(CACHE_DIR);
-      QStringList filters << "libtool*";
-      QStringList badFiles = cDir.entryList(filters, QDir::Files | QDir:: NoDotAndDotDot)
+      QDir cDir( settings->value("cachedir") );
+      QStringList filters = settings->list("skippkgs");
+      QStringList badFiles = cDir.entryList(filters, QDir::Files | QDir:: NoDotAndDotDot);
       for(int i=0; i<badFiles.length(); i++){ cDir.remove(badFiles[i]); }
-    }*/
+    }
     
     //if(!sigfile.isEmpty()){ cmd += " --sign " + sigfile; }
     qDebug() << "Build PBI command created:"<<cmd;
@@ -1331,7 +1272,7 @@
   if(ret != QMessageBox::Yes){return;}
 
   //Add the necessary glue to the command to run the pbi build
-  cmd.prepend(SU_CMD+" \"");
+  cmd.prepend(settings->value("su_cmd")+" \"");
   cmd.append("\"");
   qDebug() << "Actual command used:" << cmd;
   
@@ -1362,7 +1303,7 @@
 
 void MainGUI::on_push_build_save_clicked(){
   //Have user select a filename/location to save the log
-  QString filename = QFileDialog::getSaveFileName(this,tr("Save Log"),PROG_DIR+"/build.log",tr("Log Files")+" (*.log *.txt)");
+  QString filename = QFileDialog::getSaveFileName(this,tr("Save Log"),settings->value("progdir")+"/build.log",tr("Log Files")+" (*.log *.txt)");
   if(filename.isEmpty()){return;} //User cancelled the process
   //Open the file (as new)
   QFile *file = new QFile(filename);
@@ -1407,6 +1348,7 @@
   p->close();
   PBI_BUILDING_NOW.clear();
   PBI_BUILD_TERMINATED=FALSE;
+  delete p;
 }
 
 void MainGUI::slotKillPBIBuild(){

Modified: users/ken/EasyPBI2/mainGUI.h
===================================================================
--- users/ken/EasyPBI2/mainGUI.h	2012-11-09 17:28:38 UTC (rev 20150)
+++ users/ken/EasyPBI2/mainGUI.h	2012-11-09 18:46:23 UTC (rev 20151)
@@ -16,6 +16,7 @@
 
 #include "modBuild.h"
 #include "backend.h"
+#include "config.h"
 
 namespace Ui {
     class MainGUI;
@@ -89,17 +90,16 @@
 private:
     Ui::MainGUI *ui;
     ModBuild *currentModule;
+    Config *settings;
     QLineEdit *line_module;
     QRadioButton *radio_module_port, *radio_module_local;
     QMenu menu_addOpt, menu_elOpts, menu_validMenuCats, menu_validMenuCatsNew, menu_mime, menu_mimenew, menu_bins, menu_binsnew, menu_el_bins;
 
-    QString PROG_DIR, PORTS_DIR, PBIOUT_DIR, MODOUT_DIR, CACHE_DIR, PROGVERSION, PBISETTINGS_FILE, DEFAULTICON_FILE;
-    QString SU_CMD, PBIBUILD_CMD, PBICREATE_CMD, PBI_BUILDING_NOW;
-    bool PBI_BUILD_TERMINATED, isSixtyFourBitOS;
+    QString PBI_BUILDING_NOW;
+    bool PBI_BUILD_TERMINATED;
     QProcess *p;
 
     void SetupDefaults();
-    bool CheckForPorts();
     bool isValidPort(QString);
 
 };



More information about the Commits mailing list