summaryrefslogtreecommitdiff
path: root/library/ir.cpp
Unidiff
Diffstat (limited to 'library/ir.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/ir.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/library/ir.cpp b/library/ir.cpp
new file mode 100644
index 0000000..68345d1
--- a/dev/null
+++ b/library/ir.cpp
@@ -0,0 +1,79 @@
1#include "ir.h"
2
3#include <qstring.h>
4#include "qcopenvelope_qws.h"
5#include <qcopchannel_qws.h>
6#include "applnk.h"
7
8/*!
9 \class Ir ir.h
10 \brief The Ir class implements basic support for sending objects over an
11 infrared communication link.
12
13 The Ir class is a small helper class to enable sending of objects over an infrared communication link.
14*/
15
16/*!
17 Constructs an Ir object. The \a parent and \a name classes are the
18 standard QObject parameters.
19*/
20Ir::Ir( QObject *parent, const char *name )
21 : QObject( parent, name )
22{
23 ch = new QCopChannel( "QPE/Obex" );
24 connect( ch, SIGNAL(received(const QCString &, const QByteArray &)),
25 this, SLOT(obexMessage( const QCString &, const QByteArray &)) );
26}
27
28/*!
29 Returns TRUE if the system supports infrared communication.
30*/
31bool Ir::supported()
32{
33 return QCopChannel::isRegistered( "QPE/Obex" );
34}
35
36/*!
37 Send the object in the file \a fn over the infrared link.
38 The \a description will be shown to the user while
39 sending is in progress.
40 The optional \a mimetype parameter specifies the mimetype of the object. If this parameter is not
41 set, it will be determined by the extension of the filename.
42*/
43void Ir::send( const QString &fn, const QString &description, const QString &mimetype)
44{
45 if ( !filename.isEmpty() ) return;
46 filename = fn;
47 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
48 e << description << filename << mimetype;
49}
50
51/*!
52 \overload
53
54 Uses the DocLnk::file() and DocLnk::type() of \a doc.
55*/
56void Ir::send( const DocLnk &doc, const QString &description )
57{
58 send( doc.file(), description, doc.type() );
59}
60
61/*!
62 \fn Ir::done( Ir *ir );
63
64 This signal is emitted by \a ir, when the send comand has been processed.
65*/
66
67/*!\internal
68 */
69void Ir::obexMessage( const QCString &msg, const QByteArray &data)
70{
71 if ( msg == "done(QString)" ) {
72 QString fn;
73 QDataStream stream( data, IO_ReadOnly );
74 stream >> fn;
75 if ( fn == filename )
76 emit done( this );
77 }
78}
79