-rw-r--r-- | core/obex/obex.cc | 22 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 141 | ||||
-rw-r--r-- | core/obex/obexsend.h | 47 |
3 files changed, 143 insertions, 67 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc index b8ed6e0..595fed9 100644 --- a/core/obex/obex.cc +++ b/core/obex/obex.cc | |||
@@ -3,4 +3,7 @@ | |||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qmessagebox.h> | 4 | #include <qfileinfo.h> |
5 | #include <qtextcodec.h> | ||
6 | |||
5 | #include <qpe/qcopenvelope_qws.h> | 7 | #include <qpe/qcopenvelope_qws.h> |
8 | |||
6 | #include <opie/oprocess.h> | 9 | #include <opie/oprocess.h> |
@@ -108,4 +111,10 @@ void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | |||
108 | if ( proc == m_rec ) { // only receive | 111 | if ( proc == m_rec ) { // only receive |
109 | QString str = QString::fromUtf8( buf, len ); | 112 | for (int i = 0; i < len; i++ ) { |
110 | m_outp.append( str ); | 113 | printf("%c", buf[i] ); |
114 | } | ||
115 | printf("\n"); | ||
116 | QByteArray ar( len ); | ||
117 | memcpy( ar.data(), buf, len ); | ||
118 | qWarning("parsed: %s", ar.data() ); | ||
119 | m_outp.append( ar ); | ||
111 | } | 120 | } |
@@ -118,2 +127,9 @@ void Obex::received() { | |||
118 | qWarning("ACHTUNG %s", filename.latin1() ); | 127 | qWarning("ACHTUNG %s", filename.latin1() ); |
128 | if (filename.contains( 'ö' ) || filename.contains( 'ä' ) || filename.contains('ü' ) ) { | ||
129 | qWarning("renaming!!!!"); | ||
130 | QFileInfo inf( filename ); | ||
131 | QString newName = "/tmp/opie-obex." + inf.extension(); | ||
132 | ::rename( QFile::encodeName( filename ).data(), newName ); | ||
133 | qWarning("name is %s", QFile::encodeName( filename ).data() ); | ||
134 | } | ||
119 | emit receivedFile( filename ); | 135 | emit receivedFile( filename ); |
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 | |||
@@ -5,2 +5,3 @@ | |||
5 | #include <qtimer.h> | 5 | #include <qtimer.h> |
6 | #include <qtl.h> | ||
6 | 7 | ||
@@ -61,4 +62,4 @@ void SendWidget::initUI() { | |||
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 | ||
@@ -88,12 +89,12 @@ void SendWidget::send( const QString& file, const QString& desc ) { | |||
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 | ||
@@ -108,8 +109,8 @@ 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 | ||
@@ -117,14 +118,15 @@ void SendWidget::slotIrDaDevices( const QStringList& list) { | |||
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 | ||
@@ -142,3 +144,3 @@ void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { | |||
142 | } | 144 | } |
143 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | 145 | void SendWidget::dispatchBt( const QCString&, const QByteArray& ) { |
144 | 146 | ||
@@ -151,4 +153,4 @@ void SendWidget::slotIrSent( bool b) { | |||
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(); |
@@ -156,10 +158,10 @@ void SendWidget::slotIrSent( bool b) { | |||
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 ); |
@@ -181,35 +183,66 @@ DeviceBox::~DeviceBox() { | |||
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 | { |
@@ -218,2 +251,6 @@ DeviceItem::DeviceItem( const QString& name, | |||
218 | m_dev = dev; | 251 | m_dev = dev; |
252 | m_id = id; | ||
253 | } | ||
254 | int DeviceItem::id()const { | ||
255 | return m_id; | ||
219 | } | 256 | } |
@@ -252,3 +289,3 @@ void DeviceItem::setStatus(const QString& status ) { | |||
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 | } |
diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h index fd819bc..02100f7 100644 --- a/core/obex/obexsend.h +++ b/core/obex/obexsend.h | |||
@@ -21,2 +21,14 @@ namespace OpieObex { | |||
21 | class Obex; | 21 | class Obex; |
22 | |||
23 | struct Pair { | ||
24 | Pair(const QString& first = QString::null, | ||
25 | const QString& second = QString::null) | ||
26 | : m_first(first), m_second(second ) { | ||
27 | } | ||
28 | QString first()const{ return m_first; } | ||
29 | QString second()const { return m_second; } | ||
30 | private: | ||
31 | QString m_first; | ||
32 | QString m_second; | ||
33 | }; | ||
22 | class SendWidget : public QWidget{ | 34 | class SendWidget : public QWidget{ |
@@ -40,3 +52,3 @@ namespace OpieObex { | |||
40 | void slotBTDevices( const QMap<QString, QString>& ); | 52 | void slotBTDevices( const QMap<QString, QString>& ); |
41 | void slotSelectedDevice( const QString& name, int dev ); | 53 | void slotSelectedDevice( int id, int dev ); |
42 | void dispatchIrda( const QCString& str, const QByteArray& ar ); | 54 | void dispatchIrda( const QCString& str, const QByteArray& ar ); |
@@ -55,6 +67,9 @@ namespace OpieObex { | |||
55 | int m_start; | 67 | int m_start; |
56 | QStringList m_irDa; | 68 | QMap<int, QString> m_irDa; |
57 | QMap<QString, QString> m_bt; | 69 | QMap<int, QString>::Iterator m_irDaIt; |
70 | QMap<int, Pair > m_bt; | ||
58 | QString m_file; | 71 | QString m_file; |
59 | Obex* m_obex; | 72 | Obex* m_obex; |
73 | int m_irDeSearch; // search of irda and bt devices | ||
74 | int m_btDeSearch; | ||
60 | }; | 75 | }; |
@@ -63,3 +78,3 @@ namespace OpieObex { | |||
63 | DeviceItem( const QString& name = QString::null, | 78 | DeviceItem( const QString& name = QString::null, |
64 | const QString& status = QString::null, int dev = 3); | 79 | const QString& status = QString::null, int dev = 3, int id = -1); |
65 | ~DeviceItem(); | 80 | ~DeviceItem(); |
@@ -71,2 +86,3 @@ namespace OpieObex { | |||
71 | int device()const; | 86 | int device()const; |
87 | int id()const; | ||
72 | QString toString()const; | 88 | QString toString()const; |
@@ -76,3 +92,9 @@ namespace OpieObex { | |||
76 | int m_dev; | 92 | int m_dev; |
93 | int m_id; | ||
77 | }; | 94 | }; |
95 | |||
96 | /* | ||
97 | * The text field which contains the information about sending... | ||
98 | * | ||
99 | */ | ||
78 | class DeviceBox : public QTextBrowser { | 100 | class DeviceBox : public QTextBrowser { |
@@ -85,12 +107,13 @@ namespace OpieObex { | |||
85 | void setSource( const QString& str ); | 107 | void setSource( const QString& str ); |
86 | void addDevice( const QString& name, int dev, | 108 | int addDevice( const QString& name, int dev, |
87 | const QString& status = QString::null ); | 109 | const QString& status = QString::null ); |
88 | void removeDevice( const QString& name ); | 110 | void removeDevice( int ); |
89 | void setStatus( const QString& name, const QString& ); | 111 | void setStatus( int, const QString& ); |
90 | signals: | 112 | signals: |
91 | void selectedDevice( const QString& name, int dev ); | 113 | void selectedDevice( int id, int dev ); |
92 | private: | 114 | private: |
93 | QMap<QString, DeviceItem> m_dev; | 115 | /* returns a id for a device from a device range */ |
94 | QStringList m_devices; | 116 | int idFor (int deviceType ); |
95 | 117 | QString allText(); | |
118 | QMap<int, DeviceItem> m_dev; | ||
96 | }; | 119 | }; |