4 #include <QtDBus/QtDBus>
6 #define PROCESSING "Processing..."
8 class QUssd : public QMainWindow {
12 QUssd(QString message, bool lock = false) {
15 QActionGroup *filterGroup = new QActionGroup(this);
16 filterGroup->setExclusive(true);
18 actPortrait = new QAction(tr("Portrait"), filterGroup);
19 actPortrait->setCheckable(true);
21 actLandscape = new QAction(tr("Landscape"), filterGroup);
22 actLandscape->setCheckable(true);
24 actAuto = new QAction(tr("Auto"), filterGroup);
25 actAuto->setCheckable(true);
26 actAuto->setChecked(true);
28 menuBar()->addActions(filterGroup->actions());
30 connect(actPortrait, SIGNAL(changed()), this, SLOT(setOrientation()));
31 connect(actLandscape, SIGNAL(changed()), this, SLOT(setOrientation()));
32 connect(actAuto, SIGNAL(changed()), this, SLOT(setOrientation()));
34 replyLabel = new QLabel(message);
35 replyLabel->setMinimumWidth(400);
36 replyLabel->setMaximumHeight(100);
37 replyLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
39 numberLabel = new QLabel("");
40 replyLabel->setMinimumWidth(400);
41 replyLabel->setMinimumHeight(150);
42 replyLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
44 indicationLayout = new QVBoxLayout;
45 indicationLayout->addWidget(numberLabel);
46 indicationLayout->addWidget(replyLabel);
48 padDel = new QPushButton("C");
49 connect(padDel, SIGNAL(clicked()), this, SLOT(del()));
50 padDel->setMaximumWidth(150);
51 padDel->setMaximumHeight(72);
52 padDel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
53 padSend = new QPushButton("SEND");
54 connect(padSend, SIGNAL(clicked()), this, SLOT(send()));
55 padSend->setMaximumWidth(300);
56 padSend->setMaximumHeight(72);
57 padSend->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
59 btnLayout = new QHBoxLayout;
60 btnLayout->addWidget(padSend);
61 btnLayout->addWidget(padDel);
63 numberPad = new QGridLayout();
64 numberPad->setSpacing(2);
66 padBtn1 = new QPushButton("1");
67 connect(padBtn1, SIGNAL(clicked()), this, SLOT(add1()));
68 padBtn1->setMaximumWidth(150);
69 padBtn1->setMaximumHeight(72);
70 padBtn1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
71 numberPad->addWidget(padBtn1, 0, 0);
72 padBtn2 = new QPushButton("2");
73 connect(padBtn2, SIGNAL(clicked()), this, SLOT(add2()));
74 padBtn2->setMaximumWidth(150);
75 padBtn2->setMaximumHeight(72);
76 padBtn2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
77 numberPad->addWidget(padBtn2, 0, 1);
78 padBtn3 = new QPushButton("3");
79 connect(padBtn3, SIGNAL(clicked()), this, SLOT(add3()));
80 padBtn3->setMaximumWidth(150);
81 padBtn3->setMaximumHeight(72);
82 padBtn3->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
83 numberPad->addWidget(padBtn3, 0, 2);
84 padBtn4 = new QPushButton("4");
85 connect(padBtn4, SIGNAL(clicked()), this, SLOT(add4()));
86 padBtn4->setMaximumWidth(150);
87 padBtn4->setMaximumHeight(72);
88 padBtn4->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
89 numberPad->addWidget(padBtn4, 1, 0);
90 padBtn5 = new QPushButton("5");
91 connect(padBtn5, SIGNAL(clicked()), this, SLOT(add5()));
92 padBtn5->setMaximumWidth(150);
93 padBtn5->setMaximumHeight(72);
94 padBtn5->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
95 numberPad->addWidget(padBtn5, 1, 1);
96 padBtn6 = new QPushButton("6");
97 connect(padBtn6, SIGNAL(clicked()), this, SLOT(add6()));
98 padBtn6->setMaximumWidth(150);
99 padBtn6->setMaximumHeight(72);
100 padBtn6->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
101 numberPad->addWidget(padBtn6, 1, 2);
102 padBtn7 = new QPushButton("7");
103 connect(padBtn7, SIGNAL(clicked()), this, SLOT(add7()));
104 padBtn7->setMaximumWidth(150);
105 padBtn7->setMaximumHeight(72);
106 padBtn7->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
107 numberPad->addWidget(padBtn7, 2, 0);
108 padBtn8 = new QPushButton("8");
109 connect(padBtn8, SIGNAL(clicked()), this, SLOT(add8()));
110 padBtn8->setMaximumWidth(150);
111 padBtn8->setMaximumHeight(72);
112 padBtn8->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
113 numberPad->addWidget(padBtn8, 2, 1);
114 padBtn9 = new QPushButton("9");
115 connect(padBtn9, SIGNAL(clicked()), this, SLOT(add9()));
116 padBtn9->setMaximumWidth(150);
117 padBtn9->setMaximumHeight(72);
118 padBtn9->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
119 numberPad->addWidget(padBtn9, 2, 2);
120 padBtnStar = new QPushButton("*+");
121 connect(padBtnStar, SIGNAL(clicked()), this, SLOT(addStar()));
122 padBtnStar->setMaximumWidth(150);
123 padBtnStar->setMaximumHeight(72);
124 padBtnStar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
125 numberPad->addWidget(padBtnStar, 3, 0);
126 padBtn0 = new QPushButton("0");
127 connect(padBtn0, SIGNAL(clicked()), this, SLOT(add0()));
128 padBtn0->setMaximumWidth(150);
129 padBtn0->setMaximumHeight(72);
130 padBtn0->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
131 numberPad->addWidget(padBtn0, 3, 1);
132 padBtnGrid = new QPushButton("#");
133 connect(padBtnGrid, SIGNAL(clicked()), this, SLOT(addGrid()));
134 padBtnGrid->setMaximumWidth(150);
135 padBtnGrid->setMaximumHeight(72);
136 padBtnGrid->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
137 numberPad->addWidget(padBtnGrid, 3, 2);
139 centralWidget = new QWidget;
140 setCentralWidget(centralWidget);
141 mainLayout = new QGridLayout(centralWidget);
143 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
145 orientationChanged();
151 USSDquery->write("exit\n");
152 USSDquery->closeWriteChannel();
153 USSDquery->waitForFinished();
159 void restartUSSD( int, QProcess::ExitStatus) {
160 replyLabel->setText(QString("Error: ")+QString::fromUtf8(reply));
171 QDBusInterface iface("su.kibergus.ussdd", "/su/kibergus/ussdd", "su.kibergus.ussdd", QDBusConnection::systemBus());
173 iface.call("skip_next");
174 USSDquery->write(number.toUtf8().data());
175 USSDquery->write("\n");
176 number = tr(PROCESSING);
182 for (line = USSDquery->readLine(); !line.isEmpty(); line = USSDquery->readLine()) {
184 if (reply.endsWith("\n==MESSAGE END ==\n")) {
185 reply.chop(strlen("\n==MESSAGE END ==\n"));
186 if (!reply.isEmpty())
187 replyLabel->setText(QString::fromUtf8(reply));
196 void setOrientation() {
197 if (actLandscape->isChecked())
198 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
199 else if (actPortrait->isChecked())
200 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
202 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
205 void orientationChanged() {
206 QRect screenGeometry = QApplication::desktop()->screenGeometry();
207 mainLayout->removeItem(indicationLayout);
208 mainLayout->removeItem(numberPad);
209 mainLayout->removeItem(btnLayout);
211 if (screenGeometry.width() > screenGeometry.height()) {
212 mainLayout->addLayout(indicationLayout, 0, 0);
213 mainLayout->addLayout(btnLayout, 1, 0);
214 mainLayout->addLayout(numberPad, 0, 1, -1, 1);
216 mainLayout->addLayout(indicationLayout, 0, 0);
217 mainLayout->addLayout(numberPad, 1, 0);
218 mainLayout->addLayout(btnLayout, 2, 0);
223 if (number != tr(PROCESSING)) {
230 if (number != tr(PROCESSING)) {
237 if (number != tr(PROCESSING)) {
244 if (number != tr(PROCESSING)) {
251 if (number != tr(PROCESSING)) {
258 if (number != tr(PROCESSING)) {
265 if (number != tr(PROCESSING)) {
272 if (number != tr(PROCESSING)) {
279 if (number != tr(PROCESSING)) {
286 if (number != tr(PROCESSING)) {
293 if (number != tr(PROCESSING)) {
300 if (number != tr(PROCESSING)) {
301 if (number[number.length()-1] == '*') {
302 number[number.length()-1] = '+';
310 if (number != tr(PROCESSING)) {
317 void startUSSD (bool lock = false) {
318 QString program = "ussdquery.py";
319 QStringList arguments;
320 arguments << "interactive" << "-d" << "\n==MESSAGE END ==\n";
324 USSDquery = new QProcess();
325 USSDquery->setProcessChannelMode(QProcess::MergedChannels);
326 connect(USSDquery, SIGNAL(readyReadStandardOutput()), this, SLOT(readData()));
327 connect(USSDquery, SIGNAL(readyReadStandardError()), this, SLOT(readData()));
328 connect(USSDquery, SIGNAL(finished( int, QProcess::ExitStatus )), this, SLOT(restartUSSD( int, QProcess::ExitStatus )));
330 USSDquery->start(program, arguments);
334 numberLabel->setText(QString("<p style=\"font-size: 30pt;\" align=\"center\">")+number+"</p>");
339 QAction *actPortrait;
340 QAction *actLandscape;
343 QVBoxLayout *indicationLayout;
344 QHBoxLayout *btnLayout;
345 QGridLayout *numberPad;
346 QGridLayout *mainLayout;
347 QWidget* centralWidget;
349 QPushButton *padBtn1;
350 QPushButton *padBtn2;
351 QPushButton *padBtn3;
352 QPushButton *padBtn4;
353 QPushButton *padBtn5;
354 QPushButton *padBtn6;
355 QPushButton *padBtn7;
356 QPushButton *padBtn8;
357 QPushButton *padBtn9;
358 QPushButton *padBtn0;
359 QPushButton *padBtnStar;
360 QPushButton *padBtnGrid;
363 QPushButton *padSend;
371 int main(int argc, char *argv[]) {
372 QApplication app(argc, argv);
377 message = message.fromUtf8(argv[1]);
378 if (argc >=3 && !strcmp(argv[2], "lock"))
381 QUssd w(message, lock);