author | llornkcor <llornkcor> | 2002-07-11 16:36:34 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-11 16:36:34 (UTC) |
commit | 1651f048bb129b8e748a01c514d84c8626e0f1e2 (patch) (side-by-side diff) | |
tree | 9b2783cfbb8b754a5aae098b2f4ae165b65f340c | |
parent | f568737c20bea96fb79d85681a72e142ec05d66f (diff) | |
download | opie-1651f048bb129b8e748a01c514d84c8626e0f1e2.zip opie-1651f048bb129b8e748a01c514d84c8626e0f1e2.tar.gz opie-1651f048bb129b8e748a01c514d84c8626e0f1e2.tar.bz2 |
added messageboc when copy, or move fileif file exists to ask ok to delete, added copy same dir to menu
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 314 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 1 |
2 files changed, 232 insertions, 83 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 9e38d14..f97ae99 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -1,233 +1,233 @@ /*************************************************************************** AdvancedFm.cpp ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #define DEVELOPERS_VERSION #define QTOPIA_INTERNAL_FSLP // to get access to fileproperties #include "advancedfm.h" #include "inputDialog.h" #include "filePermissions.h" #include "output.h" #include <opie/ofileselector.h> #include <opie/ofiledialog.h> #include <qpe/lnkproperties.h> #include <qpe/filemanager.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #include <qpe/mimetype.h> #include <qpe/applnk.h> #include <qpe/ir.h> //#include <opie/ofileselector.h> #include <qmultilineedit.h> #include <qtextstream.h> #include <qpushbutton.h> #include <qtoolbutton.h> #include <qdatetime.h> #include <qdir.h> #include <qfile.h> #include <qstring.h> #include <qcombobox.h> #include <qpopupmenu.h> #include <qlistview.h> #include <qmainwindow.h> #include <qlabel.h> #include <qprogressbar.h> #include <qspinbox.h> #include <qtabwidget.h> #include <qwidget.h> #include <qlayout.h> #include <qimage.h> #include <qpixmap.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qregexp.h> #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #include <dirent.h> #include <stdio.h> #include <time.h> #include <fcntl.h> #include <mntent.h> #include <string.h> #include <errno.h> AdvancedFm::AdvancedFm( ) : QMainWindow( ) { setCaption( tr( "AdvancedFm" ) ); // menuTimer( this ); QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); QPEMenuBar *menuBar = new QPEMenuBar(this); // fileMenu = new QPopupMenu( this ); fileMenu = new QPopupMenu( this ); viewMenu = new QPopupMenu( this ); layout->addMultiCellWidget( menuBar, 0, 0, 0, 1 ); menuBar->insertItem( tr( "File" ), fileMenu); menuBar->insertItem( tr( "View" ), viewMenu); qpeDirButton= new QToolButton(this,"QPEButton"); - qpeDirButton->setPixmap( Resource::loadPixmap("launcher/opielogo16x16"));//,"",this,"QPEButton"); + qpeDirButton->setPixmap( Resource::loadPixmap("launcher/opielogo16x16"));//,"",this,"QPEButton"); // qpeDirButton= new QPushButton(Resource::loadIconSet("launcher/opielogo16x16"),"",this,"QPEButton"); qpeDirButton ->setFixedSize( QSize( 20, 20 ) ); connect( qpeDirButton ,SIGNAL(released()),this,SLOT( QPEButtonPushed()) ); //qpeDirButton->setFlat(TRUE); layout->addMultiCellWidget( qpeDirButton , 0, 0, 2, 2); cfButton = new QToolButton( this,"CFButton"); - cfButton->setPixmap(Resource::loadPixmap("cardmon/pcmcia")); + cfButton->setPixmap(Resource::loadPixmap("cardmon/pcmcia")); // cfButton = new QPushButton(Resource::loadIconSet("cardmon/pcmcia"),"",this,"CFButton"); cfButton ->setFixedSize( QSize( 20, 20 ) ); connect( cfButton ,SIGNAL(released()),this,SLOT( CFButtonPushed()) ); //cfButton->setFlat(TRUE); layout->addMultiCellWidget( cfButton , 0, 0, 3, 3); sdButton = new QToolButton( this,"SDButton"); - sdButton->setPixmap(Resource::loadPixmap("sdmon/sdcard")); + sdButton->setPixmap(Resource::loadPixmap("sdmon/sdcard")); // sdButton = new QPushButton(Resource::loadIconSet("sdmon/sdcard"),"",this,"SDButton"); sdButton->setFixedSize( QSize( 20, 20 ) ); connect( sdButton ,SIGNAL(released()),this,SLOT( SDButtonPushed()) ); // sdButton->setFlat(TRUE); layout->addMultiCellWidget( sdButton , 0, 0, 4, 4); cdUpButton = new QToolButton( this,"cdUpButton"); - cdUpButton->setPixmap(Resource::loadPixmap("up")); + cdUpButton->setPixmap(Resource::loadPixmap("up")); // cdUpButton = new QPushButton(Resource::loadIconSet("up"),"",this,"cdUpButton"); cdUpButton ->setFixedSize( QSize( 20, 20 ) ); connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); //cdUpButton ->setFlat(TRUE); layout->addMultiCellWidget( cdUpButton , 0, 0, 5, 5); docButton = new QToolButton( this,"docsButton"); - docButton->setPixmap(Resource::loadPixmap("DocsIcon")); + docButton->setPixmap(Resource::loadPixmap("DocsIcon")); // docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); docButton->setFixedSize( QSize( 20, 20 ) ); connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); // docButton->setFlat(TRUE); layout->addMultiCellWidget( docButton, 0, 0, 6, 6); homeButton = new QToolButton( this,"homeButton"); - homeButton->setPixmap(Resource::loadPixmap("home")); + homeButton->setPixmap(Resource::loadPixmap("home")); // homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); homeButton->setFixedSize( QSize( 20, 20 ) ); connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); // homeButton->setFlat(TRUE); layout->addMultiCellWidget( homeButton, 0, 0, 7, 7); // fileMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); // fileMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); // fileMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); fileMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); fileMenu->insertSeparator(); fileMenu->insertItem( tr( "Make Directory" ), this, SLOT( mkDir() )); fileMenu->insertItem( tr( "Rename" ), this, SLOT( rn() )); fileMenu->insertItem( tr( "Run Command" ), this, SLOT( runCommandStd() )); fileMenu->insertItem( tr( "Run Command with Output" ), this, SLOT( runCommand() )); fileMenu->insertSeparator(); fileMenu->insertItem( tr( "Delete" ), this, SLOT( del() )); fileMenu->setCheckable(TRUE); viewMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); viewMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); viewMenu->insertSeparator(); viewMenu->insertItem( tr( "About" ), this, SLOT( doAbout() )); viewMenu->setCheckable(TRUE); currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); currentPathCombo->setEditable(TRUE); layout->addMultiCellWidget( currentPathCombo, 1, 1, 0, 7); currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); connect( currentPathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( currentPathComboActivated( const QString & ) ) ); connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), this,SLOT(currentPathComboChanged())); currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); layout->addMultiCellWidget( currentPathCombo, 1, 1, 0, 7); TabWidget = new QTabWidget( this, "TabWidget" ); layout->addMultiCellWidget( TabWidget, 2, 2, 0, 7); tab = new QWidget( TabWidget, "tab" ); tabLayout = new QGridLayout( tab ); tabLayout->setSpacing( 2); tabLayout->setMargin( 2); Local_View = new QListView( tab, "Local_View" ); // Local_View->setResizePolicy( QListView::AutoOneFit ); Local_View->addColumn( tr("File"),130); Local_View->addColumn( tr("Size"),-1); Local_View->setColumnAlignment(1,QListView::AlignRight); Local_View->addColumn( tr("Date"),-1); Local_View->setColumnAlignment(2,QListView::AlignRight); Local_View->setAllColumnsShowFocus(TRUE); Local_View->setMultiSelection( TRUE ); Local_View->setSelectionMode(QListView::Extended); QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); tabLayout->addWidget( Local_View, 0, 0 ); connect( Local_View, SIGNAL( clicked( QListViewItem*)), this,SLOT( localListClicked(QListViewItem *)) ); connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( localListPressed(int, QListViewItem *, const QPoint&, int)) ); connect( Local_View, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); TabWidget->insertTab( tab, tr("1")); tab_2 = new QWidget( TabWidget, "tab_2" ); tabLayout_2 = new QGridLayout( tab_2 ); tabLayout_2->setSpacing( 2); tabLayout_2->setMargin( 2); Remote_View = new QListView( tab_2, "Remote_View" ); Remote_View->addColumn( tr("File"),130); Remote_View->addColumn( tr("Size"),-1); Remote_View->setColumnAlignment(1,QListView::AlignRight); Remote_View->addColumn( tr("Date"),-1); Remote_View->setColumnAlignment(2,QListView::AlignRight); Remote_View->setAllColumnsShowFocus(TRUE); Remote_View->setMultiSelection( TRUE ); Remote_View->setSelectionMode(QListView::Extended); QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); connect( Remote_View, SIGNAL( clicked( QListViewItem*)), @@ -1092,340 +1092,487 @@ void AdvancedFm::homeButtonPushed() { QString current = QDir::homeDirPath(); chdir( current.latin1() ); if (TabWidget->currentPageIndex() == 0) { currentDir.cd( current, TRUE); populateLocalView(); } else { currentRemoteDir.cd( current, TRUE); populateRemoteView(); } update(); } void AdvancedFm::docButtonPushed() { QString current = QPEApplication::documentDir(); chdir( current.latin1() ); if (TabWidget->currentPageIndex() == 0) { currentDir.cd( current, TRUE); populateLocalView(); } else { currentRemoteDir.cd( current, TRUE); populateRemoteView(); } update(); } void AdvancedFm::SDButtonPushed() { QString current = "/mnt/card"; chdir( current.latin1() ); if (TabWidget->currentPageIndex() == 0) { currentDir.cd( current, TRUE); populateLocalView(); } else { currentRemoteDir.cd( current, TRUE); populateRemoteView(); } update(); } void AdvancedFm::CFButtonPushed() { QString current = "/mnt/cf"; chdir( current.latin1() ); if (TabWidget->currentPageIndex() == 0) { currentDir.cd( current, TRUE); populateLocalView(); } else { currentRemoteDir.cd( current, TRUE); populateRemoteView(); } update(); } void AdvancedFm::upDir() { if (TabWidget->currentPageIndex() == 0) { QString current = currentDir.canonicalPath(); QDir dir(current); dir.cdUp(); current = dir.canonicalPath(); chdir( current.latin1() ); currentDir.cd( current, TRUE); populateLocalView(); update(); } else { QString current = currentRemoteDir.canonicalPath(); QDir dir(current); dir.cdUp(); current = dir.canonicalPath(); chdir( current.latin1() ); currentRemoteDir.cd( current, TRUE); populateRemoteView(); update(); } } void AdvancedFm::copy() { QStringList curFileList = getPath(); if( curFileList.count() > 0) { QString curFile; if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destFile = currentRemoteDir.canonicalPath()+"/"+(*it); // if(destFile.right(1).find("/",0,TRUE) == -1) // destFile+="/"; // destFile +=(*it); curFile = currentDir.canonicalPath()+"/"+(*it); // if(curFile.right(1).find("/",0,TRUE) == -1) // curFile +="/"; // curFile +=(*it); QFile f(destFile); - if( f.exists()) + if( f.exists()) { + switch ( QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: f.remove(); + break; + case 1: + return; + break; + }; + } if(!copyFile(destFile, curFile) ) { QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); qWarning("nothin doing"); } } populateRemoteView(); TabWidget->setCurrentPage(1); } else { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destFile = currentDir.canonicalPath()+"/"+(*it); curFile = currentRemoteDir.canonicalPath()+"/"+(*it); QFile f(destFile); - if( f.exists()) + if( f.exists()) { + switch ( QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: f.remove(); + break; + case 1: + return; + break; + }; + } if(!copyFile(destFile, curFile) ) { QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); qWarning("nothin doing"); } } populateLocalView(); TabWidget->setCurrentPage(0); } -} + } } void AdvancedFm::copyAs() { QStringList curFileList = getPath(); if( curFileList.count() > 0) { - QString curFile; - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); + QString curFile; + InputDialog *fileDlg; + fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); - if (TabWidget->currentPageIndex() == 0) { - for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { - QString destFile; - curFile = currentDir.canonicalPath()+"/"+(*it); + if (TabWidget->currentPageIndex() == 0) { + for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { + QString destFile; + curFile = currentDir.canonicalPath()+"/"+(*it); // InputDialog *fileDlg; // fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); - fileDlg->setInputText((const QString &) destFile ); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - QString filename = fileDlg->LineEdit1->text(); - destFile = currentRemoteDir.canonicalPath()+"/"+(*it); + fileDlg->setInputText((const QString &) destFile ); + fileDlg->exec(); + if( fileDlg->result() == 1 ) { + QString filename = fileDlg->LineEdit1->text(); + destFile = currentRemoteDir.canonicalPath()+"/"+(*it); - QFile f(destFile); - if( f.exists()) - f.remove(); - if(!copyFile(destFile, curFile) ) { - QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); - qWarning("nothin doing"); + QFile f(destFile); + if( f.exists()) { + switch (QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + f.remove(); + break; + case 1: + return; + break; + }; + } + if(!copyFile(destFile, curFile) ) { + QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); + qWarning("nothin doing"); + } } } + populateRemoteView(); + TabWidget->setCurrentPage(1); + } else { + if (TabWidget->currentPageIndex() == 0) { + for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { + + curFile = currentDir.canonicalPath()+"/"+(*it); + QString destFile; + fileDlg->setInputText((const QString &) destFile); + fileDlg->exec(); + if( fileDlg->result() == 1 ) { + QString filename = fileDlg->LineEdit1->text(); + destFile = currentDir.canonicalPath()+"/"+(*it); + + QFile f(destFile); + if( f.exists()) { + switch ( QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + f.remove(); + break; + case 1: + return; + break; + }; + } + if(!copyFile(destFile, curFile) ) { + QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); + qWarning("nothin doing"); + } + + } + } + populateLocalView(); + TabWidget->setCurrentPage(0); + } } + } + +} + +void AdvancedFm::copySameDir() { + QStringList curFileList = getPath(); + if( curFileList.count() > 0) { + QString curFile; + InputDialog *fileDlg; - populateRemoteView(); - TabWidget->setCurrentPage(1); - } else { if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { - - curFile = currentDir.canonicalPath()+"/"+(*it); QString destFile; - fileDlg->setInputText((const QString &) destFile); + curFile = currentDir.canonicalPath()+"/"+(*it); + fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); +// InputDialog *fileDlg; +// fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); + fileDlg->setInputText((const QString &) destFile ); fileDlg->exec(); if( fileDlg->result() == 1 ) { - QString filename = fileDlg->LineEdit1->text(); - destFile = currentDir.canonicalPath()+"/"+(*it); + QString filename = fileDlg->LineEdit1->text(); + destFile = currentDir.canonicalPath()+"/"+filename; QFile f(destFile); - if( f.exists()) - f.remove(); + if( f.exists()) { + switch (QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + qDebug(""); + f.remove(); + break; + case 1: + return; + break; + }; + } if(!copyFile(destFile, curFile) ) { - QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); - qWarning("nothin doing"); + QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); + qWarning("nothin doing"); } + + qDebug("copy "+curFile+" as "+destFile); } + delete fileDlg; + } + populateRemoteView(); + TabWidget->setCurrentPage(1); + } else { + if (TabWidget->currentPageIndex() == 0) { + for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { + + curFile = currentRemoteDir.canonicalPath()+"/"+(*it); + fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); + QString destFile; + fileDlg->setInputText((const QString &) destFile); + fileDlg->exec(); + if( fileDlg->result() == 1 ) { + QString filename = fileDlg->LineEdit1->text(); + destFile = currentDir.canonicalPath()+"/"+filename; + + QFile f(destFile); + if( f.exists()) { + switch ( QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + f.remove(); + break; + case 1: + return; + break; + }; + } + if(!copyFile(destFile, curFile) ) { + QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile); + qWarning("nothin doing"); + } + qDebug("copy "+curFile+" as "+destFile); + } + delete fileDlg; + } + populateLocalView(); + TabWidget->setCurrentPage(0); } - populateLocalView(); - TabWidget->setCurrentPage(0); } - } -} -} + } +} + void AdvancedFm::move() { QStringList curFileList = getPath(); if( curFileList.count() > 0) { - QString curFile; + QString curFile; // qDebug(curFile); - QString destFile; + QString destFile; - if (TabWidget->currentPageIndex() == 0) { - for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { - QString destFile = currentRemoteDir.canonicalPath(); + if (TabWidget->currentPageIndex() == 0) { + for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { + QString destFile = currentRemoteDir.canonicalPath(); if(destFile.right(1).find("/",0,TRUE) == -1) destFile+="/"; destFile +=(*it); - curFile = currentDir.canonicalPath(); - qDebug("Destination file is "+destFile); - if(curFile.right(1).find("/",0,TRUE) == -1) - curFile +="/"; - curFile+=(*it); + curFile = currentDir.canonicalPath(); + qDebug("Destination file is "+destFile); + if(curFile.right(1).find("/",0,TRUE) == -1) + curFile +="/"; + curFile+=(*it); - QFile f(destFile); - if( f.exists()) - f.remove(); - if(!copyFile( destFile, curFile) ) { - QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); - return; + QFile f(destFile); + if( f.exists()) { + switch (QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + f.remove(); + break; + case 1: + return; + break; + }; + if(!copyFile( destFile, curFile) ) { + QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); + return; + } + QFile::remove(curFile); + } } - QFile::remove(curFile); - } - TabWidget->setCurrentPage(1); - } else { - for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { - QString destFile = currentRemoteDir.canonicalPath(); + TabWidget->setCurrentPage(1); + } else { + for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { + QString destFile = currentRemoteDir.canonicalPath(); if(destFile.right(1).find("/",0,TRUE) == -1) destFile+="/"; destFile +=(*it); - qDebug("Destination file is "+destFile); - curFile = currentDir.canonicalPath(); - if(curFile.right(1).find("/",0,TRUE) == -1) - curFile +="/"; - curFile+=(*it); + qDebug("Destination file is "+destFile); + curFile = currentDir.canonicalPath(); + if(curFile.right(1).find("/",0,TRUE) == -1) + curFile +="/"; + curFile+=(*it); - QFile f(destFile); - if( f.exists()) - f.remove(); - if(!copyFile(destFile, curFile) ) { - QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); - return; + QFile f(destFile); + if( f.exists()) { + switch (QMessageBox::warning(this,tr("Delete"), + destFile+tr(" already exists\nDo you really want to delete it?"), + tr("Yes"),tr("No"),0,0,1) ) { + case 0: + f.remove(); + break; + case 1: + return; + break; + }; + if(!copyFile(destFile, curFile) ) { + QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); + return; + } + } + QFile::remove(curFile); + TabWidget->setCurrentPage(0); + } } - QFile::remove(curFile); - TabWidget->setCurrentPage(0); + populateRemoteView(); + populateLocalView(); } - } - populateRemoteView(); - populateLocalView(); } - } bool AdvancedFm::copyFile( const QString & dest, const QString & src ) { char bf[ 50000 ]; int bytesRead; bool success = TRUE; struct stat status; QFile s( src ); QFile d( dest ); if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) { while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) { if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ success = FALSE; break; } } if( success && (bytesRead > 0) ){ d.writeBlock( bf, bytesRead ); } } else { success = FALSE; } // Set file permissions if( stat( (const char *) src, &status ) == 0 ){ chmod( (const char *) dest, status.st_mode ); } return success; } void AdvancedFm::runCommand() { QString curFile; if (TabWidget->currentPageIndex() == 0) { if( Local_View->currentItem()) curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); } else { if(Remote_View->currentItem()) curFile = currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0); } InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); QString command; if( fileDlg->result() == 1 ) { command = fileDlg->LineEdit1->text(); // int err=0; Output *outDlg; outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); outDlg->showMaximized(); outDlg->show(); qApp->processEvents(); FILE *fp; char line[130]; sleep(1); // if(command.find("2>",0,TRUE) != -1) command +=" 2>&1"; fp = popen( (const char *) command, "r"); if ( !fp ) { qDebug("Could not execute '" + command + "'! err=%d", fp); QMessageBox::warning( this, tr("AdvancedFm"), tr("command failed!"), tr("&OK") ); pclose(fp); return; } else { while ( fgets( line, sizeof line, fp)) { QString lineStr = line; lineStr=lineStr.left(lineStr.length()-1); outDlg->OutputEdit->append(lineStr); outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); } } } } void AdvancedFm::runCommandStd() { QString curFile; if (TabWidget->currentPageIndex() == 0) { if( Local_View->currentItem()) curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); } else { if(Remote_View->currentItem()) curFile = currentRemoteDir.canonicalPath() +"/"+ Remote_View->currentItem()->text(0); } InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); QString command; if( fileDlg->result() == 1 ) { qApp->processEvents(); @@ -1662,138 +1809,139 @@ void AdvancedFm::doBeam() { } else { QStringList curFileList = getPath(); if( curFileList.count() > 0) { if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString curFile = currentDir.canonicalPath()+"/"+(*it); if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); Ir *file = new Ir(this, "IR"); connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); file->send( curFile, curFile ); } } else { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it); if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); Ir *file = new Ir(this, "IR"); connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); file->send( curFile, curFile ); } } } } } void AdvancedFm::fileBeamFinished( Ir *ir) { QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); } // QList<QListViewItem> * getSelectedItems( QListView * Local_View ); // QListViewItemIterator it( Local_View ); // for ( ; it.current(); ++it ) { // if ( it.current()->isSelected() ) { // QString strItem = it.current()->text(0); // QString localFile = currentDir.canonicalPath()+"/"+strItem; // QFileInfo fi(localFile); // } // } void AdvancedFm::showFileMenu() { QString curApp; bool isLocalView = false; if (TabWidget->currentPageIndex() == 0) { isLocalView = TRUE; curApp = Local_View->currentItem()->text(0); } else { curApp = Remote_View->currentItem()->text(0); } MimeType mt( curApp ); const AppLnk* app = mt.application(); QFile fi(curApp); // QPopupMenu m; QPopupMenu *m = new QPopupMenu(0); m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); m->insertSeparator(); if ( QFileInfo(fi).isDir() ) { m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); } else { if ( app ) m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( runThis() ) ); else if( QFileInfo(fi).isExecutable() ) m->insertItem( tr( "Execute" ), this, SLOT( runThis() ) ); m->insertItem( Resource::loadPixmap( "txt" ), tr( "Open as text" ),this, SLOT( runText() ) ); } m->insertSeparator(); if(isLocalView) m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); else m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); m->insertItem( tr( "Make Symlink" ), this, SLOT( mkSym() )); m->insertSeparator(); if(isLocalView) m->insertItem( tr( "Rename" ), this, SLOT( localRename() )); else m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); m->insertItem( tr( "Copy" ), this, SLOT( copy() )); m->insertItem( tr( "Copy As" ), this, SLOT( copyAs() )); + m->insertItem( tr( "Copy Same Dir" ), this, SLOT( copySameDir() )); m->insertItem( tr( "Move" ), this, SLOT( move() )); m->insertSeparator(); if(isLocalView) m->insertItem( tr( "Rescan" ), this, SLOT( populateLocalView() )); else m->insertItem( tr( "Rescan" ), this, SLOT( populateRemoteView() )); m->insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); m->insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); m->insertSeparator(); if(isLocalView) m->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); else m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); m->insertSeparator(); m->insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) //bad hack for Sharp zaurus failings m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); m->setCheckable(TRUE); if (!b) m->setItemChecked(m->idAt(0),TRUE); else m->setItemChecked(m->idAt(0),FALSE); if(Ir::supported()) m->insertItem( tr( "Beam File" ), this, SLOT( doBeam() )); m->setFocus(); m->exec( QCursor::pos() ); sleep(1); if(m) delete m; } void AdvancedFm::cancelMenuTimer() { qDebug("selectionChanged: cancel menu timer"); if( menuTimer.isActive() ) menuTimer.stop(); } diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 7335773..7665fe9 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -31,109 +31,110 @@ class QListView; class QListviewItem; class QLabel; class QProgressBar; class QSpinBox; class QTabWidget; class QWidget; class QPEToolBar; class QPEMenuBar; class QPopupMenu; class QFile; class QListViewItem; class QLineEdit; //class QPushButton; class QToolButton; class Ir; class AdvancedFm : public QMainWindow { Q_OBJECT public: AdvancedFm(); ~AdvancedFm(); QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; QLineEdit *currentPathEdit; QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu; QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; // QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; QDir currentDir, currentRemoteDir; QComboBox *currentPathCombo; QString filterStr; QListViewItem * item; bool b; QStringList fileSystemTypeList, fsList; int currentServerConfig; protected slots: void doLocalCd(); void doRemoteCd(); // void copy(); void mkDir(); void del(); void rn(); void populateLocalView(); void populateRemoteView(); void showHidden(); void showRemoteHidden(); void writeConfig(); void readConfig(); void localListClicked(QListViewItem *); void remoteListClicked(QListViewItem *); void localListPressed( int, QListViewItem *, const QPoint&, int); void remoteListPressed( int, QListViewItem *, const QPoint&, int); void localMakDir(); void localDelete(); void remoteMakDir(); void remoteDelete(); /* bool remoteDirList(const QString &); */ /* bool remoteChDir(const QString &); */ void tabChanged(QWidget*); void cleanUp(); void remoteRename(); void localRename(); void runThis(); void runText(); void filePerms(); void doProperties(); void runCommand(); void runCommandStd(); QStringList getPath(); void mkSym(); void switchToLocalTab(); void switchToRemoteTab(); protected: QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; void keyReleaseEvent( QKeyEvent *); QString getFileSystemType(const QString &); void parsetab(const QString &fileName); protected slots: void showFileMenu(); void cancelMenuTimer(); void homeButtonPushed(); void docButtonPushed(); void SDButtonPushed(); void CFButtonPushed(); void QPEButtonPushed(); void upDir(); void currentPathComboChanged(); void copy(); void copyAs(); + void copySameDir(); void currentPathComboActivated(const QString &); void fillCombo(const QString &); bool copyFile( const QString & , const QString & ); void move(); void fileStatus(); void doAbout(); void doBeam(); void fileBeamFinished( Ir *); private: QTimer menuTimer; }; #endif // ADVANCEDFM_H |