Diffstat (limited to 'noncore/net/opietooth/manager/obexftpdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/obexftpdialog.cpp | 99 |
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 | |||
@@ -9,15 +9,21 @@ | |||
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | /* | 11 | /* |
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> |
21 | #include <qlayout.h> | 27 | #include <qlayout.h> |
22 | #include <errno.h> | 28 | #include <errno.h> |
23 | #include "obexftpdialog.h" | 29 | #include "obexftpdialog.h" |
@@ -46,12 +52,13 @@ static void info_cb(int event, const char *msg, int len, void* data); | |||
46 | ObexFtpDialog::ObexFtpDialog(const QString& device, int port, | 52 | ObexFtpDialog::ObexFtpDialog(const QString& device, int port, |
47 | QWidget* parent, const char* name, bool modal, WFlags fl) | 53 | QWidget* parent, const char* name, bool modal, WFlags fl) |
48 | : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), | 54 | : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), |
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; |
55 | progressStatus = 0; | 62 | progressStatus = 0; |
56 | localCurdir = "/"; | 63 | localCurdir = "/"; |
57 | browseLog->setEdited(FALSE); | 64 | browseLog->setEdited(FALSE); |
@@ -65,18 +72,22 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port, | |||
65 | destFile = new OFileSelector(localFs, | 72 | destFile = new OFileSelector(localFs, |
66 | OFileSelector::FileSelector, | 73 | OFileSelector::FileSelector, |
67 | OFileSelector::ExtendedAll, localCurdir, ""); | 74 | OFileSelector::ExtendedAll, localCurdir, ""); |
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&))); |
80 | } | 91 | } |
81 | 92 | ||
82 | ObexFtpDialog::~ObexFtpDialog() | 93 | ObexFtpDialog::~ObexFtpDialog() |
@@ -91,24 +102,42 @@ ObexFtpDialog::~ObexFtpDialog() | |||
91 | * Do device browsing | 102 | * Do device browsing |
92 | */ | 103 | */ |
93 | void ObexFtpDialog::slotBrowse() | 104 | 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"); |
112 | status("Connection failed"); | 141 | status("Connection failed"); |
113 | return; | 142 | return; |
114 | } | 143 | } |
@@ -118,19 +147,16 @@ void ObexFtpDialog::slotBrowse() | |||
118 | } | 147 | } |
119 | /* List folder */ | 148 | /* List folder */ |
120 | root = new FileListItem(fileList, NULL); | 149 | root = new FileListItem(fileList, NULL); |
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)); |
134 | 160 | ||
135 | a = new FileListItem(fileList, ent, fsize); | 161 | a = new FileListItem(fileList, ent, fsize); |
136 | } | 162 | } |
@@ -219,19 +245,24 @@ void ObexFtpDialog::getFile() | |||
219 | errBox("Select a destination first"); | 245 | errBox("Select a destination first"); |
220 | return; | 246 | return; |
221 | } | 247 | } |
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 += "/"; |
228 | file2get += file->text(0); | 258 | file2get += file->text(0); |
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); |
235 | if (result < 0) { | 266 | if (result < 0) { |
236 | log(file2get + QString(" receive ERROR")); | 267 | log(file2get + QString(" receive ERROR")); |
237 | errBox(file2get + QString(" receive ERROR")); | 268 | errBox(file2get + QString(" receive ERROR")); |
@@ -242,12 +273,60 @@ void ObexFtpDialog::getFile() | |||
242 | status(file2get + QString(" received")); | 273 | status(file2get + QString(" received")); |
243 | destFile->reread(); | 274 | destFile->reread(); |
244 | } | 275 | } |
245 | } | 276 | } |
246 | } | 277 | } |
247 | 278 | ||
279 | /* | ||
280 | * Put the file | ||
281 | */ | ||
282 | void 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 */ |
249 | int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) | 328 | int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) |
250 | { | 329 | { |
251 | int retry; | 330 | int retry; |
252 | if (client != NULL) | 331 | if (client != NULL) |
253 | return TRUE; | 332 | return TRUE; |
@@ -258,13 +337,13 @@ int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) | |||
258 | return FALSE; | 337 | return FALSE; |
259 | } | 338 | } |
260 | if (!use_conn) | 339 | if (!use_conn) |
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: |
268 | if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) | 347 | if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) |
269 | return TRUE; | 348 | return TRUE; |
270 | break; | 349 | break; |
@@ -306,17 +385,15 @@ void ObexFtpDialog::log(const char* str) | |||
306 | { | 385 | { |
307 | browseLog->append(str); | 386 | browseLog->append(str); |
308 | } | 387 | } |
309 | 388 | ||
310 | void ObexFtpDialog::incProgress() | 389 | void 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 | } | 393 | } |
316 | } | ||
317 | 394 | ||
318 | void ObexFtpDialog::doneProgress() | 395 | void ObexFtpDialog::doneProgress() |
319 | { | 396 | { |
320 | progressStatus = 0; | 397 | progressStatus = 0; |
321 | fileProgress->reset(); | 398 | fileProgress->reset(); |
322 | } | 399 | } |