Diffstat (limited to 'noncore/net/opieftp/opieftp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 278 |
1 files changed, 161 insertions, 117 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index eed133e..d74c55b 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -1,3 +1,3 @@ /*************************************************************************** - opieftp.cpp + opieftp.cpp ------------------- @@ -11,3 +11,3 @@ ***************************************************************************/ -//#define DEVELOPER_VERSION +#define DEVELOPERS_VERSION @@ -135,3 +135,3 @@ OpieFtp::OpieFtp( ) - connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), + connect( Local_View, SIGNAL( clicked( QListViewItem*)), this,SLOT( localListClicked(QListViewItem *)) ); @@ -156,3 +156,3 @@ OpieFtp::OpieFtp( ) - connect( Remote_View, SIGNAL( doubleClicked( QListViewItem*)), + connect( Remote_View, SIGNAL( clicked( QListViewItem*)), this,SLOT( remoteListClicked(QListViewItem *)) ); @@ -176,3 +176,2 @@ OpieFtp::OpieFtp( ) UsernameComboBox->setEditable(TRUE); -// UsernameComboBox->lineEdit()->setText("anonymous"); tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); @@ -185,3 +184,2 @@ OpieFtp::OpieFtp( ) PasswordEdit->setEchoMode(QLineEdit::Password); -// PasswordEdit->setText( tr( "me@opieftp.org" ) ); tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); @@ -194,3 +192,2 @@ OpieFtp::OpieFtp( ) ServerComboBox->setEditable(TRUE); -// ServerComboBox->lineEdit()->setText( tr( "" ) ); tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); @@ -198,2 +195,3 @@ OpieFtp::OpieFtp( ) connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); + connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this,SLOT(serverComboEdited(const QString & ) )); @@ -204,3 +202,2 @@ OpieFtp::OpieFtp( ) remotePath = new QLineEdit( "/", tab_3, "remotePath" ); - remotePath->setText( currentRemoteDir = "/"); tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); @@ -214,3 +211,2 @@ OpieFtp::OpieFtp( ) PortSpinBox->setMaxValue(32786); - PortSpinBox->setValue( 21); tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); @@ -218,3 +214,3 @@ OpieFtp::OpieFtp( ) QPushButton *deleteServerBtn; - deleteServerBtn = new QPushButton( "Delete Server",this, "OpenButton" ); + deleteServerBtn = new QPushButton( "Delete Server", tab_3 , "OpenButton" ); tabLayout_3->addMultiCellWidget( deleteServerBtn, 5, 5, 2, 3); @@ -223,6 +219,6 @@ OpieFtp::OpieFtp( ) - QPushButton *connectServerBtn; - connectServerBtn = new QPushButton( "Connect",this, "ConnectButton" ); + connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); tabLayout_3->addMultiCellWidget( connectServerBtn, 5, 5, 0, 1); - connect(connectServerBtn,SIGNAL( clicked()),SLOT( connector() )); + connectServerBtn->setToggleButton(TRUE); + connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); @@ -250,13 +246,15 @@ OpieFtp::OpieFtp( ) serverComboSelected(0); -#ifdef DEVELOPER_VERSION -// ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) ); + fillCombos(); + +#ifdef DEVELOPERS_VERSION ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); UsernameComboBox->lineEdit()->setText("root"); -// UsernameComboBox->lineEdit()->setText("llornkcor"); 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 - fillCombos(); +#endif filterStr="*"; @@ -306,2 +304,90 @@ void OpieFtp::tabChanged(QWidget *w) +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"); + } +} + +void OpieFtp::connectorBtnToggled(bool On) +{ + if(On) { + connector(); + } else { + disConnector(); + } + +} + +void OpieFtp::connector() +{ + QCopEnvelope ( "QPE/System", "busy()" ); + qApp->processEvents(); + currentRemoteDir=remotePath->text(); + if(ServerComboBox->currentText().isEmpty()) { + QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); + TabWidget->setCurrentPage(2); + ServerComboBox->setFocus(); + connectServerBtn->setOn(FALSE); + connectServerBtn->setText( tr("Connect")); + return; + } + FtpInit(); + TabWidget->setCurrentPage(1); + QString ftp_host = ServerComboBox->currentText(); + QString ftp_user = UsernameComboBox->currentText(); + QString ftp_pass = PasswordEdit->text(); + QString port=PortSpinBox->cleanText(); + port.stripWhiteSpace(); + + if(ftp_host.find("ftp://",0, TRUE) != -1 ) + ftp_host=ftp_host.right(ftp_host.length()-6); + ftp_host+=":"+port; + if (!FtpConnect( ftp_host.latin1(), &conn)) { + QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); + connectServerBtn->setOn(FALSE); + connectServerBtn->setText( tr("Connect")); + return ; + } + if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { + QString msg; + msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); + 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() @@ -330,3 +416,2 @@ void OpieFtp::localUpload() QMessageBox::message(tr("Note"),msg); -// FtpQuit(conn); } @@ -382,3 +467,2 @@ void OpieFtp::remoteDownload() QMessageBox::message(tr("Note"),msg); -// FtpQuit(conn); } @@ -391,62 +475,2 @@ void OpieFtp::remoteDownload() - -void OpieFtp::newConnection() -{ - UsernameComboBox->lineEdit()->setText(""); - PasswordEdit->setText( "" ); - ServerComboBox->lineEdit()->setText( ""); - remotePath->setText( currentRemoteDir = "/"); - PortSpinBox->setValue( 21); - TabWidget->setCurrentPage(2); - -} - -void OpieFtp::connector() -{ - QCopEnvelope ( "QPE/System", "busy()" ); - qApp->processEvents(); - currentRemoteDir=remotePath->text(); - if(ServerComboBox->currentText().isEmpty()) { - QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); - TabWidget->setCurrentPage(2); - ServerComboBox->setFocus(); - return; - } - FtpInit(); - TabWidget->setCurrentPage(1); - QString ftp_host = ServerComboBox->currentText(); - QString ftp_user = UsernameComboBox->currentText(); - QString ftp_pass = PasswordEdit->text(); - QString port=PortSpinBox->cleanText(); - port.stripWhiteSpace(); - - if(ftp_host.find("ftp://",0, TRUE) != -1 ) - ftp_host=ftp_host.right(ftp_host.length()-6); - ftp_host+=":"+port; - if (!FtpConnect( ftp_host.latin1(), &conn)) { - QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); - return ; - } - if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { - QString msg; - msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); - msg.replace(QRegExp(":"),"\n"); - QMessageBox::message(tr("Note"),msg); - FtpQuit(conn); - return ; - } - remoteDirList("/") ; - setCaption(ftp_host); - writeConfig(); - QCopEnvelope ( "QPE/System", "notBusy()" ); -} - -void OpieFtp::disConnector() -{ - FtpQuit(conn); - setCaption("OpieFtp"); - currentRemoteDir="/"; - Remote_View->clear(); -} - bool OpieFtp::remoteDirList(const QString &dir) @@ -465,3 +489,2 @@ bool OpieFtp::remoteDirList(const QString &dir) QMessageBox::message(tr("Note"),msg); -// FtpQuit(conn); return false; @@ -482,3 +505,2 @@ bool OpieFtp::remoteChDir(const QString &dir) qDebug(msg); -// FtpQuit(conn); QCopEnvelope ( "QPE/System", "notBusy()" ); @@ -583,3 +605,3 @@ bool OpieFtp::populateRemoteView( ) Remote_View->setSorting( 4,TRUE); - + return true; @@ -788,3 +810,3 @@ void OpieFtp::localDelete() break; - case 1: + case 1: // exit @@ -847,3 +869,3 @@ void OpieFtp::remoteDelete() remoteDirList( (const QString &)currentRemoteDir); //this also calls populate - + } @@ -950,3 +972,4 @@ void OpieFtp::switchToConfigTab() -void OpieFtp::readConfig() { +void OpieFtp::readConfig() +{ @@ -975,8 +998,7 @@ void OpieFtp::readConfig() { PasswordEdit->setText(password); - } - } -void OpieFtp::writeConfig() { +void OpieFtp::writeConfig() +{ @@ -984,4 +1006,12 @@ void OpieFtp::writeConfig() { cfg.setGroup("Server"); - QString temp; + QString username, remoteServerStr, remotePathStr, password, port, temp; int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); + if( currentServerConfig == -1) { + + temp.setNum( numberOfEntries + 1); + cfg.setGroup("Server"); + remoteServerStr = cfg.readEntry( temp,""); + int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); + remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); + temp.setNum(numberOfEntries+1); @@ -995,7 +1025,9 @@ void OpieFtp::writeConfig() { cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); - + + } } -void OpieFtp::fillCombos() { - Config cfg("opieftp"); +void OpieFtp::fillCombos() +{ + Config cfg("opieftp"); cfg.setGroup("Server"); @@ -1028,5 +1060,3 @@ void OpieFtp::fillCombos() { // PasswordEdit->setText(password); - } - } @@ -1034,4 +1064,5 @@ void OpieFtp::fillCombos() { -void OpieFtp::serverComboSelected(int index) { - +void OpieFtp::serverComboSelected(int index) +{ + currentServerConfig = index; QString username, remoteServerStr, remotePathStr, password, port, temp; @@ -1042,22 +1073,20 @@ void OpieFtp::serverComboSelected(int index) { -// for (int i = 0; i <= numberOfEntries; i++) { - temp.setNum(index+1); - remoteServerStr = cfg.readEntry( temp,""); - // if( remoteServerStr.find( ServerComboBox->text(index),0,TRUE) != -1 ) { - cfg.setGroup(temp); - qDebug(temp); - int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); - port = remoteServerStr.right( divider - 1); - bool ok; - PortSpinBox->setValue( port.toInt(&ok,10)); + temp.setNum(index+1); + remoteServerStr = cfg.readEntry( temp,""); + cfg.setGroup(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; - remotePath->setText(cfg.readEntry("RemotePath", "")); - username = cfg.readEntry("Username", ""); - UsernameComboBox->lineEdit()->setText(username); - PasswordEdit->setText(cfg.readEntryCrypt(username, "")); + PortSpinBox->setValue( portInt); -// } + remotePath->setText(cfg.readEntry("RemotePath", "/")); - // } - update(); + username = cfg.readEntry("Username", "anonymous"); + UsernameComboBox->lineEdit()->setText(username); + PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); + update(); } @@ -1069,4 +1098,19 @@ void OpieFtp::serverComboSelected(int index) { -void OpieFtp::deleteServer() { - +void OpieFtp::deleteServer() +{ + QString username, remoteServerStr, remotePathStr, password, port, temp; + remoteServerStr = ServerComboBox->currentText( ); + username = UsernameComboBox->currentText(); + Config cfg("opieftp"); + cfg.setGroup("Server"); + int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); + for (int i = 0; i <= numberOfEntries; i++) { + temp.setNum(i+1); + cfg.setGroup("Server"); + if( cfg.readEntry( temp,"").find( remoteServerStr,0,TRUE) != -1 + && cfg.readEntry(temp).find(username,0,TRUE) != -1 + && !remoteServerStr.isEmpty()) { + qDebug(temp); + } + } } |