author | korovkin <korovkin> | 2006-12-03 14:09:33 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-12-03 14:09:33 (UTC) |
commit | a691909050b60b94f5525093062c23d0fab11d1b (patch) (unidiff) | |
tree | 1e1d82e76d85cd75c094ae36441ec852bb5ac456 | |
parent | 9813113f0024205e09af9e54328287dd859fa2e8 (diff) | |
download | opie-a691909050b60b94f5525093062c23d0fab11d1b.zip opie-a691909050b60b94f5525093062c23d0fab11d1b.tar.gz opie-a691909050b60b94f5525093062c23d0fab11d1b.tar.bz2 |
Made OBEX library buildable if bluetooth support is disabled.
-rw-r--r-- | core/obex/btobex.h | 3 | ||||
-rw-r--r-- | core/obex/obex.pro | 10 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 45 | ||||
-rw-r--r-- | core/obex/obexsend.h | 9 | ||||
-rw-r--r-- | core/obex/receiver.cpp | 2 |
5 files changed, 62 insertions, 7 deletions
diff --git a/core/obex/btobex.h b/core/obex/btobex.h index 7e91c06..d9bd886 100644 --- a/core/obex/btobex.h +++ b/core/obex/btobex.h | |||
@@ -1,118 +1,119 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> | 3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <, > . <= redistribute it and/or modify it under | 6 | .> <, > . <= redistribute it and/or modify it under |
7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; version 2 of the License. | 9 | - . .-<_> .<> Foundation; version 2 of the License. |
10 | ._= =} : | 10 | ._= =} : |
11 | .%+i> _;_. | 11 | .%+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. . .: details. | 18 | ++= -. . .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-= this library; see the file COPYING.LIB. | 22 | -- :-= this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | /* | 28 | /* |
29 | * The Bluetooth OBEX manipulating class declaration | 29 | * The Bluetooth OBEX manipulating class declaration |
30 | */ | 30 | */ |
31 | 31 | ||
32 | 32 | ||
33 | #ifndef OpieBtObex_H | 33 | #ifndef OpieBtObex_H |
34 | #define OpieBtObex_H | 34 | #define OpieBtObex_H |
35 | #ifdef BLUETOOTH | ||
35 | 36 | ||
36 | #include "obexbase.h" | 37 | #include "obexbase.h" |
37 | #include <qobject.h> | 38 | #include <qobject.h> |
38 | #include <services.h> | 39 | #include <services.h> |
39 | #include <manager.h> | 40 | #include <manager.h> |
40 | #include <obexpush.h> | 41 | #include <obexpush.h> |
41 | #include "obexserver.h" | 42 | #include "obexserver.h" |
42 | 43 | ||
43 | namespace Opie {namespace Core {class OProcess;}} | 44 | namespace Opie {namespace Core {class OProcess;}} |
44 | class QCopChannel; | 45 | class QCopChannel; |
45 | using namespace OpieTooth; | 46 | using namespace OpieTooth; |
46 | namespace OpieObex { | 47 | namespace OpieObex { |
47 | // Maybe this should be derved from Obex. | 48 | // Maybe this should be derved from Obex. |
48 | class BtObex : public ObexBase { | 49 | class BtObex : public ObexBase { |
49 | Q_OBJECT | 50 | Q_OBJECT |
50 | public: | 51 | public: |
51 | /** | 52 | /** |
52 | * BtObex c'tor look | 53 | * BtObex c'tor look |
53 | */ | 54 | */ |
54 | BtObex( QObject *parent, const char* name); | 55 | BtObex( QObject *parent, const char* name); |
55 | /** | 56 | /** |
56 | * d'tor | 57 | * d'tor |
57 | */ | 58 | */ |
58 | ~BtObex(); | 59 | ~BtObex(); |
59 | 60 | ||
60 | /** TODO mbhaynie -- Maybe opd would be a better way to receive. | 61 | /** TODO mbhaynie -- Maybe opd would be a better way to receive. |
61 | * Starting listening to Bluetooth after enabled by the applet | 62 | * Starting listening to Bluetooth after enabled by the applet |
62 | * a signal gets emitted when received a file | 63 | * a signal gets emitted when received a file |
63 | */ | 64 | */ |
64 | void receive(); | 65 | void receive(); |
65 | void send( const QString&, const QString& ); | 66 | void send( const QString&, const QString& ); |
66 | void setReceiveEnabled( bool = false ); | 67 | void setReceiveEnabled( bool = false ); |
67 | signals: | 68 | signals: |
68 | 69 | ||
69 | /** | 70 | /** |
70 | * a signal | 71 | * a signal |
71 | * @param path The path to the received file | 72 | * @param path The path to the received file |
72 | */ | 73 | */ |
73 | void receivedFile( const QString& path); | 74 | void receivedFile( const QString& path); |
74 | /** | 75 | /** |
75 | * error signal if the program couldn't be started or the | 76 | * error signal if the program couldn't be started or the |
76 | * the connection timed out | 77 | * the connection timed out |
77 | */ | 78 | */ |
78 | void error( int ); | 79 | void error( int ); |
79 | /** | 80 | /** |
80 | * The current try to receive data | 81 | * The current try to receive data |
81 | */ | 82 | */ |
82 | void currentTry(unsigned int); | 83 | void currentTry(unsigned int); |
83 | /** | 84 | /** |
84 | * signal sent The file got beamed to the remote location | 85 | * signal sent The file got beamed to the remote location |
85 | */ | 86 | */ |
86 | void sent(bool); | 87 | void sent(bool); |
87 | void done(bool); | 88 | void done(bool); |
88 | 89 | ||
89 | private: | 90 | private: |
90 | int m_port; | 91 | int m_port; |
91 | ObexPush* m_send; | 92 | ObexPush* m_send; |
92 | bool m_receive : 1; | 93 | bool m_receive : 1; |
93 | OpieTooth::Manager* btManager; | 94 | OpieTooth::Manager* btManager; |
94 | void shutDownReceive(); | 95 | void shutDownReceive(); |
95 | ObexServer* m_rec; | 96 | ObexServer* m_rec; |
96 | 97 | ||
97 | private slots: | 98 | private slots: |
98 | 99 | ||
99 | // Push process slots | 100 | // Push process slots |
100 | void slotPushStatus(QCString&); | 101 | void slotPushStatus(QCString&); |
101 | void slotPushComplete(int); | 102 | void slotPushComplete(int); |
102 | void slotPushError(int); | 103 | void slotPushError(int); |
103 | 104 | ||
104 | // the process exited | 105 | // the process exited |
105 | void slotExited(Opie::Core::OProcess*) ; | 106 | void slotExited(Opie::Core::OProcess*) ; |
106 | void slotStdOut(Opie::Core::OProcess*, char*, int); | 107 | void slotStdOut(Opie::Core::OProcess*, char*, int); |
107 | void slotError(); | 108 | void slotError(); |
108 | void slotFoundServices(const QString&, Services::ValueList); | 109 | void slotFoundServices(const QString&, Services::ValueList); |
109 | 110 | ||
110 | private: | 111 | private: |
111 | void sendNow(); | 112 | void sendNow(); |
112 | QString parseOut(); | 113 | QString parseOut(); |
113 | void received(); | 114 | void received(); |
114 | }; | 115 | }; |
115 | }; | 116 | }; |
116 | 117 | ||
117 | 118 | #endif //BLUETOOTH | |
118 | #endif | 119 | #endif |
diff --git a/core/obex/obex.pro b/core/obex/obex.pro index 1fc6958..05118ab 100644 --- a/core/obex/obex.pro +++ b/core/obex/obex.pro | |||
@@ -1,20 +1,24 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h obexbase.h obexserver.h | 3 | HEADERS= obex.h obexhandler.h obexsend.h receiver.h obeximpl.h obexbase.h obexserver.h |
4 | SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp obexbase.cpp obexserver.cpp | 4 | SOURCES= obex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp obexbase.cpp obexserver.cpp |
5 | TARGET = opieobex | 5 | TARGET = opieobex |
6 | DESTDIR = $(OPIEDIR)/plugins/obex | 6 | DESTDIR = $(OPIEDIR)/plugins/obex |
7 | INTERFACES = obexsendbase.ui | 7 | INTERFACES = obexsendbase.ui |
8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher | 8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher |
9 | DEPENDPATH += | 9 | DEPENDPATH += |
10 | LIBS += -lqpe -lopiecore2 | 10 | LIBS += -lqpe -lopiecore2 |
11 | VERSION = 0.0.4 | 11 | VERSION = 0.0.4 |
12 | 12 | ||
13 | include( $(OPIEDIR)/include.pro ) | 13 | include( $(OPIEDIR)/include.pro ) |
14 | target.path = $$prefix/plugins/applets | 14 | target.path = $$prefix/plugins/applets |
15 | 15 | ||
16 | #FIXME: These parameters are used if bluetooth is used | 16 | #FIXME: These parameters are used if bluetooth is used |
17 | CONFTEST = $$system( echo $CONFIG_LIBOPIETOOTH ) | ||
18 | contains( CONFTEST, y ){ | ||
19 | HEADERS += btobex.h | ||
20 | SOURCES += btobex.cpp | ||
17 | INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib | 21 | INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib |
18 | LIBS += -lopietooth1 -lbluetooth -lopenobex | 22 | LIBS += -lopietooth1 -lbluetooth -lopenobex |
19 | DEFINES += BLUETOOTH | 23 | DEFINES += BLUETOOTH |
20 | 24 | } | |
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index 45754e3..d58b4e9 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -1,313 +1,352 @@ | |||
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 | #ifdef BLUETOOTH | ||
7 | #include "btobex.h" | 8 | #include "btobex.h" |
9 | #endif | ||
8 | #include "obexsend.h" | 10 | #include "obexsend.h" |
9 | using namespace OpieObex; | 11 | using namespace OpieObex; |
12 | #ifdef BLUETOOTH | ||
10 | using namespace OpieTooth; | 13 | using namespace OpieTooth; |
14 | #endif | ||
11 | 15 | ||
12 | /* OPIE */ | 16 | /* OPIE */ |
13 | #include <opie2/odebug.h> | 17 | #include <opie2/odebug.h> |
14 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
15 | #include <opie2/oresource.h> | 19 | #include <opie2/oresource.h> |
16 | #include <qpe/version.h> | 20 | #include <qpe/version.h> |
21 | #ifdef BLUETOOTH | ||
17 | #include <devicehandler.h> | 22 | #include <devicehandler.h> |
18 | #include "remotedevice.h" | 23 | #include "remotedevice.h" |
24 | #endif | ||
19 | 25 | ||
20 | using namespace Opie::Core; | 26 | using namespace Opie::Core; |
21 | 27 | ||
22 | /* QT */ | 28 | /* QT */ |
23 | #include <qlabel.h> | 29 | #include <qlabel.h> |
24 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
25 | #include <qpixmap.h> | 31 | #include <qpixmap.h> |
26 | #include <qlistview.h> | 32 | #include <qlistview.h> |
27 | 33 | ||
28 | #include <unistd.h> | 34 | #include <unistd.h> |
29 | /* TRANSLATOR OpieObex::SendWidget */ | 35 | /* TRANSLATOR OpieObex::SendWidget */ |
30 | 36 | ||
31 | /* Just for backward compatibility */ | 37 | /* Just for backward compatibility */ |
32 | #if OPIE_VERSION < 102010 | 38 | #if OPIE_VERSION < 102010 |
33 | #define OResource Resource | 39 | #define OResource Resource |
34 | #endif | 40 | #endif |
35 | 41 | ||
36 | SendWidget::SendWidget( QWidget* parent, const char* name ) | 42 | SendWidget::SendWidget( QWidget* parent, const char* name ) |
37 | : obexSendBase( parent, name ) { | 43 | : obexSendBase( parent, name ) { |
38 | initUI(); | 44 | initUI(); |
39 | } | 45 | } |
40 | SendWidget::~SendWidget() { | 46 | SendWidget::~SendWidget() { |
41 | } | 47 | } |
42 | void SendWidget::initUI() { | 48 | void SendWidget::initUI() { |
43 | m_obex = new Obex(this, "obex"); | 49 | m_obex = new Obex(this, "obex"); |
44 | connect(m_obex, SIGNAL(error(int) ), | 50 | connect(m_obex, SIGNAL(error(int) ), |
45 | this, SLOT(slotIrError(int) ) ); | 51 | this, SLOT(slotIrError(int) ) ); |
46 | connect(m_obex, SIGNAL(sent(bool) ), | 52 | connect(m_obex, SIGNAL(sent(bool) ), |
47 | this, SLOT(slotIrSent(bool) ) ); | 53 | this, SLOT(slotIrSent(bool) ) ); |
48 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), | 54 | connect(m_obex, SIGNAL(currentTry(unsigned int) ), |
49 | this, SLOT(slotIrTry(unsigned int) ) ); | 55 | this, SLOT(slotIrTry(unsigned int) ) ); |
50 | 56 | ||
51 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); | 57 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); |
52 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 58 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
53 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); | 59 | this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); |
54 | 60 | ||
61 | #ifdef BLUETOOTH | ||
55 | m_btobex = new BtObex(this, "btobex"); | 62 | m_btobex = new BtObex(this, "btobex"); |
56 | connect(m_btobex, SIGNAL(error(int) ), | 63 | connect(m_btobex, SIGNAL(error(int) ), |
57 | this, SLOT(slotBtError(int) ) ); | 64 | this, SLOT(slotBtError(int) ) ); |
58 | connect(m_btobex, SIGNAL(sent(bool) ), | 65 | connect(m_btobex, SIGNAL(sent(bool) ), |
59 | this, SLOT(slotBtSent(bool) ) ); | 66 | this, SLOT(slotBtSent(bool) ) ); |
60 | connect(m_btobex, SIGNAL(currentTry(unsigned int) ), | 67 | connect(m_btobex, SIGNAL(currentTry(unsigned int) ), |
61 | this, SLOT(slotBtTry(unsigned int) ) ); | 68 | this, SLOT(slotBtTry(unsigned int) ) ); |
62 | 69 | ||
63 | chan = new QCopChannel("QPE/BluetoothBack", this ); | 70 | chan = new QCopChannel("QPE/BluetoothBack", this ); |
64 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 71 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
65 | this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); | 72 | this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); |
66 | 73 | #endif | |
67 | } | 74 | } |
68 | 75 | ||
69 | /* | 76 | /* |
70 | * in send we'll first set everything up | 77 | * in send we'll first set everything up |
71 | * and then wait for a list of devices. | 78 | * and then wait for a list of devices. |
72 | */ | 79 | */ |
73 | void SendWidget::send( const QString& file, const QString& desc ) { | 80 | void SendWidget::send( const QString& file, const QString& desc ) { |
74 | m_file = file; | 81 | m_file = file; |
75 | m_irDa.clear(); | 82 | m_irDa.clear(); |
83 | #ifdef BLUETOOTH | ||
76 | m_bt.clear(); | 84 | m_bt.clear(); |
85 | #endif | ||
77 | m_start = 0; | 86 | m_start = 0; |
78 | 87 | ||
79 | fileToSend->setText(desc.isEmpty() ? file : desc ); | 88 | fileToSend->setText(desc.isEmpty() ? file : desc ); |
80 | 89 | ||
81 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) | 90 | if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) |
82 | { | 91 | { |
83 | irdaStatus->setText(tr("not enabled.")); | 92 | irdaStatus->setText(tr("not enabled.")); |
84 | } | 93 | } |
85 | else | 94 | else |
86 | { | 95 | { |
87 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); | 96 | QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); |
88 | irdaStatus->setText(tr("ready")); | 97 | irdaStatus->setText(tr("ready")); |
89 | sendButton->setEnabled( true ); | 98 | sendButton->setEnabled( true ); |
90 | } | 99 | } |
100 | #ifdef BLUETOOTH | ||
91 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) | 101 | if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) |
92 | { | 102 | { |
93 | btStatus->setText(tr("not enabled.")); | 103 | btStatus->setText(tr("not enabled.")); |
94 | } | 104 | } |
95 | else | 105 | else |
96 | { | 106 | { |
97 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); | 107 | QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); |
98 | btStatus->setText(tr("ready.")); | 108 | btStatus->setText(tr("ready.")); |
99 | sendButton->setEnabled( true ); | 109 | sendButton->setEnabled( true ); |
100 | } | 110 | } |
101 | read_receivers(); | 111 | read_receivers(); |
112 | #endif | ||
102 | } | 113 | } |
103 | 114 | ||
104 | int SendWidget::addReceiver(const QString& str, const char *icon) | 115 | int SendWidget::addReceiver(const QString& str, const char *icon) |
105 | { | 116 | { |
106 | QListViewItem * item = new QListViewItem( receiverList, 0 ); | 117 | QListViewItem * item = new QListViewItem( receiverList, 0 ); |
107 | item->setText( 0, str ); | 118 | item->setText( 0, str ); |
108 | item->setPixmap( 1, OResource::loadPixmap( icon ) ); | 119 | item->setPixmap( 1, OResource::loadPixmap( icon ) ); |
109 | 120 | ||
110 | int id = receivers.count(); | 121 | int id = receivers.count(); |
111 | receivers[id] = item; | 122 | receivers[id] = item; |
112 | return id; | 123 | return id; |
113 | } | 124 | } |
114 | 125 | ||
115 | bool SendWidget::receiverSelected(int id) | 126 | bool SendWidget::receiverSelected(int id) |
116 | { | 127 | { |
117 | return (bool)(receivers[id]->pixmap(2) != NULL); | 128 | return (bool)(receivers[id]->pixmap(2) != NULL); |
118 | } | 129 | } |
119 | 130 | ||
120 | void SendWidget::setReceiverStatus( int id, const QString& status ) { | 131 | void SendWidget::setReceiverStatus( int id, const QString& status ) { |
121 | if ( !receivers.contains(id) ) return; | 132 | if ( !receivers.contains(id) ) return; |
122 | receivers[id]->setText(3, status ); | 133 | receivers[id]->setText(3, status ); |
123 | } | 134 | } |
124 | 135 | ||
125 | void SendWidget::slotIrDaDevices( const QStringList& list) { | 136 | void SendWidget::slotIrDaDevices( const QStringList& list) { |
126 | for (QStringList::ConstIterator it = list.begin(); | 137 | for (QStringList::ConstIterator it = list.begin(); |
127 | it != list.end(); ++it ) { | 138 | it != list.end(); ++it ) { |
128 | int id = addReceiver(*it, "obex/irda.png"); | 139 | int id = addReceiver(*it, "obex/irda.png"); |
129 | m_irDa.insert( id, (*it) ); | 140 | m_irDa.insert( id, (*it) ); |
130 | } | 141 | } |
131 | irdaStatus->setText( tr("ready.")); | 142 | irdaStatus->setText( tr("ready.")); |
132 | m_irDaIt = m_irDa.begin(); | 143 | m_irDaIt = m_irDa.begin(); |
133 | 144 | ||
134 | } | 145 | } |
135 | 146 | ||
136 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { | 147 | void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { |
148 | #ifdef BLUETOOTH | ||
137 | for(QMap<QString, QString>::ConstIterator it = str.begin(); | 149 | for(QMap<QString, QString>::ConstIterator it = str.begin(); |
138 | it != str.end(); ++it ) { | 150 | it != str.end(); ++it ) { |
139 | int id = addReceiver(it.key(), "obex/bt.png"); | 151 | int id = addReceiver(it.key(), "obex/bt.png"); |
140 | m_bt.insert( id, Pair( it.key(), it.data() ) ); | 152 | m_bt.insert( id, Pair( it.key(), it.data() ) ); |
141 | } | 153 | } |
142 | btStatus->setText(tr("ready.")); | 154 | btStatus->setText(tr("ready.")); |
143 | m_btIt = m_bt.begin(); | 155 | m_btIt = m_bt.begin(); |
144 | 156 | ||
157 | #else | ||
158 | (void)str; | ||
159 | #endif | ||
145 | } | 160 | } |
146 | void SendWidget::slotSelectedDevice( int, int ) { | 161 | void SendWidget::slotSelectedDevice( int, int ) { |
147 | /* if ( name == m_irDeSearch ) { | 162 | /* if ( name == m_irDeSearch ) { |
148 | for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) | 163 | for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) |
149 | m_devBox->removeDevice( it.key() ); | 164 | m_devBox->removeDevice( it.key() ); |
150 | 165 | ||
151 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 166 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
152 | }*/ | 167 | }*/ |
153 | } | 168 | } |
154 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { | 169 | void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { |
155 | if ( str == "devices(QStringList)" ) { | 170 | if ( str == "devices(QStringList)" ) { |
156 | QDataStream stream( ar, IO_ReadOnly ); | 171 | QDataStream stream( ar, IO_ReadOnly ); |
157 | QStringList list; | 172 | QStringList list; |
158 | stream >> list; | 173 | stream >> list; |
159 | slotIrDaDevices( list ); | 174 | slotIrDaDevices( list ); |
160 | } | 175 | } |
161 | } | 176 | } |
162 | void SendWidget::slotIrError( int ) { | 177 | void SendWidget::slotIrError( int ) { |
163 | irdaStatus->setText(tr("error :(")); | 178 | irdaStatus->setText(tr("error :(")); |
164 | } | 179 | } |
165 | void SendWidget::slotIrSent( bool b) { | 180 | void SendWidget::slotIrSent( bool b) { |
181 | #ifdef BLUETOOTH | ||
166 | QString text = b ? tr("Sent") : tr("Failure"); | 182 | QString text = b ? tr("Sent") : tr("Failure"); |
167 | setReceiverStatus( m_irDaIt.key(), text ); | 183 | setReceiverStatus( m_irDaIt.key(), text ); |
168 | ++m_irDaIt; | 184 | ++m_irDaIt; |
169 | slotStartIrda(); | 185 | slotStartIrda(); |
186 | #else | ||
187 | (void)b; | ||
188 | #endif | ||
170 | } | 189 | } |
171 | void SendWidget::slotIrTry(unsigned int trI) { | 190 | void SendWidget::slotIrTry(unsigned int trI) { |
172 | setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); | 191 | setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); |
173 | } | 192 | } |
174 | void SendWidget::slotStartIrda() { | 193 | void SendWidget::slotStartIrda() { |
175 | if ( !m_irDa.count() ) | 194 | if ( !m_irDa.count() ) |
176 | return; | 195 | return; |
177 | if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { | 196 | if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { |
178 | irdaStatus->setText(tr("complete.")); | 197 | irdaStatus->setText(tr("complete.")); |
179 | m_irDaIt = m_irDa.begin(); | 198 | m_irDaIt = m_irDa.begin(); |
180 | return; | 199 | return; |
181 | } | 200 | } |
182 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); | 201 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); |
183 | irdaStatus->setText(tr("sending.")); | 202 | irdaStatus->setText(tr("sending.")); |
184 | m_obex->send( m_file, tr("noaddress") ); | 203 | m_obex->send( m_file, tr("noaddress") ); |
185 | } | 204 | } |
186 | 205 | ||
187 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | 206 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { |
188 | if ( str == "devices(QStringMap)" ) { | 207 | if ( str == "devices(QStringMap)" ) { |
189 | QDataStream stream( ar, IO_ReadOnly ); | 208 | QDataStream stream( ar, IO_ReadOnly ); |
190 | QMap<QString, QString> btmap; | 209 | QMap<QString, QString> btmap; |
191 | stream >> btmap; | 210 | stream >> btmap; |
192 | slotBTDevices( btmap ); | 211 | slotBTDevices( btmap ); |
193 | } | 212 | } |
194 | } | 213 | } |
195 | void SendWidget::slotBtError( int ) { | 214 | void SendWidget::slotBtError( int ) { |
196 | btStatus->setText(tr("error :(")); | 215 | btStatus->setText(tr("error :(")); |
197 | } | 216 | } |
198 | void SendWidget::slotBtSent( bool b) { | 217 | void SendWidget::slotBtSent( bool b) { |
218 | #ifdef BLUETOOTH | ||
199 | QString text = b ? tr("Sent") : tr("Failure"); | 219 | QString text = b ? tr("Sent") : tr("Failure"); |
200 | setReceiverStatus( m_btIt.key(), text ); | 220 | setReceiverStatus( m_btIt.key(), text ); |
201 | ++m_btIt; | 221 | ++m_btIt; |
202 | slotStartBt(); | 222 | slotStartBt(); |
223 | #else | ||
224 | (void)b; | ||
225 | #endif | ||
203 | } | 226 | } |
204 | void SendWidget::slotBtTry(unsigned int trI) { | 227 | void SendWidget::slotBtTry(unsigned int trI) { |
228 | #ifdef BLUETOOTH | ||
205 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); | 229 | setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); |
230 | #else | ||
231 | (void)trI; | ||
232 | #endif | ||
206 | } | 233 | } |
207 | void SendWidget::slotStartBt() { | 234 | void SendWidget::slotStartBt() { |
235 | #ifdef BLUETOOTH | ||
208 | // skip past unselected receivers | 236 | // skip past unselected receivers |
209 | if ( !m_bt.count() ) | 237 | if ( !m_bt.count() ) |
210 | return; | 238 | return; |
211 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) | 239 | while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) |
212 | ++m_btIt; | 240 | ++m_btIt; |
213 | if (m_btIt == m_bt.end() ) { | 241 | if (m_btIt == m_bt.end() ) { |
214 | btStatus->setText(tr("complete.")); | 242 | btStatus->setText(tr("complete.")); |
215 | m_btIt = m_bt.begin(); | 243 | m_btIt = m_bt.begin(); |
216 | return; | 244 | return; |
217 | } | 245 | } |
218 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); | 246 | setReceiverStatus( m_btIt.key(), tr("Start sending") ); |
219 | btStatus->setText(tr("sending.")); | 247 | btStatus->setText(tr("sending.")); |
220 | m_btobex->send( m_file, m_btIt.data().second() ); | 248 | m_btobex->send( m_file, m_btIt.data().second() ); |
249 | #endif | ||
221 | } | 250 | } |
222 | 251 | ||
223 | void SendWidget::send_to_receivers() { | 252 | void SendWidget::send_to_receivers() { |
253 | #ifdef BLUETOOTH | ||
224 | slotStartBt(); | 254 | slotStartBt(); |
255 | #endif | ||
225 | slotStartIrda(); | 256 | slotStartIrda(); |
226 | } | 257 | } |
227 | 258 | ||
259 | #ifdef BLUETOOTH | ||
228 | /** | 260 | /** |
229 | * Read receivers saved by bluetooth manager | 261 | * Read receivers saved by bluetooth manager |
230 | */ | 262 | */ |
231 | void SendWidget::read_receivers() | 263 | void SendWidget::read_receivers() |
232 | { | 264 | { |
233 | QValueList<RemoteDevice> devices; | 265 | QValueList<RemoteDevice> devices; |
234 | DeviceHandler handler; | 266 | DeviceHandler handler; |
235 | QValueList<RemoteDevice>::ConstIterator it; | 267 | QValueList<RemoteDevice>::ConstIterator it; |
236 | 268 | ||
237 | receiverList->clear(); | 269 | receiverList->clear(); |
238 | receivers.clear(); | 270 | receivers.clear(); |
239 | sendButton->setDisabled( true ); | 271 | sendButton->setDisabled( true ); |
240 | btStatus->setText(tr("load.")); | 272 | btStatus->setText(tr("load.")); |
241 | m_bt.clear(); | 273 | m_bt.clear(); |
242 | 274 | ||
243 | if ( QCopChannel::isRegistered("QPE/Bluetooth") ) | 275 | if ( QCopChannel::isRegistered("QPE/Bluetooth") ) |
244 | { | 276 | { |
245 | devices = handler.load(); | 277 | devices = handler.load(); |
246 | for( it = devices.begin(); it != devices.end() ; ++it ) | 278 | for( it = devices.begin(); it != devices.end() ; ++it ) |
247 | { | 279 | { |
248 | int id = addReceiver((*it).name(), "obex/bt.png"); | 280 | int id = addReceiver((*it).name(), "obex/bt.png"); |
249 | m_bt.insert(id, Pair((*it).name(), (*it).mac())); | 281 | m_bt.insert(id, Pair((*it).name(), (*it).mac())); |
250 | } | 282 | } |
251 | btStatus->setText(tr("ready.")); | 283 | btStatus->setText(tr("ready.")); |
252 | m_btIt = m_bt.begin(); | 284 | m_btIt = m_bt.begin(); |
253 | sendButton->setEnabled( true ); | 285 | sendButton->setEnabled( true ); |
254 | } | 286 | } |
255 | } | 287 | } |
256 | 288 | #endif | |
257 | 289 | ||
258 | void SendWidget::scan_for_receivers() | 290 | void SendWidget::scan_for_receivers() |
259 | { | 291 | { |
260 | sendButton->setDisabled( true ); | 292 | sendButton->setDisabled( true ); |
261 | receiverList->clear(); | 293 | receiverList->clear(); |
262 | receivers.clear(); | 294 | receivers.clear(); |
263 | m_irDa.clear(); | 295 | m_irDa.clear(); |
296 | #ifdef BLUETOOTH | ||
264 | m_bt.clear(); | 297 | m_bt.clear(); |
265 | 298 | #endif | |
266 | if ( QCopChannel::isRegistered("QPE/IrDaApplet") ) | 299 | if ( QCopChannel::isRegistered("QPE/IrDaApplet") ) |
267 | { | 300 | { |
268 | irdaStatus->setText(tr("searching...")); | 301 | irdaStatus->setText(tr("searching...")); |
269 | sendButton->setEnabled( true ); | 302 | sendButton->setEnabled( true ); |
270 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); | 303 | QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); |
271 | } | 304 | } |
272 | 305 | ||
306 | #ifdef BLUETOOTH | ||
273 | if ( QCopChannel::isRegistered("QPE/Bluetooth") ) | 307 | if ( QCopChannel::isRegistered("QPE/Bluetooth") ) |
274 | { | 308 | { |
275 | btStatus->setText(tr("searching...")); | 309 | btStatus->setText(tr("searching...")); |
276 | sendButton->setEnabled( true ); | 310 | sendButton->setEnabled( true ); |
277 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); | 311 | QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); |
278 | } | 312 | } |
313 | #endif | ||
279 | } | 314 | } |
280 | 315 | ||
281 | void SendWidget::toggle_receiver(QListViewItem* item) | 316 | void SendWidget::toggle_receiver(QListViewItem* item) |
282 | { | 317 | { |
283 | if (!item) | 318 | if (!item) |
284 | return; | 319 | return; |
285 | // toggle the state of an individual receiver. | 320 | // toggle the state of an individual receiver. |
286 | if (item->pixmap(2)) | 321 | if (item->pixmap(2)) |
287 | item->setPixmap(2, QPixmap()); | 322 | item->setPixmap(2, QPixmap()); |
288 | else | 323 | else |
289 | item->setPixmap(2, OResource::loadPixmap("obex/check.png")); | 324 | item->setPixmap(2, OResource::loadPixmap("obex/check.png")); |
290 | } | 325 | } |
291 | 326 | ||
292 | 327 | ||
293 | void SendWidget::closeEvent( QCloseEvent* evt) { | 328 | void SendWidget::closeEvent( QCloseEvent* evt) { |
294 | delete m_obex; | 329 | delete m_obex; |
295 | m_obex = NULL; | 330 | m_obex = NULL; |
331 | #ifdef BLUETOOTH | ||
296 | delete m_btobex; | 332 | delete m_btobex; |
297 | m_btobex = NULL; | 333 | m_btobex = NULL; |
334 | #endif | ||
298 | obexSendBase::closeEvent(evt); | 335 | obexSendBase::closeEvent(evt); |
299 | { | 336 | { |
300 | QCopEnvelope e("QPE/IrDaApplet", "disableIrda()"); | 337 | QCopEnvelope e("QPE/IrDaApplet", "disableIrda()"); |
301 | } | 338 | } |
339 | #ifdef BLUETOOTH | ||
302 | { | 340 | { |
303 | QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()"); | 341 | QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()"); |
304 | } | 342 | } |
343 | #endif | ||
305 | } | 344 | } |
306 | 345 | ||
307 | void SendWidget::userDone() { | 346 | void SendWidget::userDone() { |
308 | close(); | 347 | close(); |
309 | } | 348 | } |
310 | 349 | ||
311 | QString SendWidget::file()const { | 350 | QString SendWidget::file()const { |
312 | return m_file; | 351 | return m_file; |
313 | } | 352 | } |
diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h index f9ba340..cc27354 100644 --- a/core/obex/obexsend.h +++ b/core/obex/obexsend.h | |||
@@ -1,99 +1,108 @@ | |||
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 | // 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one | 4 | // 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one |
5 | // generated via QT2 Designer. The new form supports | 5 | // generated via QT2 Designer. The new form supports |
6 | // selection of target devices, as opposed to sending to | 6 | // selection of target devices, as opposed to sending to |
7 | // all. | 7 | // all. |
8 | 8 | ||
9 | #include <qstring.h> | 9 | #include <qstring.h> |
10 | #include <qstringlist.h> | 10 | #include <qstringlist.h> |
11 | #include <qmap.h> | 11 | #include <qmap.h> |
12 | #include "obexsendbase.h" | 12 | #include "obexsendbase.h" |
13 | 13 | ||
14 | class QLabel; | 14 | 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 | #ifdef BLUETOOTH | ||
24 | class BtObex; | 25 | class BtObex; |
26 | #endif | ||
25 | 27 | ||
26 | struct Pair { | 28 | struct Pair { |
27 | Pair(const QString& first = QString::null, | 29 | Pair(const QString& first = QString::null, |
28 | const QString& second = QString::null) | 30 | const QString& second = QString::null) |
29 | : m_first(first), m_second(second ) { | 31 | : m_first(first), m_second(second ) { |
30 | } | 32 | } |
31 | QString first()const{ return m_first; } | 33 | QString first()const{ return m_first; } |
32 | QString second()const { return m_second; } | 34 | QString second()const { return m_second; } |
33 | private: | 35 | private: |
34 | QString m_first; | 36 | QString m_first; |
35 | QString m_second; | 37 | QString m_second; |
36 | }; | 38 | }; |
37 | class SendWidget : public obexSendBase { | 39 | class SendWidget : public obexSendBase { |
38 | Q_OBJECT | 40 | Q_OBJECT |
39 | public: | 41 | public: |
40 | SendWidget( QWidget* parent = 0, const char* name = 0); | 42 | SendWidget( QWidget* parent = 0, const char* name = 0); |
41 | ~SendWidget(); | 43 | ~SendWidget(); |
42 | 44 | ||
43 | QString file()const; | 45 | QString file()const; |
44 | 46 | ||
45 | protected: | 47 | protected: |
46 | void closeEvent( QCloseEvent* ); | 48 | void closeEvent( QCloseEvent* ); |
49 | #ifdef BLUETOOTH | ||
47 | void read_receivers(); | 50 | void read_receivers(); |
51 | #endif | ||
48 | 52 | ||
49 | public slots: | 53 | public slots: |
50 | void send( const QString& file, const QString& desc ); | 54 | void send( const QString& file, const QString& desc ); |
51 | 55 | ||
52 | signals: | 56 | signals: |
53 | void done(); | 57 | void done(); |
54 | 58 | ||
55 | protected slots: | 59 | protected slots: |
56 | virtual void userDone(); | 60 | virtual void userDone(); |
57 | virtual void send_to_receivers(); | 61 | virtual void send_to_receivers(); |
58 | virtual void scan_for_receivers(); | 62 | virtual void scan_for_receivers(); |
59 | virtual void toggle_receiver(QListViewItem* item); | 63 | virtual void toggle_receiver(QListViewItem* item); |
60 | 64 | ||
61 | private slots: // QCOP slots | 65 | private slots: // QCOP slots |
62 | /* IrDa Names*/ | 66 | /* IrDa Names*/ |
63 | void slotIrDaDevices( const QStringList& ); | 67 | void slotIrDaDevices( const QStringList& ); |
64 | /* Bt Names + BD-Addr */ | 68 | /* Bt Names + BD-Addr */ |
65 | void slotBTDevices( const QMap<QString, QString>& ); | 69 | void slotBTDevices( const QMap<QString, QString>& ); |
70 | |||
66 | void slotSelectedDevice( int id, int dev ); | 71 | void slotSelectedDevice( int id, int dev ); |
67 | 72 | ||
68 | void dispatchIrda( const QCString& str, const QByteArray& ar ); | 73 | void dispatchIrda( const QCString& str, const QByteArray& ar ); |
69 | 74 | ||
70 | void slotIrError( int ); | 75 | void slotIrError( int ); |
71 | void slotIrSent(bool); | 76 | void slotIrSent(bool); |
72 | void slotIrTry(unsigned int ); | 77 | void slotIrTry(unsigned int ); |
73 | void slotStartIrda(); | 78 | void slotStartIrda(); |
74 | 79 | ||
75 | void dispatchBt( const QCString& str, const QByteArray& ar ); | 80 | void dispatchBt( const QCString& str, const QByteArray& ar ); |
76 | void slotBtError( int ); | 81 | void slotBtError( int ); |
77 | void slotBtSent(bool); | 82 | void slotBtSent(bool); |
78 | void slotBtTry(unsigned int ); | 83 | void slotBtTry(unsigned int ); |
79 | void slotStartBt(); | 84 | void slotStartBt(); |
80 | 85 | ||
81 | private: | 86 | private: |
82 | void initUI(); | 87 | void initUI(); |
83 | int addReceiver(const QString& str, const char *icon); | 88 | int addReceiver(const QString& str, const char *icon); |
84 | void setReceiverStatus( int id, const QString& status ); | 89 | void setReceiverStatus( int id, const QString& status ); |
85 | bool receiverSelected(int id); | 90 | bool receiverSelected(int id); |
86 | 91 | ||
87 | int m_start; | 92 | int m_start; |
88 | QMap<int, QString> m_irDa; | 93 | QMap<int, QString> m_irDa; |
89 | QMap<int, QString>::Iterator m_irDaIt; | 94 | QMap<int, QString>::Iterator m_irDaIt; |
95 | #ifdef BLUETOOTH | ||
90 | QMap<int, Pair > m_bt; | 96 | QMap<int, Pair > m_bt; |
91 | QMap<int, Pair>::Iterator m_btIt; | 97 | QMap<int, Pair>::Iterator m_btIt; |
98 | #endif | ||
92 | QMap<int, QListViewItem *> receivers; | 99 | QMap<int, QListViewItem *> receivers; |
93 | QString m_file; | 100 | QString m_file; |
94 | Obex* m_obex; | 101 | Obex* m_obex; |
102 | #ifdef BLUETOOTH | ||
95 | BtObex* m_btobex; | 103 | BtObex* m_btobex; |
104 | #endif | ||
96 | }; | 105 | }; |
97 | } | 106 | } |
98 | 107 | ||
99 | #endif | 108 | #endif |
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp index e153152..3190353 100644 --- a/core/obex/receiver.cpp +++ b/core/obex/receiver.cpp | |||
@@ -1,203 +1,205 @@ | |||
1 | #include "obex.h" | 1 | #include "obex.h" |
2 | #include "btobex.h" | 2 | #include "btobex.h" |
3 | #include "obexbase.h" | 3 | #include "obexbase.h" |
4 | #include "receiver.h" | 4 | #include "receiver.h" |
5 | using namespace OpieObex; | 5 | using namespace OpieObex; |
6 | 6 | ||
7 | /* OPIE */ | 7 | /* OPIE */ |
8 | #include <opie2/odebug.h> | 8 | #include <opie2/odebug.h> |
9 | #include <qpe/applnk.h> | 9 | #include <qpe/applnk.h> |
10 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
12 | #include <qpe/filemanager.h> | 12 | #include <qpe/filemanager.h> |
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | 14 | ||
15 | /* QT */ | 15 | /* QT */ |
16 | #include <qfileinfo.h> | 16 | #include <qfileinfo.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | #include <qtextview.h> | 18 | #include <qtextview.h> |
19 | #include <qpushbutton.h> | 19 | #include <qpushbutton.h> |
20 | 20 | ||
21 | /* STD */ | 21 | /* STD */ |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | 23 | #include <sys/stat.h> |
24 | #include <sys/mman.h> | 24 | #include <sys/mman.h> |
25 | #include <stdlib.h> // int system | 25 | #include <stdlib.h> // int system |
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <fcntl.h> | 27 | #include <fcntl.h> |
28 | 28 | ||
29 | /* TRANSLATOR OpieObex::Receiver */ | 29 | /* TRANSLATOR OpieObex::Receiver */ |
30 | 30 | ||
31 | Receiver::Receiver(RecType type) { | 31 | Receiver::Receiver(RecType type) { |
32 | if (type == REC_IRDA) | 32 | if (type == REC_IRDA) |
33 | m_obex = new Obex(this, "Receiver"); | 33 | m_obex = new Obex(this, "Receiver"); |
34 | #ifdef BLUETOOTH | ||
34 | else | 35 | else |
35 | m_obex = new BtObex(this, "Receiver"); | 36 | m_obex = new BtObex(this, "Receiver"); |
37 | #endif | ||
36 | connect(m_obex, SIGNAL(receivedFile(const QString&) ), | 38 | connect(m_obex, SIGNAL(receivedFile(const QString&) ), |
37 | this, SLOT(slotReceived(const QString&) ) ); | 39 | this, SLOT(slotReceived(const QString&) ) ); |
38 | m_obex->receive(); | 40 | m_obex->receive(); |
39 | } | 41 | } |
40 | Receiver::~Receiver() { | 42 | Receiver::~Receiver() { |
41 | m_obex->setReceiveEnabled( false ); | 43 | m_obex->setReceiveEnabled( false ); |
42 | delete m_obex; | 44 | delete m_obex; |
43 | } | 45 | } |
44 | void Receiver::slotReceived( const QString& _file ) { | 46 | void Receiver::slotReceived( const QString& _file ) { |
45 | QString file = _file; | 47 | QString file = _file; |
46 | int check = checkFile(file); | 48 | int check = checkFile(file); |
47 | if ( check == AddressBook ) | 49 | if ( check == AddressBook ) |
48 | handleAddr( file ); | 50 | handleAddr( file ); |
49 | else if ( check == Datebook ) | 51 | else if ( check == Datebook ) |
50 | handleDateTodo( file ); | 52 | handleDateTodo( file ); |
51 | else | 53 | else |
52 | handleOther( file ); | 54 | handleOther( file ); |
53 | } | 55 | } |
54 | void Receiver::handleAddr( const QString& str ) { | 56 | void Receiver::handleAddr( const QString& str ) { |
55 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); | 57 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); |
56 | e << str; | 58 | e << str; |
57 | } | 59 | } |
58 | /* we can not say for sure if it's a VEevent ot VTodo */ | 60 | /* we can not say for sure if it's a VEevent ot VTodo */ |
59 | void Receiver::handleDateTodo( const QString& str ) { | 61 | void Receiver::handleDateTodo( const QString& str ) { |
60 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); | 62 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); |
61 | e0 << str; | 63 | e0 << str; |
62 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); | 64 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); |
63 | e1 << str; | 65 | e1 << str; |
64 | } | 66 | } |
65 | /* | 67 | /* |
66 | * Handle other asks if it should accept the | 68 | * Handle other asks if it should accept the |
67 | * beamed object and creates a DocLnk | 69 | * beamed object and creates a DocLnk |
68 | */ | 70 | */ |
69 | void Receiver::handleOther( const QString& other ) { | 71 | void Receiver::handleOther( const QString& other ) { |
70 | OtherHandler* hand = new OtherHandler(); | 72 | OtherHandler* hand = new OtherHandler(); |
71 | hand->handle( other ); | 73 | hand->handle( other ); |
72 | } | 74 | } |
73 | void Receiver::tidyUp( QString& _file, const QString& ending) { | 75 | void Receiver::tidyUp( QString& _file, const QString& ending) { |
74 | /* libversit fails on BASE64 encoding we try to sed it away */ | 76 | /* libversit fails on BASE64 encoding we try to sed it away */ |
75 | QString file = _file; | 77 | QString file = _file; |
76 | char foo[24]; // big enough | 78 | char foo[24]; // big enough |
77 | (void)::strcpy(foo, "/tmp/opie-XXXXXX"); | 79 | (void)::strcpy(foo, "/tmp/opie-XXXXXX"); |
78 | 80 | ||
79 | int fd = ::mkstemp(foo); | 81 | int fd = ::mkstemp(foo); |
80 | 82 | ||
81 | if ( fd == -1 ) | 83 | if ( fd == -1 ) |
82 | return; | 84 | return; |
83 | 85 | ||
84 | (void)::strncat( foo, QFile::encodeName(ending), 4 ); | 86 | (void)::strncat( foo, QFile::encodeName(ending), 4 ); |
85 | _file = QString::fromLocal8Bit( foo ); | 87 | _file = QString::fromLocal8Bit( foo ); |
86 | QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); | 88 | QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); |
87 | (void)::system( QFile::encodeName(cmd) ); | 89 | (void)::system( QFile::encodeName(cmd) ); |
88 | 90 | ||
89 | cmd = QString("rm %1").arg( Global::shellQuote(file) ); | 91 | cmd = QString("rm %1").arg( Global::shellQuote(file) ); |
90 | (void)::system( QFile::encodeName(cmd) ); | 92 | (void)::system( QFile::encodeName(cmd) ); |
91 | } | 93 | } |
92 | int Receiver::checkFile( QString& file ) { | 94 | int Receiver::checkFile( QString& file ) { |
93 | int ret; | 95 | int ret; |
94 | QString ending; | 96 | QString ending; |
95 | 97 | ||
96 | if (file.right(4) == ".vcs" ) { | 98 | if (file.right(4) == ".vcs" ) { |
97 | ret = Datebook; | 99 | ret = Datebook; |
98 | ending = QString::fromLatin1(".vcs"); | 100 | ending = QString::fromLatin1(".vcs"); |
99 | }else if ( file.right(4) == ".vcf") { | 101 | }else if ( file.right(4) == ".vcf") { |
100 | ret = AddressBook; | 102 | ret = AddressBook; |
101 | ending = QString::fromLatin1(".vcf"); | 103 | ending = QString::fromLatin1(".vcf"); |
102 | }else | 104 | }else |
103 | ret = Other; | 105 | ret = Other; |
104 | 106 | ||
105 | 107 | ||
106 | if (ending.isEmpty() ) | 108 | if (ending.isEmpty() ) |
107 | return ret; | 109 | return ret; |
108 | 110 | ||
109 | /** | 111 | /** |
110 | * currently the parser is broken in regard of BASE64 encoding | 112 | * currently the parser is broken in regard of BASE64 encoding |
111 | * and M$ likes to send that. So we will executed a small | 113 | * and M$ likes to send that. So we will executed a small |
112 | * tidy up system sed script | 114 | * tidy up system sed script |
113 | * At this point we can also remove umlaute from the filename | 115 | * At this point we can also remove umlaute from the filename |
114 | */ | 116 | */ |
115 | tidyUp( file, ending ); | 117 | tidyUp( file, ending ); |
116 | 118 | ||
117 | return ret; | 119 | return ret; |
118 | } | 120 | } |
119 | 121 | ||
120 | /* TRANSLATOR OpieObex::OtherHandler */ | 122 | /* TRANSLATOR OpieObex::OtherHandler */ |
121 | 123 | ||
122 | OtherHandler::OtherHandler() | 124 | OtherHandler::OtherHandler() |
123 | : QVBox() | 125 | : QVBox() |
124 | { | 126 | { |
125 | QHBox* box = new QHBox(this); | 127 | QHBox* box = new QHBox(this); |
126 | QLabel* lbl = new QLabel(box); | 128 | QLabel* lbl = new QLabel(box); |
127 | lbl->setText(tr("<qt><b>Received:</b></qt>")); | 129 | lbl->setText(tr("<qt><b>Received:</b></qt>")); |
128 | m_na = new QLabel(box); | 130 | m_na = new QLabel(box); |
129 | 131 | ||
130 | QFrame* frame = new QFrame(this); | 132 | QFrame* frame = new QFrame(this); |
131 | frame->setFrameShape( QFrame::HLine ); | 133 | frame->setFrameShape( QFrame::HLine ); |
132 | frame->setFrameShadow( QFrame::Sunken ); | 134 | frame->setFrameShadow( QFrame::Sunken ); |
133 | 135 | ||
134 | m_view = new QTextView(this); | 136 | m_view = new QTextView(this); |
135 | 137 | ||
136 | box = new QHBox(this); | 138 | box = new QHBox(this); |
137 | QPushButton *but = new QPushButton(box); | 139 | QPushButton *but = new QPushButton(box); |
138 | but->setText(tr("Accept") ); | 140 | but->setText(tr("Accept") ); |
139 | connect(but, SIGNAL(clicked() ), | 141 | connect(but, SIGNAL(clicked() ), |
140 | this, SLOT(accept()) ); | 142 | this, SLOT(accept()) ); |
141 | 143 | ||
142 | but = new QPushButton(box); | 144 | but = new QPushButton(box); |
143 | but->setText(tr("Deny") ); | 145 | but->setText(tr("Deny") ); |
144 | connect(but, SIGNAL(clicked() ), | 146 | connect(but, SIGNAL(clicked() ), |
145 | this, SLOT(deny() ) ); | 147 | this, SLOT(deny() ) ); |
146 | 148 | ||
147 | raise(); | 149 | raise(); |
148 | showMaximized(); | 150 | showMaximized(); |
149 | } | 151 | } |
150 | OtherHandler::~OtherHandler() { | 152 | OtherHandler::~OtherHandler() { |
151 | 153 | ||
152 | } | 154 | } |
153 | void OtherHandler::handle( const QString& file ) { | 155 | void OtherHandler::handle( const QString& file ) { |
154 | m_file = file; | 156 | m_file = file; |
155 | m_na->setText(file); | 157 | m_na->setText(file); |
156 | DocLnk lnk(file); | 158 | DocLnk lnk(file); |
157 | 159 | ||
158 | QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); | 160 | QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); |
159 | m_view->setText( str ); | 161 | m_view->setText( str ); |
160 | } | 162 | } |
161 | 163 | ||
162 | /* | 164 | /* |
163 | * hehe evil evil mmap ahead :) | 165 | * hehe evil evil mmap ahead :) |
164 | * we quickly copy the file and then we'll create a DocLnk for it | 166 | * we quickly copy the file and then we'll create a DocLnk for it |
165 | */ | 167 | */ |
166 | void OtherHandler::accept() { | 168 | void OtherHandler::accept() { |
167 | QString na = targetName( m_file ); | 169 | QString na = targetName( m_file ); |
168 | copy(m_file, na ); | 170 | copy(m_file, na ); |
169 | DocLnk lnk(na); | 171 | DocLnk lnk(na); |
170 | lnk.writeLink(); | 172 | lnk.writeLink(); |
171 | QFile::remove(m_file); | 173 | QFile::remove(m_file); |
172 | delete this; | 174 | delete this; |
173 | } | 175 | } |
174 | void OtherHandler::deny() { | 176 | void OtherHandler::deny() { |
175 | QFile::remove( m_file ); | 177 | QFile::remove( m_file ); |
176 | delete this; | 178 | delete this; |
177 | } | 179 | } |
178 | QString OtherHandler::targetName( const QString& file ) { | 180 | QString OtherHandler::targetName( const QString& file ) { |
179 | QFileInfo info( file ); | 181 | QFileInfo info( file ); |
180 | 182 | ||
181 | /* $HOME needs to be set!!!! */ | 183 | /* $HOME needs to be set!!!! */ |
182 | Global::createDocDir(); | 184 | Global::createDocDir(); |
183 | 185 | ||
184 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); | 186 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); |
185 | QString newFileBase = newFile; | 187 | QString newFileBase = newFile; |
186 | 188 | ||
187 | int trie = 0; | 189 | int trie = 0; |
188 | while (QFile::exists(newFile + "."+info.extension() ) ) { | 190 | while (QFile::exists(newFile + "."+info.extension() ) ) { |
189 | newFile = newFileBase + "_"+QString::number(trie) ; | 191 | newFile = newFileBase + "_"+QString::number(trie) ; |
190 | trie++; | 192 | trie++; |
191 | } | 193 | } |
192 | newFile += "." + info.extension(); | 194 | newFile += "." + info.extension(); |
193 | 195 | ||
194 | return newFile; | 196 | return newFile; |
195 | } | 197 | } |
196 | 198 | ||
197 | /* fast cpy */ | 199 | /* fast cpy */ |
198 | void OtherHandler::copy(const QString& src, const QString& file) { | 200 | void OtherHandler::copy(const QString& src, const QString& file) { |
199 | FileManager *fm; | 201 | FileManager *fm; |
200 | if(!fm->copyFile(src,file)) { | 202 | if(!fm->copyFile(src,file)) { |
201 | owarn << "Copy failed" << oendl; | 203 | owarn << "Copy failed" << oendl; |
202 | } | 204 | } |
203 | } | 205 | } |