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

svn at pcbsd.org svn at pcbsd.org
Wed Nov 14 17:48:04 PST 2012


Author: kenmoore
Date: 2012-11-15 01:48:04 +0000 (Thu, 15 Nov 2012)
New Revision: 20231

Added:
   users/ken/EasyPBI2/preferencesDialog.cpp
   users/ken/EasyPBI2/preferencesDialog.h
Modified:
   users/ken/EasyPBI2/EasyPBI.pro
   users/ken/EasyPBI2/config.cpp
   users/ken/EasyPBI2/mainGUI.cpp
   users/ken/EasyPBI2/mainGUI.h
   users/ken/EasyPBI2/preferencesDialog.ui
Log:
Add in the preferences dialog to EasyPBI and get it completely working. Almost done! just a few of the small menu items left.



Modified: users/ken/EasyPBI2/EasyPBI.pro
===================================================================
--- users/ken/EasyPBI2/EasyPBI.pro	2012-11-15 01:29:05 UTC (rev 20230)
+++ users/ken/EasyPBI2/EasyPBI.pro	2012-11-15 01:48:04 UTC (rev 20231)
@@ -17,16 +17,19 @@
         modBuild.cpp \
 	backend.cpp \
 	newModuleDialog.cpp \
-	config.cpp
+	config.cpp \
+	preferencesDialog.cpp
 
 HEADERS  += mainGUI.h \
             modBuild.h \
 	    backend.h \
 	    newModuleDialog.h \
-	    config.h
+	    config.h \
+	    preferencesDialog.h
 
 FORMS    += mainGUI.ui \
-	    newModuleDialog.ui
+	    newModuleDialog.ui \
+	    preferencesDialog.ui
 
 RESOURCES+= EasyPBI.qrc
 

Modified: users/ken/EasyPBI2/config.cpp
===================================================================
--- users/ken/EasyPBI2/config.cpp	2012-11-15 01:29:05 UTC (rev 20230)
+++ users/ken/EasyPBI2/config.cpp	2012-11-15 01:48:04 UTC (rev 20231)
@@ -75,8 +75,10 @@
 }
 
 void Config::loadSettingsFile(){
+  //Return to the defaults
+  returnToDefaults();
   //Make sure the preferences file exists, otherwise just load the defaults
-  if( !QFile::exists(defaultSettings[6]) ){ returnToDefaults(); return; }
+  if( !QFile::exists(defaultSettings[6]) ){ return; }
   //Read the preferences file
   QFile file(defaultSettings[6]);
   //Open the file, otherwise use defaults
@@ -86,10 +88,10 @@
     return; 
   }
   QTextStream in(&file);
+  QString savedversion;
   while( !in.atEnd() ){
     QString line = in.readLine().simplified();
     //Now parse out the values
-    QString savedversion;
     if( line.startsWith("<version>") ){ savedversion = readSavedValue("<version>",line); }
     else if( line.startsWith("<pbioutdir>") ){ valueStruct[0] = readSavedValue("<pbioutdir>",line); }
     else if( line.startsWith("<moduleoutdir>") ){ valueStruct[1] = readSavedValue("<moduleoutdir>",line); }
@@ -99,8 +101,12 @@
     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("<usesignature>") ){ TFstruct[2] = (readSavedValue("<usesignature>",line).toLower() == "true"); }
     else if( line.startsWith("<usetmpfs>") ){ TFstruct[3] = (readSavedValue("<usetmpfs>",line).toLower() == "true"); }
     else if( line.startsWith("<usepkgcache>") ){ TFstruct[4] = (readSavedValue("<usepkgcache>",line).toLower() == "true"); }
+    else if( line.startsWith("<pbi_makeport>") ){ exProgStruct[0] = readSavedValue("<pbi_makeport>",line); }
+    else if( line.startsWith("<pbi_create>") ){ exProgStruct[1] = readSavedValue("<pbi_create>",line); }
+    else if( line.startsWith("<su_utility>") ){ exProgStruct[2] = readSavedValue("<su_utility>",line); }
   }
   file.close();
   //Now update any missing values in the structures
@@ -108,6 +114,8 @@
 }
 
 void Config::saveSettingsFile(){
+	//exProgStruct=[ pbi_makeport, pbi_create, su_utility ]
+	//detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
   //Get the preferences file
   QFile file(defaultSettings[6]);
   //Open the file, otherwise use defaults
@@ -125,6 +133,10 @@
   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"; }
+  if(exProgStruct[0] != detStruct[0]){ out << "<pbi_makeport>"+exProgStruct[0]+"</pbi_makeport>\n"; }
+  if(exProgStruct[1] != detStruct[1]){ out << "<pbi_create>"+exProgStruct[1]+"</pbi_create>\n"; }
+  if(exProgStruct[2] != detStruct[2]){ out << "<su_utility>"+exProgStruct[2]+"</su_utility>\n"; }
+  if(TFstruct[2]){ out << "<usesignature>TRUE</usesignature>\n"; }
   if(TFstruct[3]){ out << "<usetmpfs>TRUE</usetmpfs>\n"; }
   if(TFstruct[4]){ out << "<usepkgcache>TRUE</usepkgcache>\n"; }
   if(badPackages.length() >0){ out << "<badpackages>"+badPackages.join(";")+"</badpackages>\n"; }
@@ -227,20 +239,36 @@
 
 void Config::setValue(QString var, QString val){
     var = var.toLower();
-    if( !QFile::exists(val) ){ 
-      qDebug() << "WARNING! \""+var+"\" setting could not be changed: desired file does not exist:" + val;
+    if( !val.isEmpty() ){
+      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; }
+      
+    }else{ //reset default value
+	//detStruct=[ pbi_makeport, pbi_create, su_utility, portsDir ]
+      if(var=="pbi_makeport"){ exProgStruct[0]=detStruct[0]; }
+      else if(var=="pbi_create"){ exProgStruct[1]=detStruct[1]; }
+      else if(var=="su_cmd"){ exProgStruct[2]=detStruct[2]; }
+      else if(var=="pbidir"){ valueStruct[0]=defaultSettings[2]; }
+      else if(var=="moduledir"){ valueStruct[1]=defaultSettings[3]; }
+      else if(var=="cachedir"){ valueStruct[2]=defaultSettings[4]; }
+      else if(var=="portsdir"){ valueStruct[3]=detStruct[3]; }
+      else if(var=="icondir"){ valueStruct[4]=defaultSettings[7]; }
+      else if(var=="defaulticon"){ valueStruct[5]=defaultSettings[5]; }
+      else if(var=="sigfile"){ valueStruct[6]=""; }
+      else{ qDebug() << "invalid setvalue requested:" << var; }	    
     }
-    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; }
 
 }
 
@@ -290,7 +318,10 @@
 QString Config::readSavedValue(QString var, QString line){
   //var = "<something>"
   //line = line with the value on it
-  return line.section(var,1,1).section(var.replace("<","</"),0,0).simplified();
+  QString varend = var;
+  varend.replace("<","</");
+  QString out = line.section(var,1,1).section(varend,0,0).simplified();
+  return out;
 }
 
 void Config::checkStructures(){

Modified: users/ken/EasyPBI2/mainGUI.cpp
===================================================================
--- users/ken/EasyPBI2/mainGUI.cpp	2012-11-15 01:29:05 UTC (rev 20230)
+++ users/ken/EasyPBI2/mainGUI.cpp	2012-11-15 01:48:04 UTC (rev 20231)
@@ -3,6 +3,7 @@
 #include "modBuild.h"
 #include "backend.h"
 #include "newModuleDialog.h"
+#include "preferencesDialog.h"
 
 MainGUI::MainGUI(QWidget *parent) :
     QMainWindow(parent),
@@ -122,13 +123,15 @@
 
     //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
+    //Scan for the external utilities needed to build PBI's
+    settings->scanForExternalUtilities();
+    //Load Preferences file if possible
+    settings->loadSettingsFile();
+    //create the EasyPBI directory structure if needed
+    if( !settings->checkDirectoryStructure() ){
 	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);
     }
-    //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 ){
@@ -305,7 +308,6 @@
   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( settings->value("pbidir") );
       if(ui->text_build_log->toPlainText().isEmpty()){ ui->push_build_save->setEnabled(FALSE); }
       else{ ui->push_build_save->setEnabled(TRUE); }
     }
@@ -347,6 +349,16 @@
   this->close();
 }
 
+void MainGUI::on_actionPreferences_triggered(){
+  //Open up the preferences dialog
+  PreferencesDialog dlg(this);
+  //make the dialog modal and wait for it to close
+  dlg.exec(); 
+  //Now reload the saved settings
+  settings->loadSettingsFile();
+  //Now refresh the GUI
+  refreshGUI("all");
+}
 void MainGUI::on_actionPackage_Module_triggered(){
    currentModule->compressModule();
    QMessageBox::information(this,tr("Success"),tr("A copy of the current module has been successfully packaged  within the module directory.") );
@@ -681,7 +693,7 @@
 
 void MainGUI::on_push_resources_add_clicked(){
   //Get the desired file
-  QStringList iFiles = QFileDialog::getOpenFileNames(this, tr("Select Resources"), QDir::homePath() );
+  QStringList iFiles = QFileDialog::getOpenFileNames(this, tr("Select Resources"), settings->value("icondir") );
   //Check that there were file selected
   if(iFiles.isEmpty()){ return; }
   //Now add these files to the module
@@ -1263,7 +1275,7 @@
 void MainGUI::on_push_build_start_clicked(){
   //Check GUI to make sure settings are set before running
   bool gostatus = TRUE;
-  QString outdir = ui->line_build_outputdir->text();
+  QString outdir = settings->value("pbidir");
   if (outdir.isEmpty() ){gostatus=FALSE;}
   //QString sigfile = "";ui->linePBIDigSigFile->text(); //this one can be empty
   QString modDir = currentModule->path();
@@ -1331,8 +1343,8 @@
   //Add the necessary glue to the command to run the pbi build
   cmd.prepend(settings->value("su_cmd")+" \"");
   cmd.append("\"");
-  //qDebug() << "Actual command used:" << cmd;
-  
+  qDebug() << "Actual command used:" << cmd;
+
   //Setup the displays
   ui->push_build_stop->setEnabled(TRUE);
   ui->push_build_save->setEnabled(FALSE);
@@ -1340,6 +1352,7 @@
   ui->push_build_start->setEnabled(FALSE); //disable the button so they do not start more than 1 build at a time
   ui->text_build_log->clear(); //clear the display in case this is not the first run
   ui->line_build_module->setText(currentModule->path());
+  ui->line_build_outputdir->setText(settings->value("pbidir"));
   //Setup Process connections
   p = new QProcess(this);
   p->setProcessChannelMode(QProcess::MergedChannels);

Modified: users/ken/EasyPBI2/mainGUI.h
===================================================================
--- users/ken/EasyPBI2/mainGUI.h	2012-11-15 01:29:05 UTC (rev 20230)
+++ users/ken/EasyPBI2/mainGUI.h	2012-11-15 01:48:04 UTC (rev 20231)
@@ -41,6 +41,7 @@
     void on_actionExit_triggered();
     void on_actionNew_Module_triggered();
     void on_actionLoad_Module_triggered();
+    void on_actionPreferences_triggered();
     void on_actionPackage_Module_triggered();
     void on_actionFreeBSD_Ports_triggered();
     void on_actionPBI_Modules_triggered();

Modified: users/ken/EasyPBI2/preferencesDialog.ui
===================================================================
(Binary files differ)



More information about the Commits mailing list