-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 153 |
1 files changed, 84 insertions, 69 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index fd6b028..907a812 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -80,106 +80,110 @@ OpieFtp::OpieFtp( ) connectionMenu = new QPopupMenu( this ); localMenu = new QPopupMenu( this ); remoteMenu = new QPopupMenu( this ); tabMenu = new QPopupMenu( this ); layout->addMultiCellWidget( menuBar, 0, 0, 0, 3 ); menuBar->insertItem( tr( "Connection" ), connectionMenu); menuBar->insertItem( tr( "Local" ), localMenu); menuBar->insertItem( tr( "Remote" ), remoteMenu); menuBar->insertItem( tr( "View" ), tabMenu); connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); localMenu->insertSeparator(); localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); localMenu->insertSeparator(); localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); localMenu->setCheckable(TRUE); - + remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); remoteMenu->insertSeparator(); remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); tabMenu->setCheckable(TRUE); TabWidget = new QTabWidget( this, "TabWidget" ); layout->addMultiCellWidget( TabWidget, 1, 1, 0, 3 ); TabWidget->setTabShape(QTabWidget::Triangular); 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"),120); + Local_View->addColumn( tr("File"),150); 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 ); + QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); tabLayout->addWidget( Local_View, 0, 0 ); - connect( Local_View, SIGNAL( clicked( QListViewItem*)), + connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), this,SLOT( localListClicked(QListViewItem *)) ); connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); TabWidget->insertTab( tab, tr( "Local" ) ); 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"),120); + Remote_View->addColumn( tr("File"),150); 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->addColumn( tr("Dir"),-1); Remote_View->setColumnAlignment(4,QListView::AlignRight); Remote_View->setAllColumnsShowFocus(TRUE); + Remote_View->setMultiSelection( TRUE ); + QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); - connect( Remote_View, SIGNAL( clicked( QListViewItem*)), + connect( Remote_View, SIGNAL( doubleClicked( QListViewItem*)), this,SLOT( remoteListClicked(QListViewItem *)) ); connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); tabLayout_2->addWidget( Remote_View, 0, 0 ); TabWidget->insertTab( tab_2, tr( "Remote" ) ); tab_3 = new QWidget( TabWidget, "tab_3" ); tabLayout_3 = new QGridLayout( tab_3 ); tabLayout_3->setSpacing( 2); tabLayout_3->setMargin( 2); TextLabel1 = new QLabel( tab_3, "TextLabel1" ); TextLabel1->setText( tr( "Username" ) ); tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); UsernameComboBox->setEditable(TRUE); tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); TextLabel2 = new QLabel( tab_3, "TextLabel2" ); TextLabel2->setText( tr( "Password" ) ); tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); @@ -378,129 +382,142 @@ void OpieFtp::connector() msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); if(conn) FtpQuit(conn); connectServerBtn->setOn(FALSE); connectServerBtn->setText( tr("Connect")); return ; } remoteDirList("/") ; setCaption(ftp_host); writeConfig(); connectServerBtn->setText( tr("Disconnect")); QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::disConnector() { if(conn) FtpQuit(conn); setCaption("OpieFtp"); currentRemoteDir="/"; Remote_View->clear(); connectServerBtn->setText( tr("Connect")); connectServerBtn->setOn(FALSE); - + } void OpieFtp::localUpload() { int fsz; QCopEnvelope ( "QPE/System", "busy()" ); -// qApp->processEvents(); - QString strItem = Local_View->currentItem()->text(0); - QString localFile = currentDir.canonicalPath()+"/"+strItem; - QString remoteFile= currentRemoteDir+strItem; - QFileInfo fi(localFile); - if( !fi.isDir()) { - fsz=fi.size(); - ProgressBar->setTotalSteps(fsz); - - FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); - FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); - FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); - FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); - qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); - - if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { - QString msg; - msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); - msg.replace(QRegExp(":"),"\n"); - QMessageBox::message(tr("Note"),msg); +// qApp->processEvents(); + 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; + QString remoteFile= currentRemoteDir+strItem; + QFileInfo fi(localFile); + if( !fi.isDir()) { + fsz=fi.size(); + ProgressBar->setTotalSteps(fsz); + + FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); + FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); + FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); + FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); + qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); + + if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { + QString msg; + msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); + msg.replace(QRegExp(":"),"\n"); + QMessageBox::message(tr("Note"),msg); + } + } else { + QMessageBox::message(tr("Note"),tr("Cannot upload directories")); + } + ProgressBar->reset(); + nullifyCallBack(); + it.current()->setSelected(FALSE); + } //end currentSelected } - ProgressBar->reset(); - nullifyCallBack(); - } else { - QMessageBox::message(tr("Note"),tr("Cannot upload directories")); - } - TabWidget->setCurrentPage(1); - remoteDirList( (const QString &)currentRemoteDir); //this also calls populate - QCopEnvelope ( "QPE/System", "notBusy()" ); + TabWidget->setCurrentPage(1); + remoteDirList( (const QString &)currentRemoteDir); //this also calls populate + QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::nullifyCallBack() { FtpOptions(FTPLIB_CALLBACK, NULL, conn); FtpOptions(FTPLIB_IDLETIME, NULL, conn); FtpOptions(FTPLIB_CALLBACKARG, NULL, conn); FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn); - } void OpieFtp::remoteDownload() { // qApp->processEvents(); int fsz; QCopEnvelope ( "QPE/System", "busy()" ); - QString strItem = Remote_View->currentItem()->text(0); -// strItem=strItem.right(strItem.length()-1); - QString localFile = currentDir.canonicalPath(); - if(localFile.right(1).find("/",0,TRUE) == -1) - localFile += "/"; - localFile += strItem; + QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); + QListViewItemIterator it( Remote_View ); + for ( ; it.current(); ++it ) { + if ( it.current()->isSelected() ) { + QString strItem = it.current()->text(0); +// strItem=strItem.right(strItem.length()-1); + QString localFile = currentDir.canonicalPath(); + if(localFile.right(1).find("/",0,TRUE) == -1) + localFile += "/"; + localFile += strItem; // QString localFile = currentDir.canonicalPath()+"/"+strItem; - QString remoteFile= currentRemoteDir+strItem; - if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) - fsz = 0; - QString temp; - temp.sprintf( remoteFile+" "+" %dkb", fsz); - - ProgressBar->setTotalSteps(fsz); - FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); - FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); - FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); - FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); - qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); - - if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { - QString msg; - msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); - msg.replace(QRegExp(":"),"\n"); - QMessageBox::message(tr("Note"),msg); + QString remoteFile= currentRemoteDir+strItem; + if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) + fsz = 0; + QString temp; + temp.sprintf( remoteFile+" "+" %dkb", fsz); + + ProgressBar->setTotalSteps(fsz); + FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); + FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); + FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); + FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); + qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); + + if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { + QString msg; + msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); + msg.replace(QRegExp(":"),"\n"); + QMessageBox::message(tr("Note"),msg); + } + ProgressBar->reset(); + nullifyCallBack(); + it.current()->setSelected(FALSE); + } } - ProgressBar->reset(); - nullifyCallBack(); TabWidget->setCurrentPage(0); populateLocalView(); QCopEnvelope ( "QPE/System", "notBusy()" ); } bool OpieFtp::remoteDirList(const QString &dir) { QString tmp = QDir::homeDirPath(); if(tmp.right(1) != "/") tmp+="/._temp"; else tmp+="._temp"; // qDebug("Listing remote dir "+tmp); QCopEnvelope ( "QPE/System", "busy()" ); if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { QString msg; msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); return false; } populateRemoteView() ; QCopEnvelope ( "QPE/System", "notBusy()" ); return true; @@ -536,81 +553,80 @@ void OpieFtp::populateLocalView() while ( (fi=it.current()) ) { if (fi->isSymLink() ){ QString symLink=fi->readLink(); // qDebug("Symlink detected "+symLink); QFileInfo sym( symLink); fileS.sprintf( "%10li", sym.size() ); fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); fileDate = sym.lastModified().toString(); } else { // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); fileS.sprintf( "%10li", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); fileDate= fi->lastModified().toString(); if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; // qDebug( fileL); } } if(fileL !="./" && fi->exists()) { item= new QListViewItem( Local_View,fileL,fileS , fileDate); QPixmap pm; if(isDir || fileL.find("/",0,TRUE) != -1) { - if( !QDir( fi->filePath() ).isReadable()) + if( !QDir( fi->filePath() ).isReadable()) pm = Resource::loadPixmap( "lockedfolder" ); - else + else pm= Resource::loadPixmap( "folder" ); item->setPixmap( 0,pm ); } else { if( !fi->isReadable() ) pm = Resource::loadPixmap( "locked" ); else { MimeType mt(fi->filePath()); - pm=mt.pixmap(); + pm=mt.pixmap(); //sets the correct pixmap for mimetype if(pm.isNull()) pm = Resource::loadPixmap( "UnknownDocument-14" ); item->setPixmap( 0,pm); } } if( fileL.find("->",0,TRUE) != -1) { // overlay link image pm= Resource::loadPixmap( "folder" ); QPixmap lnk = Resource::loadPixmap( "symlink" ); QPainter painter( &pm ); painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); pm.setMask( pm.createHeuristicMask( FALSE ) ); item->setPixmap( 0, pm); } } isDir=FALSE; ++it; } Local_View->setSorting( 3,FALSE); currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() ); fillCombo( (const QString &)currentDir); - } bool OpieFtp::populateRemoteView( ) { // qDebug("populate remoteview"); QString sfile=QDir::homeDirPath(); if(sfile.right(1) != "/") sfile+="/._temp"; else sfile+="._temp"; QFile file( sfile); Remote_View->clear(); QString s, File_Name; QListViewItem *itemDir=NULL, *itemFile=NULL; QString fileL, fileS, fileDate; if ( file.open(IO_ReadOnly)) { QTextStream t( &file ); // use a text stream while ( !t.eof()) { s = t.readLine(); fileL = s.right(s.length()-55); fileL = fileL.stripWhiteSpace(); if(s.left(1) == "d") fileL = fileL+"/"; // fileL = "/"+fileL+"/"; @@ -622,49 +638,49 @@ bool OpieFtp::populateRemoteView( ) if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate,"d"); item->setPixmap( 0, Resource::loadPixmap( "folder" )); // if(itemDir) item->moveItem(itemDir); itemDir=item; } else { QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate,"f"); item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); // if(itemFile) item->moveItem(itemDir); item->moveItem(itemFile); itemFile=item; } } } QListViewItem * item1 = new QListViewItem( Remote_View, "../"); item1->setPixmap( 0, Resource::loadPixmap( "folder" )); file.close(); if( file.exists()) file. remove(); } else qDebug("temp file not opened successfullly "+sfile); Remote_View->setSorting( 4,TRUE); - return true; + return true; } void OpieFtp::remoteListClicked(QListViewItem *selectedItem) { if(item) { QCopEnvelope ( "QPE/System", "busy()" ); QString oldRemoteCurrentDir = currentRemoteDir; QString strItem=selectedItem->text(0); strItem=strItem.simplifyWhiteSpace(); if(strItem == "../") { // the user wants to go ^ if( FtpCDUp( conn) == 0) { QString msg; msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); qDebug(msg); } char path[256]; if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string QString msg; msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); qDebug(msg); @@ -738,49 +754,49 @@ void OpieFtp::localListClicked(QListViewItem *selectedItem) } //end not symlink chdir(strItem.latin1()); } } } void OpieFtp::doLocalCd() { localListClicked( Local_View->currentItem()); } void OpieFtp:: doRemoteCd() { remoteListClicked( Remote_View->currentItem()); } void OpieFtp::showHidden() { if (!b) { currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); localMenu->setItemChecked(localMenu->idAt(0),TRUE); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); b=TRUE; - + } else { currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); localMenu->setItemChecked(localMenu->idAt(0),FALSE); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); b=FALSE; } populateLocalView(); } void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) { switch (mouse) { case 1: break; case 2: showLocalMenu(item); break; }; } void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) { switch (mouse) { case 1: @@ -835,49 +851,49 @@ void OpieFtp::localMakDir() if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text(); currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); } populateLocalView(); } void OpieFtp::localDelete() { QString f = Local_View->currentItem()->text(0); if(QDir(f).exists() ) { switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; QString cmd="rmdir "+f; system( cmd.latin1()); populateLocalView(); } break; case 1: // exit break; }; - + } else { switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f +" ?",tr("Yes"),tr("No"),0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; QString cmd="rm "+f; system( cmd.latin1()); populateLocalView(); } break; case 1: // exit break; }; } } void OpieFtp::remoteMakDir() { InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text();//+".playlist"; @@ -890,49 +906,48 @@ void OpieFtp::remoteMakDir() QMessageBox::message(tr("Note"),msg); } QCopEnvelope ( "QPE/System", "notBusy()" ); remoteDirList( (const QString &)currentRemoteDir); //this also calls populate } } void OpieFtp::remoteDelete() { QString f = Remote_View->currentItem()->text(0); QCopEnvelope ( "QPE/System", "busy()" ); if( f.right(1) =="/") { QString path= currentRemoteDir+f; switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" ,tr("Yes"),tr("No"),0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; if(FtpRmdir( path.latin1(), conn) ==0) { QString msg; msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); } remoteDirList( (const QString &)currentRemoteDir); //this also calls populate - } break; }; } else { switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" ,tr("Yes"),tr("No"),0,0,1) ) { case 0: { QString path= currentRemoteDir+f; if(FtpDelete( path.latin1(), conn)==0) { QString msg; msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message(tr("Note"),msg); } remoteDirList( (const QString &)currentRemoteDir); //this also calls populate } break; }; } QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::remoteRename() { |