summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/dialer.cpp
blob: f6758ede93c5549a36b0b9d249fdc93f6463f578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "dialer.h"

#include <qlayout.h>
#include <qprogressbar.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qapp.h>

Dialer::Dialer(const QString& number, QWidget *parent, const char *name)
: QDialog(parent, name, true)
{
	QVBoxLayout *vbox;
	QLabel *desc;

	desc = new QLabel(QObject::tr("Dialing number: %1").arg(number), this);
	progress = new QProgressBar(this);
	status = new QLabel("", this);
	status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
	cancel = new QPushButton(QObject::tr("Cancel"), this);

	vbox = new QVBoxLayout(this, 2);
	vbox->add(desc);
	vbox->add(progress);
	vbox->add(status);
	vbox->add(cancel);

	reset();

	connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));

	show();

	dial(number);
}

Dialer::~Dialer()
{
}

void Dialer::slotCancel()
{
	if(state != state_online) reset();
	close();
}

void Dialer::reset()
{
	switchState(state_init);
}

void Dialer::dial(const QString& number)
{
	send("ATZ");
	QString response = receive();

	switchState(state_options);

	send("ATM0L0");
	QString response2 = receive();

	switchState(state_dialing);

	send(QString("ATDT %1").arg(number));
	QString response3 = receive();

	switchState(state_online);
}

void Dialer::send(const QString& msg)
{

}

QString Dialer::receive()
{
	for(int i = 0; i < 200000; i++)
		qApp->processEvents();
	return QString::null;
}

void Dialer::switchState(int newstate)
{
	state = newstate;

	switch(state)
	{
		case state_init:
			status->setText(QObject::tr("Initializing..."));
			progress->setProgress(10);
			break;
		case state_options:
			status->setText(QObject::tr("Reset speakers"));
			progress->setProgress(20);
			break;
		case state_dialing:
			status->setText(QObject::tr("Dial number"));
			progress->setProgress(30);
			break;
		case state_online:
			status->setText(QObject::tr("Connection established"));
			progress->setProgress(100);
			cancel->setText(QObject::tr("Dismiss"));
			break;
	}
}