summaryrefslogtreecommitdiff
path: root/noncore/net/opieftp/opieftp.cpp
authorllornkcor <llornkcor>2002-03-13 02:45:30 (UTC)
committer llornkcor <llornkcor>2002-03-13 02:45:30 (UTC)
commitfac27f0d83dd361e27bacdf552932c9ea60e66e8 (patch) (unidiff)
tree3910ee937e9bc2b018b30f9b521b7f38cdcf2124 /noncore/net/opieftp/opieftp.cpp
parentfc49c34cfd2ce2adad2920daa368b25f42b8bad7 (diff)
downloadopie-fac27f0d83dd361e27bacdf552932c9ea60e66e8.zip
opie-fac27f0d83dd361e27bacdf552932c9ea60e66e8.tar.gz
opie-fac27f0d83dd361e27bacdf552932c9ea60e66e8.tar.bz2
fixed crash bug when remote directory doesn't exist. Fixed progess bar indicator
continuing on dir listings after an upload/download.
Diffstat (limited to 'noncore/net/opieftp/opieftp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieftp/opieftp.cpp114
1 files changed, 76 insertions, 38 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp
index e1dd582..0cdac79 100644
--- a/noncore/net/opieftp/opieftp.cpp
+++ b/noncore/net/opieftp/opieftp.cpp
@@ -40,6 +40,7 @@
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <qlineedit.h> 42#include <qlineedit.h>
43#include <qregexp.h>
43 44
44#include <unistd.h> 45#include <unistd.h>
45#include <stdlib.h> 46#include <stdlib.h>
@@ -145,7 +146,7 @@ OpieFtp::OpieFtp( )
145 UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); 146 UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" );
146 UsernameComboBox->setGeometry( QRect( 10, 25, 196, 21 ) ); 147 UsernameComboBox->setGeometry( QRect( 10, 25, 196, 21 ) );
147 UsernameComboBox->setEditable(TRUE); 148 UsernameComboBox->setEditable(TRUE);
148 UsernameComboBox->lineEdit()->setText("root"); 149 UsernameComboBox->lineEdit()->setText("llornkcor");
149 150
150 TextLabel2 = new QLabel( tab_3, "TextLabel2" ); 151 TextLabel2 = new QLabel( tab_3, "TextLabel2" );
151 TextLabel2->setGeometry( QRect( 10, 50, 65, 16 ) ); 152 TextLabel2->setGeometry( QRect( 10, 50, 65, 16 ) );
@@ -160,14 +161,14 @@ OpieFtp::OpieFtp( )
160 ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); 161 ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" );
161 ServerComboBox->setGeometry( QRect( 10, 105, 195, 21 ) ); 162 ServerComboBox->setGeometry( QRect( 10, 105, 195, 21 ) );
162 ServerComboBox->setEditable(TRUE); 163 ServerComboBox->setEditable(TRUE);
163 ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); 164 ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) );
164 165
165 QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); 166 QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" );
166 TextLabel5->setGeometry( QRect( 10, 130, 95, 16 ) ); 167 TextLabel5->setGeometry( QRect( 10, 130, 95, 16 ) );
167 TextLabel5->setText( tr( "Remote path" ) ); 168 TextLabel5->setText( tr( "Remote path" ) );
168 remotePath = new QLineEdit( "/", tab_3, "remotePath" ); 169 remotePath = new QLineEdit( "/", tab_3, "remotePath" );
169 remotePath->setGeometry( QRect( 10, 145, 195, 16 ) ); 170 remotePath->setGeometry( QRect( 10, 145, 195, 16 ) );
170 remotePath->setText( currentRemoteDir = "/"); 171 remotePath->setText( currentRemoteDir = "/home/llornkcor/");
171 172
172 TextLabel4 = new QLabel( tab_3, "TextLabel4" ); 173 TextLabel4 = new QLabel( tab_3, "TextLabel4" );
173 TextLabel4->setGeometry( QRect( 10, 170, 30, 21 ) ); 174 TextLabel4->setGeometry( QRect( 10, 170, 30, 21 ) );
@@ -176,7 +177,8 @@ OpieFtp::OpieFtp( )
176 PortSpinBox->setGeometry( QRect( 40, 175, 75, 20 ) ); 177 PortSpinBox->setGeometry( QRect( 40, 175, 75, 20 ) );
177 PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); 178 PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows );
178 PortSpinBox->setMaxValue(32786); 179 PortSpinBox->setMaxValue(32786);
179 PortSpinBox->setValue( 4242 ); 180 PortSpinBox->setValue( 21);
181
180 TabWidget->insertTab( tab_3, tr( "Config" ) ); 182 TabWidget->insertTab( tab_3, tr( "Config" ) );
181 183
182 connect(TabWidget,SIGNAL(currentChanged(QWidget *)), 184 connect(TabWidget,SIGNAL(currentChanged(QWidget *)),
@@ -226,22 +228,24 @@ void OpieFtp::localUpload()
226 QString remoteFile= currentRemoteDir+strItem; 228 QString remoteFile= currentRemoteDir+strItem;
227 QFileInfo fi(localFile); 229 QFileInfo fi(localFile);
228 if( !fi.isDir()) { 230 if( !fi.isDir()) {
229 fsz=fi.size(); 231 fsz=fi.size();
230 ProgressBar->setTotalSteps(fsz); 232 ProgressBar->setTotalSteps(fsz);
231 233
232 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); 234 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
233 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); 235 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
234 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); 236 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
235 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); 237 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
236 qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); 238 qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1());
237 239
238 if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { 240 if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) {
239 QString msg; 241 QString msg;
240 msg.sprintf("Unable to upload\n%s",FtpLastResponse(conn)); 242 msg.sprintf("Unable to upload\n%s",FtpLastResponse(conn));
241 QMessageBox::message("Note",msg); 243 msg.replace(QRegExp(":"),"\n");
242 FtpQuit(conn); 244 QMessageBox::message("Note",msg);
243 } 245// FtpQuit(conn);
244 ProgressBar->reset(); 246 }
247 ProgressBar->reset();
248 nullifyCallBack();
245 } else { 249 } else {
246 QMessageBox::message("Note","Cannot upload directories"); 250 QMessageBox::message("Note","Cannot upload directories");
247 } 251 }
@@ -250,6 +254,14 @@ void OpieFtp::localUpload()
250 QCopEnvelope ( "QPE/System", "notBusy()" ); 254 QCopEnvelope ( "QPE/System", "notBusy()" );
251} 255}
252 256
257void OpieFtp::nullifyCallBack() {
258 FtpOptions(FTPLIB_CALLBACK, NULL, conn);
259 FtpOptions(FTPLIB_IDLETIME, NULL, conn);
260 FtpOptions(FTPLIB_CALLBACKARG, NULL, conn);
261 FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn);
262
263}
264
253void OpieFtp::remoteDownload() 265void OpieFtp::remoteDownload()
254{ 266{
255 int fsz; 267 int fsz;
@@ -273,10 +285,12 @@ void OpieFtp::remoteDownload()
273 if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { 285 if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) {
274 QString msg; 286 QString msg;
275 msg.sprintf("Unable to download \n%s",FtpLastResponse(conn)); 287 msg.sprintf("Unable to download \n%s",FtpLastResponse(conn));
288 msg.replace(QRegExp(":"),"\n");
276 QMessageBox::message("Note",msg); 289 QMessageBox::message("Note",msg);
277 FtpQuit(conn); 290// FtpQuit(conn);
278 } 291 }
279 ProgressBar->reset(); 292 ProgressBar->reset();
293 nullifyCallBack();
280 TabWidget->setCurrentPage(0); 294 TabWidget->setCurrentPage(0);
281 populateLocalView(); 295 populateLocalView();
282 QCopEnvelope ( "QPE/System", "notBusy()" ); 296 QCopEnvelope ( "QPE/System", "notBusy()" );
@@ -317,6 +331,7 @@ void OpieFtp::connector()
317 if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { 331 if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) {
318 QString msg; 332 QString msg;
319 msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn)); 333 msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn));
334 msg.replace(QRegExp(":"),"\n");
320 QMessageBox::message("Note",msg); 335 QMessageBox::message("Note",msg);
321 FtpQuit(conn); 336 FtpQuit(conn);
322 return ; 337 return ;
@@ -340,8 +355,9 @@ bool OpieFtp::remoteDirList(const QString &dir)
340 if (!FtpDir( "./._temp", dir.latin1(), conn) ) { 355 if (!FtpDir( "./._temp", dir.latin1(), conn) ) {
341 QString msg; 356 QString msg;
342 msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn) ); 357 msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn) );
358 msg.replace(QRegExp(":"),"\n");
343 QMessageBox::message("Note",msg); 359 QMessageBox::message("Note",msg);
344 FtpQuit(conn); 360// FtpQuit(conn);
345 return false; 361 return false;
346 } 362 }
347 populateRemoteView(); 363 populateRemoteView();
@@ -354,9 +370,11 @@ bool OpieFtp::remoteChDir(const QString &dir)
354 QCopEnvelope ( "QPE/System", "busy()" ); 370 QCopEnvelope ( "QPE/System", "busy()" );
355 if (!FtpChdir( dir.latin1(), conn )) { 371 if (!FtpChdir( dir.latin1(), conn )) {
356 QString msg; 372 QString msg;
357 msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn)); 373 msg.sprintf("Unable to change directories\n"+dir+"\n%s",FtpLastResponse(conn));
374 msg.replace(QRegExp(":"),"\n");
358 QMessageBox::message("Note",msg); 375 QMessageBox::message("Note",msg);
359 FtpQuit(conn); 376 qDebug(msg);
377// FtpQuit(conn);
360 QCopEnvelope ( "QPE/System", "notBusy()" ); 378 QCopEnvelope ( "QPE/System", "notBusy()" );
361 return FALSE; 379 return FALSE;
362 } 380 }
@@ -429,38 +447,48 @@ bool OpieFtp::populateRemoteView()
429void OpieFtp::remoteListClicked(QListViewItem *selectedItem) 447void OpieFtp::remoteListClicked(QListViewItem *selectedItem)
430{ 448{
431 QCopEnvelope ( "QPE/System", "busy()" ); 449 QCopEnvelope ( "QPE/System", "busy()" );
450 QString oldRemoteCurrentDir = currentRemoteDir;
432 QString strItem=selectedItem->text(0); 451 QString strItem=selectedItem->text(0);
433 strItem=strItem.simplifyWhiteSpace(); 452 strItem=strItem.simplifyWhiteSpace();
434 if(strItem == "../") { 453 if(strItem == "../") { // the user wants to go ^
435 if( FtpCDUp( conn) == 0) { 454 if( FtpCDUp( conn) == 0) {
436 QString msg; 455 QString msg;
437 msg.sprintf("Unable to change directories \n%s",FtpLastResponse(conn)); 456 msg.sprintf("Unable to cd up\n%s",FtpLastResponse(conn));
457 msg.replace(QRegExp(":"),"\n");
438 QMessageBox::message("Note",msg); 458 QMessageBox::message("Note",msg);
459 qDebug(msg);
439 } 460 }
440 char path[256]; 461 char path[256];
441 if( FtpPwd( path,sizeof(path),conn) == 0) { 462 if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string
442 QString msg; 463 QString msg;
443 msg.sprintf("Unable to get working dir\n%s",FtpLastResponse(conn)); 464 msg.sprintf("Unable to get working dir\n%s",FtpLastResponse(conn));
465 msg.replace(QRegExp(":"),"\n");
444 QMessageBox::message("Note",msg); 466 QMessageBox::message("Note",msg);
467 qDebug(msg);
445 } 468 }
446 currentRemoteDir=path; 469 currentRemoteDir=path;
447 } else { 470 } else {
448 if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers 471 if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers
449 strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE)-3 ); 472 strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 );
450 strItem = strItem.stripWhiteSpace(); 473 strItem = strItem.stripWhiteSpace();
451 currentRemoteDir = strItem; 474 currentRemoteDir = strItem;
452 if( remoteChDir( (const QString &)strItem) ==0) { 475 if( !remoteChDir( (const QString &)strItem)) {
453 QString msg; 476 currentRemoteDir = oldRemoteCurrentDir;
454 msg.sprintf("Unable to change directories \n%s",FtpLastResponse(conn)); 477 strItem="";
455 QMessageBox::message("Note",msg); 478 populateRemoteView();
456 } 479 qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir);
457 } else if(strItem.find("/",0,TRUE) != -1) {
458 if( remoteChDir( (const QString &)currentRemoteDir+strItem) ==0) {
459 QString msg;
460 msg.sprintf("Unable to change directories \n%s",FtpLastResponse(conn));
461 QMessageBox::message("Note",msg);
462 } 480 }
481 } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory
482 qDebug("trying directory");
483 if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) {
484 currentRemoteDir = oldRemoteCurrentDir;
485 strItem="";
486 qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir);
487
488 populateRemoteView();
489 } else {
463 currentRemoteDir = currentRemoteDir+strItem; 490 currentRemoteDir = currentRemoteDir+strItem;
491 }
464 } else { 492 } else {
465 qDebug("download "+strItem); 493 qDebug("download "+strItem);
466 } 494 }
@@ -479,7 +507,7 @@ void OpieFtp::remoteListClicked(QListViewItem *selectedItem)
479 strSize=strSize.stripWhiteSpace(); 507 strSize=strSize.stripWhiteSpace();
480 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 508 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
481 // is symlink 509 // is symlink
482 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 510 QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4);
483 if(QDir(strItem2).exists() ) { 511 if(QDir(strItem2).exists() ) {
484 currentDir.cd(strItem2, TRUE); 512 currentDir.cd(strItem2, TRUE);
485 populateLocalView(); 513 populateLocalView();
@@ -627,6 +655,7 @@ void OpieFtp::remoteMakDir()
627 if(FtpMkdir( tmp.latin1(), conn) == 0) { 655 if(FtpMkdir( tmp.latin1(), conn) == 0) {
628 QString msg; 656 QString msg;
629 msg.sprintf("Unable to make directory\n%s",FtpLastResponse(conn)); 657 msg.sprintf("Unable to make directory\n%s",FtpLastResponse(conn));
658 msg.replace(QRegExp(":"),"\n");
630 QMessageBox::message("Note",msg); 659 QMessageBox::message("Note",msg);
631 } 660 }
632 QCopEnvelope ( "QPE/System", "notBusy()" ); 661 QCopEnvelope ( "QPE/System", "notBusy()" );
@@ -647,6 +676,7 @@ void OpieFtp::remoteDelete()
647 if(FtpRmdir( path.latin1(), conn) ==0) { 676 if(FtpRmdir( path.latin1(), conn) ==0) {
648 QString msg; 677 QString msg;
649 msg.sprintf("Unable to remove directory\n%s",FtpLastResponse(conn)); 678 msg.sprintf("Unable to remove directory\n%s",FtpLastResponse(conn));
679 msg.replace(QRegExp(":"),"\n");
650 QMessageBox::message("Note",msg); 680 QMessageBox::message("Note",msg);
651 } 681 }
652 } 682 }
@@ -660,6 +690,7 @@ void OpieFtp::remoteDelete()
660 if(FtpDelete( path.latin1(), conn)==0) { 690 if(FtpDelete( path.latin1(), conn)==0) {
661 QString msg; 691 QString msg;
662 msg.sprintf("Unable to delete file\n%s",FtpLastResponse(conn)); 692 msg.sprintf("Unable to delete file\n%s",FtpLastResponse(conn));
693 msg.replace(QRegExp(":"),"\n");
663 QMessageBox::message("Note",msg); 694 QMessageBox::message("Note",msg);
664 } 695 }
665 } 696 }
@@ -683,6 +714,7 @@ void OpieFtp::remoteRename()
683 if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { 714 if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) {
684 QString msg; 715 QString msg;
685 msg.sprintf("Unable to rename file\n%s",FtpLastResponse(conn)); 716 msg.sprintf("Unable to rename file\n%s",FtpLastResponse(conn));
717 msg.replace(QRegExp(":"),"\n");
686 QMessageBox::message("Note",msg); 718 QMessageBox::message("Note",msg);
687 } 719 }
688 QCopEnvelope ( "QPE/System", "notBusy()" ); 720 QCopEnvelope ( "QPE/System", "notBusy()" );
@@ -708,6 +740,8 @@ void OpieFtp::localRename()
708 740
709void OpieFtp::currentPathEditChanged() 741void OpieFtp::currentPathEditChanged()
710{ 742{
743 QString oldRemoteCurrentDir = currentRemoteDir;
744 qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir);
711 if (TabWidget->currentPageIndex() == 0) { 745 if (TabWidget->currentPageIndex() == 0) {
712 if(QDir( currentPathEdit->text()).exists()) { 746 if(QDir( currentPathEdit->text()).exists()) {
713 currentDir.setPath( currentPathEdit->text() ); 747 currentDir.setPath( currentPathEdit->text() );
@@ -722,7 +756,11 @@ void OpieFtp::currentPathEditChanged()
722 currentRemoteDir = currentRemoteDir +"/"; 756 currentRemoteDir = currentRemoteDir +"/";
723 currentPathEdit->setText( currentRemoteDir ); 757 currentPathEdit->setText( currentRemoteDir );
724 } 758 }
725 remoteChDir( (const QString &)currentRemoteDir); 759 if( !remoteChDir( (const QString &)currentRemoteDir) ) {
760 currentRemoteDir = oldRemoteCurrentDir;
761 currentPathEdit->setText( currentRemoteDir );
762 }
763
726 remoteDirList( (const QString &)currentRemoteDir); 764 remoteDirList( (const QString &)currentRemoteDir);
727 } 765 }
728} 766}