source: src-qt4/pc-sysmanager/cmdDialog.cpp @ e9a3917

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since e9a3917 was e9a3917, checked in by Ken Moore <ken@…>, 9 months ago

Finish cleaning up the new system manager ports/source checkout functionality.
Also create a backend class that just contains a bunch of static functions for simple usage elsewhere (like generating ports update commands). This will make it easy to update the utility later if URL's or other system calls change (since we don't need to worry about all the GUI-specific stuff getting mixed in).

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "cmdDialog.h"
2#include "ui_cmdDialog.h"
3
4CMDDialog::CMDDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CMDDialog){
5  ui->setupUi(this); //load the designer UI file
6  //Setup the backend process class
7  PROC = new LongProc;
8    connect(PROC, SIGNAL(ProcMessage(QString)), this, SLOT(NewMessage(QString)) );
9    connect(PROC, SIGNAL(ProcFinished()), this, SLOT(Finished()) );
10  //Setup internal connections
11  connect(ui->push_close, SIGNAL(clicked()), this, SLOT(CloseUI()) );
12  connect(ui->push_stop, SIGNAL(clicked()), this, SLOT(stopProcess()) );
13}
14
15CMDDialog::~CMDDialog(){
16  delete PROC; 
17}
18
19void CMDDialog::start(QString cmdtype, QString branch){
20  if(PROC->isRunning()){
21    qDebug() << "ERROR: Process is already working: please wait until it is finished";
22    return;
23  }
24  ui->push_close->setEnabled(false); //make sure they cannot close this while it is running
25  ui->textEdit->clear(); //make sure this is cleared
26  QStringList cmds, dirs, info; //For generating the necessary input to the backend
27  if(cmdtype.toLower() == "ports"){
28    this->setWindowTitle(tr("Getting PC-BSD Ports Tree"));
29    Backend::generatePortsUpdateCMDS(cmds, dirs, info);
30         
31  }else if(cmdtype.toLower() == "source"){
32    this->setWindowTitle(tr("Getting PC-BSD Sources"));
33    Backend::generateSourceUpdateCMDS(branch, cmds, dirs, info);
34         
35  }else{
36    ui->textEdit->setPlainText("Unknown CMD Type: "+cmdtype);
37    ui->push_close->setEnabled(true);
38    ui->push_stop->setEnabled(false);
39    return;
40  }
41  PROC->startCMDs(cmds, dirs, info);
42  ui->push_stop->setEnabled(PROC->isRunning());
43}
44
45bool CMDDialog::isRunning(){
46  return PROC->isRunning();
47}
48// =====================
49void CMDDialog::NewMessage(QString msg){
50  if(!msg.isEmpty()){
51    //if(!msg.startsWith("\n")){ msg.prepend("\n"); } //make sure it is on a new line
52    ui->textEdit->appendPlainText(msg); //make sure it is on the next line each time   
53  }
54}
55
56void CMDDialog::Finished(){
57    ui->push_close->setEnabled(true); //enable the close button
58    ui->push_stop->setEnabled(PROC->isRunning());
59}
60
61void CMDDialog::CloseUI(){
62  this->close();
63}
64
65void CMDDialog::stopProcess(){
66  PROC->stopProc();
67  //PROC should emit the finished signal once done stopping
68}
69
70void CMDDialog::closeEvent(QCloseEvent *event){
71  //Make sure the user does not close this window while a process is running
72  event->ignore();
73  if(!ui->push_close->isEnabled()){
74    QMessageBox::warning(this, tr("Process Running"), tr("Please stop the current process before closing this window.") );
75  }else{
76    //Make sure this window is only hidden (pbsystemtab needs to make sure it always exists for checks);
77    this->hide();
78  }
79}
Note: See TracBrowser for help on using the repository browser.