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
@@ -3,27 +3,33 @@
3/*************************************************************************** 3/***************************************************************************
4 * * 4 * *
5 * This program is free software; you can redistribute it and/or modify * 5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by * 6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or * 7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. * 8 * (at your option) any later version. *
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"
24#include "filelistitem.h" 30#include "filelistitem.h"
25 31
26#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
27#include <qpe/resource.h> 33#include <qpe/resource.h>
28#include <qpe/config.h> 34#include <qpe/config.h>
29#include <opie2/odebug.h> 35#include <opie2/odebug.h>
@@ -40,103 +46,123 @@ static void info_cb(int event, const char *msg, int len, void* data);
40 46
41/* 47/*
42 * Public constructor 48 * Public constructor
43 * device - bluetooth address of the device 49 * device - bluetooth address of the device
44 * port - port to connect to 50 * port - port to connect to
45 */ 51 */
46ObexFtpDialog::ObexFtpDialog(const QString& device, int port, 52ObexFtpDialog::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);
58 fileList->setSorting(1); 65 fileList->setSorting(1);
59 fileList->clear(); 66 fileList->clear();
60 fileProgress->setTotalSteps(MAX_PROGRESS); 67 fileProgress->setTotalSteps(MAX_PROGRESS);
61 statusBar->clear(); 68 statusBar->clear();
62 localLayout = new QVBoxLayout(localFs); 69 localLayout = new QVBoxLayout(localFs);
63 localLayout->setSpacing( 0 ); 70 localLayout->setSpacing( 0 );
64 localLayout->setMargin( 0 ); 71 localLayout->setMargin( 0 );
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
82ObexFtpDialog::~ObexFtpDialog() 93ObexFtpDialog::~ObexFtpDialog()
83{ 94{
84 if (client != NULL) { 95 if (client != NULL) {
85 obexftp_disconnect(client); 96 obexftp_disconnect(client);
86 obexftp_close(client); 97 obexftp_close(client);
87 } 98 }
88} 99}
89 100
90/* 101/*
91 * Do device browsing 102 * Do device browsing
92 */ 103 */
93void ObexFtpDialog::slotBrowse() 104void 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 }
115 else { 144 else {
116 log(QString("Connected to ") + m_device); 145 log(QString("Connected to ") + m_device);
117 status(QString("Connected to ") + m_device); 146 status(QString("Connected to ") + m_device);
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 }
137 obexftp_closedir(dir); 163 obexftp_closedir(dir);
138} 164}
139 165
140//Error message box 166//Error message box
141int ObexFtpDialog::errBox(QCString msg) 167int ObexFtpDialog::errBox(QCString msg)
142{ 168{
@@ -213,64 +239,117 @@ void ObexFtpDialog::getFile()
213 int result; 239 int result;
214 if (file == NULL) 240 if (file == NULL)
215 return; 241 return;
216 file2get = "/"; 242 file2get = "/";
217 local = localCurdir; 243 local = localCurdir;
218 if (local == "") { 244 if (local == "") {
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"));
238 status(file2get + QString(" receive ERROR")); 269 status(file2get + QString(" receive ERROR"));
239 } 270 }
240 else { 271 else {
241 log(file2get + QString(" received")); 272 log(file2get + QString(" received"));
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 */
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{
251 int retry; 330 int retry;
252 if (client != NULL) 331 if (client != NULL)
253 return TRUE; 332 return TRUE;
254 /* Open */ 333 /* Open */
255 client = obexftp_open (transport, NULL, info_cb, this); 334 client = obexftp_open (transport, NULL, info_cb, this);
256 if(client == NULL) { 335 if(client == NULL) {
257 errBox("Error opening obexftp-client"); 336 errBox("Error opening obexftp-client");
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;
271 case OBEX_TRANS_BLUETOOTH: 350 case OBEX_TRANS_BLUETOOTH:
272 if (obexftp_connect_uuid(client, m_device, m_port, 351 if (obexftp_connect_uuid(client, m_device, m_port,
273 uuid, uuid_len) >= 0) 352 uuid, uuid_len) >= 0)
274 return TRUE; 353 return TRUE;
275 break; 354 break;
276 default: 355 default:
@@ -300,28 +379,26 @@ void ObexFtpDialog::log(QCString str)
300void ObexFtpDialog::log(QString& str) 379void ObexFtpDialog::log(QString& str)
301{ 380{
302 browseLog->append(str); 381 browseLog->append(str);
303} 382}
304 383
305void ObexFtpDialog::log(const char* str) 384void ObexFtpDialog::log(const char* str)
306{ 385{
307 browseLog->append(str); 386 browseLog->append(str);
308} 387}
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()
319{ 396{
320 progressStatus = 0; 397 progressStatus = 0;
321 fileProgress->reset(); 398 fileProgress->reset();
322} 399}
323 400
324void ObexFtpDialog::updateDir(const QString& newdir) 401void ObexFtpDialog::updateDir(const QString& newdir)
325{ 402{
326 localCurdir = newdir; 403 localCurdir = newdir;
327} 404}