author | korovkin <korovkin> | 2006-03-20 21:44:55 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-03-20 21:44:55 (UTC) |
commit | 74546adb68bd3f17a75003671407c4a4e6b09e73 (patch) (side-by-side diff) | |
tree | 489034b13c803dca3e0e7e487e9465189a988c77 /noncore/net/opietooth/manager/obexftpdialog.cpp | |
parent | 14fc21051eb3ff92527fd9ddeaf117009bd74af2 (diff) | |
download | opie-74546adb68bd3f17a75003671407c4a4e6b09e73.zip opie-74546adb68bd3f17a75003671407c4a4e6b09e73.tar.gz opie-74546adb68bd3f17a75003671407c4a4e6b09e73.tar.bz2 |
Added file sending.
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 @@ * * ***************************************************************************/ /* * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ */ #include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> #include <qpushbutton.h> #include <qmessagebox.h> #include <qmultilineedit.h> +#include <qspinbox.h> +#include <qcombobox.h> #include <qlistview.h> #include <qprogressbar.h> #include <qlabel.h> #include <qlayout.h> #include <errno.h> #include "obexftpdialog.h" @@ -46,12 +52,13 @@ static void info_cb(int event, const char *msg, int len, void* data); ObexFtpDialog::ObexFtpDialog(const QString& device, int port, QWidget* parent, const char* name, bool modal, WFlags fl) : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), m_port(port), curdir("") { client = NULL; + nRetries = 3; transport = OBEX_TRANS_BLUETOOTH; use_conn = TRUE; use_path = TRUE; progressStatus = 0; localCurdir = "/"; browseLog->setEdited(FALSE); @@ -65,18 +72,22 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port, destFile = new OFileSelector(localFs, OFileSelector::FileSelector, OFileSelector::ExtendedAll, localCurdir, ""); destFile->setCloseVisible(false); destFile->setNewVisible(false); localLayout->addWidget(destFile); + nReries->setValue(nRetries); connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); connect(fileList, SIGNAL(clicked(QListViewItem*)), SLOT(slotCd(QListViewItem*))); connect(getButton, SIGNAL(clicked()), SLOT(getFile())); + connect(putButton, + SIGNAL(clicked()), + SLOT(putFile())); connect(destFile, SIGNAL(dirSelected (const QString&)), SLOT(updateDir(const QString&))); } ObexFtpDialog::~ObexFtpDialog() @@ -91,24 +102,42 @@ ObexFtpDialog::~ObexFtpDialog() * Do device browsing */ void ObexFtpDialog::slotBrowse() { stat_entry_t* ent; //Directory entry void *dir; //Directory to read - const uint8_t use_uuid[] = __UUID_FBS_bytes; - int len = sizeof(UUID_FBS); + const uint8_t* use_uuid; //uuid + int len; //uuid length FileListItem* root; //root node - stat_entry_t* st; //File statistics 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)) { log("Connection failed"); errBox("Connection failed"); status("Connection failed"); return; } @@ -118,19 +147,16 @@ void ObexFtpDialog::slotBrowse() } /* List folder */ root = new FileListItem(fileList, NULL); dir = obexftp_opendir(client, curdir); while ((ent = obexftp_readdir(dir)) != NULL) { FileListItem* a; //List view item -#if 0 //Causes sigsegv if (ent->mode != 16877) { - st = obexftp_stat(client, ent->name); - fsize = st->size; + fsize = ent->size; } else -#endif fsize = 0; log(QString(ent->name) + QString(" ") + QString::number(ent->mode)); a = new FileListItem(fileList, ent, fsize); } @@ -219,19 +245,24 @@ void ObexFtpDialog::getFile() errBox("Select a destination first"); return; } if (local.right(1) != "/") local += "/"; 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); local += file->text(0); odebug << "Copy " << file2get << " to " << local << oendl; progressStatus = 0; + fileProgress->setTotalSteps(file->getsize() / 1024); fileProgress->reset(); status(tr("Receiving file ") + file2get); result = obexftp_get(client, local, file2get); if (result < 0) { log(file2get + QString(" receive ERROR")); errBox(file2get + QString(" receive ERROR")); @@ -242,12 +273,60 @@ void ObexFtpDialog::getFile() status(file2get + QString(" received")); destFile->reread(); } } } +/* + * Put the file + */ +void ObexFtpDialog::putFile() +{ + int result; //OPeration result + int idx; //Index of a symbol in the string + struct stat localFStat; //Local file information + + if (client == NULL) { + errBox("No connection established"); + return; + } + local = destFile->selectedName(); + if (local == "") { + errBox("No file slected"); + return; + } + result = stat(local, &localFStat); + 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")); + errBox(local + QString(" send ERROR")); + status(local + QString(" send ERROR")); + } + else { + log(local + QString(" sent")); + status(local + QString(" sent")); + } +} + /* connect with given uuid. re-connect every time */ int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) { int retry; if (client != NULL) return TRUE; @@ -258,13 +337,13 @@ int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) return FALSE; } if (!use_conn) client->quirks &= ~OBEXFTP_CONN_HEADER; if (!use_path) client->quirks &= ~OBEXFTP_SPLIT_SETPATH; - for (retry = 0; retry < 3; retry++) { + 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; @@ -306,17 +385,15 @@ void ObexFtpDialog::log(const char* str) { browseLog->append(str); } void ObexFtpDialog::incProgress() { - odebug << "Progress " << progressStatus << oendl; - if (progressStatus < MAX_PROGRESS) { + if (progressStatus < fileProgress->totalSteps()) fileProgress->setProgress(progressStatus++); } -} void ObexFtpDialog::doneProgress() { progressStatus = 0; fileProgress->reset(); } |