summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp3
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp2
-rw-r--r--noncore/apps/opie-console/metafactory.cpp9
-rw-r--r--noncore/apps/opie-console/metafactory.h1
-rw-r--r--noncore/apps/opie-console/test/senderui.cpp2
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp68
-rw-r--r--noncore/apps/opie-console/transferdialog.h8
7 files changed, 59 insertions, 34 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index b39dc95..8e86ebb 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -130,121 +130,124 @@ void FileTransfer::sendFile( const QFile& file ) {
* setting up communication
* between parent child and ioLayer
*/
void FileTransfer::setupChild() {
/*
* we do not want to read from our
* information channel
*/
if (m_info[0] )
close(m_info[0] );
/*
* FD_CLOEXEC will close the
* fd on successfull exec
*/
if (m_info[1] )
fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
if (m_comm[0] )
close( m_comm[0] );
/*
* now set the communication
* m_fd STDIN_FILENO
* STDOUT_FILENO
* STDERR_FILENO
*/
dup2( m_fd, STDIN_FILENO );
dup2( m_fd, STDOUT_FILENO );
dup2( m_comm[1], STDERR_FILENO );
}
/*
* read from the stderr of the child
* process
*/
void FileTransfer::slotRead() {
QByteArray ar(4096);
int len = read(m_comm[0], ar.data(), 4096 );
qWarning("slot read %d", len);
for (int i = 0; i < len; i++ ) {
// printf("%c", ar[i] );
}
ar.resize( len );
QString str( ar );
qWarning(str.simplifyWhiteSpace() );
QStringList lis = QStringList::split(' ', str );
/*
* Transfer finished.. either complete or incomplete
*/
if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
qWarning("sent!!!!");
emit sent();
return;
}
/*
* do progress reading
*/
slotProgress( lis );
}
/*
* 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 );
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 fbeaa74..88727e4 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -165,69 +165,71 @@ void MainWindow::slotDisconnect() {
if ( currentSession() )
currentSession()->layer()->close();
}
void MainWindow::slotTerminate() {
if ( currentSession() )
currentSession()->layer()->close();
slotClose();
/* FIXME move to the next session */
}
void MainWindow::slotConfigure() {
qWarning("configure");
ConfigDialog conf( manager()->all(), factory() );
conf.showMaximized();
int ret = conf.exec();
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.exec();
}
+}
diff --git a/noncore/apps/opie-console/metafactory.cpp b/noncore/apps/opie-console/metafactory.cpp
index 2b672cf..901f29f 100644
--- a/noncore/apps/opie-console/metafactory.cpp
+++ b/noncore/apps/opie-console/metafactory.cpp
@@ -65,75 +65,84 @@ QStringList MetaFactory::fileTransferLayers()const {
QMap<QString, filelayer>::ConstIterator it;
for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) {
list << it.key();
}
return list;
}
QStringList MetaFactory::emulationLayers()const {
QStringList list;
QMap<QString, emulationLayer>::ConstIterator it;
for ( it = m_emu.begin(); it != m_emu.end(); ++it ) {
list << it.key();
}
return list;
}
IOLayer* MetaFactory::newIOLayer( const QString& str,const Profile& prof ) {
IOLayer* lay = 0l;
QMap<QString, iolayer>::Iterator it;
it = m_layerFact.find( str );
if ( it != m_layerFact.end() ) {
lay = (*(it.data()))(prof);
/*
iolayer laye = it.data();
lay = (*laye )(conf);*/
}
return lay;
}
ProfileDialogWidget *MetaFactory::newConnectionPlugin ( const QString& str, QWidget *parent) {
ProfileDialogWidget* wid = 0l;
QMap<QString, configWidget>::Iterator it;
it = m_conFact.find( str );
if ( it != m_conFact.end() ) {
wid = (*(it.data() ) )(str,parent);
}
return wid;
}
ProfileDialogWidget *MetaFactory::newTerminalPlugin( const QString& str, QWidget *parent) {
if (str.isEmpty() )
return 0l;
ProfileDialogWidget* wid = 0l;
qWarning("new terminalPlugin %s %l", str.latin1(), parent );
QMap<QString, configWidget>::Iterator it;
it = m_termFact.find( str );
if ( it != m_termFact.end() ) {
wid = (*(it.data() ) )(str,parent);
}
return wid;
}
EmulationLayer* MetaFactory::newEmulationLayer( const QString& str, WidgetLayer* wid) {
EmulationLayer* lay = 0l;
QMap<QString, emulationLayer>::Iterator it;
it = m_emu.find( str );
if ( it != m_emu.end() ) {
lay = (*(it.data() ) )(wid);
}
return lay;
}
+FileTransferLayer* MetaFactory::newFileTransfer(const QString& str, IOLayer* lay ) {
+ FileTransferLayer* file = 0l;
+ QMap<QString, filelayer>::Iterator it;
+ it = m_fileFact.find( str );
+ if ( it != m_fileFact.end() ) {
+ file = (*(it.data() ) )(lay);
+ }
+ return file;
+}
QCString MetaFactory::internal( const QString& str )const {
return m_strings[str];
}
QString MetaFactory::external( const QCString& str )const {
QMap<QString, QCString>::ConstIterator it;
for ( it = m_strings.begin(); it != m_strings.end(); ++it ) {
if ( it.data() == str )
return it.key();
}
return QString::null;
}
diff --git a/noncore/apps/opie-console/metafactory.h b/noncore/apps/opie-console/metafactory.h
index d05ece4..7f0699b 100644
--- a/noncore/apps/opie-console/metafactory.h
+++ b/noncore/apps/opie-console/metafactory.h
@@ -17,90 +17,91 @@
#include "profiledialogwidget.h"
#include "emulation_layer.h"
class WidgetLayer;
class MetaFactory {
public:
typedef ProfileDialogWidget* (*configWidget)(const QString&, QWidget* parent);
typedef IOLayer* (*iolayer)(const Profile& );
typedef FileTransferLayer* (*filelayer)(IOLayer*);
typedef EmulationLayer* (*emulationLayer)(WidgetLayer* );
MetaFactory();
~MetaFactory();
/**
* add a ProfileDialogWidget to the factory
* name is the name shown to the user
*/
void addConnectionWidgetFactory( const QCString& internalName,
const QString& uiString,
configWidget );
void addTerminalWidgetFactory ( const QCString& internalName,
const QString& name,
configWidget );
/**
* adds an IOLayer factory
*/
void addIOLayerFactory( const QCString&,
const QString&,
iolayer );
/**
* adds a FileTransfer Layer
*/
void addFileTransferLayer( const QCString& name,
const QString&,
filelayer );
/**
* adds a Factory for Emulation to the Layer..
*/
void addEmulationLayer ( const QCString& name,
const QString& uiString,
emulationLayer );
/* translated UI Strings */
QStringList ioLayers()const;
QStringList connectionWidgets()const;
/**
* Terminal Configuration widgets
*/
QStringList terminalWidgets()const;
QStringList fileTransferLayers()const;
QStringList emulationLayers()const;
/**
* the generation...
*/
IOLayer* newIOLayer( const QString&,const Profile& );
ProfileDialogWidget *newConnectionPlugin ( const QString&, QWidget* );
ProfileDialogWidget* newTerminalPlugin( const QString&, QWidget* );
EmulationLayer* newEmulationLayer(const QString&, WidgetLayer* );
+ FileTransferLayer* newFileTransfer(const QString&, IOLayer* );
/*
* internal takes the maybe translated
* public QString and maps it to the internal
* not translatable QCString
*/
QCString internal( const QString& )const;
/*
* external takes the internal name
* it returns a translated name
*/
QString external( const QCString& )const;
private:
QMap<QString, QCString> m_strings;
QMap<QString, configWidget> m_conFact;
QMap<QString, configWidget> m_termFact;
QMap<QString, iolayer> m_layerFact;
QMap<QString, filelayer> m_fileFact;
QMap<QString, emulationLayer> m_emu;
};
#endif
diff --git a/noncore/apps/opie-console/test/senderui.cpp b/noncore/apps/opie-console/test/senderui.cpp
index 3e0bd65..8bc1676 100644
--- a/noncore/apps/opie-console/test/senderui.cpp
+++ b/noncore/apps/opie-console/test/senderui.cpp
@@ -1,68 +1,68 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/termios.h>
#include <qmultilineedit.h>
#include <qsocketnotifier.h>
#include "../profile.h"
#include "../io_serial.h"
#include "../filetransfer.h"
#include <opie/oprocess.h>
#include "senderui.h"
SenderUI::SenderUI()
: Sender() {
/* we do that manually */
Profile prof;
QString str = "/dev/ttyS0";
prof.writeEntry("Device",str );
prof.writeEntry("Baud", 115200 );
qWarning("prof " + prof.readEntry("Device") + " " + str);
ser = new IOSerial(prof);
connect(ser, SIGNAL(received(const QByteArray& ) ),
this, SLOT(got(const QByteArray&) ) );
if ( ser->open() )
qWarning("opened!!!");
else
qWarning("could not open");
}
SenderUI::~SenderUI() {
}
void SenderUI::slotSendFile() {
- sz = new FileTransfer(FileTransfer::SZ, ser);
+ sz = new FileTransfer(FileTransfer::SY, ser);
sz->sendFile("/home/ich/bootopie-v06-13.jffs2");
connect (sz, SIGNAL(sent()),
this, SLOT(fileTransComplete()));
}
void SenderUI::slotSend() {
QCString str = MultiLineEdit1->text().utf8();
qWarning("sending: %s", str.data() );
ser->send( str );
}
void SenderUI::got(const QByteArray& ar) {
for ( uint i = 0; i < ar.count(); i++ ) {
printf("%c", ar[i] );
}
//printf("\n");
}
void SenderUI::fileTransComplete() {
qWarning("file transfer complete");
}
void SenderUI::send() {
}
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp
index d639de6..ba06199 100644
--- a/noncore/apps/opie-console/transferdialog.cpp
+++ b/noncore/apps/opie-console/transferdialog.cpp
@@ -1,179 +1,187 @@
-#include "transferdialog.h"
+#include <qlayout.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qmessagebox.h>
+#include <qprogressbar.h>
+
+#include <opie/ofiledialog.h>
#include "filetransfer.h"
#include "io_serial.h"
+#include "metafactory.h"
+#include "mainwindow.h"
+
+#include "transferdialog.h"
+
-#include "qlayout.h"
-#include "qcombobox.h"
-#include "qlabel.h"
-#include "qlineedit.h"
-#include "qpushbutton.h"
-#include "qmessagebox.h"
-#include "qprogressbar.h"
-#include "opie/ofiledialog.h"
-TransferDialog::TransferDialog(QWidget *parent, const char *name)
-: QDialog(/*parent, name*/NULL, NULL, true)
+
+
+
+TransferDialog::TransferDialog(MainWindow *parent, const char *name)
+: QDialog(/*parent, name*/0l, 0l, true), m_win(parent)
{
+ m_lay = 0l;
QVBoxLayout *vbox;
QHBoxLayout *hbox, *hbox2;
QLabel *file, *mode, *progress, *status;
QPushButton *selector;
- transfer = NULL;
file = new QLabel(QObject::tr("Send file"), this);
mode = new QLabel(QObject::tr("Transfer mode"), 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);
- protocol->insertItem("XModem");
- protocol->insertItem("YModem");
- protocol->insertItem("ZModem");
+ /* 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) );
+ }
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(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()));
}
TransferDialog::~TransferDialog()
{
}
void TransferDialog::slotFilename()
{
QString f;
f = OFileDialog::getOpenFileName(0);
if(!f.isNull()) filename->setText(f);
}
void TransferDialog::slotTransfer()
{
if(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..."));
- FileTransfer::Type transfermode = FileTransfer::SX;
- if(protocol->currentText() == "YModem") transfermode == FileTransfer::SY;
- if(protocol->currentText() == "ZModem") transfermode == FileTransfer::SZ;
-
- // dummy profile
- Profile profile("Dummy", "serial", "vt102", Profile::White, Profile::Black, Profile::VT102);
+ m_lay = m_win->factory()->newFileTransfer( protocol->currentText(),
+ m_win->currentSession()->layer() );
+ m_lay->sendFile(filename->text());
- transfer = new FileTransfer(transfermode, new IOSerial(profile));
- transfer->sendFile(filename->text());
- connect(transfer, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int)));
- connect(transfer, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
- connect(transfer, SIGNAL(sent()), SLOT(slotSent()));
+ 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);
- if(transfer)
+ if(m_lay)
{
- transfer->cancel();
- delete transfer;
- transfer = NULL;
+ m_lay->cancel();
+ 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)
{
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."));
break;
case FileTransferLayer::NoError:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Operation not supported."));
break;
case FileTransferLayer::Undefined:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Operation not supported."));
break;
case FileTransferLayer::Incomplete:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Operation not supported."));
break;
case FileTransferLayer::Unknown:
default:
QMessageBox::critical(this,
QObject::tr("Error"),
QObject::tr("Operation not supported."));
break;
}
}
void TransferDialog::slotSent()
{
QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent."));
ok->setEnabled(true);
}
diff --git a/noncore/apps/opie-console/transferdialog.h b/noncore/apps/opie-console/transferdialog.h
index 61f425c..b0c1a76 100644
--- a/noncore/apps/opie-console/transferdialog.h
+++ b/noncore/apps/opie-console/transferdialog.h
@@ -1,38 +1,40 @@
#ifndef TRANSFER_DIALOG_H
#define TRANSFER_DIALOG_H
#include "qdialog.h"
class QLineEdit;
class QComboBox;
class QProgressBar;
class QLabel;
class QPushButton;
-class FileTransfer;
+class MainWindow;
+class FileTransferLayer;
class TransferDialog : public QDialog
{
Q_OBJECT
public:
- TransferDialog(QWidget *parent = NULL, const char *name = NULL);
+ 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();
private:
QLineEdit *filename;
QComboBox *protocol;
QProgressBar *progressbar;
QLabel *statusbar;
QPushButton *ok, *cancel;
- FileTransfer *transfer;
+ MainWindow* m_win;
+ FileTransferLayer* m_lay;
};
#endif