author | sandman <sandman> | 2002-12-22 23:54:50 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-22 23:54:50 (UTC) |
commit | 5c7694a7baadec8afe128ad2541e0a8acfc23737 (patch) (unidiff) | |
tree | c3dc0189dd9933e43565d85183474adfdc0de7aa /libopie/odevicebutton.cpp | |
parent | 3ef4b1549eca77c3d1c3ef710eb6abbd3de336be (diff) | |
download | opie-5c7694a7baadec8afe128ad2541e0a8acfc23737.zip opie-5c7694a7baadec8afe128ad2541e0a8acfc23737.tar.gz opie-5c7694a7baadec8afe128ad2541e0a8acfc23737.tar.bz2 |
- added the device button stuff to ODevice
- ODevice is now derived from QObject (don't ask me why I didn't make this
from the beginning)
-rw-r--r-- | libopie/odevicebutton.cpp | 234 |
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 | |||
27 | using namespace Opie; | ||
28 | |||
29 | |||
30 | class OQCopMessageData { | ||
31 | public: | ||
32 | QCString m_channel; | ||
33 | QCString m_message; | ||
34 | QByteArray m_data; | ||
35 | }; | ||
36 | |||
37 | |||
38 | OQCopMessage::OQCopMessage ( ) | ||
39 | : d ( 0 ) | ||
40 | { | ||
41 | init ( QCString ( ), QCString ( ), QByteArray ( )); | ||
42 | } | ||
43 | |||
44 | OQCopMessage::OQCopMessage ( const OQCopMessage © ) | ||
45 | : d ( 0 ) | ||
46 | { | ||
47 | init ( copy. channel ( ), copy. message ( ), copy. data ( )); | ||
48 | } | ||
49 | |||
50 | OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) | ||
51 | { | ||
52 | init ( assign. channel ( ), assign. message ( ), assign. data ( )); | ||
53 | return *this; | ||
54 | } | ||
55 | |||
56 | OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) | ||
57 | : d ( 0 ) | ||
58 | { | ||
59 | init ( ch, m, arg ); | ||
60 | } | ||
61 | |||
62 | void 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 | |||
71 | bool 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 | |||
84 | QCString OQCopMessage::channel ( ) const | ||
85 | { | ||
86 | return d-> m_channel; | ||
87 | } | ||
88 | |||
89 | QCString OQCopMessage::message ( ) const | ||
90 | { | ||
91 | return d-> m_message; | ||
92 | } | ||
93 | |||
94 | QByteArray OQCopMessage::data ( ) const | ||
95 | { | ||
96 | return d-> m_data; | ||
97 | } | ||
98 | |||
99 | void OQCopMessage::setChannel ( const QCString &ch ) | ||
100 | { | ||
101 | d-> m_channel = ch; | ||
102 | } | ||
103 | |||
104 | void OQCopMessage::setMessage ( const QCString &m ) | ||
105 | { | ||
106 | d-> m_message = m; | ||
107 | } | ||
108 | |||
109 | void 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 | |||
127 | ODeviceButton::ODeviceButton() | ||
128 | { | ||
129 | } | ||
130 | |||
131 | ODeviceButton::~ODeviceButton() | ||
132 | { | ||
133 | } | ||
134 | |||
135 | /*! | ||
136 | Returns the button's keycode. | ||
137 | */ | ||
138 | ushort 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 | */ | ||
147 | QString 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 | */ | ||
156 | QPixmap 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 | */ | ||
165 | OQCopMessage 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 | */ | ||
174 | OQCopMessage 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 | */ | ||
185 | OQCopMessage 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 | */ | ||
194 | OQCopMessage ODeviceButton::heldAction() const | ||
195 | { | ||
196 | if (m_HeldAction.channel().isEmpty()) | ||
197 | return factoryPresetHeldAction(); | ||
198 | return m_HeldAction; | ||
199 | } | ||
200 | |||
201 | void ODeviceButton::setKeycode(ushort keycode) | ||
202 | { | ||
203 | m_Keycode = keycode; | ||
204 | } | ||
205 | |||
206 | void ODeviceButton::setUserText(const QString& text) | ||
207 | { | ||
208 | m_UserText = text; | ||
209 | } | ||
210 | |||
211 | void ODeviceButton::setPixmap(const QPixmap& picture) | ||
212 | { | ||
213 | m_Pixmap = picture; | ||
214 | } | ||
215 | |||
216 | void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) | ||
217 | { | ||
218 | m_FactoryPresetPressedAction = action; | ||
219 | } | ||
220 | |||
221 | void ODeviceButton::setPressedAction(const OQCopMessage& action) | ||
222 | { | ||
223 | m_PressedAction = action; | ||
224 | } | ||
225 | |||
226 | void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) | ||
227 | { | ||
228 | m_FactoryPresetHeldAction = action; | ||
229 | } | ||
230 | |||
231 | void ODeviceButton::setHeldAction(const OQCopMessage& action) | ||
232 | { | ||
233 | m_HeldAction = action; | ||
234 | } | ||