Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************
- ** ui.h extension file, included from the uic-generated form implementation.
- **
- ** If you want to add, delete, or rename functions or slots, use
- ** Qt Designer to update this file, preserving your code.
- **
- ** You should not define a constructor or destructor in this file.
- ** Instead, write your code in functions called init() and destroy().
- ** These will automatically be called by the form's constructor and
- ** destructor.
- *****************************************************************************/
- #include "portsnapprogress.h"
- #include <qtextstream.h>
- #include <QProcess>
- #include <QDebug>
- #include <QDir>
- void PortsnapProgress::init(bool ports, QString pcVer)
- {
- doPorts = ports;
- if ( ports )
- initPorts();
- else
- startSource(pcVer);
- }
- void PortsnapProgress::initPorts()
- {
- //Init vars
- workdir = "/usr/ports/.git";
- portsdir = "/usr/ports/";
- QProcess::execute("rm -rf /usr/ports");
- QProcess *initports = new QProcess(this);
- initports->setWorkingDirectory(portsdir);
- initports->start("git init");
- while(!initports->waitForFinished(500)){ //0.5 sec wait
- QCoreApplication::processEvents();
- }
- if( initports->exitCode() != 0){ qDebug() << "Error"; }
- else{
- initports->setWorkingDirectory(workdir);
- initports->start("git remote add origin https://www.github.com/pcbsd/freebsd-ports.git");
- }
- }
- void PortsnapProgress::startPorts()
- {
- QProcess *updateports = new QProcess(this);
- updateports->setWorkingDirectory(workdir);
- updateports->start("git fetch --depth=1");
- while(!updateports->waitForFinished(500)){ //0.5 sec wait
- QCoreApplication::processEvents();
- }
- if( updateports->exitCode() != 0){ qDebug() << "Error"; }
- else{
- updateports->setWorkingDirectory(portsdir);
- updateports->start("git checkout -t origin/master");
- }
- }
- void PortsnapProgress::startSource(QString pcVer) {
- label->setText(tr("Downloading FreeBSD sources..."));
- QString branch;
- // Figure out which to download
- if ( pcVer.indexOf("STABLE") )
- branch = "stable/" + pcVer.section("-", 0, 0).section(".", 0, 0);
- else if ( pcVer.indexOf(".") != -1 )
- branch = "releng/" + pcVer.section("-", 0, 0);
- else
- branch = "master";
- QStringList args;
- QString prog;
- prog = "git";
- args << "clone" << "https://github.com/pcbsd/freebsd.git" << "-b" << branch << "/usr/src";
- qDebug() << args;
- portsnap = new QProcess(this);
- portsnap->setProcessChannelMode(QProcess::MergedChannels);
- connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
- connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
- portsnap->start(prog, args);
- }
- void PortsnapProgress::parseFetch()
- {
- while (portsnap->canReadLine() )
- {
- QString output = portsnap->readLine().simplified();
- qDebug() << "Portsnap Fetch: " + output;
- taskProgressLbl->setText(displayString);
- }
- }
- void PortsnapProgress::finish()
- {
- taskProgressLbl->setText("Finished!");
- cancelBut->setText("&Close");
- }
- void PortsnapProgress::cancel()
- {
- if (cancelBut->text() == "&Cancel") {
- portsnap->kill();
- }
- this->close();
- }
- void PortsnapProgress::fetchDone()
- {
- if (portsnap->exitStatus() != 0)
- {
- QMessageBox::critical(this, tr("Update Failed!"), tr("Unable to connect to server. Possible causes:\n- Your network is down\n- Target server is unresponsive."));
- this->close();
- }
- else
- {
- // If doing SVN, we can end now
- if ( ! doPorts ) {
- updateDone();
- return;
- }
- QStringList args;
- QString prog;
- prog = "/usr/local/share/pcbsd/scripts/portsnap-noterm.sh";
- // Check if we need to do a quick update or full extract
- if ( QFile::exists( workdir ) )
- startPorts();
- else
- initPorts();
- portsnap = new QProcess(this);
- portsnap->setProcessChannelMode(QProcess::MergedChannels);
- connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
- connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateDone()));
- }
- }
- void PortsnapProgress::parseUpdate()
- {
- while( portsnap->canReadLine() )
- {
- QString output = portsnap->readLine().simplified();
- output.truncate(100);
- qDebug() << "Portsnap Update: " + output;
- taskProgressLbl->setText(output);
- }
- }
- void PortsnapProgress::updateDone()
- {
- finish();
- }
Add Comment
Please, Sign In to add comment