summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp8
-rw-r--r--core/applets/obex/libopieobex.control8
-rw-r--r--core/applets/obex/obex.pro32
-rw-r--r--core/applets/obex/obexdlg.ui279
-rw-r--r--core/applets/obex/obeximpl.cc150
-rw-r--r--core/applets/obex/obeximpl.h38
-rw-r--r--core/applets/obex/obexinc.ui230
-rwxr-xr-xcore/applets/obex/processwrapper.cc114
-rw-r--r--core/obex/config.in (renamed from core/applets/obex/config.in)0
-rw-r--r--core/obex/obex.cc (renamed from core/applets/obex/obex.cc)3
-rw-r--r--core/obex/obex.h (renamed from core/applets/obex/obex.h)3
-rw-r--r--core/obex/obexhandler.cpp65
-rw-r--r--core/obex/obexhandler.h39
-rw-r--r--core/obex/obeximpl.cpp28
-rw-r--r--core/obex/obeximpl.h22
-rw-r--r--core/obex/obexsend.cpp251
-rw-r--r--core/obex/obexsend.h99
-rw-r--r--core/obex/receiver.cpp166
-rw-r--r--core/obex/receiver.h55
19 files changed, 732 insertions, 858 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
index 84c656f..a5b4bfc 100644
--- a/core/applets/irdaapplet/irda.cpp
+++ b/core/applets/irdaapplet/irda.cpp
@@ -1,347 +1,347 @@
/**********************************************************************
** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org>
** Max Reiss <harlekin@handhelds.org> [trivial stuff]
** Robert Griebl <sandman@handhelds.org>
** Holger Freyther <zecke@handhelds.org> QCOP Interface
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include <qcopchannel_qws.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qpe/ir.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/sound.h>
#include <qpainter.h>
#include <qfile.h>
#include <qtimer.h>
#include <qtextstream.h>
#include <qpopupmenu.h>
#include <unistd.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include "irda.h"
//===========================================================================
IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
: QWidget ( parent, name )
{
setFixedHeight ( 18 );
setFixedWidth ( 14 );
m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP );
m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" );
m_irda_active = false;
m_irda_discovery_active = false;
m_receive_active = false;
m_receive_state_changed = false;
m_popup = 0;
m_wasOn = false;
QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this );
connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) );
}
void IrdaApplet::show()
{
QWidget::show ( );
startTimer ( 2000 );
}
IrdaApplet::~IrdaApplet()
{
if ( m_sockfd >= 0 )
::close ( m_sockfd );
}
void IrdaApplet::popup ( QString message, QString icon )
{
if ( !m_popup )
m_popup = new QPopupMenu ( this );
m_popup-> clear ( );
if ( icon. isEmpty ( ))
m_popup-> insertItem ( message, 0 );
else
m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 );
QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
QSize s = m_popup-> sizeHint ( );
m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
p. y ( ) - s. height ( )));
QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( )));
}
void IrdaApplet::popupTimeout ( )
{
m_popup-> hide ( );
}
bool IrdaApplet::checkIrdaStatus ( )
{
struct ifreq ifr;
strcpy ( ifr. ifr_name, "irda0" );
if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
return false;
return ( ifr. ifr_flags & IFF_UP );
}
bool IrdaApplet::setIrdaStatus ( bool b )
{
struct ifreq ifr;
strcpy ( ifr. ifr_name, "irda0" );
if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
return false;
if ( b ) {
ifr. ifr_flags |= IFF_UP;
}
else {
setIrdaDiscoveryStatus ( 0 );
setIrdaReceiveStatus ( 0 );
ifr. ifr_flags &= ~IFF_UP;
}
if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 )
return false;
return true;
}
bool IrdaApplet::checkIrdaDiscoveryStatus ( )
{
QFile discovery ( "/proc/sys/net/irda/discovery" );
QString streamIn = "0";
if ( discovery. open ( IO_ReadOnly )) {
QTextStream stream ( &discovery );
streamIn = stream. read ( );
}
return streamIn. toInt ( ) > 0;
}
bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
{
QFile discovery ( "/proc/sys/net/irda/discovery" );
if ( discovery. open ( IO_WriteOnly | IO_Raw )) {
discovery.putch ( d ? '1' : '0' );
return true;
}
return false;
}
bool IrdaApplet::setIrdaReceiveStatus ( bool d )
{
QCopEnvelope e ( "QPE/Obex", "receive(int)" );
e << ( d ? 1 : 0 );
m_receive_active = d;
m_receive_state_changed = true;
return true;
}
void IrdaApplet::showDiscovered ( )
{
- static Sound snd_found ( "irdaapplet/irdaon" );
- static Sound snd_lost ( "irdaapplet/irdaoff" );
+// static Sound snd_found ( "irdaapplet/irdaon" );
+// static Sound snd_lost ( "irdaapplet/irdaoff" );
QFile discovery ( "/proc/net/irda/discovery" );
if ( discovery. open ( IO_ReadOnly )) {
bool qcopsend = false;
QString discoveredDevice;
QString deviceAddr;
// since it is /proc we _must_ use QTextStream
QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( ));
QMap <QString, QString>::Iterator it;
for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
it. data ( ). prepend ( "+++" );
for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) {
const QString &line = *lit;
if ( line. startsWith ( "nickname:" )) {
discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 );
deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 );
// qDebug(discoveredDevice + "(" + deviceAddr + ")");
if ( !m_devices. contains ( deviceAddr )) {
popup ( tr( "Found:" ) + " " + discoveredDevice );
- snd_found. play ( );
+ //snd_found. play ( );
qcopsend = true;
}
m_devices. replace ( deviceAddr, discoveredDevice );
}
}
for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) {
// qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?");
if ( it. data ( ). left ( 3 ) == "+++" ) {
popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 ));
- snd_lost. play ( );
+ //snd_lost. play ( );
QMap <QString, QString>::Iterator tmp = it;
tmp++;
m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator
it = tmp;
qcopsend = true;
}
else
it++;
}
// XXX if( qcopsend ) {
QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" );
e << ( m_devices. count ( ) > 0 );
// }
}
}
void IrdaApplet::mousePressEvent ( QMouseEvent * )
{
QPopupMenu *menu = new QPopupMenu ( this );
QString cmd;
/* Refresh active state */
timerEvent ( 0 );
// menu->insertItem( tr("More..."), 4 );
if ( m_irda_active && !m_devices. isEmpty ( )) {
menu-> insertItem ( tr( "Discovered Device:" ), 9 );
for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
menu-> insertItem ( *it );
menu-> insertSeparator ( );
}
menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 );
if ( m_irda_active ) {
menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 );
menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 );
}
QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
QSize s = menu-> sizeHint ( );
p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ));
switch ( menu-> exec ( p )) {
case 0:
setIrdaStatus ( !m_irda_active );
timerEvent ( 0 );
break;
case 1:
setIrdaDiscoveryStatus ( !m_irda_discovery_active );
timerEvent ( 0 );
break;
case 2:
setIrdaReceiveStatus ( !m_receive_active );
timerEvent( 0 );
break;
}
delete menu;
}
void IrdaApplet::timerEvent ( QTimerEvent * )
{
bool oldactive = m_irda_active;
bool olddiscovery = m_irda_discovery_active;
bool receiveUpdate = false;
if ( m_receive_state_changed ) {
receiveUpdate = true;
m_receive_state_changed = false;
}
m_irda_active = checkIrdaStatus ( );
m_irda_discovery_active = checkIrdaDiscoveryStatus ( );
if ( m_irda_discovery_active )
showDiscovered ( );
if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
update ( );
}
void IrdaApplet::paintEvent ( QPaintEvent * )
{
QPainter p ( this );
p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap );
if ( m_irda_discovery_active )
p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap );
if ( m_receive_active )
p. drawPixmap( 0, 1, m_receiveActivePixmap );
}
/*
* We know 3 calls
* a) enable
* b) disable
* a and b will temp enable the IrDa device and disable will disable it again if it wasn't on
* c) listDevices: We will return a list of known devices
*/
void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) {
if ( str == "enableIrda()") {
m_wasOn = checkIrdaStatus();
if (!m_wasOn)
setIrdaStatus( true );
}else if ( str == "disableIrda()") {
if (!m_wasOn)
setIrdaStatus( false );
}else if ( str == "listDevices()") {
QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)");
QStringList list;
QMap<QString, QString>::Iterator it;
for (it = m_devices.begin(); it != m_devices.end(); ++it )
list << (*it);
e << list;
}
}
diff --git a/core/applets/obex/libopieobex.control b/core/applets/obex/libopieobex.control
deleted file mode 100644
index 3fd0f77..0000000
--- a/core/applets/obex/libopieobex.control
+++ b/dev/null
@@ -1,8 +0,0 @@
-Files: plugins/obex/libopieobex.so*
-Priority: optional
-Section: opie/system
-Maintainer: Holger Freyther <zecke@handhelds.org>
-Architecture: arm
-Version: $QPE_VERSION-$SUB_VERSION.1
-Depends: opie-base, openobex | libopenobex1
-Description: Irda obex lib
diff --git a/core/applets/obex/obex.pro b/core/applets/obex/obex.pro
deleted file mode 100644
index d7cc338..0000000
--- a/core/applets/obex/obex.pro
+++ b/dev/null
@@ -1,32 +0,0 @@
-TEMPLATE = lib
-CONFIG += qt warn_on release
-HEADERS = obex.h obeximpl.h
-SOURCES = obex.cc obeximpl.cc
-TARGET = opieobex
-DESTDIR = $(OPIEDIR)/plugins/obex
-INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher
-DEPENDPATH += ../$(OPIEDIR)/include
-INTERFACES = obexinc.ui obexdlg.ui
-LIBS += -lqpe -lopie
-VERSION = 0.0.1
-
-TRANSLATIONS = ../../../i18n/de/libopieobex.ts \
- ../../../i18n/da/libopieobex.ts \
- ../../../i18n/xx/libopieobex.ts \
- ../../../i18n/en/libopieobex.ts \
- ../../../i18n/es/libopieobex.ts \
- ../../../i18n/fr/libopieobex.ts \
- ../../../i18n/hu/libopieobex.ts \
- ../../../i18n/ja/libopieobex.ts \
- ../../../i18n/ko/libopieobex.ts \
- ../../../i18n/no/libopieobex.ts \
- ../../../i18n/pl/libopieobex.ts \
- ../../../i18n/pt/libopieobex.ts \
- ../../../i18n/pt_BR/libopieobex.ts \
- ../../../i18n/sl/libopieobex.ts \
- ../../../i18n/zh_CN/libopieobex.ts \
- ../../../i18n/zh_TW/libopieobex.ts
-
-
-
-include ( $(OPIEDIR)/include.pro )
diff --git a/core/applets/obex/obexdlg.ui b/core/applets/obex/obexdlg.ui
deleted file mode 100644
index b367ffd..0000000
--- a/core/applets/obex/obexdlg.ui
+++ b/dev/null
@@ -1,279 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>ObexDlg</class>
-<author>me</author>
-<widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Form1</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>0</y>
- <width>204</width>
- <height>246</height>
- </rect>
- </property>
- <property stdset="1">
- <name>caption</name>
- <string>OBEX Sending</string>
- </property>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout5</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>60</y>
- <width>200</width>
- <height>70</height>
- </rect>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Sending:</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer6</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Fixed</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>lblPath</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>filename</string>
- </property>
- <property stdset="1">
- <name>textFormat</name>
- <enum>RichText</enum>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>AlignTop|AlignLeft</set>
- </property>
- <property>
- <name>hAlign</name>
- </property>
- <property>
- <name>vAlign</name>
- </property>
- </widget>
- </vbox>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer7</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer8</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout6</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>20</x>
- <y>170</y>
- <width>170</width>
- <height>34</height>
- </rect>
- </property>
- <hbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer9</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PushButton2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>&amp;Cancel</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer10</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </hbox>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer11</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer18</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
-</widget>
-<connections>
- <connection>
- <sender>PushButton2</sender>
- <signal>clicked()</signal>
- <receiver>Form1</receiver>
- <slot>slotCancel()</slot>
- </connection>
- <slot access="public">slotCancel()</slot>
-</connections>
-</UI>
diff --git a/core/applets/obex/obeximpl.cc b/core/applets/obex/obeximpl.cc
deleted file mode 100644
index 88f2d44..0000000
--- a/core/applets/obex/obeximpl.cc
+++ b/dev/null
@@ -1,150 +0,0 @@
-
-#include <qdatastream.h>
-#include <qmessagebox.h>
-
-
-#include <qpe/qcom.h>
-#include <qpe/applnk.h>
-
-#include <qlabel.h>
-
-#include "obex.h"
-#include "obeximpl.h"
-
-
-
-using namespace OpieObex;
-
-ObexImpl::ObexImpl( )
- : QObject() {
- // register to a channel
- qWarning( "c'tor" );
- m_obex = new Obex(this, "obex");
- m_sendgui = new ObexDlg();
- m_recvgui = new ObexInc();
- m_chan = new QCopChannel("QPE/Obex" );
- connect(m_chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
- this, SLOT(slotMessage(const QCString&, const QByteArray&) ) );
- connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
- this, SLOT(slotReceivedFile(const QString& ) ) );
- connect((QObject*) m_recvgui->InsertButton, SIGNAL(clicked()),
- m_recvgui, SLOT( accept() ));
- connect((QObject*) m_recvgui->RejectButton, SIGNAL(clicked()),
- m_recvgui, SLOT( reject() ));
-}
-
-ObexImpl::~ObexImpl() {
- delete m_obex;
- delete m_chan;
- delete m_sendgui;
- delete m_recvgui;
-}
-
-QRESULT ObexImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
- *iface = 0;
- if( uuid == IID_QUnknown )
- *iface = this;
- else if( uuid == IID_ObexInterface )
- *iface = this;
-
- qWarning("query" );
- if(*iface )
- (*iface)->addRef();
- return QS_OK;
-}
-
-void ObexImpl::slotMessage( const QCString& msg, const QByteArray&data ) {
- QDataStream stream( data, IO_ReadOnly );
- qWarning("Message %s", msg.data() );
- if(msg == "send(QString,QString,QString)" ) {
- QString desc;
- stream >> desc;
- stream >> m_name;
- m_sendgui->raise(); // should be on top
- m_sendgui->showMaximized();
- m_sendgui->lblPath->setText(m_name);
- connect( (QObject*)m_sendgui->PushButton2, SIGNAL(clicked()),
- this, SLOT(slotCancelSend()));
- m_obex->send(m_name );
- connect( (QObject*)m_obex, SIGNAL( sent() ), this,
- SLOT( slotSent() ) );
- connect( (QObject*)m_obex, SIGNAL( error(int) ), this,
- SLOT( slotSent() ) );
- }else if(msg == "receive(int)" ) { // open a GUI
- //m_recvgui->showMaximized();
- int receiveD = 0;
- stream >> receiveD;
- if ( receiveD == 1)
- m_obex->receive();
- else
- m_obex->setReceiveEnabled( false );
-
- } else if (msg =="done(QString)") {
- QString text;
- stream >> text;
- m_sendgui->lblPath->setText(tr("Done transfering " + text));
-
- }
-}
-
-void ObexImpl::slotCancelSend() {
- // cancel sync process too
- //m_obex->cancel(); // not ready yet
- m_sendgui->hide();
-}
-
-void ObexImpl::slotDone(bool) {
- QCopEnvelope e ("QPE/Obex", "done(QString)" ); //but this into a slot
- e << m_name;
-}
-
-void ObexImpl::slotSent() {
- m_sendgui->lblPath->setText("Done!");
- m_sendgui->hide();
-}
-
-void ObexImpl::slotError( int errorCode) {
-
- QString errorString = "";
- if (errorCode == -1) {
- errorString = "test";
- }
- qDebug("Error: " + errorString);
- m_sendgui->hide();
-}
-
-// Received a file via beam
-// check for mime type and then either
-// add to App via setDocument
-void ObexImpl::slotReceivedFile( const QString &fileName ) {
- qWarning("filename %s", fileName.latin1() );
- DocLnk lnk( fileName );
- QString exec = lnk.exec();
- qWarning("executing %s", exec.latin1() );
- if ( exec.isEmpty() || exec == "" ) {
- qWarning("empty");
- if ( fileName.right(4) == ".vcf" )
- exec = "addressbook";
- else if ( fileName.right(4) == ".vcs" ) {
- exec = "datebook";
- }
- } // now prompt and then add it
-
- m_recvgui->PixmapLabel->setPixmap( lnk.pixmap() );
- m_recvgui->AppLabel->setText( "<b>" + exec + "<b>" );
- m_recvgui->FileLabel->setText( lnk.name() );
- // m_recvgui->showMaximized();
- // if( m_recvgui->exec() == 0 ) {
- QCString str= "QPE/Application/";
- str += exec.latin1();
- qWarning("channel %s", str.data() );
- QCopEnvelope e(str , "setDocument(QString)" );
- e << fileName;
- //}
-}
-
-
-
-Q_EXPORT_INTERFACE() {
- Q_CREATE_INSTANCE( ObexImpl )
-}
diff --git a/core/applets/obex/obeximpl.h b/core/applets/obex/obeximpl.h
deleted file mode 100644
index 78d5b25..0000000
--- a/core/applets/obex/obeximpl.h
+++ b/dev/null
@@ -1,38 +0,0 @@
-
-#ifndef OpieObexImpl_H
-#define OpieObexImpl_H
-
-#include <qobject.h>
-#include <obexinterface.h>
-#include "obexdlg.h"
-#include "obexinc.h"
-#include <qpe/qcopenvelope_qws.h>
-
-namespace OpieObex {
- class Obex;
- class ObexImpl : public QObject, public ObexInterface {
- Q_OBJECT
- public:
- ObexImpl();
- virtual ~ObexImpl();
- QRESULT queryInterface( const QUuid&, QUnknownInterface** );
- Q_REFCOUNT // for reference counting (macro )
- private:
- ulong ref;
- Obex* m_obex; // obex lib
- QCopChannel *m_chan;
- ObexDlg *m_sendgui;
- ObexInc *m_recvgui;
- QString m_name;
- private slots:
- void slotCancelSend();
- void slotMessage( const QCString&, const QByteArray& );
- void slotError(int );
- // void slotCurrentTry( unsigned int ); */
- void slotDone(bool);
- void slotReceivedFile(const QString & );
- void slotSent();
-
- };
-};
-#endif
diff --git a/core/applets/obex/obexinc.ui b/core/applets/obex/obexinc.ui
deleted file mode 100644
index 4cc8056..0000000
--- a/core/applets/obex/obexinc.ui
+++ b/dev/null
@@ -1,230 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>ObexInc</class>
-<widget>
- <class>QDialog</class>
- <property stdset="1">
- <name>name</name>
- <cstring>ObexInc</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>0</y>
- <width>208</width>
- <height>248</height>
- </rect>
- </property>
- <property stdset="1">
- <name>caption</name>
- <string>OBEX Receiving</string>
- </property>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout5</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>90</x>
- <y>100</y>
- <width>79</width>
- <height>68</height>
- </rect>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>AppLabel</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>TextLabel1</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>FileLabel</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Filename</string>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>AlignTop|AlignLeft</set>
- </property>
- <property>
- <name>vAlign</name>
- </property>
- </widget>
- </vbox>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>30</x>
- <y>30</y>
- <width>161</width>
- <height>41</height>
- </rect>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>A file was beamed
-to you.</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PixmapLabel</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>30</x>
- <y>100</y>
- <width>40</width>
- <height>40</height>
- </rect>
- </property>
- <property stdset="1">
- <name>scaledContents</name>
- <bool>true</bool>
- </property>
- </widget>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout4</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>210</y>
- <width>246</width>
- <height>33</height>
- </rect>
- </property>
- <hbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer9</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>InsertButton</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Insert</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer11</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>RejectButton</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Reject</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer10</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </hbox>
- </widget>
-</widget>
-</UI>
diff --git a/core/applets/obex/processwrapper.cc b/core/applets/obex/processwrapper.cc
deleted file mode 100755
index ebc7794..0000000
--- a/core/applets/obex/processwrapper.cc
+++ b/dev/null
@@ -1,114 +0,0 @@
-//
-m_rec == KProcess
-m_count = int // the number of tries to recieve
-m_send == KProcess
-m_file == QString filename to send
-m_outp == the output of the process
-
-//
-
-
-void receive() {
- m_rec = new KProcess();
- *m_rec << "irobex_palm3";
- // connect to the necessary slots
- connect(m_rec, SIGNAL(processExited(KProcess*) ),
- this, SLOT(slotExited(KProcess*) ) );
-
- connect(m_rec, SIGNAL(receivedStdout(KProcess*, char*, int ) ),
- this, SLOT(slotStdOut(KProcess*, char*, int) ) );
-
- if(!m_rec->start(KProcess::NotifyOnExit, KProcess::AllOutput) ) {
- qWarning("could not start :(");
- emit done( false );
- }
- emit try(m_count )
-}
-void send(const QString &fileName) {
- m_count = 0;
- m_file = fileName;
- sendNow();
-}
-void sendNow() {
- if ( m_count >= 15 ) { // could not send
- emit error(-1 );
- }
- // KProcess inititialisation
- m_send = new KProcess();
- m_send << "irobex_palm3";
- m_send << m_file;
-
- // connect to slots Exited and and StdOut
- connect(m_send, SIGNAL(processExited(KProcess*) ),
- this, SLOT(slotExited(KProcess*)) );
- connect(m_send, SIGNAL(receivedStdout(KProcess*, char*, int ) )
- this, SLOT(slotStdOut(KProcess*, char*, int) ) );
- // now start it
- if (!m_send->start(/*KProcess::NotifyOnExit, KProcess::AllOutput*/ ) ) {
- m_count = 15;
- emit error(-1 );
- }
- // end
- m_count++;
- emit try( m_count );
-}
-
-void recieved() {
- if (m_rec->normalExit() ) {
- if ( m_rec->exitStatus() == 0 ) { // we got one
- QString filename = parseOut();
- emit recievedFile( filename );
- }
- }else{
- emit error(-1);
- };
- delete m_rec;
-}
-
-
-void slotExited(KProcess* proc) {
- if (proc == m_rec ) { // recieve process
- recieved();
- }else if ( proc == m_send ) {
- send();
- }
-}
-
-
-void send() {
- if (m_send->normalExit() ) {
- if ( m_send->exitStatus() == 0 ) {
- delete m_send;
- m_send=0;
- emit sent();
- }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
- // let's try it again
- delete m_send;
- m_send = 0;
- sendNow();
- }
- }else {
- emit error( -1 );
- delete m_send;
- m_send = 0;
- }
-
-}
-void parseOut() {
- QStringList list = QStringList::split("\n", m_outp);
- QStringList::Iterator it;
- for (it = list.begin(); it != list.end(); ++it ) {
- if ( (*it).startsWith("Wrote" ) ) {
- QStringList pathes = QStringList::split(' ', (*it) );
- QString path = pathes[1];
- }
- }
-}
-
-void slotStdOut(KProcess* proc, char* buf, int len) {
- if ( proc == m_rec ) { // only recieve
- QCString cstring( buf, len );
- m_outp.append( cstring.data() );
- }
-
-}
diff --git a/core/applets/obex/config.in b/core/obex/config.in
index 4d1f43d..4d1f43d 100644
--- a/core/applets/obex/config.in
+++ b/core/obex/config.in
diff --git a/core/applets/obex/obex.cc b/core/obex/obex.cc
index 43041f5..83d1faf 100644
--- a/core/applets/obex/obex.cc
+++ b/core/obex/obex.cc
@@ -1,194 +1,195 @@
#include <qapplication.h>
#include <qmessagebox.h>
#include <qpe/qcopenvelope_qws.h>
#include <opie/oprocess.h>
#include "obex.h"
using namespace OpieObex;
Obex::Obex( QObject *parent, const char* name )
: QObject(parent, name )
{
m_rec = 0;
m_send=0;
m_count = 0;
m_receive = false;
connect( this, SIGNAL(error(int) ), // for recovering to receive
SLOT(slotError() ) );
connect( this, SIGNAL(sent() ),
SLOT(slotError() ) );
};
Obex::~Obex() {
delete m_rec;
delete m_send;
}
void Obex::receive() {
m_receive = true;
m_outp = QString::null;
qWarning("Receive" );
m_rec = new OProcess();
*m_rec << "irobex_palm3";
// connect to the necessary slots
connect(m_rec, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotExited(OProcess*) ) );
connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotStdOut(OProcess*, char*, int) ) );
if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start :(");
emit done( false );
delete m_rec;
m_rec = 0;
}
// emit currentTry(m_count );
}
void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
m_count = 0;
m_file = fileName;
qWarning("send");
if (m_rec != 0 ) {
qWarning("running");
if (m_rec->isRunning() ) {
emit error(-1 );
qWarning("is running");
delete m_rec;
m_rec = 0;
}else{
qWarning("is not running");
emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
return;
}
}
sendNow();
}
void Obex::sendNow(){
qWarning("sendNow");
if ( m_count >= 25 ) { // could not send
emit error(-1 );
+ emit sent(false);
return;
}
// OProcess inititialisation
m_send = new OProcess();
*m_send << "irobex_palm3";
*m_send << m_file;
// connect to slots Exited and and StdOut
connect(m_send, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotExited(OProcess*)) );
connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )),
this, SLOT(slotStdOut(OProcess*, char*, int) ) );
// now start it
if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
qWarning("could not send" );
m_count = 25;
emit error(-1 );
delete m_send;
m_send=0;
}
// end
m_count++;
emit currentTry( m_count );
}
void Obex::slotExited(OProcess* proc ){
if (proc == m_rec ) { // receive process
received();
}else if ( proc == m_send ) {
sendEnd();
}
}
void Obex::slotStdOut(OProcess* proc, char* buf, int len){
if ( proc == m_rec ) { // only receive
QCString cstring( buf, len );
m_outp.append( cstring.data() );
}
}
void Obex::received() {
if (m_rec->normalExit() ) {
if ( m_rec->exitStatus() == 0 ) { // we got one
QString filename = parseOut();
qWarning("ACHTUNG");
emit receivedFile( filename );
}
}else{
emit done(false);
};
delete m_rec;
m_rec = 0;
receive();
}
void Obex::sendEnd() {
if (m_send->normalExit() ) {
if ( m_send->exitStatus() == 0 ) {
delete m_send;
m_send=0;
qWarning("done" );
- emit sent();
+ emit sent(true);
}else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
// let's try it again
delete m_send;
m_send = 0;
qWarning("try sending again" );
sendNow();
}
}else {
emit error( -1 );
delete m_send;
m_send = 0;
}
}
QString Obex::parseOut( ){
QString path;
QStringList list = QStringList::split("\n", m_outp);
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
if ( (*it).startsWith("Wrote" ) ) {
int pos = (*it).findRev('(' );
if ( pos > 0 ) {
qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ;
qWarning("%d %d", (*it).length(), (*it).length()-pos );
path = (*it).remove( pos, (*it).length() - pos );
qWarning("%s", path.latin1() );
path = path.mid(6 );
path = path.stripWhiteSpace();
qWarning("path %s", path.latin1() );
}
}
}
return path;
}
/**
* when sent is done slotError is called we will start receive again
*/
void Obex::slotError() {
qWarning("slotError");
if ( m_receive )
receive();
};
void Obex::setReceiveEnabled( bool receive ) {
if ( !receive ) { //
m_receive = false;
shutDownReceive();
}
}
void Obex::shutDownReceive() {
if (m_rec != 0 ) {
qWarning("running");
if (m_rec->isRunning() ) {
emit error(-1 );
qWarning("is running");
delete m_rec;
m_rec = 0;
}
}
}
diff --git a/core/applets/obex/obex.h b/core/obex/obex.h
index 781fca2..60f5d28 100644
--- a/core/applets/obex/obex.h
+++ b/core/obex/obex.h
@@ -1,85 +1,84 @@
#ifndef OpieObex_H
#define OpieObex_H
#include <qobject.h>
class OProcess;
class QCopChannel;
namespace OpieObex {
class Obex : public QObject {
Q_OBJECT
public:
/**
* Obex c'tor look
*/
Obex( QObject *parent, const char* name);
/**
* d'tor
*/
~Obex();
/**
* Starting listening to irda after enabled by the applet
* a signal gets emitted when recieved a file
*/
void receive();
void send( const QString& );
void setReceiveEnabled( bool = false );
signals:
/**
* a signal
* @param path The path to the recieved file
*/
void receivedFile( const QString& path);
/**
* error signal if the program couldn't be started or the
* the connection timed out
*/
void error( int );
/**
* The current try to receive data
*/
void currentTry(unsigned int);
/**
* signal sent The file got beamed to the remote location
*/
- void sent();
- // private slots
+ void sent(bool);
void done(bool);
private:
uint m_count;
QString m_file;
QString m_outp;
OProcess *m_send;
OProcess *m_rec;
bool m_receive : 1;
void shutDownReceive();
private slots:
/**
* send over palm obex
*/
//void send(const QString&);
// the process exited
void slotExited(OProcess* proc) ;
void slotStdOut(OProcess*, char*, int);
void slotError();
private:
void sendNow();
QString parseOut();
void received();
void sendEnd();
};
};
#endif
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp
new file mode 100644
index 0000000..f71a233
--- a/dev/null
+++ b/core/obex/obexhandler.cpp
@@ -0,0 +1,65 @@
+#include <qcopchannel_qws.h>
+
+#include <qpe/qcopenvelope_qws.h>
+
+#include "obexsend.h"
+#include "receiver.h"
+#include "obexhandler.h"
+
+using namespace OpieObex;
+
+ObexHandler::ObexHandler() {
+ m_wasRec = false;
+ m_sender = 0l;
+ m_receiver = 0l;
+ QCopChannel* chan = new QCopChannel("QPE/Obex");
+ connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
+ this, SLOT(irdaMessage(const QCString&, const QByteArray& ) ) );
+}
+ObexHandler::~ObexHandler() {
+ delete m_sender;
+ delete m_receiver;
+}
+void ObexHandler::doSend(const QString& str, const QString& desc) {
+ delete m_sender;
+ m_sender = new SendWidget;
+ m_sender->raise();
+ m_sender->showMaximized();
+ connect(m_sender, SIGNAL(done() ),
+ this, SLOT(slotSent() ) );
+ m_sender->send( str, desc );
+}
+void ObexHandler::doReceive(bool b) {
+ if (m_receiver && b ) return; // we should enable receiver and it is on
+ else if (!m_receiver && !b ) return; // we should disbale receiver and it is off
+ else if (m_receiver && !b ) {
+ delete m_receiver;
+ m_receiver=0;
+ }else if (!m_receiver && b ) {
+ m_receiver= new Receiver;
+ }
+}
+void ObexHandler::slotSent() {
+ QString file = m_sender->file();
+ delete m_sender;
+ m_sender = 0;
+ QCopEnvelope e ("QPE/Obex", "done(QString)" );
+ e << file;
+ doReceive(m_wasRec );
+ m_wasRec = false;
+}
+void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) {
+ QDataStream stream( data, IO_ReadOnly );
+ if ( msg == "send(QString,QString,QString)" ) {
+ QString name, desc;
+ stream >> name;
+ stream >> desc;
+ m_wasRec = (m_receiver != 0 );
+ doReceive( false );
+ doSend(name, desc);
+ }else if (msg == "receive(int)") {
+ int rec;
+ stream >> rec;
+ doReceive(rec);
+ }
+}
diff --git a/core/obex/obexhandler.h b/core/obex/obexhandler.h
new file mode 100644
index 0000000..230c4f0
--- a/dev/null
+++ b/core/obex/obexhandler.h
@@ -0,0 +1,39 @@
+#ifndef OPIE_OBEX_HANDLER_H
+#define OPIE_OBEX_HANDLER_H
+
+#include <qobject.h>
+#include <qstring.h>
+
+namespace OpieObex {
+ /*
+ * The handler is responsible for handling receiving
+ * and sending
+ * It will connect to the IrDa QCOP channel and then
+ * wait for activation...
+ */
+ class SendWidget;
+ class Receiver;
+ class ObexHandler : public QObject {
+ Q_OBJECT
+ public:
+ ObexHandler();
+ ~ObexHandler();
+
+ private slots:
+ void doSend(const QString&,const QString& );
+ void doReceive(bool b);
+ void slotSent();
+
+ private slots: // QCOP message
+ void irdaMessage( const QCString&, const QByteArray& );
+
+ private:
+ SendWidget* m_sender;
+ Receiver* m_receiver;
+ bool m_wasRec : 1;
+
+ };
+}
+
+
+#endif
diff --git a/core/obex/obeximpl.cpp b/core/obex/obeximpl.cpp
new file mode 100644
index 0000000..12a078f
--- a/dev/null
+++ b/core/obex/obeximpl.cpp
@@ -0,0 +1,28 @@
+#include "obexhandler.h"
+#include "obeximpl.h"
+
+using namespace OpieObex;
+
+ObexImpl::ObexImpl() {
+ m_handler = new ObexHandler;
+}
+ObexImpl::~ObexImpl() {
+ delete m_handler;
+}
+QRESULT ObexImpl::queryInterface( const QUuid& uuid, QUnknownInterface **iface ) {
+ *iface = 0;
+ if ( uuid == IID_QUnknown ) {
+ *iface = this;
+ }else if ( uuid == IID_ObexInterface )
+ *iface = this;
+
+ if (*iface)
+ (*iface)->addRef();
+
+ return QS_OK;
+}
+
+
+Q_EXPORT_INTERFACE() {
+ Q_CREATE_INSTANCE( ObexImpl )
+}
diff --git a/core/obex/obeximpl.h b/core/obex/obeximpl.h
new file mode 100644
index 0000000..604eb8f
--- a/dev/null
+++ b/core/obex/obeximpl.h
@@ -0,0 +1,22 @@
+#ifndef OPIE_OBEX_IMPL_QUERY_H
+#define OPIE_OBEX_IMPL_QUERY_H
+
+#include <obexinterface.h>
+
+namespace OpieObex {
+ class ObexHandler;
+ class ObexImpl : public ObexInterface {
+ public:
+ ObexImpl();
+ virtual ~ObexImpl();
+ QRESULT queryInterface( const QUuid&, QUnknownInterface** );
+ Q_REFCOUNT
+
+ private:
+ ulong ref;
+ ObexHandler *m_handler;
+
+ };
+};
+
+#endif
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
new file mode 100644
index 0000000..a2e4c16
--- a/dev/null
+++ b/core/obex/obexsend.cpp
@@ -0,0 +1,251 @@
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qhbox.h>
+#include <qlayout.h>
+#include <qtimer.h>
+
+#include <qcopchannel_qws.h>
+
+#include <qpe/resource.h>
+#include <qpe/qcopenvelope_qws.h>
+
+#include "obex.h"
+#include "obexsend.h"
+
+using namespace OpieObex;
+
+
+SendWidget::SendWidget( QWidget* parent, const char* name )
+ : QWidget( parent, name ) {
+ initUI();
+}
+SendWidget::~SendWidget() {
+}
+void SendWidget::initUI() {
+ m_obex = new Obex(this, "obex");
+ connect(m_obex, SIGNAL(error(int) ),
+ this, SLOT(slotIrError(int) ) );
+ connect(m_obex, SIGNAL(sent(bool) ),
+ this, SLOT(slotIrSent(bool) ) );
+ connect(m_obex, SIGNAL(currentTry(unsigned int ) ),
+ this, SLOT(slotIrTry(unsigned int ) ) );
+
+ QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
+ connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
+ this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) );
+
+ chan = new QCopChannel("QPE/BluetoothBack", this );
+ connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
+ this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) );
+
+ QVBoxLayout* lay = new QVBoxLayout(this);
+
+ QHBox* nameBox = new QHBox(this);
+ QLabel* name = new QLabel(nameBox);
+ name->setText( tr("<qt><h1>Sending:</h1></qt>") );
+ name->setAlignment( AlignLeft | AlignTop );
+ m_lblFile = new QLabel(nameBox);
+ lay->addWidget(nameBox, 0);
+
+ QFrame* frame = new QFrame(this);
+ frame->setFrameShape( QFrame::HLine );
+ frame->setFrameShadow( QFrame::Sunken );
+ lay->addWidget(frame, 10);
+
+ QLabel* devices = new QLabel(this);
+ devices->setText("<qt><b>Devices:</b></qt>");
+ devices->setAlignment( AlignLeft | AlignTop );
+ lay->addWidget( devices,10 );
+
+ m_devBox = new DeviceBox(this);
+ lay->addWidget( m_devBox, 50 );
+ connect(m_devBox, SIGNAL(selectedDevice(const QString&, int ) ),
+ this, SLOT(slotSelectedDevice(const QString&, int) ) );
+
+ QPushButton *but = new QPushButton(this);
+ but->setText(tr("Done") );
+ connect(but, SIGNAL(clicked() ),
+ this, SLOT(slotDone() ) );
+
+ lay->addWidget( but );
+ m_lay = lay;
+
+ // QT does not like if you add items to an layout which already exits....
+ // and was layouted invalidate() does not help too
+ // so we use RichText....
+}
+
+/*
+ * in send we'll first set everything up
+ * and then wait for a list of devices.
+ */
+void SendWidget::send( const QString& file, const QString& desc ) {
+ m_file = file;
+ m_irDa.clear();
+ m_start = 0;
+ m_lblFile->setText(desc.isEmpty() ? file : desc );
+
+ if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) {
+ m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error );
+ m_start++;
+ }else
+ m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search );
+
+ if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
+ m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error );
+ m_start++;
+ }else
+ m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search );
+
+ if (m_start != 2 ) {
+ QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
+ QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
+ QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
+ QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
+ }
+ QTimer::singleShot(5000, this, SLOT(testIt() ) );
+}
+void SendWidget::slotIrDaDevices( const QStringList& list) {
+ m_irDa = list;
+ m_start = 0;
+ for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
+ m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
+ m_devBox->removeDevice( tr("Search for IrDa Devices.") );
+
+ slotStartIrda();
+}
+void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
+ m_bt = str;
+ for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
+ m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
+ }
+ m_devBox->removeDevice( tr("Searching for bluetooth Devices.") );
+}
+void SendWidget::slotSelectedDevice( const QString& name, int dev ) {
+ qWarning("Start beam? %s %d", name.latin1(), dev );
+ if ( name == tr("Search again for IrDa.") ) {
+ for (QStringList::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
+ m_devBox->removeDevice( (*it) );
+ QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
+ }
+}
+void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
+ qWarning("dispatch irda %s", str.data() );
+ if ( str == "listDevices(QStringList)" ) {
+ QDataStream stream( ar, IO_ReadOnly );
+ QStringList list;
+ stream >> list;
+ slotIrDaDevices( list );
+ }
+}
+void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
+
+}
+void SendWidget::slotIrError( int ) {
+
+}
+void SendWidget::slotIrSent( bool b) {
+ QString text = b ? tr("Sent") : tr("Failure");
+ m_devBox->setStatus( m_irDa[m_start], text );
+ m_start++;
+ slotStartIrda();
+}
+void SendWidget::slotIrTry(unsigned int trI) {
+ m_devBox->setStatus( m_irDa[m_start], tr("Try %1").arg( QString::number( trI ) ) );
+}
+void SendWidget::slotStartIrda() {
+ if (m_start >= m_irDa.count() ) {
+ m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
+ return;
+ }
+ m_devBox->setStatus( m_irDa[m_start], tr("Start sending") );
+ m_obex->send( m_file );
+}
+void SendWidget::slotDone() {
+ QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
+ QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
+ emit done();
+}
+QString SendWidget::file()const {
+ return m_file;
+}
+DeviceBox::DeviceBox( QWidget* parent )
+ : QTextBrowser( parent ) {
+
+}
+DeviceBox::~DeviceBox() {
+
+}
+void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) {
+ QString tex;
+ DeviceItem item( name, status, dev );
+ m_dev.insert( name, item );
+ tex = item.toString();
+ m_devices.prepend(tex);
+ setText( text()+ "<br>"+tex );
+}
+void DeviceBox::removeDevice( const QString& name ) {
+ if (!m_dev.contains(name) ) return;
+ m_devices.remove( m_dev[name].toString() );
+
+ m_dev.remove(name);
+ setText( m_devices.join("<br>") );
+
+}
+void DeviceBox::setStatus( const QString& name, const QString& status ) {
+ if ( !m_dev.contains(name) ) return;
+ DeviceItem dev = m_dev[name];
+ QString ole = dev.toString();
+ dev.setStatus( status );
+ int index = m_devices.findIndex( ole );
+ m_devices[index] = dev.toString();
+ setText( m_devices.join("<br>") );
+}
+void DeviceBox::setSource( const QString& str ) {
+ qWarning("SetSource:%s", str.latin1() );
+ emit selectedDevice( str, m_dev[str].device() );
+}
+
+
+DeviceItem::DeviceItem( const QString& name,
+ const QString& status, int dev)
+{
+ m_name = name;
+ m_status = status;
+ m_dev = dev;
+}
+QString DeviceItem::name()const {
+ return m_name;
+}
+QString DeviceItem::status()const {
+ return m_status;
+}
+int DeviceItem::device()const {
+ return m_dev;
+}
+QString DeviceItem::pixmap()const{
+ QString str;
+ switch(m_dev) {
+ case DeviceBox::IrDa:
+ str ="obex/irda";
+ break;
+ case DeviceBox::BT:
+ str ="obex/bt";
+ break;
+ case DeviceBox::Search:
+ str = "obex/search";
+ break;
+ case DeviceBox::Error:
+ str = "editdelete";
+ break;
+ };
+ return str;
+}
+DeviceItem::~DeviceItem() {
+}
+void DeviceItem::setStatus(const QString& status ) {
+ m_status = status;
+}
+QString DeviceItem::toString()const {
+ return "<p><a href=\""+m_name +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ;
+}
diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h
new file mode 100644
index 0000000..fd819bc
--- a/dev/null
+++ b/core/obex/obexsend.h
@@ -0,0 +1,99 @@
+#ifndef OPIE_OBEX_SEND_WIDGET_H
+#define OPIE_OBEX_SEND_WIDGET_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qwidget.h>
+#include <qvbox.h>
+#include <qmap.h>
+#include <qtextbrowser.h>
+
+class QLabel;
+class QVBoxLayout;
+/**
+ * This is the new sending widget for Obex
+ * It will attemp to smart and be able to send
+ * it to multiple devices.
+ * It'll support BT + IrDa
+ */
+namespace OpieObex {
+ class DeviceBox;
+ class Obex;
+ class SendWidget : public QWidget{
+ Q_OBJECT
+ public:
+ SendWidget( QWidget* parent = 0, const char* name = 0);
+ ~SendWidget();
+
+ QString file()const;
+
+ public slots:
+ void send( const QString& file, const QString& desc );
+
+ signals:
+ void done();
+
+ private slots: // QCOP slots
+ /* IrDa Names*/
+ void slotIrDaDevices( const QStringList& );
+ /* Bt Names + BD-Addr */
+ void slotBTDevices( const QMap<QString, QString>& );
+ void slotSelectedDevice( const QString& name, int dev );
+ void dispatchIrda( const QCString& str, const QByteArray& ar );
+ void dispatchBt( const QCString& str, const QByteArray& ar );
+
+ void slotIrError( int );
+ void slotIrSent(bool);
+ void slotIrTry(unsigned int );
+ void slotStartIrda();
+ void slotDone();
+ private:
+ void initUI();
+ QLabel* m_lblFile;
+ DeviceBox* m_devBox;
+ QVBoxLayout* m_lay;
+ int m_start;
+ QStringList m_irDa;
+ QMap<QString, QString> m_bt;
+ QString m_file;
+ Obex* m_obex;
+ };
+ class DeviceItem {
+ public:
+ DeviceItem( const QString& name = QString::null,
+ const QString& status = QString::null, int dev = 3);
+ ~DeviceItem();
+ void setStatus( const QString& text );
+
+ QString name()const;
+ QString status()const;
+ QString pixmap()const;
+ int device()const;
+ QString toString()const;
+ private:
+ QString m_name;
+ QString m_status;
+ int m_dev;
+ };
+ class DeviceBox : public QTextBrowser {
+ Q_OBJECT
+ public:
+ enum Device { IrDa, BT, Search, Error };
+ DeviceBox( QWidget* parent );
+ ~DeviceBox();
+
+ void setSource( const QString& str );
+ void addDevice( const QString& name, int dev,
+ const QString& status = QString::null );
+ void removeDevice( const QString& name );
+ void setStatus( const QString& name, const QString& );
+ signals:
+ void selectedDevice( const QString& name, int dev );
+ private:
+ QMap<QString, DeviceItem> m_dev;
+ QStringList m_devices;
+
+ };
+}
+
+#endif
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
new file mode 100644
index 0000000..50ee6cb
--- a/dev/null
+++ b/core/obex/receiver.cpp
@@ -0,0 +1,166 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include <fcntl.h>
+
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qlabel.h>
+#include <qhbox.h>
+#include <qtextview.h>
+#include <qpushbutton.h>
+
+#include <qpe/applnk.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/qcopenvelope_qws.h>
+
+#include "obex.h"
+#include "receiver.h"
+
+using namespace OpieObex;
+
+Receiver::Receiver() {
+ m_obex = new Obex(this, "Receiver");
+ connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
+ this, SLOT(slotReceived(const QString& ) ) );
+ m_obex->receive();
+}
+Receiver::~Receiver() {
+ m_obex->setReceiveEnabled( false );
+ delete m_obex;
+}
+void Receiver::slotReceived( const QString& file ) {
+ int check = checkFile(file);
+ if ( check == AddressBook )
+ handleAddr( file );
+ else if ( check == Datebook )
+ handleDateTodo( file );
+ else
+ handleOther( file );
+}
+void Receiver::handleAddr( const QString& str ) {
+ QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" );
+ e << str;
+}
+/* we can not say for sure if it's a VEevent ot VTodo */
+void Receiver::handleDateTodo( const QString& str ) {
+ QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)");
+ e0 << str;
+ QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" );
+ e1 << str;
+}
+/*
+ * Handle other asks if it should accept the
+ * beamed object and creates a DocLnk
+ */
+void Receiver::handleOther( const QString& other ) {
+ OtherHandler* hand = new OtherHandler();
+ hand->handle( other );
+}
+int Receiver::checkFile( const QString& file ) {
+ int ret;
+ if (file.right(4) == ".vcs" ) {
+ ret = Datebook;
+ }else if ( file.right(4) == ".vcf") {
+ ret = AddressBook;
+ }else
+ ret = Other;
+
+ return ret;
+}
+
+OtherHandler::OtherHandler()
+ : QVBox()
+{
+ QHBox* box = new QHBox(this);
+ QLabel* lbl = new QLabel(box);
+ lbl->setText(tr("<qt><b>Received:</b></qt>"));
+ m_na = new QLabel(box);
+
+ QFrame* frame = new QFrame(this);
+ frame->setFrameShape( QFrame::HLine );
+ frame->setFrameShadow( QFrame::Sunken );
+
+ m_view = new QTextView(this);
+
+ box = new QHBox(this);
+ QPushButton *but = new QPushButton(box);
+ but->setText(tr("Accept") );
+ connect(but, SIGNAL(clicked() ),
+ this, SLOT(accept()) );
+
+ but = new QPushButton(box);
+ but->setText(tr("Deny") );
+ connect(but, SIGNAL(clicked() ),
+ this, SLOT(deny() ) );
+
+ raise();
+ showMaximized();
+}
+OtherHandler::~OtherHandler() {
+
+}
+void OtherHandler::handle( const QString& file ) {
+ m_file = file;
+ m_na->setText(file);
+ DocLnk lnk(file);
+
+ 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() );
+ m_view->setText( str );
+}
+
+/*
+ * hehe evil evil mmap ahead :)
+ * we quickly copy the file and then we'll create a DocLnk for it
+ */
+void OtherHandler::accept() {
+ QString na = targetName( m_file );
+ copy(m_file, na );
+ DocLnk lnk(na);
+ lnk.writeLink();
+ QFile::remove(m_file);
+ delete this;
+}
+void OtherHandler::deny() {
+ QFile::remove( m_file );
+ delete this;
+}
+QString OtherHandler::targetName( const QString& file ) {
+ QFileInfo info( file );
+ QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
+ QString newFileBase = newFile;
+
+ int trie = 0;
+ while (QFile::exists(newFile + info.extension() ) ) {
+ newFile = newFileBase + "_"+QString::number(trie) ;
+ trie++;
+ }
+ newFile += info.extension();
+
+ return newFile;
+}
+
+/* fast cpy */
+void OtherHandler::copy(const QString& src, const QString& file) {
+ int src_fd = ::open( QFile::encodeName( src ), O_RDONLY );
+ int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC,
+ S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP );
+
+ struct stat stater;
+ ::fstat(src_fd, &stater );
+ ::lseek(to_fd, stater.st_size-1, SEEK_SET );
+
+ void *src_addr, *dest_addr;
+ src_addr = ::mmap(0, stater.st_size, PROT_READ,
+ MAP_FILE | MAP_SHARED, src_fd, 0 );
+ dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_PRIVATE, to_fd, 0 );
+
+ ::memcpy(src_addr , dest_addr, stater.st_size );
+ ::munmap(src_addr , stater.st_size );
+ ::munmap(dest_addr, stater.st_size );
+
+ // done
+}
diff --git a/core/obex/receiver.h b/core/obex/receiver.h
new file mode 100644
index 0000000..5b20146
--- a/dev/null
+++ b/core/obex/receiver.h
@@ -0,0 +1,55 @@
+#ifndef OPIE_OBEX_RECEIVER_H
+#define OPIE_OBEX_RECEIVER_H
+
+#include <qobject.h>
+#include <qvbox.h>
+#include <qstring.h>
+
+class QLabel;
+class QTextView;
+namespace OpieObex {
+ class Obex;
+ class OtherHandler;
+ class Receiver : public QObject {
+ Q_OBJECT
+ public:
+ enum { Datebook , AddressBook, Other };
+ Receiver();
+ ~Receiver();
+
+ private:
+ void handleAddr(const QString& );
+ void handleDateTodo(const QString& );
+ void handleOther(const QString& );
+ int checkFile( const QString& file );
+ bool testDateTodo(const QString& file);
+ bool testAddressbook(const QString& file);
+
+ private slots:
+ void slotReceived( const QString& );
+
+ private:
+ Obex* m_obex;
+ };
+
+ class OtherHandler : public QVBox {
+ Q_OBJECT
+ public:
+ OtherHandler();
+ ~OtherHandler();
+
+ void handle( const QString& file );
+ private slots:
+ void accept();
+ void deny();
+ private:
+ QString targetName( const QString& file );
+ void copy( const QString& src, const QString& dest );
+ QLabel* m_na;
+ QTextView* m_view;
+ QString m_file;
+ };
+}
+
+
+#endif