author | llornkcor <llornkcor> | 2002-03-17 04:00:20 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-17 04:00:20 (UTC) |
commit | 578725ca25862c0b06b1991a7bc8ffc2ad8ae13e (patch) (side-by-side diff) | |
tree | 2217cff7ce86563ea688fc8138835230ea95c5c0 | |
parent | 624a283591094628425c94fedfdd62941ad7c853 (diff) | |
download | opie-578725ca25862c0b06b1991a7bc8ffc2ad8ae13e.zip opie-578725ca25862c0b06b1991a7bc8ffc2ad8ae13e.tar.gz opie-578725ca25862c0b06b1991a7bc8ffc2ad8ae13e.tar.bz2 |
added icons, and fixed remote dir list sorting
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 118275b..a3b29a1 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -36,24 +36,25 @@ #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> + QProgressBar *ProgressBar; static netbuf *conn=NULL; static int log_progress(netbuf *ctl, int xfered, void *arg) { int fsz = *(int *)arg; int pct = (xfered * 100) / fsz; // printf("%3d%%\r", pct); // fflush(stdout); ProgressBar->setProgress(xfered); qApp->processEvents(); return 1; @@ -85,25 +86,26 @@ OpieFtp::OpieFtp( ) 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" ); @@ -192,26 +194,26 @@ OpieFtp::OpieFtp( ) ServerComboBox->setEditable(TRUE); ServerComboBox->lineEdit()->setText( tr( "" ) ); tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); // ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) ); ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); TextLabel5->setText( tr( "Remote path" ) ); tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); remotePath = new QLineEdit( "/", tab_3, "remotePath" ); remotePath->setText( currentRemoteDir = "/"); - tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); // remotePath->setText( currentRemoteDir = "/home/llornkcor/"); + tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); TextLabel4 = new QLabel( tab_3, "TextLabel4" ); TextLabel4->setText( tr( "Port" ) ); tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); PortSpinBox->setMaxValue(32786); PortSpinBox->setValue( 4242); // PortSpinBox->setValue( 21); tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); @@ -227,24 +229,25 @@ OpieFtp::OpieFtp( ) currentDir.setPath( QDir::currentDirPath()); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" ); layout->addMultiCellWidget( currentPathEdit, 3, 3, 0, 3 ); currentPathEdit->setText( currentDir.canonicalPath()); connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged())); ProgressBar = new QProgressBar( this, "ProgressBar" ); layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 3 ); filterStr="*"; + b=FALSE; populateLocalView(); } OpieFtp::~OpieFtp() { } void OpieFtp::cleanUp() { if(conn) FtpQuit(conn); QString sfile=QDir::homeDirPath(); @@ -320,25 +323,28 @@ void OpieFtp::nullifyCallBack() FtpOptions(FTPLIB_IDLETIME, NULL, conn); FtpOptions(FTPLIB_CALLBACKARG, NULL, conn); FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn); } void OpieFtp::remoteDownload() { int fsz; QCopEnvelope ( "QPE/System", "busy()" ); qApp->processEvents(); QString strItem = Remote_View->currentItem()->text(0); - QString localFile = currentDir.canonicalPath()+"/"+strItem; +// strItem=strItem.right(strItem.length()-1); + + QString localFile = currentDir.canonicalPath()+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()); @@ -447,85 +453,110 @@ bool OpieFtp::remoteChDir(const QString &dir) } QCopEnvelope ( "QPE/System", "notBusy()" ); return TRUE; } void OpieFtp::populateLocalView() { Local_View->clear(); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter(filterStr); QString fileL, fileS, fileDate; + bool isDir=FALSE; const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); QFileInfoListIterator it(*list); QFileInfo *fi; 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); } } - item= new QListViewItem( Local_View,fileL,fileS, fileDate); + if(fileL !="./") { + item = new QListViewItem( Local_View,fileL,fileS, fileDate); + if(isDir) + item->setPixmap( 0, Resource::loadPixmap( "folder" )); + else + item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); + } + isDir=FALSE; ++it; } Local_View->setSorting( 3,FALSE); currentPathEdit->setText( currentDir.canonicalPath() ); } 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; - new QListViewItem( Remote_View, "../"); 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") + if(s.left(1) == "d") fileL = fileL+"/"; +// fileL = "/"+fileL+"/"; fileS = s.mid( 30, 42-30); fileS = fileS.stripWhiteSpace(); fileDate = s.mid( 42, 55-42); fileDate = fileDate.stripWhiteSpace(); - if(fileL.find("total",0,TRUE) == -1) - new QListViewItem( Remote_View, fileL, fileS, fileDate); + if(fileL.find("total",0,TRUE) == -1) { + QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate); + if(s.left(1) == "d") { + item->setPixmap( 0, Resource::loadPixmap( "folder" )); + if(itemDir) + item->moveItem(itemDir); + itemDir=item; + } else { + item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); + if(itemFile) + 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; } void OpieFtp::remoteListClicked(QListViewItem *selectedItem) { 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) { @@ -617,29 +648,31 @@ void OpieFtp::doLocalCd() } 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: @@ -677,24 +710,30 @@ void OpieFtp::showLocalMenu(QListViewItem * item) { QPopupMenu m; m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); m.insertSeparator(); if(item->text(0).right(1) == "/") m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); else m.insertItem( tr( "Upload" ), this, SLOT( localUpload() )); m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); + m.setCheckable(TRUE); + if (b) + m.setItemChecked(m.idAt(0),TRUE); + else + m.setItemChecked(m.idAt(0),FALSE); + m.exec( QCursor::pos() ); } void OpieFtp::localMakDir() { InputDialog *fileDlg; fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text(); currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); } @@ -828,25 +867,25 @@ void OpieFtp::localRename() if( fileDlg->result() == 1 ) { QString oldname = currentDir.canonicalPath() + "/" + curFile; QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; if( rename(oldname.latin1(), newName.latin1())== -1) QMessageBox::message("Note","Could not rename"); } populateLocalView(); } void OpieFtp::currentPathEditChanged() { QString oldRemoteCurrentDir = currentRemoteDir; - qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); +// qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); if (TabWidget->currentPageIndex() == 0) { if(QDir( currentPathEdit->text()).exists()) { currentDir.setPath( currentPathEdit->text() ); populateLocalView(); } else { QMessageBox::message("Note","That directory does not exist"); } } if (TabWidget->currentPageIndex() == 1) { currentRemoteDir = currentPathEdit->text(); if(currentRemoteDir.right(1) !="/") { currentRemoteDir = currentRemoteDir +"/"; |