summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/obexftpdialog.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/obexftpdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/obexftpdialog.cpp99
1 files changed, 88 insertions, 11 deletions
diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp
index c77d49d..80a81b4 100644
--- a/noncore/net/opietooth/manager/obexftpdialog.cpp
+++ b/noncore/net/opietooth/manager/obexftpdialog.cpp
@@ -12,9 +12,15 @@
12 * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ 12 * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/
13 */ 13 */
14#include <sys/stat.h> 14#include <sys/stat.h>
15#include <sys/types.h>
16#include <unistd.h>
17#include <string.h>
18#include <errno.h>
15#include <qpushbutton.h> 19#include <qpushbutton.h>
16#include <qmessagebox.h> 20#include <qmessagebox.h>
17#include <qmultilineedit.h> 21#include <qmultilineedit.h>
22#include <qspinbox.h>
23#include <qcombobox.h>
18#include <qlistview.h> 24#include <qlistview.h>
19#include <qprogressbar.h> 25#include <qprogressbar.h>
20#include <qlabel.h> 26#include <qlabel.h>
@@ -49,6 +55,7 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port,
49 m_port(port), curdir("") 55 m_port(port), curdir("")
50{ 56{
51 client = NULL; 57 client = NULL;
58 nRetries = 3;
52 transport = OBEX_TRANS_BLUETOOTH; 59 transport = OBEX_TRANS_BLUETOOTH;
53 use_conn = TRUE; 60 use_conn = TRUE;
54 use_path = TRUE; 61 use_path = TRUE;
@@ -68,12 +75,16 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port,
68 destFile->setCloseVisible(false); 75 destFile->setCloseVisible(false);
69 destFile->setNewVisible(false); 76 destFile->setNewVisible(false);
70 localLayout->addWidget(destFile); 77 localLayout->addWidget(destFile);
78 nReries->setValue(nRetries);
71 connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); 79 connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse()));
72 connect(fileList, SIGNAL(clicked(QListViewItem*)), 80 connect(fileList, SIGNAL(clicked(QListViewItem*)),
73 SLOT(slotCd(QListViewItem*))); 81 SLOT(slotCd(QListViewItem*)));
74 connect(getButton, 82 connect(getButton,
75 SIGNAL(clicked()), 83 SIGNAL(clicked()),
76 SLOT(getFile())); 84 SLOT(getFile()));
85 connect(putButton,
86 SIGNAL(clicked()),
87 SLOT(putFile()));
77 connect(destFile, 88 connect(destFile,
78 SIGNAL(dirSelected (const QString&)), 89 SIGNAL(dirSelected (const QString&)),
79 SLOT(updateDir(const QString&))); 90 SLOT(updateDir(const QString&)));
@@ -94,18 +105,36 @@ void ObexFtpDialog::slotBrowse()
94{ 105{
95 stat_entry_t* ent; //Directory entry 106 stat_entry_t* ent; //Directory entry
96 void *dir; //Directory to read 107 void *dir; //Directory to read
97 const uint8_t use_uuid[] = __UUID_FBS_bytes; 108 const uint8_t* use_uuid; //uuid
98 int len = sizeof(UUID_FBS); 109 int len; //uuid length
99 FileListItem* root; //root node 110 FileListItem* root; //root node
100 stat_entry_t* st; //File statistics
101 int fsize; //file size 111 int fsize; //file size
112 bool numOk; //true if the string is a number
113 int tmp; //just a temp var
102 114
103 status(tr("Connecting to ") + m_device); 115 status(tr("Connecting to ") + m_device);
104 odebug << "Browse device " << m_device << oendl; 116 odebug << "Browse device " << m_device << oendl;
105 browseLog->clear(); 117 browseLog->clear();
106 fileList->clear(); 118 fileList->clear();
107 progressStatus = 0; 119 progressStatus = 0;
120 fileProgress->setTotalSteps(MAX_PROGRESS);
108 fileProgress->reset(); 121 fileProgress->reset();
122
123 //Get parameters
124 tmp = nReries->text().toInt(&numOk);
125 if (numOk)
126 nRetries = tmp;
127 if (uuidType->currentText() == "FBS") {
128 use_uuid = UUID_FBS;
129 len = sizeof(UUID_FBS);
130 } else if (uuidType->currentText() == "S45") {
131 use_uuid = UUID_S45;
132 len = sizeof(UUID_S45);
133 } else {
134 use_uuid = UUID_FBS;
135 len = sizeof(UUID_FBS);
136 }
137
109 if (!cli_connect_uuid(use_uuid, len)) { 138 if (!cli_connect_uuid(use_uuid, len)) {
110 log("Connection failed"); 139 log("Connection failed");
111 errBox("Connection failed"); 140 errBox("Connection failed");
@@ -121,13 +150,10 @@ void ObexFtpDialog::slotBrowse()
121 dir = obexftp_opendir(client, curdir); 150 dir = obexftp_opendir(client, curdir);
122 while ((ent = obexftp_readdir(dir)) != NULL) { 151 while ((ent = obexftp_readdir(dir)) != NULL) {
123 FileListItem* a; //List view item 152 FileListItem* a; //List view item
124#if 0 //Causes sigsegv
125 if (ent->mode != 16877) { 153 if (ent->mode != 16877) {
126 st = obexftp_stat(client, ent->name); 154 fsize = ent->size;
127 fsize = st->size;
128 } 155 }
129 else 156 else
130#endif
131 fsize = 0; 157 fsize = 0;
132 log(QString(ent->name) + QString(" ") + 158 log(QString(ent->name) + QString(" ") +
133 QString::number(ent->mode)); 159 QString::number(ent->mode));
@@ -222,6 +248,10 @@ void ObexFtpDialog::getFile()
222 if (local.right(1) != "/") 248 if (local.right(1) != "/")
223 local += "/"; 249 local += "/";
224 if (file->gettype() == IS_FILE) { 250 if (file->gettype() == IS_FILE) {
251 if (client == NULL) {
252 errBox("No connection established");
253 return;
254 }
225 file2get += curdir; 255 file2get += curdir;
226 if (curdir != "" && curdir.right(1) != "/") 256 if (curdir != "" && curdir.right(1) != "/")
227 file2get += "/"; 257 file2get += "/";
@@ -229,6 +259,7 @@ void ObexFtpDialog::getFile()
229 local += file->text(0); 259 local += file->text(0);
230 odebug << "Copy " << file2get << " to " << local << oendl; 260 odebug << "Copy " << file2get << " to " << local << oendl;
231 progressStatus = 0; 261 progressStatus = 0;
262 fileProgress->setTotalSteps(file->getsize() / 1024);
232 fileProgress->reset(); 263 fileProgress->reset();
233 status(tr("Receiving file ") + file2get); 264 status(tr("Receiving file ") + file2get);
234 result = obexftp_get(client, local, file2get); 265 result = obexftp_get(client, local, file2get);
@@ -245,6 +276,54 @@ void ObexFtpDialog::getFile()
245 } 276 }
246} 277}
247 278
279/*
280 * Put the file
281 */
282void ObexFtpDialog::putFile()
283{
284 int result; //OPeration result
285 int idx; //Index of a symbol in the string
286 struct stat localFStat; //Local file information
287
288 if (client == NULL) {
289 errBox("No connection established");
290 return;
291 }
292 local = destFile->selectedName();
293 if (local == "") {
294 errBox("No file slected");
295 return;
296 }
297 result = stat(local, &localFStat);
298 if (result < 0) {
299 errBox(tr("Wrong file selected ") + local + tr(" ") +
300 tr(strerror(errno)));
301 return;
302 }
303 idx = local.findRev('/');
304 if (idx > 0) {
305 file2get = local.right(local.length() - idx - 1);
306 }
307 else
308 file2get = local;
309
310 odebug << "Copy " << local << " to " << file2get << oendl;
311 progressStatus = 0;
312 fileProgress->setTotalSteps(localFStat.st_size / 1024);
313 fileProgress->reset();
314 status(tr("Sending file ") + local);
315 result = obexftp_put_file(client, local, file2get);
316 if (result < 0) {
317 log(local + QString(" send ERROR"));
318 errBox(local + QString(" send ERROR"));
319 status(local + QString(" send ERROR"));
320 }
321 else {
322 log(local + QString(" sent"));
323 status(local + QString(" sent"));
324 }
325}
326
248/* connect with given uuid. re-connect every time */ 327/* connect with given uuid. re-connect every time */
249int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) 328int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len)
250{ 329{
@@ -261,7 +340,7 @@ int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len)
261 client->quirks &= ~OBEXFTP_CONN_HEADER; 340 client->quirks &= ~OBEXFTP_CONN_HEADER;
262 if (!use_path) 341 if (!use_path)
263 client->quirks &= ~OBEXFTP_SPLIT_SETPATH; 342 client->quirks &= ~OBEXFTP_SPLIT_SETPATH;
264 for (retry = 0; retry < 3; retry++) { 343 for (retry = 0; retry < nRetries; retry++) {
265 /* Connect */ 344 /* Connect */
266 switch (transport) { 345 switch (transport) {
267 case OBEX_TRANS_IRDA: 346 case OBEX_TRANS_IRDA:
@@ -309,10 +388,8 @@ void ObexFtpDialog::log(const char* str)
309 388
310void ObexFtpDialog::incProgress() 389void ObexFtpDialog::incProgress()
311{ 390{
312 odebug << "Progress " << progressStatus << oendl; 391 if (progressStatus < fileProgress->totalSteps())
313 if (progressStatus < MAX_PROGRESS) {
314 fileProgress->setProgress(progressStatus++); 392 fileProgress->setProgress(progressStatus++);
315 }
316} 393}
317 394
318void ObexFtpDialog::doneProgress() 395void ObexFtpDialog::doneProgress()