source: src-qt4/pc-sysmanager/portsnapprogress.cpp @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 20 months ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 4.2 KB
Line 
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
18void PortsnapProgress::init(bool ports, QString pcVer)
19{
20    doPorts = ports;
21
22    if ( ports )
23       startPorts();
24    else
25       startSource(pcVer);
26
27}
28
29void PortsnapProgress::startPorts()
30{
31    //Init vars
32    workdir = "/var/db/portsnap";
33    portsdir = "/usr/ports";
34
35    QDir checkdir;
36    if ( ! checkdir.exists(portsdir) )
37      checkdir.mkdir(portsdir);
38
39    displayString = "";
40    numberSteps = 0;
41   
42
43    //Else, just use defaults defined earlier
44   
45    QStringList args;
46    QString prog;
47    prog = "/usr/local/share/pcbsd/scripts/portsnap-noterm.sh";
48    args << "fetch";
49    portsnap = new QProcess(this);
50    portsnap->setProcessChannelMode(QProcess::MergedChannels);
51    connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseFetch()));
52    connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
53    portsnap->start(prog, args);
54
55}
56
57void PortsnapProgress::startSource(QString pcVer)
58{     
59    label->setText(tr("Downloading FreeBSD sources..."));
60
61    QString branch;
62    // Figure out which to download
63    if ( pcVer.indexOf(".") != -1 )
64       branch = "/releng/" + pcVer.section("-", 0, 0); 
65    else if ( pcVer.indexOf("STABLE") )
66       branch = "/stable/" + pcVer.section("-", 0, 0); 
67    else
68       branch = "/head";
69
70    QStringList args;
71    QString prog;
72    prog = "svn";
73    args << "co" << "svn://svn.freebsd.org/base" + branch << "/usr/src";
74    portsnap = new QProcess(this);
75    portsnap->setProcessChannelMode(QProcess::MergedChannels);
76    connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
77    connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(fetchDone()));
78    portsnap->start(prog, args);
79}
80
81
82void PortsnapProgress::parseFetch()
83{
84  while (portsnap->canReadLine() )
85  {
86    QString output = portsnap->readLine().simplified();
87    qDebug() << "Portsnap Fetch: " + output;
88    taskProgressLbl->setText(displayString);
89  }
90}
91
92
93
94void PortsnapProgress::finish()
95{
96    taskProgressLbl->setText("Finished!");
97    cancelBut->setText("&Close");
98}
99
100
101void PortsnapProgress::cancel()
102{
103    if (cancelBut->text() == "&Cancel") {
104        portsnap->kill();
105    }
106    this->close();
107}
108
109
110void PortsnapProgress::fetchDone()
111{
112    if (portsnap->exitStatus() != 0)
113    {
114        QMessageBox::critical(this, tr("Update Failed!"), tr("Unable to connect to server. Possible causes:\n- Your network is down\n- Target server is unresponsive."));
115        this->close();
116    }
117    else
118    {
119
120        // If doing SVN, we can end now
121        if ( ! doPorts ) {
122          updateDone();
123          return;
124        }
125       
126        QStringList args;
127        QString prog;
128        prog = "/usr/local/share/pcbsd/scripts/portsnap-noterm.sh";
129        // Check if we need to do a quick update or full extract
130        if ( QFile::exists( portsdir + "Mk/bsd.port.mk") ) 
131           args << "update" << "-p" << portsdir ;
132        else
133           args << "extract" << "update" << "-p" << portsdir ;
134        portsnap = new QProcess(this);
135        portsnap->setProcessChannelMode(QProcess::MergedChannels);
136        connect(portsnap, SIGNAL(readyReadStandardOutput()), this, SLOT(parseUpdate()));
137        connect(portsnap, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateDone()));
138        portsnap->start(prog, args);
139    }
140}
141
142
143void PortsnapProgress::parseUpdate()
144{
145  while( portsnap->canReadLine() )
146  {
147    QString output = portsnap->readLine().simplified();
148    qDebug() << "Portsnap Update: " + output;
149    taskProgressLbl->setText(output);
150  }
151}
152
153
154void PortsnapProgress::updateDone()
155{
156    finish();
157}
158
Note: See TracBrowser for help on using the repository browser.