author | zecke <zecke> | 2003-02-18 20:42:05 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-18 20:42:05 (UTC) |
commit | d3f15e100af8a91504ac9e5fb95dce0cadfe4837 (patch) (unidiff) | |
tree | 04ddeda0f690aa1d51ba486b114251250eef2ef9 | |
parent | 9f5098a6da637e81f6525482456394a68524dc61 (diff) | |
download | opie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.zip opie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.tar.gz opie-d3f15e100af8a91504ac9e5fb95dce0cadfe4837.tar.bz2 |
Convert the way of storing the devices in the QTextBrowser
we assign ids by now
it looks soo nice... but it counts up tries and then say there was a failure
but it is working though
-rw-r--r-- | core/obex/obex.cc | 22 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 141 | ||||
-rw-r--r-- | core/obex/obexsend.h | 45 |
3 files changed, 142 insertions, 66 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 | |||
@@ -2,6 +2,9 @@ | |||
2 | #include <qapplication.h> | 2 | #include <qapplication.h> |
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> |
7 | #include "obex.h" | 10 | #include "obex.h" |
@@ -107,6 +110,12 @@ void Obex::slotExited(OProcess* proc ){ | |||
107 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | 110 | 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 | } |
112 | } | 121 | } |
@@ -117,4 +126,11 @@ void Obex::received() { | |||
117 | QString filename = parseOut(); | 126 | QString filename = parseOut(); |
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 ); |
120 | } | 136 | } |
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 | |||
@@ -4,4 +4,5 @@ | |||
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> |
@@ -60,6 +61,6 @@ void SendWidget::initUI() { | |||
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); |
@@ -87,14 +88,14 @@ void SendWidget::send( const QString& file, const QString& 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 ) { |
@@ -107,25 +108,26 @@ void SendWidget::send( const QString& file, const QString& desc ) { | |||
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()"); |
@@ -141,5 +143,5 @@ void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { | |||
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 | } |
@@ -150,17 +152,17 @@ 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 | } |
@@ -180,41 +182,76 @@ 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; | ||
210 | } | 233 | } |
234 | return ret; | ||
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 { |
@@ -251,4 +288,4 @@ void DeviceItem::setStatus(const QString& 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 | } |
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 | |||
@@ -20,4 +20,16 @@ namespace OpieObex { | |||
20 | class DeviceBox; | 20 | class DeviceBox; |
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{ |
23 | Q_OBJECT | 35 | Q_OBJECT |
@@ -39,5 +51,5 @@ namespace OpieObex { | |||
39 | /* Bt Names + BD-Addr */ | 51 | /* Bt Names + BD-Addr */ |
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 ); |
43 | void dispatchBt( const QCString& str, const QByteArray& ar ); | 55 | void dispatchBt( const QCString& str, const QByteArray& ar ); |
@@ -54,13 +66,16 @@ namespace OpieObex { | |||
54 | QVBoxLayout* m_lay; | 66 | QVBoxLayout* m_lay; |
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 | }; |
61 | class DeviceItem { | 76 | class DeviceItem { |
62 | public: | 77 | public: |
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(); |
66 | void setStatus( const QString& text ); | 81 | void setStatus( const QString& text ); |
@@ -70,4 +85,5 @@ namespace OpieObex { | |||
70 | QString pixmap()const; | 85 | QString pixmap()const; |
71 | int device()const; | 86 | int device()const; |
87 | int id()const; | ||
72 | QString toString()const; | 88 | QString toString()const; |
73 | private: | 89 | private: |
@@ -75,5 +91,11 @@ namespace OpieObex { | |||
75 | QString m_status; | 91 | QString m_status; |
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 { |
79 | Q_OBJECT | 101 | Q_OBJECT |
@@ -84,14 +106,15 @@ namespace OpieObex { | |||
84 | 106 | ||
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 | }; |
97 | } | 120 | } |