summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp44
-rw-r--r--noncore/apps/opie-console/transferdialog.h3
2 files changed, 34 insertions, 13 deletions
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp
index 0083cc1..f9a0b87 100644
--- a/noncore/apps/opie-console/transferdialog.cpp
+++ b/noncore/apps/opie-console/transferdialog.cpp
@@ -7,48 +7,50 @@
#include <qprogressbar.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <opie/ofiledialog.h>
#include "file_layer.h"
#include "receive_layer.h"
#include "metafactory.h"
#include "mainwindow.h"
#include "transferdialog.h"
TransferDialog::TransferDialog(MainWindow *parent, const char *name)
: QDialog(0l, 0l, true), m_win(parent)
{
m_lay = 0l;
m_recvlay = 0l;
QVBoxLayout *vbox, *vbox2;
QHBoxLayout *hbox, *hbox2, *hbox3;
QLabel *file, *mode, *progress, *status;
QButtonGroup *group;
QRadioButton *mode_send, *mode_receive;
+ m_autocleanup = 0;
+
group = new QButtonGroup(QObject::tr("Transfer mode"), this);
mode_send = new QRadioButton(QObject::tr("Send"), group);
mode_receive = new QRadioButton(QObject::tr("Receive"), group);
group->insert(mode_send, id_send);
group->insert(mode_receive, id_receive);
vbox2 = new QVBoxLayout(group, 2);
vbox2->addSpacing(10);
hbox3 = new QHBoxLayout(vbox2, 2);
hbox3->add(mode_send);
hbox3->add(mode_receive);
mode_send->setChecked(true);
m_transfermode = id_send;
file = new QLabel(QObject::tr("Send file"), this);
mode = new QLabel(QObject::tr("Transfer protocol"), this);
progress = new QLabel(QObject::tr("Progress"), this);
status = new QLabel(QObject::tr("Status"), this);
statusbar = new QLabel(QObject::tr("Ready"), this);
statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken);
protocol = new QComboBox(this);
QStringList list = m_win->factory()->fileTransferLayers();
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
@@ -92,95 +94,107 @@ TransferDialog::TransferDialog(MainWindow *parent, const char *name)
TransferDialog::~TransferDialog()
{
}
void TransferDialog::slotFilename()
{
QString f;
f = OFileDialog::getOpenFileName(0);
if(!f.isNull()) filename->setText(f);
}
void TransferDialog::slotTransfer()
{
if((m_transfermode == id_send) && (filename->text().isEmpty()))
{
QMessageBox::information(this,
QObject::tr("Attention"),
QObject::tr("No file has been specified."));
return;
}
ok->setEnabled(false);
+ cleanup();
+ m_autocleanup = 0;
+
if(m_transfermode == id_send) statusbar->setText(QObject::tr("Sending..."));
else statusbar->setText(QObject::tr("Receiving..."));
if(m_transfermode == id_send)
{
m_lay = m_win->factory()->newFileTransfer(protocol->currentText(), m_win->currentSession()->layer());
m_lay->sendFile(filename->text());
connect(m_lay, SIGNAL(progress(const QString&, int, int, int, int, int)),
SLOT(slotProgress(const QString&, int, int, int, int, int)));
connect(m_lay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
connect(m_lay, SIGNAL(sent()), SLOT(slotSent()));
}
else
{
m_recvlay = m_win->factory()->newReceive(protocol->currentText(), m_win->currentSession()->layer());
m_recvlay->receive();
connect(m_recvlay, SIGNAL(progress(const QString&, int, int, int, int, int)),
SLOT(slotProgress(const QString&, int, int, int, int, int)));
connect(m_recvlay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
connect(m_recvlay, SIGNAL(received(const QString&)), SLOT(slotReceived(const QString&)));
}
}
+void TransferDialog::cleanup()
+{
+ if(m_lay)
+ {
+ m_lay->cancel();
+ delete m_lay;
+ m_lay = 0l;
+ }
+ if(m_recvlay)
+ {
+ m_recvlay->cancel();
+ delete m_recvlay;
+ m_recvlay = 0l;
+ }
+}
+
void TransferDialog::slotCancel()
{
ok->setEnabled(true);
statusbar->setText(QObject::tr("Ready"));
if((m_lay) || (m_recvlay))
{
- if(m_lay)
- {
- m_lay->cancel();
- delete m_lay;
- m_lay = 0l;
- }
- if(m_recvlay)
+ cleanup();
+ if(m_autocleanup) close();
+ else
{
- m_recvlay->cancel();
- delete m_recvlay;
- m_recvlay = 0l;
+ QMessageBox::information(this,
+ QObject::tr("Cancelled"),
+ QObject::tr("The file transfer has been cancelled."));
}
- QMessageBox::information(this,
- QObject::tr("Cancelled"),
- QObject::tr("The file transfer has been cancelled."));
}
else
{
close();
}
}
void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds)
{
progressbar->setProgress(progress);
}
void TransferDialog::slotError(int error, const QString& message)
{
statusbar->setText(QObject::tr("Ready"));
switch(error)
{
case FileTransferLayer::NotSupported:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Operation not supported."));
break;
case FileTransferLayer::StartError:
@@ -189,55 +203,59 @@ void TransferDialog::slotError(int error, const QString& message)
QObject::tr("Transfer could not be started."));
break;
case FileTransferLayer::NoError:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("No error."));
break;
case FileTransferLayer::Undefined:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Undefined error occured."));
break;
case FileTransferLayer::Incomplete:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Incomplete transfer."));
break;
case FileTransferLayer::Unknown:
default:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Unknown error occured."));
break;
}
+
+ m_autocleanup = 1;
}
void TransferDialog::slotSent()
{
QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent."));
ok->setEnabled(true);
statusbar->setText(QObject::tr("Ready"));
+ m_autocleanup = 1;
}
void TransferDialog::slotReceived(const QString& file)
{
QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been received as %1.").arg(file));
ok->setEnabled(true);
statusbar->setText(QObject::tr("Ready"));
+ m_autocleanup = 1;
}
void TransferDialog::slotMode(int id)
{
if(id == id_send)
{
selector->setEnabled(true);
filename->setEnabled(true);
}
else
{
selector->setEnabled(false);
filename->setEnabled(false);
}
m_transfermode = id;
}
diff --git a/noncore/apps/opie-console/transferdialog.h b/noncore/apps/opie-console/transferdialog.h
index de3a5cf..1b27f16 100644
--- a/noncore/apps/opie-console/transferdialog.h
+++ b/noncore/apps/opie-console/transferdialog.h
@@ -15,37 +15,40 @@ class ReceiveLayer;
class TransferDialog : public QDialog
{
Q_OBJECT
public:
TransferDialog(MainWindow *parent = 0l, const char *name = 0l);
~TransferDialog();
public slots:
void slotFilename();
void slotTransfer();
void slotCancel();
void slotProgress(const QString&, int, int, int, int, int);
void slotError(int error, const QString& message);
void slotSent();
void slotReceived(const QString& file);
void slotMode(int id);
private:
enum Modes
{
id_send,
id_receive
};
+ void cleanup();
+
QLineEdit *filename;
QComboBox *protocol;
QProgressBar *progressbar;
QLabel *statusbar;
QPushButton *ok, *cancel, *selector;
MainWindow* m_win;
FileTransferLayer* m_lay;
ReceiveLayer *m_recvlay;
int m_transfermode;
+ int m_autocleanup;
};
#endif