source: src-qt4/EasyPBI/newModuleDialog.cpp @ 9209fef

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

Replace the user home directory with "~" on the new module dialog whenever applicable (makes better screenshots)

  • Property mode set to 100644
File size: 3.9 KB
Line 
1#include "newModuleDialog.h"
2#include "ui_newModuleDialog.h"
3#include <QDir>
4#include <QDebug>
5
6NewModuleDialog::NewModuleDialog(QWidget *parent, QString portsDir) :
7    QDialog(parent),
8    ui(new Ui::NewModuleDialog)
9{
10       
11       //Setup Initial state of GUI objects and connect signal/slots
12       ui->setupUi(this);  //load the main UI from designer
13       isAccepted = FALSE;
14       PORTS_DIR = portsDir;
15        //Setup the dialog icons
16        ui->push_port->setIcon(Backend::icon("load"));
17        ui->push_sources->setIcon(Backend::icon("load"));
18        ui->push_icon->setIcon(Backend::icon("file"));
19        //Connect up the type changed slot
20       connect(ui->radio_port, SIGNAL(clicked()), this, SLOT(slotTypeChanged()) );
21       connect(ui->radio_local, SIGNAL(clicked()), this, SLOT(slotTypeChanged()) );
22        //now run the slot to properly setup the UI elements
23        slotTypeChanged();
24}
25
26NewModuleDialog::~NewModuleDialog(){
27}
28
29
30void NewModuleDialog::on_buttonBox_accepted(){
31  isAccepted=TRUE;
32  //Now set the public variables
33  if(ui->radio_port->isChecked()){
34    moduleType = "port";
35    moduleData = ui->line_port->text();
36  }else if(ui->radio_local->isChecked() ){
37    moduleType="local";
38    moduleData = ui->line_sources->text().replace("~",QDir::homePath());
39  }else{
40    moduleType.clear(); moduleData.clear();
41  }
42  moduleIcon = ui->line_icon->text().replace("~",QDir::homePath());
43  if(moduleIcon.isEmpty()){ moduleIcon = ui->line_icon->placeholderText().replace("~",QDir::homePath()); }
44  //Now close the UI
45  this->close();
46}
47
48void NewModuleDialog::on_buttonBox_rejected(){
49  isAccepted=FALSE;
50  moduleType.clear();
51  moduleData.clear();
52  moduleIcon.clear();
53  this->close();
54}
55
56void NewModuleDialog::slotTypeChanged(){
57  if(ui->radio_port->isChecked()){
58    ui->label_port->setVisible(TRUE); ui->line_port->setVisible(TRUE); ui->push_port->setVisible(TRUE);
59    ui->label_sources->setVisible(FALSE); ui->line_sources->setVisible(FALSE); ui->push_sources->setVisible(FALSE);
60  }else if(ui->radio_local->isChecked()){
61    ui->label_port->setVisible(FALSE); ui->line_port->setVisible(FALSE); ui->push_port->setVisible(FALSE);
62    ui->label_sources->setVisible(TRUE); ui->line_sources->setVisible(TRUE); ui->push_sources->setVisible(TRUE);
63  }else{
64    ui->label_port->setVisible(FALSE); ui->line_port->setVisible(FALSE); ui->push_port->setVisible(FALSE);
65    ui->label_sources->setVisible(FALSE); ui->line_sources->setVisible(FALSE); ui->push_sources->setVisible(FALSE);
66  }
67  if(PORTS_DIR.isEmpty()){ ui->push_port->setEnabled(FALSE); }
68}
69
70void NewModuleDialog::on_push_port_clicked(){
71  if( PORTS_DIR.isEmpty() ){
72    //No ports tree available
73    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."));
74    return;
75  }
76  //Prompt for a new port
77  QString portSel = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
78  if(portSel.isEmpty()){return;} //action cancelled or closed   
79  else{
80    ui->line_port->setText(portSel.remove(PORTS_DIR+"/"));
81  }
82}
83
84void NewModuleDialog::on_push_sources_clicked(){
85  //Prompt for a new selection
86  QString Sel = QFileDialog::getExistingDirectory(this, tr("Select Package Directory"), QDir::homePath());
87  if(Sel.isEmpty()){return;} //action cancelled or closed       
88  else{
89    ui->line_sources->setText(Sel.replace(QDir::homePath(),"~"));
90  }
91}
92
93void NewModuleDialog::on_push_icon_clicked(){
94//Prompt for a new selection
95  QString Sel = QFileDialog::getOpenFileName(this, tr("Select PNG Icon"), QDir::homePath(), tr("PNG icon (*.png)") );
96  if(Sel.isEmpty()){return;} //action cancelled or closed       
97  else{
98    ui->line_icon->setText(Sel);
99  }
100}
101
102void NewModuleDialog::setDefaultIconFile(QString icon){
103  ui->line_icon->setPlaceholderText(icon.replace(QDir::homePath(),"~"));
104}
Note: See TracBrowser for help on using the repository browser.