-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 7ca3fff..293c391 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -253,102 +253,104 @@ OpieFtp::OpieFtp( ) 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, 4); currentPathCombo->setEditable(TRUE); currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); connect( currentPathCombo, SIGNAL( activated( 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, 4); -// fillCombos(); + fillCombos(); filterStr="*"; b=FALSE; populateLocalView(); +qDebug("read COnfig"); readConfig(); + qDebug("Set current item"); ServerComboBox->setCurrentItem(currentServerConfig); TabWidget->setCurrentPage(2); } OpieFtp::~OpieFtp() { } void OpieFtp::cleanUp() { if(conn) FtpQuit(conn); QString sfile=QDir::homeDirPath(); if(sfile.right(1) != "/") sfile+="/._temp"; else sfile+="._temp"; QFile file( sfile); if(file.exists()) file.remove(); exit(0); } void OpieFtp::tabChanged(QWidget *w) { if (TabWidget->currentPageIndex() == 0) { currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); if(cdUpButton->isHidden()) cdUpButton->show(); if(homeButton->isHidden()) homeButton->show(); } if (TabWidget->currentPageIndex() == 1) { currentPathCombo->lineEdit()->setText( currentRemoteDir ); tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); if(cdUpButton->isHidden()) cdUpButton->show(); homeButton->hide(); } if (TabWidget->currentPageIndex() == 2) { @@ -386,96 +388,97 @@ void OpieFtp::connectorBtnToggled(bool On) 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); + if( currentServerConfig == -1) 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); setCaption("OpieFtp"); } void OpieFtp::localUpload() { int fsz; // QCopEnvelope ( "QPE/System", "busy()" ); // 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")); @@ -1100,193 +1103,202 @@ void OpieFtp::fillRemoteCombo(const QString ¤tPath) { 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 { QMessageBox::message(tr("Note"),tr("That directory does not exist")); } } if (TabWidget->currentPageIndex() == 1) { currentRemoteDir = currentPathCombo->lineEdit()->text(); if(currentRemoteDir.right(1) !="/") { currentRemoteDir = currentRemoteDir +"/"; currentPathCombo->lineEdit()->setText( currentRemoteDir ); } if( !remoteChDir( (const QString &)currentRemoteDir) ) { currentRemoteDir = oldRemoteCurrentDir; currentPathCombo->lineEdit()->setText( currentRemoteDir ); } remoteDirList( (const QString &)currentRemoteDir); } } void OpieFtp::switchToLocalTab() { TabWidget->setCurrentPage(0); } void OpieFtp::switchToRemoteTab() { TabWidget->setCurrentPage(1); } void OpieFtp::switchToConfigTab() { TabWidget->setCurrentPage(2); } void OpieFtp::readConfig() { fillCombos(); Config cfg("opieftp"); cfg.setGroup("Server"); currentServerConfig = cfg.readNumEntry("currentServer", -1); + // qDebug("Reading %d", currentServerConfig); serverComboSelected( currentServerConfig); } void OpieFtp::writeConfig() { Config cfg("opieftp"); cfg.setGroup("Server"); QString username, remoteServerStr, remotePathStr, password, port, temp; int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); if( currentServerConfig == -1) { for (int i = 1; i <= numberOfEntries; i++) { temp.setNum(i); cfg.setGroup("Server"); QString tempStr = cfg.readEntry( temp,""); } 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); cfg.setGroup("Server"); cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); + cfg.writeEntry("currentServer", numberOfEntries+1); cfg.setGroup(temp); cfg.writeEntry("RemotePath", remotePath->text()); cfg.writeEntry("Username", UsernameComboBox->currentText()); cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); cfg.setGroup("Server"); cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); + } } void OpieFtp::fillCombos() { Config cfg("opieftp"); cfg.setGroup("Server"); QString username, remoteServerStr, remotePathStr, password, port, temp; int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); for (int i = 1; i <= numberOfEntries; i++) { temp.setNum(i); + qDebug(temp); cfg.setGroup("Server"); remoteServerStr = cfg.readEntry( temp,""); + qDebug( remoteServerStr); int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); port = remoteServerStr.right( divider - 1); bool ok; PortSpinBox->setValue( port.toInt(&ok,10)); remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); + qDebug( remoteServerStr); ServerComboBox->insertItem( remoteServerStr ); // cfg.setGroup(temp); // remotePathStr = cfg.readEntry(remoteServer,""); // int divider = remoteServer.length() - remoteServer.find(":",0,TRUE); // port = remoteServer.right( divider+1); // PortSpinBox->setValue( port); // remoteServer = remoteServer.left(divider - 1); // remotePath->setText( remotePathStr); // username = cfg.readEntry(temp); // UsernameComboBox->insertItem(username); // password = cfg.readEntryCrypt(username,""); // PasswordEdit->setText(password); } } 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); + temp.setNum(index); remoteServerStr = cfg.readEntry( temp,""); + qDebug("Group" +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; PortSpinBox->setValue( portInt); remotePath->setText(cfg.readEntry("RemotePath", "/")); username = cfg.readEntry("Username", "anonymous"); UsernameComboBox->lineEdit()->setText(username); - + qDebug(username); // qDebug("Password is "+cfg.readEntryCrypt(username, "me@opieftp.org")); PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); +// UsernameComboBox +// PasswordEdit cfg.setGroup("Server"); temp.sprintf("%d",currentServerConfig); cfg.writeEntry("currentServer", temp); update(); } // UsernameComboBox->lineEdit()->setText("root"); // PasswordEdit->setText( tr( "" ) ); // ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); // remotePath->setText( currentRemoteDir = "/home/llornkcor/"); // PortSpinBox->setValue( 4242); 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); } } } void OpieFtp::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 { 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); |