source: src-qt4/EasyPBI/mainGUI.cpp @ 47239e7

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 47239e7 was 47239e7, checked in by Ken Moore <ken@…>, 18 months ago

Adjust a couple user messages that used to reference the old Ports dialog, and remove a few compiler warnings about unused variables.

  • Property mode set to 100644
File size: 63.5 KB
Line 
1#include "mainGUI.h"
2#include "ui_mainGUI.h"
3#include "modBuild.h"
4#include "backend.h"
5#include "newModuleDialog.h"
6#include "preferencesDialog.h"
7#include "aboutDialog.h"
8
9MainGUI::MainGUI(QWidget *parent) :
10    QMainWindow(parent),
11    ui(new Ui::MainGUI)
12{
13        // NOTE: "plus"/"minus" icons are set in QtDesigner using the current theme
14        //      since none are available in the Qt Embedded resources
15       
16       //Setup Initial state of GUI objects and connect signal/slots
17       ui->setupUi(this);  //load the mainGUI.ui file
18        // Create the module class as necessary
19        currentModule = new ModBuild();
20        // Create the config class
21        settings = new Config();
22        //Setup the Menu items
23        ui->actionExit->setIcon(Backend::icon("close"));
24        ui->actionRefresh_Module->setIcon(Backend::icon("refresh"));
25        //Setup the pushbutton menu lists
26        menu_elOpts.addAction("binary");
27        menu_elOpts.addAction("linux");
28        menu_elOpts.addAction("keep");
29        menu_elOpts.addAction("replace");
30        menu_elOpts.addAction("nocrash");
31        //Setup Toolbar
32        ui->actionNew_Module->setIcon(Backend::icon("new"));
33        ui->actionLoad_Module->setIcon(Backend::icon("load"));
34        line_module = new QLineEdit(this);
35        line_module->setPlaceholderText(tr("No Module Loaded"));
36        line_module->setReadOnly(TRUE);
37        line_module->setFocusPolicy(Qt::NoFocus);
38        ui->toolBar->addWidget(line_module);
39        ui->toolBar->addSeparator();
40        radio_module_port = new QRadioButton(tr("FreeBSD Port"),this);
41        radio_module_port->setEnabled(FALSE);
42        ui->toolBar->addWidget(radio_module_port);
43        radio_module_local = new QRadioButton(tr("Local Sources"),this);
44        radio_module_local->setEnabled(FALSE);
45        ui->toolBar->addWidget(radio_module_local);
46        //Setup Module Editor
47        connect(ui->tabWidget, SIGNAL(currentChanged(int)),this,SLOT(slotModTabChanged(int)) ); //setup to refresh each tab once it is selected
48        // -- pbi.conf tab --
49        ui->push_change_progdir->setIcon(Backend::icon("load"));
50        ui->push_change_makeport->setIcon(Backend::icon("file"));
51        ui->push_addmakeopt->setIcon(Backend::icon("left"));
52        ui->push_addmakeopt->setMenu(&menu_addOpt);
53        connect(&menu_addOpt,SIGNAL(triggered(QAction*)),this,SLOT(slotAddMakeOption(QAction*)) );
54        ui->push_config_save->setIcon(Backend::icon("save"));
55        // -- resources tab --
56        ui->push_resources_savewrapper->setIcon(Backend::icon("save"));
57        connect(ui->listw_resources, SIGNAL(itemSelectionChanged()), this, SLOT(slotResourceChanged()) );
58        connect(ui->push_resources_savewrapper, SIGNAL(clicked()), this, SLOT(slotResourceScriptSaved()) );
59        // -- XDG entries tab --
60        connect(ui->radio_xdg_desktop,SIGNAL(clicked()),this,SLOT(slotXdgTypeChanged()) );
61        connect(ui->radio_xdg_menu,SIGNAL(clicked()),this,SLOT(slotXdgTypeChanged()) );
62        connect(ui->list_xdg_files,SIGNAL(itemSelectionChanged()), this, SLOT(slotXdgFileChanged()) );
63        ui->push_xdg_refresh->setIcon(Backend::icon("refresh"));
64        connect(ui->push_xdg_refresh, SIGNAL(clicked()), this, SLOT(slotXdgTypeChanged()) );
65        ui->push_xdg_exec->setIcon(Backend::icon("left"));
66        ui->push_xdg_exec->setMenu(&menu_bins);
67        connect(&menu_bins, SIGNAL(triggered(QAction*)), this, SLOT(slotAddBin(QAction*)) );
68        ui->push_xdg_savechanges->setIcon(Backend::icon("save"));
69        ui->push_xdg_menu->setIcon(Backend::icon("left"));
70        ui->push_xdg_menu->setMenu(&menu_validMenuCats);
71        connect(&menu_validMenuCats,SIGNAL(triggered(QAction*)),this,SLOT(slotAddMenuCat(QAction*)) );
72        ui->push_xdg_clearentry->setIcon(Backend::icon("file"));
73       
74        // -- Scripts tab --
75        ui->push_scripts_save->setIcon(Backend::icon("save"));
76        ui->push_scripts_create->setIcon(Backend::icon("new"));
77        ui->list_scripts_file->addItems(QStringList() << " ---"+tr("Installation Scripts")+"---" << "pre-portmake.sh" << "post-portmake.sh" << "pre-pbicreate.sh" << "pre-install.sh" << "post-install.sh" << "pre-remove.sh" );
78        connect(ui->list_scripts_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotScriptChanged(int)) );
79        // -- External links tab --
80        ui->push_el_file->setIcon(Backend::icon("left"));
81        ui->push_el_file->setMenu(&menu_el_bins);
82        connect(&menu_el_bins,SIGNAL(triggered(QAction*)),this,SLOT(slotELSetFile(QAction*)) );
83        ui->push_el_filetype->setIcon(Backend::icon("left"));
84        ui->push_el_filetype->setMenu(&menu_elOpts);
85        connect(&menu_elOpts,SIGNAL(triggered(QAction*)),this,SLOT(slotELSetType(QAction*)) );
86        //Setup PBI Builder
87        ui->push_build_stop->setIcon(Backend::icon("close"));
88        ui->push_build_save->setIcon(Backend::icon("save"));
89       
90      SetupDefaults(); //load program defaults
91      refreshGUI("all"); //make items visible/invisible as necessary
92     
93      //Connect "option changed" signals to the respective slot
94      // PBI tab
95      connect(ui->line_progname,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
96      connect(ui->line_progauthor,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
97      connect(ui->line_progversion,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
98      connect(ui->line_progweb,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
99      connect(ui->line_progdir,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
100      connect(ui->line_makeport,SIGNAL(textChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
101      connect(ui->list_progicon,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotOptionChanged(QString)) );
102      connect(ui->edit_makeopts,SIGNAL(textChanged()),this,SLOT(slotOptionChanged()) );
103      connect(ui->check_requiresroot, SIGNAL(clicked()),this,SLOT(slotOptionChanged()) );
104      // Rwsources tab
105      connect(ui->text_resources_script,SIGNAL(textChanged()),this,SLOT(slotResourceScriptChanged()) );
106      // XDG tab
107      connect(ui->line_xdg_name,SIGNAL(textChanged(QString)),this,SLOT(slotXDGOptionChanged(QString)) );
108      connect(ui->line_xdg_mimepatterns,SIGNAL(textChanged(QString)),this,SLOT(slotXDGOptionChanged(QString)) );
109      connect(ui->line_xdg_exec,SIGNAL(textChanged(QString)),this,SLOT(slotXDGOptionChanged(QString)) );
110      connect(ui->line_xdg_menu,SIGNAL(textChanged(QString)),this,SLOT(slotXDGOptionChanged(QString)) );
111      connect(ui->check_xdg_nodisplay,SIGNAL(clicked()),this,SLOT(slotXDGOptionChanged()) );
112      connect(ui->check_xdg_requiresroot,SIGNAL(clicked()),this,SLOT(slotXDGOptionChanged()) );
113      connect(ui->check_xdg_terminal,SIGNAL(clicked()),this,SLOT(slotXDGOptionChanged()) );
114      connect(ui->list_xdg_icon,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotXDGOptionChanged(QString)) );
115      // Scripts tab
116      connect(ui->text_scripts_edit,SIGNAL(textChanged()),this,SLOT(slotScriptModified()) );
117       
118}
119
120MainGUI::~MainGUI()
121{
122  qDebug() << "Shutting down EasyPBI normally";
123}
124
125void MainGUI::slotSingleInstance(){
126  this->showNormal();
127  this->activateWindow();
128  this->raise();
129}
130
131void MainGUI::SetupDefaults(){
132    qDebug() << "Starting up EasyPBI (version "+settings->value("version")+")"; 
133    //Make sure that the program is not being started with root permissions
134    QString id = QProcessEnvironment::systemEnvironment().toStringList().filter("HOME=").join(" ").simplified();
135    if( id.contains("root") ){
136      qDebug() << "EasyPBI should not be run with root permissions! exiting.....";
137      exit(1);
138    }
139
140    //Load the current configuration settings
141    settings->readMachineArch(); //set the 64-bit flag as appropriate
142    //Scan for the external utilities needed to build PBI's
143    settings->scanForExternalUtilities();
144    //Load Preferences file if possible
145    settings->loadSettingsFile();
146    //create the EasyPBI directory structure if needed
147    if( !settings->checkDirectoryStructure() ){
148        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.") );
149        exit(1);
150    }
151    //Pop up a warning box if some external resources are not available
152    bool chkOK = (settings->check("isMakeportAvailable") && settings->check("iscreateAvailable") && settings->check("isSUavailable") );
153    if( !chkOK ){
154        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 settings to correct this deficiency.") );
155    }
156    //Pop up a warning about a missing ports tree
157    if( !settings->check("isPortsAvailable") ){
158        QMessageBox::warning(this, tr("FreeBSD Ports Missing"), tr("The FreeBSD ports tree is missing from your system.")+"\n"+tr("Please open up the EasyPBI settings to correct this deficiency.") );
159    }
160    //Set a couple more internal flags
161    PBI_BUILDING_NOW.clear();
162    PBI_BUILD_TERMINATED=FALSE;
163}
164
165bool MainGUI::isValidPort(QString pPath){
166  bool ok = FALSE;
167  if( QFile::exists(pPath) && QFile::exists(pPath+"/Makefile") && QFile::exists(pPath+"/distinfo") ){
168    ok = TRUE;
169  }
170  return ok;
171}
172
173void MainGUI::refreshGUI(QString item){
174  //Enable/disable the interface appropriately
175 
176  //Stupid check to make sure that a module is actually loaded
177  if( currentModule->path().isEmpty() ){ 
178    ui->actionPackage_Module->setEnabled(FALSE);
179    ui->actionRefresh_Module->setEnabled(FALSE);
180    if(PBI_BUILDING_NOW.isEmpty() ){ui->toolBox->setEnabled(FALSE); return; }
181    else{ 
182      ui->toolBox->setItemEnabled(0,FALSE);
183      ui->toolBox->setItemEnabled(1,TRUE);
184      ui->toolBox->setCurrentIndex(1); 
185      item="pbibuild";
186    }
187  }else{ 
188    ui->toolBox->setEnabled(TRUE); 
189    ui->actionPackage_Module->setEnabled(TRUE); 
190    ui->actionRefresh_Module->setEnabled(TRUE);
191  }
192  //Figure out the type of module that is loaded
193  bool isport = radio_module_port->isChecked();
194  //See if we should refresh everything (default) 
195  bool doall = ( (item == "all") || item.isEmpty() );
196  bool doeditor = (item == "editor"); //also add a flag to just refresh the editor
197  //Refresh the desired tab(s)
198  // ------PBI.CONF------
199  if( doall || doeditor || (item == "pbiconf")){
200    if(isport){
201        ui->line_progversion->setVisible(FALSE); ui->label_progversion->setVisible(FALSE);
202        ui->line_progdir->setVisible(FALSE); ui->push_change_progdir->setVisible(FALSE); ui->label_progdir->setVisible(FALSE);
203        ui->line_makeport->setVisible(TRUE); ui->push_change_makeport->setVisible(TRUE); ui->label_makeport->setVisible(TRUE);
204        ui->edit_makeopts->setVisible(TRUE); ui->push_addmakeopt->setVisible(TRUE); ui->label_makeopts->setVisible(TRUE);
205        ui->list_portbefore->setVisible(TRUE); ui->push_addportbefore->setVisible(TRUE); ui->push_rmportbefore->setVisible(TRUE);ui->label_portbefore->setVisible(TRUE);
206        ui->list_portafter->setVisible(TRUE); ui->push_addportafter->setVisible(TRUE); ui->push_rmportafter->setVisible(TRUE); ui->label_portafter->setVisible(TRUE);
207    }else{
208        ui->line_progversion->setVisible(TRUE); ui->label_progversion->setVisible(TRUE);
209        ui->line_progdir->setVisible(TRUE); ui->push_change_progdir->setVisible(TRUE); ui->label_progdir->setVisible(TRUE);
210        ui->line_makeport->setVisible(FALSE); ui->push_change_makeport->setVisible(FALSE); ui->label_makeport->setVisible(FALSE);
211        ui->edit_makeopts->setVisible(FALSE); ui->push_addmakeopt->setVisible(FALSE); ui->label_makeopts->setVisible(FALSE);
212        ui->list_portbefore->setVisible(FALSE); ui->push_addportbefore->setVisible(FALSE); ui->push_rmportbefore->setVisible(FALSE);ui->label_portbefore->setVisible(FALSE);
213        ui->list_portafter->setVisible(FALSE); ui->push_addportafter->setVisible(FALSE); ui->push_rmportafter->setVisible(FALSE); ui->label_portafter->setVisible(FALSE);
214    }
215    //Display the variables from the currentModule structure
216    // -- check boxes
217    QString chk = currentModule->readValue("requiresroot").toLower();
218    if( (chk=="true") || (chk=="yes") ){ ui->check_requiresroot->setChecked(TRUE); }
219    else{ ui->check_requiresroot->setChecked(FALSE); }
220    // -- line edits
221    ui->line_progname->setText(currentModule->readValue("progname"));
222    ui->line_progversion->setText(currentModule->readValue("progversion"));
223    ui->line_progweb->setText(currentModule->readValue("progweb"));
224    ui->line_progauthor->setText(currentModule->readValue("progauthor"));
225    ui->line_progdir->setText(currentModule->readValue("packagedir"));
226    ui->line_makeport->setText(currentModule->readValue("makeport"));
227    ui->edit_makeopts->setPlainText(currentModule->readValue("makeoptions"));
228    // -- combo boxes (lists)
229    ui->list_portbefore->clear(); ui->list_portafter->clear(); ui->list_progicon->clear();
230    ui->list_portbefore->addItems( currentModule->readValue("makeportbefore").split(" ") );
231    ui->list_portafter->addItems( currentModule->readValue("makeportafter").split(" ") );
232    QStringList icons = currentModule->currentIcons;
233    if(icons.length() > 0){
234      for(int i=0; i<icons.length(); i++){
235        ui->list_progicon->addItem(QIcon(currentModule->path()+"/resources/"+icons[i]),icons[i]);
236      }     
237      int cicon = icons.indexOf(currentModule->readValue("progicon"));
238      if( cicon == -1 ){ 
239              ui->list_progicon->addItem(currentModule->readValue("progicon")); 
240              cicon = icons.indexOf(currentModule->readValue("progicon"));
241      }
242      ui->list_progicon->setCurrentIndex(cicon);
243    }else{
244      ui->list_progicon->addItem(currentModule->readValue("progicon"));
245    }
246    menu_addOpt.clear();
247    QStringList opts = currentModule->readValue("portoptions").split(" ",QString::SkipEmptyParts);
248    if(!opts.isEmpty()){
249      for(int i=0; i<opts.length(); i++){
250        menu_addOpt.addAction(opts[i]);
251      }
252    }
253    ui->push_config_save->setEnabled(FALSE);  //disable the save button until something changes
254  }
255  // -----RESOURCES--------
256  if( doall || doeditor || (item == "resources")){
257    //Get the all the current files in the resources category and add them to the list
258    QStringList rs = currentModule->filesAvailable("resources");
259    //disconnect the signal/slot connection to make sure we don't get an extra phantom refresh
260    disconnect(ui->listw_resources, SIGNAL(itemSelectionChanged()), this, SLOT(slotResourceChanged()) );
261    //Update the Widget
262    ui->listw_resources->clear();
263    ui->listw_resources->addItems(rs);
264    //re-connect the signal/slot
265    connect(ui->listw_resources, SIGNAL(itemSelectionChanged()), this, SLOT(slotResourceChanged()) );
266    //Load the file into the viewers
267    slotResourceChanged();
268  }
269  //------XDG------
270  if( doall || doeditor || (item == "xdg")){
271    slotXdgTypeChanged();
272  }
273  //------SCRIPTS-----
274  if( doall || doeditor || (item == "scripts")){
275    //Update the list of available scripts and determine if one needs to be read
276    bool loadScript = FALSE;
277    QString path = currentModule->path()+"/scripts/";
278    int currentIndex = ui->list_scripts_file->currentIndex();
279    for(int i=1; i< ui->list_scripts_file->count(); i++){ //Skip the first item (is nothing)
280      if( QFile::exists( path+ui->list_scripts_file->itemText(i) ) ){
281        if(i == currentIndex){ loadScript = TRUE; }
282        ui->list_scripts_file->setItemIcon(i,Backend::icon("file"));
283      }else{
284        ui->list_scripts_file->setItemIcon(i,Backend::icon("close"));
285      }
286    }
287    //Update the GUI appropriately
288    if(loadScript){
289      //Read and display the script
290      QStringList contents = ModBuild::readFile(path+ui->list_scripts_file->currentText());
291      ui->text_scripts_edit->setPlainText(contents.join("\n"));
292      //Setup display items
293      ui->push_scripts_create->setVisible(FALSE);
294      ui->push_scripts_remove->setVisible(TRUE);
295      ui->push_scripts_save->setVisible(TRUE);
296      ui->text_scripts_edit->setVisible(TRUE);
297    }else{
298      //Setup display items
299      ui->push_scripts_create->setVisible(TRUE);
300      ui->push_scripts_remove->setVisible(FALSE);
301      ui->push_scripts_save->setVisible(FALSE);
302      ui->text_scripts_edit->setVisible(FALSE);
303    }
304    if(currentIndex == 0){ ui->push_scripts_create->setVisible(FALSE); }
305    ui->push_scripts_save->setEnabled(FALSE); //disable the save button until something changes
306   
307  }
308  //------EXTERNAL-LINKS------
309  if( doall || doeditor || (item == "external-links")){
310    //nothing to make visible/invisible here
311    //Load the external-links file
312    ui->tree_el_view->clear();
313    QStringList cLinks = currentModule->externalLinks();
314    QStringList labels; labels << tr("File") << tr("Link To") << tr("File Type");
315    for( int i=0; i<cLinks.length(); i++ ){
316      QStringList link = cLinks[i].split("\t");
317      ui->tree_el_view->addTopLevelItem(new QTreeWidgetItem(link));
318    }
319    //Clear the input boxes
320    ui->line_el_file->clear();
321    ui->line_el_linkto->clear();
322    ui->line_el_filetype->clear();
323    //update the available binaries
324    menu_el_bins.clear();
325    QStringList cBins = currentModule->currentBins;
326    if(!cBins.isEmpty()){
327      for(int i=0; i<cBins.length(); i++){
328        menu_el_bins.addAction(cBins[i]);
329      } 
330    }
331  }
332  //------FREENAS PLUGINS-------
333  if( doall || doeditor || (item == "freenas")){
334    //nothing to make visible/invisible here
335  }
336  //------PBI BUILDER--------
337  if( doall || (item == "pbibuild")){
338    if(PBI_BUILDING_NOW.isEmpty()){
339      //only change things if there is nothing building at the moment
340      if(ui->text_build_log->toPlainText().isEmpty()){ ui->push_build_save->setEnabled(FALSE); }
341      else{ ui->push_build_save->setEnabled(TRUE); }
342    }
343    ui->push_build_start->setFocus();//make sure the focus starts out on the build button
344  }
345  //------OVERALL SETTINGS------
346  if( doall || doeditor ){
347    //Enable/disable the buttons that require the FreeBSD ports tree
348    if( settings->check("isportsavailable") ){
349      ui->push_change_makeport->setEnabled(TRUE);
350      ui->push_addportbefore->setEnabled(TRUE);
351      ui->push_addportafter->setEnabled(TRUE);
352    }else{
353      ui->push_change_makeport->setEnabled(FALSE);
354      ui->push_addportbefore->setEnabled(FALSE);
355      ui->push_addportafter->setEnabled(FALSE);
356    }
357    //Check for a 64-bit system to enable the 32-bit build option
358    if( settings->check("is64bit") && !currentModule->isLocalPBI ){ ui->check_build_32->setVisible(TRUE); }
359    else{ ui->check_build_32->setVisible(FALSE); ui->check_build_32->setChecked(FALSE); }
360    //Disable tabs that are not used when bulding local PBI's
361    if(currentModule->isLocalPBI){
362        ui->tabWidget->setTabEnabled(5,FALSE);
363    }else{
364        ui->tabWidget->setTabEnabled(5,TRUE);
365    }
366    //Set the default focus on the "load" button
367    this->setFocus();
368  }
369}
370/*----------------------------------
371   MENU OPTIONS
372  -----------------------------------
373*/
374
375void MainGUI::on_actionExit_triggered(){
376  qDebug() << "Close EasyPBI requested";
377  this->close();
378}
379
380void MainGUI::on_actionPreferences_triggered(){
381  //Open up the preferences dialog
382  PreferencesDialog dlg(this);
383  //make the dialog modal and wait for it to close
384  dlg.exec(); 
385  //Now reload the saved settings
386  settings->loadSettingsFile();
387  //Now refresh the GUI
388  refreshGUI("all");
389}
390void MainGUI::on_actionPackage_Module_triggered(){
391   currentModule->compressModule();
392   QMessageBox::information(this,tr("Success"),tr("A copy of the current module has been successfully packaged  within the module directory.") );
393
394}
395
396void MainGUI::on_actionRefresh_Module_triggered(){
397  QString modSel = currentModule->path(); //re-load the current module
398  bool ok = currentModule->loadModule(modSel); 
399  if(ok){ 
400    qDebug() << "Loaded module:"<<modSel;         
401    line_module->setText(modSel.replace(QDir::homePath(),"~")); 
402    if(currentModule->isLocalPBI){ radio_module_local->toggle(); }
403    else{ 
404      radio_module_port->toggle(); //Port PBI
405      if( settings->check("isportsavailable") ){ 
406        currentModule->readPortInformation(settings->value("portsdir")+"/"+currentModule->readValue("makeport"));
407      }
408    }
409    refreshGUI("all");
410  }
411}
412
413void MainGUI::on_actionFreeBSD_Ports_triggered(){
414  QString port;
415  if(!line_module->text().isEmpty()){
416        //Get the currently selected port
417        port = currentModule->readValue("makeport");
418  }
419  QString target_url = "http://www.freshports.org/" + port;
420  qDebug() << "Opening URL:" << target_url; 
421  target_url.prepend("xdg-open ");
422  system(target_url.toUtf8()); 
423}
424
425void MainGUI::on_actionPBI_Modules_triggered(){
426  //Open the PC-BSD wiki to the module builders guide
427   QString target_url = "http://wiki.pcbsd.org/index.php/PBI_Module_Builder_Guide";
428   qDebug() << "Opening URL:" << target_url; 
429   target_url.prepend("xdg-open ");
430   system(target_url.toUtf8());
431}
432
433void MainGUI::on_actionAbout_EasyPBI_triggered(){
434  aboutDialog dlg(this,settings->value("version"));
435  dlg.exec();
436}
437
438
439/*----------------------------------
440   TOOLBAR OPTIONS
441  -----------------------------------
442*/
443void MainGUI::on_actionNew_Module_triggered(){
444  qDebug() << "New Module triggered";
445  //Create and run the new dialog
446  NewModuleDialog* dlg = new NewModuleDialog(this, settings->value("portsdir"));
447  dlg->setDefaultIconFile(settings->value("defaulticon"));
448  dlg->exec();
449  //Determine if the action was cancelled
450  if( dlg->isAccepted ){
451    //Now create the new module
452    QString modPath, modType, modBase, oldIconPath;
453    modType = dlg->moduleType;
454    modBase = dlg->moduleData;
455    oldIconPath = dlg->moduleIcon;
456    modPath = settings->value("moduledir")+"/"+modBase.section("/",-1).toLower();
457          //modPath ->full path, modType->"local"or "port", modBase->makeport or packagedir
458    bool ok = currentModule->createNewModule(modPath,modType,modBase);
459    if(!ok){
460      QMessageBox::warning(this,tr("EasyPBI: Permissions Error"), tr("Could not create PBI module. Please check the directory permissions and try again."));
461    }else{
462      //MODULE CREATED, NOW FILL IT APPROPRIATELY
463      //Icon
464      currentModule->addResource(FALSE, oldIconPath); //copy the icon file into the module
465      currentModule->writeValue("progicon", oldIconPath.section("/",-1) );
466      //Load Port info if appropriate
467      if(currentModule->isPortPBI){
468        radio_module_port->toggle();
469        //Use the port info if possible
470        if( settings->check("isportsAvailable") ){
471          currentModule->readPortInformation(settings->value("portsdir")+"/"+modBase);
472          //Now save the detected information into the module
473          currentModule->writeValue("progname", currentModule->readValue("portname"));
474          currentModule->writeValue("progweb", currentModule->readValue("portwebsite"));
475          currentModule->writeValue("progauthor", currentModule->readValue("portauthor"));
476          currentModule->writePBIconf();
477        }
478      }else if(currentModule->isLocalPBI){
479        radio_module_local->toggle();
480             
481      }
482      //Now let the UI reflect the new module
483      line_module->setText( currentModule->path().replace(QDir::homePath(),"~") );     
484    }
485  }
486  //Refresh the UI
487  refreshGUI("all");
488  delete dlg;
489}
490
491void MainGUI::on_actionLoad_Module_triggered(){
492  QString modSel = QFileDialog::getExistingDirectory(this, tr("Select Module"), settings->value("moduledir"));
493  if(modSel.isEmpty()){return;} //action cancelled or closed
494  bool ok = currentModule->loadModule(modSel);
495  if(ok){ 
496    qDebug() << "Loaded module:"<<modSel;         
497    line_module->setText(modSel.replace(QDir::homePath(),"~")); 
498    if(currentModule->isLocalPBI){ radio_module_local->toggle(); }
499    else{ 
500      radio_module_port->toggle(); //Port PBI
501      if( settings->check("isportsavailable") ){ 
502        currentModule->readPortInformation(settings->value("portsdir")+"/"+currentModule->readValue("makeport"));
503      }
504    }
505    refreshGUI("all");
506  }
507}
508
509/*----------------------------------
510   MODULE EDITOR OPTIONS
511  -----------------------------------
512*/
513void MainGUI::slotModTabChanged(int newtab){
514  switch(newtab){
515    case 0:
516            refreshGUI("pbiconf"); break;
517    case 1:
518            refreshGUI("resources"); break;
519    case 2:
520            refreshGUI("xdg"); break;
521    case 3:
522            refreshGUI("scripts"); break;
523    case 4:
524            refreshGUI("external-links"); break;
525    case 5:
526            refreshGUI("freenas"); break;
527    default:
528            refreshGUI("editor"); break; //do all the module editor tabs
529  }       
530}
531
532/*----------------------------------
533   PBI.CONF OPTIONS
534  -----------------------------------
535*/
536void MainGUI::on_push_change_makeport_clicked(){
537  if( !settings->check("isportsavailable") ){
538    //No ports tree available
539    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."));
540    return;
541  }
542  //Prompt for a new port
543  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
544  if(portSel.isEmpty()){return;} //action cancelled or closed   
545  //Check if the port is valid
546  if( !isValidPort(portSel) ){
547    QMessageBox::warning(this,tr("EasyPBI: Invalid Port"), tr("The directory selected is not a valid FreeBSD port. Please select a port directory which contains the appropriate Makefile and distinfo."));
548    return;
549  }
550  //Save the port info to the GUI
551  ui->line_makeport->setText(portSel.remove(settings->value("portsdir")+"/"));
552  ui->push_config_save->setEnabled(TRUE);
553}
554
555void MainGUI::on_push_change_progdir_clicked(){
556  //Prompt for a new directory
557  QString dirSel = QFileDialog::getExistingDirectory(this, tr("Select Package Directory"), QDir::homePath());
558  if(dirSel.isEmpty()){return;} //action cancelled or closed   
559  //Save the port info to the GUI
560  ui->line_progdir->setText(dirSel);
561  ui->push_config_save->setEnabled(TRUE);
562}
563
564void MainGUI::slotAddMakeOption(QAction* act){
565  qDebug() << "Trying to add build option:" << act->text();
566  QString opt = act->text();
567  if(opt.isEmpty() ){ return; } //Do nothing if nothing selected
568  //Check whther the option is set or unset
569  QString typ = opt.section("_",0,0,QString::SectionSkipEmpty).toLower(); //get the type
570  opt = opt.section("_",1,50,QString::SectionSkipEmpty); //trim off the type of setting
571  QString chk = currentModule->readValue("makeport").section("/",-1);
572  bool isSet;
573  if(typ == "with"){chk.append("_SET"); isSet=TRUE;}
574  else if(typ=="without"){chk.append("_UNSET"); isSet=FALSE;}
575  else{ qDebug() << "Error: Unknown option type:"<<typ<<"option:"<<opt; return; }
576  //Now read the current option settings
577  QStringList curr = ui->edit_makeopts->toPlainText().split("\n"); //split according to lines
578  bool found = FALSE;
579  for(int i=0; i<curr.length(); i++){
580    if(curr[i].contains(chk) ){ //look for optionsNG framework
581      found = TRUE;         
582      QStringList cOpts = curr[i].split(" ",QString::SkipEmptyParts);
583      if( !cOpts.contains(opt) ){
584        //Not found, add it to the end of the list
585        cOpts << opt;
586        curr[i] = cOpts.join(" ");
587      }
588    }else if(curr[i].contains(opt)){ //look for legacy options framework
589      QStringList cOpts = curr[i].split(" ",QString::SkipEmptyParts);
590      int index = cOpts.indexOf(opt);
591      if(index != -1){ //option currently set somehow
592        found = TRUE; 
593        if(isSet){ //option should be set
594          if( cOpts[index].contains("WITH_"+opt) ){} //Already set
595          else if( cOpts[index].contains("WITHOUT_"+opt) ){ cOpts[index] = "WITH_"+opt+"=true"; }
596          else if( curr[i].contains(chk.replace("_SET","_UNSET")) ){ cOpts.removeAt(index); found=FALSE;} //Remove the inverse option if it is set
597        }else{ //options should be unset
598          if( cOpts[index].contains("WITHOUT_"+opt) ){} //Already set
599          else if( cOpts[index].contains("WITH_"+opt) ){ cOpts[index] = "WITHOUT_"+opt+"=true"; }
600          else if( curr[i].contains(chk.replace("_UNSET","_SET")) ){ cOpts.removeAt(index); found=FALSE;} //Remove the inverse option if it is set
601        }
602        curr[i] = cOpts.join(" "); //put the line back together
603      }
604    } //end checking different options frameworks
605  } // end loop over lines
606  if(!found){
607    //Append the option to the end on a new line
608    curr << chk+"= "+opt;
609  }
610  //Now put the new options list back onto the GUI
611  ui->edit_makeopts->setPlainText(curr.join("\n"));
612  ui->push_config_save->setEnabled(TRUE);
613}
614
615void MainGUI::on_push_addportbefore_clicked(){
616  if( !settings->check("isportsavailable") ){
617    //No ports tree available
618    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."));
619  }
620  //Prompt for a new port
621  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
622  if(portSel.isEmpty()){return;} //action cancelled or closed   
623  //Check if the port is valid
624  if( !isValidPort(portSel) ){
625    QMessageBox::warning(this,tr("EasyPBI: Invalid Port"), tr("The directory selected is not a valid FreeBSD port. Please select a port directory which contains the appropriate Makefile and distinfo files."));
626    return;
627  }
628  //Save the port info to the GUI
629  if(ui->list_portbefore->count() == 1 && ui->list_portbefore->currentText().isEmpty() ){ ui->list_portbefore->clear(); }
630  ui->list_portbefore->addItem(portSel.remove(settings->value("portsdir")+"/"));
631  ui->push_config_save->setEnabled(TRUE);
632}
633
634void MainGUI::on_push_rmportbefore_clicked(){
635  int index = ui->list_portbefore->currentIndex();
636  if(index != -1){
637    ui->list_portbefore->removeItem(index);
638  }
639  ui->push_config_save->setEnabled(TRUE);
640}
641
642void MainGUI::on_push_addportafter_clicked(){
643  if( !settings->check("isportsavailable") ){
644    //No ports tree available
645    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."));
646  }
647  //Prompt for a new port
648  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), settings->value("portsdir"));
649  if(portSel.isEmpty()){return;} //action cancelled or closed   
650  //Check if the port is valid
651  if( !isValidPort(portSel) ){
652    QMessageBox::warning(this,tr("EasyPBI: Invalid Port"), tr("The directory selected is not a valid FreeBSD port. Please select a port directory which contains the appropriate Makefile and distinfo files."));
653    return;
654  }
655  //Save the port info to the GUI
656  if(ui->list_portafter->count() == 1 && ui->list_portafter->currentText().isEmpty() ){ ui->list_portafter->clear(); }
657  ui->list_portafter->addItem(portSel.remove(settings->value("portsdir")+"/"));
658  ui->push_config_save->setEnabled(TRUE);
659}
660
661void MainGUI::on_push_rmportafter_clicked(){
662  int index = ui->list_portafter->currentIndex();
663  if(index != -1){
664    ui->list_portafter->removeItem(index);
665  }
666  ui->push_config_save->setEnabled(TRUE);
667}
668
669void MainGUI::on_push_config_save_clicked(){
670  //Save the current settings to the backend structures
671    //global settings for all modules
672    currentModule->writeValue("progname",ui->line_progname->text());
673    currentModule->writeValue("progweb",ui->line_progweb->text());
674    currentModule->writeValue("progauthor",ui->line_progauthor->text());
675    currentModule->writeValue("progicon",ui->list_progicon->currentText());
676    if(ui->check_requiresroot->isChecked()){ currentModule->writeValue("requiresroot", "true"); }
677    else{ currentModule->writeValue("requiresroot","false"); }
678    //Module-dependant settings
679    bool newport = FALSE;
680    if( radio_module_port->isChecked() ){ //FreeBSD port module
681        if(currentModule->readValue("makeport") != ui->line_makeport->text()){ newport=TRUE; }
682        currentModule->writeValue("makeport",ui->line_makeport->text());
683        currentModule->writeValue("makeoptions",ui->edit_makeopts->toPlainText());
684        QString tmp;
685        for(int i=0; i < ui->list_portbefore->count(); i++){
686          tmp.append(" "+ui->list_portbefore->itemText(i) );
687        }
688        currentModule->writeValue("makeportbefore",tmp.simplified());
689        tmp.clear();
690        for(int i=0; i < ui->list_portafter->count(); i++){
691          tmp.append(" "+ui->list_portafter->itemText(i) );
692        }
693        currentModule->writeValue("makeportafter",tmp.simplified());
694       
695    }else{ //local sources module
696        currentModule->writeValue("packagedir",ui->line_progdir->text());
697        currentModule->writeValue("progversion",ui->line_progversion->text());
698    }
699  //save the new settings to pbi.conf
700  bool ok = currentModule->writePBIconf();
701  if(!ok){
702    //Display a warning that the file could not be saved
703    qDebug() << "Error: pbi.conf could not be written:" << currentModule->path()+"/pbi.conf";
704    QMessageBox::warning(this,tr("EasyPBI Error"), tr("The PBI configuration file could not be saved. Please check your file permissions before trying again."));
705  }else if(newport){
706    //Refresh the port information if the main port changed
707    currentModule->readPortInformation(settings->value("portsdir")+"/"+ui->line_makeport->text());
708    refreshGUI("pbiconf");
709  }
710}
711
712void MainGUI::slotOptionChanged(QString tmp){
713  tmp.clear(); //just to remove compiler warning about unused variable
714  ui->push_config_save->setEnabled(TRUE);       
715}
716
717/*------------------------------------------------
718   RESOURCE EDITOR OPTIONS
719  -------------------------------------------------
720*/
721void MainGUI::slotResourceChanged(){
722  //Get the current file selected
723  QString cfile;
724  if(ui->listw_resources->currentRow() != -1){ cfile = ui->listw_resources->currentItem()->text(); }
725  if(cfile.isEmpty()){ //no item selected
726    ui->push_resources_savewrapper->setVisible(FALSE);
727    ui->text_resources_script->setVisible(FALSE);
728    ui->label_resources_description->setVisible(FALSE);
729    ui->label_resources_icon->setVisible(FALSE);
730         
731  }else{ //item selected
732    QString path = currentModule->path() + "/resources/";
733    if( cfile.endsWith(".png") || cfile.endsWith(".jpg") ){
734      //Image file, show full size
735      QPixmap img(path+cfile);
736      ui->label_resources_icon->setPixmap(img);
737      ui->label_resources_icon->setVisible(TRUE);
738      QString desc = QString::number(img.width()) +" x "+QString::number(img.height())+" "+cfile.section(".",-1).toUpper();
739      ui->label_resources_description->setText(desc);
740      ui->label_resources_description->setVisible(TRUE);
741      //hide the other widgets
742      ui->push_resources_savewrapper->setVisible(FALSE);
743      ui->text_resources_script->setVisible(FALSE);
744    }else{
745      ui->push_resources_savewrapper->setVisible(TRUE);
746      QStringList contents = ModBuild::readFile(path+cfile);
747      ui->text_resources_script->clear();
748      ui->text_resources_script->setText(contents.join("\n"));
749      ui->text_resources_script->setVisible(TRUE);
750      //hide the other widgets
751      ui->label_resources_description->setVisible(FALSE);
752      ui->label_resources_icon->setVisible(FALSE);
753    }
754  }
755  ui->push_resources_savewrapper->setEnabled(FALSE);
756 
757}
758
759void MainGUI::on_push_resources_add_clicked(){
760  //Get the desired file
761  QStringList iFiles = QFileDialog::getOpenFileNames(this, tr("Select Resources"), settings->value("icondir") );
762  //Check that there were file selected
763  if(iFiles.isEmpty()){ return; }
764  //Now add these files to the module
765  for(int i=0; i<iFiles.length(); i++){
766    currentModule->addResource(FALSE,iFiles[i]);
767  }
768  //Now update the GUI
769  refreshGUI("resources");
770}
771
772void MainGUI::on_push_resources_remove_clicked(){
773  //Get the currently selected resource
774  QString cfile;
775  if(ui->listw_resources->currentRow() != -1){ cfile = ui->listw_resources->currentItem()->text(); }
776  //Check that there is something selected 
777  if(cfile.isEmpty()){ return; }
778  //Remove the resource
779  if(currentModule->removeResource(cfile)){
780      qDebug() << "Removed Resource:" << cfile;
781  }else{
782      qDebug() << "Error: Could not remove resource:"<<cfile;
783  }
784  //Refresh the GUI
785  refreshGUI("resources");
786}
787
788void MainGUI::on_push_resources_mkwrapper_clicked(){
789  //Get the desired filename for the wrapper script
790  bool ok;
791  QString cFile = QInputDialog::getText(this, tr("New Wrapper Script"), tr("Filename")+":", QLineEdit::Normal, "",&ok);
792  //Check for a valid input
793  if(!ok || cFile.isEmpty()){ return; }
794  //Now create the new file
795  currentModule->addResource(TRUE,cFile);
796  //Refresh the GUI
797  refreshGUI("resources");
798}
799
800void MainGUI::slotResourceScriptSaved(){
801  //get the current file and path
802  QString cfile;
803  if(ui->listw_resources->currentRow() != -1){ cfile = ui->listw_resources->currentItem()->text(); }
804  if(cfile.isEmpty()){ return; } // do nothing if no file selected
805  QString filePath = currentModule->path() + "/resources/" + cfile;
806  //Read the current text for the resource
807  QStringList contents = ui->text_resources_script->toPlainText().split("\n");
808  //overwrite the resource with the new contents
809  ModBuild::createFile(filePath,contents);
810  ui->push_resources_savewrapper->setEnabled(FALSE);
811}
812
813void MainGUI::slotResourceScriptChanged(){
814  ui->push_resources_savewrapper->setEnabled(TRUE);     
815}
816/*------------------------------------------------
817   XDG EDITOR OPTIONS
818  -------------------------------------------------
819*/
820void MainGUI::slotXdgTypeChanged(){
821  //Update the file list appropriately
822  if(ui->radio_xdg_desktop->isChecked()){
823    //update the files available
824    ui->list_xdg_files->clear();
825    ui->list_xdg_files->addItems(currentModule->filesAvailable("xdg-desktop"));
826    //Set the visibility
827        //Current file
828        ui->label_xdg_name->setVisible(TRUE); ui->line_xdg_name->setVisible(TRUE);
829        ui->label_xdg_exec->setVisible(TRUE); ui->line_xdg_exec->setVisible(TRUE); ui->push_xdg_exec->setVisible(TRUE);
830        ui->label_xdg_icon->setVisible(TRUE); ui->list_xdg_icon->setVisible(TRUE);
831        ui->label_xdg_menu->setVisible(FALSE); ui->line_xdg_menu->setVisible(FALSE); ui->push_xdg_menu->setVisible(FALSE);
832        ui->check_xdg_nodisplay->setVisible(TRUE);
833        ui->check_xdg_terminal->setVisible(TRUE);
834        ui->label_xdg_mimepatterns->setVisible(FALSE); ui->line_xdg_mimepatterns->setVisible(FALSE);
835       
836  }else if(ui->radio_xdg_menu->isChecked()){
837    //update the files available
838    ui->list_xdg_files->clear();
839    ui->list_xdg_files->addItems(currentModule->filesAvailable("xdg-menu"));     
840    //Set the visibility
841        //Current file
842        ui->label_xdg_name->setVisible(TRUE); ui->line_xdg_name->setVisible(TRUE);
843        ui->label_xdg_exec->setVisible(TRUE); ui->line_xdg_exec->setVisible(TRUE); ui->push_xdg_exec->setVisible(TRUE);
844        ui->label_xdg_icon->setVisible(TRUE); ui->list_xdg_icon->setVisible(TRUE);
845        ui->label_xdg_menu->setVisible(TRUE); ui->line_xdg_menu->setVisible(TRUE); ui->push_xdg_menu->setVisible(TRUE);
846        ui->check_xdg_nodisplay->setVisible(TRUE);
847        ui->check_xdg_terminal->setVisible(TRUE);
848        ui->label_xdg_mimepatterns->setVisible(TRUE); ui->line_xdg_mimepatterns->setVisible(TRUE);
849       
850  }
851  //Select the first file in the list if one is available
852  if( ui->list_xdg_files->count() > 0){ ui->list_xdg_files->setCurrentRow(0); }
853  //Update the program icon list for new entries
854  //QStringList icons = currentModule->currentIcons;
855
856  //Update the buttons that only need a refresh when the type changes (such as menu's)
857  //Available binaries pushbuttons
858  menu_bins.clear();
859  QStringList cBins = currentModule->currentBins;
860  if(!cBins.isEmpty()){
861    for(int i=0; i<cBins.length(); i++){
862      menu_bins.addAction(cBins[i]);
863    } 
864  }
865  //Menu categories
866  QString recMenu = currentModule->readValue("portmenucategory");
867  QStringList cats = currentModule->validMenuCategories;
868  menu_validMenuCats.clear();
869  for(int i=0; i<cats.length(); i++){
870    if(recMenu==cats[i]){ //Add an icon showing the recommended menu category
871      menu_validMenuCats.addAction(Backend::icon("start"),cats[i]);     
872    }else{
873      menu_validMenuCats.addAction(cats[i]);
874    }
875  }
876  //Now update read the currently selected file
877  slotXdgFileChanged();
878}
879
880void MainGUI::slotXdgFileChanged(){     
881  bool clearUI =FALSE;
882  if(ui->list_xdg_files->currentRow() == -1){ clearUI=TRUE; }
883
884  //Reset the icon list
885  ui->list_xdg_icon->clear();
886  QStringList icons = currentModule->currentIcons;
887  if(icons.length() > 0){
888      for(int i=0; i<icons.length(); i++){
889        ui->list_xdg_icon->addItem(QIcon(currentModule->path()+"/resources/"+icons[i]),icons[i]);
890      }     
891  }
892  //Get the selected file
893  QString file;
894  if( !clearUI ){ file = ui->list_xdg_files->currentItem()->text(); }
895  if( clearUI || file.isEmpty() ){
896    //Clear the UI lines
897    ui->line_xdg_name->clear();
898    ui->line_xdg_exec->clear();
899    ui->line_xdg_menu->clear();
900    ui->line_xdg_mimepatterns->clear();
901    ui->check_xdg_terminal->setChecked(FALSE);
902    ui->check_xdg_nodisplay->setChecked(FALSE);
903    ui->check_requiresroot->setChecked(FALSE);
904    ui->push_xdg_savechanges->setEnabled(FALSE);
905    ui->push_xdg_savenew->setEnabled(FALSE);
906    //Make sure we don't have any of the structures loaded from previously
907    currentModule->loadDesktop("");
908    currentModule->loadMenu("");
909    currentModule->loadMime("");
910    //Now return
911    return; 
912  }
913  //Now setup the UI as appropriate
914  if(ui->radio_xdg_desktop->isChecked()){
915    //Load the file
916    currentModule->loadDesktop(file);
917    //update the file info on the GUI
918    ui->line_xdg_name->setText( currentModule->readValue("desktopname") );
919    ui->line_xdg_exec->setText( currentModule->readValue("desktopexec") ); 
920    //comboboxes
921    int cicon = icons.indexOf(currentModule->readValue("desktopicon"));
922    if( cicon == -1 ){ 
923      ui->list_xdg_icon->addItem(currentModule->readValue("desktopicon")); 
924      cicon = icons.indexOf(currentModule->readValue("desktopicon"));
925    }
926    ui->list_xdg_icon->setCurrentIndex(cicon);
927
928    //Checkboxes
929    QString chk = currentModule->readValue("desktopterminal").toLower();
930    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_terminal->setChecked(TRUE); }
931    else{ ui->check_xdg_terminal->setChecked(FALSE); }
932    chk = currentModule->readValue("desktopnodisplay").toLower();
933    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_nodisplay->setChecked(TRUE); }
934    else{ ui->check_xdg_nodisplay->setChecked(FALSE); }
935    chk = currentModule->readValue("desktoprequiresroot").toLower();
936    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_requiresroot->setChecked(TRUE); }
937    else{ ui->check_xdg_requiresroot->setChecked(FALSE); }
938       
939  }else if(ui->radio_xdg_menu->isChecked()){
940    //Load the file
941    currentModule->loadMenu(file);
942    //update the file info on the GUI
943    ui->line_xdg_name->setText( currentModule->readValue("menuname") );
944    ui->line_xdg_exec->setText( currentModule->readValue("menuexec") ); 
945    ui->line_xdg_menu->setText( currentModule->readValue("menucategories") );
946    //comboboxes
947          //icons
948    int cicon = icons.indexOf(currentModule->readValue("menuicon"));
949    if( cicon == -1 ){ 
950      ui->list_xdg_icon->addItem(currentModule->readValue("menuicon")); 
951      cicon = icons.indexOf(currentModule->readValue("menuicon"));
952    }
953    ui->list_xdg_icon->setCurrentIndex(cicon);
954   
955    //Checkboxes
956    QString chk = currentModule->readValue("menuterminal").toLower();
957    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_terminal->setChecked(TRUE); }
958    else{ ui->check_xdg_terminal->setChecked(FALSE); }
959    chk = currentModule->readValue("menunodisplay").toLower();
960    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_nodisplay->setChecked(TRUE); }
961    else{ ui->check_xdg_nodisplay->setChecked(FALSE); }
962    chk = currentModule->readValue("menurequiresroot").toLower();
963    if( (chk == "true") || (chk=="yes") ){ ui->check_xdg_requiresroot->setChecked(TRUE); }
964    else{ ui->check_xdg_requiresroot->setChecked(FALSE); }
965   
966    //Load the XDG-MIME file associations
967    QString mime = currentModule->readValue("menumimetype");
968    QStringList mimeavailable = currentModule->filesAvailable("xdg-mime");
969    bool found = FALSE;
970    for( int i=0; i<mimeavailable.length(); i++){
971      currentModule->loadMime(mimeavailable[i]);
972      if(currentModule->readValue("mimetype") == mime){
973        found = TRUE;
974        break;
975      }
976    }
977    //qDebug() << "mimetype detected:" << mime;
978    if(found){
979      ui->line_xdg_mimepatterns->setText( currentModule->readValue("mimepatterns") ); 
980    }else{
981      currentModule->loadMime(""); //Make sure we don't have any mime file loaded
982      ui->line_xdg_mimepatterns->clear();
983    }
984   
985  }else{
986    //do nothing, unknown radio button selected (or none)
987  }
988  ui->push_xdg_savechanges->setEnabled(FALSE);
989  ui->push_xdg_savenew->setEnabled(FALSE);
990}
991
992void MainGUI::slotAddMenuCat(QAction* act){
993  //get the selected menu category
994  QString newcat = act->text();
995  //Read the current categories
996  QStringList oldcats = ui->line_xdg_menu->text().split(";", QString::SkipEmptyParts);
997  for(int i=0; i<oldcats.length(); i++){
998    oldcats[i] = oldcats[i].simplified();
999    if(oldcats[i] == newcat){return;} //category already in the list, do nothing
1000  }
1001  //Add the item
1002  oldcats << newcat;
1003  //Now replace the line onto the GUI
1004  ui->line_xdg_menu->setText(oldcats.join("; "));
1005}
1006
1007void MainGUI::slotAddBin(QAction* act){
1008  //replace the current executable with the new one
1009  ui->line_xdg_exec->setText(act->text().section("/",-1) );     
1010}
1011
1012void MainGUI::on_push_xdg_remove_clicked(){
1013  //Figure out if a file is selected
1014  if( ui->list_xdg_files->currentItem()->text().isEmpty() ){ return; }
1015  //Now remove the file
1016  bool ok = FALSE;
1017  if( ui->radio_xdg_desktop->isChecked() ){
1018    ok = currentModule->removeDesktop();
1019  }else if( ui->radio_xdg_menu->isChecked() ){
1020    ok = currentModule->removeMenu();
1021  }
1022  //Now inform the user if there was an error
1023  if(!ok){
1024    QMessageBox::warning(this, tr("EasyPBI Error"), tr("Could not remove the XDG entry.")+"\n"+tr("Check the file permissions and try again") );
1025  }
1026  //Now refresh the GUI
1027  refreshGUI("xdg");
1028 
1029}
1030
1031void MainGUI::on_push_xdg_savechanges_clicked(){
1032  //save the current UI settings to the module structure then save the file
1033  bool ok = FALSE;
1034  if( ui->radio_xdg_desktop->isChecked() ){
1035    currentModule->writeValue("desktopname",ui->line_xdg_name->text());
1036    currentModule->writeValue("desktopgenericname",ui->line_xdg_name->text().toLower());
1037    currentModule->writeValue("desktopexec",ui->line_xdg_exec->text());
1038    currentModule->writeValue("desktopicon",ui->list_xdg_icon->currentText());
1039    QString checked = "false";
1040    if(ui->check_xdg_terminal->isChecked()){ checked="true"; }
1041    currentModule->writeValue("desktopterminal",checked);
1042    checked = "false";
1043    if(ui->check_xdg_nodisplay->isChecked()){ checked="true"; }
1044    currentModule->writeValue("desktopnodisplay",checked);
1045    checked = "false";
1046    if(ui->check_xdg_requiresroot->isChecked()){ checked="true"; }
1047    currentModule->writeValue("desktoprequiresroot", checked);
1048    //Now save the file
1049    ok = currentModule->writeDesktop();
1050   
1051  }else if( ui->radio_xdg_menu->isChecked() ){
1052    currentModule->writeValue("menuname",ui->line_xdg_name->text());
1053    currentModule->writeValue("menugenericname",ui->line_xdg_name->text().toLower());
1054    currentModule->writeValue("menuexec",ui->line_xdg_exec->text());
1055    currentModule->writeValue("menuicon",ui->list_xdg_icon->currentText());
1056    currentModule->writeValue("menucategories", ui->line_xdg_menu->text());
1057    QString checked = "false";
1058    if(ui->check_xdg_terminal->isChecked()){ checked="true"; }
1059    currentModule->writeValue("menuterminal",checked);
1060    checked = "false";
1061    if(ui->check_xdg_nodisplay->isChecked()){ checked="true"; }
1062    currentModule->writeValue("menunodisplay",checked);
1063    checked = "false";
1064    if(ui->check_xdg_requiresroot->isChecked()){ checked="true"; }
1065    currentModule->writeValue("menurequiresroot", checked);
1066    //Setup the mime type associations as appropriate
1067    checkMime();
1068    //Now save the file
1069    ok = currentModule->writeMenu();   
1070  }
1071  //Now inform the user if there was an error
1072  if(!ok){
1073    QMessageBox::warning(this, tr("EasyPBI Error"), tr("Could not save the changes to the XDG entry.")+"\n"+tr("Check the file permissions and try again") );
1074  }
1075  //Now refresh the GUI
1076  //refreshGUI("xdg"); //refresh the entire tab
1077  slotXdgFileChanged(); //only update the proper half of the tab
1078}
1079
1080void MainGUI::on_push_xdg_savenew_clicked(){
1081  //Get the filename we want to save
1082  QString filename;
1083  //Now check that the filename does not already exist
1084  QStringList cFiles;
1085  if(ui->radio_xdg_desktop->isChecked() ){
1086    filename = ui->line_xdg_exec->text().section("/",-1);
1087    cFiles = currentModule->filesAvailable("xdg-desktop").replaceInStrings(".desktop","");
1088  }else if(ui->radio_xdg_menu->isChecked() ){
1089    filename = ui->line_xdg_exec->text().section("/",-1);
1090    cFiles = currentModule->filesAvailable("xdg-menu").replaceInStrings(".desktop","");
1091  }
1092  if(filename.isEmpty()){ return;}
1093 
1094  if(cFiles.indexOf(filename) != -1){
1095    int num = 1;
1096    while(cFiles.indexOf(filename+QString::number(num)) != -1){ num++; }
1097    filename.append( QString::number(num) );
1098  }
1099  //save the current UI settings to the module structure then save the file
1100  bool ok = FALSE;
1101  if( ui->radio_xdg_desktop->isChecked() ){
1102    currentModule->loadDesktop(filename+".desktop"); //get the new file ready
1103    currentModule->writeValue("desktopname",ui->line_xdg_name->text());
1104    currentModule->writeValue("desktopgenericname",ui->line_xdg_name->text().toLower());
1105    currentModule->writeValue("desktopexec",ui->line_xdg_exec->text());
1106    currentModule->writeValue("desktopicon",ui->list_xdg_icon->currentText());
1107    QString checked = "false";
1108    if(ui->check_xdg_terminal->isChecked()){ checked="true"; }
1109    currentModule->writeValue("desktopterminal",checked);
1110    checked = "false";
1111    if(ui->check_xdg_nodisplay->isChecked()){ checked="true"; }
1112    currentModule->writeValue("desktopnodisplay",checked);
1113    checked = "false";
1114    if(ui->check_xdg_requiresroot->isChecked()){ checked="true"; }
1115    currentModule->writeValue("desktoprequiresroot", checked);
1116    //Now save the file
1117    ok = currentModule->writeDesktop();
1118   
1119  }else if( ui->radio_xdg_menu->isChecked() ){
1120    currentModule->loadMenu(filename+".desktop"); //get the new file ready
1121    //Update the MIME associations
1122    checkMime();
1123    //Save the MENU values
1124    currentModule->writeValue("menuname",ui->line_xdg_name->text());
1125    currentModule->writeValue("menugenericname",ui->line_xdg_name->text().toLower());
1126    currentModule->writeValue("menuexec",ui->line_xdg_exec->text());
1127    currentModule->writeValue("menuicon",ui->list_xdg_icon->currentText());
1128    currentModule->writeValue("menucategories", ui->line_xdg_menu->text());
1129    QString checked = "false";
1130    if(ui->check_xdg_terminal->isChecked()){ checked="true"; }
1131    currentModule->writeValue("menuterminal",checked);
1132    checked = "false";
1133    if(ui->check_xdg_nodisplay->isChecked()){ checked="true"; }
1134    currentModule->writeValue("menunodisplay",checked);
1135    checked = "false";
1136    if(ui->check_xdg_requiresroot->isChecked()){ checked="true"; }
1137    currentModule->writeValue("menurequiresroot", checked);
1138    //Now save the file
1139    ok = currentModule->writeMenu();   
1140  }
1141  //Now inform the user if there was an error
1142  if(!ok){
1143    QMessageBox::warning(this, tr("EasyPBI Error"), tr("Could not save the changes to the XDG entry.")+"\n"+tr("Check the file permissions and try again") );
1144  }
1145  //Now refresh the GUI
1146  refreshGUI("xdg");
1147}
1148
1149void MainGUI::on_push_xdg_clearentry_clicked(){
1150  //Clear the UI
1151        //reset the item selected to nothing
1152        ui->list_xdg_files->setCurrentRow(-1);
1153        //De-activate the "save" button
1154        ui->push_xdg_savechanges->setEnabled(FALSE);
1155        //Now clear the
1156        slotXdgFileChanged();
1157}
1158
1159void MainGUI::checkMime(){
1160    //This function will check the UI for differences in the MIME patterns
1161      // and update/create the MIME file appropriately
1162      // The MENU mime type will also be appropriately set
1163       
1164    QString menumimetype = currentModule->readValue("menumimetype");
1165    QString menumimepat = ui->line_xdg_mimepatterns->text();
1166    QString cmimetype = currentModule->readValue("mimetype");
1167    QString cmimepat = currentModule->readValue("mimepatterns");
1168    if( menumimepat != cmimepat ){ //something different about the mime patterns
1169        //  ---- Change the MIME file as well ----
1170          //Delete MIME file
1171        if(menumimepat.isEmpty()){
1172          currentModule->removeMime();
1173          currentModule->writeValue("menumimetype",""); //set MENU value
1174               
1175          //Create new MIME file
1176        }else if( cmimetype.isEmpty() || (ui->line_xdg_exec->text() != currentModule->readValue("menuexec")) ){
1177          QString exec = ui->line_xdg_exec->text().simplified();
1178          menumimetype = "application/x-"+exec;
1179          QString newfile = exec+"-xdg.xml";
1180          currentModule->loadMime(newfile); //setup structure
1181          currentModule->writeValue("mimetype",menumimetype); //set mime type
1182          currentModule->writeValue("mimepatterns",menumimepat); //set mime patterns
1183          currentModule->writeMime(); //save the MIME file (using default mime info)
1184               
1185          currentModule->writeValue("menumimetype",menumimetype); //set MENU value
1186               
1187          //Overwrite existing MIME file
1188        }else{
1189          currentModule->writeValue("mimepatterns", menumimepat); //overwrite mime patterns
1190          currentModule->writeMime(); //overwrite the MIME file
1191               
1192          currentModule->writeValue("menumimetype",cmimetype); //set MENU value
1193        }
1194    }
1195}
1196
1197void MainGUI::slotXDGOptionChanged(QString tmp){
1198  tmp.clear(); //remove warning about unused variables
1199  ui->push_xdg_savechanges->setEnabled(TRUE);
1200  ui->push_xdg_savenew->setEnabled(TRUE);
1201}
1202
1203/*------------------------------------------------
1204   SCRIPTS EDITOR OPTIONS
1205  -------------------------------------------------
1206*/
1207void MainGUI::slotScriptChanged(int index){
1208  index=0; //just to remove the warning about unused variables
1209  refreshGUI("scripts");
1210}
1211
1212void MainGUI::on_push_scripts_create_clicked(){
1213  //Setup display items
1214  ui->push_scripts_create->setVisible(FALSE);
1215  ui->push_scripts_remove->setVisible(FALSE);
1216  ui->push_scripts_save->setVisible(TRUE);
1217  ui->text_scripts_edit->setVisible(TRUE);
1218  ui->text_scripts_edit->clear();
1219  ui->push_scripts_save->setEnabled(FALSE); //disable the save button until something changes
1220}
1221
1222void MainGUI::on_push_scripts_remove_clicked(){
1223  //Get the current file
1224  QString filename = ui->list_scripts_file->currentText();
1225  //Remove the file
1226  QDir dir(currentModule->path()+"/scripts");
1227  dir.remove(filename);
1228  //refresh the UI
1229  refreshGUI("scripts");
1230}
1231
1232void MainGUI::on_push_scripts_save_clicked(){
1233  //Get the current file text
1234  QStringList contents = ui->text_scripts_edit->toPlainText().split("\n");
1235  //get the current file
1236  QString filename = currentModule->path() + "/scripts/"+ui->list_scripts_file->currentText();
1237  //Save the file
1238  bool ok = ModBuild::createFile(filename,contents);
1239  //display a warning if error
1240  if(!ok){
1241    QMessageBox::warning(this,tr("Error Saving File"), tr("Could not save the script")+"\n"+tr("Please check the file permissions and try again") );
1242  }
1243  //Now refresh the UI
1244  refreshGUI("scripts");
1245}
1246
1247void MainGUI::slotScriptModified(){
1248  ui->push_scripts_save->setEnabled(TRUE);     
1249}
1250/*------------------------------------------------
1251   EXTERNAL-LINKS EDITOR OPTIONS
1252  -------------------------------------------------
1253*/
1254void MainGUI::on_push_el_add_clicked(){
1255  //Read the user inputs
1256  QString file = ui->line_el_file->text();
1257  QString linkto = ui->line_el_linkto->text();
1258  QString opts = ui->line_el_filetype->text();
1259  //check for valid inputs
1260  if( file.isEmpty() || linkto.isEmpty() || opts.isEmpty() ){ return; }
1261  //Add the link
1262  currentModule->addExternalLink(file, linkto, opts.split(",") );
1263  //Save the file
1264  currentModule->writeExternalLinks();
1265  //Refresh the UI
1266  refreshGUI("external-links");
1267}
1268
1269void MainGUI::on_push_el_remove_clicked(){
1270  //Get the currently selected link
1271  QTreeWidgetItem *line = ui->tree_el_view->currentItem();
1272  if(line->columnCount() != 3){ return; }
1273  QString file = line->text(0);
1274  QString linkto = line->text(1);
1275  //Remove the link
1276  currentModule->removeExternalLink(file,linkto);
1277  //Save the file
1278  currentModule->writeExternalLinks();
1279  //Refresh the UI
1280  refreshGUI("external-links");
1281}
1282
1283void MainGUI::slotELSetFile(QAction* act){
1284  //get the selected file and set it in the UI
1285  ui->line_el_file->setText( act->text() );
1286  ui->line_el_linkto->setText( act->text() );
1287}
1288
1289void MainGUI::slotELSetType(QAction* act){
1290  //Get the current types
1291  QStringList types = ui->line_el_filetype->text().split(",", QString::SkipEmptyParts);
1292  //get the new type
1293  QString ntype  = act->text();
1294  //Now properly add the type as appropriate
1295  bool ok = FALSE;
1296  for(int i=0; i<types.length(); i++){
1297    //Check for special cases
1298    if( (types[i] == "keep") && (ntype=="replace") ){
1299      types[i] = ntype;
1300      ok = TRUE;
1301      break;
1302    }else if( (types[i] == "replace") && (ntype=="keep") ){
1303      types[i] = ntype;
1304      ok = TRUE;
1305      break;
1306    }else if( (types[i]=="binary") && (ntype=="linux") ){
1307      types[i] = ntype;
1308      ok = TRUE;
1309      break;
1310    }else if( (types[i]=="linux") && (ntype=="binary") ){
1311      types[i] = ntype;
1312      ok = TRUE;
1313      break;
1314    }else if( types[i] == ntype ){
1315      ok=TRUE;
1316      break;
1317    }
1318  }
1319  if(!ok){ types << ntype; } //append the type to the list
1320  //Add the new types to the UI
1321  ui->line_el_filetype->setText( types.join(",") );
1322}
1323/*------------------------------------------------
1324   FREENAS PLUGINS EDITOR OPTIONS
1325  -------------------------------------------------
1326*/
1327
1328
1329/*------------------------------------------------
1330   PBI BUILDER OPTIONS
1331  -------------------------------------------------
1332*/
1333void MainGUI::on_push_build_start_clicked(){
1334  //Check GUI to make sure settings are set before running
1335  bool gostatus = TRUE;
1336  QString outdir = settings->value("pbidir");
1337  if (outdir.isEmpty() ){gostatus=FALSE;}
1338  //QString sigfile = "";ui->linePBIDigSigFile->text(); //this one can be empty
1339  QString modDir = currentModule->path();
1340  if(modDir.isEmpty()){gostatus=FALSE;}
1341  if(!gostatus){
1342    QMessageBox::warning(this,tr("Error"),tr("Invalid PBI Settings"));
1343    return;
1344  }
1345 
1346  //Generate the PBI build command
1347  QString cmd;
1348  // -- PBI from ports
1349  if(radio_module_port->isChecked()){
1350    //Check that the ports tree is available
1351    if( !settings->check("isportsavailable") ){ 
1352      qDebug() << "Cannot build a PBI from ports without the FreeBSD ports tree available";
1353      return;
1354    }
1355    //Setup the pbi_makeport command from GUI settings
1356    cmd = settings->value("pbi_makeport");
1357    if(ui->check_build_32->isChecked()){ cmd += " -32"; }
1358    cmd += " -c " + modDir;
1359    if(settings->value("portsdir") != "/usr/ports"){ cmd += " -d " + settings->value("portsdir"); }
1360    cmd += " -o " + outdir;
1361    cmd += " --delbuild";
1362    if( settings->check("usetmpfs") ){ cmd += " --tmpfs"; }
1363    if( settings->check("usecache") ){ 
1364      cmd += " --pkgdir " + settings->value("cachedir");
1365      //Remove known "bad" packages (ones that routinely cause failures)
1366      QDir cDir( settings->value("cachedir") );
1367      QStringList filters = settings->list("skippkgs");
1368      QStringList badFiles = cDir.entryList(filters, QDir::Files | QDir:: NoDotAndDotDot);
1369      for(int i=0; i<badFiles.length(); i++){ cDir.remove(badFiles[i]); }
1370    }
1371    if( settings->check("usesignature") && QFile::exists(settings->value("sigfile")) ){ cmd += " --sign " + settings->value("sigfile"); }
1372   
1373  // -- PBI from local directory
1374  }else if(radio_module_local->isChecked() ){
1375        //get the base command
1376        cmd = settings->value("pbi_create");
1377        //Setup the ports options if non-standard port location
1378        if(settings->value("portsdir") != "/usr/ports"){ cmd += " -d " + settings->value("portsdir"); }
1379        //Setup the output directory
1380        cmd += " -o "+outdir;
1381        //Load the module
1382        cmd += " -c "+modDir;
1383        //Sign the PBI
1384        if( settings->check("usesignature") && QFile::exists(settings->value("sigfile")) ){ cmd += " --sign " + settings->value("sigfile"); }
1385        //Now setup the directory to package
1386        cmd += " "+ currentModule->readValue("packagedir");
1387  }
1388  //Display the command created in hte terminal
1389  qDebug() << "Build PBI command created:"<<cmd;
1390 
1391  //Receive User verification before beginning build process due to:
1392  //  -- long time required, internet connection required, root permissions required
1393  QMessageBox verify(this);
1394  verify.setText(tr("Are you sure you wish to start the PBI build?"));
1395  verify.setInformativeText(tr("This requires an active internet connection and root permissions. The time required to build a PBI varies depending upon system specifications and ports to be compiled."));
1396  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
1397  verify.setDefaultButton(QMessageBox::Yes);
1398  int ret = verify.exec();
1399  if(ret != QMessageBox::Yes){return;}
1400
1401  //Add the necessary glue to the command to run the pbi build
1402  cmd.prepend(settings->value("su_cmd")+" \"");
1403  cmd.append("\"");
1404  qDebug() << "Actual command used:" << cmd;
1405
1406  //Setup the displays
1407  ui->push_build_stop->setEnabled(TRUE);
1408  ui->push_build_save->setEnabled(FALSE);
1409  ui->check_build_32->setEnabled(FALSE);
1410  ui->push_build_start->setEnabled(FALSE); //disable the button so they do not start more than 1 build at a time
1411  ui->text_build_log->clear(); //clear the display in case this is not the first run
1412  ui->line_build_module->setText(currentModule->path());
1413  ui->line_build_outputdir->setText(settings->value("pbidir"));
1414  //Setup Process connections
1415  p = new QProcess(this);
1416  p->setProcessChannelMode(QProcess::MergedChannels);
1417  p->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
1418  connect(p,SIGNAL(readyReadStandardOutput()),this,SLOT(slotUpdatePBIBuild()) );
1419  connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotPBIbuildFinished(int,QProcess::ExitStatus)) );
1420  connect(p,SIGNAL(error(QProcess::ProcessError)),this,SLOT(slotBuildError(QProcess::ProcessError)) );
1421  //Setup the flag for the finishing checks
1422  PBI_BUILDING_NOW=outdir+":::"+currentModule->readValue("progname");
1423  //Start the Process
1424  qDebug() << "Starting the PBI build process...";
1425  ui->toolBox->setItemText(0,tr("PBI Builder (Working)"));
1426  p->start(cmd);
1427}
1428
1429void MainGUI::on_push_build_stop_clicked(){
1430  slotKillPBIBuild();
1431}
1432
1433void MainGUI::on_push_build_save_clicked(){
1434  //Have user select a filename/location to save the log
1435  QString filename = QFileDialog::getSaveFileName(this,tr("Save Log"),settings->value("progdir")+"/build.log",tr("Log Files")+" (*.log *.txt)");
1436  if(filename.isEmpty()){return;} //User cancelled the process
1437  //Open the file (as new)
1438  QFile *file = new QFile(filename);
1439  file->open(QIODevice::WriteOnly);
1440  //Save the log into the file
1441  file->write(ui->text_build_log->toPlainText().toUtf8());
1442  file->close();
1443}
1444
1445void MainGUI::slotUpdatePBIBuild(){
1446  QString tmp = p->readAllStandardOutput();
1447  if( tmp.startsWith("\n") ){tmp.remove(0,0);} //remove newline at the beginning (too much whitespace in log)
1448  if( tmp.endsWith("\n") ){tmp.chop(1);} //remove newline at the end (already accounted for by appending)
1449  if(!tmp.isEmpty()){ ui->text_build_log->append( tmp ); }
1450  //qDebug() << "Update output: " << tmp;
1451}
1452
1453void MainGUI::slotPBIbuildFinished(int exitCode,QProcess::ExitStatus exitStatus){
1454  //Check to see if the PBI process finished successfully
1455  qDebug() << "PBI build process Finished" << exitStatus << exitCode;
1456  //Check that the new PBI exists
1457  QDir outdir( PBI_BUILDING_NOW.section(":::",0,0) );
1458  QString pbiname= PBI_BUILDING_NOW.section(":::",1,1).toLower().remove(" ");
1459  QFileInfoList fL = outdir.entryInfoList( QStringList() << pbiname+"*.pbi" ,QDir::Files | QDir::NoSymLinks);
1460  bool success = FALSE;
1461  for(int i=0; i<fL.length(); i++){
1462          qint64 msdiff = QDateTime::currentMSecsSinceEpoch() - fL[i].created().toMSecsSinceEpoch();
1463          if(msdiff < 30000){ success = true; break; } //if less than a 30sec since creation of file - success
1464  }
1465 
1466  if(exitCode == 0 && success){
1467      QMessageBox::information(this,tr("PBI Build Success"),tr("The PBI finished building successfully"));
1468  }else if(exitCode == 0 && PBI_BUILD_TERMINATED){
1469      //The user killed the process - No Message
1470  }else{
1471    QMessageBox::warning(this,tr("PBI Build Failure"),tr("The PBI failed to build.")+"\n"+tr("Please check the build log to find the cause of the failure and adjust the module accordingly"));
1472  }
1473  ui->push_build_start->setEnabled(TRUE);
1474  ui->push_build_save->setEnabled(TRUE);
1475  ui->push_build_stop->setEnabled(FALSE);
1476  ui->check_build_32->setEnabled(TRUE);
1477  p->close();
1478  PBI_BUILDING_NOW.clear();
1479  PBI_BUILD_TERMINATED=FALSE;
1480  ui->toolBox->setItemText(0,tr("PBI Builder (Finished)"));
1481  delete p;
1482}
1483
1484void MainGUI::slotKillPBIBuild(){
1485  if( p->state()==QProcess::Running ){
1486    //qDebug() << "Process PID:" << p->pid();
1487    PBI_BUILD_TERMINATED=TRUE;   
1488    p->terminate();
1489    ui->text_build_log->append("---PBI Build Terminated---");
1490  }
1491}
1492
1493void MainGUI::slotBuildError(QProcess::ProcessError error){
1494  qDebug() << "QProcess PBI Build error#" << error;
1495}
Note: See TracBrowser for help on using the repository browser.