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

enter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since e9a3917 was e9a3917, checked in by Ken Moore <ken@…>, 18 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: 3.0 KB
Line 
1#include "longProc.h"
2
3
4LongProc::LongProc(){
5  //initialize the internal worker process
6  process = new QProcess;
7  process->setProcessChannelMode(QProcess::MergedChannels);
8  connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()) );
9  connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procDone()) );
10  running = false; stopped = false;
11  cmdList.clear(); dirList.clear(); infoList.clear();
12  timer = new QTimer();
13        timer->setSingleShot(true);
14        timer->setInterval(10000); //10 second ping to make sure user knows it is still running
15  connect(timer, SIGNAL(timeout()), this, SLOT(procTimeout()) );
16}
17
18LongProc::~LongProc(){
19  //Clean up the internal worker process
20  delete process;
21}
22       
23// ========================
24//     PUBLIC WRAPPER FUNCTIONS
25// ========================
26bool LongProc::startCMDs(QStringList cmds, QStringList dirs, QStringList info){
27  //Check that it is not already running
28  if(running){ return false; }
29  //Now check input lengths
30  if( (cmds.length() != dirs.length()) || (cmds.length() != info.length()) && !cmds.isEmpty() ){
31    qDebug() << "Invalid input lengths: all three inputs must have the same number of strings";
32    return false;
33  }
34  //Now save the inputs internally
35  cmdList = cmds; dirList = dirs; infoList = info;
36  //Now get the first command running
37  currentItem = 0;
38  if( !infoList[currentItem].isEmpty() ){ emit ProcMessage("--- "+infoList[currentItem]+" ---"); }
39  if( !dirList[currentItem].isEmpty() && QFile::exists(dirList[currentItem]) ){ process->setWorkingDirectory(dirList[currentItem]); }
40  timer->start();
41  process->start(cmdList[currentItem]);
42  running = true;
43  return running;
44}
45
46void LongProc::stopProc(){
47  stopped = true;
48  process->terminate();
49}
50
51// ==============
52//     PRIVATE SLOTS
53// ==============
54void LongProc::parseUpdate(){
55  while(process->canReadLine()){
56    QString output = process->readLine().simplified();
57    //could add a check here to not send the message for empty lines
58    emit ProcMessage(output);
59  }
60  timer->start(); //reset the timer
61}
62
63void LongProc::procDone(){
64  //Start the next command if there is one
65  bool success = (process->exitCode() == 0);
66  if( currentItem+1 < cmdList.length() && success && !stopped){
67    currentItem++;
68    if( !infoList[currentItem].isEmpty() ){ emit ProcMessage("\n--- "+infoList[currentItem]+" ---"); }
69    if( !dirList[currentItem].isEmpty() && QFile::exists(dirList[currentItem]) ){ process->setWorkingDirectory(dirList[currentItem]); }
70    process->start(cmdList[currentItem]);
71    timer->start(); //reset timer
72  }else{
73    //All finished
74    if(stopped){
75      emit ProcMessage("\n ---- KILLED ----");
76      stopped=false; //reset flag
77    }else if(success){
78      emit ProcMessage("\n ---- FINISHED ----");
79    }else{
80      emit ProcMessage("\n ---- ERROR ----");
81    }
82    running = false;
83    emit ProcFinished();
84    timer->stop();
85  }
86}
87
88void LongProc::procTimeout(){
89  emit ProcMessage("."); //just to make sure that a quiet and long process still looks active to the user
90  timer->start(); //restart the timer
91}
Note: See TracBrowser for help on using the repository browser.