summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevicebutton.cpp
Unidiff
Diffstat (limited to 'libopie2/opiecore/device/odevicebutton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevicebutton.cpp246
1 files changed, 246 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevicebutton.cpp b/libopie2/opiecore/device/odevicebutton.cpp
new file mode 100644
index 0000000..0b593d5
--- a/dev/null
+++ b/libopie2/opiecore/device/odevicebutton.cpp
@@ -0,0 +1,246 @@
1/*
2                 This file is part of the Opie Project
3              Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 =.
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include <qpixmap.h>
31#include <qstring.h>
32
33#include <qpe/qcopenvelope_qws.h>
34#include <opie2/odevicebutton.h>
35
36using namespace Opie;
37
38class OQCopMessageData
39{
40 public:
41 QCString m_channel;
42 QCString m_message;
43 QByteArray m_data;
44};
45
46
47OQCopMessage::OQCopMessage()
48 : d ( 0 )
49{
50 init ( QCString(), QCString(), QByteArray());
51}
52
53OQCopMessage::OQCopMessage ( const OQCopMessage &copy )
54 : d ( 0 )
55{
56 init ( copy. channel(), copy. message(), copy. data());
57}
58
59OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign )
60{
61 init ( assign. channel(), assign. message(), assign. data());
62 return *this;
63}
64
65OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg )
66 : d ( 0 )
67{
68 init ( ch, m, arg );
69}
70
71void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg )
72{
73 if ( !d )
74 d = new OQCopMessageData();
75 d->m_channel = ch;
76 d->m_message = m;
77 d->m_data = arg;
78}
79
80bool OQCopMessage::send()
81{
82 if ( d->m_channel. isEmpty() || d->m_message. isEmpty() )
83 return false;
84
85 QCopEnvelope e ( d->m_channel, d->m_message );
86
87 if ( d->m_data. size())
88 e. writeRawBytes ( d->m_data. data(), d->m_data. size());
89
90 return true;
91}
92
93QCString OQCopMessage::channel() const
94{
95 return d->m_channel;
96}
97
98QCString OQCopMessage::message() const
99{
100 return d->m_message;
101}
102
103QByteArray OQCopMessage::data() const
104{
105 return d->m_data;
106}
107
108bool OQCopMessage::isNull() const
109{
110 return d->m_message.isNull() || d->m_channel.isNull();
111}
112void OQCopMessage::setChannel ( const QCString &ch )
113{
114 d->m_channel = ch;
115}
116
117void OQCopMessage::setMessage ( const QCString &m )
118{
119 d->m_message = m;
120}
121
122void OQCopMessage::setData ( const QByteArray &data )
123{
124 d->m_data = data;
125}
126
127/*! \class Opie::ODeviceButton
128 \brief The Opie::ODeviceButton class represents a physical user mappable button on a Qtopia device.
129
130 This class represents a physical button on a Qtopia device. A
131 device may have "user programmable" buttons.
132 The location and number of buttons will vary from device to
133 device. userText() and pixmap() may be used to describe this button
134 to the user in help documentation.
135
136 \ingroup qtopiaemb
137 \internal
138*/
139
140ODeviceButton::ODeviceButton()
141{}
142
143ODeviceButton::~ODeviceButton()
144{}
145
146/*!
147Returns the button's keycode.
148*/
149ushort ODeviceButton::keycode() const
150{
151 return m_Keycode;
152}
153
154
155/*!
156This function returns a human readable, translated description of the button.
157*/
158QString ODeviceButton::userText() const
159{
160 return m_UserText;
161}
162
163/*!
164This function returns the pixmap for this button. If there isn't one
165it will return an empty (null) pixmap.
166*/
167QPixmap ODeviceButton::pixmap() const
168{
169 return m_Pixmap;
170}
171
172/*!
173This function returns the factory preset (default) action for when this button
174is pressed. The return value is a legal QCop message.
175*/
176OQCopMessage ODeviceButton::factoryPresetPressedAction() const
177{
178 return m_FactoryPresetPressedAction;
179}
180
181/*!
182This function returns the user assigned action for when this button is pressed.
183If no action is assigned, factoryPresetAction() is returned.
184*/
185OQCopMessage ODeviceButton::pressedAction() const
186{
187 if (m_PressedAction.channel().isEmpty())
188 return factoryPresetPressedAction();
189 return m_PressedAction;
190}
191
192/*!
193This function returns the factory preset (default) action for when this button
194is pressed and held. The return value is a legal QCop message.
195*/
196OQCopMessage ODeviceButton::factoryPresetHeldAction() const
197{
198 return m_FactoryPresetHeldAction;
199}
200
201/*!
202This function returns the user assigned action for when this button is pressed
203and held. If no action is assigned, factoryPresetAction() is returned.
204*/
205OQCopMessage ODeviceButton::heldAction() const
206{
207 if (m_HeldAction.channel().isEmpty())
208 return factoryPresetHeldAction();
209 return m_HeldAction;
210}
211
212void ODeviceButton::setKeycode(ushort keycode)
213{
214 m_Keycode = keycode;
215}
216
217void ODeviceButton::setUserText(const QString& text)
218{
219 m_UserText = text;
220}
221
222void ODeviceButton::setPixmap(const QPixmap& picture)
223{
224 m_Pixmap = picture;
225}
226
227void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action)
228{
229 m_FactoryPresetPressedAction = action;
230}
231
232
233void ODeviceButton::setPressedAction(const OQCopMessage& action)
234{
235 m_PressedAction = action;
236}
237
238void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action)
239{
240 m_FactoryPresetHeldAction = action;
241}
242
243void ODeviceButton::setHeldAction(const OQCopMessage& action)
244{
245 m_HeldAction = action;
246}