summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-12 21:18:46 (UTC)
committer zecke <zecke>2002-10-12 21:18:46 (UTC)
commit9b33ff5f74c30a5a4905093715a6f345edee26ab (patch) (unidiff)
treeeb0155744adb8c0901e27e001c7e09fc8c789369
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 (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
@@ -98,153 +98,156 @@ void FileTransfer::sendFile( const QString& file ) {
98 // len == 0 or something like this 98 // len == 0 or something like this
99 break; 99 break;
100 } 100 }
101 if ( m_info[0] ) 101 if ( m_info[0] )
102 close( m_info[0] ); 102 close( m_info[0] );
103 103
104 104
105 105
106 /* replace by QSocketNotifier!!! */ 106 /* replace by QSocketNotifier!!! */
107 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); 107 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
108 connect(m_not, SIGNAL(activated(int) ), 108 connect(m_not, SIGNAL(activated(int) ),
109 this, SLOT(slotRead() ) ); 109 this, SLOT(slotRead() ) );
110 if ( pipe(m_term) < 0 ) 110 if ( pipe(m_term) < 0 )
111 m_term[0] = m_term[1] = 0; 111 m_term[0] = m_term[1] = 0;
112 112
113 ProcCtl::self()->add(m_pid, m_term[1] ); 113 ProcCtl::self()->add(m_pid, m_term[1] );
114 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); 114 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
115 connect(m_proc, SIGNAL(activated(int) ), 115 connect(m_proc, SIGNAL(activated(int) ),
116 this, SLOT(slotExec() ) ); 116 this, SLOT(slotExec() ) );
117 117
118 } 118 }
119 break; 119 break;
120 } 120 }
121} 121}
122/* 122/*
123 * let's call the one with the filename 123 * let's call the one with the filename
124 */ 124 */
125void FileTransfer::sendFile( const QFile& file ) { 125void FileTransfer::sendFile( const QFile& file ) {
126 sendFile( file.name() ); 126 sendFile( file.name() );
127} 127}
128 128
129/* 129/*
130 * setting up communication 130 * setting up communication
131 * between parent child and ioLayer 131 * between parent child and ioLayer
132 */ 132 */
133void FileTransfer::setupChild() { 133void FileTransfer::setupChild() {
134 /* 134 /*
135 * we do not want to read from our 135 * we do not want to read from our
136 * information channel 136 * information channel
137 */ 137 */
138 if (m_info[0] ) 138 if (m_info[0] )
139 close(m_info[0] ); 139 close(m_info[0] );
140 /* 140 /*
141 * FD_CLOEXEC will close the 141 * FD_CLOEXEC will close the
142 * fd on successfull exec 142 * fd on successfull exec
143 */ 143 */
144 if (m_info[1] ) 144 if (m_info[1] )
145 fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); 145 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
146 146
147 if (m_comm[0] ) 147 if (m_comm[0] )
148 close( m_comm[0] ); 148 close( m_comm[0] );
149 /* 149 /*
150 * now set the communication 150 * now set the communication
151 * m_fd STDIN_FILENO 151 * m_fd STDIN_FILENO
152 * STDOUT_FILENO 152 * STDOUT_FILENO
153 * STDERR_FILENO 153 * STDERR_FILENO
154 */ 154 */
155 dup2( m_fd, STDIN_FILENO ); 155 dup2( m_fd, STDIN_FILENO );
156 dup2( m_fd, STDOUT_FILENO ); 156 dup2( m_fd, STDOUT_FILENO );
157 dup2( m_comm[1], STDERR_FILENO ); 157 dup2( m_comm[1], STDERR_FILENO );
158} 158}
159 159
160/* 160/*
161 * read from the stderr of the child 161 * read from the stderr of the child
162 * process 162 * process
163 */ 163 */
164void FileTransfer::slotRead() { 164void FileTransfer::slotRead() {
165 QByteArray ar(4096); 165 QByteArray ar(4096);
166 int len = read(m_comm[0], ar.data(), 4096 ); 166 int len = read(m_comm[0], ar.data(), 4096 );
167 qWarning("slot read %d", len); 167 qWarning("slot read %d", len);
168 for (int i = 0; i < len; i++ ) { 168 for (int i = 0; i < len; i++ ) {
169 // printf("%c", ar[i] ); 169 // printf("%c", ar[i] );
170 } 170 }
171 ar.resize( len ); 171 ar.resize( len );
172 QString str( ar ); 172 QString str( ar );
173 qWarning(str.simplifyWhiteSpace() ); 173 qWarning(str.simplifyWhiteSpace() );
174 QStringList lis = QStringList::split(' ', str ); 174 QStringList lis = QStringList::split(' ', str );
175 /* 175 /*
176 * Transfer finished.. either complete or incomplete 176 * Transfer finished.. either complete or incomplete
177 */ 177 */
178 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { 178 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
179 qWarning("sent!!!!"); 179 qWarning("sent!!!!");
180 emit sent(); 180 emit sent();
181 return; 181 return;
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() );
206 sent = progi[0].toULong(&complete ); 208 sent = progi[0].toULong(&complete );
207 if (!complete ) return; 209 if (!complete ) return;
208 210
209 total = progi[1].toULong(&complete ); 211 total = progi[1].toULong(&complete );
210 if (!complete || total == 0) { 212 if (!complete || total == 0) {
211 return; 213 return;
212 } 214 }
213 215
214 qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); 216 qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total );
215 217
216 double pro = (double)sent/total; 218 double pro = (double)sent/total;
217 int prog = pro * 100; 219 int prog = pro * 100;
218 220
219 // speed 221 // speed
220 progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); 222 progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
221 bps = progi[1].toInt(); 223 bps = progi[1].toInt();
222 224
223 // time 225 // time
224 progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); 226 progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
225 min = progi[0].toInt(); 227 min = progi[0].toInt();
226 sec = progi[1].toInt(); 228 sec = progi[1].toInt();
227 229
228 230
229 if ( prog > m_prog ) { 231 if ( prog > m_prog ) {
230 m_prog = prog; 232 m_prog = prog;
231 emit progress(m_file, m_prog, bps, -1, min , sec ); 233 emit progress(m_file, m_prog, bps, -1, min , sec );
232 } 234 }
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
@@ -133,101 +133,103 @@ MainWindow::~MainWindow() {
133 delete m_factory; 133 delete m_factory;
134 manager()->save(); 134 manager()->save();
135} 135}
136 136
137MetaFactory* MainWindow::factory() { 137MetaFactory* MainWindow::factory() {
138 return m_factory; 138 return m_factory;
139} 139}
140 140
141Session* MainWindow::currentSession() { 141Session* MainWindow::currentSession() {
142 return m_curSession; 142 return m_curSession;
143} 143}
144 144
145QList<Session> MainWindow::sessions() { 145QList<Session> MainWindow::sessions() {
146 return m_sessions; 146 return m_sessions;
147} 147}
148 148
149void MainWindow::slotNew() { 149void MainWindow::slotNew() {
150 qWarning("New Connection"); 150 qWarning("New Connection");
151 ProfileEditorDialog dlg(factory() ); 151 ProfileEditorDialog dlg(factory() );
152 int ret = dlg.exec(); 152 int ret = dlg.exec();
153 153
154 if ( ret == QDialog::Accepted ) { 154 if ( ret == QDialog::Accepted ) {
155 create( dlg.profile() ); 155 create( dlg.profile() );
156 } 156 }
157} 157}
158 158
159void MainWindow::slotConnect() { 159void MainWindow::slotConnect() {
160 if ( currentSession() ) 160 if ( currentSession() )
161 currentSession()->layer()->open(); 161 currentSession()->layer()->open();
162} 162}
163 163
164void MainWindow::slotDisconnect() { 164void MainWindow::slotDisconnect() {
165 if ( currentSession() ) 165 if ( currentSession() )
166 currentSession()->layer()->close(); 166 currentSession()->layer()->close();
167} 167}
168 168
169void MainWindow::slotTerminate() { 169void MainWindow::slotTerminate() {
170 if ( currentSession() ) 170 if ( currentSession() )
171 currentSession()->layer()->close(); 171 currentSession()->layer()->close();
172 172
173 slotClose(); 173 slotClose();
174 /* FIXME move to the next session */ 174 /* FIXME move to the next session */
175} 175}
176 176
177void MainWindow::slotConfigure() { 177void MainWindow::slotConfigure() {
178 qWarning("configure"); 178 qWarning("configure");
179 ConfigDialog conf( manager()->all(), factory() ); 179 ConfigDialog conf( manager()->all(), factory() );
180 conf.showMaximized(); 180 conf.showMaximized();
181 181
182 int ret = conf.exec(); 182 int ret = conf.exec();
183 183
184 if ( QDialog::Accepted == ret ) { 184 if ( QDialog::Accepted == ret ) {
185 qWarning("conf %d", conf.list().count() ); 185 qWarning("conf %d", conf.list().count() );
186 manager()->setProfiles( conf.list() ); 186 manager()->setProfiles( conf.list() );
187 populateProfiles(); 187 populateProfiles();
188 } 188 }
189} 189}
190/* 190/*
191 * we will remove 191 * we will remove
192 * this window from the tabwidget 192 * this window from the tabwidget
193 * remove it from the list 193 * remove it from the list
194 * delete it 194 * delete it
195 * and set the currentSession() 195 * and set the currentSession()
196 */ 196 */
197void MainWindow::slotClose() { 197void MainWindow::slotClose() {
198 qWarning("close"); 198 qWarning("close");
199 if (!currentSession() ) 199 if (!currentSession() )
200 return; 200 return;
201 201
202 tabWidget()->remove( currentSession() ); 202 tabWidget()->remove( currentSession() );
203 /*it's autodelete */ 203 /*it's autodelete */
204 m_sessions.remove( m_curSession ); 204 m_sessions.remove( m_curSession );
205 m_curSession = m_sessions.first(); 205 m_curSession = m_sessions.first();
206 tabWidget()->setCurrent( m_curSession ); 206 tabWidget()->setCurrent( m_curSession );
207} 207}
208 208
209/* 209/*
210 * We will get the name 210 * We will get the name
211 * Then the profile 211 * Then the profile
212 * and then we will make a profile 212 * and then we will make a profile
213 */ 213 */
214void MainWindow::slotProfile( int id) { 214void MainWindow::slotProfile( int id) {
215 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 215 Profile prof = manager()->profile( m_sessionsPop->text( id) );
216 create( prof ); 216 create( prof );
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
@@ -33,107 +33,116 @@ void MetaFactory::addFileTransferLayer( const QCString& name,
33void MetaFactory::addEmulationLayer( const QCString& name, 33void MetaFactory::addEmulationLayer( const QCString& name,
34 const QString& str, 34 const QString& str,
35 emulationLayer em) { 35 emulationLayer em) {
36 m_strings.insert(str, name ); 36 m_strings.insert(str, name );
37 m_emu.insert( str, em ); 37 m_emu.insert( str, em );
38} 38}
39QStringList MetaFactory::ioLayers()const { 39QStringList MetaFactory::ioLayers()const {
40 QStringList list; 40 QStringList list;
41 QMap<QString, iolayer>::ConstIterator it; 41 QMap<QString, iolayer>::ConstIterator it;
42 for (it = m_layerFact.begin(); it != m_layerFact.end(); ++it ) { 42 for (it = m_layerFact.begin(); it != m_layerFact.end(); ++it ) {
43 list << it.key(); 43 list << it.key();
44 } 44 }
45 return list; 45 return list;
46} 46}
47QStringList MetaFactory::connectionWidgets()const { 47QStringList MetaFactory::connectionWidgets()const {
48 QStringList list; 48 QStringList list;
49 QMap<QString, configWidget>::ConstIterator it; 49 QMap<QString, configWidget>::ConstIterator it;
50 for ( it = m_conFact.begin(); it != m_conFact.end(); ++it ) { 50 for ( it = m_conFact.begin(); it != m_conFact.end(); ++it ) {
51 list << it.key(); 51 list << it.key();
52 } 52 }
53 return list; 53 return list;
54} 54}
55QStringList MetaFactory::terminalWidgets()const { 55QStringList MetaFactory::terminalWidgets()const {
56 QStringList list; 56 QStringList list;
57 QMap<QString, configWidget>::ConstIterator it; 57 QMap<QString, configWidget>::ConstIterator it;
58 for ( it = m_termFact.begin(); it != m_termFact.end(); ++it ) { 58 for ( it = m_termFact.begin(); it != m_termFact.end(); ++it ) {
59 list << it.key(); 59 list << it.key();
60 } 60 }
61 return list; 61 return list;
62} 62}
63QStringList MetaFactory::fileTransferLayers()const { 63QStringList MetaFactory::fileTransferLayers()const {
64 QStringList list; 64 QStringList list;
65 QMap<QString, filelayer>::ConstIterator it; 65 QMap<QString, filelayer>::ConstIterator it;
66 for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) { 66 for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) {
67 list << it.key(); 67 list << it.key();
68 } 68 }
69 return list; 69 return list;
70} 70}
71QStringList MetaFactory::emulationLayers()const { 71QStringList MetaFactory::emulationLayers()const {
72 QStringList list; 72 QStringList list;
73 QMap<QString, emulationLayer>::ConstIterator it; 73 QMap<QString, emulationLayer>::ConstIterator it;
74 for ( it = m_emu.begin(); it != m_emu.end(); ++it ) { 74 for ( it = m_emu.begin(); it != m_emu.end(); ++it ) {
75 list << it.key(); 75 list << it.key();
76 } 76 }
77 return list; 77 return list;
78} 78}
79 79
80IOLayer* MetaFactory::newIOLayer( const QString& str,const Profile& prof ) { 80IOLayer* MetaFactory::newIOLayer( const QString& str,const Profile& prof ) {
81 IOLayer* lay = 0l; 81 IOLayer* lay = 0l;
82 82
83 QMap<QString, iolayer>::Iterator it; 83 QMap<QString, iolayer>::Iterator it;
84 it = m_layerFact.find( str ); 84 it = m_layerFact.find( str );
85 if ( it != m_layerFact.end() ) { 85 if ( it != m_layerFact.end() ) {
86 lay = (*(it.data()))(prof); 86 lay = (*(it.data()))(prof);
87 /* 87 /*
88 iolayer laye = it.data(); 88 iolayer laye = it.data();
89 lay = (*laye )(conf);*/ 89 lay = (*laye )(conf);*/
90 } 90 }
91 91
92 return lay; 92 return lay;
93} 93}
94 94
95ProfileDialogWidget *MetaFactory::newConnectionPlugin ( const QString& str, QWidget *parent) { 95ProfileDialogWidget *MetaFactory::newConnectionPlugin ( const QString& str, QWidget *parent) {
96 ProfileDialogWidget* wid = 0l; 96 ProfileDialogWidget* wid = 0l;
97 97
98 QMap<QString, configWidget>::Iterator it; 98 QMap<QString, configWidget>::Iterator it;
99 it = m_conFact.find( str ); 99 it = m_conFact.find( str );
100 if ( it != m_conFact.end() ) { 100 if ( it != m_conFact.end() ) {
101 wid = (*(it.data() ) )(str,parent); 101 wid = (*(it.data() ) )(str,parent);
102 } 102 }
103 return wid; 103 return wid;
104} 104}
105ProfileDialogWidget *MetaFactory::newTerminalPlugin( const QString& str, QWidget *parent) { 105ProfileDialogWidget *MetaFactory::newTerminalPlugin( const QString& str, QWidget *parent) {
106 if (str.isEmpty() ) 106 if (str.isEmpty() )
107 return 0l; 107 return 0l;
108 ProfileDialogWidget* wid = 0l; 108 ProfileDialogWidget* wid = 0l;
109 qWarning("new terminalPlugin %s %l", str.latin1(), parent ); 109 qWarning("new terminalPlugin %s %l", str.latin1(), parent );
110 110
111 QMap<QString, configWidget>::Iterator it; 111 QMap<QString, configWidget>::Iterator it;
112 it = m_termFact.find( str ); 112 it = m_termFact.find( str );
113 if ( it != m_termFact.end() ) { 113 if ( it != m_termFact.end() ) {
114 wid = (*(it.data() ) )(str,parent); 114 wid = (*(it.data() ) )(str,parent);
115 } 115 }
116 return wid; 116 return wid;
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
@@ -1,106 +1,107 @@
1#ifndef OPIE_META_FACTORY_H 1#ifndef OPIE_META_FACTORY_H
2#define OPIE_META_FACTORY_H 2#define OPIE_META_FACTORY_H
3 3
4/** 4/**
5 * The MetaFactory is used to keep track of all IOLayers, FileTransferLayers and ConfigWidgets 5 * The MetaFactory is used to keep track of all IOLayers, FileTransferLayers and ConfigWidgets
6 * and to instantiate these implementations on demand 6 * and to instantiate these implementations on demand
7 */ 7 */
8 8
9#include <qwidget.h> 9#include <qwidget.h>
10#include <qmap.h> 10#include <qmap.h>
11 11
12#include <qpe/config.h> 12#include <qpe/config.h>
13 13
14#include "io_layer.h" 14#include "io_layer.h"
15#include "file_layer.h" 15#include "file_layer.h"
16#include "profile.h" 16#include "profile.h"
17#include "profiledialogwidget.h" 17#include "profiledialogwidget.h"
18#include "emulation_layer.h" 18#include "emulation_layer.h"
19 19
20class WidgetLayer; 20class WidgetLayer;
21class MetaFactory { 21class MetaFactory {
22public: 22public:
23 typedef ProfileDialogWidget* (*configWidget)(const QString&, QWidget* parent); 23 typedef ProfileDialogWidget* (*configWidget)(const QString&, QWidget* parent);
24 typedef IOLayer* (*iolayer)(const Profile& ); 24 typedef IOLayer* (*iolayer)(const Profile& );
25 typedef FileTransferLayer* (*filelayer)(IOLayer*); 25 typedef FileTransferLayer* (*filelayer)(IOLayer*);
26 typedef EmulationLayer* (*emulationLayer)(WidgetLayer* ); 26 typedef EmulationLayer* (*emulationLayer)(WidgetLayer* );
27 27
28 MetaFactory(); 28 MetaFactory();
29 ~MetaFactory(); 29 ~MetaFactory();
30 30
31 /** 31 /**
32 * add a ProfileDialogWidget to the factory 32 * add a ProfileDialogWidget to the factory
33 * name is the name shown to the user 33 * name is the name shown to the user
34 */ 34 */
35 void addConnectionWidgetFactory( const QCString& internalName, 35 void addConnectionWidgetFactory( const QCString& internalName,
36 const QString& uiString, 36 const QString& uiString,
37 configWidget ); 37 configWidget );
38 void addTerminalWidgetFactory ( const QCString& internalName, 38 void addTerminalWidgetFactory ( const QCString& internalName,
39 const QString& name, 39 const QString& name,
40 configWidget ); 40 configWidget );
41 41
42 /** 42 /**
43 * adds an IOLayer factory 43 * adds an IOLayer factory
44 */ 44 */
45 void addIOLayerFactory( const QCString&, 45 void addIOLayerFactory( const QCString&,
46 const QString&, 46 const QString&,
47 iolayer ); 47 iolayer );
48 48
49 /** 49 /**
50 * adds a FileTransfer Layer 50 * adds a FileTransfer Layer
51 */ 51 */
52 void addFileTransferLayer( const QCString& name, 52 void addFileTransferLayer( const QCString& name,
53 const QString&, 53 const QString&,
54 filelayer ); 54 filelayer );
55 55
56 /** 56 /**
57 * adds a Factory for Emulation to the Layer.. 57 * adds a Factory for Emulation to the Layer..
58 */ 58 */
59 void addEmulationLayer ( const QCString& name, 59 void addEmulationLayer ( const QCString& name,
60 const QString& uiString, 60 const QString& uiString,
61 emulationLayer ); 61 emulationLayer );
62 62
63 /* translated UI Strings */ 63 /* translated UI Strings */
64 QStringList ioLayers()const; 64 QStringList ioLayers()const;
65 QStringList connectionWidgets()const; 65 QStringList connectionWidgets()const;
66 66
67 /** 67 /**
68 * Terminal Configuration widgets 68 * Terminal Configuration widgets
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 */
93 QString external( const QCString& )const; 94 QString external( const QCString& )const;
94 95
95 96
96private: 97private:
97 QMap<QString, QCString> m_strings; 98 QMap<QString, QCString> m_strings;
98 QMap<QString, configWidget> m_conFact; 99 QMap<QString, configWidget> m_conFact;
99 QMap<QString, configWidget> m_termFact; 100 QMap<QString, configWidget> m_termFact;
100 QMap<QString, iolayer> m_layerFact; 101 QMap<QString, iolayer> m_layerFact;
101 QMap<QString, filelayer> m_fileFact; 102 QMap<QString, filelayer> m_fileFact;
102 QMap<QString, emulationLayer> m_emu; 103 QMap<QString, emulationLayer> m_emu;
103}; 104};
104 105
105 106
106#endif 107#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 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <stdio.h> 2#include <stdio.h>
3#include <fcntl.h> 3#include <fcntl.h>
4#include <sys/termios.h> 4#include <sys/termios.h>
5 5
6#include <qmultilineedit.h> 6#include <qmultilineedit.h>
7#include <qsocketnotifier.h> 7#include <qsocketnotifier.h>
8 8
9#include "../profile.h" 9#include "../profile.h"
10#include "../io_serial.h" 10#include "../io_serial.h"
11#include "../filetransfer.h" 11#include "../filetransfer.h"
12 12
13#include <opie/oprocess.h> 13#include <opie/oprocess.h>
14 14
15#include "senderui.h" 15#include "senderui.h"
16 16
17SenderUI::SenderUI() 17SenderUI::SenderUI()
18 : Sender() { 18 : Sender() {
19 19
20 /* we do that manually */ 20 /* we do that manually */
21 Profile prof; 21 Profile prof;
22 QString str = "/dev/ttyS0"; 22 QString str = "/dev/ttyS0";
23 prof.writeEntry("Device",str ); 23 prof.writeEntry("Device",str );
24 prof.writeEntry("Baud", 115200 ); 24 prof.writeEntry("Baud", 115200 );
25 25
26 qWarning("prof " + prof.readEntry("Device") + " " + str); 26 qWarning("prof " + prof.readEntry("Device") + " " + str);
27 ser = new IOSerial(prof); 27 ser = new IOSerial(prof);
28 connect(ser, SIGNAL(received(const QByteArray& ) ), 28 connect(ser, SIGNAL(received(const QByteArray& ) ),
29 this, SLOT(got(const QByteArray&) ) ); 29 this, SLOT(got(const QByteArray&) ) );
30 30
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) {
56 for ( uint i = 0; i < ar.count(); i++ ) { 56 for ( uint i = 0; i < ar.count(); i++ ) {
57 printf("%c", ar[i] ); 57 printf("%c", ar[i] );
58 } 58 }
59 //printf("\n"); 59 //printf("\n");
60} 60}
61 61
62void SenderUI::fileTransComplete() { 62void SenderUI::fileTransComplete() {
63 63
64 qWarning("file transfer complete"); 64 qWarning("file transfer complete");
65} 65}
66void SenderUI::send() { 66void SenderUI::send() {
67 67
68} 68}
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 @@
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);
50 hbox = new QHBoxLayout(vbox, 0); 63 hbox = new QHBoxLayout(vbox, 0);
51 hbox->add(filename); 64 hbox->add(filename);
52 hbox->add(selector); 65 hbox->add(selector);
53 vbox->add(mode); 66 vbox->add(mode);
54 vbox->add(protocol); 67 vbox->add(protocol);
55 vbox->add(progress); 68 vbox->add(progress);
56 vbox->add(progressbar); 69 vbox->add(progressbar);
57 vbox->add(status); 70 vbox->add(status);
58 vbox->add(statusbar); 71 vbox->add(statusbar);
59 vbox->addStretch(1); 72 vbox->addStretch(1);
60 hbox2 = new QHBoxLayout(vbox, 2); 73 hbox2 = new QHBoxLayout(vbox, 2);
61 hbox2->add(ok); 74 hbox2->add(ok);
62 hbox2->add(cancel); 75 hbox2->add(cancel);
63 76
64 setCaption(QObject::tr("File transfer")); 77 setCaption(QObject::tr("File transfer"));
65 show(); 78 show();
66 79
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{
133 progressbar->setProgress(progress); 141 progressbar->setProgress(progress);
134} 142}
135 143
136void TransferDialog::slotError(int error, const QString& message) 144void TransferDialog::slotError(int error, const QString& message)
137{ 145{
138 switch(error) 146 switch(error)
139 { 147 {
140 case FileTransferLayer::NotSupported: 148 case FileTransferLayer::NotSupported:
141 QMessageBox::critical(this, 149 QMessageBox::critical(this,
142 QObject::tr("Error"), 150 QObject::tr("Error"),
143 QObject::tr("Operation not supported.")); 151 QObject::tr("Operation not supported."));
144 break; 152 break;
145 case FileTransferLayer::StartError: 153 case FileTransferLayer::StartError:
146 QMessageBox::critical(this, 154 QMessageBox::critical(this,
147 QObject::tr("Error"), 155 QObject::tr("Error"),
148 QObject::tr("Operation not supported.")); 156 QObject::tr("Operation not supported."));
149 break; 157 break;
150 case FileTransferLayer::NoError: 158 case FileTransferLayer::NoError:
151 QMessageBox::critical(this, 159 QMessageBox::critical(this,
152 QObject::tr("Error"), 160 QObject::tr("Error"),
153 QObject::tr("Operation not supported.")); 161 QObject::tr("Operation not supported."));
154 break; 162 break;
155 case FileTransferLayer::Undefined: 163 case FileTransferLayer::Undefined:
156 QMessageBox::critical(this, 164 QMessageBox::critical(this,
157 QObject::tr("Error"), 165 QObject::tr("Error"),
158 QObject::tr("Operation not supported.")); 166 QObject::tr("Operation not supported."));
159 break; 167 break;
160 case FileTransferLayer::Incomplete: 168 case FileTransferLayer::Incomplete:
161 QMessageBox::critical(this, 169 QMessageBox::critical(this,
162 QObject::tr("Error"), 170 QObject::tr("Error"),
163 QObject::tr("Operation not supported.")); 171 QObject::tr("Operation not supported."));
164 break; 172 break;
165 case FileTransferLayer::Unknown: 173 case FileTransferLayer::Unknown:
166 default: 174 default:
167 QMessageBox::critical(this, 175 QMessageBox::critical(this,
168 QObject::tr("Error"), 176 QObject::tr("Error"),
169 QObject::tr("Operation not supported.")); 177 QObject::tr("Operation not supported."));
170 break; 178 break;
171 } 179 }
172} 180}
173 181
174void TransferDialog::slotSent() 182void TransferDialog::slotSent()
175{ 183{
176 QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); 184 QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent."));
177 ok->setEnabled(true); 185 ok->setEnabled(true);
178} 186}
179 187
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