source: src-qt4/EasyPBI/mainGUI.cpp @ 9959e70

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 9959e70 was 9959e70, checked in by Ken Moore <ken@…>, 14 months ago

Re-word the build notification strings for EasyPBI to read "administrator privileges" instead of "root permissions" this that causes confusion with the new sudo usage

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