Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

advancedfmMenu.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    AdvancedFm.cpp
00003   -------------------
00004   ** Created: Sat Mar 9 23:33:09 2002
00005     copyright            : (C) 2002 by ljp
00006     email               : ljp@llornkcor.com
00007     *   This program is free software; you can redistribute it and/or modify  *
00008     *   it under the terms of the GNU General Public License as published by  *
00009     *   the Free Software Foundation; either version 2 of the License, or     *
00010     *   (at your option) any later version.                                   *
00011     ***************************************************************************/
00012 
00013 #include "advancedfm.h"
00014 #include "output.h"
00015 #include "filePermissions.h"
00016 
00017 /* OPIE */
00018 #include <opie2/odebug.h>
00019 #include <qpe/lnkproperties.h>
00020 #include <qpe/qpeapplication.h>
00021 #include <qpe/applnk.h>
00022 using namespace Opie::Core;
00023 
00024 /* QT*/
00025 
00026 #include <qmessagebox.h>
00027 #include <qpopupmenu.h>
00028 #include <qlistview.h>
00029 
00030 /* STD */
00031 
00032 #include <errno.h>
00033 #include <stdlib.h>
00034 #include <unistd.h>
00035 #include <sys/stat.h>
00036 #include <dirent.h>
00037 #include <sys/sendfile.h>
00038 #include <fcntl.h>
00039 
00040 void AdvancedFm::doDirChange() {
00041    QString pathItem = CurrentView()->currentItem()->text(0);
00042    if( pathItem == "../") {
00043       ListClicked( CurrentView()->currentItem());
00044    } else {
00045       if( pathItem.find(" -> ",0,TRUE) != -1)
00046          pathItem = dealWithSymName((const QString&)pathItem)+"/";
00047 //      owarn << pathItem << oendl;
00048       changeTo( CurrentDir()->path()+"/"+pathItem.left( pathItem.length() - 1) );
00049    }
00050 }
00051 
00052 void AdvancedFm::showMenuHidden() {
00053                 if (b) {
00054                                 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
00055                                 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
00056                                 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
00057     } else {
00058                                 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00059                                 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00060                                 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
00061     }
00062                 b = !b;
00063                 populateView();
00064 }
00065 
00066 void AdvancedFm::showHidden() {
00067                 if (b) {
00068                                 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
00069                                 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
00070     }  else {
00071                                 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00072                                 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00073     }
00074                 populateView();
00075 }
00076 
00077 QString AdvancedFm::dealWithSymName(const QString &fileName) {
00078                 QString strItem = fileName;
00079                 return  strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4);
00080 }
00081 
00082 void AdvancedFm::runThis() {
00083                 if( !CurrentView()->currentItem()) return;
00084                 QString fs;
00085                 QDir *thisDir = CurrentDir();
00086 
00087                 QString curFile = CurrentView()->currentItem()->text(0);
00088                 QString path = thisDir->canonicalPath();
00089 
00090                 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 )  //if symlink
00091 
00092                                 curFile = dealWithSymName((const QString&)curFile);
00093 
00094                 if(curFile != "../") {
00095 
00096                                 fs = getFileSystemType((const QString &) path);
00097                                 QFileInfo fileInfo( path  + "/" + curFile);
00098 //      odebug << fileInfo.owner() << oendl;
00099 
00100                                 if( (fileInfo.permission( QFileInfo::ExeUser)
00101                                                  | fileInfo.permission( QFileInfo::ExeGroup)
00102                                                  | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) {
00103                                                 | fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
00104                                                 QCopEnvelope e("QPE/System", "execute(QString)" );
00105                                                 e << curFile;
00106                                 } else {
00107                                                 curFile =  path + "/" + curFile;
00108                                                 DocLnk nf(curFile);
00109                                                 QString execStr = nf.exec();
00110 //          odebug << execStr << oendl;
00111                                                 if( execStr.isEmpty() ) {
00112             } else {
00113                                                                 nf.execute();
00114             }
00115         }
00116     }
00117 }
00118 
00119 void AdvancedFm::runText() {
00120                 if( !CurrentView()->currentItem()) return;
00121                 QString curFile = CurrentView()->currentItem()->text(0);
00122                 if(curFile != "../") {
00123                                 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 )  //if symlink
00124                                                 curFile = dealWithSymName((const QString&)curFile);
00125                                 curFile =  CurrentDir()->canonicalPath()+"/"+curFile;
00126                                 QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" );
00127                                 e << curFile;
00128     }
00129 }
00130 
00131 void AdvancedFm::makeDir() {
00132                 InputDialog *fileDlg;
00133                 fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
00134                 fileDlg->exec();
00135                 if( fileDlg->result() == 1 ) {
00136                                 QDir *thisDir = CurrentDir();
00137                                 QString  filename = fileDlg->LineEdit1->text();
00138                                 thisDir->mkdir( thisDir->canonicalPath()+"/"+filename);
00139                 }
00140     populateView();
00141 }
00142 
00143 void AdvancedFm::doDelete() {
00144    QStringList curFileList = getPath();
00145    bool doMsg=true;
00146    int count = curFileList.count();
00147    if( count > 0)  {
00148       if(count > 1 ) {
00149          QString msg;
00150          msg=tr("<p>Really delete %1 files?</p>").arg(count);
00151          switch ( QMessageBox::warning(this,tr("Delete"),msg
00152                                        ,tr("Yes"),tr("No"),0,0,1) )
00153          {
00154          case 0:
00155             doMsg=false;
00156             break;
00157          case 1:
00158             return;
00159             break;
00160                                  default:
00161                                          return;
00162                                          break;
00163          };
00164       }
00165 
00166       QString myFile;
00167 
00168       for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00169          myFile = (*it);
00170          if( myFile.find(" -> ",0,TRUE) != -1)
00171             myFile = myFile.left( myFile.find(" -> ",0,TRUE));
00172 
00173          QString f = CurrentDir()->canonicalPath();
00174          if(f.right(1).find("/",0,TRUE) == -1)
00175             f += "/";
00176          f += myFile;
00177          if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
00178             //if file is a directory
00179 
00180             switch ( QMessageBox::warning( this, tr("Delete Directory?"),
00181                                            tr("<p>Really delete %1 and all it's contents?</p>" ).arg( f ) ,
00182                                            tr("Yes"), tr("No"), 0, 0, 1) ) {
00183             case 0:
00184                                                         {
00185                                                                 f=f.left(f.length()-1);
00186                                                                 QString cmd="rm -rf "+f;
00187                                                                 startProcess( (const QString)cmd.latin1() );
00188                                                                 populateView();
00189                                                         }
00190                                                         break;
00191             case 1:
00192                                                         // exit
00193                                                         break;
00194                                                 default:
00195                                                         break;
00196             };
00197 
00198          } else {
00199                                          if(doMsg) {
00200                                                  switch ( QMessageBox::warning(this,tr("Delete"),
00201                                                                          tr("<p>Really delete %1?</p>").arg( myFile ),
00202                                                                          tr("Yes"), tr("No"), 0, 0, 1) ) {
00203                                                  case 0:
00204                                                          break;
00205                                                  case 1:
00206                                                          return;
00207                                                          break;
00208                                                  default:
00209                                                          return;
00210                                                          break;
00211                                                  };
00212                                          }
00213 
00214             QString cmd="rm "+f;
00215             QFile file(f);
00216             QFileInfo fi(myFile);
00217             if( fi.fileName().find("../",0,TRUE)==-1) {
00218 //               odebug << "remove link files "+myFile << oendl;
00219 
00220 //               DocLnk lnk(f);
00221                  DocLnk *lnk;
00222                  lnk = new DocLnk(f);
00223 //                 odebug << "Deleting doclnk " + lnk->linkFile() << oendl;
00224                  if(lnk->isValid())
00225                     lnk->removeLinkFile();
00226                // delete lnk;
00227                file.remove();
00228             }
00229          }
00230       }
00231    }
00232     populateView();
00233 }
00234 
00235 void AdvancedFm::filePerms() {
00236    QStringList curFileList = getPath();
00237    QString filePath;
00238 
00239    filePath = CurrentDir()->canonicalPath()+"/";
00240 
00241    for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00242       filePermissions *filePerm;
00243       filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it));
00244       QPEApplication::execDialog( filePerm );
00245       if( filePerm )
00246          delete  filePerm;
00247    }
00248     populateView();
00249 }
00250 
00251 void AdvancedFm::doProperties() {
00252 #if defined(QT_QWS_OPIE)
00253 
00254    QStringList curFileList = getPath();
00255 
00256    QString filePath;
00257    filePath = CurrentDir()->canonicalPath()+"/";
00258 
00259 //   odebug << "" << curFileList.count() << "" << oendl;
00260 
00261    for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00262 //      odebug << (filePath+*it) << oendl;
00263       DocLnk lnk( (filePath+*it));
00264       LnkProperties prop( &lnk );
00265       QPEApplication::execDialog( &prop );
00266    }
00267 #endif
00268 
00269 }
00270 
00271 void AdvancedFm::upDir() {
00272 
00273   QDir dir( CurrentDir()->canonicalPath());
00274   dir.cdUp();
00275         changeTo(dir.canonicalPath());
00276 }
00277 
00278 void AdvancedFm::copyTimer() {
00279                 QTimer::singleShot(125,this,SLOT(copy()));
00280 }
00281 
00282 void AdvancedFm::copy() {
00283                 QStringList curFileList = getPath();
00284 
00285                 QDir *thisDir = CurrentDir();
00286                 QDir *thatDir = OtherDir();
00287 
00288                 bool doMsg = true;
00289                 int count = curFileList.count();
00290                 if( count > 0) {
00291                                 if(count > 1 ){
00292                                                 QString msg;
00293                                                 msg=tr("<p>Really copy %1 files?</p>").arg(count);
00294                                                 switch ( QMessageBox::warning(this,tr("Copy"),msg
00295                                                                                                                                                                         ,tr("Yes"),tr("No"),0,0,1) )
00296                                                         {
00297                                                         case 0:
00298                                                                 doMsg=false;
00299                                                                 break;
00300                                                         case 1:
00301                                                                 return;
00302                                                                 break;
00303                                                         default:
00304                 return;
00305                                                                 break;
00306                                                         };
00307                                 }
00308 
00309                                 QString curFile, item, destFile;
00310                                 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00311                                                 item=(*it);
00312                                                 if(item.find("->",0,TRUE)) //symlink
00313                                                                 item = item.left(item.find("->",0,TRUE));
00314 
00315                                                 curFile = thisDir->canonicalPath()+"/"+ item;
00316                                                 destFile = thatDir->canonicalPath()+"/"+ item;
00317 
00318 //          odebug << "Destination file is "+destFile << oendl;
00319 //          odebug << "CurrentFile file is " + curFile << oendl;
00320 
00321                                                 QFile f(destFile);
00322                                                 if( f.exists()) {
00323                                                                 if(doMsg) {
00324                                                                         switch ( QMessageBox::warning(this,tr("File Exists!"),
00325                                                                                                                                                                                                 tr("<p>%1 already  exists. Ok to overwrite?</P>").arg(item),
00326                                                                                                                                                                                                 tr("Yes"),tr("No"),0,0,1)) {
00327                                                                                 case 0:
00328                                                                                 break;
00329                                                                         case 1:
00330                                                                                 return;
00331                                                                                 break;
00332                                                                         default:
00333                                                                                 return;
00334                                                                                 break;
00335                                                                         };
00336                                                                 }
00337                                                                 f.remove();
00338                                                 }
00339 
00340                                                 if( !copyFile( curFile, destFile) )  {
00341                                                                 QMessageBox::message("AdvancedFm",
00342                                                                                                                                                  tr( "<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
00343                                                                 return;
00344                                                 }
00345                                 }
00346                                 rePopulate();
00347                 }
00348 }
00349 
00350 void AdvancedFm::copyAsTimer() {
00351                 QTimer::singleShot(125,this,SLOT(copyAs()));
00352 }
00353 
00354 void AdvancedFm::copyAs() {
00355 
00356    QStringList curFileList = getPath();
00357    QString curFile, item;
00358    InputDialog *fileDlg;
00359 
00360    QDir *thisDir = CurrentDir();
00361    QDir *thatDir = OtherDir();
00362 
00363    for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00364       QString destFile;
00365       item=(*it);
00366       curFile = thisDir->canonicalPath()+"/"+(*it);
00367       fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0);
00368 
00369       fileDlg->setInputText((const QString &) destFile );
00370       fileDlg->exec();
00371 
00372       if( fileDlg->result() == 1 ) {
00373          QString  filename = fileDlg->LineEdit1->text();
00374          destFile = thatDir->canonicalPath()+"/"+filename;
00375 
00376          QFile f( destFile);
00377          if( f.exists()) {
00378                                          switch (QMessageBox::warning(this,tr("File Exists!"),
00379                                                                                                                                                                 tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item),
00380                                                                                                                                                                 tr("Yes"),tr("No"),0,0,1) ) {
00381                                          case 0:
00382                                                  f.remove();
00383                                                  break;
00384                                          case 1:
00385                                                  return;
00386                                                  break;
00387                                          default:
00388                                                  return;
00389              break;
00390                                          };
00391          }
00392          if( !copyFile( curFile, destFile) ) {
00393             QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
00394             return;
00395          }
00396       }
00397       delete fileDlg;
00398 
00399    }
00400          rePopulate();
00401 //       setOtherTabCurrent();
00402    qApp->processEvents();
00403 
00404 }
00405 
00406 void AdvancedFm::copySameDirTimer() {
00407                 QTimer::singleShot(125,this,SLOT(copySameDir()));
00408 }
00409 
00410 void AdvancedFm::copySameDir() {
00411   qApp->processEvents();
00412   QStringList curFileList = getPath();
00413   QString curFile, item, destFile;
00414   InputDialog *fileDlg;
00415 
00416   QDir *thisDir = CurrentDir();
00417 
00418   for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00419       item=(*it);
00420       curFile = thisDir->canonicalPath()+"/"+ item;
00421 
00422       fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
00423       fileDlg->setInputText((const QString &) destFile );
00424       fileDlg->exec();
00425 
00426       if( fileDlg->result() == 1 ) {
00427 
00428           QString filename = fileDlg->LineEdit1->text();
00429           destFile = thisDir->canonicalPath()+"/"+filename;
00430 
00431           QFile f(destFile);
00432           if( f.exists()) {
00433                                                 switch (QMessageBox::warning(this,tr("Delete"),
00434                                                                                                                                                                  tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile),
00435                                                                                                                                                                  tr("Yes"),tr("No"),0,0,1) ) {
00436                                                 case 0:
00437                                                         f.remove();
00438                                                         break;
00439                                                 case 1:
00440                                                         return;
00441                                                         break;
00442                                                 default:
00443                                                         return;
00444                                                         break;
00445                                                 };
00446             }
00447           if(!copyFile( curFile,destFile) )  {
00448               QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
00449               return;
00450             }
00451 
00452 //          odebug << "copy "+curFile+" as "+destFile << oendl;
00453         }
00454       delete fileDlg;
00455     }
00456             rePopulate();
00457 }
00458 
00459 void AdvancedFm::moveTimer() {
00460                 QTimer::singleShot(125,this,SLOT(move()));
00461 }
00462 
00463 void AdvancedFm::move() {
00464 
00465                 QStringList curFileList = getPath();
00466                 if( curFileList.count() > 0) {
00467                                 QString curFile, destFile, item;
00468 
00469                                 QDir *thisDir = CurrentDir();
00470                                 QDir *thatDir = OtherDir();
00471                                 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00472                                                 item=(*it);
00473                                                 QString destFile =  thatDir->canonicalPath();
00474 
00475                                                 if(destFile.right(1).find("/",0,TRUE) == -1)
00476                                                                 destFile+="/";
00477                                                 destFile += item;
00478 //          odebug << "Destination file is "+destFile << oendl;
00479 
00480                                                 curFile = thisDir->canonicalPath();
00481                                                 if(curFile.right(1).find("/",0,TRUE) == -1)
00482                                                                 curFile +="/";
00483                                                 curFile+= item;
00484 //           odebug << "CurrentFile file is " + curFile << oendl;
00485 
00486                                                 if(QFileInfo(curFile).isDir()) {
00487                                                                 moveDirectory( curFile, destFile );
00488                                                                 rePopulate();
00489                                                                 return;
00490                                                 }
00491                                                 QFile f( destFile);
00492                                                 if( f.exists()) {
00493                                                         switch ( QMessageBox::warning(this,tr("File Exists!"),
00494                                                                                                                                                                                 tr("<p>%1 already  exists. Ok to overwrite?</P>").arg(destFile),
00495                                                                                                                                                                                 tr("Yes"),tr("No"),0,0,1)) {
00496                                                         case 0:
00497                                                                 break;
00498                                                         case 1:
00499                                                                 return;
00500                                                                 break;
00501                                                         default:
00502                                                                 return;
00503                                                                 break;
00504                                                         };
00505                                                 }
00506                                                                 if( !copyFile( curFile, destFile) )  {
00507                                                                                 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile));
00508                                                                                 return;
00509                                                                 } else
00510                                                                                 QFile::remove(curFile);
00511                                 }
00512                 }
00513                 rePopulate();
00514 //      setOtherTabCurrent();
00515 }
00516 
00517 bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
00518                 int err = 0;
00519                 if( copyDirectory( src, dest ) ) {
00520                                 QString cmd = "rm -rf " + src;
00521                                 err = system((const char*)cmd);
00522                 } else
00523                                 err = -1;
00524 
00525                 if(err!=0) {
00526                                 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src));
00527                                 return false;
00528                 }
00529                 return true;
00530 }
00531 
00532 bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
00533 
00534                 QString cmd = "/bin/cp -fpR " + src + " " + dest;
00535     owarn << cmd << oendl;
00536                 int    err = system( (const char *) cmd );
00537                 if ( err != 0 ) {
00538                                 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) );
00539                                 return false;
00540                 }
00541 
00542                 return true;
00543 }
00544 
00545 
00546 bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
00547                 if(QFileInfo(src).isDir()) {
00548                                 if( copyDirectory( src, dest )) {
00549 //                                              setOtherTabCurrent();
00550                                                 rePopulate();
00551                                                 return true;
00552                                 }
00553                                 else
00554                                                 return false;
00555                 }
00556 
00557 
00558                 bool success = true;
00559                 struct stat status;
00560                 QFile srcFile(src);
00561                 QFile destFile(dest);
00562                 int err=0;
00563                 int read_fd=0;
00564                 int write_fd=0;
00565                 struct stat stat_buf;
00566                 off_t offset = 0;
00567                 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
00568 //         owarn << "open failed" << oendl;
00569                                 return success = false;
00570                 }
00571                 read_fd = srcFile.handle();
00572                 if(read_fd != -1) {
00573                                 fstat (read_fd, &stat_buf);
00574                                 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
00575 //       owarn << "destfile open failed" << oendl;
00576                                                 return success = false;
00577                                 }
00578                                 write_fd = destFile.handle();
00579                                 if(write_fd != -1) {
00580                                                 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
00581                                                 if( err == -1) {
00582                                                                 QString msg;
00583                                                                 switch(err) {
00584                                                                         case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
00585                                                                         case EINVAL: msg = "Descriptor is not valid or locked. ";
00586                                                                         case ENOMEM: msg = "Insufficient memory to read from in_fd.";
00587                                                                         case EIO: msg = "Unspecified error while reading from in_fd.";
00588                                                                 };
00589                                                                 success = false;
00590 //              owarn << msg << oendl;
00591                                                 }
00592                                 } else {
00593                                                 success = false;
00594                                 }
00595                 } else {
00596                                 success = false;
00597                 }
00598                 srcFile.close();
00599                 destFile.close();
00600                         // Set file permissions
00601                 if( stat( QFile::encodeName(src), &status ) == 0 )  {
00602                                 chmod( QFile::encodeName(dest), status.st_mode );
00603     }
00604 
00605                 return success;
00606 }
00607 
00608 void AdvancedFm::runCommand() {
00609    if( !CurrentView()->currentItem()) return;
00610    QDir *thisDir = CurrentDir();
00611 
00612    QString curFile;
00613    curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0);
00614 
00615    InputDialog *fileDlg;
00616    fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
00617    fileDlg->setInputText(curFile);
00618    fileDlg->exec();
00619    //QString command;
00620 
00621    if( fileDlg->result() == 1 ) {
00622 //      odebug << fileDlg->LineEdit1->text() << oendl;
00623       QStringList command;
00624 
00625       command << "/bin/sh";
00626       command << "-c";
00627       command <<  fileDlg->LineEdit1->text();
00628       Output *outDlg;
00629       outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
00630       QPEApplication::execDialog( outDlg );
00631       qApp->processEvents();
00632 
00633    }
00634 }
00635 
00636 void AdvancedFm::runCommandStd() {
00637    if( !CurrentView()->currentItem()) return;
00638    QString curFile;
00639    QDir *thisDir = CurrentDir();
00640    QListView *thisView = CurrentView();
00641    if( thisView->currentItem())
00642       curFile = thisDir->canonicalPath() +"/"+  thisView->currentItem()->text(0);
00643 
00644    InputDialog *fileDlg;
00645    fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
00646    fileDlg->setInputText(curFile);
00647    fileDlg->exec();
00648 
00649    if( fileDlg->result() == 1 ) {
00650       qApp->processEvents();
00651       startProcess( (const QString)fileDlg->LineEdit1->text().latin1());
00652    }
00653 }
00654 
00655 void AdvancedFm::fileStatus() {
00656                 if( !CurrentView()->currentItem()) return;
00657                 QString curFile;
00658                 curFile = CurrentView()->currentItem()->text(0);
00659                 if(QFileInfo("/usr/bin/stat").exists()) {
00660                                 QStringList command;
00661                                 command << "/bin/sh";
00662                                 command << "-c";
00663                                 command << "stat -l "+ curFile;
00664                                 Output *outDlg;
00665                                 outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
00666                                 QPEApplication::execDialog( outDlg );
00667                 } else {
00668 /*    struct stat buf;
00669                 stat( curFile.local8bit(), &buf);
00670                 
00671                 st_dev dev;
00672                 st_uid uid;
00673                 st_gid gid;
00674                 st_size size;
00675                 st_atime atime;
00676                 st_mtime mtime;
00677                 st_ctime ctime;
00678     st_mode mode;
00679 */
00680                 }
00681 
00682                 qApp->processEvents();
00683 }
00684 
00685 
00686 void AdvancedFm::mkDir() {
00687     makeDir();
00688 }
00689 
00690 void AdvancedFm::rn() {
00691   renameIt();
00692 }
00693 
00694 void AdvancedFm::del() {
00695     doDelete();
00696 }
00697 
00698 void AdvancedFm::mkSym() {
00699   QString cmd;
00700   QStringList curFileList = getPath();
00701   if( curFileList.count() > 0) {
00702       QDir *thisDir = CurrentDir();
00703       QDir * thatDir = OtherDir();
00704 
00705       for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00706 
00707           QString destName = thatDir->canonicalPath()+"/"+(*it);
00708           if(destName.right(1) == "/") {
00709               destName = destName.left( destName.length() -1);
00710             }
00711 
00712           QString curFile =  thisDir->canonicalPath()+"/"+(*it);
00713 
00714           if( curFile.right(1) == "/") {
00715               curFile = curFile.left( curFile.length() -1);
00716             }
00717 
00718           cmd = "ln -s "+curFile+" "+destName;
00719 //          odebug << cmd << oendl;
00720           startProcess( (const QString)cmd );
00721         }
00722             rePopulate();
00723             setOtherTabCurrent();
00724     }
00725 }
00726 
00727 void AdvancedFm::doBeam() {
00728    Ir ir;
00729    if(!ir.supported())  {
00730    } else {
00731       QStringList curFileList = getPath();
00732       if( curFileList.count() > 0)  {
00733          for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
00734             QString curFile = (*it);
00735             QString curFilePath =  CurrentDir()->canonicalPath()+"/"+curFile;
00736             if( curFilePath.right(1) == "/") {
00737                curFilePath = curFilePath.left( curFilePath.length() -1);
00738             }
00739             Ir *file = new Ir(this, "IR");
00740             connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*)));
00741             file->send( curFilePath, curFile );
00742          }
00743       }
00744    }
00745 }
00746 
00747 void AdvancedFm::fileBeamFinished( Ir *) {
00748   QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") );
00749 }
00750 
00751 void AdvancedFm::selectAll() {
00752   QListView *thisView = CurrentView();
00753   thisView->selectAll(true);
00754   thisView->setSelected( thisView->firstChild(),false);
00755 }
00756 
00757 void AdvancedFm::startProcess(const QString & cmd) {
00758   QStringList command;
00759   OProcess *process;
00760   process = new OProcess();
00761   connect(process,SIGNAL(processExited(Opie::Core::OProcess*)),this,SLOT(processEnded(Opie::Core::OProcess*)));
00762   connect(process,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(oprocessStderr(Opie::Core::OProcess*,char*,int)));
00763 
00764   command << "/bin/sh";
00765   command << "-c";
00766   command << cmd.latin1();
00767   *process << command;
00768   if(!process->start(OProcess::NotifyOnExit, OProcess::All) )
00769     odebug << "could not start process" << oendl;
00770 }
00771 
00772 void AdvancedFm::processEnded(OProcess *) {
00773             rePopulate();
00774 }
00775 
00776 void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) {
00777 //    owarn << "received stderrt " << buflen << " bytes" << oendl;
00778 
00779     QString lineStr = buffer;
00780     QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") );
00781 }
00782 
00783 bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) {
00784                 if ( o->inherits( "QLineEdit" ) )  {
00785                                 if ( e->type() == QEvent::KeyPress ) {
00786                                                 QKeyEvent *ke = (QKeyEvent*)e;
00787                                                 if ( ke->key() == Key_Return ||
00788                                                                  ke->key() == Key_Enter )  {
00789                                                                 okRename();
00790                                                                 return true;
00791             }
00792                                                 else if ( ke->key() == Key_Escape ) {
00793                 cancelRename();
00794                 return true;
00795                                                 }
00796         }
00797                                 else if ( e->type() == QEvent::FocusOut ) {
00798             cancelRename();
00799             return true;
00800                                 }
00801     }
00802    if ( o->inherits( "QListView" ) ) {
00803        if ( e->type() == QEvent::FocusIn ) {
00804             if( o == Local_View) { //keep track of which view
00805                whichTab = 1;
00806                                        viewMenu->setItemChecked(viewMenu->idAt(0), true);
00807                                        viewMenu->setItemChecked(viewMenu->idAt(1), false);
00808             } else {
00809                whichTab = 2;
00810                                        viewMenu->setItemChecked(viewMenu->idAt(0), false);
00811                                        viewMenu->setItemChecked(viewMenu->idAt(1), true);
00812             }
00813        }
00814        OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection
00815      }
00816 
00817   return QWidget::eventFilter( o, e );
00818 }
00819 
00820 
00821 void AdvancedFm::cancelRename() {
00822 //  odebug << "cancel rename" << oendl;
00823   QListView * view;
00824   view = CurrentView();
00825 
00826   bool resetFocus = view->viewport()->focusProxy() == renameBox;
00827   delete renameBox;
00828   renameBox = 0;
00829   if ( resetFocus ) {
00830       view->viewport()->setFocusProxy( view);
00831       view->setFocus();
00832     }
00833 }
00834 
00835 void AdvancedFm::doRename(QListView * view) {
00836    if( !CurrentView()->currentItem()) return;
00837 
00838     QRect r = view->itemRect( view->currentItem( ));
00839     r = QRect( view->viewportToContents( r.topLeft() ), r.size() );
00840     r.setX( view->contentsX() );
00841                 if ( r.width() > view->visibleWidth() )
00842         r.setWidth( view->visibleWidth() );
00843 
00844     renameBox = new QLineEdit( view->viewport(), "qt_renamebox" );
00845     renameBox->setFrame(true);
00846     renameBox->setText(  view->currentItem()->text(0) );
00847     renameBox->selectAll();
00848     renameBox->installEventFilter( this );
00849     view->addChild( renameBox, r.x(), r.y() );
00850                 renameBox->resize( r.size() );
00851                 view->viewport()->setFocusProxy( renameBox );
00852                 renameBox->setFocus();
00853     renameBox->show();
00854 }
00855 
00856 
00857 void AdvancedFm::renameIt() {
00858                 if( !CurrentView()->currentItem()) return;
00859 
00860                 QListView *thisView = CurrentView();
00861     oldName = thisView->currentItem()->text(0);
00862     doRename( thisView );
00863 }
00864 
00865 void AdvancedFm::okRename() {
00866                 qDebug("okrename");
00867                 if( !renameBox) return;
00868 
00869                 QString newName = renameBox->text();
00870                 cancelRename();
00871                 QListView * view = CurrentView();
00872                 QString path =  CurrentDir()->canonicalPath() + "/";
00873                 oldName = path + oldName;
00874                 newName = path + newName;
00875                 if( rename( oldName.latin1(), newName.latin1())== -1)
00876                                 QMessageBox::message(tr("Note"),tr("Could not rename"));
00877                 else
00878                                 oldName = "";
00879                 QListViewItem *item = view->currentItem();
00880                 view->takeItem( item );
00881                 delete item;
00882                 populateView();
00883                 
00884 }
00885 
00886 void AdvancedFm::openSearch() {
00887     QMessageBox::message(tr("Note"),tr("Not Yet Implemented"));
00888 }

Generated on Sat Nov 5 16:16:47 2005 for OPIE by  doxygen 1.4.2