summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/obexftpdialog.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/opietooth/manager/obexftpdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/obexftpdialog.cpp29
1 files changed, 21 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
@@ -91,86 +91,91 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port,
SIGNAL(clicked()),
SLOT(putFile()));
connect(delButton,
SIGNAL(clicked()),
SLOT(delFile()));
connect(destFile,
SIGNAL(dirSelected (const QString&)),
SLOT(updateDir(const QString&)));
connect(saveButton,
SIGNAL(clicked()),
SLOT(slotSaveLog()));
connect(browseButton,
SIGNAL(clicked()),
SLOT(slotBrowseLog()));
}
ObexFtpDialog::~ObexFtpDialog()
{
if (client != NULL) {
obexftp_disconnect(client);
obexftp_close(client);
}
}
+void ObexFtpDialog::slotBrowse()
+{
+ doBrowse(TRUE);
+}
+
/*
* Do device browsing
*/
-void ObexFtpDialog::slotBrowse()
+void ObexFtpDialog::doBrowse(bool reconnect)
{
stat_entry_t* ent; //Directory entry
void *dir; //Directory to read
const uint8_t* use_uuid; //uuid
int len; //uuid length
FileListItem* root; //root node
int fsize; //file size
bool numOk; //true if the string is a number
int tmp; //just a temp var
status(tr("Connecting to ") + m_device);
odebug << "Browse device " << m_device << oendl;
browseLog->clear();
fileList->clear();
progressStatus = 0;
fileProgress->setTotalSteps(MAX_PROGRESS);
fileProgress->reset();
//Get parameters
tmp = nReries->text().toInt(&numOk);
if (numOk)
nRetries = tmp;
if (uuidType->currentText() == "FBS") {
use_uuid = UUID_FBS;
len = sizeof(UUID_FBS);
} else if (uuidType->currentText() == "S45") {
use_uuid = UUID_S45;
len = sizeof(UUID_S45);
} else {
use_uuid = UUID_FBS;
len = sizeof(UUID_FBS);
}
- if (!cli_connect_uuid(use_uuid, len)) {
+ if (!cli_connect_uuid(use_uuid, len, reconnect)) {
log(tr("Connection failed: ") + tr(strerror(errno)));
errBox("Connection failed");
status("Connection failed");
return;
}
else {
log(QString("Connected to ") + m_device);
status(QString("Connected to ") + m_device);
}
/* List folder */
root = new FileListItem(fileList, NULL);
dir = obexftp_opendir(client, curdir);
while ((ent = obexftp_readdir(dir)) != NULL) {
FileListItem* a; //List view item
if (ent->mode != 16877) {
fsize = ent->size;
}
else
fsize = 0;
log(QString(ent->name) + QString(" ") +
QString::number(ent->mode));
a = new FileListItem(fileList, ent, fsize);
}
@@ -219,49 +224,49 @@ void ObexFtpDialog::slotCd(QListViewItem* item)
{
FileListItem* file = (FileListItem*)item;
int idx;
if (file == NULL)
return;
odebug << "Item " << file->text(0) << " clicked" << oendl;
if (file->gettype() == IS_DIR) {
if (file->text(0) == "../") {
if (curdir.right(1) == "/")
curdir.remove(curdir.length() - 1, 1);
idx = curdir.findRev('/');
if (idx >= 0)
curdir.remove(idx, curdir.length() - idx);
else
curdir = "";
}
else {
if (curdir != "" && curdir.right(1) != "/")
curdir += "/";
curdir += file->text(0);
}
odebug << "Browse " << curdir << oendl;
if (obexftp_setpath(client, curdir, 0) < 0)
log(tr("CD failed: ") + tr(strerror(errno)));
- slotBrowse();
+ doBrowse();
}
}
/*
* Copy file from a remote device to the local device
*/
void ObexFtpDialog::getFile()
{
FileListItem* file = (FileListItem*)fileList->selectedItem();
int result;
if (file == NULL)
return;
file2get = "/";
local = localCurdir;
if (local == "") {
errBox("Select a destination first");
return;
}
if (local.right(1) != "/")
local += "/";
if (file->gettype() == IS_FILE) {
if (client == NULL) {
errBox("No connection established");
return;
@@ -312,98 +317,106 @@ void ObexFtpDialog::putFile()
if (result < 0) {
errBox(tr("Wrong file selected ") + local + tr(" ") +
tr(strerror(errno)));
return;
}
idx = local.findRev('/');
if (idx > 0) {
file2get = local.right(local.length() - idx - 1);
}
else
file2get = local;
odebug << "Copy " << local << " to " << file2get << oendl;
progressStatus = 0;
fileProgress->setTotalSteps(localFStat.st_size / 1024);
fileProgress->reset();
status(tr("Sending file ") + local);
result = obexftp_put_file(client, local, file2get);
if (result < 0) {
log(local + QString(" send ERROR:\n") + tr(strerror(errno)));
errBox(local + QString(" send ERROR"));
status(local + QString(" send ERROR"));
}
else {
- slotBrowse();
+ doBrowse();
log(local + QString(" sent"));
status(local + QString(" sent"));
}
}
/*
* Delete file on a remote device
*/
void ObexFtpDialog::delFile()
{
FileListItem* file = (FileListItem*)fileList->selectedItem();
int result;
if (file == NULL)
return;
file2get = "/";
if (file->gettype() == IS_FILE) {
if (client == NULL) {
errBox("No connection established");
return;
}
file2get += curdir;
if (curdir != "" && curdir.right(1) != "/")
file2get += "/";
file2get += file->text(0);
}
result = QMessageBox::warning(this, tr("Remove File"),
tr("Do you want to remove\n") + file2get, "Yes", "No");
if (result != 0)
return;
odebug << "Remove " << file2get << oendl;
result = obexftp_del(client, file2get);
if (result < 0) {
log(file2get + QString(" remove ERROR\n") + tr(strerror(errno)));
errBox(file2get + QString(" remove ERROR"));
status(file2get + QString(" remove ERROR"));
}
else {
- slotBrowse();
+ doBrowse();
log(file2get + QString(" removed"));
status(file2get + QString(" removed"));
}
}
/* connect with given uuid. re-connect every time */
-int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len)
+int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len,
+ bool reconnect)
{
int retry;
- if (client != NULL)
- return TRUE;
+ if (client != NULL) {
+ if (reconnect) {
+ obexftp_disconnect(client);
+ obexftp_close(client);
+ sleep(3);
+ }
+ else
+ return TRUE;
+ }
/* Open */
client = obexftp_open (transport, NULL, info_cb, this);
if(client == NULL) {
errBox("Error opening obexftp-client");
return FALSE;
}
if (!use_conn)
client->quirks &= ~OBEXFTP_CONN_HEADER;
if (!use_path)
client->quirks &= ~OBEXFTP_SPLIT_SETPATH;
for (retry = 0; retry < nRetries; retry++) {
/* Connect */
switch (transport) {
case OBEX_TRANS_IRDA:
if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0)
return TRUE;
break;
case OBEX_TRANS_BLUETOOTH:
if (obexftp_connect_uuid(client, m_device, m_port,
uuid, uuid_len) >= 0)
return TRUE;
break;
default:
errBox("Transport type unknown");