Changeset 48743e0


Ignore:
Timestamp:
06/25/14 10:15:03 (3 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.3
Children:
143a31e
Parents:
ad79832
Message:

Get the full cut/copy/paste/rename functionality working in lumina-fm.
It will use the global clipboard for saving the cut/copy information, but since there is no standardized method/format I used the following:
Mimetype: x-special/lumina-copied-files
Data: QStringList(converted to bytes) of "\n" delimited entries of the form:
[cut/copy]::::[path-to-file]

Location:
lumina/lumina-fm
Files:
4 edited

Legend:

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

    r08438b40 r48743e0  
    1414  ui->push_stop->setIcon( LXDG::findIcon("edit-delete","") ); 
    1515  //Now set the internal defaults 
    16   isRM = isCP = isRESTORE = isMV = stopped = overwrite = noerrors = false; 
     16  isRM = isCP = isRESTORE = isMV = stopped = noerrors = false; 
     17  overwrite = -1; //set to automatic by default 
    1718} 
    1819 
     
    2223 
    2324void FODialog::setOverwrite(bool ovw){ 
    24   overwrite = ovw; 
     25  if(ovw){ overwrite = 1; } 
     26  else{ overwrite = 0; } 
    2527} 
    2628 
     
    9092  QStringList err;       
    9193  for(int i=0; i<items.length(); i++){ 
    92     if(items[i]==path){ 
    93       QDir dir; 
    94       if( !dir.rmdir(items[i]) ){ err << items[i]; }         
    95     }else if(QFileInfo(items[i]).isDir()){ 
    96       err << removeItem(items[i]); 
     94    if(QFileInfo(items[i]).isDir()){ 
     95      if(items[i]==path){ 
     96        //Current Directory Removal 
     97        QDir dir; 
     98        if( !dir.rmdir(items[i]) ){ err << items[i]; }                 
     99      }else{ 
     100        //Recursive Directory Removal 
     101        err << removeItem(items[i]);           
     102      } 
    97103    }else{ 
    98       if( !QFile::remove(items[i]) ){ err << items[i]; } 
     104      //Simple File Removal 
     105      if( !QFile::remove(items[i]) ){ err << items[i]; }             
    99106    } 
    100107  } 
     
    117124      if(isCP){ 
    118125        QFile::setPermissions(newpath, QFile::permissions(oldpath)); 
     126        //Nothing special for copies at the moment (might be something we run into later) 
    119127      }else if(isRESTORE){ 
    120         QFile::setPermissions(newpath, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup); 
     128        QFile::setPermissions(newpath, QFile::permissions(oldpath)); 
     129        //Nothing special for restores at the moment (might be something we run into later) 
    121130      } 
    122131    } 
     
    132141  ui->progressBar->setValue(0); 
    133142  ui->progressBar->setVisible(true); 
     143  if(!isRM && overwrite==-1){ 
     144    //Check if the new files already exist, and prompt for action 
     145    QStringList existing; 
     146    for(int i=0; i<nfiles.length(); i++){ 
     147      if(QFile::exists(nfiles[i])){ existing << nfiles[i].section("/",-1); } 
     148    } 
     149    if(!existing.isEmpty()){ 
     150      //Prompt for whether to overwrite, not overwrite, or cancel 
     151      QMessageBox::StandardButton ans = QMessageBox::question(this, tr("Overwrite Files?"), tr("Do you want to overwrite the existing files?")+"\n"+tr("Note: It will just add a number to the filename otherwise.")+"\n\n"+existing.join(", "), QMessageBox::YesToAll | QMessageBox::NoToAll | QMessageBox::Cancel, QMessageBox::NoToAll); 
     152      if(ans==QMessageBox::NoToAll){ overwrite = 0; } //don't overwrite 
     153      else if(ans==QMessageBox::YesToAll){ overwrite = 1; } //overwrite 
     154      else{ this->close(); return; } //cancel operations 
     155    } 
     156  } 
    134157  //Now start iterating over the operations 
    135158  QStringList errlist; 
  • lumina/lumina-fm/FODialog.h

    rb3b0822 r48743e0  
    2121// libLumina includes 
    2222#include <LuminaXDG.h> 
     23#include <LuminaUtils.h> 
    2324 
    2425namespace Ui{ 
     
    4344        Ui::FODialog *ui; 
    4445        bool isRM, isCP, isRESTORE, isMV; 
    45         bool stopped, overwrite; 
     46        bool stopped; 
     47        int overwrite; // [-1= auto, 0= no overwrite, 1= overwrite] 
    4648        QStringList ofiles, nfiles; //original/new files 
    4749 
  • lumina/lumina-fm/MainUI.cpp

    rba50b13 r48743e0  
    561561void MainUI::OpenContextMenu(const QPoint &pt){ 
    562562  CItem = ui->tree_dir_view->indexAt(pt); 
    563   if(!CItem.isValid()){ return; } 
    564   //Create the context menu for this particular item 
     563    //Create the context menu 
    565564  contextMenu->clear(); 
    566   if(fsmod->isDir(CItem)){ 
    567     contextMenu->addAction(LXDG::findIcon("tab-new-background",""), tr("Open in new tab"), this, SLOT(OpenDir()) ); 
    568   }else{ 
    569     contextMenu->addAction(LXDG::findIcon("quickopen-file",""), tr("Open"), this, SLOT(OpenItem()) ); 
    570     contextMenu->addAction(tr("Open With..."), this, SLOT(OpenItemWith()) ); 
    571   } 
     565  if(CItem.isValid()){ 
     566    //Valid Item right-clicked, show the item-specific options 
     567    if(fsmod->isDir(CItem)){ 
     568      contextMenu->addAction(LXDG::findIcon("tab-new-background",""), tr("Open in new tab"), this, SLOT(OpenDir()) ); 
     569    }else{ 
     570      contextMenu->addAction(LXDG::findIcon("quickopen-file",""), tr("Open"), this, SLOT(OpenItem()) ); 
     571      contextMenu->addAction(tr("Open With..."), this, SLOT(OpenItemWith()) ); 
     572    } 
     573    contextMenu->addAction(LXDG::findIcon("edit-rename",""), tr("Rename"), this, SLOT(RenameItem()) )->setEnabled(isUserWritable); 
     574    contextMenu->addSeparator(); 
     575  } 
     576  //Now add the general selection options 
     577  contextMenu->addAction(LXDG::findIcon("edit-cut",""), tr("Cut Selection"), this, SLOT(CutItems()) )->setEnabled(isUserWritable); 
     578  contextMenu->addAction(LXDG::findIcon("edit-copy",""), tr("Copy Selection"), this, SLOT(CopyItems()) ); 
     579  contextMenu->addAction(LXDG::findIcon("edit-paste",""), tr("Paste"), this, SLOT(PasteItems()) )->setEnabled(QApplication::clipboard()->mimeData()->hasFormat("x-special/lumina-copied-files")); 
    572580  contextMenu->addSeparator(); 
    573   contextMenu->addAction(LXDG::findIcon("list-remove",""), tr("Delete"), this, SLOT(RemoveItem()) ); 
     581  contextMenu->addAction(LXDG::findIcon("edit-delete",""), tr("Delete Selection"), this, SLOT(RemoveItem()) )->setEnabled(isUserWritable); 
     582  //Now add all the general  
    574583  contextMenu->popup(ui->tree_dir_view->mapToGlobal(pt)); 
    575584} 
     
    668677void MainUI::OpenItem(){ 
    669678  if(!CItem.isValid()){ return; } 
    670   QString fname = fsmod->fileName(CItem); 
    671   QString baseDir = getCurrentDir(); 
    672   if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
    673   baseDir.append(fname); 
    674   qDebug() << "Opening File:" << baseDir; 
    675   QProcess::startDetached("lumina-open \""+baseDir+"\""); 
     679  QString fname = fsmod->filePath(CItem); 
     680  qDebug() << "Opening File:" << fname; 
     681  QProcess::startDetached("lumina-open \""+fname+"\""); 
    676682} 
    677683 
    678684void MainUI::OpenItemWith(){ 
    679685  if(!CItem.isValid()){ return; } 
    680   QString fname = fsmod->fileName(CItem); 
    681   QString baseDir = getCurrentDir(); 
    682   if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
    683   baseDir.append(fname); 
    684   qDebug() << "Opening File:" << baseDir; 
    685   QProcess::startDetached("lumina-open -select \""+baseDir+"\"");        
     686  QString fname = fsmod->filePath(CItem); 
     687  qDebug() << "Opening File:" << fname; 
     688  QProcess::startDetached("lumina-open -select \""+fname+"\"");  
    686689} 
    687690 
    688691void MainUI::OpenDir(){ 
    689692  if(!CItem.isValid()){ return; } 
    690   QString fname = fsmod->fileName(CItem); 
    691   QString baseDir = getCurrentDir(); 
    692   if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
    693   baseDir.append(fname); 
    694   OpenDirs(QStringList() << baseDir);            
     693  QString fname = fsmod->filePath(CItem); 
     694  OpenDirs(QStringList() << fname);              
    695695} 
    696696 
     
    723723} 
    724724 
     725void MainUI::RenameItem(){ 
     726  if(!CItem.isValid()){ return; } 
     727  QString fname = fsmod->filePath(CItem); 
     728  QString path = fname; 
     729    fname = fname.section("/",-1); //turn this into just the file name 
     730    path.chop(fname.length());  //turn this into the base directory path (has a "/" at the end) 
     731  //Now prompt for the new filename 
     732  bool ok = false; 
     733  QString nname = QInputDialog::getText(this, tr("Rename File"),tr("New Name:"), QLineEdit::Normal, fname, &ok); 
     734  if(!ok || nname.isEmpty()){ return; } //cancelled 
     735  //Now check for a file extension and add it if necessary 
     736  QString oext = fname.section(".",-1); 
     737    if(oext==fname){ oext.clear(); } //no extension 
     738  QString next = nname.section(".",-1); 
     739    if(next==nname){ next.clear(); } //no extension 
     740  if(next.isEmpty() && !oext.isEmpty()){ 
     741    nname.append( "."+oext ); 
     742  } 
     743  //Check if this filename already exists 
     744  bool overwrite = QFile::exists(path+nname); 
     745  if(overwrite){ 
     746    if(QMessageBox::Yes != QMessageBox::question(this, tr("Overwrite File?"), tr("An existing file with the same name will be replaced. Are you sure you want to proceed?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
     747      return; //cancelled 
     748    } 
     749  } 
     750  //Now perform the move 
     751  qDebug() << "Rename:" << path+fname << "->" << path+nname; 
     752  FODialog dlg(this); 
     753    dlg.setOverwrite(overwrite); 
     754    dlg.MoveFiles(QStringList() << path+fname, QStringList() << path+nname); 
     755    dlg.exec(); 
     756} 
     757 
     758void MainUI::CutItems(){ 
     759  //Get all the selected Items  
     760  QStringList sel; 
     761  QModelIndexList items = ui->tree_dir_view->selectionModel()->selectedIndexes(); 
     762  for(int i=0; i<items.length(); i++){ 
     763    sel << fsmod->filePath(items[i]); 
     764  } 
     765  sel.removeDuplicates(); 
     766  if(sel.isEmpty()){ return; } //nothing selected 
     767  qDebug() << "Cut Items:" << sel; 
     768  //Format the data string 
     769  for(int i=0; i<sel.length(); i++){ 
     770    sel[i] = sel[i].prepend("cut::::"); 
     771  } 
     772   
     773  //Now save that data to the global clipboard 
     774  QMimeData *dat = new QMimeData; 
     775        dat->clear(); 
     776        dat->setData("x-special/lumina-copied-files", sel.join("\n").toLocal8Bit()); 
     777  QApplication::clipboard()->clear(); 
     778  QApplication::clipboard()->setMimeData(dat); 
     779} 
     780 
     781void MainUI::CopyItems(){ 
     782  //Get all the selected Items  
     783  QStringList sel; 
     784  QModelIndexList items = ui->tree_dir_view->selectionModel()->selectedIndexes(); 
     785  for(int i=0; i<items.length(); i++){ 
     786    sel << fsmod->filePath(items[i]); 
     787  } 
     788  sel.removeDuplicates(); 
     789  if(sel.isEmpty()){ return; } //nothing selected 
     790  qDebug() << "Copy Items:" << sel; 
     791  //Format the data string 
     792  for(int i=0; i<sel.length(); i++){ 
     793    sel[i] = sel[i].prepend("copy::::"); 
     794  } 
     795  //Now save that data to the global clipboard 
     796  QMimeData *dat = new QMimeData; 
     797        dat->clear(); 
     798        dat->setData("x-special/lumina-copied-files", sel.join("\n").toLocal8Bit()); 
     799  QApplication::clipboard()->clear(); 
     800  QApplication::clipboard()->setMimeData(dat);   
     801} 
     802 
     803void MainUI::PasteItems(){ 
     804  const QMimeData *dat = QApplication::clipboard()->mimeData(); 
     805  if(!dat->hasFormat("x-special/lumina-copied-files")){ return; } //nothing to paste 
     806  QStringList cut, copy, newcut, newcopy; 
     807  QStringList raw = QString(dat->data("x-special/lumina-copied-files")).split("\n"); 
     808  QString base = getCurrentDir(); 
     809  if(!base.endsWith("/")){ base.append("/"); } 
     810  for(int i=0; i<raw.length(); i++){ 
     811    if(raw[i].startsWith("cut::::")){  
     812        cut << raw[i].section("::::",1,50); 
     813        newcut << base+raw[i].section("::::",1,50).section("/",-1); 
     814    } 
     815    else if(raw[i].startsWith("copy::::")){  
     816        copy << raw[i].section("::::",1,50);  
     817        newcopy<< base+raw[i].section("::::",1,50).section("/",-1); 
     818    } 
     819  } 
     820 
     821  if(!copy.isEmpty()){  
     822    qDebug() << "Paste Copy:" << copy << "->" << newcopy; 
     823    FODialog dlg(this); 
     824      dlg.CopyFiles(copy, newcopy); 
     825      dlg.exec(); 
     826  } 
     827  if(!cut.isEmpty()){ 
     828    qDebug() << "Paste Cut:" << cut << "->" << newcut; 
     829    FODialog dlg(this); 
     830      dlg.MoveFiles(cut, newcut); 
     831      dlg.exec(); 
     832  } 
     833         
     834} 
     835 
    725836void MainUI::RunInMediaPlayer(){ //open in the media player 
    726837         
  • lumina/lumina-fm/MainUI.h

    rba50b13 r48743e0  
    2626#include <QShortcut> 
    2727#include <QCompleter> 
     28#include <QClipboard> 
     29#include <QMimeData> 
    2830 
    2931// libLumina includes 
     
    136138         
    137139        //Context Menu Actions 
     140         // - single item actions 
    138141        void OpenItem(); //run "lumina-open" on it 
    139142        void OpenItemWith(); //run "lumina-open -select" on it 
    140143        void OpenDir(); //open the dir in a new tab 
    141144        void RemoveItem(); //Remove the item permanently 
     145        void RenameItem(); 
     146         // - full selection actions 
     147        void CutItems(); 
     148        void CopyItems(); 
     149        void PasteItems(); 
     150         // - optional launching actions 
    142151        void RunInMediaPlayer(); //open in the media player 
    143152        void RunInSlideShow(); //open in slideshow viewer 
Note: See TracChangeset for help on using the changeset viewer.