summaryrefslogtreecommitdiff
path: root/noncore
authorzecke <zecke>2002-10-12 21:18:46 (UTC)
committer zecke <zecke>2002-10-12 21:18:46 (UTC)
commit9b33ff5f74c30a5a4905093715a6f345edee26ab (patch) (unidiff)
treeeb0155744adb8c0901e27e001c7e09fc8c789369 /noncore
parent3eb9678dfab4d152858b7f72c7f0c057fe393541 (diff)
downloadopie-9b33ff5f74c30a5a4905093715a6f345edee26ab.zip
opie-9b33ff5f74c30a5a4905093715a6f345edee26ab.tar.gz
opie-9b33ff5f74c30a5a4905093715a6f345edee26ab.tar.bz2
Calmed down... 2nd try after merge
Use MetaFactory cuase it's so nice and avoids thousands of if() else if stuff Fix a bug in filetransfer where cancel after exit leaded to a crash cause of bogus adresses in the QSocketNotifiers..
Diffstat (limited to 'noncore') (more/less context) (ignore 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.cpp70
-rw-r--r--noncore/apps/opie-console/transferdialog.h8
7 files changed, 60 insertions, 35 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
@@ -182,24 +182,26 @@ void FileTransfer::slotRead() {
182 } 182 }
183 /* 183 /*
184 * do progress reading 184 * do progress reading
185 */ 185 */
186 slotProgress( lis ); 186 slotProgress( lis );
187 187
188 188
189} 189}
190/* 190/*
191 * find the progress 191 * find the progress
192 */ 192 */
193void FileTransfer::slotProgress( const QStringList& list ) { 193void FileTransfer::slotProgress( const QStringList& list ) {
194 if ( m_type != SZ )
195 return;
194 bool complete = true; 196 bool complete = true;
195 int min, sec; 197 int min, sec;
196 int bps; 198 int bps;
197 unsigned long sent, total; 199 unsigned long sent, total;
198 200
199 min = sec = bps = -1; 201 min = sec = bps = -1;
200 sent = total = 0; 202 sent = total = 0;
201 203
202 // Data looks like this 204 // Data looks like this
203 // 0 1 2 3 4 5 205 // 0 1 2 3 4 5
204 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 206 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
205 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); 207 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
@@ -233,18 +235,19 @@ void FileTransfer::slotProgress( const QStringList& list ) {
233 235
234} 236}
235void FileTransfer::cancel() { 237void FileTransfer::cancel() {
236 ::kill(m_pid,9 ); 238 ::kill(m_pid,9 );
237 delete m_not; 239 delete m_not;
238} 240}
239void FileTransfer::slotExec() { 241void FileTransfer::slotExec() {
240 qWarning("exited!"); 242 qWarning("exited!");
241 char buf[2]; 243 char buf[2];
242 ::read(m_term[0], buf, 1 ); 244 ::read(m_term[0], buf, 1 );
243 delete m_proc; 245 delete m_proc;
244 delete m_not; 246 delete m_not;
247 m_proc = m_not = 0l;
245 close( m_term[0] ); 248 close( m_term[0] );
246 close( m_term[1] ); 249 close( m_term[1] );
247 close( m_comm[0] ); 250 close( m_comm[0] );
248 close( m_comm[1] ); 251 close( m_comm[1] );
249 emit sent(); 252 emit sent();
250} 253}
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
@@ -217,17 +217,19 @@ void MainWindow::slotProfile( int id) {
217} 217}
218void MainWindow::create( const Profile& prof ) { 218void MainWindow::create( const Profile& prof ) {
219 Session *ses = manager()->fromProfile( prof, tabWidget() ); 219 Session *ses = manager()->fromProfile( prof, tabWidget() );
220 220
221 m_sessions.append( ses ); 221 m_sessions.append( ses );
222 tabWidget()->add( ses ); 222 tabWidget()->add( ses );
223 m_curSession = ses; 223 m_curSession = ses;
224 224
225} 225}
226 226
227void MainWindow::slotTransfer() 227void MainWindow::slotTransfer()
228{ 228{
229 if ( currentSession() ) {
229 TransferDialog dlg(this); 230 TransferDialog dlg(this);
230 dlg.showMaximized(); 231 dlg.showMaximized();
231 dlg.exec(); 232 dlg.exec();
233 }
232} 234}
233 235
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
@@ -117,23 +117,32 @@ ProfileDialogWidget *MetaFactory::newTerminalPlugin( const QString& str, QWidget
117} 117}
118EmulationLayer* MetaFactory::newEmulationLayer( const QString& str, WidgetLayer* wid) { 118EmulationLayer* MetaFactory::newEmulationLayer( const QString& str, WidgetLayer* wid) {
119 EmulationLayer* lay = 0l; 119 EmulationLayer* lay = 0l;
120 120
121 QMap<QString, emulationLayer>::Iterator it; 121 QMap<QString, emulationLayer>::Iterator it;
122 it = m_emu.find( str ); 122 it = m_emu.find( str );
123 if ( it != m_emu.end() ) { 123 if ( it != m_emu.end() ) {
124 lay = (*(it.data() ) )(wid); 124 lay = (*(it.data() ) )(wid);
125 } 125 }
126 126
127 return lay; 127 return lay;
128} 128}
129FileTransferLayer* MetaFactory::newFileTransfer(const QString& str, IOLayer* lay ) {
130 FileTransferLayer* file = 0l;
131 QMap<QString, filelayer>::Iterator it;
132 it = m_fileFact.find( str );
133 if ( it != m_fileFact.end() ) {
134 file = (*(it.data() ) )(lay);
135 }
136 return file;
137}
129QCString MetaFactory::internal( const QString& str )const { 138QCString MetaFactory::internal( const QString& str )const {
130 return m_strings[str]; 139 return m_strings[str];
131} 140}
132QString MetaFactory::external( const QCString& str )const { 141QString MetaFactory::external( const QCString& str )const {
133 QMap<QString, QCString>::ConstIterator it; 142 QMap<QString, QCString>::ConstIterator it;
134 for ( it = m_strings.begin(); it != m_strings.end(); ++it ) { 143 for ( it = m_strings.begin(); it != m_strings.end(); ++it ) {
135 if ( it.data() == str ) 144 if ( it.data() == str )
136 return it.key(); 145 return it.key();
137 } 146 }
138 return QString::null; 147 return QString::null;
139} 148}
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
@@ -69,24 +69,25 @@ public:
69 */ 69 */
70 QStringList terminalWidgets()const; 70 QStringList terminalWidgets()const;
71 QStringList fileTransferLayers()const; 71 QStringList fileTransferLayers()const;
72 QStringList emulationLayers()const; 72 QStringList emulationLayers()const;
73 73
74 /** 74 /**
75 * the generation... 75 * the generation...
76 */ 76 */
77 IOLayer* newIOLayer( const QString&,const Profile& ); 77 IOLayer* newIOLayer( const QString&,const Profile& );
78 ProfileDialogWidget *newConnectionPlugin ( const QString&, QWidget* ); 78 ProfileDialogWidget *newConnectionPlugin ( const QString&, QWidget* );
79 ProfileDialogWidget* newTerminalPlugin( const QString&, QWidget* ); 79 ProfileDialogWidget* newTerminalPlugin( const QString&, QWidget* );
80 EmulationLayer* newEmulationLayer(const QString&, WidgetLayer* ); 80 EmulationLayer* newEmulationLayer(const QString&, WidgetLayer* );
81 FileTransferLayer* newFileTransfer(const QString&, IOLayer* );
81 82
82 /* 83 /*
83 * internal takes the maybe translated 84 * internal takes the maybe translated
84 * public QString and maps it to the internal 85 * public QString and maps it to the internal
85 * not translatable QCString 86 * not translatable QCString
86 */ 87 */
87 QCString internal( const QString& )const; 88 QCString internal( const QString& )const;
88 89
89 /* 90 /*
90 * external takes the internal name 91 * external takes the internal name
91 * it returns a translated name 92 * it returns a translated name
92 */ 93 */
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
@@ -31,25 +31,25 @@ SenderUI::SenderUI()
31 if ( ser->open() ) 31 if ( ser->open() )
32 qWarning("opened!!!"); 32 qWarning("opened!!!");
33 else 33 else
34 qWarning("could not open"); 34 qWarning("could not open");
35 35
36 36
37} 37}
38SenderUI::~SenderUI() { 38SenderUI::~SenderUI() {
39 39
40} 40}
41void SenderUI::slotSendFile() { 41void SenderUI::slotSendFile() {
42 42
43 sz = new FileTransfer(FileTransfer::SZ, ser); 43 sz = new FileTransfer(FileTransfer::SY, ser);
44 sz->sendFile("/home/ich/bootopie-v06-13.jffs2"); 44 sz->sendFile("/home/ich/bootopie-v06-13.jffs2");
45 45
46 connect (sz, SIGNAL(sent()), 46 connect (sz, SIGNAL(sent()),
47 this, SLOT(fileTransComplete())); 47 this, SLOT(fileTransComplete()));
48} 48}
49 49
50void SenderUI::slotSend() { 50void SenderUI::slotSend() {
51 QCString str = MultiLineEdit1->text().utf8(); 51 QCString str = MultiLineEdit1->text().utf8();
52 qWarning("sending: %s", str.data() ); 52 qWarning("sending: %s", str.data() );
53 ser->send( str ); 53 ser->send( str );
54} 54}
55void SenderUI::got(const QByteArray& ar) { 55void SenderUI::got(const QByteArray& ar) {
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,49 +1,62 @@
1#include "transferdialog.h" 1#include <qlayout.h>
2#include <qcombobox.h>
3#include <qlabel.h>
4#include <qlineedit.h>
5#include <qpushbutton.h>
6#include <qmessagebox.h>
7#include <qprogressbar.h>
8
9#include <opie/ofiledialog.h>
2 10
3#include "filetransfer.h" 11#include "filetransfer.h"
4#include "io_serial.h" 12#include "io_serial.h"
13#include "metafactory.h"
14#include "mainwindow.h"
15
16#include "transferdialog.h"
17
5 18
6#include "qlayout.h"
7#include "qcombobox.h"
8#include "qlabel.h"
9#include "qlineedit.h"
10#include "qpushbutton.h"
11#include "qmessagebox.h"
12#include "qprogressbar.h"
13 19
14#include "opie/ofiledialog.h"
15 20
16TransferDialog::TransferDialog(QWidget *parent, const char *name) 21
17: QDialog(/*parent, name*/NULL, NULL, true) 22
23
24TransferDialog::TransferDialog(MainWindow *parent, const char *name)
25: QDialog(/*parent, name*/0l, 0l, true), m_win(parent)
18{ 26{
27 m_lay = 0l;
19 QVBoxLayout *vbox; 28 QVBoxLayout *vbox;
20 QHBoxLayout *hbox, *hbox2; 29 QHBoxLayout *hbox, *hbox2;
21 QLabel *file, *mode, *progress, *status; 30 QLabel *file, *mode, *progress, *status;
22 QPushButton *selector; 31 QPushButton *selector;
23 32
24 transfer = NULL;
25 33
26 file = new QLabel(QObject::tr("Send file"), this); 34 file = new QLabel(QObject::tr("Send file"), this);
27 mode = new QLabel(QObject::tr("Transfer mode"), this); 35 mode = new QLabel(QObject::tr("Transfer mode"), this);
28 progress = new QLabel(QObject::tr("Progress"), this); 36 progress = new QLabel(QObject::tr("Progress"), this);
29 status = new QLabel(QObject::tr("Status"), this); 37 status = new QLabel(QObject::tr("Status"), this);
30 38
31 statusbar = new QLabel(QObject::tr("ready"), this); 39 statusbar = new QLabel(QObject::tr("ready"), this);
32 statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); 40 statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken);
33 41
34 protocol = new QComboBox(this); 42 protocol = new QComboBox(this);
35 protocol->insertItem("XModem"); 43 /* use the fscking MetaFactory
36 protocol->insertItem("YModem"); 44 * because we invented it for that fscking reason
37 protocol->insertItem("ZModem"); 45 * I'm really getting UPSET!!!!
46 */
47 QStringList list = m_win->factory()->fileTransferLayers();
48 for (QStringList::Iterator it =list.begin(); it != list.end(); ++it ) {
49 protocol->insertItem( (*it) );
50 }
38 51
39 filename = new QLineEdit(this); 52 filename = new QLineEdit(this);
40 53
41 progressbar = new QProgressBar(this); 54 progressbar = new QProgressBar(this);
42 progressbar->setProgress(0); 55 progressbar->setProgress(0);
43 56
44 selector = new QPushButton("...", this); 57 selector = new QPushButton("...", this);
45 ok = new QPushButton(QObject::tr("Start transfer"), this); 58 ok = new QPushButton(QObject::tr("Start transfer"), this);
46 cancel = new QPushButton(QObject::tr("Cancel"), this); 59 cancel = new QPushButton(QObject::tr("Cancel"), this);
47 60
48 vbox = new QVBoxLayout(this, 2); 61 vbox = new QVBoxLayout(this, 2);
49 vbox->add(file); 62 vbox->add(file);
@@ -67,66 +80,61 @@ TransferDialog::TransferDialog(QWidget *parent, const char *name)
67 connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); 80 connect(selector, SIGNAL(clicked()), SLOT(slotFilename()));
68 connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); 81 connect(ok, SIGNAL(clicked()), SLOT(slotTransfer()));
69 connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); 82 connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
70} 83}
71 84
72TransferDialog::~TransferDialog() 85TransferDialog::~TransferDialog()
73{ 86{
74} 87}
75 88
76void TransferDialog::slotFilename() 89void TransferDialog::slotFilename()
77{ 90{
78 QString f; 91 QString f;
79 92
80 f = OFileDialog::getOpenFileName(0); 93 f = OFileDialog::getOpenFileName(0);
81 if(!f.isNull()) filename->setText(f); 94 if(!f.isNull()) filename->setText(f);
82} 95}
83 96
84void TransferDialog::slotTransfer() 97void TransferDialog::slotTransfer()
85{ 98{
86 if(filename->text().isEmpty()) 99 if(filename->text().isEmpty())
87 { 100 {
88 QMessageBox::information(this, 101 QMessageBox::information(this,
89 QObject::tr("Attention"), 102 QObject::tr("Attention"),
90 QObject::tr("No file has been specified.")); 103 QObject::tr("No file has been specified."));
91 return; 104 return;
92 } 105 }
93 106
94 ok->setEnabled(false); 107 ok->setEnabled(false);
95 108
96 statusbar->setText(QObject::tr("Sending...")); 109 statusbar->setText(QObject::tr("Sending..."));
97 110
98 FileTransfer::Type transfermode = FileTransfer::SX; 111 m_lay = m_win->factory()->newFileTransfer( protocol->currentText(),
99 if(protocol->currentText() == "YModem") transfermode == FileTransfer::SY; 112 m_win->currentSession()->layer() );
100 if(protocol->currentText() == "ZModem") transfermode == FileTransfer::SZ; 113 m_lay->sendFile(filename->text());
101
102 // dummy profile
103 Profile profile("Dummy", "serial", "vt102", Profile::White, Profile::Black, Profile::VT102);
104 114
105 transfer = new FileTransfer(transfermode, new IOSerial(profile)); 115 connect(m_lay, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int)));
106 transfer->sendFile(filename->text()); 116 connect(m_lay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
107 connect(transfer, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); 117 connect(m_lay, SIGNAL(sent()), SLOT(slotSent()));
108 connect(transfer, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&)));
109 connect(transfer, SIGNAL(sent()), SLOT(slotSent()));
110} 118}
111 119
112void TransferDialog::slotCancel() 120void TransferDialog::slotCancel()
113{ 121{
114 ok->setEnabled(true); 122 ok->setEnabled(true);
115 123
116 if(transfer) 124 if(m_lay)
117 { 125 {
118 transfer->cancel(); 126 m_lay->cancel();
119 delete transfer; 127 delete m_lay;
120 transfer = NULL; 128 m_lay = 0l;
121 QMessageBox::information(this, 129 QMessageBox::information(this,
122 QObject::tr("Cancelled"), 130 QObject::tr("Cancelled"),
123 QObject::tr("The file transfer has been cancelled.")); 131 QObject::tr("The file transfer has been cancelled."));
124 } 132 }
125 else 133 else
126 { 134 {
127 close(); 135 close();
128 } 136 }
129} 137}
130 138
131void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds) 139void TransferDialog::slotProgress(const QString& file, int progress, int speed, int hours, int minutes, int seconds)
132{ 140{
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 @@
1#ifndef TRANSFER_DIALOG_H 1#ifndef TRANSFER_DIALOG_H
2#define TRANSFER_DIALOG_H 2#define TRANSFER_DIALOG_H
3 3
4#include "qdialog.h" 4#include "qdialog.h"
5 5
6class QLineEdit; 6class QLineEdit;
7class QComboBox; 7class QComboBox;
8class QProgressBar; 8class QProgressBar;
9class QLabel; 9class QLabel;
10class QPushButton; 10class QPushButton;
11class FileTransfer; 11class MainWindow;
12class FileTransferLayer;
12 13
13class TransferDialog : public QDialog 14class TransferDialog : public QDialog
14{ 15{
15 Q_OBJECT 16 Q_OBJECT
16 public: 17 public:
17 TransferDialog(QWidget *parent = NULL, const char *name = NULL); 18 TransferDialog(MainWindow *parent = 0l, const char *name = 0l);
18 ~TransferDialog(); 19 ~TransferDialog();
19 20
20 public slots: 21 public slots:
21 void slotFilename(); 22 void slotFilename();
22 void slotTransfer(); 23 void slotTransfer();
23 void slotCancel(); 24 void slotCancel();
24 void slotProgress(const QString&, int, int, int, int, int); 25 void slotProgress(const QString&, int, int, int, int, int);
25 void slotError(int error, const QString& message); 26 void slotError(int error, const QString& message);
26 void slotSent(); 27 void slotSent();
27 28
28 private: 29 private:
29 QLineEdit *filename; 30 QLineEdit *filename;
30 QComboBox *protocol; 31 QComboBox *protocol;
31 QProgressBar *progressbar; 32 QProgressBar *progressbar;
32 QLabel *statusbar; 33 QLabel *statusbar;
33 QPushButton *ok, *cancel; 34 QPushButton *ok, *cancel;
34 FileTransfer *transfer; 35 MainWindow* m_win;
36 FileTransferLayer* m_lay;
35}; 37};
36 38
37#endif 39#endif
38 40