Guest User

Untitled

a guest
Dec 21st, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. /****************************************************************************
  2. ** ui.h extension file, included from the uic-generated form implementation.
  3. **
  4. ** If you want to add, delete, or rename functions or slots, use
  5. ** Qt Designer to update this file, preserving your code.
  6. **
  7. ** You should not define a constructor or destructor in this file.
  8. ** Instead, write your code in functions called init() and destroy().
  9. ** These will automatically be called by the form's constructor and
  10. ** destructor.
  11. *****************************************************************************/
  12. #include "portsnapprogress.h"
  13. #include <qtextstream.h>
  14. #include <QProcess>
  15. #include <QDebug>
  16. #include <QDir>
  17.  
  18. void PortsnapProgress::init(bool ports, QString pcVer)
  19. {
  20. doPorts = ports;
  21.  
  22. if ( ports )
  23. initPorts();
  24. else
  25. startSource(pcVer);
  26.  
  27. }
  28.  
  29. void PortsnapProgress::initPorts()
  30. {
  31. //Init vars
  32. workdir = "/usr/ports/.git";
  33. portsdir = "/usr/ports/";
  34.  
  35. QProcess::execute("rm -rf /usr/ports");
  36. QProcess *initports = new QProcess(this);
  37. initports->setWorkingDirectory(portsdir);
  38. initports->start("git init");
  39. while(!initports->waitForFinished(500)){ //0.5 sec wait
  40. QCoreApplication::processEvents();
  41. }
  42. if( initports->exitCode() != 0){ qDebug() << "Error"; }
  43. else{
  44. initports->setWorkingDirectory(workdir);
  45. initports->start("git remote add origin https://www.github.com/pcbsd/freebsd-ports.git");
  46. }
  47. }
  48.  
  49. void PortsnapProgress::startPorts()
  50. {
  51. QProcess *updateports = new QProcess(this);
  52. updateports->setWorkingDirectory(workdir);
  53. updateports->start("git fetch --depth=1");
  54. while(!updateports->waitForFinished(500)){ //0.5 sec wait
  55. QCoreApplication::processEvents();
  56. }
  57. if( updateports->exitCode() != 0){ qDebug() << "Error"; }
  58. else{
  59. updateports->setWorkingDirectory(portsdir);
  60. updateports->start("git checkout -t origin/master");
  61. }
  62. }
  63.  
  64. void PortsnapProgress::startSource(QString pcVer) {
  65. label->setText(tr("Downloading FreeBSD sources..."));
  66.  
  67. QString branch;
  68. // Figure out which to download
  69. if ( pcVer.indexOf("STABLE") )
  70. branch = "stable/" + pcVer.section("-", 0, 0).section(".", 0, 0);
  71. else if ( pcVer.indexOf(".") != -1 )
  72. branch = "releng/" + pcVer.section("-", 0, 0);
  73. else
  74. branch = "master";
  75.  
  76. QStringList args;
  77. QString prog;
  78. prog = "git";
  79. args << "clone" << "https://github.com/pcbsd/freebsd.git" << "-b" << branch << "/usr/src";
  80. qDebug() << args;
  81. portsnap = new QProcess(this);
  82. portsnap->setProcessChannelMode(QProcess::MergedChannels);
  83. connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
  84. connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
  85. portsnap->start(prog, args);
  86. }
  87.  
  88. void PortsnapProgress::parseFetch()
  89. {
  90. while (portsnap->canReadLine() )
  91. {
  92. QString output = portsnap->readLine().simplified();
  93. qDebug() << "Portsnap Fetch: " + output;
  94. taskProgressLbl->setText(displayString);
  95. }
  96. }
  97.  
  98.  
  99.  
  100. void PortsnapProgress::finish()
  101. {
  102. taskProgressLbl->setText("Finished!");
  103. cancelBut->setText("&Close");
  104. }
  105.  
  106.  
  107. void PortsnapProgress::cancel()
  108. {
  109. if (cancelBut->text() == "&Cancel") {
  110. portsnap->kill();
  111. }
  112. this->close();
  113. }
  114.  
  115. void PortsnapProgress::fetchDone()
  116. {
  117. if (portsnap->exitStatus() != 0)
  118. {
  119. QMessageBox::critical(this, tr("Update Failed!"), tr("Unable to connect to server. Possible causes:\n- Your network is down\n- Target server is unresponsive."));
  120. this->close();
  121. }
  122. else
  123. {
  124.  
  125. // If doing SVN, we can end now
  126. if ( ! doPorts ) {
  127. updateDone();
  128. return;
  129. }
  130. QStringList args;
  131. QString prog;
  132. prog = "/usr/local/share/pcbsd/scripts/portsnap-noterm.sh";
  133. // Check if we need to do a quick update or full extract
  134. if ( QFile::exists( workdir ) )
  135. startPorts();
  136. else
  137. initPorts();
  138. portsnap = new QProcess(this);
  139. portsnap->setProcessChannelMode(QProcess::MergedChannels);
  140. connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
  141. connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateDone()));
  142. }
  143. }
  144.  
  145.  
  146. void PortsnapProgress::parseUpdate()
  147. {
  148. while( portsnap->canReadLine() )
  149. {
  150. QString output = portsnap->readLine().simplified();
  151. output.truncate(100);
  152. qDebug() << "Portsnap Update: " + output;
  153. taskProgressLbl->setText(output);
  154. }
  155. }
  156.  
  157.  
  158. void PortsnapProgress::updateDone()
  159. {
  160. finish();
  161. }
Add Comment
Please, Sign In to add comment