summaryrefslogtreecommitdiff
path: root/core
Unidiff
Diffstat (limited to 'core') (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,10 +1,13 @@
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
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
@@ -12,38 +15,38 @@
12    .i_,=:_.      -<s. This library is distributed in the hope that 15    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
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 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
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,
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 48RotateApplet::RotateApplet()
45RotateApplet::RotateApplet ( ) 49 :QObject( 0, "RotateApplet" ), ref( 0 ), m_flipped( false )
46 : QObject ( 0, "RotateApplet" ), ref ( 0 ), m_flipped( false )
47{ 50{
48 51
49#if !defined(QT_NO_COP) 52#if !defined(QT_NO_COP)
@@ -55,36 +58,58 @@ 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 }
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{
77 return 3; 102 return 3;
78} 103}
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}
89 114
90/*QString RotateApplet::tr( const char* s ) const 115/*QString RotateApplet::tr( const char* s ) const
@@ -98,50 +123,39 @@ QString RotateApplet::tr( const char* s, const char* p ) const
98} 123}
99*/ 124*/
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" );
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()" );
@@ -152,9 +166,8 @@ void RotateApplet::rotateDefault ( )
152 m_flipped = false; 166 m_flipped = false;
153 167
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,27 +177,38 @@ 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)
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 }
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 )
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 }
189 213
190 QCopEnvelope env( "QPE/System", "setCurrentRotation(int)" ); 214 QCopEnvelope env( "QPE/System", "setCurrentRotation(int)" );
@@ -194,20 +218,20 @@ void RotateApplet::activated ( )
194} 218}
195 219
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}