Guest User

Untitled

a guest
Dec 19th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 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. portsdir = "/usr/ports/.git/";
  33. QStringList args;
  34. QString prog;
  35.  
  36. system("rm -rf /usr/ports/" );
  37. system("git init /usr/ports" );
  38. prog = "git";
  39. args << "--git-dir=/usr/ports/.git" << "remote" << "add" << "origin" << "https://www.github.com/pcbsd/freebsd-ports.git";
  40. portsnap = new QProcess(this);
  41. portsnap->setProcessChannelMode(QProcess::MergedChannels);
  42. connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseFetch()));
  43. connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
  44. portsnap->start(prog, args);
  45. }
  46.  
  47. void PortsnapProgress::startPorts()
  48. {
  49. QStringList args;
  50. QString prog;
  51.  
  52. system("git --git-dir=/usr/ports/.git fetch" );
  53. prog = "git";
  54. args << "--git-dir=/usr/ports/.git" << "checkout -t origin/master";
  55. portsnap = new QProcess(this);
  56. portsnap->setProcessChannelMode(QProcess::MergedChannels);
  57. connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseFetch()));
  58. connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
  59. portsnap->start(prog, args);
  60. }
  61.  
  62.  
  63. void PortsnapProgress::startSource(QString pcVer)
  64. {
  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.  
  89. void PortsnapProgress::parseFetch()
  90. {
  91. while (portsnap->canReadLine() )
  92. {
  93. QString output = portsnap->readLine().simplified();
  94. qDebug() << "Portsnap Fetch: " + output;
  95. taskProgressLbl->setText(displayString);
  96. }
  97. }
  98.  
  99.  
  100.  
  101. void PortsnapProgress::finish()
  102. {
  103. taskProgressLbl->setText("Finished!");
  104. cancelBut->setText("&Close");
  105. }
  106.  
  107.  
  108. void PortsnapProgress::cancel()
  109. {
  110. if (cancelBut->text() == "&Cancel") {
  111. portsnap->kill();
  112. }
  113. this->close();
  114. }
  115.  
  116. void PortsnapProgress::fetchDone()
  117. {
  118. if (portsnap->exitStatus() != 0)
  119. {
  120. QMessageBox::critical(this, tr("Update Failed!"), tr("Unable to connect to server. Possible causes:\n- Your network is down\n- Target server is unresponsive."));
  121. this->close();
  122. }
  123. else
  124. {
  125.  
  126. // If doing SVN, we can end now
  127. if ( ! doPorts ) {
  128. updateDone();
  129. return;
  130. }
  131.  
  132. QStringList args;
  133. QString prog;
  134. prog = "/usr/local/share/pcbsd/scripts/portsnap-noterm.sh";
  135. // Check if we need to do a quick update or full extract
  136. if ( QFile::exists( portsdir ) )
  137. startPorts();
  138. else
  139. initPorts();
  140. portsnap = new QProcess(this);
  141. portsnap->setProcessChannelMode(QProcess::MergedChannels);
  142. connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
  143. connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateDone()));
  144. }
  145. }
  146.  
  147. void PortsnapProgress::parseUpdate()
  148. {
  149. while( portsnap->canReadLine() )
  150. {
  151. QString output = portsnap->readLine().simplified();
  152. output.truncate(100);
  153. qDebug() << "Portsnap Update: " + output;
  154. taskProgressLbl->setText(output);
  155. }
  156. }
  157.  
  158.  
  159. void PortsnapProgress::updateDone()
  160. {
  161. finish();
  162. }
Add Comment
Please, Sign In to add comment