-rw-r--r-- | core/obex/obexsend.cpp | 141 |
1 files changed, 89 insertions, 52 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index d5ebd81..0da57ca 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -1,29 +1,30 @@ | |||
1 | #include <qpushbutton.h> | 1 | #include <qpushbutton.h> |
2 | #include <qlabel.h> | 2 | #include <qlabel.h> |
3 | #include <qhbox.h> | 3 | #include <qhbox.h> |
4 | #include <qlayout.h> | 4 | #include <qlayout.h> |
5 | #include <qtimer.h> | 5 | #include <qtimer.h> |
6 | #include <qtl.h> | ||
6 | 7 | ||
7 | #include <qcopchannel_qws.h> | 8 | #include <qcopchannel_qws.h> |
8 | 9 | ||
9 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
10 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
11 | 12 | ||
12 | #include "obex.h" | 13 | #include "obex.h" |
13 | #include "obexsend.h" | 14 | #include "obexsend.h" |
14 | 15 | ||
15 | using namespace OpieObex; | 16 | using namespace OpieObex; |
16 | 17 | ||
17 | 18 | ||
18 | SendWidget::SendWidget( QWidget* parent, const char* name ) | 19 | SendWidget::SendWidget( QWidget* parent, const char* name ) |
19 | : QWidget( parent, name ) { | 20 | : QWidget( parent, name ) { |
20 | initUI(); | 21 | initUI(); |
21 | } | 22 | } |
22 | SendWidget::~SendWidget() { | 23 | SendWidget::~SendWidget() { |
23 | } | 24 | } |
24 | void SendWidget::initUI() { | 25 | void SendWidget::initUI() { |
25 | m_obex = new Obex(this, "obex"); | 26 | m_obex = new Obex(this, "obex"); |
26 | connect(m_obex, SIGNAL(error(int) ), | 27 | connect(m_obex, SIGNAL(error(int) ), |
27 | this, SLOT(slotIrError(int) ) ); | 28 | this, SLOT(slotIrError(int) ) ); |
28 | connect(m_obex, SIGNAL(sent(bool) ), | 29 | connect(m_obex, SIGNAL(sent(bool) ), |
29 | this, SLOT(slotIrSent(bool) ) ); | 30 | this, SLOT(slotIrSent(bool) ) ); |
@@ -38,217 +39,253 @@ void SendWidget::initUI() { | |||
38 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), | 39 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), |
39 | this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) ); | 40 | this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) ); |
40 | 41 | ||
41 | QVBoxLayout* lay = new QVBoxLayout(this); | 42 | QVBoxLayout* lay = new QVBoxLayout(this); |
42 | 43 | ||
43 | QHBox* nameBox = new QHBox(this); | 44 | QHBox* nameBox = new QHBox(this); |
44 | QLabel* name = new QLabel(nameBox); | 45 | QLabel* name = new QLabel(nameBox); |
45 | name->setText( tr("<qt><h1>Sending:</h1></qt>") ); | 46 | name->setText( tr("<qt><h1>Sending:</h1></qt>") ); |
46 | name->setAlignment( AlignLeft | AlignTop ); | 47 | name->setAlignment( AlignLeft | AlignTop ); |
47 | m_lblFile = new QLabel(nameBox); | 48 | m_lblFile = new QLabel(nameBox); |
48 | lay->addWidget(nameBox, 0); | 49 | lay->addWidget(nameBox, 0); |
49 | 50 | ||
50 | QFrame* frame = new QFrame(this); | 51 | QFrame* frame = new QFrame(this); |
51 | frame->setFrameShape( QFrame::HLine ); | 52 | frame->setFrameShape( QFrame::HLine ); |
52 | frame->setFrameShadow( QFrame::Sunken ); | 53 | frame->setFrameShadow( QFrame::Sunken ); |
53 | lay->addWidget(frame, 10); | 54 | lay->addWidget(frame, 10); |
54 | 55 | ||
55 | QLabel* devices = new QLabel(this); | 56 | QLabel* devices = new QLabel(this); |
56 | devices->setText("<qt><b>Devices:</b></qt>"); | 57 | devices->setText("<qt><b>Devices:</b></qt>"); |
57 | devices->setAlignment( AlignLeft | AlignTop ); | 58 | devices->setAlignment( AlignLeft | AlignTop ); |
58 | lay->addWidget( devices,10 ); | 59 | lay->addWidget( devices,10 ); |
59 | 60 | ||
60 | m_devBox = new DeviceBox(this); | 61 | m_devBox = new DeviceBox(this); |
61 | lay->addWidget( m_devBox, 50 ); | 62 | lay->addWidget( m_devBox, 50 ); |
62 | connect(m_devBox, SIGNAL(selectedDevice(const QString&, int ) ), | 63 | connect(m_devBox, SIGNAL(selectedDevice(int, int ) ), |
63 | this, SLOT(slotSelectedDevice(const QString&, int) ) ); | 64 | this, SLOT(slotSelectedDevice(int, int) ) ); |
64 | 65 | ||
65 | QPushButton *but = new QPushButton(this); | 66 | QPushButton *but = new QPushButton(this); |
66 | but->setText(tr("Done") ); | 67 | but->setText(tr("Done") ); |
67 | connect(but, SIGNAL(clicked() ), | 68 | connect(but, SIGNAL(clicked() ), |
68 | this, SLOT(slotDone() ) ); | 69 | this, SLOT(slotDone() ) ); |
69 | 70 | ||
70 | lay->addWidget( but ); | 71 | lay->addWidget( but ); |
71 | m_lay = lay; | 72 | m_lay = lay; |
72 | 73 | ||
73 | // QT does not like if you add items to an layout which already exits.... | 74 | // QT does not like if you add items to an layout which already exits.... |
74 | // and was layouted invalidate() does not help too | 75 | // and was layouted invalidate() does not help too |
75 | // so we use RichText.... | 76 | // so we use RichText.... |
76 | } | 77 | } |
77 | 78 | ||
78 | /* | 79 | /* |
79 | * in send we'll first set everything up | 80 | * in send we'll first set everything up |
80 | * and then wait for a list of devices. | 81 | * and then wait for a list of devices. |
81 | */ | 82 | */ |
82 | void SendWidget::send( const QString& file, const QString& desc ) { | 83 | void SendWidget::send( const QString& file, const QString& desc ) { |
83 | m_file = file; | 84 | m_file = file; |
84 | m_irDa.clear(); | 85 | m_irDa.clear(); |
85 | m_start = 0; | 86 | m_start = 0; |
86 | m_lblFile->setText(desc.isEmpty() ? file : desc ); | 87 | m_lblFile->setText(desc.isEmpty() ? file : desc ); |
87 | 88 | ||
88 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) { | 89 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) { |
89 | m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error ); | 90 | m_irDeSearch = m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error ); |
90 | m_start++; | 91 | m_start++; |
91 | }else | 92 | }else |
92 | m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search ); | 93 | m_irDeSearch = m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search ); |
93 | 94 | ||
94 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) { | 95 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) { |
95 | m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error ); | 96 | m_btDeSearch = m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error ); |
96 | m_start++; | 97 | m_start++; |
97 | }else | 98 | }else |
98 | m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search ); | 99 | m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search ); |
99 | 100 | ||
100 | if (m_start != 2 ) { | 101 | if (m_start != 2 ) { |
101 | QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()"); | 102 | QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()"); |
102 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); | 103 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); |
103 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 104 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
104 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); | 105 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); |
105 | } | 106 | } |
106 | } | 107 | } |
107 | void SendWidget::slotIrDaDevices( const QStringList& list) { | 108 | void SendWidget::slotIrDaDevices( const QStringList& list) { |
108 | qWarning("slot it irda devices "); | 109 | qWarning("slot it irda devices "); |
109 | m_irDa = list; | 110 | for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) { |
110 | m_start = 0; | 111 | int id = m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") ); |
111 | for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) | 112 | m_irDa.insert( id, (*it) ); |
112 | m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") ); | 113 | } |
113 | 114 | m_devBox->removeDevice( m_irDeSearch ); | |
114 | m_devBox->removeDevice( tr("Searching for IrDa Devices.") ); | 115 | m_irDaIt = m_irDa.begin(); |
115 | 116 | ||
116 | slotStartIrda(); | 117 | slotStartIrda(); |
117 | } | 118 | } |
119 | |||
118 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { | 120 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { |
119 | m_bt = str; | ||
120 | for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { | 121 | for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { |
121 | m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") ); | 122 | int id = m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") ); |
123 | m_bt.insert( id, Pair( it.key(), it.data() ) ); | ||
122 | } | 124 | } |
123 | m_devBox->removeDevice( tr("Searching for bluetooth Devices.") ); | 125 | m_devBox->removeDevice( m_btDeSearch ); |
124 | } | 126 | } |
125 | void SendWidget::slotSelectedDevice( const QString& name, int dev ) { | 127 | void SendWidget::slotSelectedDevice( int name, int dev ) { |
126 | qWarning("Start beam? %s %d", name.latin1(), dev ); | 128 | qWarning("Start beam? %d %d", name, dev ); |
127 | if ( name == tr("Search again for IrDa.") ) { | 129 | if ( name == m_irDeSearch ) { |
128 | for (QStringList::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) | 130 | for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) |
129 | m_devBox->removeDevice( (*it) ); | 131 | m_devBox->removeDevice( it.key() ); |
130 | 132 | ||
131 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 133 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
132 | } | 134 | } |
133 | } | 135 | } |
134 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { | 136 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { |
135 | qWarning("dispatch irda %s", str.data() ); | 137 | qWarning("dispatch irda %s", str.data() ); |
136 | if ( str == "devices(QStringList)" ) { | 138 | if ( str == "devices(QStringList)" ) { |
137 | QDataStream stream( ar, IO_ReadOnly ); | 139 | QDataStream stream( ar, IO_ReadOnly ); |
138 | QStringList list; | 140 | QStringList list; |
139 | stream >> list; | 141 | stream >> list; |
140 | slotIrDaDevices( list ); | 142 | slotIrDaDevices( list ); |
141 | } | 143 | } |
142 | } | 144 | } |
143 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | 145 | void SendWidget::dispatchBt( const QCString&, const QByteArray& ) { |
144 | 146 | ||
145 | } | 147 | } |
146 | void SendWidget::slotIrError( int ) { | 148 | void SendWidget::slotIrError( int ) { |
147 | 149 | ||
148 | } | 150 | } |
149 | void SendWidget::slotIrSent( bool b) { | 151 | void SendWidget::slotIrSent( bool b) { |
150 | qWarning("irda sent!!"); | 152 | qWarning("irda sent!!"); |
151 | QString text = b ? tr("Sent") : tr("Failure"); | 153 | QString text = b ? tr("Sent") : tr("Failure"); |
152 | // m_devBox->setStatus( m_irDa[m_start], text ); | 154 | m_devBox->setStatus( m_irDaIt.key(), text ); |
153 | m_start++; | 155 | ++m_irDaIt; |
154 | slotStartIrda(); | 156 | slotStartIrda(); |
155 | } | 157 | } |
156 | void SendWidget::slotIrTry(unsigned int trI) { | 158 | void SendWidget::slotIrTry(unsigned int trI) { |
157 | // m_devBox->setStatus( m_irDa[m_start], tr("Try %1").arg( QString::number( trI ) ) ); | 159 | m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); |
158 | } | 160 | } |
159 | void SendWidget::slotStartIrda() { | 161 | void SendWidget::slotStartIrda() { |
160 | if (m_start >= m_irDa.count() ) { | 162 | if (m_irDaIt == m_irDa.end() ) { |
161 | m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search ); | 163 | m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search ); |
162 | return; | 164 | return; |
163 | } | 165 | } |
164 | // m_devBox->setStatus( m_irDa[m_start], tr("Start sending") ); | 166 | m_devBox->setStatus( m_irDaIt.key(), tr("Start sending") ); |
165 | m_obex->send( m_file ); | 167 | m_obex->send( m_file ); |
166 | } | 168 | } |
167 | void SendWidget::slotDone() { | 169 | void SendWidget::slotDone() { |
168 | QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); | 170 | QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); |
169 | QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); | 171 | QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); |
170 | emit done(); | 172 | emit done(); |
171 | } | 173 | } |
172 | QString SendWidget::file()const { | 174 | QString SendWidget::file()const { |
173 | return m_file; | 175 | return m_file; |
174 | } | 176 | } |
175 | DeviceBox::DeviceBox( QWidget* parent ) | 177 | DeviceBox::DeviceBox( QWidget* parent ) |
176 | : QTextBrowser( parent ) { | 178 | : QTextBrowser( parent ) { |
177 | 179 | ||
178 | } | 180 | } |
179 | DeviceBox::~DeviceBox() { | 181 | DeviceBox::~DeviceBox() { |
180 | 182 | ||
181 | } | 183 | } |
182 | void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { | 184 | int DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { |
183 | QString tex; | 185 | /* return a id for a range of devices */ |
184 | DeviceItem item( name, status, dev ); | 186 | int id = idFor ( dev ); |
185 | m_dev.insert( name, item ); | 187 | DeviceItem item( name, status, dev,id ); |
186 | tex = item.toString(); | 188 | m_dev.insert( id, item ); |
187 | m_devices.prepend(tex); | 189 | setText( allText() ); |
188 | setText( text()+ "<br>"+tex ); | ||
189 | } | ||
190 | void DeviceBox::removeDevice( const QString& name ) { | ||
191 | if (!m_dev.contains(name) ) return; | ||
192 | m_devices.remove( m_dev[name].toString() ); | ||
193 | 190 | ||
194 | m_dev.remove(name); | 191 | return id; |
195 | setText( m_devices.join("<br>") ); | 192 | } |
193 | void DeviceBox::removeDevice( int id ) { | ||
194 | if (!m_dev.contains(id) ) return; | ||
196 | 195 | ||
196 | m_dev.remove( id ); | ||
197 | setText( allText() ); | ||
197 | } | 198 | } |
198 | void DeviceBox::setStatus( const QString& name, const QString& status ) { | 199 | void DeviceBox::setStatus( int id, const QString& status ) { |
199 | if ( !m_dev.contains(name) ) return; | 200 | if ( !m_dev.contains(id) ) return; |
200 | DeviceItem dev = m_dev[name]; | 201 | m_dev[id].setStatus(status ); |
201 | QString ole = dev.toString(); | 202 | setText( allText() ); |
202 | dev.setStatus( status ); | ||
203 | int index = m_devices.findIndex( ole ); | ||
204 | m_devices[index] = dev.toString(); | ||
205 | setText( m_devices.join("<br>") ); | ||
206 | } | 203 | } |
207 | void DeviceBox::setSource( const QString& str ) { | 204 | void DeviceBox::setSource( const QString& str ) { |
208 | qWarning("SetSource:%s", str.latin1() ); | 205 | qWarning("SetSource:%d", str.toInt() ); |
209 | emit selectedDevice( str, m_dev[str].device() ); | 206 | int id = str.toInt(); |
207 | emit selectedDevice( id, m_dev[id].device() ); | ||
208 | } | ||
209 | int DeviceBox::idFor ( int id ) { | ||
210 | static int irId = 1501; | ||
211 | static int irBT = 1001; | ||
212 | static int irSr = 501; | ||
213 | static int irEr = 0; | ||
214 | |||
215 | int ret = -1; | ||
216 | switch(id ) { | ||
217 | case IrDa: | ||
218 | ret = irId; | ||
219 | irId++; | ||
220 | break; | ||
221 | case BT: | ||
222 | ret = irBT; | ||
223 | irBT++; | ||
224 | break; | ||
225 | case Search: | ||
226 | ret = irSr; | ||
227 | irSr++; | ||
228 | break; | ||
229 | case Error: | ||
230 | ret = irEr; | ||
231 | irEr++; | ||
232 | break; | ||
233 | } | ||
234 | return ret; | ||
210 | } | 235 | } |
236 | QString DeviceBox::allText() { | ||
237 | QString str; | ||
238 | typedef QMap<int, DeviceItem> DeviceMap; | ||
211 | 239 | ||
240 | for (QMap<int, DeviceItem>::Iterator it = m_dev.begin(); it != m_dev.end(); ++it ) { | ||
241 | str += it.data().toString() + "<br>"; | ||
242 | } | ||
243 | return str; | ||
244 | } | ||
212 | 245 | ||
213 | DeviceItem::DeviceItem( const QString& name, | 246 | DeviceItem::DeviceItem( const QString& name, |
214 | const QString& status, int dev) | 247 | const QString& status, int dev, int id) |
215 | { | 248 | { |
216 | m_name = name; | 249 | m_name = name; |
217 | m_status = status; | 250 | m_status = status; |
218 | m_dev = dev; | 251 | m_dev = dev; |
252 | m_id = id; | ||
253 | } | ||
254 | int DeviceItem::id()const { | ||
255 | return m_id; | ||
219 | } | 256 | } |
220 | QString DeviceItem::name()const { | 257 | QString DeviceItem::name()const { |
221 | return m_name; | 258 | return m_name; |
222 | } | 259 | } |
223 | QString DeviceItem::status()const { | 260 | QString DeviceItem::status()const { |
224 | return m_status; | 261 | return m_status; |
225 | } | 262 | } |
226 | int DeviceItem::device()const { | 263 | int DeviceItem::device()const { |
227 | return m_dev; | 264 | return m_dev; |
228 | } | 265 | } |
229 | QString DeviceItem::pixmap()const{ | 266 | QString DeviceItem::pixmap()const{ |
230 | QString str; | 267 | QString str; |
231 | switch(m_dev) { | 268 | switch(m_dev) { |
232 | case DeviceBox::IrDa: | 269 | case DeviceBox::IrDa: |
233 | str ="obex/irda"; | 270 | str ="obex/irda"; |
234 | break; | 271 | break; |
235 | case DeviceBox::BT: | 272 | case DeviceBox::BT: |
236 | str ="obex/bt"; | 273 | str ="obex/bt"; |
237 | break; | 274 | break; |
238 | case DeviceBox::Search: | 275 | case DeviceBox::Search: |
239 | str = "obex/search"; | 276 | str = "obex/search"; |
240 | break; | 277 | break; |
241 | case DeviceBox::Error: | 278 | case DeviceBox::Error: |
242 | str = "editdelete"; | 279 | str = "editdelete"; |
243 | break; | 280 | break; |
244 | }; | 281 | }; |
245 | return str; | 282 | return str; |
246 | } | 283 | } |
247 | DeviceItem::~DeviceItem() { | 284 | DeviceItem::~DeviceItem() { |
248 | } | 285 | } |
249 | void DeviceItem::setStatus(const QString& status ) { | 286 | void DeviceItem::setStatus(const QString& status ) { |
250 | m_status = status; | 287 | m_status = status; |
251 | } | 288 | } |
252 | QString DeviceItem::toString()const { | 289 | QString DeviceItem::toString()const { |
253 | return "<p><a href=\""+m_name +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ; | 290 | return "<p><a href=\""+QString::number(m_id) +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ; |
254 | } | 291 | } |