summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-18 11:36:34 (UTC)
committer josef <josef>2002-10-18 11:36:34 (UTC)
commit24c0ae04669e94d554fe8ef49888ffb5a6a00656 (patch) (unidiff)
tree96e48d488555d789de7ac73797d016c7e8262956
parent3484cd354a54bcc20d389b123423028e09d884df (diff)
downloadopie-24c0ae04669e94d554fe8ef49888ffb5a6a00656.zip
opie-24c0ae04669e94d554fe8ef49888ffb5a6a00656.tar.gz
opie-24c0ae04669e94d554fe8ef49888ffb5a6a00656.tar.bz2
- increase dialog responsiveness
The higher the value (currently 100) is, the faster the modem dials, but lower values guarantee a smoother UI.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/dialer.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp
index 7bf9352..51d4093 100644
--- a/noncore/apps/opie-console/dialer.cpp
+++ b/noncore/apps/opie-console/dialer.cpp
@@ -1,295 +1,296 @@
1#include "dialer.h" 1#include "dialer.h"
2 2
3#include <qlayout.h> 3#include <qlayout.h>
4#include <qprogressbar.h> 4#include <qprogressbar.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qpushbutton.h> 6#include <qpushbutton.h>
7#include <qapp.h> 7#include <qapp.h>
8#include <qtimer.h> 8#include <qtimer.h>
9#include <qmessagebox.h> 9#include <qmessagebox.h>
10 10
11#include <unistd.h> 11#include <unistd.h>
12#include <string.h> 12#include <string.h>
13#include <fcntl.h> 13#include <fcntl.h>
14#include <errno.h> 14#include <errno.h>
15 15
16// State machine: | When an error occurs, we don't have to 16// State machine: | When an error occurs, we don't have to
17// | reset everything. 17// | reset everything.
18// (init) <------+ | But if the user wants to reset, 18// (init) <------+ | But if the user wants to reset,
19// | | | we stop dialing immediately. 19// | | | we stop dialing immediately.
20// v | | 20// v | |
21// (options) ----+ | Following the state machine is necessary 21// (options) ----+ | Following the state machine is necessary
22// | \ | to get determinable results. 22// | \ | to get determinable results.
23// v ^ | 23// v ^ |
24// (dial) ----+ | 24// (dial) ----+ |
25// | ^ | 25// | ^ |
26// v | | 26// v | |
27// (online) --+ | 27// (online) --+ |
28// | | 28// | |
29// v | 29// v |
30 30
31 31
32// from atconfigdialog 32// from atconfigdialog
33//initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) ); 33//initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) );
34//resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); 34//resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) );
35//dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); 35//dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) );
36//dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); 36//dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
37//dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); 37//dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) );
38//dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); 38//dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
39//dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); 39//dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) );
40//dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); 40//dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
41//connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); 41//connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) );
42//hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); 42//hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) );
43 43
44// from modemconfigwidget 44// from modemconfigwidget
45//int rad_flow = prof.readNumEntry("Flow"); 45//int rad_flow = prof.readNumEntry("Flow");
46//int rad_parity = prof.readNumEntry("Parity"); 46//int rad_parity = prof.readNumEntry("Parity");
47//int speed = prof.readNumEntry("Speed"); 47//int speed = prof.readNumEntry("Speed");
48//QString number = prof.readEntry("Number"); 48//QString number = prof.readEntry("Number");
49 49
50Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) 50Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name)
51: QDialog(parent, name, true), m_fd(fd), m_profile(profile) 51: QDialog(parent, name, true), m_fd(fd), m_profile(profile)
52{ 52{
53 QVBoxLayout *vbox; 53 QVBoxLayout *vbox;
54 QLabel *desc; 54 QLabel *desc;
55 55
56 //m_profile.writeEntry("InitString", "ATZ"); 56 //m_profile.writeEntry("InitString", "ATZ");
57 //m_profile.writeEntry("DialPrefix1", "ATDT"); 57 //m_profile.writeEntry("DialPrefix1", "ATDT");
58 //m_profile.writeEntry("Termination", "\n"); 58 //m_profile.writeEntry("Termination", "\n");
59 59
60 usercancel = 0; 60 usercancel = 0;
61 61
62 fcntl(m_fd, F_SETFL, O_NONBLOCK); 62 fcntl(m_fd, F_SETFL, O_NONBLOCK);
63 63
64 desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); 64 desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this);
65 progress = new QProgressBar(this); 65 progress = new QProgressBar(this);
66 status = new QLabel("", this); 66 status = new QLabel("", this);
67 status->setFrameStyle(QFrame::Panel | QFrame::Sunken); 67 status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
68 cancel = new QPushButton(QObject::tr("Cancel"), this); 68 cancel = new QPushButton(QObject::tr("Cancel"), this);
69 69
70 vbox = new QVBoxLayout(this, 2); 70 vbox = new QVBoxLayout(this, 2);
71 vbox->add(desc); 71 vbox->add(desc);
72 vbox->add(progress); 72 vbox->add(progress);
73 vbox->add(status); 73 vbox->add(status);
74 vbox->add(cancel); 74 vbox->add(cancel);
75 75
76 connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); 76 connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
77 77
78 show(); 78 show();
79 79
80 QTimer::singleShot(500, this, SLOT(slotAutostart())); 80 QTimer::singleShot(500, this, SLOT(slotAutostart()));
81} 81}
82 82
83Dialer::~Dialer() 83Dialer::~Dialer()
84{ 84{
85} 85}
86 86
87void Dialer::setHangupOnly() 87void Dialer::setHangupOnly()
88{ 88{
89 state = state_cancel; 89 state = state_cancel;
90 usercancel = 1; 90 usercancel = 1;
91} 91}
92 92
93void Dialer::slotCancel() 93void Dialer::slotCancel()
94{ 94{
95 if(state != state_online) 95 if(state != state_online)
96 { 96 {
97 usercancel = 1; 97 usercancel = 1;
98 reset(); 98 reset();
99 } 99 }
100 else accept(); 100 else accept();
101} 101}
102 102
103void Dialer::reset() 103void Dialer::reset()
104{ 104{
105 switchState(state_cancel); 105 switchState(state_cancel);
106} 106}
107 107
108void Dialer::slotAutostart() 108void Dialer::slotAutostart()
109{ 109{
110 //state = state_preinit; 110 //state = state_preinit;
111 dial(m_profile.readEntry("Number")); 111 dial(m_profile.readEntry("Number"));
112} 112}
113 113
114void Dialer::dial(const QString& number) 114void Dialer::dial(const QString& number)
115{ 115{
116 while(state != state_online) 116 while(state != state_online)
117 { 117 {
118 if(!usercancel) 118 if(!usercancel)
119 { 119 {
120 state = state_preinit; 120 state = state_preinit;
121 trydial(number); 121 trydial(number);
122 } 122 }
123 else break; 123 else break;
124 } 124 }
125 125
126 if(usercancel) 126 if(usercancel)
127 { 127 {
128 // modem hangup 128 // modem hangup
129 trydial(QString::null); 129 trydial(QString::null);
130 reject(); 130 reject();
131 } 131 }
132} 132}
133 133
134void Dialer::trydial(const QString& number) 134void Dialer::trydial(const QString& number)
135{ 135{
136 //if(state != state_cancel) 136 //if(state != state_cancel)
137 //{ 137 //{
138 if(state != state_cancel) switchState(state_preinit); 138 if(state != state_cancel) switchState(state_preinit);
139 send("+++ATH"); 139 send("+++ATH");
140 send(""); 140 send("");
141 //QString response = receive(); 141 //QString response = receive();
142 //} 142 //}
143 143
144 if(state != state_cancel) 144 if(state != state_cancel)
145 { 145 {
146 switchState(state_init); 146 switchState(state_init);
147 send("ATZ"); 147 send("ATZ");
148 //send(m_profile.readEntry("InitString")); 148 //send(m_profile.readEntry("InitString"));
149 QString response2 = receive(); 149 QString response2 = receive();
150 if(!response2.contains("\nOK\r")) 150 if(!response2.contains("\nOK\r"))
151 reset(); 151 reset();
152 } 152 }
153 153
154 if(state != state_cancel) 154 if(state != state_cancel)
155 { 155 {
156 switchState(state_options); 156 switchState(state_options);
157 157
158 send("ATM3L3"); 158 send("ATM3L3");
159 QString response3 = receive(); 159 QString response3 = receive();
160 if(!response3.contains("\nOK\r")) 160 if(!response3.contains("\nOK\r"))
161 reset(); 161 reset();
162 } 162 }
163 163
164 if(state != state_cancel) 164 if(state != state_cancel)
165 { 165 {
166 switchState(state_dialtone); 166 switchState(state_dialtone);
167 167
168 send("ATX1"); 168 send("ATX1");
169 QString response4 = receive(); 169 QString response4 = receive();
170 if(!response4.contains("\nOK\r")) 170 if(!response4.contains("\nOK\r"))
171 reset(); 171 reset();
172 } 172 }
173 173
174 if(state != state_cancel) 174 if(state != state_cancel)
175 { 175 {
176 switchState(state_dialing); 176 switchState(state_dialing);
177 177
178 send(QString("ATDT %1").arg(number)); 178 send(QString("ATDT %1").arg(number));
179 //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); 179 //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number));
180 QString response5 = receive(); 180 QString response5 = receive();
181 if(!response5.contains("\nCONNECT")) 181 if(!response5.contains("\nCONNECT"))
182 { 182 {
183 if(response5.contains("BUSY")) 183 if(response5.contains("BUSY"))
184 switchState(state_dialing); 184 switchState(state_dialing);
185 else 185 else
186 { 186 {
187 QMessageBox::warning(this, 187 QMessageBox::warning(this,
188 QObject::tr("Failure"), 188 QObject::tr("Failure"),
189 QObject::tr("Dialing the number failed.")); 189 QObject::tr("Dialing the number failed."));
190 slotCancel(); 190 slotCancel();
191 } 191 }
192 } 192 }
193 } 193 }
194 194
195 if(state != state_cancel) 195 if(state != state_cancel)
196 { 196 {
197 switchState(state_online); 197 switchState(state_online);
198 } 198 }
199} 199}
200 200
201void Dialer::send(const QString& msg) 201void Dialer::send(const QString& msg)
202{ 202{
203 QString m = msg; 203 QString m = msg;
204 int bytes; 204 int bytes;
205 QString termination; 205 QString termination;
206 206
207qWarning("Sending: '%s'", m.latin1()); 207qWarning("Sending: '%s'", m.latin1());
208 208
209 termination = "\r"; 209 termination = "\r";
210 //termination = m_profile.readEntry("Termination"); 210 //termination = m_profile.readEntry("Termination");
211 if(termination == "\n") m = m + "\n"; 211 if(termination == "\n") m = m + "\n";
212 else if(termination == "\r") m = m + "\r"; 212 else if(termination == "\r") m = m + "\r";
213 else m = m + "\r\n"; 213 else m = m + "\r\n";
214 214
215 bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); 215 bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit()));
216 if(bytes < 0) 216 if(bytes < 0)
217 { 217 {
218 reset(); 218 reset();
219 } 219 }
220} 220}
221 221
222QString Dialer::receive() 222QString Dialer::receive()
223{ 223{
224 QString buf; 224 QString buf;
225 char buffer[1024]; 225 char buffer[1024];
226 int ret; 226 int ret;
227 227 int counter;
228 qApp->processEvents();
229 228
230 while(1) 229 while(1)
231 { 230 {
232 ret = ::read(m_fd, buffer, sizeof(buffer)); 231 ret = ::read(m_fd, buffer, sizeof(buffer));
233 232
234 if(ret > 0) 233 if(ret > 0)
235 { 234 {
236 for(int i = 0; i < ret; i++) 235 for(int i = 0; i < ret; i++)
237 buffer[i] = buffer[i] & 0x7F; 236 buffer[i] = buffer[i] & 0x7F;
238 buffer[ret] = 0; 237 buffer[ret] = 0;
239qWarning("Got: '%s'", buffer); 238qWarning("Got: '%s'", buffer);
240 buf.append(QString(buffer)); 239 buf.append(QString(buffer));
241 if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) 240 if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY")))
242{ 241{
243qWarning("Receiving: '%s'", buf.latin1()); 242qWarning("Receiving: '%s'", buf.latin1());
244 return buf; 243 return buf;
245} 244}
246 } 245 }
247 else if(ret < 0) 246 else if(ret < 0)
248 { 247 {
249 if(errno != EAGAIN) reset(); 248 if(errno != EAGAIN) reset();
249 else if(!(counter++ % 100)) qApp->processEvents();
250 } 250 }
251 else if(!(counter++ % 100)) qApp->processEvents();
251 } 252 }
252 253
253 return QString::null; 254 return QString::null;
254} 255}
255 256
256void Dialer::switchState(int newstate) 257void Dialer::switchState(int newstate)
257{ 258{
258 int oldstate = state; 259 int oldstate = state;
259 state = newstate; 260 state = newstate;
260 261
261 switch(state) 262 switch(state)
262 { 263 {
263 case state_cancel: 264 case state_cancel:
264 status->setText(QObject::tr("Cancelling...")); 265 status->setText(QObject::tr("Cancelling..."));
265 progress->setProgress(0); 266 progress->setProgress(0);
266 break; 267 break;
267 case state_preinit: 268 case state_preinit:
268 status->setText(QObject::tr("Searching modem")); 269 status->setText(QObject::tr("Searching modem"));
269 progress->setProgress(10); 270 progress->setProgress(10);
270 break; 271 break;
271 case state_init: 272 case state_init:
272 status->setText(QObject::tr("Initializing...")); 273 status->setText(QObject::tr("Initializing..."));
273 progress->setProgress(20); 274 progress->setProgress(20);
274 break; 275 break;
275 case state_options: 276 case state_options:
276 status->setText(QObject::tr("Reset speakers")); 277 status->setText(QObject::tr("Reset speakers"));
277 progress->setProgress(30); 278 progress->setProgress(30);
278 break; 279 break;
279 case state_dialtone: 280 case state_dialtone:
280 status->setText(QObject::tr("Turning off dialtone")); 281 status->setText(QObject::tr("Turning off dialtone"));
281 progress->setProgress(40); 282 progress->setProgress(40);
282 break; 283 break;
283 case state_dialing: 284 case state_dialing:
284 if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); 285 if(oldstate != state_dialing) status->setText(QObject::tr("Dial number"));
285 else status->setText(QObject::tr("Line busy, redialing number")); 286 else status->setText(QObject::tr("Line busy, redialing number"));
286 progress->setProgress(50); 287 progress->setProgress(50);
287 break; 288 break;
288 case state_online: 289 case state_online:
289 status->setText(QObject::tr("Connection established")); 290 status->setText(QObject::tr("Connection established"));
290 progress->setProgress(100); 291 progress->setProgress(100);
291 cancel->setText(QObject::tr("Dismiss")); 292 cancel->setText(QObject::tr("Dismiss"));
292 break; 293 break;
293 } 294 }
294} 295}
295 296