-rw-r--r-- | library/ir.cpp | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/library/ir.cpp b/library/ir.cpp index 68345d1..a7cf7b1 100644 --- a/library/ir.cpp +++ b/library/ir.cpp | |||
@@ -1,79 +1,120 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
1 | #include "ir.h" | 21 | #include "ir.h" |
2 | 22 | ||
3 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #ifdef QWS | ||
4 | #include "qcopenvelope_qws.h" | 25 | #include "qcopenvelope_qws.h" |
5 | #include <qcopchannel_qws.h> | 26 | #include <qcopchannel_qws.h> |
27 | #endif | ||
6 | #include "applnk.h" | 28 | #include "applnk.h" |
7 | 29 | ||
8 | /*! | 30 | /*! |
9 | \class Ir ir.h | 31 | \class Ir ir.h |
10 | \brief The Ir class implements basic support for sending objects over an | 32 | \brief The Ir class implements basic support for sending objects over an |
11 | infrared communication link. | 33 | infrared communication link. |
12 | 34 | ||
13 | The Ir class is a small helper class to enable sending of objects over an infrared communication link. | 35 | Both \link doclnk.html DocLnk\endlink objects and files can be |
36 | sent to another device via the infrared link using the send() | ||
37 | function. When the send has completed the done() signal is | ||
38 | emitted. | ||
39 | |||
40 | The supported() function returns whether the device supports | ||
41 | infrared communication or not. | ||
42 | |||
43 | \ingroup qtopiaemb | ||
14 | */ | 44 | */ |
15 | 45 | ||
16 | /*! | 46 | /*! |
17 | Constructs an Ir object. The \a parent and \a name classes are the | 47 | Constructs an Ir object. The \a parent and \a name classes are the |
18 | standard QObject parameters. | 48 | standard QObject parameters. |
19 | */ | 49 | */ |
20 | Ir::Ir( QObject *parent, const char *name ) | 50 | Ir::Ir( QObject *parent, const char *name ) |
21 | : QObject( parent, name ) | 51 | : QObject( parent, name ) |
22 | { | 52 | { |
53 | #ifndef QT_NO_COP | ||
23 | ch = new QCopChannel( "QPE/Obex" ); | 54 | ch = new QCopChannel( "QPE/Obex" ); |
24 | connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), | 55 | connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), |
25 | this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); | 56 | this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); |
57 | #endif | ||
26 | } | 58 | } |
27 | 59 | ||
28 | /*! | 60 | /*! |
29 | Returns TRUE if the system supports infrared communication. | 61 | Returns TRUE if the system supports infrared communication; |
62 | otherwise returns FALSE. | ||
30 | */ | 63 | */ |
31 | bool Ir::supported() | 64 | bool Ir::supported() |
32 | { | 65 | { |
66 | #ifndef QT_NO_COP | ||
33 | return QCopChannel::isRegistered( "QPE/Obex" ); | 67 | return QCopChannel::isRegistered( "QPE/Obex" ); |
68 | #endif | ||
34 | } | 69 | } |
35 | 70 | ||
36 | /*! | 71 | /*! |
37 | Send the object in the file \a fn over the infrared link. | 72 | Sends the object in file \a fn over the infrared link. The \a |
38 | The \a description will be shown to the user while | 73 | description is used in the text shown to the user while sending |
39 | sending is in progress. | 74 | is in progress. The optional \a mimetype parameter specifies the |
40 | The optional \a mimetype parameter specifies the mimetype of the object. If this parameter is not | 75 | mimetype of the object. If this parameter is not set, it is |
41 | set, it will be determined by the extension of the filename. | 76 | determined by the the filename's suffix. |
77 | |||
78 | \sa done() | ||
42 | */ | 79 | */ |
43 | void Ir::send( const QString &fn, const QString &description, const QString &mimetype) | 80 | void Ir::send( const QString &fn, const QString &description, const QString &mimetype) |
44 | { | 81 | { |
45 | if ( !filename.isEmpty() ) return; | 82 | if ( !filename.isEmpty() ) return; |
46 | filename = fn; | 83 | filename = fn; |
84 | #ifndef QT_NO_COP | ||
47 | QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); | 85 | QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); |
48 | e << description << filename << mimetype; | 86 | e << description << filename << mimetype; |
87 | #endif | ||
49 | } | 88 | } |
50 | 89 | ||
51 | /*! | 90 | /*! |
52 | \overload | 91 | \overload |
53 | 92 | ||
54 | Uses the DocLnk::file() and DocLnk::type() of \a doc. | 93 | Uses the DocLnk::file() and DocLnk::type() of \a doc. |
94 | |||
95 | \sa done() | ||
55 | */ | 96 | */ |
56 | void Ir::send( const DocLnk &doc, const QString &description ) | 97 | void Ir::send( const DocLnk &doc, const QString &description ) |
57 | { | 98 | { |
58 | send( doc.file(), description, doc.type() ); | 99 | send( doc.file(), description, doc.type() ); |
59 | } | 100 | } |
60 | 101 | ||
61 | /*! | 102 | /*! |
62 | \fn Ir::done( Ir *ir ); | 103 | \fn Ir::done( Ir *ir ); |
63 | 104 | ||
64 | This signal is emitted by \a ir, when the send comand has been processed. | 105 | This signal is emitted by \a ir, when the send comand has been processed. |
65 | */ | 106 | */ |
66 | 107 | ||
67 | /*!\internal | 108 | /*!\internal |
68 | */ | 109 | */ |
69 | void Ir::obexMessage( const QCString &msg, const QByteArray &data) | 110 | void Ir::obexMessage( const QCString &msg, const QByteArray &data) |
70 | { | 111 | { |
71 | if ( msg == "done(QString)" ) { | 112 | if ( msg == "done(QString)" ) { |
72 | QString fn; | 113 | QString fn; |
73 | QDataStream stream( data, IO_ReadOnly ); | 114 | QDataStream stream( data, IO_ReadOnly ); |
74 | stream >> fn; | 115 | stream >> fn; |
75 | if ( fn == filename ) | 116 | if ( fn == filename ) |
76 | emit done( this ); | 117 | emit done( this ); |
77 | } | 118 | } |
78 | } | 119 | } |
79 | 120 | ||