author | llornkcor <llornkcor> | 2002-03-12 01:17:36 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-12 01:17:36 (UTC) |
commit | 3e450bfc664c55e1e185953ba47e83f2b981ee68 (patch) (unidiff) | |
tree | 684808759ad7c60ee273c1832925da4231da05af /noncore/net/opieftp/opieftp.cpp | |
parent | 13b87f9eb4c51c43dc127b7fbce2ccdbf0353da2 (diff) | |
download | opie-3e450bfc664c55e1e185953ba47e83f2b981ee68.zip opie-3e450bfc664c55e1e185953ba47e83f2b981ee68.tar.gz opie-3e450bfc664c55e1e185953ba47e83f2b981ee68.tar.bz2 |
added opieftp- the opief tp client
Diffstat (limited to 'noncore/net/opieftp/opieftp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 719 |
1 files changed, 719 insertions, 0 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp new file mode 100644 index 0000000..151be84 --- a/dev/null +++ b/noncore/net/opieftp/opieftp.cpp | |||
@@ -0,0 +1,719 @@ | |||
1 | /*************************************************************************** | ||
2 | opieftp.cpp | ||
3 | ------------------- | ||
4 | ** Created: Sat Mar 9 23:33:09 2002 | ||
5 | copyright : (C) 2002 by ljp | ||
6 | email : ljp@llornkcor.com | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | ||
12 | |||
13 | #include "opieftp.h" | ||
14 | #include "ftplib.h" | ||
15 | #include "inputDialog.h" | ||
16 | |||
17 | #include <qpe/qpemenubar.h> | ||
18 | #include <qpe/qpetoolbar.h> | ||
19 | #include <qpe/qpeapplication.h> | ||
20 | #include <qpe/resource.h> | ||
21 | #include <qpe/qcopenvelope_qws.h> | ||
22 | |||
23 | #include <qtextstream.h> | ||
24 | #include <qtoolbutton.h> | ||
25 | #include <qdatetime.h> | ||
26 | #include <qdir.h> | ||
27 | #include <qfile.h> | ||
28 | #include <qstring.h> | ||
29 | #include <qcombobox.h> | ||
30 | #include <qpopupmenu.h> | ||
31 | #include <qlistview.h> | ||
32 | #include <qmainwindow.h> | ||
33 | #include <qlabel.h> | ||
34 | #include <qprogressbar.h> | ||
35 | #include <qspinbox.h> | ||
36 | #include <qtabwidget.h> | ||
37 | #include <qwidget.h> | ||
38 | #include <qlayout.h> | ||
39 | #include <qimage.h> | ||
40 | #include <qpixmap.h> | ||
41 | #include <qmessagebox.h> | ||
42 | #include <qlineedit.h> | ||
43 | |||
44 | #include <unistd.h> | ||
45 | #include <stdlib.h> | ||
46 | |||
47 | QProgressBar *ProgressBar; | ||
48 | static netbuf *conn=NULL; | ||
49 | |||
50 | static int log_progress(netbuf *ctl, int xfered, void *arg) | ||
51 | { | ||
52 | int fsz = *(int *)arg; | ||
53 | int pct = (xfered * 100) / fsz; | ||
54 | // printf("%3d%%\r", pct); | ||
55 | // fflush(stdout); | ||
56 | ProgressBar->setProgress(xfered); | ||
57 | qApp->processEvents(); | ||
58 | return 1; | ||
59 | } | ||
60 | |||
61 | OpieFtp::OpieFtp( ) | ||
62 | : QMainWindow( ) | ||
63 | { | ||
64 | resize( 236, 290 ); | ||
65 | setMaximumSize( QSize( 240, 320 ) ); | ||
66 | setCaption( tr( "OpieFtp" ) ); | ||
67 | |||
68 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | ||
69 | |||
70 | QPEMenuBar *menuBar = new QPEMenuBar( this ); | ||
71 | connectionMenu = new QPopupMenu( this ); | ||
72 | localMenu = new QPopupMenu( this ); | ||
73 | remoteMenu = new QPopupMenu( this ); | ||
74 | menuBar->insertItem( tr( "Connection" ), connectionMenu); | ||
75 | menuBar->insertItem( tr( "Local" ), localMenu); | ||
76 | menuBar->insertItem( tr( "Remote" ), remoteMenu); | ||
77 | |||
78 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); | ||
79 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); | ||
80 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); | ||
81 | |||
82 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | ||
83 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | ||
84 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | ||
85 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | ||
86 | localMenu->insertSeparator(); | ||
87 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | ||
88 | |||
89 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | ||
90 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | ||
91 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | ||
92 | remoteMenu->insertSeparator(); | ||
93 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | ||
94 | |||
95 | ProgressBar = new QProgressBar( this, "ProgressBar" ); | ||
96 | ProgressBar->setGeometry( QRect( 5, 268, 231, 15 ) ); | ||
97 | |||
98 | TabWidget = new QTabWidget( this, "TabWidget2" ); | ||
99 | TabWidget->setGeometry( QRect( 3, 25, 240, 220 ) ); | ||
100 | TabWidget->setTabShape(QTabWidget::Triangular); | ||
101 | |||
102 | tab = new QWidget( TabWidget, "tab" ); | ||
103 | |||
104 | Local_View = new QListView( tab, "Local_View" ); | ||
105 | Local_View->setGeometry( QRect( 3, 2, 225, 195 ) ); | ||
106 | Local_View->addColumn( "File",120); | ||
107 | Local_View->addColumn( "Size",-1); | ||
108 | Local_View->setColumnAlignment(1,QListView::AlignRight); | ||
109 | Local_View->addColumn( "Date",-1); | ||
110 | Local_View->setColumnAlignment(2,QListView::AlignRight); | ||
111 | Local_View->setAllColumnsShowFocus(TRUE); | ||
112 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); | ||
113 | |||
114 | connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), | ||
115 | this,SLOT( localListClicked(QListViewItem *)) ); | ||
116 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
117 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
118 | |||
119 | TabWidget->insertTab( tab, tr( "Local" ) ); | ||
120 | |||
121 | tab_2 = new QWidget( TabWidget, "tab_2" ); | ||
122 | |||
123 | Remote_View = new QListView( tab_2, "Remote_View" ); | ||
124 | Remote_View->setGeometry( QRect( 3, 2, 225, 195 ) ); | ||
125 | Remote_View->addColumn( "File",120); | ||
126 | Remote_View->addColumn( "Size",-1); | ||
127 | Remote_View->setColumnAlignment(1,QListView::AlignRight); | ||
128 | Remote_View->addColumn( "Date",-1); | ||
129 | Remote_View->setColumnAlignment(2,QListView::AlignRight); | ||
130 | Remote_View->setAllColumnsShowFocus(TRUE); | ||
131 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); | ||
132 | |||
133 | connect( Remote_View, SIGNAL( doubleClicked( QListViewItem*)), | ||
134 | this,SLOT( remoteListClicked(QListViewItem *)) ); | ||
135 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
136 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
137 | |||
138 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); | ||
139 | |||
140 | tab_3 = new QWidget( TabWidget, "tab_3" ); | ||
141 | |||
142 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); | ||
143 | TextLabel1->setGeometry( QRect( 10, 10, 60, 16 ) ); | ||
144 | TextLabel1->setText( tr( "Username" ) ); | ||
145 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); | ||
146 | UsernameComboBox->setGeometry( QRect( 10, 25, 196, 21 ) ); | ||
147 | UsernameComboBox->setEditable(TRUE); | ||
148 | UsernameComboBox->lineEdit()->setText("root"); | ||
149 | |||
150 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); | ||
151 | TextLabel2->setGeometry( QRect( 10, 50, 65, 16 ) ); | ||
152 | TextLabel2->setText( tr( "Password" ) ); | ||
153 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); | ||
154 | PasswordEdit->setGeometry( QRect( 10, 65, 195, 16 ) ); | ||
155 | PasswordEdit->setEchoMode(QLineEdit::Password); | ||
156 | |||
157 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); | ||
158 | TextLabel3->setGeometry( QRect( 10, 90, 95, 16 ) ); | ||
159 | TextLabel3->setText( tr( "Remote server" ) ); | ||
160 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); | ||
161 | ServerComboBox->setGeometry( QRect( 10, 105, 195, 21 ) ); | ||
162 | ServerComboBox->setEditable(TRUE); | ||
163 | ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); | ||
164 | |||
165 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); | ||
166 | TextLabel5->setGeometry( QRect( 10, 130, 95, 16 ) ); | ||
167 | TextLabel5->setText( tr( "Remote path" ) ); | ||
168 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); | ||
169 | remotePath->setGeometry( QRect( 10, 145, 195, 16 ) ); | ||
170 | remotePath->setText( currentRemoteDir = "/"); | ||
171 | |||
172 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); | ||
173 | TextLabel4->setGeometry( QRect( 10, 170, 30, 21 ) ); | ||
174 | TextLabel4->setText( tr( "Port" ) ); | ||
175 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); | ||
176 | PortSpinBox->setGeometry( QRect( 40, 175, 75, 20 ) ); | ||
177 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); | ||
178 | PortSpinBox->setMaxValue(32786); | ||
179 | PortSpinBox->setValue( 4242 ); | ||
180 | TabWidget->insertTab( tab_3, tr( "Config" ) ); | ||
181 | |||
182 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), | ||
183 | this,SLOT(tabChanged(QWidget*))); | ||
184 | |||
185 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
186 | currentDir.setPath( QDir::currentDirPath()); | ||
187 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
188 | currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" ); | ||
189 | currentPathEdit->setGeometry( QRect( 5, 248, 220, 18 ) ); | ||
190 | currentPathEdit->setText( currentDir.canonicalPath()); | ||
191 | connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged())); | ||
192 | |||
193 | filterStr="*"; | ||
194 | populateLocalView(); | ||
195 | } | ||
196 | |||
197 | OpieFtp::~OpieFtp() | ||
198 | { | ||
199 | } | ||
200 | |||
201 | void OpieFtp::cleanUp() | ||
202 | { | ||
203 | if(conn) | ||
204 | FtpQuit(conn); | ||
205 | QFile f("./._temp"); | ||
206 | if(f.exists()) | ||
207 | f. remove(); | ||
208 | } | ||
209 | |||
210 | void OpieFtp::tabChanged(QWidget *w) | ||
211 | { | ||
212 | if (TabWidget->currentPageIndex() == 0) { | ||
213 | currentPathEdit->setText( currentDir.canonicalPath()); | ||
214 | } else if (TabWidget->currentPageIndex() == 1) { | ||
215 | currentPathEdit->setText( currentRemoteDir ); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | void OpieFtp::localUpload() | ||
220 | { | ||
221 | int fsz; | ||
222 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
223 | qApp->processEvents(); | ||
224 | QString strItem = Local_View->currentItem()->text(0); | ||
225 | QString localFile = currentDir.canonicalPath()+"/"+strItem; | ||
226 | QString remoteFile= currentRemoteDir+strItem; | ||
227 | QFileInfo fi(localFile); | ||
228 | if( !fi.isDir()) { | ||
229 | fsz=fi.size(); | ||
230 | ProgressBar->setTotalSteps(fsz); | ||
231 | |||
232 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | ||
233 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | ||
234 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | ||
235 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | ||
236 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); | ||
237 | |||
238 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | ||
239 | QString msg; | ||
240 | msg.sprintf("Unable to upload\n%s",FtpLastResponse(conn)); | ||
241 | QMessageBox::message("Note",msg); | ||
242 | FtpQuit(conn); | ||
243 | } | ||
244 | ProgressBar->reset(); | ||
245 | } else { | ||
246 | QMessageBox::message("Note","Cannot upload directories"); | ||
247 | } | ||
248 | TabWidget->setCurrentPage(1); | ||
249 | populateRemoteView(); | ||
250 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
251 | } | ||
252 | |||
253 | void OpieFtp::remoteDownload() | ||
254 | { | ||
255 | int fsz; | ||
256 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
257 | qApp->processEvents(); | ||
258 | QString strItem = Remote_View->currentItem()->text(0); | ||
259 | QString localFile = currentDir.canonicalPath()+"/"+strItem; | ||
260 | QString remoteFile= currentRemoteDir+strItem; | ||
261 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) | ||
262 | fsz = 0; | ||
263 | QString temp; | ||
264 | temp.sprintf( remoteFile+" "+" %dkb", fsz); | ||
265 | |||
266 | ProgressBar->setTotalSteps(fsz); | ||
267 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | ||
268 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | ||
269 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | ||
270 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | ||
271 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); | ||
272 | |||
273 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | ||
274 | QString msg; | ||
275 | msg.sprintf("Unable to download \n%s",FtpLastResponse(conn)); | ||
276 | QMessageBox::message("Note",msg); | ||
277 | FtpQuit(conn); | ||
278 | } | ||
279 | ProgressBar->reset(); | ||
280 | TabWidget->setCurrentPage(0); | ||
281 | populateLocalView(); | ||
282 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
283 | } | ||
284 | |||
285 | |||
286 | void OpieFtp::newConnection() | ||
287 | { | ||
288 | TabWidget->setCurrentPage(2); | ||
289 | } | ||
290 | |||
291 | void OpieFtp::connector() | ||
292 | { | ||
293 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
294 | qApp->processEvents(); | ||
295 | currentRemoteDir=remotePath->text(); | ||
296 | if(ServerComboBox->currentText().isEmpty()) { | ||
297 | QMessageBox::warning(this,"Ftp","Please set the server info","Ok",0,0); | ||
298 | TabWidget->setCurrentPage(2); | ||
299 | ServerComboBox->setFocus(); | ||
300 | return; | ||
301 | } | ||
302 | FtpInit(); | ||
303 | TabWidget->setCurrentPage(1); | ||
304 | QString ftp_host = ServerComboBox->currentText(); | ||
305 | QString ftp_user = UsernameComboBox->currentText(); | ||
306 | QString ftp_pass = PasswordEdit->text(); | ||
307 | QString port=PortSpinBox->cleanText(); | ||
308 | port.stripWhiteSpace(); | ||
309 | |||
310 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) | ||
311 | ftp_host=ftp_host.right(ftp_host.length()-6); | ||
312 | ftp_host+=":"+port; | ||
313 | if (!FtpConnect( ftp_host.latin1(), &conn)) { | ||
314 | QMessageBox::message("Note","Unable to connect to\n"+ftp_host); | ||
315 | return ; | ||
316 | } | ||
317 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { | ||
318 | QString msg; | ||
319 | msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn)); | ||
320 | QMessageBox::message("Note",msg); | ||
321 | FtpQuit(conn); | ||
322 | return ; | ||
323 | } | ||
324 | remoteDirList("/") ; | ||
325 | setCaption(ftp_host); | ||
326 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
327 | } | ||
328 | |||
329 | void OpieFtp::disConnector() | ||
330 | { | ||
331 | FtpQuit(conn); | ||
332 | setCaption("OpieFtp"); | ||
333 | currentRemoteDir="/"; | ||
334 | Remote_View->clear(); | ||
335 | } | ||
336 | |||
337 | bool OpieFtp::remoteDirList(const QString &dir) | ||
338 | { | ||
339 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
340 | if (!FtpDir( "./._temp", dir.latin1(), conn) ) { | ||
341 | QString msg; | ||
342 | msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn) ); | ||
343 | QMessageBox::message("Note",msg); | ||
344 | FtpQuit(conn); | ||
345 | return false; | ||
346 | } | ||
347 | populateRemoteView(); | ||
348 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
349 | return true; | ||
350 | } | ||
351 | |||
352 | bool OpieFtp::remoteChDir(const QString &dir) | ||
353 | { | ||
354 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
355 | if (!FtpChdir( dir.latin1(), conn )) { | ||
356 | QString msg; | ||
357 | msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn)); | ||
358 | QMessageBox::message("Note",msg); | ||
359 | FtpQuit(conn); | ||
360 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
361 | return FALSE; | ||
362 | } | ||
363 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
364 | return TRUE; | ||
365 | } | ||
366 | |||
367 | void OpieFtp::populateLocalView() | ||
368 | { | ||
369 | Local_View->clear(); | ||
370 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
371 | currentDir.setMatchAllDirs(TRUE); | ||
372 | currentDir.setNameFilter(filterStr); | ||
373 | QString fileL, fileS, fileDate; | ||
374 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | ||
375 | QFileInfoListIterator it(*list); | ||
376 | QFileInfo *fi; | ||
377 | while ( (fi=it.current()) ) { | ||
378 | if (fi->isSymLink() ){ | ||
379 | QString symLink=fi->readLink(); | ||
380 | // qDebug("Symlink detected "+symLink); | ||
381 | QFileInfo sym( symLink); | ||
382 | fileS.sprintf( "%10li", sym.size() ); | ||
383 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | ||
384 | fileDate = sym.lastModified().toString(); | ||
385 | } else { | ||
386 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | ||
387 | fileS.sprintf( "%10li", fi->size() ); | ||
388 | fileL.sprintf( "%s",fi->fileName().data() ); | ||
389 | fileDate= fi->lastModified().toString(); | ||
390 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | ||
391 | fileL+="/"; | ||
392 | // qDebug( fileL); | ||
393 | } | ||
394 | } | ||
395 | item= new QListViewItem( Local_View,fileL,fileS, fileDate); | ||
396 | ++it; | ||
397 | } | ||
398 | Local_View->setSorting( 3,FALSE); | ||
399 | currentPathEdit->setText( currentDir.canonicalPath() ); | ||
400 | } | ||
401 | |||
402 | bool OpieFtp::populateRemoteView() | ||
403 | { | ||
404 | Remote_View->clear(); | ||
405 | QFile tmp("./._temp"); | ||
406 | QString s, File_Name; | ||
407 | QString fileL, fileS, fileDate; | ||
408 | new QListViewItem( Remote_View, "../"); | ||
409 | if (tmp.open(IO_ReadOnly)) { | ||
410 | QTextStream t( &tmp ); // use a text stream | ||
411 | while ( !t.eof()) { | ||
412 | s = t.readLine(); | ||
413 | fileL = s.right(s.length()-55); | ||
414 | fileL = fileL.stripWhiteSpace(); | ||
415 | if(s.left(1) == "d") | ||
416 | fileL = fileL+"/"; | ||
417 | fileS = s.mid( 30, 42-30); | ||
418 | fileS = fileS.stripWhiteSpace(); | ||
419 | fileDate = s.mid( 42, 55-42); | ||
420 | fileDate = fileDate.stripWhiteSpace(); | ||
421 | if(fileL.find("total",0,TRUE) == -1) | ||
422 | new QListViewItem( Remote_View, fileL, fileS, fileDate); | ||
423 | } | ||
424 | tmp.close(); | ||
425 | } | ||
426 | return true; | ||
427 | } | ||
428 | |||
429 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) | ||
430 | { | ||
431 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
432 | QString strItem=selectedItem->text(0); | ||
433 | strItem=strItem.simplifyWhiteSpace(); | ||
434 | if(strItem == "../") { | ||
435 | if( FtpCDUp( conn) == 0) { | ||
436 | QString msg; | ||
437 | msg.sprintf("Unable to change directories \n%s",FtpLastResponse(conn)); | ||
438 | QMessageBox::message("Note",msg); | ||
439 | } | ||
440 | char path[256]; | ||
441 | if( FtpPwd( path,sizeof(path),conn) == 0) { | ||
442 | QString msg; | ||
443 | msg.sprintf("Unable to get working dir\n%s",FtpLastResponse(conn)); | ||
444 | QMessageBox::message("Note",msg); | ||
445 | } | ||
446 | currentRemoteDir=path; | ||
447 | } else { | ||
448 | if(strItem.find("/",0,TRUE) != -1) { | ||
449 | if( remoteChDir( (const QString &)currentRemoteDir+strItem) ==0) { | ||
450 | QString msg; | ||
451 | msg.sprintf("Unable to change directories \n%s",FtpLastResponse(conn)); | ||
452 | QMessageBox::message("Note",msg); | ||
453 | } | ||
454 | currentRemoteDir = currentRemoteDir+strItem; | ||
455 | } else { | ||
456 | qDebug("download "+strItem); | ||
457 | } | ||
458 | } | ||
459 | if(currentRemoteDir.right(1) !="/") | ||
460 | currentRemoteDir +="/"; | ||
461 | currentPathEdit->setText( currentRemoteDir ); | ||
462 | remoteDirList( (const QString &)currentRemoteDir); | ||
463 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
464 | } | ||
465 | |||
466 | void OpieFtp::localListClicked(QListViewItem *selectedItem) | ||
467 | { | ||
468 | QString strItem=selectedItem->text(0); | ||
469 | QString strSize=selectedItem->text(1); | ||
470 | strSize=strSize.stripWhiteSpace(); | ||
471 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | ||
472 | // is symlink | ||
473 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | ||
474 | if(QDir(strItem2).exists() ) { | ||
475 | currentDir.cd(strItem2, TRUE); | ||
476 | populateLocalView(); | ||
477 | } | ||
478 | } else { // not a symlink | ||
479 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | ||
480 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | ||
481 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
482 | currentDir.cd(strItem,FALSE); | ||
483 | populateLocalView(); | ||
484 | } else { | ||
485 | currentDir.cdUp(); | ||
486 | populateLocalView(); | ||
487 | } | ||
488 | if(QDir(strItem).exists()){ | ||
489 | currentDir.cd(strItem, TRUE); | ||
490 | populateLocalView(); | ||
491 | } | ||
492 | } else { | ||
493 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
494 | if( QFile::exists(strItem ) ) { | ||
495 | qDebug("upload "+strItem); | ||
496 | } | ||
497 | } //end not symlink | ||
498 | chdir(strItem.latin1()); | ||
499 | } | ||
500 | } | ||
501 | |||
502 | void OpieFtp::showHidden() | ||
503 | { | ||
504 | if (!b) { | ||
505 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | ||
506 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
507 | b=TRUE; | ||
508 | |||
509 | } else { | ||
510 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
511 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
512 | b=FALSE; | ||
513 | } | ||
514 | populateLocalView(); | ||
515 | } | ||
516 | |||
517 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | ||
518 | { | ||
519 | switch (mouse) { | ||
520 | case 1: | ||
521 | break; | ||
522 | case 2: | ||
523 | showLocalMenu(); | ||
524 | break; | ||
525 | }; | ||
526 | } | ||
527 | |||
528 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | ||
529 | { | ||
530 | switch (mouse) { | ||
531 | case 1: | ||
532 | break; | ||
533 | case 2: | ||
534 | showRemoteMenu(); | ||
535 | break; | ||
536 | }; | ||
537 | } | ||
538 | |||
539 | void OpieFtp::showRemoteMenu() | ||
540 | { | ||
541 | QPopupMenu m;// = new QPopupMenu( Local_View ); | ||
542 | m.insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | ||
543 | m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | ||
544 | m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | ||
545 | m.insertSeparator(); | ||
546 | m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | ||
547 | m.exec( QCursor::pos() ); | ||
548 | } | ||
549 | |||
550 | void OpieFtp::showLocalMenu() | ||
551 | { | ||
552 | QPopupMenu m; | ||
553 | m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | ||
554 | m.insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | ||
555 | m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | ||
556 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | ||
557 | m.insertSeparator(); | ||
558 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | ||
559 | m.exec( QCursor::pos() ); | ||
560 | } | ||
561 | |||
562 | void OpieFtp::localMakDir() | ||
563 | { | ||
564 | InputDialog *fileDlg; | ||
565 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | ||
566 | fileDlg->exec(); | ||
567 | if( fileDlg->result() == 1 ) { | ||
568 | QString filename = fileDlg->LineEdit1->text(); | ||
569 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | ||
570 | } | ||
571 | populateLocalView(); | ||
572 | } | ||
573 | |||
574 | void OpieFtp::localDelete() | ||
575 | { | ||
576 | QString f = Local_View->currentItem()->text(0); | ||
577 | if(QDir(f).exists() ) { | ||
578 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ | ||
579 | " ?\nIt must be empty","Yes","No",0,0,1) ) { | ||
580 | case 0: { | ||
581 | f=currentDir.canonicalPath()+"/"+f; | ||
582 | QString cmd="rmdir "+f; | ||
583 | system( cmd.latin1()); | ||
584 | populateLocalView(); | ||
585 | } | ||
586 | break; | ||
587 | case 1: | ||
588 | // exit | ||
589 | break; | ||
590 | }; | ||
591 | |||
592 | } else { | ||
593 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f | ||
594 | +" ?","Yes","No",0,0,1) ) { | ||
595 | case 0: { | ||
596 | f=currentDir.canonicalPath()+"/"+f; | ||
597 | QString cmd="rm "+f; | ||
598 | system( cmd.latin1()); | ||
599 | populateLocalView(); | ||
600 | } | ||
601 | break; | ||
602 | case 1: | ||
603 | // exit | ||
604 | break; | ||
605 | }; | ||
606 | } | ||
607 | } | ||
608 | |||
609 | void OpieFtp::remoteMakDir() | ||
610 | { | ||
611 | InputDialog *fileDlg; | ||
612 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | ||
613 | fileDlg->exec(); | ||
614 | if( fileDlg->result() == 1 ) { | ||
615 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; | ||
616 | QString tmp=currentRemoteDir+filename; | ||
617 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
618 | if(FtpMkdir( tmp.latin1(), conn) == 0) { | ||
619 | QString msg; | ||
620 | msg.sprintf("Unable to make directory\n%s",FtpLastResponse(conn)); | ||
621 | QMessageBox::message("Note",msg); | ||
622 | } | ||
623 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
624 | } | ||
625 | populateRemoteView(); | ||
626 | } | ||
627 | |||
628 | void OpieFtp::remoteDelete() | ||
629 | { | ||
630 | QString f = Remote_View->currentItem()->text(0); | ||
631 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
632 | if( f.right(1) =="/") { | ||
633 | QString path= currentRemoteDir+f; | ||
634 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" | ||
635 | ,"Yes","No",0,0,1) ) { | ||
636 | case 0: { | ||
637 | f=currentDir.canonicalPath()+"/"+f; | ||
638 | if(FtpRmdir( path.latin1(), conn) ==0) { | ||
639 | QString msg; | ||
640 | msg.sprintf("Unable to remove directory\n%s",FtpLastResponse(conn)); | ||
641 | QMessageBox::message("Note",msg); | ||
642 | } | ||
643 | } | ||
644 | break; | ||
645 | }; | ||
646 | } else { | ||
647 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" | ||
648 | ,"Yes","No",0,0,1) ) { | ||
649 | case 0: { | ||
650 | QString path= currentRemoteDir+f; | ||
651 | if(FtpDelete( path.latin1(), conn)==0) { | ||
652 | QString msg; | ||
653 | msg.sprintf("Unable to delete file\n%s",FtpLastResponse(conn)); | ||
654 | QMessageBox::message("Note",msg); | ||
655 | } | ||
656 | } | ||
657 | break; | ||
658 | }; | ||
659 | } | ||
660 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
661 | } | ||
662 | |||
663 | void OpieFtp::remoteRename() | ||
664 | { | ||
665 | QString curFile = Remote_View->currentItem()->text(0); | ||
666 | InputDialog *fileDlg; | ||
667 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); | ||
668 | fileDlg->inputText = curFile; | ||
669 | fileDlg->exec(); | ||
670 | if( fileDlg->result() == 1 ) { | ||
671 | QString oldName = currentRemoteDir +"/"+ curFile; | ||
672 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; | ||
673 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
674 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { | ||
675 | QString msg; | ||
676 | msg.sprintf("Unable to rename file\n%s",FtpLastResponse(conn)); | ||
677 | QMessageBox::message("Note",msg); | ||
678 | } | ||
679 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
680 | } | ||
681 | populateRemoteView(); | ||
682 | } | ||
683 | |||
684 | void OpieFtp::localRename() | ||
685 | { | ||
686 | QString curFile = Local_View->currentItem()->text(0); | ||
687 | InputDialog *fileDlg; | ||
688 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); | ||
689 | fileDlg->inputText = curFile; | ||
690 | fileDlg->exec(); | ||
691 | if( fileDlg->result() == 1 ) { | ||
692 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | ||
693 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | ||
694 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
695 | QMessageBox::message("Note","Could not rename"); | ||
696 | } | ||
697 | populateLocalView(); | ||
698 | } | ||
699 | |||
700 | void OpieFtp::currentPathEditChanged() | ||
701 | { | ||
702 | if (TabWidget->currentPageIndex() == 0) { | ||
703 | if(QDir( currentPathEdit->text()).exists()) { | ||
704 | currentDir.setPath( currentPathEdit->text() ); | ||
705 | populateLocalView(); | ||
706 | } else { | ||
707 | QMessageBox::message("Note","That directory does not exist"); | ||
708 | } | ||
709 | } | ||
710 | if (TabWidget->currentPageIndex() == 1) { | ||
711 | currentRemoteDir = currentPathEdit->text(); | ||
712 | if(currentRemoteDir.right(1) !="/") { | ||
713 | currentRemoteDir = currentRemoteDir +"/"; | ||
714 | currentPathEdit->setText( currentRemoteDir ); | ||
715 | } | ||
716 | remoteChDir( (const QString &)currentRemoteDir); | ||
717 | remoteDirList( (const QString &)currentRemoteDir); | ||
718 | } | ||
719 | } | ||