summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-24 14:14:49 (UTC)
committer llornkcor <llornkcor>2002-03-24 14:14:49 (UTC)
commit807ea39f3ccfbc26e769fc16a79d459327e13437 (patch) (side-by-side diff)
treefa25defd4f0d6f6630cecad2f7eb274dcac30db6
parent5c17e8b168cf27ac2922e7c118cb886b116eab42 (diff)
downloadopie-807ea39f3ccfbc26e769fc16a79d459327e13437.zip
opie-807ea39f3ccfbc26e769fc16a79d459327e13437.tar.gz
opie-807ea39f3ccfbc26e769fc16a79d459327e13437.tar.bz2
radnom fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieftp/ftplib.c2
-rw-r--r--noncore/net/opieftp/opieftp.cpp278
-rw-r--r--noncore/net/opieftp/opieftp.h9
3 files changed, 168 insertions, 121 deletions
diff --git a/noncore/net/opieftp/ftplib.c b/noncore/net/opieftp/ftplib.c
index b9ca746..5116170 100644
--- a/noncore/net/opieftp/ftplib.c
+++ b/noncore/net/opieftp/ftplib.c
@@ -37,49 +37,49 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#elif defined(VMS)
#include <types.h>
#include <socket.h>
#include <in.h>
#include <netdb.h>
#include <inet.h>
#elif defined(_WIN32)
#include <winsock.h>
#endif
#define BUILDING_LIBRARY
#include "ftplib.h"
#if defined(_WIN32)
#define SETSOCKOPT_OPTVAL_TYPE (const char *)
#else
#define SETSOCKOPT_OPTVAL_TYPE (void *)
#endif
#define FTPLIB_BUFSIZ 8192
-#define ACCEPT_TIMEOUT 30
+#define ACCEPT_TIMEOUT 15
#define FTPLIB_CONTROL 0
#define FTPLIB_READ 1
#define FTPLIB_WRITE 2
#if !defined FTPLIB_DEFMODE
#define FTPLIB_DEFMODE FTPLIB_PASSIVE
#endif
struct NetBuf {
char *cput,*cget;
int handle;
int cavail,cleft;
char *buf;
int dir;
netbuf *ctrl;
netbuf *data;
int cmode;
struct timeval idletime;
FtpCallback idlecb;
void *idlearg;
int xfered;
int cbbytes;
int xfered1;
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,36 +1,36 @@
/***************************************************************************
- opieftp.cpp
+ opieftp.cpp
-------------------
** 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. *
***************************************************************************/
-//#define DEVELOPER_VERSION
+#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 <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>
@@ -112,244 +112,329 @@ OpieFtp::OpieFtp( )
tabMenu->setCheckable(TRUE);
TabWidget = new QTabWidget( this, "TabWidget" );
layout->addMultiCellWidget( TabWidget, 1, 1, 0, 3 );
TabWidget->setTabShape(QTabWidget::Triangular);
tab = new QWidget( TabWidget, "tab" );
tabLayout = new QGridLayout( tab );
tabLayout->setSpacing( 2);
tabLayout->setMargin( 2);
Local_View = new QListView( tab, "Local_View" );
// Local_View->setResizePolicy( QListView::AutoOneFit );
Local_View->addColumn( tr("File"),120);
Local_View->addColumn( tr("Size"),-1);
Local_View->setColumnAlignment(1,QListView::AlignRight);
Local_View->addColumn( tr("Date"),-1);
Local_View->setColumnAlignment(2,QListView::AlignRight);
Local_View->setAllColumnsShowFocus(TRUE);
QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold);
tabLayout->addWidget( Local_View, 0, 0 );
- connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)),
+ connect( Local_View, SIGNAL( clicked( QListViewItem*)),
this,SLOT( localListClicked(QListViewItem *)) );
connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
TabWidget->insertTab( tab, tr( "Local" ) );
tab_2 = new QWidget( TabWidget, "tab_2" );
tabLayout_2 = new QGridLayout( tab_2 );
tabLayout_2->setSpacing( 2);
tabLayout_2->setMargin( 2);
Remote_View = new QListView( tab_2, "Remote_View" );
Remote_View->addColumn( tr("File"),120);
Remote_View->addColumn( tr("Size"),-1);
Remote_View->setColumnAlignment(1,QListView::AlignRight);
Remote_View->addColumn( tr("Date"),-1);
Remote_View->setColumnAlignment(2,QListView::AlignRight);
Remote_View->setAllColumnsShowFocus(TRUE);
QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold);
- connect( Remote_View, SIGNAL( doubleClicked( QListViewItem*)),
+ 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);
-// UsernameComboBox->lineEdit()->setText("anonymous");
tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 );
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);
-// PasswordEdit->setText( tr( "me@opieftp.org" ) );
tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 );
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);
-// ServerComboBox->lineEdit()->setText( tr( "" ) );
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" );
- remotePath->setText( currentRemoteDir = "/");
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);
- PortSpinBox->setValue( 21);
tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1);
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);
connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer()));
- 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) ));
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);
currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" );
layout->addMultiCellWidget( currentPathEdit, 3, 3, 0, 3 );
currentPathEdit->setText( currentDir.canonicalPath());
connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged()));
ProgressBar = new QProgressBar( this, "ProgressBar" );
layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 3 );
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="*";
b=FALSE;
populateLocalView();
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();
}
void OpieFtp::tabChanged(QWidget *w)
{
if (TabWidget->currentPageIndex() == 0) {
currentPathEdit->setText( currentDir.canonicalPath());
tabMenu->setItemChecked(tabMenu->idAt(0),TRUE);
tabMenu->setItemChecked(tabMenu->idAt(1),FALSE);
tabMenu->setItemChecked(tabMenu->idAt(2),FALSE);
}
if (TabWidget->currentPageIndex() == 1) {
currentPathEdit->setText( currentRemoteDir );
tabMenu->setItemChecked(tabMenu->idAt(1),TRUE);
tabMenu->setItemChecked(tabMenu->idAt(0),FALSE);
tabMenu->setItemChecked(tabMenu->idAt(2),FALSE);
}
if (TabWidget->currentPageIndex() == 2) {
tabMenu->setItemChecked(tabMenu->idAt(2),TRUE);
tabMenu->setItemChecked(tabMenu->idAt(0),FALSE);
tabMenu->setItemChecked(tabMenu->idAt(1),FALSE);
}
}
+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()
{
int fsz;
QCopEnvelope ( "QPE/System", "busy()" );
qApp->processEvents();
QString strItem = Local_View->currentItem()->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);
-// FtpQuit(conn);
}
ProgressBar->reset();
nullifyCallBack();
} else {
QMessageBox::message(tr("Note"),tr("Cannot upload directories"));
}
TabWidget->setCurrentPage(1);
remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
QCopEnvelope ( "QPE/System", "notBusy()" );
}
void OpieFtp::nullifyCallBack()
{
FtpOptions(FTPLIB_CALLBACK, NULL, conn);
FtpOptions(FTPLIB_IDLETIME, NULL, conn);
FtpOptions(FTPLIB_CALLBACKARG, NULL, conn);
FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn);
}
void OpieFtp::remoteDownload()
{
int fsz;
QCopEnvelope ( "QPE/System", "busy()" );
@@ -359,149 +444,86 @@ void OpieFtp::remoteDownload()
QString localFile = currentDir.canonicalPath();
if(localFile.right(1).find("/",0,TRUE) == -1)
localFile += "/";
localFile += strItem;
// QString localFile = currentDir.canonicalPath()+"/"+strItem;
QString remoteFile= currentRemoteDir+strItem;
if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn))
fsz = 0;
QString temp;
temp.sprintf( remoteFile+" "+" %dkb", fsz);
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("Get: %s, %s",localFile.latin1(),remoteFile.latin1());
if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) {
QString msg;
msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn));
msg.replace(QRegExp(":"),"\n");
QMessageBox::message(tr("Note"),msg);
-// FtpQuit(conn);
}
ProgressBar->reset();
nullifyCallBack();
TabWidget->setCurrentPage(0);
populateLocalView();
QCopEnvelope ( "QPE/System", "notBusy()" );
}
-
-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)
{
QString tmp = QDir::homeDirPath();
if(tmp.right(1) != "/")
tmp+="/._temp";
else
tmp+="._temp";
// qDebug("Listing remote dir "+tmp);
QCopEnvelope ( "QPE/System", "busy()" );
if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) {
QString msg;
msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) );
msg.replace(QRegExp(":"),"\n");
QMessageBox::message(tr("Note"),msg);
-// FtpQuit(conn);
return false;
}
populateRemoteView() ;
QCopEnvelope ( "QPE/System", "notBusy()" );
return true;
}
bool OpieFtp::remoteChDir(const QString &dir)
{
QCopEnvelope ( "QPE/System", "busy()" );
if (!FtpChdir( dir.latin1(), conn )) {
QString msg;
msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn));
msg.replace(QRegExp(":"),"\n");
QMessageBox::message(tr("Note"),msg);
qDebug(msg);
-// FtpQuit(conn);
QCopEnvelope ( "QPE/System", "notBusy()" );
return FALSE;
}
QCopEnvelope ( "QPE/System", "notBusy()" );
return TRUE;
}
void OpieFtp::populateLocalView()
{
Local_View->clear();
currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
currentDir.setMatchAllDirs(TRUE);
currentDir.setNameFilter(filterStr);
QString fileL, fileS, fileDate;
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() );
@@ -560,49 +582,49 @@ bool OpieFtp::populateRemoteView( )
fileDate = fileDate.stripWhiteSpace();
if(fileL.find("total",0,TRUE) == -1) {
QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate);
if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) {
item->setPixmap( 0, Resource::loadPixmap( "folder" ));
if(itemDir)
item->moveItem(itemDir);
itemDir=item;
} else {
item->setPixmap( 0, Resource::loadPixmap( "fileopen" ));
if(itemFile)
item->moveItem(itemFile);
itemFile=item;
}
}
}
QListViewItem * item1 = new QListViewItem( Remote_View, "../");
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);
@@ -765,49 +787,49 @@ void OpieFtp::localMakDir()
{
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
QString filename = fileDlg->LineEdit1->text();
currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
}
populateLocalView();
}
void OpieFtp::localDelete()
{
QString f = Local_View->currentItem()->text(0);
if(QDir(f).exists() ) {
switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+
tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) {
case 0: {
f=currentDir.canonicalPath()+"/"+f;
QString cmd="rmdir "+f;
system( cmd.latin1());
populateLocalView();
}
break;
- case 1:
+ case 1:
// exit
break;
};
} else {
switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f
+" ?",tr("Yes"),tr("No"),0,0,1) ) {
case 0: {
f=currentDir.canonicalPath()+"/"+f;
QString cmd="rm "+f;
system( cmd.latin1());
populateLocalView();
}
break;
case 1:
// exit
break;
};
}
}
void OpieFtp::remoteMakDir()
{
InputDialog *fileDlg;
@@ -824,49 +846,49 @@ void OpieFtp::remoteMakDir()
QMessageBox::message(tr("Note"),msg);
}
QCopEnvelope ( "QPE/System", "notBusy()" );
remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
}
}
void OpieFtp::remoteDelete()
{
QString f = Remote_View->currentItem()->text(0);
QCopEnvelope ( "QPE/System", "busy()" );
if( f.right(1) =="/") {
QString path= currentRemoteDir+f;
switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?"
,tr("Yes"),tr("No"),0,0,1) ) {
case 0: {
f=currentDir.canonicalPath()+"/"+f;
if(FtpRmdir( path.latin1(), conn) ==0) {
QString msg;
msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn));
msg.replace(QRegExp(":"),"\n");
QMessageBox::message(tr("Note"),msg);
}
remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
-
+
}
break;
};
} else {
switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?"
,tr("Yes"),tr("No"),0,0,1) ) {
case 0: {
QString path= currentRemoteDir+f;
if(FtpDelete( path.latin1(), conn)==0) {
QString msg;
msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn));
msg.replace(QRegExp(":"),"\n");
QMessageBox::message(tr("Note"),msg);
}
remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
}
break;
};
}
QCopEnvelope ( "QPE/System", "notBusy()" );
}
void OpieFtp::remoteRename()
{
@@ -927,146 +949,168 @@ void OpieFtp::currentPathEditChanged()
if( !remoteChDir( (const QString &)currentRemoteDir) ) {
currentRemoteDir = oldRemoteCurrentDir;
currentPathEdit->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() {
+void OpieFtp::readConfig()
+{
Config cfg("opieftp");
cfg.setGroup("Server");
QString username, remoteServer, remotePathStr, password, port, temp;
int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
for (int i = 0; i <= numberOfEntries; i++) {
temp.setNum(i+1);
cfg.setGroup("Server");
remoteServer = cfg.readEntry( temp,"");
ServerComboBox->insertItem( remoteServer );
cfg.setGroup(temp);
remotePathStr = cfg.readEntry(remoteServer,"");
int divider = remoteServer.length() - remoteServer.find(":",0,TRUE);
port = remoteServer.right( divider+1);
bool ok;
PortSpinBox->setValue( port.toInt(&ok,10));
remoteServer = remoteServer.left(divider - 1);
remotePath->setText( remotePathStr);
username = cfg.readEntry(temp);
UsernameComboBox->insertItem(username);
password = cfg.readEntryCrypt(username,"");
PasswordEdit->setText(password);
-
}
-
}
-void OpieFtp::writeConfig() {
+void OpieFtp::writeConfig()
+{
Config cfg("opieftp");
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);
cfg.setGroup("Server");
cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() );
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");
+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);
cfg.setGroup("Server");
remoteServerStr = cfg.readEntry( temp,"");
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);
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) {
-
+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);
-// 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();
}
// 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() {
-
+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);
+ }
+ }
}
diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h
index c88a15b..52ed885 100644
--- a/noncore/net/opieftp/opieftp.h
+++ b/noncore/net/opieftp/opieftp.h
@@ -15,94 +15,97 @@
#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 QLabel;
class QProgressBar;
class QSpinBox;
class QTabWidget;
class QWidget;
class QPEToolBar;
class QPEMenuBar;
class QPopupMenu;
class QFile;
class QListViewItem;
class QLineEdit;
+class QPushButton;
class OpieFtp : public QMainWindow
-{
+{
Q_OBJECT
public:
OpieFtp( );
~OpieFtp();
QTabWidget *TabWidget;
QWidget *tab, *tab_2, *tab_3;
QListView *Local_View, *Remote_View;
QComboBox *UsernameComboBox, *ServerComboBox;
QLineEdit *PasswordEdit, *remotePath, *currentPathEdit;
QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;;
QSpinBox* PortSpinBox;
QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu;
QDir currentDir;
QString currentRemoteDir;
QString filterStr;
QListViewItem * item;
+ QPushButton *connectServerBtn;
bool b;
-
+ int currentServerConfig;
protected slots:
+ void serverComboEdited(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 currentPathEditChanged();
void switchToLocalTab();
void switchToRemoteTab();
void switchToConfigTab();
void fillCombos();
void serverComboSelected(int);
void deleteServer();
-
+ void connectorBtnToggled(bool);
protected:
void nullifyCallBack();
QGridLayout* tabLayout;
QGridLayout* tabLayout_2;
QGridLayout* tabLayout_3;
};
#endif // OPIEFTP_H