summaryrefslogtreecommitdiff
authorzecke <zecke>2003-02-18 20:42:05 (UTC)
committer zecke <zecke>2003-02-18 20:42:05 (UTC)
commitd3f15e100af8a91504ac9e5fb95dce0cadfe4837 (patch) (unidiff)
tree04ddeda0f690aa1d51ba486b114251250eef2ef9
parent9f5098a6da637e81f6525482456394a68524dc61 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obex.cc22
-rw-r--r--core/obex/obexsend.cpp141
-rw-r--r--core/obex/obexsend.h47
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
@@ -1,196 +1,212 @@
1 1
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"
8 11
9using namespace OpieObex; 12using namespace OpieObex;
10 13
11Obex::Obex( QObject *parent, const char* name ) 14Obex::Obex( QObject *parent, const char* name )
12 : QObject(parent, name ) 15 : QObject(parent, name )
13{ 16{
14 m_rec = 0; 17 m_rec = 0;
15 m_send=0; 18 m_send=0;
16 m_count = 0; 19 m_count = 0;
17 m_receive = false; 20 m_receive = false;
18 connect( this, SIGNAL(error(int) ), // for recovering to receive 21 connect( this, SIGNAL(error(int) ), // for recovering to receive
19 SLOT(slotError() ) ); 22 SLOT(slotError() ) );
20 connect( this, SIGNAL(sent(bool) ), 23 connect( this, SIGNAL(sent(bool) ),
21 SLOT(slotError() ) ); 24 SLOT(slotError() ) );
22}; 25};
23Obex::~Obex() { 26Obex::~Obex() {
24 delete m_rec; 27 delete m_rec;
25 delete m_send; 28 delete m_send;
26} 29}
27void Obex::receive() { 30void Obex::receive() {
28 m_receive = true; 31 m_receive = true;
29 m_outp = QString::null; 32 m_outp = QString::null;
30 qWarning("Receive" ); 33 qWarning("Receive" );
31 m_rec = new OProcess(); 34 m_rec = new OProcess();
32 *m_rec << "irobex_palm3"; 35 *m_rec << "irobex_palm3";
33 // connect to the necessary slots 36 // connect to the necessary slots
34 connect(m_rec, SIGNAL(processExited(OProcess*) ), 37 connect(m_rec, SIGNAL(processExited(OProcess*) ),
35 this, SLOT(slotExited(OProcess*) ) ); 38 this, SLOT(slotExited(OProcess*) ) );
36 39
37 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 40 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
38 this, SLOT(slotStdOut(OProcess*, char*, int) ) ); 41 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
39 42
40 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 43 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
41 qWarning("could not start :("); 44 qWarning("could not start :(");
42 emit done( false ); 45 emit done( false );
43 delete m_rec; 46 delete m_rec;
44 m_rec = 0; 47 m_rec = 0;
45 } 48 }
46// emit currentTry(m_count ); 49// emit currentTry(m_count );
47 50
48} 51}
49void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 52void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
50 m_count = 0; 53 m_count = 0;
51 m_file = fileName; 54 m_file = fileName;
52 qWarning("send %s", fileName.latin1() ); 55 qWarning("send %s", fileName.latin1() );
53 if (m_rec != 0 ) { 56 if (m_rec != 0 ) {
54 qWarning("running"); 57 qWarning("running");
55 if (m_rec->isRunning() ) { 58 if (m_rec->isRunning() ) {
56 emit error(-1 ); 59 emit error(-1 );
57 qWarning("is running"); 60 qWarning("is running");
58 delete m_rec; 61 delete m_rec;
59 m_rec = 0; 62 m_rec = 0;
60 63
61 }else{ 64 }else{
62 qWarning("is not running"); 65 qWarning("is not running");
63 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 66 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
64 return; 67 return;
65 } 68 }
66 } 69 }
67 sendNow(); 70 sendNow();
68} 71}
69void Obex::sendNow(){ 72void Obex::sendNow(){
70 qWarning("sendNow"); 73 qWarning("sendNow");
71 if ( m_count >= 25 ) { // could not send 74 if ( m_count >= 25 ) { // could not send
72 emit error(-1 ); 75 emit error(-1 );
73 emit sent(false); 76 emit sent(false);
74 return; 77 return;
75 } 78 }
76 // OProcess inititialisation 79 // OProcess inititialisation
77 m_send = new OProcess(); 80 m_send = new OProcess();
78 *m_send << "irobex_palm3"; 81 *m_send << "irobex_palm3";
79 *m_send << QFile::encodeName(m_file); 82 *m_send << QFile::encodeName(m_file);
80 83
81 // connect to slots Exited and and StdOut 84 // connect to slots Exited and and StdOut
82 connect(m_send, SIGNAL(processExited(OProcess*) ), 85 connect(m_send, SIGNAL(processExited(OProcess*) ),
83 this, SLOT(slotExited(OProcess*)) ); 86 this, SLOT(slotExited(OProcess*)) );
84 connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )), 87 connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )),
85 this, SLOT(slotStdOut(OProcess*, char*, int) ) ); 88 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
86 89
87 // now start it 90 // now start it
88 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 91 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
89 qWarning("could not send" ); 92 qWarning("could not send" );
90 m_count = 25; 93 m_count = 25;
91 emit error(-1 ); 94 emit error(-1 );
92 delete m_send; 95 delete m_send;
93 m_send=0; 96 m_send=0;
94 } 97 }
95 // end 98 // end
96 m_count++; 99 m_count++;
97 emit currentTry( m_count ); 100 emit currentTry( m_count );
98} 101}
99 102
100void Obex::slotExited(OProcess* proc ){ 103void Obex::slotExited(OProcess* proc ){
101 if (proc == m_rec ) { // receive process 104 if (proc == m_rec ) { // receive process
102 received(); 105 received();
103 }else if ( proc == m_send ) { 106 }else if ( proc == m_send ) {
104 sendEnd(); 107 sendEnd();
105 } 108 }
106} 109}
107void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 110void 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}
113 122
114void Obex::received() { 123void Obex::received() {
115 if (m_rec->normalExit() ) { 124 if (m_rec->normalExit() ) {
116 if ( m_rec->exitStatus() == 0 ) { // we got one 125 if ( m_rec->exitStatus() == 0 ) { // we got one
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 }
121 }else{ 137 }else{
122 emit done(false); 138 emit done(false);
123 }; 139 };
124 delete m_rec; 140 delete m_rec;
125 m_rec = 0; 141 m_rec = 0;
126 receive(); 142 receive();
127} 143}
128 144
129void Obex::sendEnd() { 145void Obex::sendEnd() {
130 if (m_send->normalExit() ) { 146 if (m_send->normalExit() ) {
131 if ( m_send->exitStatus() == 0 ) { 147 if ( m_send->exitStatus() == 0 ) {
132 delete m_send; 148 delete m_send;
133 m_send=0; 149 m_send=0;
134 qWarning("done" ); 150 qWarning("done" );
135 emit sent(true); 151 emit sent(true);
136 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 152 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
137 // let's try it again 153 // let's try it again
138 delete m_send; 154 delete m_send;
139 m_send = 0; 155 m_send = 0;
140 qWarning("try sending again" ); 156 qWarning("try sending again" );
141 sendNow(); 157 sendNow();
142 } 158 }
143 }else { 159 }else {
144 emit error( -1 ); 160 emit error( -1 );
145 delete m_send; 161 delete m_send;
146 m_send = 0; 162 m_send = 0;
147 } 163 }
148} 164}
149QString Obex::parseOut( ){ 165QString Obex::parseOut( ){
150 QString path; 166 QString path;
151 QStringList list = QStringList::split("\n", m_outp); 167 QStringList list = QStringList::split("\n", m_outp);
152 QStringList::Iterator it; 168 QStringList::Iterator it;
153 for (it = list.begin(); it != list.end(); ++it ) { 169 for (it = list.begin(); it != list.end(); ++it ) {
154 if ( (*it).startsWith("Wrote" ) ) { 170 if ( (*it).startsWith("Wrote" ) ) {
155 int pos = (*it).findRev('(' ); 171 int pos = (*it).findRev('(' );
156 if ( pos > 0 ) { 172 if ( pos > 0 ) {
157 qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ; 173 qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ;
158 qWarning("%d %d", (*it).length(), (*it).length()-pos ); 174 qWarning("%d %d", (*it).length(), (*it).length()-pos );
159 175
160 path = (*it).remove( pos, (*it).length() - pos ); 176 path = (*it).remove( pos, (*it).length() - pos );
161 qWarning("%s", path.latin1() ); 177 qWarning("%s", path.latin1() );
162 path = path.mid(6 ); 178 path = path.mid(6 );
163 path = path.stripWhiteSpace(); 179 path = path.stripWhiteSpace();
164 qWarning("path %s", path.latin1() ); 180 qWarning("path %s", path.latin1() );
165 } 181 }
166 } 182 }
167 } 183 }
168 return path; 184 return path;
169} 185}
170/** 186/**
171 * when sent is done slotError is called we will start receive again 187 * when sent is done slotError is called we will start receive again
172 */ 188 */
173void Obex::slotError() { 189void Obex::slotError() {
174 qWarning("slotError"); 190 qWarning("slotError");
175 if ( m_receive ) 191 if ( m_receive )
176 receive(); 192 receive();
177}; 193};
178void Obex::setReceiveEnabled( bool receive ) { 194void Obex::setReceiveEnabled( bool receive ) {
179 if ( !receive ) { // 195 if ( !receive ) { //
180 m_receive = false; 196 m_receive = false;
181 shutDownReceive(); 197 shutDownReceive();
182 } 198 }
183} 199}
184 200
185void Obex::shutDownReceive() { 201void Obex::shutDownReceive() {
186 if (m_rec != 0 ) { 202 if (m_rec != 0 ) {
187 qWarning("running"); 203 qWarning("running");
188 if (m_rec->isRunning() ) { 204 if (m_rec->isRunning() ) {
189 emit error(-1 ); 205 emit error(-1 );
190 qWarning("is running"); 206 qWarning("is running");
191 delete m_rec; 207 delete m_rec;
192 m_rec = 0; 208 m_rec = 0;
193 } 209 }
194 } 210 }
195 211
196} 212}
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,254 +1,291 @@
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
15using namespace OpieObex; 16using namespace OpieObex;
16 17
17 18
18SendWidget::SendWidget( QWidget* parent, const char* name ) 19SendWidget::SendWidget( QWidget* parent, const char* name )
19 : QWidget( parent, name ) { 20 : QWidget( parent, name ) {
20 initUI(); 21 initUI();
21} 22}
22SendWidget::~SendWidget() { 23SendWidget::~SendWidget() {
23} 24}
24void SendWidget::initUI() { 25void 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) ) );
30 connect(m_obex, SIGNAL(currentTry(unsigned int ) ), 31 connect(m_obex, SIGNAL(currentTry(unsigned int ) ),
31 this, SLOT(slotIrTry(unsigned int ) ) ); 32 this, SLOT(slotIrTry(unsigned int ) ) );
32 33
33 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); 34 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
34 connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), 35 connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
35 this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) ); 36 this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) );
36 37
37 chan = new QCopChannel("QPE/BluetoothBack", this ); 38 chan = new QCopChannel("QPE/BluetoothBack", this );
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 */
82void SendWidget::send( const QString& file, const QString& desc ) { 83void 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}
107void SendWidget::slotIrDaDevices( const QStringList& list) { 108void 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
118void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { 120void 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}
125void SendWidget::slotSelectedDevice( const QString& name, int dev ) { 127void 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}
134void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { 136void 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}
143void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 145void SendWidget::dispatchBt( const QCString&, const QByteArray& ) {
144 146
145} 147}
146void SendWidget::slotIrError( int ) { 148void SendWidget::slotIrError( int ) {
147 149
148} 150}
149void SendWidget::slotIrSent( bool b) { 151void 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}
156void SendWidget::slotIrTry(unsigned int trI) { 158void 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}
159void SendWidget::slotStartIrda() { 161void 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}
167void SendWidget::slotDone() { 169void 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}
172QString SendWidget::file()const { 174QString SendWidget::file()const {
173 return m_file; 175 return m_file;
174} 176}
175DeviceBox::DeviceBox( QWidget* parent ) 177DeviceBox::DeviceBox( QWidget* parent )
176 : QTextBrowser( parent ) { 178 : QTextBrowser( parent ) {
177 179
178} 180}
179DeviceBox::~DeviceBox() { 181DeviceBox::~DeviceBox() {
180 182
181} 183}
182void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { 184int 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}
190void 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}
193void DeviceBox::removeDevice( int id ) {
194 if (!m_dev.contains(id) ) return;
196 195
196 m_dev.remove( id );
197 setText( allText() );
197} 198}
198void DeviceBox::setStatus( const QString& name, const QString& status ) { 199void 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}
207void DeviceBox::setSource( const QString& str ) { 204void 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}
209int 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}
236QString 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
213DeviceItem::DeviceItem( const QString& name, 246DeviceItem::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}
254int DeviceItem::id()const {
255 return m_id;
219} 256}
220QString DeviceItem::name()const { 257QString DeviceItem::name()const {
221 return m_name; 258 return m_name;
222} 259}
223QString DeviceItem::status()const { 260QString DeviceItem::status()const {
224 return m_status; 261 return m_status;
225} 262}
226int DeviceItem::device()const { 263int DeviceItem::device()const {
227 return m_dev; 264 return m_dev;
228} 265}
229QString DeviceItem::pixmap()const{ 266QString 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}
247DeviceItem::~DeviceItem() { 284DeviceItem::~DeviceItem() {
248} 285}
249void DeviceItem::setStatus(const QString& status ) { 286void DeviceItem::setStatus(const QString& status ) {
250 m_status = status; 287 m_status = status;
251} 288}
252QString DeviceItem::toString()const { 289QString 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
@@ -1,99 +1,122 @@
1#ifndef OPIE_OBEX_SEND_WIDGET_H 1#ifndef OPIE_OBEX_SEND_WIDGET_H
2#define OPIE_OBEX_SEND_WIDGET_H 2#define OPIE_OBEX_SEND_WIDGET_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qwidget.h> 6#include <qwidget.h>
7#include <qvbox.h> 7#include <qvbox.h>
8#include <qmap.h> 8#include <qmap.h>
9#include <qtextbrowser.h> 9#include <qtextbrowser.h>
10 10
11class QLabel; 11class QLabel;
12class QVBoxLayout; 12class QVBoxLayout;
13/** 13/**
14 * This is the new sending widget for Obex 14 * This is the new sending widget for Obex
15 * It will attemp to smart and be able to send 15 * It will attemp to smart and be able to send
16 * it to multiple devices. 16 * it to multiple devices.
17 * It'll support BT + IrDa 17 * It'll support BT + IrDa
18 */ 18 */
19namespace OpieObex { 19namespace 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
24 public: 36 public:
25 SendWidget( QWidget* parent = 0, const char* name = 0); 37 SendWidget( QWidget* parent = 0, const char* name = 0);
26 ~SendWidget(); 38 ~SendWidget();
27 39
28 QString file()const; 40 QString file()const;
29 41
30 public slots: 42 public slots:
31 void send( const QString& file, const QString& desc ); 43 void send( const QString& file, const QString& desc );
32 44
33 signals: 45 signals:
34 void done(); 46 void done();
35 47
36 private slots: // QCOP slots 48 private slots: // QCOP slots
37 /* IrDa Names*/ 49 /* IrDa Names*/
38 void slotIrDaDevices( const QStringList& ); 50 void slotIrDaDevices( const QStringList& );
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 );
44 56
45 void slotIrError( int ); 57 void slotIrError( int );
46 void slotIrSent(bool); 58 void slotIrSent(bool);
47 void slotIrTry(unsigned int ); 59 void slotIrTry(unsigned int );
48 void slotStartIrda(); 60 void slotStartIrda();
49 void slotDone(); 61 void slotDone();
50 private: 62 private:
51 void initUI(); 63 void initUI();
52 QLabel* m_lblFile; 64 QLabel* m_lblFile;
53 DeviceBox* m_devBox; 65 DeviceBox* m_devBox;
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 );
67 82
68 QString name()const; 83 QString name()const;
69 QString status()const; 84 QString status()const;
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:
74 QString m_name; 90 QString m_name;
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
80 public: 102 public:
81 enum Device { IrDa, BT, Search, Error }; 103 enum Device { IrDa, BT, Search, Error };
82 DeviceBox( QWidget* parent ); 104 DeviceBox( QWidget* parent );
83 ~DeviceBox(); 105 ~DeviceBox();
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}
98 121
99#endif 122#endif