author | llornkcor <llornkcor> | 2002-07-20 02:35:34 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-20 02:35:34 (UTC) |
commit | 8256eec0103a50f80905e71891904a4267754559 (patch) (side-by-side diff) | |
tree | 8dc249ea2db645d38c9ce39a6000e9ee833978b4 /noncore | |
parent | a4a56e27ba0f4fd2bdbc56e20c9e7f4ccc8be535 (diff) | |
download | opie-8256eec0103a50f80905e71891904a4267754559.zip opie-8256eec0103a50f80905e71891904a4267754559.tar.gz opie-8256eec0103a50f80905e71891904a4267754559.tar.bz2 |
fixes and changes.. _should_ remember servers. Still needs work
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 260 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 42 |
2 files changed, 237 insertions, 65 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 9d6356d..9beac94 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -30,72 +30,73 @@ extern "C" { #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> #include <qmainwindow.h> #include <qlabel.h> #include <qprogressbar.h> #include <qspinbox.h> #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 <qlistbox.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; } OpieFtp::OpieFtp( ) : QMainWindow( ) { setCaption( tr( "OpieFtp" ) ); - + fuckeduphack=FALSE; QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); QPEMenuBar *menuBar = new QPEMenuBar(this); // QPEToolBar *menuBar = new QPEToolBar(this); // menuBar->setHorizontalStretchable( TRUE ); connectionMenu = new QPopupMenu( this ); localMenu = new QPopupMenu( this ); remoteMenu = new QPopupMenu( this ); tabMenu = new QPopupMenu( this ); layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 ); 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() )); @@ -203,257 +204,302 @@ OpieFtp::OpieFtp( ) QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); connect( Remote_View, SIGNAL( clicked( 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 ); + connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this,SLOT( UsernameComboBoxEdited(const QString & ) )); + TextLabel2 = new QLabel( tab_3, "TextLabel2" ); TextLabel2->setText( tr( "Password" ) ); tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); PasswordEdit->setEchoMode(QLineEdit::Password); tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); + + connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this,SLOT( PasswordEditEdited(const QString & ) )); + //PasswordEdit->setFixedWidth(85); TextLabel3 = new QLabel( tab_3, "TextLabel3" ); TextLabel3->setText( tr( "Remote server" ) ); tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); 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())); + serverListView = new QListBox( tab_3, "ServerListView" ); + tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5); + connect( serverListView, SIGNAL( highlighted( const QString &)), + this,SLOT( serverListClicked( const QString &) ) ); + connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); - tabLayout_3->addMultiCellWidget( connectServerBtn, 5, 5, 0, 1); + tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1); connectServerBtn->setToggleButton(TRUE); connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); + newServerButton= new QPushButton( "Add", tab_3 , "NewServerButton" ); + tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2); + connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() )); + + QPushButton *deleteServerBtn; + deleteServerBtn = new QPushButton( "Delete", tab_3 , "OpenButton" ); + tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3); + + connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); + + 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 ->setFixedWidth(220); 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(); - + ProgressBar->setMaximumHeight(10); filterStr="*"; b=FALSE; populateLocalView(); -qDebug("read COnfig"); - readConfig(); - qDebug("Set current item"); - ServerComboBox->setCurrentItem(currentServerConfig); + readConfig(); + +// 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(); + Config cfg("opieftp"); + cfg.setGroup("Server"); + cfg.writeEntry("currentServer", currentServerConfig); + 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) { tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); cdUpButton->hide(); homeButton->hide(); } } void OpieFtp::newConnection() { UsernameComboBox->lineEdit()->setText(""); PasswordEdit->setText( "" ); ServerComboBox->lineEdit()->setText( ""); remotePath->setText( currentRemoteDir = "/"); PortSpinBox->setValue( 21); TabWidget->setCurrentPage(2); } void OpieFtp::serverComboEdited(const QString & edit) { - if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { - qDebug("ServerComboEdited"); - currentServerConfig = -1; - } +// if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { +// qDebug("ServerComboEdited"); +// // currentServerConfig = -1; +// } +} + +void OpieFtp::UsernameComboBoxEdited(const QString & use) { +// currentServerConfig = -1; +} + +void OpieFtp::PasswordEditEdited(const QString & pass) { +// currentServerConfig = -1; } 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()) { + + 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(); + Config cfg("opieftp"); + cfg.setGroup("Server"); + int current=cfg.readNumEntry("currentServer", 1); + +// if(ftp_host!= cfg.readEntry(QString::number( current))) +// currentServerConfig=-1; +// cfg.setGroup(QString::number(current)); +// if( ftp_user != cfg.readEntry("Username")) +// currentServerConfig=-1; +// if(ftp_pass != cfg.readEntry(cfg.readEntry("Username"))) +// currentServerConfig=-1; + + 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) + 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 ); @@ -601,49 +647,49 @@ void OpieFtp::populateLocalView() 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", fi->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, fileDate, fileS ); + item = new QListViewItem( Local_View,fileL, fileDate, fileS ); QPixmap pm; if(isDir || fileL.find("/",0,TRUE) != -1) { 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 { MimeType mt(fi->filePath()); 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( "opie/symlink" ); QPainter painter( &pm ); @@ -1128,181 +1174,258 @@ void OpieFtp::currentPathComboChanged() 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); + serverComboSelected( currentServerConfig-1); + } void OpieFtp::writeConfig() { + qDebug("write config"); 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++) { + + 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); + + currentServerConfig = numberOfEntries+1; + qDebug("setting currentserverconfig to %d", currentServerConfig); + cfg.setGroup(temp); + if(!newServerName.isEmpty()) + cfg.writeEntry("ServerName", newServerName); + 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::clearCombos() { + qDebug("clearing"); + ServerComboBox->clear(); + UsernameComboBox->clear(); + PasswordEdit->clear(); + serverListView->clear(); +} + + void OpieFtp::fillCombos() { + clearCombos(); + 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); + qDebug( "remote server string "+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); + cfg.setGroup(temp); -// remoteServer = remoteServer.left(divider - 1); -// remotePath->setText( remotePathStr); + username = cfg.readEntry(temp); + UsernameComboBox->insertItem(username); + password = cfg.readEntryCrypt(username,""); + PasswordEdit->setText(password); -// username = cfg.readEntry(temp); -// UsernameComboBox->insertItem(username); -// password = cfg.readEntryCrypt(username,""); -// PasswordEdit->setText(password); + serverListView->insertItem( cfg.readEntry("ServerName")); } } void OpieFtp::serverComboSelected(int index) { - currentServerConfig = index; + currentServerConfig = index+1; + qDebug("server combo selected %d", index+1); 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); + temp.setNum(index+1); 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; - + + ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); + 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); + cfg.writeEntry("currentServer", temp); + + fuckeduphack = TRUE; + serverListView->setCurrentItem( index); + fuckeduphack=FALSE; + qDebug("server list set selected %d",index); 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; + QString username, remoteServerStr, remotePathStr, password, port, temp, servername; remoteServerStr = ServerComboBox->currentText( ); username = UsernameComboBox->currentText(); + servername=serverListView->currentText(); + Config cfg("opieftp"); cfg.setGroup("Server"); + QString tempname; 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); + + for (int i = 1; i <= numberOfEntries; i++) { + temp.setNum(i); +// cfg.setGroup("Server"); + cfg.setGroup(QString::number(i)); + tempname=cfg.readEntry( "ServerName",""); + + if( tempname.find( servername,0,TRUE) != -1 ) { +// servername.find( cfg.readEntry("ServerName")) != -1 && +// remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 && +// username.find( cfg.readEntry("Username")) != -1) { + + serverListView->removeItem(i); + + qDebug("OK DELETE "+tempname); + cfg.removeEntry(QString::number(i)); + for ( i; i <= numberOfEntries; i++) { + cfg.setGroup("Server"); + cfg.writeEntry("Server", QString::number(numberOfEntries + 1 )); + + cfg.setGroup(QString::number(i+1)); //get next server config + servername=cfg.readEntry("ServerName"); + remoteServerStr=cfg.readEntry("RemotePath"); + username=cfg.readEntry("Username"); + password=cfg.readEntryCrypt( username); + + cfg.setGroup(QString::number(i)); + + cfg.writeEntry("RemotePath", remoteServerStr); + cfg.writeEntry("ServerName", servername); + cfg.writeEntry("Username", username); + cfg.writeEntryCrypt( username, password); + + } + cfg.setGroup("Server"); + cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 )); } } + cfg.setGroup(QString::number(numberOfEntries)); + cfg.removeEntry("Server"); + cfg.removeEntry("RemotePath"); + cfg.removeEntry("ServerName"); + username=cfg.readEntry("Username"); + cfg.removeEntry("Username"); + cfg.removeEntry(username); + + currentServerConfig=currentServerConfig-1; + + fillCombos(); + update(); } 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); // qDebug(msg); } char path[256]; if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string QString msg; @@ -1324,24 +1447,57 @@ void OpieFtp::upDir() void OpieFtp::docButtonPushed() { QString current = QPEApplication::documentDir(); chdir( current.latin1() ); currentDir.cd( current, TRUE); populateLocalView(); update(); } void OpieFtp::homeButtonPushed() { QString current = QDir::homeDirPath(); chdir( current.latin1() ); currentDir.cd( current, TRUE); populateLocalView(); update(); } void OpieFtp::doAbout() { QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n" "L.J.Potter<llornkcor@handhelds.org>\n" "and uses ftplib copyright 1996-2000\n" "by Thomas Pfau, pfau@cnj.digex.net\n\n" "and is licensed by the GPL"); } + +void OpieFtp::NewServer() { + InputDialog *fileDlg; + fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0); + fileDlg->exec(); + Config cfg("opieftp"); + if( fileDlg->result() == 1 ) { + newServerName = fileDlg->LineEdit1->text(); + for(int i=1;i<serverListView->count();i++) { + cfg.setGroup( QString::number(i)); + if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) { + QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken")); + return; + } + } + currentServerConfig =-1; + writeConfig(); + serverListView->insertItem( newServerName ); + serverListView->setCurrentItem( serverListView->count()); + } +} + +void OpieFtp::serverListClicked( const QString &item) { + if(item.isEmpty()) return; + Config cfg("opieftp"); + qDebug("highltined "+item); + int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); + for (int i = 1; i <= numberOfEntries; i++) { + cfg.setGroup(QString::number(i)); + if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) + serverComboSelected(i-1); + } +} diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index ad36b1d..2aa691a 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h @@ -3,120 +3,136 @@ ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef OPIEFTP_H #define OPIEFTP_H #include <qvariant.h> #include <qdialog.h> #include <qmainwindow.h> #include <qdir.h> #include <qstring.h> #include <qpoint.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QComboBox; class QListView; -class QListviewItem; +class QListViewItem; class QLabel; class QProgressBar; class QSpinBox; class QTabWidget; class QWidget; class QPEToolBar; class QPEMenuBar; class QPopupMenu; class QFile; -class QListViewItem; class QLineEdit; class QPushButton; class QToolButton; class QStringList; +class QListBox; class OpieFtp : public QMainWindow { Q_OBJECT public: OpieFtp( ); ~OpieFtp(); QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; + QListBox *serverListView; QComboBox *UsernameComboBox, *ServerComboBox, *currentPathCombo; QLineEdit *PasswordEdit, *remotePath; QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; QSpinBox* PortSpinBox; QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu, *aboutMenu; QDir currentDir; QString currentRemoteDir; QString filterStr; QListViewItem * item; - QPushButton *connectServerBtn;// + QPushButton *connectServerBtn, *newServerButton;// QToolButton *cdUpButton, *homeButton, *docButton; bool b; int currentServerConfig; protected slots: void upDir(); void homeButtonPushed(); void docButtonPushed(); void doAbout(); + void serverComboEdited(const QString & ); + void UsernameComboBoxEdited(const QString & ); + void PasswordEditEdited(const QString & ); + void showLocalMenu( QListViewItem *); void showRemoteMenu( QListViewItem *); void doLocalCd(); void doRemoteCd(); void localUpload(); void remoteDownload(); void newConnection(); void connector(); void disConnector(); void populateLocalView(); bool populateRemoteView(); void showHidden(); void writeConfig(); void readConfig(); void localListClicked(QListViewItem *); void remoteListClicked(QListViewItem *); void ListPressed( int, QListViewItem *, const QPoint&, int); void RemoteListPressed( int, QListViewItem *, const QPoint&, int); void localMakDir(); void localDelete(); void remoteMakDir(); void remoteDelete(); + bool remoteDirList(const QString &); bool remoteChDir(const QString &); + void tabChanged(QWidget*); void cleanUp(); + void remoteRename(); void localRename(); + void currentPathComboChanged(); - void currentPathComboActivated(const QString &); - void switchToLocalTab(); - void switchToRemoteTab(); - void switchToConfigTab(); - void fillCombos(); - void fillRemoteCombo(const QString&); - void fillCombo(const QString &); - void serverComboSelected(int); - void deleteServer(); - void connectorBtnToggled(bool); + void currentPathComboActivated(const QString &); + void switchToLocalTab(); + void switchToRemoteTab(); + void switchToConfigTab(); + + void fillCombos(); + void clearCombos(); + void fillRemoteCombo(const QString&); + void fillCombo(const QString &); + void serverComboSelected(int); + void deleteServer(); + void connectorBtnToggled(bool); + void NewServer(); + void serverListClicked( const QString &); + protected: + bool fuckeduphack; QStringList remoteDirPathStringList, localDirPathStringList; + QString newServerName; void nullifyCallBack(); QGridLayout* tabLayout; QGridLayout* tabLayout_2; QGridLayout* tabLayout_3; }; #endif // OPIEFTP_H |