Diffstat (limited to 'noncore/settings/networksettings2/opietooth2_applet/opietoothapplet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2_applet/opietoothapplet.cpp | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2_applet/opietoothapplet.cpp b/noncore/settings/networksettings2/opietooth2_applet/opietoothapplet.cpp new file mode 100644 index 0000000..e419942 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2_applet/opietoothapplet.cpp | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <, > . <= redistribute it and/or modify it under | ||
7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. . .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-= this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | |||
30 | #include <qapplication.h> | ||
31 | |||
32 | #include <qpe/qcopenvelope_qws.h> | ||
33 | #include <qpe/config.h> | ||
34 | |||
35 | #include <qpoint.h> | ||
36 | #include <qpainter.h> | ||
37 | #include <qlayout.h> | ||
38 | #include <qframe.h> | ||
39 | #include <qpixmap.h> | ||
40 | #include <qstring.h> | ||
41 | #include <qpopupmenu.h> | ||
42 | |||
43 | #include <OTGateway.h> | ||
44 | #include <OTIcons.h> | ||
45 | #include <opietoothapplet.h> | ||
46 | |||
47 | namespace Opietooth2 { | ||
48 | |||
49 | // | ||
50 | // | ||
51 | // Panel | ||
52 | // | ||
53 | // | ||
54 | |||
55 | MessagePanel::MessagePanel( const QString & Msg, | ||
56 | QWidget* parent, const char* name ): | ||
57 | QLabel( parent, name, WType_Popup ){ | ||
58 | |||
59 | QLabel * L = new QLabel( Msg, this ); | ||
60 | L->setAlignment( Qt::WordBreak | Qt::AlignCenter ); | ||
61 | |||
62 | QVBoxLayout * VL = new QVBoxLayout( this ); | ||
63 | VL->addWidget( this ); | ||
64 | VL->setMargin( 3 ); | ||
65 | |||
66 | setFrameStyle( WinPanel|Raised ); | ||
67 | setAlignment( AlignCenter ); | ||
68 | |||
69 | resize(150,100); | ||
70 | |||
71 | moves = 0; | ||
72 | } | ||
73 | |||
74 | void MessagePanel::mouseReleaseEvent( QMouseEvent * e){ | ||
75 | |||
76 | if (rect().contains( e->pos() ) || moves > 5) | ||
77 | close(); | ||
78 | } | ||
79 | |||
80 | void MessagePanel::closeEvent( QCloseEvent *e ){ | ||
81 | |||
82 | e->accept(); | ||
83 | |||
84 | moves = 0; | ||
85 | |||
86 | if (!popupParent) | ||
87 | return; | ||
88 | |||
89 | /* | ||
90 | remember that we (as a popup) might recieve the mouse | ||
91 | release event instead of the popupParent. This is due to | ||
92 | the fact that the popupParent popped us up in its | ||
93 | mousePressEvent handler. To avoid the button remaining in | ||
94 | pressed state we simply send a faked mouse button release | ||
95 | event to it. | ||
96 | */ | ||
97 | |||
98 | QMouseEvent me( QEvent::MouseButtonRelease, | ||
99 | QPoint(0,0), | ||
100 | QPoint(0,0), | ||
101 | QMouseEvent::LeftButton, | ||
102 | QMouseEvent::NoButton); | ||
103 | QApplication::sendEvent( popupParent, &me ); | ||
104 | } | ||
105 | |||
106 | void MessagePanel::popup( QWidget* parent) { | ||
107 | |||
108 | popupParent = parent; | ||
109 | |||
110 | if (popupParent) | ||
111 | move( popupParent->mapToGlobal( | ||
112 | popupParent->rect().bottomLeft() ) | ||
113 | ); | ||
114 | show(); | ||
115 | } | ||
116 | |||
117 | |||
118 | // | ||
119 | // | ||
120 | // Applet code | ||
121 | // | ||
122 | // | ||
123 | |||
124 | Opietooth2Applet::Opietooth2Applet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | ||
125 | OTIcons Ic; | ||
126 | setFixedHeight( 18 ); | ||
127 | setFixedWidth( 14 ); | ||
128 | |||
129 | OT = OTGateway::getOTGateway(); | ||
130 | |||
131 | OnP = Ic.loadPixmap( "bluezon" ); | ||
132 | OffP = Ic.loadPixmap( "bluezoff" ); | ||
133 | |||
134 | // sent when bluetooth on device is enabled/disabled | ||
135 | connect( OT, | ||
136 | SIGNAL( deviceEnabled( bool ) ), | ||
137 | this, | ||
138 | SLOT( SLOT_StateChange( bool ) ) ); | ||
139 | |||
140 | // sent when error | ||
141 | connect( OT, | ||
142 | SIGNAL( error( const QString & ) ), | ||
143 | this, | ||
144 | SLOT( SLOT_Error( const QString & ) ) ); | ||
145 | } | ||
146 | |||
147 | Opietooth2Applet::~Opietooth2Applet() { | ||
148 | OTGateway::releaseOTGateway(); | ||
149 | } | ||
150 | |||
151 | void Opietooth2Applet::mousePressEvent( QMouseEvent *) { | ||
152 | |||
153 | QPopupMenu *menu = new QPopupMenu(); | ||
154 | // QPopupMenu *signal = new QPopupMenu(); | ||
155 | int ret=0; | ||
156 | |||
157 | /* Refresh active state */ | ||
158 | menu->insertItem( ( (OT->isEnabled()) ? | ||
159 | tr("Disable") : | ||
160 | tr("Enable") | ||
161 | ), | ||
162 | 1 ); | ||
163 | menu->insertItem( tr("Launch manager"), 2 ); | ||
164 | |||
165 | //menu->insertItem( tr("Signal strength"), signal, 5); | ||
166 | //menu->insertSeparator(8); | ||
167 | |||
168 | /* | ||
169 | menu->insertItem( ( (DiscoveryActive) ? | ||
170 | tr("Disable discovery") : | ||
171 | tr("Enable discovery") | ||
172 | ), | ||
173 | 3 ); | ||
174 | */ | ||
175 | |||
176 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | ||
177 | |||
178 | ret = menu->exec(p, 0); | ||
179 | |||
180 | switch(ret) { | ||
181 | case 1: | ||
182 | // toggle enabling of BT | ||
183 | OT->SLOT_SetEnabled( ! OT->isEnabled() ); | ||
184 | break; | ||
185 | case 2: | ||
186 | // start bluetoothmanager | ||
187 | launchManager(); | ||
188 | break; | ||
189 | //case 3: | ||
190 | // DiscoveryActive = 1 - DiscoveryActive; | ||
191 | // setDiscoveryStatus( DiscoveryActive ); | ||
192 | // break; | ||
193 | // case 7: | ||
194 | // With table of currently-detected devices. | ||
195 | } | ||
196 | // delete signal; | ||
197 | delete menu; | ||
198 | } | ||
199 | |||
200 | |||
201 | void Opietooth2Applet::SLOT_Error( const QString & S ) { | ||
202 | MessagePanel * MP = new MessagePanel( S ); | ||
203 | |||
204 | QPoint p = mapToGlobal( | ||
205 | QPoint(1, - MP->sizeHint().height()-1) ); | ||
206 | MP->move( p ); | ||
207 | |||
208 | MP->popup( 0 ); | ||
209 | delete MP; | ||
210 | } | ||
211 | |||
212 | /** | ||
213 | * Launches the bluetooth manager | ||
214 | */ | ||
215 | void Opietooth2Applet::launchManager() { | ||
216 | QCopEnvelope e("QPE/System", "execute(QString)"); | ||
217 | e << QString("networksettings2-opietooth"); | ||
218 | } | ||
219 | |||
220 | void Opietooth2Applet::SLOT_StateChange( bool ) { | ||
221 | // changed | ||
222 | |||
223 | // trigger painting | ||
224 | update(); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Implementation of the paint event | ||
229 | * @param the QPaintEvent | ||
230 | */ | ||
231 | void Opietooth2Applet::paintEvent( QPaintEvent* ) { | ||
232 | QPainter p(this); | ||
233 | |||
234 | p.drawPixmap( 0, 1, (( OT->isEnabled() ) ? OnP : OffP) ); | ||
235 | } | ||
236 | |||
237 | // | ||
238 | // end of namespace | ||
239 | // | ||
240 | |||
241 | }; | ||