summaryrefslogtreecommitdiff
path: root/core/applets/rotateapplet
Unidiff
Diffstat (limited to 'core/applets/rotateapplet') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/rotateapplet/rotate.cpp116
1 files changed, 70 insertions, 46 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,6 +1,9 @@
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
@@ -23,25 +26,25 @@
23 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
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>
36#include <qpopupmenu.h> 44#include <qpopupmenu.h>
37 45
38#include <opie/odevice.h>
39
40#include "rotate.h"
41
42using namespace Opie; 46using namespace Opie;
43 47
44
45RotateApplet::RotateApplet ( ) 48RotateApplet::RotateApplet ( )
46 : QObject ( 0, "RotateApplet" ), ref ( 0 ), m_flipped( false ) 49 : QObject ( 0, "RotateApplet" ), ref ( 0 ), m_flipped( false )
47{ 50{
@@ -55,23 +58,45 @@ RotateApplet::RotateApplet ( )
55} 58}
56 59
57RotateApplet::~RotateApplet ( ) 60RotateApplet::~RotateApplet ( )
58{ 61{}
59}
60
61 62
62/** 63/**
63 * Qcop receive method. 64 * Qcop receive method.
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 }
94 else if ( msg == "rotateDefault()")
95 {
70 rotateDefault(); 96 rotateDefault();
71 } 97 }
72} 98}
73 99
74
75int RotateApplet::position ( ) const 100int RotateApplet::position ( ) const
76{ 101{
77 return 3; 102 return 3;
@@ -102,7 +127,6 @@ QIconSet RotateApplet::icon ( ) const
102{ 127{
103 QPixmap pix; 128 QPixmap pix;
104 QImage img = Resource::loadImage ( "Rotation" ); 129 QImage img = Resource::loadImage ( "Rotation" );
105
106 if ( !img. isNull ( )) 130 if ( !img. isNull ( ))
107 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 131 pix. convertFromImage ( img. smoothScale ( 14, 14 ));
108 return pix; 132 return pix;
@@ -115,33 +139,23 @@ QPopupMenu *RotateApplet::popup ( QWidget * ) const
115 139
116void RotateApplet::rotateDefault ( ) 140void RotateApplet::rotateDefault ( )
117{ 141{
118
119 int rot = ODevice::inst()->rotation(); 142 int rot = ODevice::inst()->rotation();
120 143
121 switch (rot) { 144 switch (rot)
122 case Rot0: 145 {
123 rot=0; 146 case Rot0: rot=0; break;
124 break; 147 case Rot90: rot=90; break;
125 case Rot90: 148 case Rot180: rot=180; break;
126 rot=90; 149 case Rot270: rot=270; break;
127 break; 150 default: rot=0; 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 } 151 }
152
138 Config cfg( "qpe" ); 153 Config cfg( "qpe" );
139 cfg.setGroup( "Appearance" ); 154 cfg.setGroup( "Appearance" );
140 155
141 bool rotateEnabled = cfg.readBoolEntry( "rotateEnabled",true ); 156 bool rotateEnabled = cfg.readBoolEntry( "rotateEnabled",true );
142 157
143 if (rotateEnabled == false) 158 if ( !rotateEnabled) return;
144 return;
145 159
146 // hide inputs methods before rotation 160 // hide inputs methods before rotation
147 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" ); 161 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" );
@@ -154,7 +168,6 @@ void RotateApplet::rotateDefault ( )
154} 168}
155void RotateApplet::activated ( ) 169void RotateApplet::activated ( )
156{ 170{
157
158 int defaultRotation = QPEApplication::defaultRotation(); 171 int defaultRotation = QPEApplication::defaultRotation();
159 int newRotation = defaultRotation; 172 int newRotation = defaultRotation;
160 173
@@ -164,25 +177,36 @@ void RotateApplet::activated ( )
164 int rotDirection = cfg.readNumEntry( "rotatedir" ); 177 int rotDirection = cfg.readNumEntry( "rotatedir" );
165 ODirection rot = CW; 178 ODirection rot = CW;
166 179
167 if (rotDirection == -1) { 180 if (rotDirection == -1)
181 {
168 rot = ODevice::inst ( )-> direction ( ); 182 rot = ODevice::inst ( )-> direction ( );
169 } else { 183 }
184 else
185 {
170 rot = (ODirection)rotDirection; 186 rot = (ODirection)rotDirection;
171 } 187 }
172 188
173 // hide inputs methods before rotation 189 // hide inputs methods before rotation
174 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" ); 190 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" );
175 191
176 if ( m_flipped ) { 192 if ( m_flipped )
193 {
177 // if flipped, flip back to the original state, 194 // if flipped, flip back to the original state,
178 // regardless of rotation direction 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 }