summaryrefslogtreecommitdiff
path: root/core/applets/rotateapplet
authormickeyl <mickeyl>2004-01-04 16:34:58 (UTC)
committer mickeyl <mickeyl>2004-01-04 16:34:58 (UTC)
commitc076942e5b0cdaa68a467354a563d1071c866d92 (patch) (unidiff)
tree4da1b79ef326101b410dd85f57f25014b618c23c /core/applets/rotateapplet
parent6ee1d5d35243f611e0a848d454bfa309b8de0fc9 (diff)
downloadopie-c076942e5b0cdaa68a467354a563d1071c866d92.zip
opie-c076942e5b0cdaa68a467354a563d1071c866d92.tar.gz
opie-c076942e5b0cdaa68a467354a563d1071c866d92.tar.bz2
- implement action on closing the hinge for devices with hinge sensors
- first batch of minor code cleanup
Diffstat (limited to 'core/applets/rotateapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/rotateapplet/rotate.cpp204
1 files changed, 114 insertions, 90 deletions
diff --git a/core/applets/rotateapplet/rotate.cpp b/core/applets/rotateapplet/rotate.cpp
index dd71cad..ea114bb 100644
--- a/core/applets/rotateapplet/rotate.cpp
+++ b/core/applets/rotateapplet/rotate.cpp
@@ -1,8 +1,11 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2 This file is part of the OPIE Project
3             .=l. Copyright (c) 2003 Maximilian Reiss <harlekin@handhelds.org> 3 Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
4 Copyright (C) 2003 Greg Gilbert <ggilbert@treke.net>
5               =. Copyright (C) 2004 Michael Lauer <mickey@Vanille.de>
6             .=l.
4           .>+-= 7           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 8 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under 9.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
@@ -14,6 +17,6 @@
14    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details. 21++=   -.     .     .: details.
19 :     =  ...= . :.=- 22 :     =  ...= . :.=-
@@ -21,3 +24,3 @@
21  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
22    --        :-= this library; see the file COPYING.LIB. 25    --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
@@ -25,11 +28,16 @@
25 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
26
27*/ 29*/
28 30
31#include "rotate.h"
29 32
30#include <qpe/resource.h> 33/* OPIE */
34#include <opie/odevice.h>
35#include <qpe/applnk.h>
36#include <qpe/config.h>
37#include <qpe/power.h>
38#include <qpe/qpeapplication.h>
31#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40#include <qpe/resource.h>
32 41
33#include <qpe/qpeapplication.h> 42/* QT */
34#include <qpe/config.h>
35#include <qiconset.h> 43#include <qiconset.h>
@@ -37,11 +45,6 @@
37 45
38#include <opie/odevice.h>
39
40#include "rotate.h"
41
42using namespace Opie; 46using namespace Opie;
43 47
44 48RotateApplet::RotateApplet()
45RotateApplet::RotateApplet ( ) 49 :QObject( 0, "RotateApplet" ), ref( 0 ), m_flipped( false )
46 : QObject ( 0, "RotateApplet" ), ref ( 0 ), m_flipped( false )
47{ 50{
@@ -57,5 +60,3 @@ RotateApplet::RotateApplet ( )
57RotateApplet::~RotateApplet ( ) 60RotateApplet::~RotateApplet ( )
58{ 61{}
59}
60
61 62
@@ -64,13 +65,37 @@ RotateApplet::~RotateApplet ( )
64 */ 65 */
65void RotateApplet::channelReceived( const QCString &msg, const QByteArray & data ) { 66void RotateApplet::channelReceived( const QCString &msg, const QByteArray & data )
67{
68 qDebug( "RotateApplet::channelReceived( '%s' )", (const char*) msg );
69
70 if ( ODevice::inst()->hasHingeSensor() )
71 {
72 OHingeStatus status = ODevice::inst()->readHingeSensor();
73 qDebug( "RotateApplet::readHingeSensor = %d", (int) status );
74 if ( status == CASE_CLOSED )
75 {
76 Config cfg( "apm" );
77 cfg.setGroup( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ? "AC" : "Battery" );
78 int action = cfg.readNumEntry( "CloseHingeAction", 0 );
79 switch ( action )
80 {
81 case 1: /* DISPLAY OFF */ ODevice::inst()->setDisplayStatus( false ); ODevice::inst()->setDisplayBrightness( 0 ); break;
82 case 2: /* SUSPEND */ ODevice::inst()->suspend(); break;
83 default: /* IGNORE */ break;
84 }
85 qDebug( "RotateApplet::switchAction %d performed.", cfg.readNumEntry( "CloseHingeAction", 0 ) );
86 }
87 }
88
66 QDataStream stream( data, IO_ReadOnly ); 89 QDataStream stream( data, IO_ReadOnly );
67 if ( msg == "flip()" ) { 90 if ( msg == "flip()" )
91 {
68 activated ( ); 92 activated ( );
69 } else if ( msg == "rotateDefault()") { 93 }
70 rotateDefault(); 94 else if ( msg == "rotateDefault()")
71 } 95 {
96 rotateDefault();
97 }
72} 98}
73 99
74 100int RotateApplet::position() const
75int RotateApplet::position ( ) const
76{ 101{
@@ -79,10 +104,10 @@ int RotateApplet::position ( ) const
79 104
80QString RotateApplet::name ( ) const 105QString RotateApplet::name() const
81{ 106{
82 return tr( "Rotate shortcut" ); 107 return tr( "Rotate shortcut" );
83} 108}
84 109
85QString RotateApplet::text ( ) const 110QString RotateApplet::text() const
86{ 111{
87 return tr( "Rotate" ); 112 return tr( "Rotate" );
88} 113}
@@ -100,39 +125,29 @@ QString RotateApplet::tr( const char* s, const char* p ) const
100 125
101QIconSet RotateApplet::icon ( ) const 126QIconSet RotateApplet::icon() const
102{ 127{
103 QPixmap pix; 128 QPixmap pix;
104 QImage img = Resource::loadImage ( "Rotation" ); 129 QImage img = Resource::loadImage( "Rotation" );
105 130 if ( !img.isNull() )
106 if ( !img. isNull ( )) 131 pix.convertFromImage( img.smoothScale( 14, 14 ) );
107 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 132 return pix;
108 return pix;
109} 133}
110 134
111QPopupMenu *RotateApplet::popup ( QWidget * ) const 135QPopupMenu* RotateApplet::popup(QWidget*) const
112{ 136{
113 return 0; 137 return 0;
114} 138}
115 139
116void RotateApplet::rotateDefault ( ) 140void RotateApplet::rotateDefault()
117{ 141{
142 int rot = ODevice::inst()->rotation();
143
144 switch (rot)
145 {
146 case Rot0: rot=0; break;
147 case Rot90: rot=90; break;
148 case Rot180: rot=180; break;
149 case Rot270: rot=270; break;
150 default: rot=0; break;
151 }
118 152
119 int rot = ODevice::inst()->rotation();
120
121 switch (rot) {
122 case Rot0:
123 rot=0;
124 break;
125 case Rot90:
126 rot=90;
127 break;
128 case Rot180:
129 rot=180;
130 break;
131 case Rot270:
132 rot=270;
133 break;
134 default:
135 rot=0;
136 break;
137 }
138 Config cfg( "qpe" ); 153 Config cfg( "qpe" );
@@ -142,4 +157,3 @@ void RotateApplet::rotateDefault ( )
142 157
143 if (rotateEnabled == false) 158 if ( !rotateEnabled) return;
144 return;
145 159
@@ -154,5 +168,4 @@ void RotateApplet::rotateDefault ( )
154} 168}
155void RotateApplet::activated ( ) 169void RotateApplet::activated()
156{ 170{
157
158 int defaultRotation = QPEApplication::defaultRotation(); 171 int defaultRotation = QPEApplication::defaultRotation();
@@ -166,6 +179,9 @@ void RotateApplet::activated ( )
166 179
167 if (rotDirection == -1) { 180 if (rotDirection == -1)
168 rot = ODevice::inst ( )-> direction ( ); 181 {
169 } else { 182 rot = ODevice::inst()->direction();
170 rot = (ODirection)rotDirection; 183 }
184 else
185 {
186 rot = (ODirection) rotDirection;
171 } 187 }
@@ -175,14 +191,22 @@ void RotateApplet::activated ( )
175 191
176 if ( m_flipped ) { 192 if ( m_flipped )
177 // if flipped, flip back to the original state, 193 {
178 // regardless of rotation direction 194 // if flipped, flip back to the original state,
195 // regardless of rotation direction
179 newRotation = defaultRotation; 196 newRotation = defaultRotation;
180 } else { 197 }
181 if ( rot == CCW ) { 198 else
199 {
200 if ( rot == CCW )
201 {
182 newRotation = ( defaultRotation + 90 ) % 360; 202 newRotation = ( defaultRotation + 90 ) % 360;
183 } else if ( rot == CW ) { 203 }
204 else if ( rot == CW )
205 {
184 newRotation = ( defaultRotation + 270 ) % 360; 206 newRotation = ( defaultRotation + 270 ) % 360;
185 } else if ( rot == Flip ) { 207 }
208 else if ( rot == Flip )
209 {
186 newRotation = ( defaultRotation + 180 ) % 360; 210 newRotation = ( defaultRotation + 180 ) % 360;
187 } 211 }
188 } 212 }
@@ -196,18 +220,18 @@ void RotateApplet::activated ( )
196 220
197QRESULT RotateApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 221QRESULT RotateApplet::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
198{ 222{
199 *iface = 0; 223 *iface = 0;
200 if ( uuid == IID_QUnknown ) 224 if ( uuid == IID_QUnknown )
201 *iface = this; 225 *iface = this;
202 else if ( uuid == IID_MenuApplet ) 226 else if ( uuid == IID_MenuApplet )
203 *iface = this; 227 *iface = this;
204 228
205 if ( *iface ) 229 if ( *iface )
206 (*iface)-> addRef ( ); 230 (*iface)->addRef();
207 return QS_OK; 231 return QS_OK;
208} 232}
209 233
210Q_EXPORT_INTERFACE( ) 234Q_EXPORT_INTERFACE()
211{ 235{
212 Q_CREATE_INSTANCE( RotateApplet ) 236 Q_CREATE_INSTANCE( RotateApplet )
213} 237}