source: src-qt4/EasyPBI/preferencesDialog.cpp @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 12 months ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 9.7 KB
Line 
1#include "preferencesDialog.h"
2#include "ui_preferencesDialog.h"
3#include <QDebug>
4
5PreferencesDialog::PreferencesDialog(QWidget *parent) :
6    QDialog(parent),
7    ui(new Ui::PreferencesDialog)
8{
9       
10       //Setup Initial state of GUI objects and connect signal/slots
11       ui->setupUi(this);  //load the main UI from designer
12        //Setup the dialog icons
13        ui->push_pbioutdir->setIcon(Backend::icon("load"));
14        ui->push_sigfile->setIcon(Backend::icon("file"));
15        ui->push_clearcache->setIcon(Backend::icon("clear"));
16        ui->push_portsdir->setIcon(Backend::icon("load"));
17        ui->push_moduledir->setIcon(Backend::icon("load"));
18        ui->push_icondir->setIcon(Backend::icon("load"));
19        ui->push_defaulticon->setIcon(Backend::icon("file"));
20        ui->push_suutility->setIcon(Backend::icon("file"));
21        ui->push_makeport->setIcon(Backend::icon("file"));
22        ui->push_pbicreate->setIcon(Backend::icon("file"));
23        ui->push_resetutils->setIcon(Backend::icon("refresh"));
24        //Setup the internal settings structure
25        settings = new Config();
26        settings->scanForExternalUtilities();   
27        settings->loadSettingsFile();
28        //Put the current settings into the GUI
29        resetGUI();
30}
31
32PreferencesDialog::~PreferencesDialog(){
33}
34
35//Setup the UI
36void PreferencesDialog::resetGUI(){
37  //Put the current settings into all the dialog widgets
38        //pbi tab
39        ui->line_pbioutdir->setText(settings->value("pbidir"));
40        ui->check_signpbi->setChecked(settings->check("usesignature"));
41        ui->line_sigfile->setText(settings->value("sigfile"));
42        ui->check_usetmpfs->setChecked(settings->check("usetmpfs"));
43        ui->check_usepkgcache->setChecked(settings->check("usecache"));
44        ui->list_badpkg->clear();
45        ui->list_badpkg->addItems(settings->list("skippkgs"));
46        //paths tab
47        ui->line_moduledir->setText(settings->value("moduledir"));
48        ui->line_icondir->setText(settings->value("icondir"));
49        ui->line_defaulticon->setText(settings->value("defaulticon"));
50        //utilities tab
51        ui->line_suutility->setText(settings->value("su_cmd"));
52        ui->line_pbicreate->setText(settings->value("pbi_create"));
53        ui->line_makeport->setText(settings->value("pbi_makeport"));
54        ui->line_portsdir->setText(settings->value("portsdir"));
55       
56        //Now adjust the visibility of the necessary elements
57        if( ui->check_signpbi->isChecked() ){ ui->groupBox_sig->setVisible(TRUE); }
58        else{ ui->groupBox_sig->setVisible(FALSE); }
59        if( ui->check_usepkgcache->isChecked() ){ ui->groupBox_pkgcache->setVisible(TRUE); }
60        else{ ui->groupBox_pkgcache->setVisible(FALSE); }
61 
62}
63
64//Save/Cancel buttons
65void PreferencesDialog::on_buttonBox_accepted(){
66    //Save the settings in the GUI to the stucture
67    settings->setValue("pbidir", ui->line_pbioutdir->text() );
68    settings->setCheck("usesignature", ui->check_signpbi->isChecked() );
69    settings->setValue("sigfile", ui->line_sigfile->text() );
70    settings->setCheck("usetmpfs", ui->check_usetmpfs->isChecked() );
71    settings->setCheck("usecache", ui->check_usepkgcache->isChecked() );
72    QStringList badpkgs;
73    for(int i=0; i<ui->list_badpkg->count(); i++){
74      badpkgs << ui->list_badpkg->item(i)->text();
75    }
76    badpkgs.removeDuplicates();
77    settings->setList("skippkgs", badpkgs);
78    settings->setValue("portsdir", ui->line_portsdir->text() );
79    settings->setValue("moduledir", ui->line_moduledir->text() );
80    settings->setValue("icondir", ui->line_icondir->text() );
81    settings->setValue("defaulticon", ui->line_defaulticon->text() );
82    settings->setValue("su_cmd", ui->line_suutility->text() );
83    settings->setValue("pbi_create", ui->line_pbicreate->text() );
84    settings->setValue("pbi_makeport", ui->line_makeport->text() );
85    //Now save the settings to disk
86    settings->saveSettingsFile();
87    //Now close the dialog
88    this->close();
89}
90
91void PreferencesDialog::on_buttonBox_rejected(){
92    //Don't save any of the settings and just close the dialog
93    this->close();
94}
95
96// PBI Settings Tab
97void PreferencesDialog::on_push_pbioutdir_clicked(){
98  //Get the desired directory
99  QString seldir = QFileDialog::getExistingDirectory(this, tr("Select PBI Output Directory"), QDir::homePath() );
100  if(seldir.isEmpty()){ return; } //action cancelled
101  //Save the selection to the GUI
102  ui->line_pbioutdir->setText(seldir); 
103}
104
105void PreferencesDialog::on_push_sigfile_clicked(){
106  //Get the desired directory
107  QString seldir = QFileDialog::getOpenFileName(this, tr("Select Digital Signature File"), QDir::homePath(), tr("Signature Files (*)") );
108  if(seldir.isEmpty()){ return; } //action cancelled
109  //Save the selection to the GUI
110  ui->line_sigfile->setText(seldir); 
111}
112
113void PreferencesDialog::on_push_addpkg_clicked(){
114  //Get the desired directory
115  QString seldir = QFileDialog::getOpenFileName(this, tr("Select the Package to Ignore"), settings->value("cachedir"), tr("Package Files (*.txz)") );
116  if(seldir.isEmpty()){ return; } //action cancelled
117  //get just the package name (ignore the version and extension)
118  QString pkg = seldir.remove(seldir.section("-",-1));
119  pkg.append("*");
120  //Save the selection to the GUI
121  ui->list_badpkg->addItem(pkg); 
122}
123
124void PreferencesDialog::on_push_rmpkg_clicked(){
125  //get the currently selected item
126  int row = ui->list_badpkg->currentRow();
127  if(row == -1){ return; } //nothing selected
128  //Remove it from the list
129  delete ui->list_badpkg->takeItem(row);
130}
131
132void PreferencesDialog::on_push_clearcache_clicked(){
133  //Verify that this is what the user really wants to do
134  QMessageBox verify(this);
135  verify.setText(tr("Are you sure you wish to clear the PBI package cache?"));
136  verify.setInformativeText(tr("This will delete all the files and directories in the cache directory. The next time you start a PBI build, it will begin to rebuild all the packages from source."));
137  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
138  verify.setDefaultButton(QMessageBox::Yes);
139  int ret = verify.exec();
140  if(ret != QMessageBox::Yes){return;}
141  //Remove all files/directories in the EasyPBI cache dir
142  QString cmd = "cd "+settings->value("cachedir")+"; rm -rf *";
143  system(cmd.toUtf8());
144}
145
146void PreferencesDialog::on_check_signpbi_stateChanged(int state){
147  if(state == Qt::Checked){ ui->groupBox_sig->setVisible(TRUE); }
148  else{ ui->groupBox_sig->setVisible(FALSE); }
149}
150
151void PreferencesDialog::on_check_usepkgcache_stateChanged(int state){
152  if(state == Qt::Checked){ ui->groupBox_pkgcache->setVisible(TRUE); }
153  else{ ui->groupBox_pkgcache->setVisible(FALSE); }
154}
155
156// Paths Tab 
157void PreferencesDialog::on_push_moduledir_clicked(){
158  //Get the desired directory
159  QString seldir = QFileDialog::getExistingDirectory(this, tr("Select Default Module Directory"), QDir::homePath() );
160  if(seldir.isEmpty()){ return; } //action cancelled
161  //Save the selection to the GUI
162  ui->line_moduledir->setText(seldir); 
163}
164
165void PreferencesDialog::on_push_icondir_clicked(){
166  //Get the desired directory
167  QString seldir = QFileDialog::getExistingDirectory(this, tr("Select Default Directory To Find Icon Files"), QDir::homePath() );
168  if(seldir.isEmpty()){ return; } //action cancelled
169  //Save the selection to the GUI
170  ui->line_icondir->setText(seldir); 
171}
172void PreferencesDialog::on_push_defaulticon_clicked(){
173  //Get the desired directory
174  QString seldir = QFileDialog::getOpenFileName(this, tr("Select Default Icon FIle"), QDir::homePath(), tr("PNG Images (*.png)") );
175  if(seldir.isEmpty()){ return; } //action cancelled
176  //Save the selection to the GUI
177  ui->line_defaulticon->setText(seldir); 
178}
179
180//Utilities Tab
181void PreferencesDialog::on_push_suutility_clicked(){
182  //Get the desired directory
183  QString seldir = QFileDialog::getOpenFileName(this, tr("Select Graphical Switch-User Utility"), QDir::homePath() );
184  if(seldir.isEmpty()){ return; } //action cancelled
185  //Save the selection to the GUI
186  ui->line_suutility->setText(seldir); 
187}
188
189void PreferencesDialog::on_push_pbicreate_clicked(){
190  //Get the desired directory
191  QString seldir = QFileDialog::getOpenFileName(this, tr("Select 'pbi_create' File Location"), QDir::homePath(), "(pbi_create)" );
192  if(seldir.isEmpty()){ return; } //action cancelled
193  //Save the selection to the GUI
194  ui->line_pbicreate->setText(seldir); 
195}
196
197void PreferencesDialog::on_push_makeport_clicked(){
198  //Get the desired directory
199  QString seldir = QFileDialog::getOpenFileName(this, tr("Select 'pbi_makeport' File Location"), QDir::homePath(), "(pbi_makeport)" );
200  if(seldir.isEmpty()){ return; } //action cancelled
201  //Save the selection to the GUI
202  ui->line_makeport->setText(seldir); 
203}
204
205void PreferencesDialog::on_push_resetutils_clicked(){
206  //Verify that this is what the user really wants to do
207  QMessageBox verify(this);
208  verify.setText(tr("Are you sure you wish to return to the automatically detected utility paths?"));
209  verify.setInformativeText(tr("This will remove any customized path settings for the external utilities."));
210  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
211  verify.setDefaultButton(QMessageBox::Yes);
212  int ret = verify.exec();
213  if(ret != QMessageBox::Yes){return;}
214  //Rescan for external utilities
215  settings->scanForExternalUtilities();
216  //Reset the values in the structure (will revert to detected values if any)
217  settings->setValue("pbi_makeport","");
218  settings->setValue("pbi_create","");
219  settings->setValue("su_cmd","");
220  settings->setValue("portsdir","");
221  //Reset the utilities on the GUI     
222  ui->line_suutility->setText(settings->value("su_cmd"));
223  ui->line_pbicreate->setText(settings->value("pbi_create"));
224  ui->line_makeport->setText(settings->value("pbi_makeport"));
225  ui->line_portsdir->setText(settings->value("portsdir"));
226}
227   
228void PreferencesDialog::on_push_portsdir_clicked(){
229  //Get the desired directory
230  QString seldir = QFileDialog::getExistingDirectory(this, tr("Select FreeBSD Ports Directory"), QDir::homePath() );
231  if(seldir.isEmpty()){ return; } //action cancelled
232  //Save the selection to the GUI
233  ui->line_portsdir->setText(seldir); 
234}
Note: See TracBrowser for help on using the repository browser.