Ignore:
Timestamp:
Apr 24, 2013 8:06:56 AM (12 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.1-release, 9.2-release, releng/10.0, releng/10.0.1
Children:
47239e7
Parents:
f424798
git-author:
Ken Moore <ken@…> (04/24/13 08:04:57)
git-committer:
Ken Moore <ken@…> (04/24/13 08:06:56)
Message:

Update EasyPBI to version 2.1
Changes: FreeBSD ports dialog merged into the settings dialog, save buttons now dynamicly enabled, use portsnap for all ports fetching/updating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/EasyPBI/preferencesDialog.cpp

    r1620346 re177abf  
    1414        ui->push_sigfile->setIcon(Backend::icon("file")); 
    1515        ui->push_clearcache->setIcon(Backend::icon("clear")); 
    16         ui->push_portsdir->setIcon(Backend::icon("load")); 
    1716        ui->push_moduledir->setIcon(Backend::icon("load")); 
    1817        ui->push_icondir->setIcon(Backend::icon("load")); 
     
    2221        ui->push_pbicreate->setIcon(Backend::icon("file")); 
    2322        ui->push_resetutils->setIcon(Backend::icon("refresh")); 
     23        ui->tool_otherPortsDir->setIcon(Backend::icon("load")); 
     24        ui->push_updatePorts->setIcon(Backend::icon("refresh")); 
     25         
    2426        //Setup the internal settings structure 
    2527        settings = new Config(); 
    2628        settings->scanForExternalUtilities();    
    2729        settings->loadSettingsFile(); 
     30        //initialize the QProcess 
     31        process = new QProcess(this); 
     32        process->setProcessEnvironment( QProcessEnvironment::systemEnvironment() ); 
     33        connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(updateStatusBar()) ); 
     34        connect(process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)) ); 
    2835        //Put the current settings into the GUI 
    2936        resetGUI(); 
     
    4855        ui->line_icondir->setText(settings->value("icondir")); 
    4956        ui->line_defaulticon->setText(settings->value("defaulticon")); 
    50         //utilities tab 
    5157        ui->line_suutility->setText(settings->value("su_cmd")); 
    5258        ui->line_pbicreate->setText(settings->value("pbi_create")); 
    5359        ui->line_makeport->setText(settings->value("pbi_makeport")); 
    54         ui->line_portsdir->setText(settings->value("portsdir")); 
    55          
     60        //ports tab 
     61        ui->list_portsDirectories->clear(); 
     62        QStringList pDirs; pDirs<< tr("Current User (~/EasyPBI/ports)") << tr("All Users (/usr/ports)") << tr("Other"); 
     63        ui->list_portsDirectories->addItems(pDirs); 
     64        QString portsdir = settings->value("portsdir"); 
     65        if(portsdir.endsWith("/")){ portsdir.chop(1); } 
     66        if(portsdir == (QDir::homePath()+"/EasyPBI/ports") ){ 
     67          ui->list_portsDirectories->setCurrentIndex(0); //User dir 
     68        }else if(portsdir == "/usr/ports"){ 
     69          ui->list_portsDirectories->setCurrentIndex(1); //system dir    
     70        }else{ 
     71          ui->list_portsDirectories->setCurrentIndex(2); //other 
     72          ui->line_otherPortsDir->setText(portsdir); 
     73        } 
     74        ui->progressBar->setMaximum(0); ui->progressBar->setMinimum(0); //default to a "loading" indicator 
     75        updateGUI(); 
     76} 
     77 
     78void PreferencesDialog::updateGUI(){ 
    5679        //Now adjust the visibility of the necessary elements 
     80        //pbi tab 
    5781        if( ui->check_signpbi->isChecked() ){ ui->groupBox_sig->setVisible(TRUE); } 
    5882        else{ ui->groupBox_sig->setVisible(FALSE); } 
    5983        if( ui->check_usepkgcache->isChecked() ){ ui->groupBox_pkgcache->setVisible(TRUE); } 
    6084        else{ ui->groupBox_pkgcache->setVisible(FALSE); } 
    61    
     85        //ports tab 
     86        int pIndex = ui->list_portsDirectories->currentIndex(); 
     87        if(pIndex == 2){ 
     88          ui->line_otherPortsDir->setVisible(TRUE); ui->tool_otherPortsDir->setVisible(TRUE); 
     89        }else{ 
     90          ui->line_otherPortsDir->setVisible(FALSE); ui->tool_otherPortsDir->setVisible(FALSE);  
     91        } 
     92        QString pDir; 
     93        switch (pIndex){ 
     94        case 0:  
     95                pDir = QDir::homePath()+"/EasyPBI/ports"; break; 
     96        case 1: 
     97                pDir = "/usr/ports"; break; 
     98        default: 
     99                pDir = ui->line_otherPortsDir->text(); 
     100        }        
     101        QString pUpdate; 
     102        if(!pDir.isEmpty()){ pUpdate = getLastPortsUpdate(pDir); } //check for existance and last update 
     103        if( !pUpdate.isEmpty() ){ 
     104          ui->push_fetchPorts->setVisible(FALSE); 
     105          ui->push_updatePorts->setVisible(TRUE); 
     106          ui->label_portsUpdated->setText( pUpdate ); 
     107        }else{ 
     108          ui->push_fetchPorts->setVisible(TRUE); 
     109          ui->push_updatePorts->setVisible(FALSE); 
     110          ui->label_portsUpdated->setText( tr("Nonexistent") ); 
     111        } 
     112        if(process->state() == QProcess::NotRunning){ 
     113          ui->list_portsDirectories->setEnabled(TRUE); 
     114          ui->line_otherPortsDir->setEnabled(TRUE); ui->tool_otherPortsDir->setEnabled(TRUE); 
     115          ui->label_status->setVisible(FALSE); ui->progressBar->setVisible(FALSE); 
     116          ui->push_fetchPorts->setEnabled(TRUE); ui->push_updatePorts->setEnabled(TRUE); 
     117          ui->buttonBox->setEnabled(TRUE); 
     118        }else{ 
     119          ui->list_portsDirectories->setEnabled(FALSE); 
     120          ui->line_otherPortsDir->setEnabled(FALSE); ui->tool_otherPortsDir->setEnabled(FALSE); 
     121          ui->label_status->setVisible(TRUE); ui->progressBar->setVisible(TRUE); 
     122          ui->push_fetchPorts->setEnabled(FALSE); ui->push_updatePorts->setEnabled(FALSE); 
     123          ui->buttonBox->setEnabled(FALSE); 
     124        } 
    62125} 
    63126 
     
    76139    badpkgs.removeDuplicates(); 
    77140    settings->setList("skippkgs", badpkgs); 
    78     settings->setValue("portsdir", ui->line_portsdir->text() ); 
     141    QString portsDir; 
     142    int pIndex = ui->list_portsDirectories->currentIndex(); 
     143    if( pIndex == 0 ){portsDir = QDir::homePath()+"/EasyPBI/ports"; } 
     144    else if( pIndex == 1){ portsDir = "/usr/ports"; } 
     145    else{ portsDir = ui->line_otherPortsDir->text(); }     
     146    settings->setValue("portsdir", portsDir ); 
    79147    settings->setValue("moduledir", ui->line_moduledir->text() ); 
    80148    settings->setValue("icondir", ui->line_icondir->text() ); 
     
    94162} 
    95163 
    96 // PBI Settings Tab 
     164// ===== PBI Settings Tab ===== 
    97165void PreferencesDialog::on_push_pbioutdir_clicked(){ 
    98166  //Get the desired directory 
     
    154222} 
    155223 
    156 // Paths Tab   
     224// ===== Paths Tab =====   
    157225void PreferencesDialog::on_push_moduledir_clicked(){ 
    158226  //Get the desired directory 
     
    178246} 
    179247 
    180 //Utilities Tab 
     248// ===== Utilities Tab ===== 
    181249void PreferencesDialog::on_push_suutility_clicked(){ 
    182250  //Get the desired directory 
     
    218286  settings->setValue("pbi_create",""); 
    219287  settings->setValue("su_cmd",""); 
    220   settings->setValue("portsdir",""); 
    221288  //Reset the utilities on the GUI       
    222289  ui->line_suutility->setText(settings->value("su_cmd")); 
    223290  ui->line_pbicreate->setText(settings->value("pbi_create")); 
    224291  ui->line_makeport->setText(settings->value("pbi_makeport")); 
    225   ui->line_portsdir->setText(settings->value("portsdir")); 
     292} 
     293 
     294// ======  Ports Tab ====== 
     295void PreferencesDialog::on_list_portsDirectories_currentIndexChanged(int index){ 
     296  updateGUI();   
     297} 
     298 
     299void PreferencesDialog::on_line_otherPortsDir_textChanged(QString text){ 
     300  updateGUI();   
     301} 
     302void PreferencesDialog::on_tool_otherPortsDir_clicked(){ 
     303  //Get the desired directory 
     304  QString seldir = QFileDialog::getExistingDirectory(this, tr("Select FreeBSD Ports Directory"), QDir::homePath() ); 
     305  if(seldir.isEmpty()){ return; } //action cancelled 
     306  //Save the selection to the GUI 
     307  ui->line_otherPortsDir->setText(seldir); 
     308  updateGUI(); 
     309} 
     310 
     311void PreferencesDialog::on_push_fetchPorts_clicked(){ 
     312  int pIndex = ui->list_portsDirectories->currentIndex(); 
     313  QString pDir; 
     314    if( pIndex == 0 ){pDir = QDir::homePath()+"/EasyPBI/ports"; } 
     315    else if( pIndex == 1){ pDir = "/usr/ports"; } 
     316    else{ pDir = ui->line_otherPortsDir->text(); } 
     317  fetchPorts(pDir,TRUE); //is a new ports directory 
     318  updateGUI(); 
     319} 
     320 
     321void PreferencesDialog::on_push_updatePorts_clicked(){ 
     322  int pIndex = ui->list_portsDirectories->currentIndex(); 
     323  QString pDir; 
     324    if( pIndex == 0 ){pDir = QDir::homePath()+"/EasyPBI/ports"; } 
     325    else if( pIndex == 1){ pDir = "/usr/ports"; } 
     326    else{ pDir = ui->line_otherPortsDir->text(); } 
     327  fetchPorts(pDir,FALSE); //is an existing ports directory 
     328  updateGUI(); 
    226329} 
    227330     
    228 void PreferencesDialog::on_push_portsdir_clicked(){ 
    229   //Get the desired directory 
    230   QString seldir = QFileDialog::getExistingDirectory(this, tr("Select FreeBSD Ports Directory"), QDir::homePath() ); 
    231   if(seldir.isEmpty()){ return; } //action cancelled 
    232   //Save the selection to the GUI 
    233   ui->line_portsdir->setText(seldir);  
    234 } 
     331void PreferencesDialog::updateStatusBar(){ 
     332  QString tmp = process->readAllStandardOutput(); 
     333  if(tmp.endsWith("\n")){ tmp.chop(1); } 
     334  tmp = tmp.section("\n",-1); 
     335  tmp = tmp.remove("\n").simplified(); 
     336  //qDebug() << "Status Update:" << tmp; 
     337  ui->label_status->clear(); 
     338  ui->label_status->setText(tmp); 
     339} 
     340 
     341void PreferencesDialog::processFinished(int exitCode,QProcess::ExitStatus status){ 
     342  qDebug() << " - Ports update finished:" << exitCode << status; 
     343  //Inform the user of the result 
     344  if(exitCode == 0){ 
     345    //Finished successfully 
     346    QMessageBox::information(this, tr("Success"), tr("The FreeBSD ports tree has been successfully updated") ); 
     347  }else{ 
     348    //Finished with error 
     349    QString msg = process->readAllStandardError(); 
     350    if(msg.isEmpty()){ msg = process->readAllStandardOutput(); } 
     351    QMessageBox::information(this, tr("Failure"), QString(tr("The FreeBSD ports tree has failed to update.")+"\n"+tr("Last Message: %1") ).arg(msg) ); 
     352  } 
     353  updateGUI(); //Update the interface times and such 
     354} 
     355 
     356QString PreferencesDialog::getLastPortsUpdate(QString ports){ 
     357  QDir dir(ports); 
     358  QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs, QDir::Time); //sort by most recently changed 
     359  QString out; 
     360  if(list.length() > 2){ //good ports tree 
     361    out = list[0].lastModified().toString(); 
     362  } 
     363  return out; 
     364} 
     365 
     366void PreferencesDialog::fetchPorts(QString portsDir, bool isNew){ 
     367  bool needRoot = TRUE; 
     368  QString localPSDB = QDir::homePath()+"/EasyPBI/.portSnapDB"; 
     369  if( portsDir.startsWith( QDir::homePath() )){ needRoot = FALSE; } 
     370   
     371  // == Generate the System Command == 
     372  QString cmd; 
     373  bool usePortsnap = FALSE; 
     374  //Graphical SU utility as needed 
     375  if(needRoot){  
     376    ui->label_status->setText(tr("Requesting Root Access")); //Put placeholder info 
     377    cmd = ui->line_suutility->text() + " \""; //use the switch-user utility 
     378  } 
     379  //Figure out whether to use portsnap or not 
     380  if( !isNew && QFile::exists(portsDir+"/.svn") ){ 
     381    //Use Subversion 
     382    cmd.append("svn update "+portsDir); 
     383  }else{ 
     384    //Use Portsnap 
     385    cmd.append("portsnap fetch "); 
     386    if(isNew){ cmd.append("extract "); } 
     387    else{ cmd.append("update "); } 
     388    cmd.append("-p "+portsDir); 
     389    if(!needRoot){ cmd.append(" -d "+localPSDB); } 
     390    usePortsnap=TRUE; 
     391     
     392  } 
     393  if(needRoot){ cmd.append("\""); } //close the quotes 
     394   
     395  //If using portsnap, make sure the intermediate file is there in the EasyPBI directory 
     396  if( usePortsnap ){ 
     397    QString pspath = QDir::homePath()+"/EasyPBI/.portsnapNI.sh"; // Non-Interactive (NI) version of portsnap 
     398    if( !QFile::exists(pspath) ){ 
     399      //Create the Non-Interactive version of portsnap if it does not exist yet 
     400      QString pscmd ="echo \"#!/bin/sh \n#Non-Interactive portsnap workaround for EasyPBI \ncat /usr/sbin/portsnap | sed 's|! -t 0|-z '1'|g' | /bin/sh -s \\$@\" > "+pspath+"; chmod 755 "+pspath; 
     401      //qDebug() << "system call:" << pscmd; 
     402      system(pscmd.toUtf8()); 
     403    } 
     404    if(!needRoot && !QFile::exists(localPSDB)){ 
     405      //Create the local portsnap database directory 
     406      QString tmpcmd = "mkdir "+localPSDB; 
     407      system(tmpcmd.toUtf8()); 
     408    } 
     409    cmd.replace("portsnap",pspath); 
     410  } 
     411  //Now run the command 
     412  process->start(cmd); 
     413  qDebug() << "Ports fetch started: CMD:" << cmd;        
     414} 
Note: See TracChangeset for help on using the changeset viewer.