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

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

Add system source branch detection to the system manager.

  • Property mode set to 100644
File size: 4.9 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    //Check for if the port tree needs to be initialized first
30    qDebug() << "WARNING: Ports init check still needs to be implemented";
31    bool init = true;
32    //Now create the commands necessary
33    if(init){
34      ui->textEdit->setPlainText("Starting Ports Tree Initialization....");
35      if(QFile::exists("/usr/ports")){
36        cmds << "rm -rf /usr/ports/* /usr/ports/.g*"; info << "Removing the old ports tree"; dirs << ""; //Clean the old ports tree
37      }else{
38        cmds << "mkdir /usr/ports"; info << "Creating the ports tree"; dirs << ""; //Create the ports tree
39      }
40      cmds << "git init"; info << "Initialize GIT"; dirs << "/usr/ports"; //setup git
41      cmds << "git remote remove origin"; info << ""; dirs <<"/usr/ports";
42      cmds << "git remote add origin https://www.github.com/pcbsd/freebsd-ports.git"; info << ""; dirs << "/usr/ports/.git"; //setup PC-BSD git repo
43    }else{
44      ui->textEdit->setPlainText("Updating the Ports Tree....");
45    }
46    //Now create the git update commands
47    cmds << "git fetch --depth=1"; info << "Fetch new GIT info (this may take a while)"; dirs << "/usr/ports/.git";
48    cmds << "git checkout master"; info << "Checkout the tree"; dirs << "/usr/ports"; 
49
50  }else if(cmdtype.toLower() == "source"){
51    this->setWindowTitle(tr("Getting PC-BSD Sources"));
52    //Check for if the source tree needs to be initialized first
53    qDebug() << "WARNING: Source init check still needs to be implemented";
54    bool init = true;
55    //Now create the commands necessary
56    if(init){
57      ui->textEdit->setPlainText("Starting Source Tree Initialization....");
58      if(QFile::exists("/usr/src")){
59        cmds << "rm -rf /usr/src/* /usr/src/.g*"; info << "Removing the old source tree"; dirs << ""; //Clean the old source tree
60      }else{
61        cmds << "mkdir /usr/src"; info << "Creating the source tree"; dirs << ""; //Create the source tree
62      }
63      cmds << "git init"; info << "Initialize GIT"; dirs << "/usr/src"; //setup git
64      cmds << "git remote remove origin"; info << ""; dirs <<"/usr/src";
65      cmds << "git remote add origin https://www.github.com/pcbsd/freebsd.git"; info << ""; dirs << "/usr/src/.git"; //setup PC-BSD git repo
66    }else{
67      ui->textEdit->setPlainText("Updating the Source Tree....");
68    }
69    //Now create the git update commands
70    cmds << "git fetch --depth=1"; info << "Fetch new GIT info (this may take a while)"; dirs << "/usr/src/.git";
71    cmds << "git checkout "+branch; info << "Checkout the right version of the tree"; dirs << "/usr/src"; 
72  }else{
73    ui->textEdit->setPlainText("Unknown CMD Type: "+cmdtype);
74    ui->push_close->setEnabled(true);
75    ui->push_stop->setEnabled(false);
76    return;
77  }
78  PROC->startCMDs(cmds, dirs, info);
79  ui->push_stop->setEnabled(PROC->isRunning());
80}
81
82bool CMDDialog::isRunning(){
83  return PROC->isRunning();
84}
85// =====================
86void CMDDialog::NewMessage(QString msg){
87  if(!msg.isEmpty()){
88    //if(!msg.startsWith("\n")){ msg.prepend("\n"); } //make sure it is on a new line
89    ui->textEdit->appendPlainText(msg); //make sure it is on the next line each time   
90  }
91}
92
93void CMDDialog::Finished(){
94    ui->push_close->setEnabled(true); //enable the close button
95    ui->push_stop->setEnabled(PROC->isRunning());
96}
97
98void CMDDialog::CloseUI(){
99  this->close();
100}
101
102void CMDDialog::stopProcess(){
103  PROC->stopProc();
104  //PROC should emit the finished signal once done stopping
105}
106
107void CMDDialog::closeEvent(QCloseEvent *event){
108  //Make sure the user does not close this window while a process is running
109  event->ignore();
110  if(!ui->push_close->isEnabled()){
111    QMessageBox::warning(this, tr("Process Running"), tr("Please stop the current process before closing this window.") );
112  }else{
113    //Make sure this window is only hidden (pbsystemtab needs to make sure it always exists for checks);
114    this->hide();
115  }
116}
Note: See TracBrowser for help on using the repository browser.