summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-05-06 18:37:33 (UTC)
committer korovkin <korovkin>2006-05-06 18:37:33 (UTC)
commit2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1 (patch) (unidiff)
treed42ffb6e48f3d0f3b6b53b6c1b628e28e0783ceb
parent0430a18e64df0cdfc1e468a7f7bbe77efc63d0ca (diff)
downloadopie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.zip
opie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.tar.gz
opie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.tar.bz2
Browse button forces reconnection.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/obexftpdialog.cpp27
-rw-r--r--noncore/net/opietooth/manager/obexftpdialog.h4
2 files changed, 23 insertions, 8 deletions
diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp
index 2f04ecf..efb3ff2 100644
--- a/noncore/net/opietooth/manager/obexftpdialog.cpp
+++ b/noncore/net/opietooth/manager/obexftpdialog.cpp
@@ -103,28 +103,33 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port,
103 SIGNAL(clicked()), 103 SIGNAL(clicked()),
104 SLOT(slotBrowseLog())); 104 SLOT(slotBrowseLog()));
105} 105}
106 106
107ObexFtpDialog::~ObexFtpDialog() 107ObexFtpDialog::~ObexFtpDialog()
108{ 108{
109 if (client != NULL) { 109 if (client != NULL) {
110 obexftp_disconnect(client); 110 obexftp_disconnect(client);
111 obexftp_close(client); 111 obexftp_close(client);
112 } 112 }
113} 113}
114 114
115void ObexFtpDialog::slotBrowse()
116{
117 doBrowse(TRUE);
118}
119
115/* 120/*
116 * Do device browsing 121 * Do device browsing
117 */ 122 */
118void ObexFtpDialog::slotBrowse() 123void ObexFtpDialog::doBrowse(bool reconnect)
119{ 124{
120 stat_entry_t* ent; //Directory entry 125 stat_entry_t* ent; //Directory entry
121 void *dir; //Directory to read 126 void *dir; //Directory to read
122 const uint8_t* use_uuid; //uuid 127 const uint8_t* use_uuid; //uuid
123 int len; //uuid length 128 int len; //uuid length
124 FileListItem* root; //root node 129 FileListItem* root; //root node
125 int fsize; //file size 130 int fsize; //file size
126 bool numOk; //true if the string is a number 131 bool numOk; //true if the string is a number
127 int tmp; //just a temp var 132 int tmp; //just a temp var
128 133
129 status(tr("Connecting to ") + m_device); 134 status(tr("Connecting to ") + m_device);
130 odebug << "Browse device " << m_device << oendl; 135 odebug << "Browse device " << m_device << oendl;
@@ -140,25 +145,25 @@ void ObexFtpDialog::slotBrowse()
140 nRetries = tmp; 145 nRetries = tmp;
141 if (uuidType->currentText() == "FBS") { 146 if (uuidType->currentText() == "FBS") {
142 use_uuid = UUID_FBS; 147 use_uuid = UUID_FBS;
143 len = sizeof(UUID_FBS); 148 len = sizeof(UUID_FBS);
144 } else if (uuidType->currentText() == "S45") { 149 } else if (uuidType->currentText() == "S45") {
145 use_uuid = UUID_S45; 150 use_uuid = UUID_S45;
146 len = sizeof(UUID_S45); 151 len = sizeof(UUID_S45);
147 } else { 152 } else {
148 use_uuid = UUID_FBS; 153 use_uuid = UUID_FBS;
149 len = sizeof(UUID_FBS); 154 len = sizeof(UUID_FBS);
150 } 155 }
151 156
152 if (!cli_connect_uuid(use_uuid, len)) { 157 if (!cli_connect_uuid(use_uuid, len, reconnect)) {
153 log(tr("Connection failed: ") + tr(strerror(errno))); 158 log(tr("Connection failed: ") + tr(strerror(errno)));
154 errBox("Connection failed"); 159 errBox("Connection failed");
155 status("Connection failed"); 160 status("Connection failed");
156 return; 161 return;
157 } 162 }
158 else { 163 else {
159 log(QString("Connected to ") + m_device); 164 log(QString("Connected to ") + m_device);
160 status(QString("Connected to ") + m_device); 165 status(QString("Connected to ") + m_device);
161 } 166 }
162 /* List folder */ 167 /* List folder */
163 root = new FileListItem(fileList, NULL); 168 root = new FileListItem(fileList, NULL);
164 dir = obexftp_opendir(client, curdir); 169 dir = obexftp_opendir(client, curdir);
@@ -231,25 +236,25 @@ void ObexFtpDialog::slotCd(QListViewItem* item)
231 curdir.remove(idx, curdir.length() - idx); 236 curdir.remove(idx, curdir.length() - idx);
232 else 237 else
233 curdir = ""; 238 curdir = "";
234 } 239 }
235 else { 240 else {
236 if (curdir != "" && curdir.right(1) != "/") 241 if (curdir != "" && curdir.right(1) != "/")
237 curdir += "/"; 242 curdir += "/";
238 curdir += file->text(0); 243 curdir += file->text(0);
239 } 244 }
240 odebug << "Browse " << curdir << oendl; 245 odebug << "Browse " << curdir << oendl;
241 if (obexftp_setpath(client, curdir, 0) < 0) 246 if (obexftp_setpath(client, curdir, 0) < 0)
242 log(tr("CD failed: ") + tr(strerror(errno))); 247 log(tr("CD failed: ") + tr(strerror(errno)));
243 slotBrowse(); 248 doBrowse();
244 } 249 }
245} 250}
246 251
247/* 252/*
248 * Copy file from a remote device to the local device 253 * Copy file from a remote device to the local device
249 */ 254 */
250void ObexFtpDialog::getFile() 255void ObexFtpDialog::getFile()
251{ 256{
252 FileListItem* file = (FileListItem*)fileList->selectedItem(); 257 FileListItem* file = (FileListItem*)fileList->selectedItem();
253 int result; 258 int result;
254 if (file == NULL) 259 if (file == NULL)
255 return; 260 return;
@@ -324,25 +329,25 @@ void ObexFtpDialog::putFile()
324 odebug << "Copy " << local << " to " << file2get << oendl; 329 odebug << "Copy " << local << " to " << file2get << oendl;
325 progressStatus = 0; 330 progressStatus = 0;
326 fileProgress->setTotalSteps(localFStat.st_size / 1024); 331 fileProgress->setTotalSteps(localFStat.st_size / 1024);
327 fileProgress->reset(); 332 fileProgress->reset();
328 status(tr("Sending file ") + local); 333 status(tr("Sending file ") + local);
329 result = obexftp_put_file(client, local, file2get); 334 result = obexftp_put_file(client, local, file2get);
330 if (result < 0) { 335 if (result < 0) {
331 log(local + QString(" send ERROR:\n") + tr(strerror(errno))); 336 log(local + QString(" send ERROR:\n") + tr(strerror(errno)));
332 errBox(local + QString(" send ERROR")); 337 errBox(local + QString(" send ERROR"));
333 status(local + QString(" send ERROR")); 338 status(local + QString(" send ERROR"));
334 } 339 }
335 else { 340 else {
336 slotBrowse(); 341 doBrowse();
337 log(local + QString(" sent")); 342 log(local + QString(" sent"));
338 status(local + QString(" sent")); 343 status(local + QString(" sent"));
339 } 344 }
340} 345}
341 346
342/* 347/*
343 * Delete file on a remote device 348 * Delete file on a remote device
344 */ 349 */
345void ObexFtpDialog::delFile() 350void ObexFtpDialog::delFile()
346{ 351{
347 FileListItem* file = (FileListItem*)fileList->selectedItem(); 352 FileListItem* file = (FileListItem*)fileList->selectedItem();
348 int result; 353 int result;
@@ -362,36 +367,44 @@ void ObexFtpDialog::delFile()
362 result = QMessageBox::warning(this, tr("Remove File"), 367 result = QMessageBox::warning(this, tr("Remove File"),
363 tr("Do you want to remove\n") + file2get, "Yes", "No"); 368 tr("Do you want to remove\n") + file2get, "Yes", "No");
364 if (result != 0) 369 if (result != 0)
365 return; 370 return;
366 odebug << "Remove " << file2get << oendl; 371 odebug << "Remove " << file2get << oendl;
367 result = obexftp_del(client, file2get); 372 result = obexftp_del(client, file2get);
368 if (result < 0) { 373 if (result < 0) {
369 log(file2get + QString(" remove ERROR\n") + tr(strerror(errno))); 374 log(file2get + QString(" remove ERROR\n") + tr(strerror(errno)));
370 errBox(file2get + QString(" remove ERROR")); 375 errBox(file2get + QString(" remove ERROR"));
371 status(file2get + QString(" remove ERROR")); 376 status(file2get + QString(" remove ERROR"));
372 } 377 }
373 else { 378 else {
374 slotBrowse(); 379 doBrowse();
375 log(file2get + QString(" removed")); 380 log(file2get + QString(" removed"));
376 status(file2get + QString(" removed")); 381 status(file2get + QString(" removed"));
377 } 382 }
378} 383}
379 384
380/* connect with given uuid. re-connect every time */ 385/* connect with given uuid. re-connect every time */
381int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) 386int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len,
387 bool reconnect)
382{ 388{
383 int retry; 389 int retry;
384 if (client != NULL) 390 if (client != NULL) {
391 if (reconnect) {
392 obexftp_disconnect(client);
393 obexftp_close(client);
394 sleep(3);
395 }
396 else
385 return TRUE; 397 return TRUE;
398 }
386 /* Open */ 399 /* Open */
387 client = obexftp_open (transport, NULL, info_cb, this); 400 client = obexftp_open (transport, NULL, info_cb, this);
388 if(client == NULL) { 401 if(client == NULL) {
389 errBox("Error opening obexftp-client"); 402 errBox("Error opening obexftp-client");
390 return FALSE; 403 return FALSE;
391 } 404 }
392 if (!use_conn) 405 if (!use_conn)
393 client->quirks &= ~OBEXFTP_CONN_HEADER; 406 client->quirks &= ~OBEXFTP_CONN_HEADER;
394 if (!use_path) 407 if (!use_path)
395 client->quirks &= ~OBEXFTP_SPLIT_SETPATH; 408 client->quirks &= ~OBEXFTP_SPLIT_SETPATH;
396 for (retry = 0; retry < nRetries; retry++) { 409 for (retry = 0; retry < nRetries; retry++) {
397 /* Connect */ 410 /* Connect */
diff --git a/noncore/net/opietooth/manager/obexftpdialog.h b/noncore/net/opietooth/manager/obexftpdialog.h
index 75ee95b..45699d2 100644
--- a/noncore/net/opietooth/manager/obexftpdialog.h
+++ b/noncore/net/opietooth/manager/obexftpdialog.h
@@ -26,31 +26,33 @@ namespace OpieTooth {
26 public: 26 public:
27 ObexFtpDialog(const QString& device = 0, int port = 0, 27 ObexFtpDialog(const QString& device = 0, int port = 0,
28 QWidget* parent = 0, const char* name = 0, bool modal = TRUE, 28 QWidget* parent = 0, const char* name = 0, bool modal = TRUE,
29 WFlags fl = 0); 29 WFlags fl = 0);
30 ~ObexFtpDialog(); 30 ~ObexFtpDialog();
31 void log(QString str); 31 void log(QString str);
32 void log(QCString str); 32 void log(QCString str);
33 void log(const char* str); 33 void log(const char* str);
34 void log(QString& str); 34 void log(QString& str);
35 void incProgress(); 35 void incProgress();
36 void doneProgress(); 36 void doneProgress();
37 protected: 37 protected:
38 int cli_connect_uuid(const uint8_t *uuid, int uuid_len); 38 int cli_connect_uuid(const uint8_t *uuid, int uuid_len,
39 bool reconnect = FALSE);
39 int errBox(QCString msg); //Error message box 40 int errBox(QCString msg); //Error message box
40 int errBox(QString msg); //Error message box 41 int errBox(QString msg); //Error message box
41 int errBox(const char* msg); //Error message box 42 int errBox(const char* msg); //Error message box
42 void status(QCString msg); //Text in the status bar 43 void status(QCString msg); //Text in the status bar
43 void status(QString msg); //Text in the status bar 44 void status(QString msg); //Text in the status bar
44 void status(const char* msg); //Text in the status bar 45 void status(const char* msg); //Text in the status bar
46 void doBrowse(bool reconnect = FALSE); //Browse device
45 protected: 47 protected:
46 QString m_device; //device MAC address 48 QString m_device; //device MAC address
47 int m_port; //port 49 int m_port; //port
48 int transport; //transport type 50 int transport; //transport type
49 bool use_conn; 51 bool use_conn;
50 bool use_path; 52 bool use_path;
51 obexftp_client_t* client; //Obex ftp client handler 53 obexftp_client_t* client; //Obex ftp client handler
52 QString curdir; //Current directory on device 54 QString curdir; //Current directory on device
53 QString localCurdir; //Local current directory 55 QString localCurdir; //Local current directory
54 QString file2get; //Remote file name 56 QString file2get; //Remote file name
55 QString local; //Local file name 57 QString local; //Local file name
56 int progressStatus; //Progress status 58 int progressStatus; //Progress status