summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevicebutton.cpp
blob: a081b7f1265a4e761217960aec913bce420077e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
                             This file is part of the Opie Project
                             Copyright (C) The Opie Team <opie-devel@handhelds.org>
              =.
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.
*/

#include <qpixmap.h>
#include <qstring.h>

#include <qpe/qcopenvelope_qws.h>
#include <opie2/odevicebutton.h>


namespace Opie {
namespace Core {
namespace Private {

class OQCopMessageData
{
  public:
    QCString m_channel;
    QCString m_message;
    QByteArray m_data;
};
}

using namespace Opie::Core;
using namespace Opie::Core::Private;

OQCopMessage::OQCopMessage()
        : d ( 0 )
{
    init ( QCString(), QCString(), QByteArray());
}

OQCopMessage::OQCopMessage ( const OQCopMessage &copy )
        : d ( 0 )
{
    init ( copy. channel(), copy. message(), copy. data());
}

OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign )
{
    init ( assign. channel(), assign. message(), assign. data());
    return *this;
}

OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg )
        : d ( 0 )
{
    init ( ch, m, arg );
}

void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg )
{
    if ( !d )
        d = new OQCopMessageData();
    d->m_channel = ch;
    d->m_message = m;
    d->m_data = arg;
}

bool OQCopMessage::send()
{
    if ( d->m_channel. isEmpty() || d->m_message. isEmpty() )
        return false;

    QCopEnvelope e ( d->m_channel, d->m_message );

    if ( d->m_data. size())
        e. writeRawBytes ( d->m_data. data(), d->m_data. size());

    return true;
}

QCString OQCopMessage::channel() const
{
    return d->m_channel;
}

QCString OQCopMessage::message() const
{
    return d->m_message;
}

QByteArray OQCopMessage::data() const
{
    return d->m_data;
}

bool OQCopMessage::isNull() const
{
    return d->m_message.isNull() || d->m_channel.isNull();
}
void OQCopMessage::setChannel ( const QCString &ch )
{
    d->m_channel = ch;
}

void OQCopMessage::setMessage ( const QCString &m )
{
    d->m_message = m;
}

void OQCopMessage::setData ( const QByteArray &data )
{
    d->m_data = data;
}

/*! \class Opie::Core::ODeviceButton
    \brief The Opie::Core::ODeviceButton class represents a physical user mappable button on a Qtopia device.
 
    This class represents a physical button on a Qtopia device.    A
    device may have "user programmable" buttons.
    The location and number of buttons will vary from device to
    device.    userText() and pixmap() may be used to describe this button
    to the user in help documentation.
 
    \ingroup qtopiaemb
    \internal
*/

ODeviceButton::ODeviceButton()
{}

ODeviceButton::~ODeviceButton()
{}

/*!
Returns the button's keycode.
*/
ushort ODeviceButton::keycode() const
{
    return m_Keycode;
}


/*!
This function returns a human readable, translated description of the button.
*/
QString ODeviceButton::userText() const
{
    return m_UserText;
}

/*!
This function returns the pixmap for this button.    If there isn't one
it will return an empty (null) pixmap.
*/
QPixmap ODeviceButton::pixmap() const
{
    return m_Pixmap;
}

/*!
This function returns the factory preset (default) action for when this button
is pressed.    The return value is a legal QCop message.
*/
OQCopMessage ODeviceButton::factoryPresetPressedAction() const
{
    return m_FactoryPresetPressedAction;
}

/*!
This function returns the user assigned action for when this button is pressed.
If no action is assigned, factoryPresetAction() is returned.
*/
OQCopMessage ODeviceButton::pressedAction() const
{
    if (m_PressedAction.channel().isEmpty())
        return factoryPresetPressedAction();
    return m_PressedAction;
}

/*!
This function returns the factory preset (default) action for when this button
is pressed and held.    The return value is a legal QCop message.
*/
OQCopMessage ODeviceButton::factoryPresetHeldAction() const
{
    return m_FactoryPresetHeldAction;
}

/*!
This function returns the user assigned action for when this button is pressed
and held. If no action is assigned, factoryPresetAction() is returned.
*/
OQCopMessage ODeviceButton::heldAction() const
{
    if (m_HeldAction.channel().isEmpty())
        return factoryPresetHeldAction();
    return m_HeldAction;
}

void ODeviceButton::setKeycode(ushort keycode)
{
    m_Keycode = keycode;
}

void ODeviceButton::setUserText(const QString& text)
{
    m_UserText = text;
}

void ODeviceButton::setPixmap(const QPixmap& picture)
{
    m_Pixmap = picture;
}

void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action)
{
    m_FactoryPresetPressedAction = action;
}


void ODeviceButton::setPressedAction(const OQCopMessage& action)
{
    m_PressedAction = action;
}

void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action)
{
    m_FactoryPresetHeldAction = action;
}

void ODeviceButton::setHeldAction(const OQCopMessage& action)
{
    m_HeldAction = action;
}

}
}