author | korovkin <korovkin> | 2006-11-10 20:49:54 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-11-10 20:49:54 (UTC) |
commit | 961e5561b24452d9cfc2bf7400f6f5952b31431c (patch) (unidiff) | |
tree | 44439765333edad675966ce33f88427240cdbb0e | |
parent | b742daec72bbef07039b785dcadca9dca9a0dc1c (diff) | |
download | opie-961e5561b24452d9cfc2bf7400f6f5952b31431c.zip opie-961e5561b24452d9cfc2bf7400f6f5952b31431c.tar.gz opie-961e5561b24452d9cfc2bf7400f6f5952b31431c.tar.bz2 |
Made list of receivers loaded form files saved by bt-manager.
-rw-r--r-- | core/obex/obexsend.cpp | 53 | ||||
-rw-r--r-- | core/obex/obexsend.h | 3 |
2 files changed, 52 insertions, 4 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index 5c177e3..bca6784 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -1,114 +1,117 @@ | |||
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 | using namespace OpieTooth; | ||
10 | 11 | ||
11 | /* OPIE */ | 12 | /* OPIE */ |
12 | #include <opie2/odebug.h> | 13 | #include <opie2/odebug.h> |
13 | #include <qpe/qcopenvelope_qws.h> | 14 | #include <qpe/qcopenvelope_qws.h> |
14 | #include <opie2/oresource.h> | 15 | #include <opie2/oresource.h> |
15 | #include <qpe/version.h> | 16 | #include <qpe/version.h> |
17 | #include <devicehandler.h> | ||
18 | #include "remotedevice.h" | ||
16 | 19 | ||
17 | using namespace Opie::Core; | 20 | using namespace Opie::Core; |
18 | 21 | ||
19 | /* QT */ | 22 | /* QT */ |
20 | #include <qlabel.h> | 23 | #include <qlabel.h> |
21 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
22 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
23 | #include <qlistview.h> | 26 | #include <qlistview.h> |
24 | 27 | ||
25 | #include <unistd.h> | 28 | #include <unistd.h> |
26 | /* TRANSLATOR OpieObex::SendWidget */ | 29 | /* TRANSLATOR OpieObex::SendWidget */ |
27 | 30 | ||
28 | /* Just for backward compatibility */ | 31 | /* Just for backward compatibility */ |
29 | #if OPIE_VERSION < 102010 | 32 | #if OPIE_VERSION < 102010 |
30 | #define OResource Resource | 33 | #define OResource Resource |
31 | #endif | 34 | #endif |
32 | 35 | ||
33 | SendWidget::SendWidget( QWidget* parent, const char* name ) | 36 | SendWidget::SendWidget( QWidget* parent, const char* name ) |
34 | : obexSendBase( parent, name ) { | 37 | : obexSendBase( parent, name ) { |
35 | initUI(); | 38 | initUI(); |
36 | } | 39 | } |
37 | SendWidget::~SendWidget() { | 40 | SendWidget::~SendWidget() { |
38 | } | 41 | } |
39 | void SendWidget::initUI() { | 42 | void SendWidget::initUI() { |
40 | m_obex = new Obex(this, "obex"); | 43 | m_obex = new Obex(this, "obex"); |
41 | connect(m_obex, SIGNAL(error(int) ), | 44 | connect(m_obex, SIGNAL(error(int) ), |
42 | this, SLOT(slotIrError(int) ) ); | 45 | this, SLOT(slotIrError(int) ) ); |
43 | connect(m_obex, SIGNAL(sent(bool) ), | 46 | connect(m_obex, SIGNAL(sent(bool) ), |
44 | this, SLOT(slotIrSent(bool) ) ); | 47 | this, SLOT(slotIrSent(bool) ) ); |
45 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), | 48 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), |
46 | this, SLOT(slotIrTry(unsigned int) ) ); | 49 | this, SLOT(slotIrTry(unsigned int) ) ); |
47 | 50 | ||
48 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); | 51 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); |
49 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 52 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
50 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); | 53 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); |
51 | 54 | ||
52 | m_btobex = new BtObex(this, "btobex"); | 55 | m_btobex = new BtObex(this, "btobex"); |
53 | connect(m_btobex, SIGNAL(error(int) ), | 56 | connect(m_btobex, SIGNAL(error(int) ), |
54 | this, SLOT(slotBtError(int) ) ); | 57 | this, SLOT(slotBtError(int) ) ); |
55 | connect(m_btobex, SIGNAL(sent(bool) ), | 58 | connect(m_btobex, SIGNAL(sent(bool) ), |
56 | this, SLOT(slotBtSent(bool) ) ); | 59 | this, SLOT(slotBtSent(bool) ) ); |
57 | connect(m_btobex, SIGNAL(currentTry(unsigned int) ), | 60 | connect(m_btobex, SIGNAL(currentTry(unsigned int) ), |
58 | this, SLOT(slotBtTry(unsigned int) ) ); | 61 | this, SLOT(slotBtTry(unsigned int) ) ); |
59 | 62 | ||
60 | chan = new QCopChannel("QPE/BluetoothBack", this ); | 63 | chan = new QCopChannel("QPE/BluetoothBack", this ); |
61 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 64 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
62 | this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); | 65 | this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); |
63 | 66 | ||
64 | } | 67 | } |
65 | 68 | ||
66 | /* | 69 | /* |
67 | * in send we'll first set everything up | 70 | * in send we'll first set everything up |
68 | * and then wait for a list of devices. | 71 | * and then wait for a list of devices. |
69 | */ | 72 | */ |
70 | void SendWidget::send( const QString& file, const QString& desc ) { | 73 | void SendWidget::send( const QString& file, const QString& desc ) { |
71 | m_file = file; | 74 | m_file = file; |
72 | m_irDa.clear(); | 75 | m_irDa.clear(); |
73 | m_start = 0; | 76 | m_start = 0; |
74 | 77 | ||
75 | fileToSend->setText(desc.isEmpty() ? file : desc ); | 78 | fileToSend->setText(desc.isEmpty() ? file : desc ); |
76 | scan_for_receivers(); | 79 | read_receivers(); |
77 | } | 80 | } |
78 | 81 | ||
79 | int SendWidget::addReceiver(const char *r, const char *icon) | 82 | int SendWidget::addReceiver(const QString& str, const char *icon) |
80 | { | 83 | { |
81 | QListViewItem * item = new QListViewItem( receiverList, 0 ); | 84 | QListViewItem * item = new QListViewItem( receiverList, 0 ); |
82 | item->setText( 0, r); | 85 | item->setText( 0, str ); |
83 | item->setPixmap( 1, OResource::loadPixmap( icon ) ); | 86 | item->setPixmap( 1, OResource::loadPixmap( icon ) ); |
84 | 87 | ||
85 | int id=receivers.count(); | 88 | int id=receivers.count(); |
86 | receivers[id]=item; | 89 | receivers[id]=item; |
87 | return id; | 90 | return id; |
88 | } | 91 | } |
89 | 92 | ||
90 | bool SendWidget::receiverSelected(int id) | 93 | bool SendWidget::receiverSelected(int id) |
91 | { | 94 | { |
92 | return (bool)(receivers[id]->pixmap(2) != NULL); | 95 | return (bool)(receivers[id]->pixmap(2) != NULL); |
93 | } | 96 | } |
94 | 97 | ||
95 | void SendWidget::setReceiverStatus( int id, const QString& status ) { | 98 | void SendWidget::setReceiverStatus( int id, const QString& status ) { |
96 | if ( !receivers.contains(id) ) return; | 99 | if ( !receivers.contains(id) ) return; |
97 | receivers[id]->setText(3, status ); | 100 | receivers[id]->setText(3, status ); |
98 | } | 101 | } |
99 | 102 | ||
100 | void SendWidget::slotIrDaDevices( const QStringList& list) { | 103 | void SendWidget::slotIrDaDevices( const QStringList& list) { |
101 | for (QStringList::ConstIterator it = list.begin(); | 104 | for (QStringList::ConstIterator it = list.begin(); |
102 | it != list.end(); ++it ) { | 105 | it != list.end(); ++it ) { |
103 | int id = addReceiver(*it, "obex/irda.png"); | 106 | int id = addReceiver(*it, "obex/irda.png"); |
104 | m_irDa.insert( id, (*it) ); | 107 | m_irDa.insert( id, (*it) ); |
105 | } | 108 | } |
106 | irdaStatus->setText( tr("ready.")); | 109 | irdaStatus->setText( tr("ready.")); |
107 | m_irDaIt = m_irDa.begin(); | 110 | m_irDaIt = m_irDa.begin(); |
108 | 111 | ||
109 | } | 112 | } |
110 | 113 | ||
111 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { | 114 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { |
112 | for(QMap<QString, QString>::ConstIterator it = str.begin(); | 115 | for(QMap<QString, QString>::ConstIterator it = str.begin(); |
113 | it != str.end(); ++it ) { | 116 | it != str.end(); ++it ) { |
114 | int id = addReceiver(it.key(), "obex/bt.png"); | 117 | int id = addReceiver(it.key(), "obex/bt.png"); |
@@ -165,64 +168,108 @@ void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | |||
165 | slotBTDevices( btmap ); | 168 | slotBTDevices( btmap ); |
166 | } | 169 | } |
167 | } | 170 | } |
168 | void SendWidget::slotBtError( int ) { | 171 | void SendWidget::slotBtError( int ) { |
169 | btStatus->setText(tr("error :(")); | 172 | btStatus->setText(tr("error :(")); |
170 | } | 173 | } |
171 | void SendWidget::slotBtSent( bool b) { | 174 | void SendWidget::slotBtSent( bool b) { |
172 | QString text = b ? tr("Sent") : tr("Failure"); | 175 | QString text = b ? tr("Sent") : tr("Failure"); |
173 | setReceiverStatus( m_btIt.key(), text ); | 176 | setReceiverStatus( m_btIt.key(), text ); |
174 | ++m_btIt; | 177 | ++m_btIt; |
175 | slotStartBt(); | 178 | slotStartBt(); |
176 | } | 179 | } |
177 | void SendWidget::slotBtTry(unsigned int trI) { | 180 | void SendWidget::slotBtTry(unsigned int trI) { |
178 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); | 181 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); |
179 | } | 182 | } |
180 | void SendWidget::slotStartBt() { | 183 | void SendWidget::slotStartBt() { |
181 | // skip past unselected receivers | 184 | // skip past unselected receivers |
182 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) | 185 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) |
183 | ++m_btIt; | 186 | ++m_btIt; |
184 | if (m_btIt == m_bt.end() ) { | 187 | if (m_btIt == m_bt.end() ) { |
185 | btStatus->setText(tr("complete.")); | 188 | btStatus->setText(tr("complete.")); |
186 | return; | 189 | return; |
187 | } | 190 | } |
188 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); | 191 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); |
189 | m_btobex->send( m_file, m_btIt.data().second() ); | 192 | m_btobex->send( m_file, m_btIt.data().second() ); |
190 | } | 193 | } |
191 | 194 | ||
192 | void SendWidget::send_to_receivers() { | 195 | void SendWidget::send_to_receivers() { |
193 | slotStartIrda(); | 196 | slotStartIrda(); |
194 | slotStartBt(); | 197 | slotStartBt(); |
195 | } | 198 | } |
196 | 199 | ||
200 | /** | ||
201 | * Read receivers saved by bluetooth manager | ||
202 | */ | ||
203 | void SendWidget::read_receivers() | ||
204 | { | ||
205 | QValueList<RemoteDevice> devices; | ||
206 | DeviceHandler handler; | ||
207 | QValueList<RemoteDevice>::ConstIterator it; | ||
208 | |||
209 | receiverList->clear(); | ||
210 | receivers.clear(); | ||
211 | sendButton->setDisabled( true ); | ||
212 | |||
213 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) | ||
214 | { | ||
215 | irdaStatus->setText(tr("not enabled.")); | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); | ||
220 | irdaStatus->setText(tr("ready")); | ||
221 | sendButton->setEnabled( true ); | ||
222 | } | ||
223 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) | ||
224 | { | ||
225 | btStatus->setText(tr("not enabled.")); | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); | ||
230 | |||
231 | devices = handler.load(); | ||
232 | for( it = devices.begin(); it != devices.end() ; ++it ) | ||
233 | { | ||
234 | int id = addReceiver((*it).name(), "obex/bt.png"); | ||
235 | m_bt.insert(id, Pair((*it).name(), (*it).mac())); | ||
236 | } | ||
237 | btStatus->setText(tr("ready.")); | ||
238 | m_btIt = m_bt.begin(); | ||
239 | sendButton->setEnabled( true ); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | |||
197 | void SendWidget::scan_for_receivers() | 244 | void SendWidget::scan_for_receivers() |
198 | { | 245 | { |
199 | receiverList->clear(); | 246 | receiverList->clear(); |
200 | receivers.clear(); | 247 | receivers.clear(); |
201 | sendButton->setDisabled( true ); | 248 | sendButton->setDisabled( true ); |
202 | 249 | ||
203 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) | 250 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) |
204 | { | 251 | { |
205 | irdaStatus->setText(tr("not enabled.")); | 252 | irdaStatus->setText(tr("not enabled.")); |
206 | } | 253 | } |
207 | else | 254 | else |
208 | { | 255 | { |
209 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); | 256 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); |
210 | irdaStatus->setText(tr("searching...")); | 257 | irdaStatus->setText(tr("searching...")); |
211 | sendButton->setEnabled( true ); | 258 | sendButton->setEnabled( true ); |
212 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 259 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
213 | } | 260 | } |
214 | 261 | ||
215 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) | 262 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) |
216 | { | 263 | { |
217 | btStatus->setText(tr("not enabled.")); | 264 | btStatus->setText(tr("not enabled.")); |
218 | } | 265 | } |
219 | else | 266 | else |
220 | { | 267 | { |
221 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); | 268 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); |
222 | btStatus->setText(tr("searching...")); | 269 | btStatus->setText(tr("searching...")); |
223 | sendButton->setEnabled( true ); | 270 | sendButton->setEnabled( true ); |
224 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); | 271 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); |
225 | } | 272 | } |
226 | } | 273 | } |
227 | 274 | ||
228 | void SendWidget::toggle_receiver(QListViewItem* item) | 275 | void SendWidget::toggle_receiver(QListViewItem* item) |
diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h index 030e180..f9ba340 100644 --- a/core/obex/obexsend.h +++ b/core/obex/obexsend.h | |||
@@ -15,84 +15,85 @@ class QLabel; | |||
15 | class QVBoxLayout; | 15 | class QVBoxLayout; |
16 | /** | 16 | /** |
17 | * This is the new sending widget for Obex | 17 | * This is the new sending widget for Obex |
18 | * It will attemp to smart and be able to send | 18 | * It will attemp to smart and be able to send |
19 | * it to multiple (selected) devices. | 19 | * it to multiple (selected) devices. |
20 | * It'll support BT + IrDa | 20 | * It'll support BT + IrDa |
21 | */ | 21 | */ |
22 | namespace OpieObex { | 22 | namespace OpieObex { |
23 | class Obex; | 23 | class Obex; |
24 | class BtObex; | 24 | class BtObex; |
25 | 25 | ||
26 | struct Pair { | 26 | struct Pair { |
27 | Pair(const QString& first = QString::null, | 27 | Pair(const QString& first = QString::null, |
28 | const QString& second = QString::null) | 28 | const QString& second = QString::null) |
29 | : m_first(first), m_second(second ) { | 29 | : m_first(first), m_second(second ) { |
30 | } | 30 | } |
31 | QString first()const{ return m_first; } | 31 | QString first()const{ return m_first; } |
32 | QString second()const { return m_second; } | 32 | QString second()const { return m_second; } |
33 | private: | 33 | private: |
34 | QString m_first; | 34 | QString m_first; |
35 | QString m_second; | 35 | QString m_second; |
36 | }; | 36 | }; |
37 | class SendWidget : public obexSendBase { | 37 | class SendWidget : public obexSendBase { |
38 | Q_OBJECT | 38 | Q_OBJECT |
39 | public: | 39 | public: |
40 | SendWidget( QWidget* parent = 0, const char* name = 0); | 40 | SendWidget( QWidget* parent = 0, const char* name = 0); |
41 | ~SendWidget(); | 41 | ~SendWidget(); |
42 | 42 | ||
43 | QString file()const; | 43 | QString file()const; |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | void closeEvent( QCloseEvent* ); | 46 | void closeEvent( QCloseEvent* ); |
47 | void read_receivers(); | ||
47 | 48 | ||
48 | public slots: | 49 | public slots: |
49 | void send( const QString& file, const QString& desc ); | 50 | void send( const QString& file, const QString& desc ); |
50 | 51 | ||
51 | signals: | 52 | signals: |
52 | void done(); | 53 | void done(); |
53 | 54 | ||
54 | protected slots: | 55 | protected slots: |
55 | virtual void userDone(); | 56 | virtual void userDone(); |
56 | virtual void send_to_receivers(); | 57 | virtual void send_to_receivers(); |
57 | virtual void scan_for_receivers(); | 58 | virtual void scan_for_receivers(); |
58 | virtual void toggle_receiver(QListViewItem* item); | 59 | virtual void toggle_receiver(QListViewItem* item); |
59 | 60 | ||
60 | private slots: // QCOP slots | 61 | private slots: // QCOP slots |
61 | /* IrDa Names*/ | 62 | /* IrDa Names*/ |
62 | void slotIrDaDevices( const QStringList& ); | 63 | void slotIrDaDevices( const QStringList& ); |
63 | /* Bt Names + BD-Addr */ | 64 | /* Bt Names + BD-Addr */ |
64 | void slotBTDevices( const QMap<QString, QString>& ); | 65 | void slotBTDevices( const QMap<QString, QString>& ); |
65 | void slotSelectedDevice( int id, int dev ); | 66 | void slotSelectedDevice( int id, int dev ); |
66 | 67 | ||
67 | void dispatchIrda( const QCString& str, const QByteArray& ar ); | 68 | void dispatchIrda( const QCString& str, const QByteArray& ar ); |
68 | 69 | ||
69 | void slotIrError( int ); | 70 | void slotIrError( int ); |
70 | void slotIrSent(bool); | 71 | void slotIrSent(bool); |
71 | void slotIrTry(unsigned int ); | 72 | void slotIrTry(unsigned int ); |
72 | void slotStartIrda(); | 73 | void slotStartIrda(); |
73 | 74 | ||
74 | void dispatchBt( const QCString& str, const QByteArray& ar ); | 75 | void dispatchBt( const QCString& str, const QByteArray& ar ); |
75 | void slotBtError( int ); | 76 | void slotBtError( int ); |
76 | void slotBtSent(bool); | 77 | void slotBtSent(bool); |
77 | void slotBtTry(unsigned int ); | 78 | void slotBtTry(unsigned int ); |
78 | void slotStartBt(); | 79 | void slotStartBt(); |
79 | 80 | ||
80 | private: | 81 | private: |
81 | void initUI(); | 82 | void initUI(); |
82 | int addReceiver(const char *r, const char *icon); | 83 | int addReceiver(const QString& str, const char *icon); |
83 | void setReceiverStatus( int id, const QString& status ); | 84 | void setReceiverStatus( int id, const QString& status ); |
84 | bool receiverSelected(int id); | 85 | bool receiverSelected(int id); |
85 | 86 | ||
86 | int m_start; | 87 | int m_start; |
87 | QMap<int, QString> m_irDa; | 88 | QMap<int, QString> m_irDa; |
88 | QMap<int, QString>::Iterator m_irDaIt; | 89 | QMap<int, QString>::Iterator m_irDaIt; |
89 | QMap<int, Pair > m_bt; | 90 | QMap<int, Pair > m_bt; |
90 | QMap<int, Pair>::Iterator m_btIt; | 91 | QMap<int, Pair>::Iterator m_btIt; |
91 | QMap<int, QListViewItem *> receivers; | 92 | QMap<int, QListViewItem *> receivers; |
92 | QString m_file; | 93 | QString m_file; |
93 | Obex* m_obex; | 94 | Obex* m_obex; |
94 | BtObex* m_btobex; | 95 | BtObex* m_btobex; |
95 | }; | 96 | }; |
96 | } | 97 | } |
97 | 98 | ||
98 | #endif | 99 | #endif |