Changes in / [a7429d5:aa7ba66]


Ignore:
Location:
src-qt4/pc-sysmanager
Files:
2 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-sysmanager/cmdDialog.cpp

    r8d1c3e0 r8a4c7a0  
    55  ui->setupUi(this); //load the designer UI file 
    66  //Setup the backend process class 
    7   PROC = new gitProc; 
     7  PROC = new LongProc; 
    88    connect(PROC, SIGNAL(ProcMessage(QString)), this, SLOT(NewMessage(QString)) ); 
    9     connect(PROC, SIGNAL(procFinished(bool)), this, SLOT(Finished(bool)) ); 
    10   //Setup internal flags 
    11   initPorts = false; initSource = false; //make sure these are both initially disabled 
    12   connect(ui->push_close, SIGNAL(clicked()), this, SLOT(CloseUI()) );    
     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()) ); 
    1313} 
    1414 
     
    1717} 
    1818 
    19 void CMDDialog::start(QString cmdtype){ 
     19void CMDDialog::start(QString cmdtype, QString branch){ 
    2020  if(PROC->isRunning()){ 
    2121    qDebug() << "ERROR: Process is already working: please wait until it is finished"; 
     
    2323  } 
    2424  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 
    2527  if(cmdtype.toLower() == "ports"){ 
     28    this->setWindowTitle(tr("Getting PC-BSD Ports Tree")); 
    2629    //Check for if the port tree needs to be initialized first 
    2730    qDebug() << "WARNING: Ports init check still needs to be implemented"; 
    2831    bool init = true; 
     32    //Now create the commands necessary 
    2933    if(init){ 
    30       initPorts = true; //set the internal flag 
    3134      ui->textEdit->setPlainText("Starting Ports Tree Initialization...."); 
    32       bool ok = PROC->startInitPorts(); 
    33       if(!ok){  
    34         ui->textEdit->appendPlainText("\nERROR: Could not clean and git init /usr/ports"); 
    35         ui->push_close->setEnabled(true); //they can now close the window 
     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 
    3639      } 
     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 
    3743    }else{ 
    38       ui->textEdit->setPlainText("Fetching the Ports Tree...."); 
    39       bool ok = PROC->startPorts(); 
    40       if(!ok){  
    41         ui->textEdit->appendPlainText("\nERROR: Could not setup git fetch within /usr/ports"); 
    42         ui->push_close->setEnabled(true); //they can now close the window 
    43       } 
     44      ui->textEdit->setPlainText("Updating the Ports Tree...."); 
    4445    } 
     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 
    4550  }else if(cmdtype.toLower() == "source"){ 
     51    this->setWindowTitle(tr("Getting PC-BSD Sources")); 
    4652    //Check for if the source tree needs to be initialized first 
    4753    qDebug() << "WARNING: Source init check still needs to be implemented"; 
    4854    bool init = true; 
     55    //Now create the commands necessary 
    4956    if(init){ 
    50       initSource = true; //set the internal flag 
    5157      ui->textEdit->setPlainText("Starting Source Tree Initialization...."); 
    52       bool ok = PROC->startInitSource(); 
    53       if(!ok){  
    54         ui->textEdit->appendPlainText("\nERROR: Could not clean and git init /usr/src"); 
    55         ui->push_close->setEnabled(true); //they can now close the window 
     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 
    5662      } 
     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 
    5766    }else{ 
    58       ui->textEdit->setPlainText("Fetching the Source Tree...."); 
    59       bool ok = PROC->startSource(); 
    60       if(!ok){  
    61         ui->textEdit->appendPlainText("\nERROR: Could not setup git fetch within /usr/src"); 
    62         ui->push_close->setEnabled(true); //they can now close the window 
    63       } 
     67      ui->textEdit->setPlainText("Updating the Source Tree...."); 
    6468    } 
     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";  
    6572  }else{ 
    6673    ui->textEdit->setPlainText("Unknown CMD Type: "+cmdtype); 
    6774    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     
    6890  } 
    6991} 
    7092 
    71 // ===================== 
    72 void CMDDialog::NewMessage(QString msg){ 
    73   ui->textEdit->appendPlainText("\n"+msg); //make sure it is on the next line each time  
    74 } 
    75  
    76 void CMDDialog::Finished(bool ok){ 
    77   if(!ok){ 
    78     ui->textEdit->appendPlainText("\n=============\nProcess Completed Unsuccessfully"); 
    79     ui->push_close->setEnabled(true); //enabled the close button 
    80   }else if(initPorts){ 
    81     initPorts = false; //make sure it doesn't fall into this catch again 
    82     //ports tree initialized successfully - start the fetch process 
    83     ui->textEdit->appendPlainText("\n=============\nFetching the Ports Tree...."); 
    84     bool ok = PROC->startPorts(); 
    85     if(!ok){  
    86       ui->textEdit->appendPlainText("\nERROR: Could not setup git fetch within /usr/ports"); 
    87       ui->push_close->setEnabled(true); //they can now close the window 
    88     } 
    89   }else if(initSource){ 
    90     initSource = false; //make sure it doesn't fall into this catch again 
    91     //Source tree initialized successfully - start the fetch process 
    92     ui->textEdit->appendPlainText("\n=============\nFetching the Source Tree...."); 
    93     bool ok = PROC->startPorts(); 
    94     if(!ok){  
    95       ui->textEdit->appendPlainText("\nERROR: Could not setup git fetch within /usr/src"); 
    96       ui->push_close->setEnabled(true); //they can now close the window 
    97     } 
    98   }else{ 
    99     ui->textEdit->appendPlainText("\n=============\nFinished Successfully"); 
    100   } 
     93void CMDDialog::Finished(){ 
     94    ui->push_close->setEnabled(true); //enable the close button 
     95    ui->push_stop->setEnabled(PROC->isRunning()); 
    10196} 
    10297 
     
    10499  this->close(); 
    105100} 
     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} 
  • src-qt4/pc-sysmanager/cmdDialog.h

    r6d7b1e6 r8a4c7a0  
    55#include <QString> 
    66#include <QWidget> 
     7#include <QMessageBox> 
    78 
    8 #include "gitprogress.h" 
     9#include "longProc.h" 
    910 
    1011namespace Ui{ 
     
    1819        ~CMDDialog(); 
    1920 
    20         void start(QString cmdtype); 
     21        void start(QString cmdtype, QString branch = ""); 
     22        bool isRunning(); 
    2123 
    2224private: 
    2325        Ui::CMDDialog *ui; 
    24         gitProc *PROC; 
    25         bool initPorts, initSource; //to keep track if only the first step was running 
     26        LongProc *PROC; 
    2627 
    2728private slots: 
    2829        void NewMessage(QString); 
    29         void Finished(bool); 
     30        void Finished(); 
    3031        void CloseUI(); 
     32        void stopProcess(); 
     33 
     34protected: 
     35        void closeEvent(QCloseEvent *event); 
    3136}; 
    3237#endif 
  • src-qt4/pc-sysmanager/cmdDialog.ui

    r6d7b1e6 r8f95077  
    1616  <layout class="QVBoxLayout" name="verticalLayout"> 
    1717   <item> 
    18     <widget class="QPlainTextEdit" name="textEdit"/> 
     18    <widget class="QPlainTextEdit" name="textEdit"> 
     19     <property name="readOnly"> 
     20      <bool>true</bool> 
     21     </property> 
     22    </widget> 
    1923   </item> 
    2024   <item> 
    2125    <layout class="QHBoxLayout" name="horizontalLayout"> 
     26     <item> 
     27      <widget class="QPushButton" name="push_stop"> 
     28       <property name="text"> 
     29        <string>Stop</string> 
     30       </property> 
     31      </widget> 
     32     </item> 
    2233     <item> 
    2334      <spacer name="horizontalSpacer"> 
     
    4455  </layout> 
    4556 </widget> 
    46  <resources/> 
     57 <resources> 
     58  <include location="PBSystem.qrc"/> 
     59 </resources> 
    4760 <connections/> 
    4861</ui> 
  • src-qt4/pc-sysmanager/pbsystemtab.cpp

    r7cd7e8f r8a4c7a0  
    2626{ 
    2727    //Grab the username 
    28     username = QString::fromLocal8Bit(getenv("SUDO_USER")); 
    29     qDebug() << "Username:" << username; 
     28    username = QString::fromLocal8Bit(getenv("SUDO_USER")); //since the app is always run as root with sudo 
     29    if(username.isEmpty()){ username = QString::fromLocal8Bit(getenv("LOGNAME")); } //in case SUDO_USER is not set 
     30    //qDebug() << "Username:" << username; 
    3031    // Set the Uname on the General Tab 
    3132    CheckUname(); 
     
    6869    connect(fetchSourceBut, SIGNAL( clicked() ), this, SLOT( fetchSourcePressed() ) ); 
    6970    connect(fetchPortsBut, SIGNAL( clicked() ), this, SLOT( fetchPortsPressed() ) ); 
     71     
     72    cmdDlg = new CMDDialog(this); 
     73    cmdDlg->hide(); 
    7074} 
    7175 
     
    148152        args << SheetFileName; 
    149153        args << username; 
    150         qDebug() << "CMD: " << prog+" "+args.join(" "); 
     154        //qDebug() << "CMD: " << prog+" "+args.join(" "); 
    151155        connect( SheetGenScript, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedSheet()) ); 
    152156                 
     
    206210void PBSystemTab::fetchSourcePressed() 
    207211{ 
    208     portsnapUI = new CMDDialog(this); 
    209     portsnapUI->start("source"); //Version not implemented yet 
    210     portsnapUI->show(); 
     212    if(cmdDlg->isRunning() ){ 
     213      QMessageBox::warning(this, tr("Process Already Running"), tr("You already have a process running. Please wait for that one to finish first.") ); 
     214    }else{ 
     215      //Get the current version branch of the source tree 
     216      QString version = pcbsd::Utils::runShellCommand("uname -r").join(" "); 
     217      QString branch; 
     218      if(version.contains("RELEASE")){ branch = "releng/"+version.section("-",0,0).simplified(); } 
     219      else if(version.contains("STABLE")){ branch = "stable/"+version.section("-",0,0).section(".",0,0).simplified(); } 
     220      else{ branch = "master"; } //CURRENT 
     221       
     222      cmdDlg->start("source", branch); //Version not implemented yet 
     223      cmdDlg->show(); 
     224    } 
    211225} 
    212226 
    213227void PBSystemTab::fetchPortsPressed() 
    214228{ 
    215     portsnapUI = new CMDDialog(this); 
    216     portsnapUI->start("ports"); //Version not implemented yet 
    217     portsnapUI->show(); 
     229    if(cmdDlg->isRunning() ){ 
     230      QMessageBox::warning(this, tr("Process Already Running"), tr("You already have a process running. Please wait for that one to finish first.") ); 
     231    }else{ 
     232      cmdDlg->start("ports"); //Version not implemented yet 
     233      cmdDlg->show(); 
     234    } 
    218235} 
    219236 
     
    371388  QNetworkProxy::setApplicationProxy(proxy); 
    372389} 
     390 
     391void PBSystemTab::closeEvent(QCloseEvent *event){ 
     392    if(cmdDlg->isRunning()){ 
     393      //Process Running - minimize the main window instead 
     394      event->ignore(); 
     395      this->showMinimized(); 
     396    } 
     397} 
  • src-qt4/pc-sysmanager/pbsystemtab.h

    r7cd7e8f r8f95077  
    1212#include <QTextStream> 
    1313#include <QTimer> 
     14#include <QCloseEvent> 
    1415 
    1516#include <pcbsd-utils.h> 
     
    7576    QProcess *GetPBVer; 
    7677    QProcess *GetUname; 
    77     CMDDialog *portsnapUI; 
     78    CMDDialog *cmdDlg; 
    7879    QString username; 
    7980    bool miscChanged; 
     
    140141    metaWidget *pkgWidget; 
    141142 
     143protected: 
     144        void closeEvent(QCloseEvent *event); 
    142145 
    143146signals: 
  • src-qt4/pc-sysmanager/pbsystemtab.ui

    rba438ce ra4325b4  
    660660  <include location="local">qfile.h</include> 
    661661  <include location="local">qsettings.h</include> 
    662   <include location="local">gitprogress.h</include> 
    663662  <include location="global">qregexp.h</include> 
    664663  <include location="global">pcbsd-utils.h</include> 
  • src-qt4/pc-sysmanager/pc-sysmanager.pro

    ra2d9be0 ra4325b4  
    99 
    1010HEADERS += pbsystemtab.h \ 
    11         gitprogress.h \ 
    1211        updaterDialog.h \ 
    13         cmdDialog.h 
     12        cmdDialog.h \ 
     13        longProc.h 
    1414 
    1515SOURCES += main.cpp \ 
    1616        pbsystemtab.cpp \ 
    17         gitprogress.cpp \ 
    1817        updaterDialog.cpp \ 
    19         cmdDialog.cpp 
     18        cmdDialog.cpp \ 
     19        longProc.cpp 
     20         
    2021 
    2122FORMS   = pbsystemtab.ui \ 
    22         gitprogress.ui \ 
    2323        updaterDialog.ui \ 
    2424        cmdDialog.ui 
Note: See TracChangeset for help on using the changeset viewer.