Changeset b3b08221


Ignore:
Timestamp:
06/22/14 08:25:01 (14 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, enter/10, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2, releng/10.2
Children:
c70a5c9
Parents:
20c7552
Message:

Get lumina-fm copy/restores working properly - now the zfs file/dir restore working completely.

Location:
lumina/lumina-fm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lumina/lumina-fm/FODialog.cpp

    r20c7552 rb3b08221  
    1414  ui->push_stop->setIcon( LXDG::findIcon("edit-delete","") ); 
    1515  //Now set the internal defaults 
    16   isRM = isCP = isRESTORE = isMV = stopped = false; 
     16  isRM = isCP = isRESTORE = isMV = stopped = overwrite = noerrors = false; 
    1717} 
    1818 
    1919FODialog::~FODialog(){ 
    2020  stopped = true; //just in case it might still be running when closed 
     21} 
     22 
     23void FODialog::setOverwrite(bool ovw){ 
     24  overwrite = ovw; 
    2125} 
    2226 
     
    3337    ofiles = oldPaths; nfiles = newPaths; 
    3438  } 
     39  isCP=true; 
    3540  QTimer::singleShot(10,this, SLOT(slotStartOperations())); 
    3641} 
     
    4146    ofiles = oldPaths; nfiles = newPaths; 
    4247  } 
     48  isRESTORE = true; 
    4349  QTimer::singleShot(10,this, SLOT(slotStartOperations())); 
    4450} 
     
    4955    ofiles = oldPaths; nfiles = newPaths; 
    5056  } 
     57  isMV=true; 
    5158  QTimer::singleShot(10,this, SLOT(slotStartOperations())); 
    5259} 
     
    6875} 
    6976 
     77QString FODialog::newFileName(QString path){ 
     78  int num=1; 
     79  QString extension = path.section(".",-1); 
     80  if(!extension.isEmpty()){  
     81    extension.prepend(".");  
     82    path.chop(extension.length()); 
     83  } 
     84  while( QFile::exists(path+"-"+QString::number(num)+extension) ){ num++; } 
     85  return QString(path+"-"+QString::number(num)+extension); 
     86} 
     87 
     88QStringList FODialog::removeItem(QString path){ 
     89  QStringList items = subfiles(path); 
     90  QStringList err;       
     91  for(int i=0; i<items.length(); i++){ 
     92    if(QFileInfo(items[i]).isDir()){ 
     93      QDir dir; 
     94      if( !dir.rmdir(items[i]) ){ err << items[i]; } 
     95    }else{ 
     96      if( !QFile::remove(items[i]) ){ err << items[i]; } 
     97    } 
     98  } 
     99  return err; 
     100} 
     101 
     102QStringList FODialog::copyItem(QString oldpath, QString newpath){ 
     103  QStringList err; 
     104  if(QFileInfo(oldpath).isDir()){ 
     105    QDir dir; 
     106    if( !dir.mkpath(newpath) ){ err << oldpath; } 
     107    else{ 
     108      dir.cd(oldpath); 
     109      QStringList subs = dir.entryList(QDir::Files | QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst); 
     110      for(int i=0; i<subs.length(); i++){ err << copyItem(oldpath+"/"+subs[i], newpath+"/"+subs[i]); } 
     111    } 
     112  }else{ 
     113    if( !QFile::copy(oldpath, newpath) ){ err << oldpath; } 
     114    else{ 
     115      if(isCP){ 
     116        QFile::setPermissions(newpath, QFile::permissions(oldpath)); 
     117      }else if(isRESTORE){ 
     118        QFile::setPermissions(newpath, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup); 
     119      } 
     120    } 
     121  } 
     122  return err; 
     123} 
     124 
    70125// ==== PRIVATE SLOTS ==== 
    71126void FODialog::slotStartOperations(){ 
    72127  ui->label->setText(tr("Calculating...")); 
    73   if(isRM){ 
    74     //Need to remove directory contents before the directory: find them 
    75     nfiles.clear(); 
    76     for(int i=0; i<ofiles.length(); i++){ 
    77       nfiles << subfiles(ofiles[i]); 
    78     } 
    79     nfiles.removeAll(""); 
    80     ofiles = nfiles; //use the new list of files to remove (put them in the order to remove) 
    81   } 
    82128  //Now setup the UI 
    83129  ui->progressBar->setRange(0,ofiles.length()); 
     
    89135    if(isRM){ 
    90136      ui->label->setText( QString(tr("Removing: %1")).arg(ofiles[i].section("/",-1)) ); 
    91       if(QFileInfo(ofiles[i]).isDir()){ 
    92         QDir dir; 
    93         if( !dir.rmdir(ofiles[i]) ){ errlist << ofiles[i]; } 
    94       }else{ 
    95         if( !QFile::remove(ofiles[i]) ){ errlist << ofiles[i]; } 
     137      errlist << removeItem(ofiles[i]); 
     138    }else if(isCP || isRESTORE){ 
     139      ui->label->setText( QString(tr("Copying: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); 
     140      if(QFile::exists(nfiles[i])){ 
     141        if(overwrite){ 
     142          errlist << removeItem(nfiles[i]); 
     143        }else{ 
     144          nfiles[i] = newFileName(nfiles[i]); 
     145        } 
    96146      } 
    97     }else if(isCP){ 
    98       ui->label->setText( QString(tr("Copying: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); 
    99       if( !QFile::copy(ofiles[i], nfiles[i]) ){ 
    100         errlist << ofiles[i]; 
    101       }else{ 
    102         // for "copies" use the same permissions as the original file 
    103         QFile::setPermissions(nfiles[i], QFile::permissions(ofiles[i])); 
    104       } 
    105     }else if(isRESTORE){ 
    106       ui->label->setText( QString(tr("Copying: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); 
    107       if( !QFile::copy(ofiles[i], nfiles[i]) ){ 
    108         errlist << ofiles[i]; 
    109       }else{ 
    110         // for "restores" set user/group read/write 
    111         QFile::setPermissions(nfiles[i], QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup); 
    112       } 
     147      errlist << copyItem(ofiles[i], nfiles[i]); 
    113148    }else if(isMV){ 
    114149      ui->label->setText( QString(tr("Moving: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); 
     
    120155  } 
    121156  //All finished, so close the dialog if successful 
     157  errlist.removeAll(""); //make sure to clear any empty items 
    122158  if(!errlist.isEmpty()){ 
    123159    QString msg; 
     
    128164    QMessageBox::warning(this, tr("File Errors"), msg+"\n\n"+errlist.join("\n")); 
    129165  } 
     166  noerrors = errlist.isEmpty(); 
    130167  this->close(); 
    131168} 
  • lumina/lumina-fm/FODialog.h

    r20c7552 rb3b08221  
    3232        ~FODialog(); 
    3333 
     34        bool noerrors; 
     35 
     36        void setOverwrite(bool); 
    3437        void RemoveFiles(QStringList paths); 
    3538        void CopyFiles(QStringList oldPaths, QStringList newPaths);       //same permissions as old files 
     
    4043        Ui::FODialog *ui; 
    4144        bool isRM, isCP, isRESTORE, isMV; 
    42         bool stopped; 
     45        bool stopped, overwrite; 
    4346        QStringList ofiles, nfiles; //original/new files 
    4447 
    4548        QStringList subfiles(QString dirpath); //recursive function for fetching all "child" files/dirs (dirs last) 
     49        QString newFileName(QString path); 
     50        QStringList removeItem(QString path); 
     51        QStringList copyItem(QString oldpath, QString newpath); 
    4652 
    4753private slots: 
  • lumina/lumina-fm/MainUI.cpp

    r20c7552 rb3b08221  
    117117  connect(ui->tool_zfs_nextSnap, SIGNAL(clicked()), this, SLOT(nextSnapshot()) ); 
    118118  connect(ui->tool_zfs_prevSnap, SIGNAL(clicked()), this, SLOT(prevSnapshot()) ); 
     119  connect(ui->tool_zfs_restoreItem, SIGNAL(clicked()), this, SLOT(restoreItems()) ); 
    119120} 
    120121 
     
    290291  ui->slider_zfs_snapshot->setValue(snapDirs.length()); 
    291292  //Now go to the file restore page 
     293  showSnapshot(); //Make sure it is updated for the current directory 
    292294  ui->stackedWidget->setCurrentWidget(ui->page_zfs);     
    293295} 
     
    435437void MainUI::ItemRun(const QModelIndex &index){ 
    436438  //This is called when the user double clicks a file/directory 
    437   QString val = fsmod->fileName(index); 
     439  QString val = fsmod->filePath(index).section("/",-1); 
    438440  QString itemPath = getCurrentDir(); 
    439441  if( !itemPath.endsWith("/")){ itemPath.append("/"); } 
     
    516518} 
    517519 
     520void MainUI::restoreItems(){ 
     521   //Get the selected items 
     522   QStringList sel; 
     523   QModelIndexList items = ui->tree_zfs_dir->selectionModel()->selectedIndexes(); 
     524   for(int i=0; i<items.length(); i++){ 
     525     sel << snapmod->filePath(items[i]).section("/",-1); 
     526   } 
     527   sel.removeDuplicates(); 
     528   if(sel.isEmpty()){ return; } //nothing selected 
     529   //Get the directories 
     530   QString snapdir = snapDirs[ui->slider_zfs_snapshot->value()-1]; 
     531   QString basedir = getCurrentDir(); 
     532   if(!basedir.endsWith("/")){ basedir.append("/"); } 
     533   if(!snapdir.endsWith("/")){ snapdir.append("/"); } 
     534   //Fill out the lists appropriately 
     535   QStringList resto; 
     536   qDebug() << "Items Selected:" << sel; 
     537   for(int i=0; i<sel.length(); i++){ 
     538     resto << basedir+sel[i]; 
     539     sel[i] = snapdir+sel[i]; 
     540   } 
     541   qDebug() << "Restore Items:" << sel << "\n" << resto; 
     542   //Restore the items 
     543   FODialog dlg(this); 
     544        dlg.setOverwrite(ui->check_zfs_overwrite->isChecked()); 
     545        dlg.RestoreFiles(sel, resto); 
     546   dlg.exec(); 
     547   if(dlg.noerrors){ 
     548     QMessageBox::information(this, tr("Success"), tr("Successfully restored selection") ); 
     549   } 
     550} 
     551 
    518552// Context Menu Actions 
    519553void MainUI::OpenItem(){ 
     
    547581 
    548582void MainUI::RemoveItem(){ 
    549   if(!CItem.isValid()){ return; } 
    550   QModelIndex index = CItem; //save this for the moment - since the CItem might get cleared in a couple seconds 
    551   QString fname = fsmod->fileName(index); 
    552   QString baseDir = getCurrentDir(); 
    553   if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
    554   baseDir.append(fname); 
     583   //Get the selected items 
     584   QStringList sel, names; 
     585   QModelIndexList items = ui->tree_dir_view->selectionModel()->selectedIndexes(); 
     586   QString baseDir = getCurrentDir(); 
     587   if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
     588   for(int i=0; i<items.length(); i++){ 
     589     if(!names.contains(fsmod->filePath(items[i]).section("/",-1)) ){ 
     590        names << fsmod->filePath(items[i]).section("/",-1); 
     591        sel << baseDir+fsmod->filePath(items[i]).section("/",-1); 
     592     } 
     593   } 
     594   if(sel.isEmpty()){ return; } //nothing selected 
    555595  //Verify permanent removal of file/dir 
    556   if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file/directory from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+fname, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
     596  if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file(s) from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+names.join("\n"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
    557597    return; //cancelled 
    558598  } 
    559599  //Now remove the file/dir 
    560   //bool ok = false; 
    561   qDebug() << "Delete: "<<baseDir; 
     600  qDebug() << "Delete: "<<sel; 
    562601  FODialog dlg(this); 
    563     dlg.RemoveFiles(QStringList() << baseDir); 
     602    dlg.RemoveFiles(sel); 
    564603    dlg.exec(); 
    565   /*if(fsmod->isDir(index)){ 
    566     qDebug() << " - Note: Recursive directory deletion not implemented yet!"; 
    567     ok = fsmod->rmdir(index); 
    568   }else{ 
    569     ok = fsmod->remove(index); 
    570   } 
    571   if(!ok){ 
    572     QMessageBox::warning(this, tr("Removal Failure"), tr("The file or directory could not be deleted. Please check that you have the proper permissions to delete it.")); 
    573   }*/ 
    574604} 
    575605 
  • lumina/lumina-fm/MainUI.h

    r20c7552 rb3b08221  
    115115        void nextSnapshot(); 
    116116        void prevSnapshot(); 
     117        void restoreItems(); 
    117118         
    118119        //Context Menu Actions 
  • lumina/lumina-fm/MainUI.ui

    r20c7552 rb3b08221  
    1919     <widget class="QStackedWidget" name="stackedWidget"> 
    2020      <property name="currentIndex"> 
    21        <number>0</number> 
     21       <number>3</number> 
    2222      </property> 
    2323      <widget class="QWidget" name="page_browser"> 
     
    390390          <property name="selectionMode"> 
    391391           <enum>QAbstractItemView::ExtendedSelection</enum> 
     392          </property> 
     393          <property name="selectionBehavior"> 
     394           <enum>QAbstractItemView::SelectRows</enum> 
    392395          </property> 
    393396          <property name="rootIsDecorated"> 
Note: See TracChangeset for help on using the changeset viewer.