-rw-r--r-- | core/obex/obexsend.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index 9cd9972..dbbb7b3 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -1,48 +1,48 @@ | |||
1 | // 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one | 1 | // 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one |
2 | // generated via QT2 Designer. The new form supports | 2 | // generated via QT2 Designer. The new form supports |
3 | // selection of target devices, as opposed to sending to | 3 | // selection of target devices, as opposed to sending to |
4 | // all. | 4 | // all. |
5 | 5 | ||
6 | #include "obex.h" | 6 | #include "obex.h" |
7 | #include "btobex.h" | 7 | #include "btobex.h" |
8 | #include "obexsend.h" | 8 | #include "obexsend.h" |
9 | using namespace OpieObex; | 9 | using namespace OpieObex; |
10 | 10 | ||
11 | /* OPIE */ | 11 | /* OPIE */ |
12 | #include <opie2/odebug.h> | 12 | #include <opie2/odebug.h> |
13 | #include <qpe/qcopenvelope_qws.h> | 13 | #include <qpe/qcopenvelope_qws.h> |
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | 15 | ||
16 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
17 | 17 | ||
18 | /* QT */ | 18 | /* QT */ |
19 | #include <qlabel.h> | 19 | #include <qlabel.h> |
20 | #include <qpushbutton.h> | 20 | #include <qpushbutton.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qlistview.h> | 22 | #include <qlistview.h> |
23 | #include <qtimer.h> | ||
24 | 23 | ||
24 | #include <unistd.h> | ||
25 | /* TRANSLATOR OpieObex::SendWidget */ | 25 | /* TRANSLATOR OpieObex::SendWidget */ |
26 | 26 | ||
27 | SendWidget::SendWidget( QWidget* parent, const char* name ) | 27 | SendWidget::SendWidget( QWidget* parent, const char* name ) |
28 | : obexSendBase( parent, name ) { | 28 | : obexSendBase( parent, name ) { |
29 | initUI(); | 29 | initUI(); |
30 | } | 30 | } |
31 | SendWidget::~SendWidget() { | 31 | SendWidget::~SendWidget() { |
32 | } | 32 | } |
33 | void SendWidget::initUI() { | 33 | void SendWidget::initUI() { |
34 | m_obex = new Obex(this, "obex"); | 34 | m_obex = new Obex(this, "obex"); |
35 | connect(m_obex, SIGNAL(error(int) ), | 35 | connect(m_obex, SIGNAL(error(int) ), |
36 | this, SLOT(slotIrError(int) ) ); | 36 | this, SLOT(slotIrError(int) ) ); |
37 | connect(m_obex, SIGNAL(sent(bool) ), | 37 | connect(m_obex, SIGNAL(sent(bool) ), |
38 | this, SLOT(slotIrSent(bool) ) ); | 38 | this, SLOT(slotIrSent(bool) ) ); |
39 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), | 39 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), |
40 | this, SLOT(slotIrTry(unsigned int) ) ); | 40 | this, SLOT(slotIrTry(unsigned int) ) ); |
41 | 41 | ||
42 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); | 42 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); |
43 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 43 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
44 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); | 44 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); |
45 | 45 | ||
46 | m_btobex = new BtObex(this, "btobex"); | 46 | m_btobex = new BtObex(this, "btobex"); |
47 | connect(m_btobex, SIGNAL(error(int) ), | 47 | connect(m_btobex, SIGNAL(error(int) ), |
48 | this, SLOT(slotBtError(int) ) ); | 48 | this, SLOT(slotBtError(int) ) ); |
@@ -62,49 +62,49 @@ void SendWidget::initUI() { | |||
62 | * and then wait for a list of devices. | 62 | * and then wait for a list of devices. |
63 | */ | 63 | */ |
64 | void SendWidget::send( const QString& file, const QString& desc ) { | 64 | void SendWidget::send( const QString& file, const QString& desc ) { |
65 | m_file = file; | 65 | m_file = file; |
66 | m_irDa.clear(); | 66 | m_irDa.clear(); |
67 | m_start = 0; | 67 | m_start = 0; |
68 | 68 | ||
69 | fileToSend->setText(desc.isEmpty() ? file : desc ); | 69 | fileToSend->setText(desc.isEmpty() ? file : desc ); |
70 | scan_for_receivers(); | 70 | scan_for_receivers(); |
71 | } | 71 | } |
72 | 72 | ||
73 | int SendWidget::addReceiver(const char *r, const char *icon) | 73 | int SendWidget::addReceiver(const char *r, const char *icon) |
74 | { | 74 | { |
75 | QListViewItem * item = new QListViewItem( receiverList, 0 ); | 75 | QListViewItem * item = new QListViewItem( receiverList, 0 ); |
76 | item->setText( 0, r); | 76 | item->setText( 0, r); |
77 | item->setPixmap( 1, Resource::loadPixmap( icon ) ); | 77 | item->setPixmap( 1, Resource::loadPixmap( icon ) ); |
78 | 78 | ||
79 | int id=receivers.count(); | 79 | int id=receivers.count(); |
80 | receivers[id]=item; | 80 | receivers[id]=item; |
81 | return id; | 81 | return id; |
82 | } | 82 | } |
83 | 83 | ||
84 | bool SendWidget::receiverSelected(int id) | 84 | bool SendWidget::receiverSelected(int id) |
85 | { | 85 | { |
86 | return receivers[id]->pixmap(2); | 86 | return (bool)(receivers[id]->pixmap(2) != NULL); |
87 | } | 87 | } |
88 | 88 | ||
89 | void SendWidget::setReceiverStatus( int id, const QString& status ) { | 89 | void SendWidget::setReceiverStatus( int id, const QString& status ) { |
90 | if ( !receivers.contains(id) ) return; | 90 | if ( !receivers.contains(id) ) return; |
91 | receivers[id]->setText(3, status ); | 91 | receivers[id]->setText(3, status ); |
92 | } | 92 | } |
93 | 93 | ||
94 | void SendWidget::slotIrDaDevices( const QStringList& list) { | 94 | void SendWidget::slotIrDaDevices( const QStringList& list) { |
95 | for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) { | 95 | for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) { |
96 | int id = addReceiver(*it, "obex/irda.png"); | 96 | int id = addReceiver(*it, "obex/irda.png"); |
97 | m_irDa.insert( id, (*it) ); | 97 | m_irDa.insert( id, (*it) ); |
98 | } | 98 | } |
99 | irdaStatus->setText( tr("ready.")); | 99 | irdaStatus->setText( tr("ready.")); |
100 | m_irDaIt = m_irDa.begin(); | 100 | m_irDaIt = m_irDa.begin(); |
101 | 101 | ||
102 | } | 102 | } |
103 | 103 | ||
104 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { | 104 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { |
105 | for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { | 105 | for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { |
106 | int id = addReceiver(it.key(), "obex/bt.png"); | 106 | int id = addReceiver(it.key(), "obex/bt.png"); |
107 | m_bt.insert( id, Pair( it.key(), it.data() ) ); | 107 | m_bt.insert( id, Pair( it.key(), it.data() ) ); |
108 | } | 108 | } |
109 | btStatus->setText(tr("ready.")); | 109 | btStatus->setText(tr("ready.")); |
110 | m_btIt = m_bt.begin(); | 110 | m_btIt = m_bt.begin(); |
@@ -120,120 +120,122 @@ void SendWidget::slotSelectedDevice( int, int ) { | |||
120 | } | 120 | } |
121 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { | 121 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { |
122 | if ( str == "devices(QStringList)" ) { | 122 | if ( str == "devices(QStringList)" ) { |
123 | QDataStream stream( ar, IO_ReadOnly ); | 123 | QDataStream stream( ar, IO_ReadOnly ); |
124 | QStringList list; | 124 | QStringList list; |
125 | stream >> list; | 125 | stream >> list; |
126 | slotIrDaDevices( list ); | 126 | slotIrDaDevices( list ); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | void SendWidget::slotIrError( int ) { | 129 | void SendWidget::slotIrError( int ) { |
130 | irdaStatus->setText(tr("error :(")); | 130 | irdaStatus->setText(tr("error :(")); |
131 | } | 131 | } |
132 | void SendWidget::slotIrSent( bool b) { | 132 | void SendWidget::slotIrSent( bool b) { |
133 | QString text = b ? tr("Sent") : tr("Failure"); | 133 | QString text = b ? tr("Sent") : tr("Failure"); |
134 | setReceiverStatus( m_irDaIt.key(), text ); | 134 | setReceiverStatus( m_irDaIt.key(), text ); |
135 | ++m_irDaIt; | 135 | ++m_irDaIt; |
136 | slotStartIrda(); | 136 | slotStartIrda(); |
137 | } | 137 | } |
138 | void SendWidget::slotIrTry(unsigned int trI) { | 138 | void SendWidget::slotIrTry(unsigned int trI) { |
139 | setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); | 139 | setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); |
140 | } | 140 | } |
141 | void SendWidget::slotStartIrda() { | 141 | void SendWidget::slotStartIrda() { |
142 | if ( !m_irDa.count() ) return; | 142 | if ( !m_irDa.count() ) return; |
143 | if ( m_irDaIt == m_irDa.end() ) { | 143 | if ( m_irDaIt == m_irDa.end() ) { |
144 | irdaStatus->setText(tr("complete.")); | 144 | irdaStatus->setText(tr("complete.")); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); | 147 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); |
148 | m_obex->send( m_file ); | 148 | m_obex->send( m_file ); |
149 | } | 149 | } |
150 | 150 | ||
151 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | 151 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { |
152 | if ( str == "devices(QStringMap)" ) { | 152 | if ( str == "devices(QStringMap)" ) { |
153 | QDataStream stream( ar, IO_ReadOnly ); | 153 | QDataStream stream( ar, IO_ReadOnly ); |
154 | QMap<QString, QString> btmap; | 154 | QMap<QString, QString> btmap; |
155 | stream >> btmap; | 155 | stream >> btmap; |
156 | slotBTDevices( btmap ); | 156 | slotBTDevices( btmap ); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | void SendWidget::slotBtError( int ) { | 159 | void SendWidget::slotBtError( int ) { |
160 | btStatus->setText(tr("error :(")); | 160 | btStatus->setText(tr("error :(")); |
161 | } | 161 | } |
162 | void SendWidget::slotBtSent( bool b) { | 162 | void SendWidget::slotBtSent( bool b) { |
163 | QString text = b ? tr("Sent") : tr("Failure"); | 163 | QString text = b ? tr("Sent") : tr("Failure"); |
164 | setReceiverStatus( m_btIt.key(), text ); | 164 | setReceiverStatus( m_btIt.key(), text ); |
165 | ++m_btIt; | 165 | ++m_btIt; |
166 | slotStartBt(); | 166 | slotStartBt(); |
167 | } | 167 | } |
168 | void SendWidget::slotBtTry(unsigned int trI) { | 168 | void SendWidget::slotBtTry(unsigned int trI) { |
169 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); | 169 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); |
170 | } | 170 | } |
171 | void SendWidget::slotStartBt() { | 171 | void SendWidget::slotStartBt() { |
172 | // skip past unselected receivers | 172 | // skip past unselected receivers |
173 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) | 173 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) |
174 | ++m_btIt; | 174 | ++m_btIt; |
175 | if (m_btIt == m_bt.end() ) { | 175 | if (m_btIt == m_bt.end() ) { |
176 | btStatus->setText(tr("complete.")); | 176 | btStatus->setText(tr("complete.")); |
177 | return; | 177 | return; |
178 | } | 178 | } |
179 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); | 179 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); |
180 | m_btobex->send( m_file, m_btIt.data().second() ); | 180 | m_btobex->send( m_file, m_btIt.data().second() ); |
181 | } | 181 | } |
182 | 182 | ||
183 | void SendWidget::send_to_receivers() { | 183 | void SendWidget::send_to_receivers() { |
184 | slotStartIrda(); | 184 | slotStartIrda(); |
185 | slotStartBt(); | 185 | slotStartBt(); |
186 | } | 186 | } |
187 | 187 | ||
188 | void SendWidget::scan_for_receivers() | 188 | void SendWidget::scan_for_receivers() |
189 | { | 189 | { |
190 | //FIXME: Clean ListBox prior to (re)scan | 190 | receiverList->clear(); |
191 | receivers.clear(); | ||
191 | sendButton->setDisabled( true ); | 192 | sendButton->setDisabled( true ); |
192 | 193 | ||
193 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) | 194 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) |
194 | { | 195 | { |
195 | irdaStatus->setText(tr("not enabled.")); | 196 | irdaStatus->setText(tr("not enabled.")); |
196 | } | 197 | } |
197 | else | 198 | else |
198 | { | 199 | { |
199 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); | 200 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); |
200 | irdaStatus->setText(tr("searching...")); | 201 | irdaStatus->setText(tr("searching...")); |
201 | sendButton->setEnabled( true ); | 202 | sendButton->setEnabled( true ); |
202 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 203 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
203 | } | 204 | } |
204 | 205 | ||
205 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) | 206 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) |
206 | { | 207 | { |
207 | btStatus->setText(tr("not enabled.")); | 208 | btStatus->setText(tr("not enabled.")); |
208 | } | 209 | } |
209 | else | 210 | else |
210 | { | 211 | { |
211 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); | 212 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); |
212 | btStatus->setText(tr("searching...")); | 213 | btStatus->setText(tr("searching...")); |
213 | sendButton->setEnabled( true ); | 214 | sendButton->setEnabled( true ); |
214 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); | 215 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); |
215 | } | 216 | } |
216 | } | 217 | } |
217 | 218 | ||
218 | void SendWidget::toggle_receiver(QListViewItem* item) | 219 | void SendWidget::toggle_receiver(QListViewItem* item) |
219 | { | 220 | { |
220 | // toggle the state of an individual receiver. | 221 | // toggle the state of an individual receiver. |
221 | if(item->pixmap(2)) | 222 | if(item->pixmap(2)) |
222 | item->setPixmap(2,QPixmap()); | 223 | item->setPixmap(2,QPixmap()); |
223 | else | 224 | else |
224 | item->setPixmap(2,Resource::loadPixmap("backup/check.png")); | 225 | item->setPixmap(2,Resource::loadPixmap("backup/check.png")); |
225 | } | 226 | } |
226 | 227 | ||
227 | 228 | ||
228 | void SendWidget::closeEvent( QCloseEvent* e) { | 229 | void SendWidget::closeEvent( QCloseEvent* e) { |
229 | e->accept(); // make sure | 230 | obexSendBase::closeEvent(e); |
230 | QTimer::singleShot(0, this, SLOT(userDone() ) ); | ||
231 | } | ||
232 | void SendWidget::userDone() { | ||
233 | QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); | 231 | QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); |
234 | QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); | 232 | QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); |
235 | emit done(); | ||
236 | } | 233 | } |
234 | |||
235 | void SendWidget::userDone() { | ||
236 | close(); | ||
237 | } | ||
238 | |||
237 | QString SendWidget::file()const { | 239 | QString SendWidget::file()const { |
238 | return m_file; | 240 | return m_file; |
239 | } | 241 | } |