summaryrefslogtreecommitdiff
path: root/noncore/unsupported/gsmtool/gsmtool.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/gsmtool/gsmtool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/gsmtool/gsmtool.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/unsupported/gsmtool/gsmtool.cpp b/noncore/unsupported/gsmtool/gsmtool.cpp
index 5940b0e..47920e5 100644
--- a/noncore/unsupported/gsmtool/gsmtool.cpp
+++ b/noncore/unsupported/gsmtool/gsmtool.cpp
@@ -1,235 +1,235 @@
1#include "gsmtool.h" 1#include "gsmtool.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qcombobox.h> 3#include <qcombobox.h>
4#include <qlineedit.h> 4#include <qlineedit.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qtabwidget.h> 6#include <qtabwidget.h>
7#include <qlistview.h> 7#include <qlistview.h>
8#include <qtextbrowser.h> 8#include <qtextbrowser.h>
9#include <qmultilineedit.h> 9#include <qmultilineedit.h>
10 10
11#include <termios.h> 11#include <termios.h>
12 12
13#include <gsmlib/gsm_me_ta.h> 13#include <gsmlib/gsm_me_ta.h>
14#include <gsmlib/gsm_unix_serial.h> 14#include <gsmlib/gsm_unix_serial.h>
15#include <gsmlib/gsm_sms.h> 15#include <gsmlib/gsm_sms.h>
16#include <gsmlib/gsm_sorted_sms_store.h> 16#include <gsmlib/gsm_sorted_sms_store.h>
17 17
18using namespace gsmlib; 18using namespace gsmlib;
19 19
20 20
21/* 21/*
22 * Constructs a GSMTool which is a child of 'parent', with the 22 * Constructs a GSMTool which is a child of 'parent', with the
23 * name 'name' and widget flags set to 'f' 23 * name 'name' and widget flags set to 'f'
24 */ 24 */
25GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl ) 25GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl )
26 : GSMToolBase( parent, name, fl ) 26 : GSMToolBase( parent, name, fl )
27{ 27{
28 devicelocked = 0; 28 devicelocked = 0;
29 me = NULL; 29 me = NULL;
30 sms_store = NULL; 30 sms_store = NULL;
31 setConnected(FALSE); 31 setConnected(FALSE);
32 /* FIXME: Persistent settings for device/baudrate */ 32 /* FIXME: Persistent settings for device/baudrate */
33 connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton())); 33 connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton()));
34 connect(SMSDeleteButton, SIGNAL(clicked()), this, SLOT(doSMSDeleteButton())); 34 connect(SMSDeleteButton, SIGNAL(clicked()), this, SLOT(doSMSDeleteButton()));
35 connect(SMSSendButton, SIGNAL(clicked()), this, SLOT(doSMSSendButton())); 35 connect(SMSSendButton, SIGNAL(clicked()), this, SLOT(doSMSSendButton()));
36 connect(NewSMSClearButton, SIGNAL(clicked()), this, SLOT(doNewSMSClearButton())); 36 connect(NewSMSClearButton, SIGNAL(clicked()), this, SLOT(doNewSMSClearButton()));
37 connect(NewSMSSaveButton, SIGNAL(clicked()), this, SLOT(doNewSMSSaveButton())); 37 connect(NewSMSSaveButton, SIGNAL(clicked()), this, SLOT(doNewSMSSaveButton()));
38 connect(NewSMSSendButton, SIGNAL(clicked()), this, SLOT(doNewSMSSendButton())); 38 connect(NewSMSSendButton, SIGNAL(clicked()), this, SLOT(doNewSMSSendButton()));
39 connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton())); 39 connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton()));
40 connect(TabWidget2, SIGNAL(currentChanged(QWidget *)), this, SLOT(doTabChanged())); 40 connect(TabWidget2, SIGNAL(currentChanged(QWidget*)), this, SLOT(doTabChanged()));
41 connect(SMSStoreList, SIGNAL(activated(int)), this, SLOT(doSMSStoreChanged())); 41 connect(SMSStoreList, SIGNAL(activated(int)), this, SLOT(doSMSStoreChanged()));
42 connect(SMSViewType, SIGNAL(activated(int)), this, SLOT(doSMSTypeChanged())); 42 connect(SMSViewType, SIGNAL(activated(int)), this, SLOT(doSMSTypeChanged()));
43 connect(SMSList, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(doSelectedSMSChanged(QListViewItem *))); 43 connect(SMSList, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(doSelectedSMSChanged(QListViewItem*)));
44 timerid = -1; // Is this not possible normally? 44 timerid = -1; // Is this not possible normally?
45} 45}
46 46
47/* 47/*
48 * Destroys the object and frees any allocated resources 48 * Destroys the object and frees any allocated resources
49 */ 49 */
50GSMTool::~GSMTool() 50GSMTool::~GSMTool()
51{ 51{
52 // no need to delete child widgets, Qt does it all for us 52 // no need to delete child widgets, Qt does it all for us
53 if (devicelocked) 53 if (devicelocked)
54 unlockDevice(); 54 unlockDevice();
55} 55}
56const speed_t GSMTool::baudrates[12] = { 56const speed_t GSMTool::baudrates[12] = {
57 B300, B600, B1200, B2400, B4800, B9600, B19200, 57 B300, B600, B1200, B2400, B4800, B9600, B19200,
58 B38400, B57600, B115200, B230400, B460800 58 B38400, B57600, B115200, B230400, B460800
59}; 59};
60 60
61int GSMTool::lockDevice( ) 61int GSMTool::lockDevice( )
62{ 62{
63 devicelocked = 1; 63 devicelocked = 1;
64 /* FIXME */ 64 /* FIXME */
65 return 0; 65 return 0;
66} 66}
67 67
68void GSMTool::unlockDevice( ) 68void GSMTool::unlockDevice( )
69{ 69{
70 devicelocked = 0; 70 devicelocked = 0;
71} 71}
72 72
73void GSMTool::setConnected( bool conn ) 73void GSMTool::setConnected( bool conn )
74{ 74{
75 TabWidget2->setTabEnabled(tab_2, conn); 75 TabWidget2->setTabEnabled(tab_2, conn);
76 TabWidget2->setTabEnabled(tab_3, conn); 76 TabWidget2->setTabEnabled(tab_3, conn);
77 //TabWidget2->setTabEnabled(tab_4, conn); 77 //TabWidget2->setTabEnabled(tab_4, conn);
78 NewSMSSendButton->setEnabled(conn); 78 NewSMSSendButton->setEnabled(conn);
79 MfrLabel->setEnabled(conn); 79 MfrLabel->setEnabled(conn);
80 MfrText->setEnabled(conn); 80 MfrText->setEnabled(conn);
81 ModelLabel->setEnabled(conn); 81 ModelLabel->setEnabled(conn);
82 ModelText->setEnabled(conn); 82 ModelText->setEnabled(conn);
83 RevisionLabel->setEnabled(conn); 83 RevisionLabel->setEnabled(conn);
84 RevisionText->setEnabled(conn); 84 RevisionText->setEnabled(conn);
85 SerialLabel->setEnabled(conn); 85 SerialLabel->setEnabled(conn);
86 SerialText->setEnabled(conn); 86 SerialText->setEnabled(conn);
87 87
88} 88}
89void GSMTool::doTabChanged() 89void GSMTool::doTabChanged()
90{ 90{
91 int index = TabWidget2->currentPageIndex(); 91 int index = TabWidget2->currentPageIndex();
92 qDebug("tab changed to %d", index); 92 qDebug("tab changed to %d", index);
93 93
94 if (index == 1) { 94 if (index == 1) {
95 timerid = startTimer(5000); 95 timerid = startTimer(5000);
96 timerEvent(NULL); 96 timerEvent(NULL);
97 } else if (timerid != -1) { 97 } else if (timerid != -1) {
98 killTimer(timerid); 98 killTimer(timerid);
99 timerid = -1; 99 timerid = -1;
100 } 100 }
101} 101}
102 102
103void GSMTool::timerEvent( QTimerEvent * ) 103void GSMTool::timerEvent( QTimerEvent * )
104{ 104{
105 OPInfo opi; 105 OPInfo opi;
106 106
107 opi = me->getCurrentOPInfo(); 107 opi = me->getCurrentOPInfo();
108 108
109 if (opi._numericName == NOT_SET) { 109 if (opi._numericName == NOT_SET) {
110 NetStatText->setText("No network"); 110 NetStatText->setText("No network");
111 NetworkLabel->setEnabled(FALSE); 111 NetworkLabel->setEnabled(FALSE);
112 NetworkText->setEnabled(FALSE); 112 NetworkText->setEnabled(FALSE);
113 NetworkText->setText(""); 113 NetworkText->setText("");
114 SigStrText->setEnabled(FALSE); 114 SigStrText->setEnabled(FALSE);
115 SigStrText->setText(""); 115 SigStrText->setText("");
116 dB->setEnabled(FALSE); 116 dB->setEnabled(FALSE);
117 SigStrLabel->setEnabled(FALSE); 117 SigStrLabel->setEnabled(FALSE);
118 } else { 118 } else {
119 // FIXME: Add 'roaming' info from AT+CFUN 119 // FIXME: Add 'roaming' info from AT+CFUN
120 qDebug("network"); 120 qDebug("network");
121 NetStatText->setText("Registered"); 121 NetStatText->setText("Registered");
122 NetworkLabel->setEnabled(TRUE); 122 NetworkLabel->setEnabled(TRUE);
123 NetworkText->setEnabled(TRUE); 123 NetworkText->setEnabled(TRUE);
124 NetworkText->setText(opi._longName.c_str()); 124 NetworkText->setText(opi._longName.c_str());
125 SigStrText->setEnabled(TRUE); 125 SigStrText->setEnabled(TRUE);
126 126
127 qDebug("get sig str"); 127 qDebug("get sig str");
128 int csq = me->getSignalStrength(); 128 int csq = me->getSignalStrength();
129 if (csq == 0) { 129 if (csq == 0) {
130 SigStrText->setText("<= -113"); 130 SigStrText->setText("<= -113");
131 dB->setEnabled(TRUE); 131 dB->setEnabled(TRUE);
132 SigStrLabel->setEnabled(TRUE); 132 SigStrLabel->setEnabled(TRUE);
133 } else if (csq == 99) { 133 } else if (csq == 99) {
134 SigStrText->setText("Unknown"); 134 SigStrText->setText("Unknown");
135 dB->setEnabled(FALSE); 135 dB->setEnabled(FALSE);
136 SigStrLabel->setEnabled(FALSE); 136 SigStrLabel->setEnabled(FALSE);
137 } else { 137 } else {
138 char buf[6]; 138 char buf[6];
139 sprintf(buf, "%d", -113 + (2*csq)); 139 sprintf(buf, "%d", -113 + (2*csq));
140 SigStrText->setText(buf); 140 SigStrText->setText(buf);
141 dB->setEnabled(TRUE); 141 dB->setEnabled(TRUE);
142 SigStrLabel->setEnabled(TRUE); 142 SigStrLabel->setEnabled(TRUE);
143 } 143 }
144 } 144 }
145} 145}
146 146
147void GSMTool::doSMSStoreChanged() 147void GSMTool::doSMSStoreChanged()
148{ 148{
149 const char *storename = SMSStoreList->currentText().ascii(); 149 const char *storename = SMSStoreList->currentText().ascii();
150 qDebug("Store Changed to '%s'", storename); 150 qDebug("Store Changed to '%s'", storename);
151 if (!strcmp(storename, "None")) { 151 if (!strcmp(storename, "None")) {
152 sms_store = NULL; 152 sms_store = NULL;
153 } else try { 153 } else try {
154 sms_store = new SortedSMSStore(me->getSMSStore(storename)); 154 sms_store = new SortedSMSStore(me->getSMSStore(storename));
155 sms_store->setSortOrder(ByIndex); 155 sms_store->setSortOrder(ByIndex);
156 156
157 qDebug("got store of size %d", sms_store->size()); 157 qDebug("got store of size %d", sms_store->size());
158 } catch (GsmException) { 158 } catch (GsmException) {
159 sms_store = NULL; 159 sms_store = NULL;
160 qDebug("get store failed"); 160 qDebug("get store failed");
161 } 161 }
162 162
163 SMSList->setEnabled(!(sms_store == NULL)); 163 SMSList->setEnabled(!(sms_store == NULL));
164 NewSMSSaveButton->setEnabled(!(sms_store == NULL)); 164 NewSMSSaveButton->setEnabled(!(sms_store == NULL));
165 doSMSTypeChanged(); 165 doSMSTypeChanged();
166} 166}
167 167
168void GSMTool::doSMSTypeChanged() 168void GSMTool::doSMSTypeChanged()
169{ 169{
170 int direction = SMSViewType->currentItem(); 170 int direction = SMSViewType->currentItem();
171 qDebug("direction %s\n", direction?"outgoing":"incoming"); 171 qDebug("direction %s\n", direction?"outgoing":"incoming");
172 if (direction) 172 if (direction)
173 SMSSendButton->setText("Send"); 173 SMSSendButton->setText("Send");
174 else 174 else
175 SMSSendButton->setText("Reply"); 175 SMSSendButton->setText("Reply");
176 176
177 SMSList->clear(); 177 SMSList->clear();
178 doSelectedSMSChanged(NULL); 178 doSelectedSMSChanged(NULL);
179 179
180 if (sms_store == NULL) 180 if (sms_store == NULL)
181 return; 181 return;
182 for (SortedSMSStore::iterator e = sms_store->begin(); 182 for (SortedSMSStore::iterator e = sms_store->begin();
183 e != sms_store->end(); e++) { 183 e != sms_store->end(); e++) {
184 // qDebug("Message %d", i); 184 // qDebug("Message %d", i);
185 qDebug("Is%sempty", e->empty()?" ":" not "); 185 qDebug("Is%sempty", e->empty()?" ":" not ");
186 if (e->empty()) 186 if (e->empty())
187 continue; 187 continue;
188 188
189 qDebug("Status %d", e->status()); 189 qDebug("Status %d", e->status());
190 SMSMessageRef message = e->message(); 190 SMSMessageRef message = e->message();
191 qDebug("Got message."); 191 qDebug("Got message.");
192 192
193 // qDebug(message->toString().c_str()); 193 // qDebug(message->toString().c_str());
194 if (direction == message->messageType()) { 194 if (direction == message->messageType()) {
195 qDebug("yes\n"); 195 qDebug("yes\n");
196 char buf[3]; 196 char buf[3];
197 snprintf(buf, 3, "%d", e->index()); 197 snprintf(buf, 3, "%d", e->index());
198 new QListViewItem(SMSList, message->address()._number.c_str(), message->serviceCentreTimestamp().toString().c_str(), buf); 198 new QListViewItem(SMSList, message->address()._number.c_str(), message->serviceCentreTimestamp().toString().c_str(), buf);
199 } 199 }
200 } 200 }
201} 201}
202 202
203void GSMTool::doSelectedSMSChanged(QListViewItem *item) 203void GSMTool::doSelectedSMSChanged(QListViewItem *item)
204{ 204{
205 qDebug("message changed\n"); 205 qDebug("message changed\n");
206 206
207 if (!item || sms_store == NULL) { 207 if (!item || sms_store == NULL) {
208 SMSText->setText(""); 208 SMSText->setText("");
209 SMSText->setEnabled(FALSE); 209 SMSText->setEnabled(FALSE);
210 SMSDeleteButton->setEnabled(FALSE); 210 SMSDeleteButton->setEnabled(FALSE);
211 SMSSendButton->setEnabled(FALSE); 211 SMSSendButton->setEnabled(FALSE);
212 return; 212 return;
213 } 213 }
214 /* ARGH. This sucks. Surely there's an app-private pointer in the 214 /* ARGH. This sucks. Surely there's an app-private pointer in the
215 QListViewItem that I've failed to notice? 215 QListViewItem that I've failed to notice?
216 216
217 SMSMessageRef message = *(SMSMessageRef*)item->private; 217 SMSMessageRef message = *(SMSMessageRef*)item->private;
218 */ 218 */
219 qDebug("item %p\n", item); 219 qDebug("item %p\n", item);
220 220
221 qDebug("text(2) is %s\n", item->text(2).ascii()); 221 qDebug("text(2) is %s\n", item->text(2).ascii());
222 int index = atoi(item->text(2).ascii()); 222 int index = atoi(item->text(2).ascii());
223 qDebug("index %d\n", index); 223 qDebug("index %d\n", index);
224 SMSMessageRef message = sms_store->find(index)->message(); 224 SMSMessageRef message = sms_store->find(index)->message();
225 225
226 SMSText->setText(message->userData().c_str()); 226 SMSText->setText(message->userData().c_str());
227 SMSText->setEnabled(TRUE); 227 SMSText->setEnabled(TRUE);
228 SMSDeleteButton->setEnabled(TRUE); 228 SMSDeleteButton->setEnabled(TRUE);
229 SMSSendButton->setEnabled(TRUE); 229 SMSSendButton->setEnabled(TRUE);
230 230
231} 231}
232 232
233void GSMTool::doSMSSendButton() 233void GSMTool::doSMSSendButton()
234{ 234{
235 qDebug("SMSSendButton"); 235 qDebug("SMSSendButton");