5 #define PROCESSING "Processing..."
7 class QUssd : public QMainWindow {
11 QUssd(QString message, bool lock = false) {
14 QActionGroup *filterGroup = new QActionGroup(this);
15 filterGroup->setExclusive(true);
17 actPortrait = new QAction(tr("Portrait"), filterGroup);
18 actPortrait->setCheckable(true);
20 actLandscape = new QAction(tr("Landscape"), filterGroup);
21 actLandscape->setCheckable(true);
23 actAuto = new QAction(tr("Auto"), filterGroup);
24 actAuto->setCheckable(true);
25 actAuto->setChecked(true);
27 menuBar()->addActions(filterGroup->actions());
29 connect(actPortrait, SIGNAL(changed()), this, SLOT(setOrientation()));
30 connect(actLandscape, SIGNAL(changed()), this, SLOT(setOrientation()));
31 connect(actAuto, SIGNAL(changed()), this, SLOT(setOrientation()));
33 replyLabel = new QTextEdit(message);
34 replyLabel->setMinimumWidth(400);
35 replyLabel->setMinimumHeight(200);
36 replyLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
37 replyLabel->setFrameStyle(QFrame::NoFrame);
38 QPalette pal = palette();
39 pal.setColor(QPalette::Base, Qt::transparent);
40 pal.setColor(QPalette::Text, pal.color(QPalette::ButtonText));
41 replyLabel->setPalette(pal);
42 // replyLabel->setTextBackgroundColor(Qt::black);
43 // replyLabel->setTextColor(Qt::white);
44 replyLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
46 numberLabel = new QLabel("");
47 numberLabel->setMinimumWidth(400);
48 numberLabel->setMaximumHeight(100);
49 numberLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
51 indicationLayout = new QVBoxLayout;
52 indicationLayout->addWidget(numberLabel);
54 indicationLayout->addWidget(replyLabel);
56 padDel = new QPushButton("C");
57 connect(padDel, SIGNAL(clicked()), this, SLOT(del()));
58 padDel->setMaximumWidth(150);
59 padDel->setMaximumHeight(72);
60 padDel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
61 padSend = new QPushButton("SEND");
62 connect(padSend, SIGNAL(clicked()), this, SLOT(send()));
63 padSend->setMaximumWidth(300);
64 padSend->setMaximumHeight(72);
65 padSend->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
67 btnLayout = new QHBoxLayout;
68 btnLayout->addWidget(padSend);
69 btnLayout->addWidget(padDel);
71 numberPad = new QGridLayout();
72 numberPad->setSpacing(2);
74 padBtn1 = new QPushButton("1");
75 connect(padBtn1, SIGNAL(clicked()), this, SLOT(add1()));
76 padBtn1->setMaximumWidth(150);
77 padBtn1->setMaximumHeight(72);
78 padBtn1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
79 numberPad->addWidget(padBtn1, 0, 0);
80 padBtn2 = new QPushButton("2");
81 connect(padBtn2, SIGNAL(clicked()), this, SLOT(add2()));
82 padBtn2->setMaximumWidth(150);
83 padBtn2->setMaximumHeight(72);
84 padBtn2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
85 numberPad->addWidget(padBtn2, 0, 1);
86 padBtn3 = new QPushButton("3");
87 connect(padBtn3, SIGNAL(clicked()), this, SLOT(add3()));
88 padBtn3->setMaximumWidth(150);
89 padBtn3->setMaximumHeight(72);
90 padBtn3->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
91 numberPad->addWidget(padBtn3, 0, 2);
92 padBtn4 = new QPushButton("4");
93 connect(padBtn4, SIGNAL(clicked()), this, SLOT(add4()));
94 padBtn4->setMaximumWidth(150);
95 padBtn4->setMaximumHeight(72);
96 padBtn4->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
97 numberPad->addWidget(padBtn4, 1, 0);
98 padBtn5 = new QPushButton("5");
99 connect(padBtn5, SIGNAL(clicked()), this, SLOT(add5()));
100 padBtn5->setMaximumWidth(150);
101 padBtn5->setMaximumHeight(72);
102 padBtn5->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
103 numberPad->addWidget(padBtn5, 1, 1);
104 padBtn6 = new QPushButton("6");
105 connect(padBtn6, SIGNAL(clicked()), this, SLOT(add6()));
106 padBtn6->setMaximumWidth(150);
107 padBtn6->setMaximumHeight(72);
108 padBtn6->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
109 numberPad->addWidget(padBtn6, 1, 2);
110 padBtn7 = new QPushButton("7");
111 connect(padBtn7, SIGNAL(clicked()), this, SLOT(add7()));
112 padBtn7->setMaximumWidth(150);
113 padBtn7->setMaximumHeight(72);
114 padBtn7->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
115 numberPad->addWidget(padBtn7, 2, 0);
116 padBtn8 = new QPushButton("8");
117 connect(padBtn8, SIGNAL(clicked()), this, SLOT(add8()));
118 padBtn8->setMaximumWidth(150);
119 padBtn8->setMaximumHeight(72);
120 padBtn8->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
121 numberPad->addWidget(padBtn8, 2, 1);
122 padBtn9 = new QPushButton("9");
123 connect(padBtn9, SIGNAL(clicked()), this, SLOT(add9()));
124 padBtn9->setMaximumWidth(150);
125 padBtn9->setMaximumHeight(72);
126 padBtn9->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
127 numberPad->addWidget(padBtn9, 2, 2);
128 padBtnStar = new QPushButton("*+");
129 connect(padBtnStar, SIGNAL(clicked()), this, SLOT(addStar()));
130 padBtnStar->setMaximumWidth(150);
131 padBtnStar->setMaximumHeight(72);
132 padBtnStar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
133 numberPad->addWidget(padBtnStar, 3, 0);
134 padBtn0 = new QPushButton("0");
135 connect(padBtn0, SIGNAL(clicked()), this, SLOT(add0()));
136 padBtn0->setMaximumWidth(150);
137 padBtn0->setMaximumHeight(72);
138 padBtn0->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
139 numberPad->addWidget(padBtn0, 3, 1);
140 padBtnGrid = new QPushButton("#");
141 connect(padBtnGrid, SIGNAL(clicked()), this, SLOT(addGrid()));
142 padBtnGrid->setMaximumWidth(150);
143 padBtnGrid->setMaximumHeight(72);
144 padBtnGrid->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
145 numberPad->addWidget(padBtnGrid, 3, 2);
147 centralWidget = new QWidget;
148 setCentralWidget(centralWidget);
149 mainLayout = new QGridLayout(centralWidget);
151 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
153 orientationChanged();
159 USSDquery->write("exit\n");
160 USSDquery->closeWriteChannel();
161 USSDquery->waitForFinished();
167 void restartUSSD( int, QProcess::ExitStatus) {
168 replyLabel->setText(QString("Error: ")+QString::fromUtf8(reply));
179 USSDquery->write(number.toUtf8().data());
180 USSDquery->write("\n");
181 number = tr(PROCESSING);
187 for (line = USSDquery->readLine(); !line.isEmpty(); line = USSDquery->readLine()) {
189 if (reply.endsWith("\n==MESSAGE END ==\n")) {
190 reply.chop(strlen("\n==MESSAGE END ==\n"));
191 if (!reply.isEmpty())
192 replyLabel->setText(QString::fromUtf8(reply));
201 void setOrientation() {
202 if (actLandscape->isChecked())
203 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
204 else if (actPortrait->isChecked())
205 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
207 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
210 void orientationChanged() {
211 QRect screenGeometry = QApplication::desktop()->screenGeometry();
212 mainLayout->removeItem(indicationLayout);
213 mainLayout->removeItem(numberPad);
214 mainLayout->removeItem(btnLayout);
216 if (screenGeometry.width() > screenGeometry.height()) {
217 mainLayout->addLayout(indicationLayout, 0, 0);
218 mainLayout->addLayout(btnLayout, 1, 0);
219 mainLayout->addLayout(numberPad, 0, 1, -1, 1);
221 mainLayout->addLayout(indicationLayout, 0, 0);
222 mainLayout->addLayout(numberPad, 1, 0);
223 mainLayout->addLayout(btnLayout, 2, 0);
228 if (number != tr(PROCESSING)) {
235 if (number != tr(PROCESSING)) {
242 if (number != tr(PROCESSING)) {
249 if (number != tr(PROCESSING)) {
256 if (number != tr(PROCESSING)) {
263 if (number != tr(PROCESSING)) {
270 if (number != tr(PROCESSING)) {
277 if (number != tr(PROCESSING)) {
284 if (number != tr(PROCESSING)) {
291 if (number != tr(PROCESSING)) {
298 if (number != tr(PROCESSING)) {
305 if (number != tr(PROCESSING)) {
306 // Do not change star if it was created more than 3 seconds before.
307 if (number[number.length()-1] == '*' && lastStar.elapsed() < 3*1000) {
308 number[number.length()-1] = '+';
319 if (number != tr(PROCESSING)) {
326 void startUSSD (bool lock = false) {
327 QString program = "ussdquery.py";
328 QStringList arguments;
329 arguments << "interactive" << "-d" << "\n==MESSAGE END ==\n";
333 USSDquery = new QProcess();
334 USSDquery->setProcessChannelMode(QProcess::MergedChannels);
335 connect(USSDquery, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
336 connect(USSDquery, SIGNAL(readyReadStandardError()), this, SLOT(readData()));
337 connect(USSDquery, SIGNAL(finished( int, QProcess::ExitStatus )), this, SLOT(restartUSSD( int, QProcess::ExitStatus )));
339 USSDquery->start(program, arguments);
343 numberLabel->setText(QString("<p style=\"font-size: 30pt;\" align=\"center\">")+number+"</p>");
346 QTextEdit *replyLabel;
348 QAction *actPortrait;
349 QAction *actLandscape;
352 QVBoxLayout *indicationLayout;
353 QHBoxLayout *btnLayout;
354 QGridLayout *numberPad;
355 QGridLayout *mainLayout;
356 QWidget* centralWidget;
358 QPushButton *padBtn1;
359 QPushButton *padBtn2;
360 QPushButton *padBtn3;
361 QPushButton *padBtn4;
362 QPushButton *padBtn5;
363 QPushButton *padBtn6;
364 QPushButton *padBtn7;
365 QPushButton *padBtn8;
366 QPushButton *padBtn9;
367 QPushButton *padBtn0;
368 QPushButton *padBtnStar;
369 QPushButton *padBtnGrid;
372 QPushButton *padSend;
382 int main(int argc, char *argv[]) {
383 QApplication app(argc, argv);
388 message = message.fromUtf8(argv[1]);
389 if (argc >=3 && !strcmp(argv[2], "lock"))
392 QUssd w(message, lock);