-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 @@ -53,2 +53,3 @@ extern "C" { #include <qregexp.h> +#include <qlistbox.h> @@ -76,3 +77,3 @@ OpieFtp::OpieFtp( ) setCaption( tr( "OpieFtp" ) ); - + fuckeduphack=FALSE; QGridLayout *layout = new QGridLayout( this ); @@ -226,2 +227,4 @@ OpieFtp::OpieFtp( ) + connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this,SLOT( UsernameComboBoxEdited(const QString & ) )); + TextLabel2 = new QLabel( tab_3, "TextLabel2" ); @@ -233,2 +236,5 @@ OpieFtp::OpieFtp( ) tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); + + connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this,SLOT( PasswordEditEdited(const QString & ) )); + //PasswordEdit->setFixedWidth(85); @@ -261,10 +267,10 @@ OpieFtp::OpieFtp( ) - 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); @@ -272,2 +278,13 @@ OpieFtp::OpieFtp( ) + 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 ); @@ -298,5 +315,3 @@ OpieFtp::OpieFtp( ) layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4); - - fillCombos(); - + ProgressBar->setMaximumHeight(10); filterStr="*"; @@ -304,6 +319,5 @@ OpieFtp::OpieFtp( ) populateLocalView(); -qDebug("read COnfig"); - readConfig(); - qDebug("Set current item"); - ServerComboBox->setCurrentItem(currentServerConfig); + readConfig(); + +// ServerComboBox->setCurrentItem(currentServerConfig); @@ -328,2 +342,6 @@ void OpieFtp::cleanUp() file.remove(); + Config cfg("opieftp"); + cfg.setGroup("Server"); + cfg.writeEntry("currentServer", currentServerConfig); + exit(0); @@ -375,6 +393,14 @@ 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; } @@ -396,3 +422,5 @@ void OpieFtp::connector() 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); @@ -404,3 +432,5 @@ void OpieFtp::connector() } + FtpInit(); + TabWidget->setCurrentPage(1); @@ -412,2 +442,15 @@ void OpieFtp::connector() + 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 ) @@ -415,2 +458,3 @@ void OpieFtp::connector() ftp_host+=":"+port; + if (!FtpConnect( ftp_host.latin1(), &conn)) { @@ -421,2 +465,3 @@ void OpieFtp::connector() } + if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { @@ -432,5 +477,6 @@ void OpieFtp::connector() } + remoteDirList("/") ; setCaption(ftp_host); - if( currentServerConfig == -1) + if( currentServerConfig == -1) writeConfig(); @@ -624,3 +670,3 @@ void OpieFtp::populateLocalView() if(fileL !="./" && fi->exists()) { - item= new QListViewItem( Local_View,fileL, fileDate, fileS ); + item = new QListViewItem( Local_View,fileL, fileDate, fileS ); QPixmap pm; @@ -1151,3 +1197,4 @@ void OpieFtp::readConfig() // qDebug("Reading %d", currentServerConfig); - serverComboSelected( currentServerConfig); + serverComboSelected( currentServerConfig-1); + } @@ -1156,8 +1203,13 @@ 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); @@ -1166,5 +1218,8 @@ void OpieFtp::writeConfig() } + temp.setNum( numberOfEntries + 1); cfg.setGroup("Server"); + remoteServerStr = cfg.readEntry( temp,""); + int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); @@ -1174,9 +1229,20 @@ void OpieFtp::writeConfig() 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 )); @@ -1186,4 +1252,15 @@ void OpieFtp::writeConfig() +void OpieFtp::clearCombos() { + qDebug("clearing"); + ServerComboBox->clear(); + UsernameComboBox->clear(); + PasswordEdit->clear(); + serverListView->clear(); +} + + void OpieFtp::fillCombos() { + clearCombos(); + Config cfg("opieftp"); @@ -1192,2 +1269,3 @@ void OpieFtp::fillCombos() int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); + for (int i = 1; i <= numberOfEntries; i++) { @@ -1198,2 +1276,3 @@ void OpieFtp::fillCombos() qDebug( remoteServerStr); + int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); @@ -1204,18 +1283,13 @@ void OpieFtp::fillCombos() 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")); } @@ -1226,5 +1300,7 @@ 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"); @@ -1233,4 +1309,5 @@ void OpieFtp::serverComboSelected(int index) - temp.setNum(index); + temp.setNum(index+1); remoteServerStr = cfg.readEntry( temp,""); + qDebug("Group" +temp); @@ -1243,3 +1320,5 @@ void OpieFtp::serverComboSelected(int index) if( portInt == 0) portInt = 21; - + + ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); + PortSpinBox->setValue( portInt); @@ -1258,10 +1337,10 @@ void OpieFtp::serverComboSelected(int index) 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); @@ -1269,17 +1348,61 @@ 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(); } @@ -1347 +1470,34 @@ void OpieFtp::doAbout() { } + +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 @@ -26,3 +26,3 @@ class QComboBox; class QListView; -class QListviewItem; +class QListViewItem; class QLabel; @@ -36,3 +36,2 @@ class QPopupMenu; class QFile; -class QListViewItem; class QLineEdit; @@ -41,2 +40,3 @@ class QToolButton; class QStringList; +class QListBox; @@ -53,2 +53,3 @@ public: QListView *Local_View, *Remote_View; + QListBox *serverListView; @@ -63,3 +64,3 @@ public: QListViewItem * item; - QPushButton *connectServerBtn;// + QPushButton *connectServerBtn, *newServerButton;// QToolButton *cdUpButton, *homeButton, *docButton; @@ -72,3 +73,7 @@ protected slots: void doAbout(); + void serverComboEdited(const QString & ); + void UsernameComboBoxEdited(const QString & ); + void PasswordEditEdited(const QString & ); + void showLocalMenu( QListViewItem *); @@ -95,21 +100,32 @@ protected slots: 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(); |