summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-13 12:11:15 (UTC)
committer josef <josef>2002-10-13 12:11:15 (UTC)
commit0e6d241e26211a8ffff07ba8e23f4a3cec9065be (patch) (side-by-side diff)
tree1cecafc71b4261943250cf7f83013e749c5c3a1e
parent5f9fb52583eb399c79a108b8e79c1a558a730422 (diff)
downloadopie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.zip
opie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.tar.gz
opie-0e6d241e26211a8ffff07ba8e23f4a3cec9065be.tar.bz2
- extend file transfer dialog so it can receive too (without filename argument)
- fix error messages so they match the error code - don't show dialog maximized. It's still modal but we're coming near... - reset status to "ready" after interrupting or finishing operation - bugfix in filetransfer.cpp: don't kill process if pid is not set => before the fix, cancel() killed random processes!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp4
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp2
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp99
-rw-r--r--noncore/apps/opie-console/transferdialog.h14
4 files changed, 79 insertions, 40 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 8e86ebb..14787f6 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,65 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <qcstring.h>
#include <qsocketnotifier.h>
#include <opie/oprocess.h>
#include "procctl.h"
#include "filetransfer.h"
FileTransfer::FileTransfer( Type t, IOLayer* lay )
- : FileTransferLayer( lay ), m_type( t ) {
+ : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
signal(SIGPIPE, SIG_IGN );
m_not = 0l;
m_proc = 0l;
}
FileTransfer::~FileTransfer() {
}
/**
* now we will send the file.
*
* we request an fd. The IOLayer should be closed
* then we will setup a pipe for progress communication
* then we will dup2 the m_fd in the forked process
* to do direct IO from and to the fd
*/
void FileTransfer::sendFile( const QString& file ) {
m_prog =-1;
m_fd = layer()->rawIO();
//
// m_fd = ::open("/dev/ttyS0", O_RDWR);
m_file = file;
if ( pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if ( pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
m_pid = fork();
switch( m_pid ) {
case -1:
emit error( StartError, tr("Was not able to fork") );
break;
case 0:{
setupChild();
qWarning("output:"+file );
/* exec */
char* verbose = "-vv";
char* binray = "-b";
char* typus;
switch(m_type ) {
case SZ:
typus = "";
break;
case SX:
@@ -190,64 +190,64 @@ void FileTransfer::slotRead() {
/*
* find the progress
*/
void FileTransfer::slotProgress( const QStringList& list ) {
if ( m_type != SZ )
return;
bool complete = true;
int min, sec;
int bps;
unsigned long sent, total;
min = sec = bps = -1;
sent = total = 0;
// Data looks like this
// 0 1 2 3 4 5
// Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
sent = progi[0].toULong(&complete );
if (!complete ) return;
total = progi[1].toULong(&complete );
if (!complete || total == 0) {
return;
}
qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total );
double pro = (double)sent/total;
int prog = pro * 100;
// speed
progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
bps = progi[1].toInt();
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
}
}
void FileTransfer::cancel() {
- ::kill(m_pid,9 );
+ if(m_pid > 0) ::kill(m_pid,9 );
delete m_not;
}
void FileTransfer::slotExec() {
qWarning("exited!");
char buf[2];
::read(m_term[0], buf, 1 );
delete m_proc;
delete m_not;
m_proc = m_not = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
emit sent();
}
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 3af0cba..8f5d56b 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -216,60 +216,60 @@ void MainWindow::slotConfigure() {
if ( QDialog::Accepted == ret ) {
qWarning("conf %d", conf.list().count() );
manager()->setProfiles( conf.list() );
populateProfiles();
}
}
/*
* we will remove
* this window from the tabwidget
* remove it from the list
* delete it
* and set the currentSession()
*/
void MainWindow::slotClose() {
qWarning("close");
if (!currentSession() )
return;
tabWidget()->remove( currentSession() );
/*it's autodelete */
m_sessions.remove( m_curSession );
m_curSession = m_sessions.first();
tabWidget()->setCurrent( m_curSession );
}
/*
* We will get the name
* Then the profile
* and then we will make a profile
*/
void MainWindow::slotProfile( int id) {
Profile prof = manager()->profile( m_sessionsPop->text( id) );
create( prof );
}
void MainWindow::create( const Profile& prof ) {
Session *ses = manager()->fromProfile( prof, tabWidget() );
m_sessions.append( ses );
tabWidget()->add( ses );
m_curSession = ses;
}
void MainWindow::slotTransfer()
{
if ( currentSession() ) {
TransferDialog dlg(this);
- dlg.showMaximized();
+ //dlg.showMaximized();
dlg.exec();
}
}
void MainWindow::slotOpenKeb(bool state) {
if (state) m_keyBar->show();
else m_keyBar->hide();
}
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp
index ba06199..d3b9c0a 100644
--- a/noncore/apps/opie-console/transferdialog.cpp
+++ b/noncore/apps/opie-console/transferdialog.cpp
@@ -1,187 +1,218 @@
#include <qlayout.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qprogressbar.h>
+#include <qradiobutton.h>
+#include <qbuttongroup.h>
#include <opie/ofiledialog.h>
#include "filetransfer.h"
#include "io_serial.h"
#include "metafactory.h"
#include "mainwindow.h"
#include "transferdialog.h"
-
-
-
-
-
-
TransferDialog::TransferDialog(MainWindow *parent, const char *name)
-: QDialog(/*parent, name*/0l, 0l, true), m_win(parent)
+: QDialog(0l, 0l, true), m_win(parent)
{
- m_lay = 0l;
- QVBoxLayout *vbox;
- QHBoxLayout *hbox, *hbox2;
+ m_lay = 0l;
+ QVBoxLayout *vbox, *vbox2;
+ QHBoxLayout *hbox, *hbox2, *hbox3;
QLabel *file, *mode, *progress, *status;
- QPushButton *selector;
-
+ QButtonGroup *group;
+ QRadioButton *mode_send, *mode_receive;
+
+ 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 mode"), 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 = new QLabel(QObject::tr("Ready"), this);
statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken);
protocol = new QComboBox(this);
- /* use the fscking MetaFactory
- * because we invented it for that fscking reason
- * I'm really getting UPSET!!!!
- */
- QStringList list = m_win->factory()->fileTransferLayers();
- for (QStringList::Iterator it =list.begin(); it != list.end(); ++it ) {
- protocol->insertItem( (*it) );
- }
+ QStringList list = m_win->factory()->fileTransferLayers();
+ for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
+ protocol->insertItem((*it));
filename = new QLineEdit(this);
progressbar = new QProgressBar(this);
progressbar->setProgress(0);
selector = new QPushButton("...", this);
ok = new QPushButton(QObject::tr("Start transfer"), this);
cancel = new QPushButton(QObject::tr("Cancel"), this);
vbox = new QVBoxLayout(this, 2);
+ vbox->add(group);
vbox->add(file);
hbox = new QHBoxLayout(vbox, 0);
hbox->add(filename);
hbox->add(selector);
vbox->add(mode);
vbox->add(protocol);
vbox->add(progress);
vbox->add(progressbar);
vbox->add(status);
vbox->add(statusbar);
vbox->addStretch(1);
hbox2 = new QHBoxLayout(vbox, 2);
hbox2->add(ok);
hbox2->add(cancel);
setCaption(QObject::tr("File transfer"));
show();
connect(selector, SIGNAL(clicked()), SLOT(slotFilename()));
connect(ok, SIGNAL(clicked()), SLOT(slotTransfer()));
connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
+ connect(group, SIGNAL(clicked(int)), SLOT(slotMode(int)));
}
TransferDialog::~TransferDialog()
{
}
void TransferDialog::slotFilename()
{
QString f;
f = OFileDialog::getOpenFileName(0);
if(!f.isNull()) filename->setText(f);
}
void TransferDialog::slotTransfer()
{
- if(filename->text().isEmpty())
+ 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);
- statusbar->setText(QObject::tr("Sending..."));
+ if(m_transfermode == id_send) statusbar->setText(QObject::tr("Sending..."));
+ else statusbar->setText(QObject::tr("Receiving..."));
- m_lay = m_win->factory()->newFileTransfer( protocol->currentText(),
- m_win->currentSession()->layer() );
- m_lay->sendFile(filename->text());
+ m_lay = m_win->factory()->newFileTransfer(protocol->currentText(), m_win->currentSession()->layer());
+ if(m_transfermode == id_send)
+ {
+ m_lay->sendFile(filename->text());
+ }
+ else
+ {
+ }
- 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(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()));
}
void TransferDialog::slotCancel()
{
ok->setEnabled(true);
+ statusbar->setText(QObject::tr("Ready"));
if(m_lay)
{
m_lay->cancel();
- delete m_lay;
+ delete m_lay;
m_lay = 0l;
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:
QMessageBox::critical(this,
QObject::tr("Error"),
- QObject::tr("Operation not supported."));
+ QObject::tr("Transfer could not be started."));
break;
case FileTransferLayer::NoError:
QMessageBox::critical(this,
QObject::tr("Error"),
- QObject::tr("Operation not supported."));
+ QObject::tr("No error."));
break;
case FileTransferLayer::Undefined:
QMessageBox::critical(this,
QObject::tr("Error"),
- QObject::tr("Operation not supported."));
+ QObject::tr("Undefined error occured."));
break;
case FileTransferLayer::Incomplete:
QMessageBox::critical(this,
QObject::tr("Error"),
- QObject::tr("Operation not supported."));
+ QObject::tr("Incomplete transfer."));
break;
case FileTransferLayer::Unknown:
default:
QMessageBox::critical(this,
QObject::tr("Error"),
- QObject::tr("Operation not supported."));
+ QObject::tr("Unknown error occured."));
break;
}
}
void TransferDialog::slotSent()
{
QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent."));
ok->setEnabled(true);
+ statusbar->setText(QObject::tr("Ready"));
+}
+
+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 b0c1a76..a567161 100644
--- a/noncore/apps/opie-console/transferdialog.h
+++ b/noncore/apps/opie-console/transferdialog.h
@@ -1,40 +1,48 @@
#ifndef TRANSFER_DIALOG_H
#define TRANSFER_DIALOG_H
#include "qdialog.h"
class QLineEdit;
class QComboBox;
class QProgressBar;
class QLabel;
class QPushButton;
class MainWindow;
class FileTransferLayer;
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 slotMode(int id);
private:
+ enum Modes
+ {
+ id_send,
+ id_receive
+ };
+
QLineEdit *filename;
QComboBox *protocol;
QProgressBar *progressbar;
QLabel *statusbar;
- QPushButton *ok, *cancel;
- MainWindow* m_win;
- FileTransferLayer* m_lay;
+ QPushButton *ok, *cancel, *selector;
+ MainWindow* m_win;
+ FileTransferLayer* m_lay;
+ int m_transfermode;
};
#endif