00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "rotate.h"
00034
00035
00036 #include <opie2/odebug.h>
00037 #include <opie2/odevice.h>
00038 #include <opie2/oresource.h>
00039
00040 #include <qpe/applnk.h>
00041 #include <qpe/config.h>
00042 #include <qpe/power.h>
00043 #include <qpe/qcopenvelope_qws.h>
00044 using namespace Opie::Core;
00045
00046
00047 #include <time.h>
00048
00049 RotateApplet::RotateApplet()
00050 :QObject( 0, "RotateApplet" ), m_flipped( false )
00051 {
00052
00053 #if !defined(QT_NO_COP)
00054 QCopChannel *rotateChannel = new QCopChannel( "QPE/Rotation" , this );
00055 connect ( rotateChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
00056 this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) );
00057 #endif
00058
00059 }
00060
00061 RotateApplet::~RotateApplet ( )
00062 {}
00063
00067 void RotateApplet::channelReceived( const QCString &msg, const QByteArray & data )
00068 {
00069 odebug << "RotateApplet::channelReceived( '" << msg << "' )" << oendl;
00070
00071 if ( ODevice::inst()->hasHingeSensor() )
00072 {
00073 struct timespec interval;
00074 struct timespec remain;
00075 interval.tv_sec = 0;
00076 interval.tv_nsec = 600000;
00077 ::nanosleep( &interval, &remain );
00078 OHingeStatus status = ODevice::inst()->readHingeSensor();
00079 odebug << "RotateApplet::readHingeSensor = " << (int) status << "" << oendl;
00080
00081 Config cfg( "apm" );
00082 cfg.setGroup( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ? "AC" : "Battery" );
00083 int action = cfg.readNumEntry( "CloseHingeAction", 0 );
00084
00085 if ( status == CASE_CLOSED )
00086 {
00087 switch ( action )
00088 {
00089 case 1: ODevice::inst()->setDisplayBrightness( 0 ); break;
00090 case 2: ODevice::inst()->suspend(); break;
00091 default: break;
00092 }
00093 }
00094 else
00095 {
00096 switch ( action )
00097 {
00098 case 1: ODevice::inst()->setDisplayBrightness( 127 ); break;
00099 case 2: ; break;
00100 default: break;
00101 }
00102 }
00103 odebug << "RotateApplet::switchAction " << cfg.readNumEntry( "CloseHingeAction" ) << " performed." << oendl;
00104 }
00105
00106 QDataStream stream( data, IO_ReadOnly );
00107 if ( msg == "flip()" )
00108 {
00109 activated ( );
00110 }
00111 else if ( msg == "rotateDefault()")
00112 {
00113 rotateDefault();
00114 }
00115 }
00116
00117 int RotateApplet::position() const
00118 {
00119 return 3;
00120 }
00121
00122 QString RotateApplet::name() const
00123 {
00124 return tr( "Rotate shortcut" );
00125 }
00126
00127 QString RotateApplet::text() const
00128 {
00129 return tr( "Rotate" );
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 QIconSet RotateApplet::icon() const
00144 {
00145 QPixmap pix = Opie::Core::OResource::loadPixmap( "Rotation", Opie::Core::OResource::SmallIcon );
00146 return pix;
00147 }
00148
00149 QPopupMenu* RotateApplet::popup(QWidget*) const
00150 {
00151 return 0;
00152 }
00153
00154 void RotateApplet::rotateDefault()
00155 {
00156 int rot = ODevice::inst()->rotation();
00157
00158 switch (rot)
00159 {
00160 case Rot0: rot=0; break;
00161 case Rot90: rot=90; break;
00162 case Rot180: rot=180; break;
00163 case Rot270: rot=270; break;
00164 default: rot=0; break;
00165 }
00166
00167 Config cfg( "qpe" );
00168 cfg.setGroup( "Appearance" );
00169
00170 bool rotateEnabled = cfg.readBoolEntry( "rotateEnabled",true );
00171
00172 if ( !rotateEnabled) return;
00173
00174
00175 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" );
00176
00177 QCopEnvelope env( "QPE/System", "setCurrentRotation(int)" );
00178 env << rot;
00179
00180 m_flipped = false;
00181
00182 }
00183 void RotateApplet::activated()
00184 {
00185 int defaultRotation = QPEApplication::defaultRotation();
00186 int newRotation = defaultRotation;
00187
00188 Config cfg( "qpe" );
00189 cfg.setGroup( "Appearance" );
00190
00191 int rotDirection = cfg.readNumEntry( "rotatedir" );
00192 ODirection rot = CW;
00193
00194 if (rotDirection == -1)
00195 {
00196 rot = ODevice::inst()->direction();
00197 }
00198 else
00199 {
00200 rot = (ODirection) rotDirection;
00201 }
00202
00203
00204 QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" );
00205
00206 if ( m_flipped )
00207 {
00208
00209
00210 newRotation = defaultRotation;
00211 }
00212 else
00213 {
00214 if ( rot == CCW )
00215 {
00216 newRotation = ( defaultRotation + 90 ) % 360;
00217 }
00218 else if ( rot == CW )
00219 {
00220 newRotation = ( defaultRotation + 270 ) % 360;
00221 }
00222 else if ( rot == Flip )
00223 {
00224 newRotation = ( defaultRotation + 180 ) % 360;
00225 }
00226 }
00227
00228 QCopEnvelope env( "QPE/System", "setCurrentRotation(int)" );
00229 env << newRotation;
00230
00231 m_flipped = !m_flipped;
00232 }
00233
00234
00235 QRESULT RotateApplet::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00236 {
00237 *iface = 0;
00238 if ( uuid == IID_QUnknown )
00239 *iface = this;
00240 else if ( uuid == IID_MenuApplet )
00241 *iface = this;
00242 else
00243 return QS_FALSE;
00244
00245 if ( *iface )
00246 (*iface)->addRef();
00247 return QS_OK;
00248 }
00249
00250 Q_EXPORT_INTERFACE()
00251 {
00252 Q_CREATE_INSTANCE( RotateApplet )
00253 }