author | ar <ar> | 2004-02-21 18:32:37 (UTC) |
---|---|---|
committer | ar <ar> | 2004-02-21 18:32:37 (UTC) |
commit | 536f271b1e6a1d1886e96a28524a3503c4c38c4e (patch) (unidiff) | |
tree | 63b3c0ce472a89a0f9731195fececc701bf4ca67 /noncore/settings/networksettings/ppp/modeminfo.cpp | |
parent | db2afda83e495bff9fc19fa14a30072f1cd4c67a (diff) | |
download | opie-536f271b1e6a1d1886e96a28524a3503c4c38c4e.zip opie-536f271b1e6a1d1886e96a28524a3503c4c38c4e.tar.gz opie-536f271b1e6a1d1886e96a28524a3503c4c38c4e.tar.bz2 |
improve support for BigScreen
Diffstat (limited to 'noncore/settings/networksettings/ppp/modeminfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modeminfo.cpp | 383 |
1 files changed, 201 insertions, 182 deletions
diff --git a/noncore/settings/networksettings/ppp/modeminfo.cpp b/noncore/settings/networksettings/ppp/modeminfo.cpp index dbb26db..df0bf9b 100644 --- a/noncore/settings/networksettings/ppp/modeminfo.cpp +++ b/noncore/settings/networksettings/ppp/modeminfo.cpp | |||
@@ -26,67 +26,71 @@ | |||
26 | 26 | ||
27 | #include <unistd.h> | 27 | #include "modeminfo.h" |
28 | #include "modem.h" | ||
29 | |||
30 | /* OPIE */ | ||
31 | #include <qpe/qpeapplication.h> | ||
32 | |||
33 | /* QT */ | ||
28 | #include <qregexp.h> | 34 | #include <qregexp.h> |
29 | #include <qlayout.h> | 35 | #include <qlayout.h> |
30 | // #include <kwin.h> | ||
31 | // #include <kmessagebox.h> | ||
32 | // #include <kapplication.h> | ||
33 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
34 | #include <qapplication.h> | 37 | #include <qapplication.h> |
35 | #include "modeminfo.h" | 38 | |
36 | #include "modem.h" | 39 | /* STD */ |
40 | #include <unistd.h> | ||
37 | 41 | ||
38 | ModemTransfer::ModemTransfer(Modem *mo, QWidget *parent, const char *name) | 42 | ModemTransfer::ModemTransfer(Modem *mo, QWidget *parent, const char *name) |
39 | : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder), | 43 | : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder), |
40 | _modem(mo) | 44 | _modem(mo) |
41 | { | 45 | { |
42 | setCaption(QObject::tr("ATI Query")); | 46 | setCaption(QObject::tr("ATI Query")); |
43 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | 47 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); |
44 | 48 | ||
45 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | 49 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); |
46 | 50 | ||
47 | progressBar = new QProgressBar(this, "bar"); | 51 | progressBar = new QProgressBar(this, "bar"); |
48 | progressBar->setTotalSteps(8); | 52 | progressBar->setTotalSteps(8); |
49 | 53 | ||
50 | statusBar = new QLabel(this,"sBar"); | 54 | statusBar = new QLabel(this,"sBar"); |
51 | statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken); | 55 | statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken); |
52 | statusBar->setAlignment(AlignCenter); | 56 | statusBar->setAlignment(AlignCenter); |
53 | 57 | ||
54 | // This is a rather complicated case. Since we do not know which | 58 | // This is a rather complicated case. Since we do not know which |
55 | // message is the widest in the national language, we'd to | 59 | // message is the widest in the national language, we'd to |
56 | // search all these messages. This is a little overkill, so I take | 60 | // search all these messages. This is a little overkill, so I take |
57 | // the longest english message, translate it and give it additional | 61 | // the longest english message, translate it and give it additional |
58 | // 20 percent space. Hope this is enough. | 62 | // 20 percent space. Hope this is enough. |
59 | statusBar->setText(QObject::tr("Unable to create modem lock file.")); | 63 | statusBar->setText(QObject::tr("Unable to create modem lock file.")); |
60 | statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10); | 64 | statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10); |
61 | statusBar->setFixedHeight(statusBar->sizeHint().height() + 4); | 65 | statusBar->setFixedHeight(statusBar->sizeHint().height() + 4); |
62 | 66 | ||
63 | // set original text | 67 | // set original text |
64 | statusBar->setText(QObject::tr("Looking for modem...")); | 68 | statusBar->setText(QObject::tr("Looking for modem...")); |
65 | progressBar->setFixedHeight(statusBar->minimumSize().height()); | 69 | progressBar->setFixedHeight(statusBar->minimumSize().height()); |
66 | tl->addWidget(progressBar); | 70 | tl->addWidget(progressBar); |
67 | tl->addWidget(statusBar); | 71 | tl->addWidget(statusBar); |
68 | 72 | ||
69 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 73 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
70 | cancel->setFocus(); | 74 | cancel->setFocus(); |
71 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); | 75 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); |
72 | 76 | ||
73 | QHBoxLayout *l1 = new QHBoxLayout; | 77 | QHBoxLayout *l1 = new QHBoxLayout; |
74 | tl->addLayout(l1); | 78 | tl->addLayout(l1); |
75 | l1->addStretch(1); | 79 | l1->addStretch(1); |
76 | l1->addWidget(cancel); | 80 | l1->addWidget(cancel); |
77 | 81 | ||
78 | setFixedSize(sizeHint()); | 82 | setFixedSize(sizeHint()); |
79 | 83 | ||
80 | step = 0; | 84 | step = 0; |
81 | 85 | ||
82 | //////////////////////////////////////////////// | 86 | //////////////////////////////////////////////// |
83 | 87 | ||
84 | timeout_timer = new QTimer(this); | 88 | timeout_timer = new QTimer(this); |
85 | connect(timeout_timer, SIGNAL(timeout()), SLOT(time_out_slot())); | 89 | connect(timeout_timer, SIGNAL(timeout()), SLOT(time_out_slot())); |
86 | 90 | ||
87 | scripttimer = new QTimer(this); | 91 | scripttimer = new QTimer(this); |
88 | connect(scripttimer, SIGNAL(timeout()), SLOT(do_script())); | 92 | connect(scripttimer, SIGNAL(timeout()), SLOT(do_script())); |
89 | 93 | ||
90 | timeout_timer->start(15000,TRUE); // 15 secs single shot | 94 | timeout_timer->start(15000,TRUE); // 15 secs single shot |
91 | QTimer::singleShot(500, this, SLOT(init())); | 95 | QTimer::singleShot(500, this, SLOT(init())); |
92 | 96 | ||
@@ -95,18 +99,19 @@ ModemTransfer::ModemTransfer(Modem *mo, QWidget *parent, const char *name) | |||
95 | 99 | ||
96 | void ModemTransfer::ati_done() { | 100 | void ModemTransfer::ati_done() |
97 | scripttimer->stop(); | 101 | { |
98 | timeout_timer->stop(); | 102 | scripttimer->stop(); |
99 | _modem->closetty(); | 103 | timeout_timer->stop(); |
100 | _modem->unlockdevice(); | 104 | _modem->closetty(); |
101 | hide(); | 105 | _modem->unlockdevice(); |
106 | hide(); | ||
107 | |||
108 | // open the result window | ||
109 | ModemInfo *mi = new ModemInfo(this); | ||
110 | for(int i = 0; i < NUM_OF_ATI; i++) | ||
111 | mi->setAtiString(i, ati_query_strings[i]); | ||
102 | 112 | ||
103 | // open the result window | 113 | QPEApplication::execDialog( mi ); |
104 | ModemInfo *mi = new ModemInfo(this); | 114 | delete mi; |
105 | for(int i = 0; i < NUM_OF_ATI; i++) | ||
106 | mi->setAtiString(i, ati_query_strings[i]); | ||
107 | mi->showMaximized(); | ||
108 | mi->exec(); | ||
109 | delete mi; | ||
110 | 115 | ||
111 | accept(); | 116 | accept(); |
112 | } | 117 | } |
@@ -114,8 +119,9 @@ void ModemTransfer::ati_done() { | |||
114 | 119 | ||
115 | void ModemTransfer::time_out_slot() { | 120 | void ModemTransfer::time_out_slot() |
116 | timeout_timer->stop(); | 121 | { |
117 | scripttimer->stop(); | 122 | timeout_timer->stop(); |
123 | scripttimer->stop(); | ||
118 | 124 | ||
119 | QMessageBox::warning(this, tr("Error"), QObject::tr("Modem Query timed out.")); | 125 | QMessageBox::warning(this, tr("Error"), QObject::tr("Modem Query timed out.")); |
120 | reject(); | 126 | reject(); |
121 | } | 127 | } |
@@ -123,43 +129,48 @@ void ModemTransfer::time_out_slot() { | |||
123 | 129 | ||
124 | void ModemTransfer::init() { | 130 | void ModemTransfer::init() |
131 | { | ||
125 | 132 | ||
126 | qApp->processEvents(); | 133 | qApp->processEvents(); |
127 | 134 | ||
128 | int lock = _modem->lockdevice(); | 135 | int lock = _modem->lockdevice(); |
129 | if (lock == 1) { | 136 | if (lock == 1) |
137 | { | ||
130 | 138 | ||
131 | statusBar->setText(QObject::tr("Modem device is locked.")); | 139 | statusBar->setText(QObject::tr("Modem device is locked.")); |
132 | return; | 140 | return; |
133 | } | 141 | } |
134 | 142 | ||
135 | if (lock == -1) { | 143 | if (lock == -1) |
144 | { | ||
136 | 145 | ||
137 | statusBar->setText(QObject::tr("Unable to create modem lock file.")); | 146 | statusBar->setText(QObject::tr("Unable to create modem lock file.")); |
138 | return; | 147 | return; |
139 | } | 148 | } |
140 | 149 | ||
141 | 150 | ||
142 | if(_modem->opentty()) { | 151 | if(_modem->opentty()) |
143 | if(_modem->hangup()) { | 152 | { |
144 | usleep(100000); // wait 0.1 secs | 153 | if(_modem->hangup()) |
145 | _modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ... | 154 | { |
155 | usleep(100000); // wait 0.1 secs | ||
156 | _modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ... | ||
146 | 157 | ||
147 | statusBar->setText(QObject::tr("Modem Ready")); | 158 | statusBar->setText(QObject::tr("Modem Ready")); |
148 | qApp->processEvents(); | 159 | qApp->processEvents(); |
149 | usleep(100000); // wait 0.1 secs | 160 | usleep(100000); // wait 0.1 secs |
150 | qApp->processEvents(); | 161 | qApp->processEvents(); |
151 | scripttimer->start(1000); // this one does the ati query | 162 | scripttimer->start(1000); // this one does the ati query |
152 | 163 | ||
153 | // clear modem buffer | 164 | // clear modem buffer |
154 | _modem->flush(); | 165 | _modem->flush(); |
155 | 166 | ||
156 | _modem->notify(this, SLOT(readChar(unsigned char))); | 167 | _modem->notify(this, SLOT(readChar(unsigned char))); |
157 | return; | 168 | return; |
169 | } | ||
158 | } | 170 | } |
159 | } | ||
160 | 171 | ||
161 | // opentty() or hangup() failed | 172 | // opentty() or hangup() failed |
162 | statusBar->setText(_modem->modemMessage()); | 173 | statusBar->setText(_modem->modemMessage()); |
163 | step = 99; // wait until cancel is pressed | 174 | step = 99; // wait until cancel is pressed |
164 | _modem->unlockdevice(); | 175 | _modem->unlockdevice(); |
165 | } | 176 | } |
@@ -167,54 +178,58 @@ void ModemTransfer::init() { | |||
167 | 178 | ||
168 | void ModemTransfer::do_script() { | 179 | void ModemTransfer::do_script() |
169 | QString msg; | 180 | { |
170 | QString query; | 181 | QString msg; |
171 | 182 | QString query; | |
172 | switch(step) { | 183 | |
173 | case 0: | 184 | switch(step) |
174 | readtty(); | 185 | { |
175 | statusBar->setText("ATI..."); | 186 | case 0: |
176 | progressBar->setProgress( progressBar->progress() + 1); | 187 | readtty(); |
177 | _modem->writeLine("ATI\n"); | 188 | statusBar->setText("ATI..."); |
178 | break; | 189 | progressBar->setProgress( progressBar->progress() + 1); |
179 | 190 | _modem->writeLine("ATI\n"); | |
180 | case 1: | 191 | break; |
181 | case 2: | 192 | |
182 | case 3: | 193 | case 1: |
183 | case 4: | 194 | case 2: |
184 | case 5: | 195 | case 3: |
185 | case 6: | 196 | case 4: |
186 | case 7: | 197 | case 5: |
187 | readtty(); | 198 | case 6: |
188 | msg.sprintf("ATI %d ...", step); | 199 | case 7: |
189 | query.sprintf("ATI%d\n", step); | 200 | readtty(); |
190 | statusBar->setText(msg); | 201 | msg.sprintf("ATI %d ...", step); |
191 | progressBar->setProgress( progressBar->progress() + 1); | 202 | query.sprintf("ATI%d\n", step); |
192 | _modem->writeLine(query.local8Bit()); | 203 | statusBar->setText(msg); |
193 | break; | 204 | progressBar->setProgress( progressBar->progress() + 1); |
194 | 205 | _modem->writeLine(query.local8Bit()); | |
195 | default: | 206 | break; |
196 | readtty(); | 207 | |
197 | ati_done(); | 208 | default: |
198 | } | 209 | readtty(); |
199 | step++; | 210 | ati_done(); |
211 | } | ||
212 | step++; | ||
200 | } | 213 | } |
201 | 214 | ||
202 | void ModemTransfer::readChar(unsigned char c) { | 215 | void ModemTransfer::readChar(unsigned char c) |
203 | if(readbuffer.length() < 255) | 216 | { |
204 | readbuffer += c; | 217 | if(readbuffer.length() < 255) |
218 | readbuffer += c; | ||
205 | } | 219 | } |
206 | 220 | ||
207 | void ModemTransfer::readtty() { | 221 | void ModemTransfer::readtty() |
222 | { | ||
208 | 223 | ||
209 | if (step == 0) | 224 | if (step == 0) |
210 | return; | 225 | return; |
211 | 226 | ||
212 | readbuffer.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r | 227 | readbuffer.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r |
213 | readbuffer = readbuffer.stripWhiteSpace(); // strip of leading or trailing white | 228 | readbuffer = readbuffer.stripWhiteSpace(); // strip of leading or trailing white |
214 | // space | 229 | // space |
215 | 230 | ||
216 | if(step <= NUM_OF_ATI) | 231 | if(step <= NUM_OF_ATI) |
217 | ati_query_strings[step-1] = readbuffer.copy(); | 232 | ati_query_strings[step-1] = readbuffer.copy(); |
218 | 233 | ||
219 | readbuffer = ""; | 234 | readbuffer = ""; |
220 | } | 235 | } |
@@ -222,15 +237,16 @@ void ModemTransfer::readtty() { | |||
222 | 237 | ||
223 | void ModemTransfer::cancelbutton() { | 238 | void ModemTransfer::cancelbutton() |
224 | scripttimer->stop(); | 239 | { |
225 | _modem->stop(); | 240 | scripttimer->stop(); |
226 | timeout_timer->stop(); | 241 | _modem->stop(); |
242 | timeout_timer->stop(); | ||
227 | 243 | ||
228 | statusBar->setText(QObject::tr("One moment please...")); | 244 | statusBar->setText(QObject::tr("One moment please...")); |
229 | qApp->processEvents(); | 245 | qApp->processEvents(); |
230 | 246 | ||
231 | _modem->hangup(); | 247 | _modem->hangup(); |
232 | 248 | ||
233 | _modem->closetty(); | 249 | _modem->closetty(); |
234 | _modem->unlockdevice(); | 250 | _modem->unlockdevice(); |
235 | reject(); | 251 | reject(); |
236 | } | 252 | } |
@@ -238,5 +254,6 @@ void ModemTransfer::cancelbutton() { | |||
238 | 254 | ||
239 | void ModemTransfer::closeEvent( QCloseEvent *e ) { | 255 | void ModemTransfer::closeEvent( QCloseEvent *e ) |
240 | cancelbutton(); | 256 | { |
241 | e->accept(); | 257 | cancelbutton(); |
258 | e->accept(); | ||
242 | } | 259 | } |
@@ -245,42 +262,43 @@ void ModemTransfer::closeEvent( QCloseEvent *e ) { | |||
245 | ModemInfo::ModemInfo(QWidget *parent, const char* name) | 262 | ModemInfo::ModemInfo(QWidget *parent, const char* name) |
246 | : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder) | 263 | : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder) |
247 | { | 264 | { |
248 | QString label_text; | 265 | QString label_text; |
249 | 266 | ||
250 | setCaption(QObject::tr("Modem Query Results")); | 267 | setCaption(QObject::tr("Modem Query Results")); |
251 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | 268 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); |
252 | 269 | ||
253 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | 270 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); |
254 | 271 | ||
255 | QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5); | 272 | QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5); |
256 | tl->addLayout(l1, 1); | 273 | tl->addLayout(l1, 1); |
257 | for(int i = 0 ; i < NUM_OF_ATI ; i++) { | 274 | for(int i = 0 ; i < NUM_OF_ATI ; i++) |
275 | { | ||
258 | 276 | ||
259 | label_text = ""; | 277 | label_text = ""; |
260 | if ( i == 0) | 278 | if ( i == 0) |
261 | label_text.sprintf("ATI :"); | 279 | label_text.sprintf("ATI :"); |
262 | else | 280 | else |
263 | label_text.sprintf("ATI %d:", i ); | 281 | label_text.sprintf("ATI %d:", i ); |
264 | 282 | ||
265 | ati_label[i] = new QLabel(label_text, this); | 283 | ati_label[i] = new QLabel(label_text, this); |
266 | l1->addWidget(ati_label[i], i, 0); | 284 | l1->addWidget(ati_label[i], i, 0); |
267 | 285 | ||
268 | ati_label_result[i] = new QLineEdit(this); | 286 | ati_label_result[i] = new QLineEdit(this); |
269 | ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24); | 287 | ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24); |
270 | l1->addWidget(ati_label_result[i], i, 1); | 288 | l1->addWidget(ati_label_result[i], i, 1); |
271 | } | 289 | } |
272 | //tl->addSpacing(1); | 290 | //tl->addSpacing(1); |
273 | 291 | ||
274 | QHBoxLayout *l2 = new QHBoxLayout; | 292 | QHBoxLayout *l2 = new QHBoxLayout; |
275 | QPushButton *ok = new QPushButton(QObject::tr("Close"), this); | 293 | QPushButton *ok = new QPushButton(QObject::tr("Close"), this); |
276 | ok->setDefault(TRUE); | 294 | ok->setDefault(TRUE); |
277 | ok->setFocus(); | 295 | ok->setFocus(); |
278 | 296 | ||
279 | tl->addLayout(l2); | 297 | tl->addLayout(l2); |
280 | l2->addStretch(1); | 298 | l2->addStretch(1); |
281 | 299 | ||
282 | connect(ok, SIGNAL(clicked()), SLOT(accept())); | 300 | connect(ok, SIGNAL(clicked()), SLOT(accept())); |
283 | l2->addWidget(ok); | 301 | l2->addWidget(ok); |
284 | 302 | ||
285 | setMinimumSize(sizeHint()); | 303 | setMinimumSize(sizeHint()); |
286 | } | 304 | } |
@@ -288,5 +306,6 @@ ModemInfo::ModemInfo(QWidget *parent, const char* name) | |||
288 | 306 | ||
289 | void ModemInfo::setAtiString(int i, QString s) { | 307 | void ModemInfo::setAtiString(int i, QString s) |
290 | if(i < NUM_OF_ATI) | 308 | { |
291 | ati_label_result[i]->setText(s); | 309 | if(i < NUM_OF_ATI) |
310 | ati_label_result[i]->setText(s); | ||
292 | } | 311 | } |