author | korovkin <korovkin> | 2006-04-24 19:09:42 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-04-24 19:09:42 (UTC) |
commit | 8856190fa34ad67488adc137dc7c8646d0689795 (patch) (side-by-side diff) | |
tree | a9f6f610ec63a35dfec922020d3627026dc81884 /noncore/net/opietooth/manager/obexftpdialog.cpp | |
parent | 71722eacaa44f3b738318d68dc6148c9e2ff643d (diff) | |
download | opie-8856190fa34ad67488adc137dc7c8646d0689795.zip opie-8856190fa34ad67488adc137dc7c8646d0689795.tar.gz opie-8856190fa34ad67488adc137dc7c8646d0689795.tar.bz2 |
Improved diagnostic messages.
Added LOG saving functionality.
Diffstat (limited to 'noncore/net/opietooth/manager/obexftpdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/obexftpdialog.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp index 80a81b4..f479ca2 100644 --- a/noncore/net/opietooth/manager/obexftpdialog.cpp +++ b/noncore/net/opietooth/manager/obexftpdialog.cpp @@ -6,47 +6,52 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * 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 <qlineedit.h> #include <qspinbox.h> #include <qcombobox.h> #include <qlistview.h> #include <qprogressbar.h> #include <qlabel.h> #include <qlayout.h> #include <errno.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qstringlist.h> #include "obexftpdialog.h" #include "filelistitem.h" #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #include <opie2/odebug.h> #include <opie2/ofileselector.h> +#include <opie2/ofiledialog.h> using namespace Opie::Core; using namespace Opie::Ui; using namespace OpieTooth; #define MAX_PROGRESS 14 //Maximal progress bar static void info_cb(int event, const char *msg, int len, void* data); /* * Public constructor * device - bluetooth address of the device * port - port to connect to */ ObexFtpDialog::ObexFtpDialog(const QString& device, int port, @@ -75,32 +80,38 @@ ObexFtpDialog::ObexFtpDialog(const QString& device, int port, 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&))); + connect(saveButton, + SIGNAL(clicked()), + SLOT(slotSaveLog())); + connect(browseButton, + SIGNAL(clicked()), + SLOT(slotBrowseLog())); } ObexFtpDialog::~ObexFtpDialog() { if (client != NULL) { obexftp_disconnect(client); obexftp_close(client); } } /* * Do device browsing */ void ObexFtpDialog::slotBrowse() { stat_entry_t* ent; //Directory entry @@ -123,33 +134,33 @@ void ObexFtpDialog::slotBrowse() //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"); + 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; } @@ -212,33 +223,33 @@ void ObexFtpDialog::slotCd(QListViewItem* item) 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("CD failed"); + log(tr("CD failed: ") + tr(strerror(errno))); slotBrowse(); } } /* * Get the file */ void ObexFtpDialog::getFile() { FileListItem* file = (FileListItem*)fileList->selectedItem(); int result; if (file == NULL) return; file2get = "/"; local = localCurdir; if (local == "") { @@ -251,33 +262,33 @@ void ObexFtpDialog::getFile() 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")); + log(file2get + QString(" receive ERROR: ") + tr(strerror(errno))); errBox(file2get + QString(" receive ERROR")); status(file2get + QString(" receive ERROR")); } else { log(file2get + QString(" received")); status(file2get + QString(" received")); destFile->reread(); } } } /* * Put the file */ void ObexFtpDialog::putFile() { @@ -301,33 +312,33 @@ void ObexFtpDialog::putFile() 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")); + log(local + QString(" send ERROR: ") + tr(strerror(errno))); 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; /* Open */ @@ -390,32 +401,60 @@ void ObexFtpDialog::incProgress() { if (progressStatus < fileProgress->totalSteps()) fileProgress->setProgress(progressStatus++); } void ObexFtpDialog::doneProgress() { progressStatus = 0; fileProgress->reset(); } void ObexFtpDialog::updateDir(const QString& newdir) { localCurdir = newdir; } +/** + * Save Log to the specified file + */ +void ObexFtpDialog::slotSaveLog() +{ + QFile logFile(saveLogEdit->text()); + if (!logFile.open(IO_WriteOnly)) { + errBox(tr("Unable to open file ") + saveLogEdit->text() + tr(" ") + + tr(strerror(errno))); + return; + } + QTextStream stream(&logFile); + stream << browseLog->text() << endl; + QMessageBox::information(this, tr("Saving"), + tr("Log file saved to ") + saveLogEdit->text()); +} + +void ObexFtpDialog::slotBrowseLog() +{ + MimeTypes types; + QStringList all; + all << "*/*"; + types.insert("All Files", all ); + + QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 ); + saveLogEdit->setText(str); +} + /* * Event callback function */ static void info_cb(int event, const char *msg, int len, void* data) { ObexFtpDialog* dlg = (ObexFtpDialog*)data; QCString cmsg(msg, len); //Message to display switch (event) { case OBEXFTP_EV_ERRMSG: dlg->log(QCString("Error: ") + cmsg); break; case OBEXFTP_EV_ERR: dlg->log(QCString("failed: ") + cmsg); |