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
@@ -31,24 +31,25 @@
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qmainwindow.h> 32#include <qmainwindow.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qprogressbar.h> 34#include <qprogressbar.h>
35#include <qspinbox.h> 35#include <qspinbox.h>
36#include <qtabwidget.h> 36#include <qtabwidget.h>
37#include <qwidget.h> 37#include <qwidget.h>
38#include <qlayout.h> 38#include <qlayout.h>
39#include <qimage.h> 39#include <qimage.h>
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>
46 47
47QProgressBar *ProgressBar; 48QProgressBar *ProgressBar;
48static netbuf *conn=NULL; 49static netbuf *conn=NULL;
49 50
50static int log_progress(netbuf *ctl, int xfered, void *arg) 51static int log_progress(netbuf *ctl, int xfered, void *arg)
51{ 52{
52 int fsz = *(int *)arg; 53 int fsz = *(int *)arg;
53 int pct = (xfered * 100) / fsz; 54 int pct = (xfered * 100) / fsz;
54// printf("%3d%%\r", pct); 55// printf("%3d%%\r", pct);
@@ -136,56 +137,57 @@ OpieFtp::OpieFtp( )
136 this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); 137 this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) );
137 138
138 TabWidget->insertTab( tab_2, tr( "Remote" ) ); 139 TabWidget->insertTab( tab_2, tr( "Remote" ) );
139 140
140 tab_3 = new QWidget( TabWidget, "tab_3" ); 141 tab_3 = new QWidget( TabWidget, "tab_3" );
141 142
142 TextLabel1 = new QLabel( tab_3, "TextLabel1" ); 143 TextLabel1 = new QLabel( tab_3, "TextLabel1" );
143 TextLabel1->setGeometry( QRect( 10, 10, 60, 16 ) ); 144 TextLabel1->setGeometry( QRect( 10, 10, 60, 16 ) );
144 TextLabel1->setText( tr( "Username" ) ); 145 TextLabel1->setText( tr( "Username" ) );
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 ) );
152 TextLabel2->setText( tr( "Password" ) ); 153 TextLabel2->setText( tr( "Password" ) );
153 PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); 154 PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" );
154 PasswordEdit->setGeometry( QRect( 10, 65, 195, 16 ) ); 155 PasswordEdit->setGeometry( QRect( 10, 65, 195, 16 ) );
155 PasswordEdit->setEchoMode(QLineEdit::Password); 156 PasswordEdit->setEchoMode(QLineEdit::Password);
156 157
157 TextLabel3 = new QLabel( tab_3, "TextLabel3" ); 158 TextLabel3 = new QLabel( tab_3, "TextLabel3" );
158 TextLabel3->setGeometry( QRect( 10, 90, 95, 16 ) ); 159 TextLabel3->setGeometry( QRect( 10, 90, 95, 16 ) );
159 TextLabel3->setText( tr( "Remote server" ) ); 160 TextLabel3->setText( tr( "Remote server" ) );
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 ) );
174 TextLabel4->setText( tr( "Port" ) ); 175 TextLabel4->setText( tr( "Port" ) );
175 PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); 176 PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" );
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 *)),
183 this,SLOT(tabChanged(QWidget*))); 185 this,SLOT(tabChanged(QWidget*)));
184 186
185 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 187 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
186 currentDir.setPath( QDir::currentDirPath()); 188 currentDir.setPath( QDir::currentDirPath());
187// currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 189// currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
188 currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" ); 190 currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" );
189 currentPathEdit->setGeometry( QRect( 5, 248, 220, 18 ) ); 191 currentPathEdit->setGeometry( QRect( 5, 248, 220, 18 ) );
190 currentPathEdit->setText( currentDir.canonicalPath()); 192 currentPathEdit->setText( currentDir.canonicalPath());
191 connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged())); 193 connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged()));
@@ -217,75 +219,87 @@ void OpieFtp::tabChanged(QWidget *w)
217} 219}
218 220
219void OpieFtp::localUpload() 221void OpieFtp::localUpload()
220{ 222{
221 int fsz; 223 int fsz;
222 QCopEnvelope ( "QPE/System", "busy()" ); 224 QCopEnvelope ( "QPE/System", "busy()" );
223 qApp->processEvents(); 225 qApp->processEvents();
224 QString strItem = Local_View->currentItem()->text(0); 226 QString strItem = Local_View->currentItem()->text(0);
225 QString localFile = currentDir.canonicalPath()+"/"+strItem; 227 QString localFile = currentDir.canonicalPath()+"/"+strItem;
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 }
248 TabWidget->setCurrentPage(1); 252 TabWidget->setCurrentPage(1);
249 populateRemoteView(); 253 populateRemoteView();
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;
256 QCopEnvelope ( "QPE/System", "busy()" ); 268 QCopEnvelope ( "QPE/System", "busy()" );
257 qApp->processEvents(); 269 qApp->processEvents();
258 QString strItem = Remote_View->currentItem()->text(0); 270 QString strItem = Remote_View->currentItem()->text(0);
259 QString localFile = currentDir.canonicalPath()+"/"+strItem; 271 QString localFile = currentDir.canonicalPath()+"/"+strItem;
260 QString remoteFile= currentRemoteDir+strItem; 272 QString remoteFile= currentRemoteDir+strItem;
261 if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) 273 if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn))
262 fsz = 0; 274 fsz = 0;
263 QString temp; 275 QString temp;
264 temp.sprintf( remoteFile+" "+" %dkb", fsz); 276 temp.sprintf( remoteFile+" "+" %dkb", fsz);
265 277
266 ProgressBar->setTotalSteps(fsz); 278 ProgressBar->setTotalSteps(fsz);
267 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); 279 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
268 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); 280 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
269 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); 281 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
270 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); 282 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
271 qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); 283 qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1());
272 284
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()" );
283} 297}
284 298
285 299
286void OpieFtp::newConnection() 300void OpieFtp::newConnection()
287{ 301{
288 TabWidget->setCurrentPage(2); 302 TabWidget->setCurrentPage(2);
289} 303}
290 304
291void OpieFtp::connector() 305void OpieFtp::connector()
@@ -308,64 +322,68 @@ void OpieFtp::connector()
308 port.stripWhiteSpace(); 322 port.stripWhiteSpace();
309 323
310 if(ftp_host.find("ftp://",0, TRUE) != -1 ) 324 if(ftp_host.find("ftp://",0, TRUE) != -1 )
311 ftp_host=ftp_host.right(ftp_host.length()-6); 325 ftp_host=ftp_host.right(ftp_host.length()-6);
312 ftp_host+=":"+port; 326 ftp_host+=":"+port;
313 if (!FtpConnect( ftp_host.latin1(), &conn)) { 327 if (!FtpConnect( ftp_host.latin1(), &conn)) {
314 QMessageBox::message("Note","Unable to connect to\n"+ftp_host); 328 QMessageBox::message("Note","Unable to connect to\n"+ftp_host);
315 return ; 329 return ;
316 } 330 }
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 ;
323 } 338 }
324 remoteDirList("/") ; 339 remoteDirList("/") ;
325 setCaption(ftp_host); 340 setCaption(ftp_host);
326 QCopEnvelope ( "QPE/System", "notBusy()" ); 341 QCopEnvelope ( "QPE/System", "notBusy()" );
327} 342}
328 343
329void OpieFtp::disConnector() 344void OpieFtp::disConnector()
330{ 345{
331 FtpQuit(conn); 346 FtpQuit(conn);
332 setCaption("OpieFtp"); 347 setCaption("OpieFtp");
333 currentRemoteDir="/"; 348 currentRemoteDir="/";
334 Remote_View->clear(); 349 Remote_View->clear();
335} 350}
336 351
337bool OpieFtp::remoteDirList(const QString &dir) 352bool OpieFtp::remoteDirList(const QString &dir)
338{ 353{
339 QCopEnvelope ( "QPE/System", "busy()" ); 354 QCopEnvelope ( "QPE/System", "busy()" );
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();
348 QCopEnvelope ( "QPE/System", "notBusy()" ); 364 QCopEnvelope ( "QPE/System", "notBusy()" );
349 return true; 365 return true;
350} 366}
351 367
352bool OpieFtp::remoteChDir(const QString &dir) 368bool OpieFtp::remoteChDir(const QString &dir)
353{ 369{
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 }
363 QCopEnvelope ( "QPE/System", "notBusy()" ); 381 QCopEnvelope ( "QPE/System", "notBusy()" );
364 return TRUE; 382 return TRUE;
365} 383}
366 384
367void OpieFtp::populateLocalView() 385void OpieFtp::populateLocalView()
368{ 386{
369 Local_View->clear(); 387 Local_View->clear();
370 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 388 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
371 currentDir.setMatchAllDirs(TRUE); 389 currentDir.setMatchAllDirs(TRUE);
@@ -420,75 +438,85 @@ bool OpieFtp::populateRemoteView()
420 fileDate = fileDate.stripWhiteSpace(); 438 fileDate = fileDate.stripWhiteSpace();
421 if(fileL.find("total",0,TRUE) == -1) 439 if(fileL.find("total",0,TRUE) == -1)
422 new QListViewItem( Remote_View, fileL, fileS, fileDate); 440 new QListViewItem( Remote_View, fileL, fileS, fileDate);
423 } 441 }
424 tmp.close(); 442 tmp.close();
425 } 443 }
426 return true; 444 return true;
427} 445}
428 446
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 }
467 } 495 }
468 if(currentRemoteDir.right(1) !="/") 496 if(currentRemoteDir.right(1) !="/")
469 currentRemoteDir +="/"; 497 currentRemoteDir +="/";
470 currentPathEdit->setText( currentRemoteDir ); 498 currentPathEdit->setText( currentRemoteDir );
471 remoteDirList( (const QString &)currentRemoteDir); 499 remoteDirList( (const QString &)currentRemoteDir);
472 QCopEnvelope ( "QPE/System", "notBusy()" ); 500 QCopEnvelope ( "QPE/System", "notBusy()" );
473} 501}
474 502
475 void OpieFtp::localListClicked(QListViewItem *selectedItem) 503 void OpieFtp::localListClicked(QListViewItem *selectedItem)
476{ 504{
477 QString strItem=selectedItem->text(0); 505 QString strItem=selectedItem->text(0);
478 QString strSize=selectedItem->text(1); 506 QString strSize=selectedItem->text(1);
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();
486 } 514 }
487 } else { // not a symlink 515 } else { // not a symlink
488 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 516 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
489 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 517 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
490 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 518 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
491 currentDir.cd(strItem,FALSE); 519 currentDir.cd(strItem,FALSE);
492 populateLocalView(); 520 populateLocalView();
493 } else { 521 } else {
494 currentDir.cdUp(); 522 currentDir.cdUp();
@@ -618,80 +646,84 @@ void OpieFtp::localDelete()
618void OpieFtp::remoteMakDir() 646void OpieFtp::remoteMakDir()
619{ 647{
620 InputDialog *fileDlg; 648 InputDialog *fileDlg;
621 fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); 649 fileDlg = new InputDialog(this,"Make Directory",TRUE, 0);
622 fileDlg->exec(); 650 fileDlg->exec();
623 if( fileDlg->result() == 1 ) { 651 if( fileDlg->result() == 1 ) {
624 QString filename = fileDlg->LineEdit1->text();//+".playlist"; 652 QString filename = fileDlg->LineEdit1->text();//+".playlist";
625 QString tmp=currentRemoteDir+filename; 653 QString tmp=currentRemoteDir+filename;
626 QCopEnvelope ( "QPE/System", "busy()" ); 654 QCopEnvelope ( "QPE/System", "busy()" );
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()" );
633 } 662 }
634 populateRemoteView(); 663 populateRemoteView();
635} 664}
636 665
637void OpieFtp::remoteDelete() 666void OpieFtp::remoteDelete()
638{ 667{
639 QString f = Remote_View->currentItem()->text(0); 668 QString f = Remote_View->currentItem()->text(0);
640 QCopEnvelope ( "QPE/System", "busy()" ); 669 QCopEnvelope ( "QPE/System", "busy()" );
641 if( f.right(1) =="/") { 670 if( f.right(1) =="/") {
642 QString path= currentRemoteDir+f; 671 QString path= currentRemoteDir+f;
643 switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" 672 switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?"
644 ,"Yes","No",0,0,1) ) { 673 ,"Yes","No",0,0,1) ) {
645 case 0: { 674 case 0: {
646 f=currentDir.canonicalPath()+"/"+f; 675 f=currentDir.canonicalPath()+"/"+f;
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 }
653 break; 683 break;
654 }; 684 };
655 } else { 685 } else {
656 switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" 686 switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?"
657 ,"Yes","No",0,0,1) ) { 687 ,"Yes","No",0,0,1) ) {
658 case 0: { 688 case 0: {
659 QString path= currentRemoteDir+f; 689 QString path= currentRemoteDir+f;
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 }
666 break; 697 break;
667 }; 698 };
668 } 699 }
669 QCopEnvelope ( "QPE/System", "notBusy()" ); 700 QCopEnvelope ( "QPE/System", "notBusy()" );
670} 701}
671 702
672void OpieFtp::remoteRename() 703void OpieFtp::remoteRename()
673{ 704{
674 QString curFile = Remote_View->currentItem()->text(0); 705 QString curFile = Remote_View->currentItem()->text(0);
675 InputDialog *fileDlg; 706 InputDialog *fileDlg;
676 fileDlg = new InputDialog(this,"Rename",TRUE, 0); 707 fileDlg = new InputDialog(this,"Rename",TRUE, 0);
677 fileDlg->inputText = curFile; 708 fileDlg->inputText = curFile;
678 fileDlg->exec(); 709 fileDlg->exec();
679 if( fileDlg->result() == 1 ) { 710 if( fileDlg->result() == 1 ) {
680 QString oldName = currentRemoteDir +"/"+ curFile; 711 QString oldName = currentRemoteDir +"/"+ curFile;
681 QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; 712 QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist";
682 QCopEnvelope ( "QPE/System", "busy()" ); 713 QCopEnvelope ( "QPE/System", "busy()" );
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()" );
689 } 721 }
690 populateRemoteView(); 722 populateRemoteView();
691} 723}
692 724
693void OpieFtp::localRename() 725void OpieFtp::localRename()
694{ 726{
695 QString curFile = Local_View->currentItem()->text(0); 727 QString curFile = Local_View->currentItem()->text(0);
696 InputDialog *fileDlg; 728 InputDialog *fileDlg;
697 fileDlg = new InputDialog(this,"Rename",TRUE, 0); 729 fileDlg = new InputDialog(this,"Rename",TRUE, 0);
@@ -699,30 +731,36 @@ void OpieFtp::localRename()
699 fileDlg->exec(); 731 fileDlg->exec();
700 if( fileDlg->result() == 1 ) { 732 if( fileDlg->result() == 1 ) {
701 QString oldname = currentDir.canonicalPath() + "/" + curFile; 733 QString oldname = currentDir.canonicalPath() + "/" + curFile;
702 QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; 734 QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist";
703 if( rename(oldname.latin1(), newName.latin1())== -1) 735 if( rename(oldname.latin1(), newName.latin1())== -1)
704 QMessageBox::message("Note","Could not rename"); 736 QMessageBox::message("Note","Could not rename");
705 } 737 }
706 populateLocalView(); 738 populateLocalView();
707} 739}
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() );
714 populateLocalView(); 748 populateLocalView();
715 } else { 749 } else {
716 QMessageBox::message("Note","That directory does not exist"); 750 QMessageBox::message("Note","That directory does not exist");
717 } 751 }
718 } 752 }
719 if (TabWidget->currentPageIndex() == 1) { 753 if (TabWidget->currentPageIndex() == 1) {
720 currentRemoteDir = currentPathEdit->text(); 754 currentRemoteDir = currentPathEdit->text();
721 if(currentRemoteDir.right(1) !="/") { 755 if(currentRemoteDir.right(1) !="/") {
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}