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

clock.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 ** Copyright (C) 2002 Trolltech AS.  All rights reserved.
00004 **
00005 ** This file is part of Qtopia Environment.
00006 **
00007 ** This file may be distributed and/or modified under the terms of the
00008 ** GNU General Public License version 2 as published by the Free Software
00009 ** Foundation and appearing in the file LICENSE.GPL included in the
00010 ** packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00016 **
00017 ** Contact info@trolltech.com if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 **********************************************************************/
00021 // merged in the StyleFix. Applets should raise Popup!
00022 // by zecke@handhelds.org 6th of may 2004
00023 
00024 #include "clock.h"
00025 
00026 /* OPIE */
00027 #include <opie2/odebug.h>
00028 #include <opie2/oresource.h>
00029 #include <opie2/otaskbarapplet.h>
00030 
00031 #include <qpe/qpeapplication.h>
00032 #include <qpe/qcopenvelope_qws.h>
00033 #include <qpe/config.h>
00034 
00035 #include <qpopupmenu.h>
00036 
00037 using namespace Opie::Core;
00038 using namespace Opie::Ui;
00039 
00040 LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent )
00041 {
00042     // If you want a sunken border around the clock do this:
00043     // setFrameStyle( QFrame::Panel | QFrame::Sunken );
00044     //setFont( QFont( "Helvetica", , QFont::Normal ) );
00045     connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime() ) );
00046     connect( qApp, SIGNAL( clockChanged(bool) ),
00047        this, SLOT( slotClockChanged(bool) ) );
00048     readConfig();
00049     timerId = 0;
00050     timerEvent( 0 );
00051     show();
00052 }
00053 
00054 int LauncherClock::position()
00055 {
00056     return 10;
00057 }
00058 
00059 void LauncherClock::readConfig() {
00060     Config config( "qpe" );
00061     config.setGroup( "Time" );
00062     ampmFormat = config.readBoolEntry( "AMPM", TRUE );
00063     config.setGroup( "Date" );
00064     format = config.readNumEntry("ClockApplet",0);
00065 }
00066 
00067 void LauncherClock::mousePressEvent( QMouseEvent * )
00068 {
00069     QPopupMenu *menu = new QPopupMenu(this);
00070     menu->insertItem(tr("Set time..."), 0);
00071     menu->insertSeparator();
00072     menu->insertItem(tr("Clock.."), 1);
00073 
00074 
00075     Config config( "Clock" );
00076     config.setGroup( "Daily Alarm" );
00077     bool alarmOn = config.readBoolEntry("Enabled", FALSE);
00078     menu->insertItem( Opie::Core::OResource::loadPixmap( alarmOn ? "clockapplet/smallalarm" : "clockapplet/smallalarm_off",
00079                                                          Opie::Core::OResource::SmallIcon ), tr("Alarm..."), 2 );
00080 
00081 
00082     /* FIXME use OTaskBarApplet ### */
00083     QPoint curPos = mapToGlobal( QPoint(0,0) );
00084     QSize sh = menu->sizeHint();
00085     switch (menu->exec( curPos-QPoint((sh.width()-width())/2,sh.height()) )) {
00086         case 0:
00087             Global::execute( "systemtime" );
00088             break;
00089         case 1: {
00090             QCopEnvelope e("QPE/Application/clock", "showClock()" );
00091             }
00092             break;
00093         case 2: {
00094                 QCopEnvelope e("QPE/Application/clock", "editDailyAlarm()" );
00095             }
00096             break;
00097         default:
00098             break;
00099     }
00100     delete menu;
00101 }
00102 
00103 
00104 void LauncherClock::timerEvent( QTimerEvent *e )
00105 {
00106     if ( !e || e->timerId() == timerId ) {
00107   killTimer( timerId );
00108   changeTime();
00109   QTime t = QTime::currentTime();
00110   int ms = (60 - t.second())*1000 - t.msec();
00111   timerId = startTimer( ms );
00112     } else {
00113   QLabel::timerEvent( e );
00114     }
00115 }
00116 
00117 void LauncherClock::updateTime( void )
00118 {
00119     changeTime();
00120 }
00121 
00122 void LauncherClock::changeTime( void )
00123 {
00124     QTime tm = QDateTime::currentDateTime().time();
00125     QString s;
00126     if( ampmFormat ) {
00127   int hour = tm.hour();
00128   if (hour == 0)
00129       hour = 12;
00130   if (hour > 12)
00131       hour -= 12;
00132   s.sprintf( "%2d:%02d %s", hour, tm.minute(),
00133        (tm.hour() >= 12) ? "PM" : "AM" );
00134     } else
00135   s.sprintf( "%2d:%02d", tm.hour(), tm.minute() );
00136 
00137     if (format==1) {
00138   QDate dm = QDate::currentDate();
00139   QString d;
00140   d.sprintf("%d/%d ", dm.day(), dm.month());
00141   setText( d+s );
00142     } else if (format==2) {
00143   QDate dm = QDate::currentDate();
00144   QString d;
00145   d.sprintf("%d/%d ", dm.month(), dm.day());
00146   setText( d+s );
00147     } else {
00148   setText( s );
00149     }
00150 }
00151 
00152 void LauncherClock::slotClockChanged( bool  )
00153 {
00154     readConfig();
00155     updateTime();
00156 }
00157 
00158 
00159 EXPORT_OPIE_APPLET_v1( LauncherClock )
00160 

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