Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

rotate.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
00005                              Copyright (C) 2003 Greg Gilbert <ggilbert@treke.net>
00006                              Copyright (C) 2004 Michael Lauer <mickey@Vanille.de>
00007               =.
00008             .=l.
00009            .>+-=
00010  _;:,     .>    :=|.         This program is free software; you can
00011 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00012     :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00013 .="- .-=="i,     .._         License as published by the Free Software
00014  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00015      ._= =}       :          or (at your option) any later version.
00016     .%`+i>       _;_.
00017     .i_,=:_.      -<s.       This program is distributed in the hope that
00018      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00019     : ..    .:,     . . .    without even the implied warranty of
00020     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00021   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00022 ..}^=.=       =       ;      Library General Public License for more
00023 ++=   -.     .`     .:       details.
00024     :     =  ...= . :.=-
00025  -.   .:....=;==+<;          You should have received a copy of the GNU
00026   -_. . .   )=.  =           Library General Public License along with
00027     --        :-=`           this library; see the file COPYING.LIB.
00028                              If not, write to the Free Software Foundation,
00029                              Inc., 59 Temple Place - Suite 330,
00030                              Boston, MA 02111-1307, USA.
00031 */
00032 
00033 #include "rotate.h"
00034 
00035 /* OPIE */
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 /* STD */
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: /* DISPLAY OFF */ ODevice::inst()->setDisplayBrightness( 0 ); break;
00090                 case 2: /* SUSPEND */ ODevice::inst()->suspend(); break;
00091                 default: /* IGNORE */ break;
00092             }
00093         }
00094         else /* status != CASE_CLOSED */
00095         {
00096             switch ( action )
00097             {
00098                 case 1: /* DISPLAY OFF */ ODevice::inst()->setDisplayBrightness( 127 ); break;
00099                 case 2: /* SUSPEND */ /* How to wake up the device from kernel? */; break;
00100                 default: /* IGNORE */ 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 /*QString RotateApplet::tr( const char* s ) const
00133 {
00134     return qApp->translate( "RotateApplet", s, 0 );
00135 }
00136 
00137 QString RotateApplet::tr( const char* s, const char* p ) const
00138 {
00139     return qApp->translate( "RotateApplet", s, p );
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     // hide inputs methods before rotation
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     // hide inputs methods before rotation
00204     QCopEnvelope en( "QPE/TaskBar", "hideInputMethod()" );
00205 
00206     if ( m_flipped )
00207     {
00208         // if flipped, flip back to the original state,
00209         // regardless of rotation direction
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 }

Generated on Sat Nov 5 16:15:24 2005 for OPIE by  doxygen 1.4.2