summaryrefslogtreecommitdiff
path: root/libopie/odevicebutton.cpp
Unidiff
Diffstat (limited to 'libopie/odevicebutton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevicebutton.cpp234
1 files changed, 234 insertions, 0 deletions
diff --git a/libopie/odevicebutton.cpp b/libopie/odevicebutton.cpp
new file mode 100644
index 0000000..2270343
--- a/dev/null
+++ b/libopie/odevicebutton.cpp
@@ -0,0 +1,234 @@
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
21#include <qpixmap.h>
22#include <qstring.h>
23
24#include <qpe/qcopenvelope_qws.h>
25#include <opie/odevicebutton.h>
26
27using namespace Opie;
28
29
30class OQCopMessageData {
31 public:
32 QCString m_channel;
33 QCString m_message;
34 QByteArray m_data;
35};
36
37
38OQCopMessage::OQCopMessage ( )
39 : d ( 0 )
40{
41 init ( QCString ( ), QCString ( ), QByteArray ( ));
42}
43
44OQCopMessage::OQCopMessage ( const OQCopMessage &copy )
45 : d ( 0 )
46{
47 init ( copy. channel ( ), copy. message ( ), copy. data ( ));
48}
49
50OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign )
51{
52 init ( assign. channel ( ), assign. message ( ), assign. data ( ));
53 return *this;
54}
55
56OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg )
57 : d ( 0 )
58{
59 init ( ch, m, arg );
60}
61
62void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg )
63{
64 if ( !d )
65 d = new OQCopMessageData ( );
66 d-> m_channel = ch;
67 d-> m_message = m;
68 d-> m_data = arg;
69}
70
71bool OQCopMessage::send ( )
72{
73 if ( d-> m_channel. isEmpty ( ) || d-> m_message. isEmpty ( ))
74 return false;
75
76 QCopEnvelope e ( d-> m_channel, d-> m_message );
77
78 if ( d-> m_data. size ( ))
79 e. writeRawBytes ( d-> m_data. data ( ), d-> m_data. size ( ));
80
81 return true;
82}
83
84QCString OQCopMessage::channel ( ) const
85{
86 return d-> m_channel;
87}
88
89QCString OQCopMessage::message ( ) const
90{
91 return d-> m_message;
92}
93
94QByteArray OQCopMessage::data ( ) const
95{
96 return d-> m_data;
97}
98
99void OQCopMessage::setChannel ( const QCString &ch )
100{
101 d-> m_channel = ch;
102}
103
104void OQCopMessage::setMessage ( const QCString &m )
105{
106 d-> m_message = m;
107}
108
109void OQCopMessage::setData ( const QByteArray &data )
110{
111 d-> m_data = data;
112}
113
114/*! \class ODeviceButton
115 \brief The ODeviceButton class represents a physical user mappable button on a Qtopia device.
116
117 This class represents a physical button on a Qtopia device. A
118 device may have "user programmable" buttons.
119 The location and number of buttons will vary from device to
120 device. userText() and pixmap() may be used to describe this button
121 to the user in help documentation.
122
123 \ingroup qtopiaemb
124 \internal
125*/
126
127ODeviceButton::ODeviceButton()
128{
129}
130
131ODeviceButton::~ODeviceButton()
132{
133}
134
135/*!
136 Returns the button's keycode.
137 */
138ushort ODeviceButton::keycode() const
139{
140 return m_Keycode;
141}
142
143
144/*!
145 This function returns a human readable, translated description of the button.
146 */
147QString ODeviceButton::userText() const
148{
149 return m_UserText;
150}
151
152/*!
153 This function returns the pixmap for this button. If there isn't one
154 it will return an empty (null) pixmap.
155 */
156QPixmap ODeviceButton::pixmap() const
157{
158 return m_Pixmap;
159}
160
161/*!
162 This function returns the factory preset (default) action for when this button
163 is pressed. The return value is a legal QCop message.
164 */
165OQCopMessage ODeviceButton::factoryPresetPressedAction() const
166{
167 return m_FactoryPresetPressedAction;
168}
169
170/*!
171 This function returns the user assigned action for when this button is pressed.
172 If no action is assigned, factoryPresetAction() is returned.
173 */
174OQCopMessage ODeviceButton::pressedAction() const
175{
176 if (m_PressedAction.channel().isEmpty())
177 return factoryPresetPressedAction();
178 return m_PressedAction;
179}
180
181/*!
182 This function returns the factory preset (default) action for when this button
183 is pressed and held. The return value is a legal QCop message.
184 */
185OQCopMessage ODeviceButton::factoryPresetHeldAction() const
186{
187 return m_FactoryPresetHeldAction;
188}
189
190/*!
191 This function returns the user assigned action for when this button is pressed
192 and held. If no action is assigned, factoryPresetAction() is returned.
193 */
194OQCopMessage ODeviceButton::heldAction() const
195{
196 if (m_HeldAction.channel().isEmpty())
197 return factoryPresetHeldAction();
198 return m_HeldAction;
199}
200
201void ODeviceButton::setKeycode(ushort keycode)
202{
203 m_Keycode = keycode;
204}
205
206void ODeviceButton::setUserText(const QString& text)
207{
208 m_UserText = text;
209}
210
211void ODeviceButton::setPixmap(const QPixmap& picture)
212{
213 m_Pixmap = picture;
214}
215
216void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action)
217{
218 m_FactoryPresetPressedAction = action;
219}
220
221void ODeviceButton::setPressedAction(const OQCopMessage& action)
222{
223 m_PressedAction = action;
224}
225
226void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action)
227{
228 m_FactoryPresetHeldAction = action;
229}
230
231void ODeviceButton::setHeldAction(const OQCopMessage& action)
232{
233 m_HeldAction = action;
234}