Diffstat (limited to 'noncore/net/opieftp/opieftp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 204 |
1 files changed, 108 insertions, 96 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 37e2134..fd6b028 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -12,24 +12,25 @@ //#define DEVELOPERS_VERSION #include "opieftp.h" #include "ftplib.h" #include "inputDialog.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 <qstringlist.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> @@ -193,87 +194,88 @@ OpieFtp::OpieFtp( ) ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); ServerComboBox->setEditable(TRUE); tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this,SLOT(serverComboEdited(const QString & ) )); 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" ); 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); tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); QPushButton *deleteServerBtn; deleteServerBtn = new QPushButton( "Delete Server", tab_3 , "OpenButton" ); tabLayout_3->addMultiCellWidget( deleteServerBtn, 5, 5, 2, 3); connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); tabLayout_3->addMultiCellWidget( connectServerBtn, 5, 5, 0, 1); connectServerBtn->setToggleButton(TRUE); connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); - QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); tabLayout_3->addItem( spacer, 5, 0 ); TabWidget->insertTab( tab_3, tr( "Config" ) ); connect(TabWidget,SIGNAL(currentChanged(QWidget *)), this,SLOT(tabChanged(QWidget*))); currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); currentDir.setPath( QDir::currentDirPath()); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 3 ); - + currentPathCombo->setEditable(TRUE); currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); connect( currentPathCombo, SIGNAL( activated( const QString & ) ), - this, SLOT( currentPathComboChanged()currentPathCombo( const QString & ) ) ); + this, SLOT( currentPathComboActivated( const QString & ) ) ); connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), this,SLOT(currentPathComboChanged())); ProgressBar = new QProgressBar( this, "ProgressBar" ); layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 3 ); // fillCombos(); #ifdef DEVELOPERS_VERSION ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); UsernameComboBox->lineEdit()->setText("root"); PortSpinBox->setValue( 4242); remotePath->setText( currentRemoteDir = "/"); // ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) ); // UsernameComboBox->lineEdit()->setText("llornkcor"); // PortSpinBox->setValue( 21); // remotePath->setText( currentRemoteDir = "/home/llornkcor"); PasswordEdit->setText( tr( "" ) ); #endif + filterStr="*"; b=FALSE; populateLocalView(); readConfig(); ServerComboBox->setCurrentItem(currentServerConfig); TabWidget->setCurrentPage(2); } OpieFtp::~OpieFtp() { } @@ -317,25 +319,25 @@ void OpieFtp::newConnection() UsernameComboBox->lineEdit()->setText(""); PasswordEdit->setText( "" ); ServerComboBox->lineEdit()->setText( ""); remotePath->setText( currentRemoteDir = "/"); PortSpinBox->setValue( 21); TabWidget->setCurrentPage(2); currentServerConfig = -1; } void OpieFtp::serverComboEdited(const QString & edit) { if( !edit.isEmpty() ) { currentServerConfig = -1; - qDebug("comboedited"); +// qDebug("comboedited"); } } void OpieFtp::connectorBtnToggled(bool On) { if(On) { connector(); } else { disConnector(); } } @@ -541,42 +543,48 @@ void OpieFtp::populateLocalView() 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 !="./") { - item= new QListViewItem( ListView,fileL,fileS , fileDate); + if(fileL !="./" && fi->exists()) { + item= new QListViewItem( Local_View,fileL,fileS , fileDate); QPixmap pm; - pm= Resource::loadPixmap( "folder" ); if(isDir || fileL.find("/",0,TRUE) != -1) { - if( !QDir( fi->filePath() ).isReadable()) + if( !QDir( fi->filePath() ).isReadable()) pm = Resource::loadPixmap( "lockedfolder" ); + else + pm= Resource::loadPixmap( "folder" ); item->setPixmap( 0,pm ); } else { if( !fi->isReadable() ) pm = Resource::loadPixmap( "locked" ); - else - pm = Resource::loadPixmap( "fileopen" ); - item->setPixmap( 0,pm); + else { + MimeType mt(fi->filePath()); + pm=mt.pixmap(); + 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() ); @@ -631,110 +639,114 @@ bool OpieFtp::populateRemoteView( ) 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) { - 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); - } - currentRemoteDir=path; - } else { - if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers - strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); - strItem = strItem.stripWhiteSpace(); - currentRemoteDir = strItem; - if( !remoteChDir( (const QString &)strItem)) { - currentRemoteDir = oldRemoteCurrentDir; - strItem=""; - qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); + 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); } - } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory - qDebug("trying directory"); - if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { - currentRemoteDir = oldRemoteCurrentDir; - strItem=""; - qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); + 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); + } + currentRemoteDir=path; + } else { + if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers + strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); + strItem = strItem.stripWhiteSpace(); + currentRemoteDir = strItem; + if( !remoteChDir( (const QString &)strItem)) { + currentRemoteDir = oldRemoteCurrentDir; + strItem=""; + qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); + } + } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory + qDebug("trying directory"); + if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { + currentRemoteDir = oldRemoteCurrentDir; + strItem=""; + qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); + } else { + currentRemoteDir = currentRemoteDir+strItem; + } } else { - currentRemoteDir = currentRemoteDir+strItem; + qDebug("download "+strItem); } - } else { - qDebug("download "+strItem); } + remoteDirList( (const QString &)currentRemoteDir); //this also calls populate + if(currentRemoteDir.right(1) !="/") + currentRemoteDir +="/"; + currentPathCombo->lineEdit()->setText( currentRemoteDir ); + fillRemoteCombo( (const QString &)currentDir); + QCopEnvelope ( "QPE/System", "notBusy()" ); } - remoteDirList( (const QString &)currentRemoteDir); //this also calls populate - if(currentRemoteDir.right(1) !="/") - currentRemoteDir +="/"; - currentPathCombo->lineEdit()->setText( currentRemoteDir ); - fillRemoteCombo( (const QString &)currentDir); - QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::localListClicked(QListViewItem *selectedItem) { - QString strItem=selectedItem->text(0); - QString strSize=selectedItem->text(1); - strSize=strSize.stripWhiteSpace(); - if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink - // is symlink - QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); - if(QDir(strItem2).exists() ) { - currentDir.cd(strItem2, TRUE); - populateLocalView(); - } - } else { // not a symlink - if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { - if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { - strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); - currentDir.cd(strItem,FALSE); - populateLocalView(); - } else { - currentDir.cdUp(); + if(item) { + QString strItem=selectedItem->text(0); + QString strSize=selectedItem->text(1); + strSize=strSize.stripWhiteSpace(); + if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink + // is symlink + QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); + if(QDir(strItem2).exists() ) { + currentDir.cd(strItem2, TRUE); populateLocalView(); } - if(QDir(strItem).exists()){ - currentDir.cd(strItem, TRUE); - populateLocalView(); - } - } else { - strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); - if( QFile::exists(strItem ) ) { - qDebug("upload "+strItem); - } - } //end not symlink - chdir(strItem.latin1()); + } else { // not a symlink + if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { + if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { + strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); + currentDir.cd(strItem,FALSE); + populateLocalView(); + } else { + currentDir.cdUp(); + populateLocalView(); + } + if(QDir(strItem).exists()){ + currentDir.cd(strItem, TRUE); + populateLocalView(); + } + } else { + strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); + if( QFile::exists(strItem ) ) { + qDebug("upload "+strItem); + } + } //end not symlink + chdir(strItem.latin1()); + } } } void OpieFtp::doLocalCd() { localListClicked( Local_View->currentItem()); } void OpieFtp:: doRemoteCd() { remoteListClicked( Remote_View->currentItem()); @@ -955,58 +967,58 @@ void OpieFtp::localRename() QString oldname = currentDir.canonicalPath() + "/" + curFile; QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; if( rename(oldname.latin1(), newName.latin1())== -1) QMessageBox::message(tr("Note"),tr("Could not rename")); } populateLocalView(); } void OpieFtp::currentPathComboActivated(const QString & currentPath) { if (TabWidget->currentPageIndex() == 0) { chdir( currentPath.latin1() ); currentDir.cd( currentPath, TRUE); - populateLocalList(); + populateLocalView(); update(); } else { // chdir( currentPath.latin1() ); // currentDir.cd( currentPath, TRUE); // populateList(); // update(); } } void OpieFtp::fillCombo(const QString ¤tPath) { - currentPathComboBox->lineEdit()->setText(currentPath); + currentPathCombo->lineEdit()->setText(currentPath); if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { - currentPathComboBox->clear(); + currentPathCombo->clear(); localDirPathStringList.prepend(currentPath ); - currentPathComboBox->insertStringList( localDirPathStringList,-1); + currentPathCombo->insertStringList( localDirPathStringList,-1); } - currentPathComboBox->lineEdit()->setText(currentPath); + currentPathCombo->lineEdit()->setText(currentPath); if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { - currentPathComboBox->clear(); + currentPathCombo->clear(); remoteDirPathStringList.prepend(currentPath ); - currentPathComboBox->insertStringList( remoteDirPathStringList,-1); + currentPathCombo->insertStringList( remoteDirPathStringList,-1); } } void OpieFtp::fillRemoteCombo(const QString ¤tPath) { - dirPathCombo->lineEdit()->setText(currentPath); + currentPathCombo->lineEdit()->setText(currentPath); if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { - dirPathCombo->clear(); + currentPathCombo->clear(); remoteDirPathStringList.prepend(currentPath ); - dirPathCombo->insertStringList( remoteDirPathStringList,-1); + currentPathCombo->insertStringList( remoteDirPathStringList,-1); } } void OpieFtp::currentPathComboChanged() { QString oldRemoteCurrentDir = currentRemoteDir; // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); if (TabWidget->currentPageIndex() == 0) { if(QDir( currentPathCombo->lineEdit()->text()).exists()) { currentDir.setPath( currentPathCombo->lineEdit()->text() ); populateLocalView(); } else { @@ -1118,25 +1130,25 @@ void OpieFtp::fillCombos() void OpieFtp::serverComboSelected(int index) { currentServerConfig = index; QString username, remoteServerStr, remotePathStr, password, port, temp; // remoteServerStr = ServerComboBox->text(index); Config cfg("opieftp"); cfg.setGroup("Server"); int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); temp.setNum(index+1); remoteServerStr = cfg.readEntry( temp,""); cfg.setGroup(temp); - qDebug(temp); +// qDebug(temp); int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); port = remoteServerStr.right( divider - 1); bool ok; int portInt = port.toInt(&ok,10); if( portInt == 0) portInt = 21; PortSpinBox->setValue( portInt); remotePath->setText(cfg.readEntry("RemotePath", "/")); username = cfg.readEntry("Username", "anonymous"); UsernameComboBox->lineEdit()->setText(username); |