summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/clockapplet/clock.cpp45
1 files changed, 25 insertions, 20 deletions
diff --git a/core/applets/clockapplet/clock.cpp b/core/applets/clockapplet/clock.cpp
index fa76eb0..c186fb3 100644
--- a/core/applets/clockapplet/clock.cpp
+++ b/core/applets/clockapplet/clock.cpp
@@ -1,112 +1,117 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "clock.h" 21#include "clock.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26 26
27#include <qmainwindow.h> 27#include <qmainwindow.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qmessagebox.h> 30#include <qmessagebox.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34#include <stdlib.h> 34#include <stdlib.h>
35 35
36 36
37LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent ) 37LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent )
38{ 38{
39 // If you want a sunken border around the clock do this: 39 // If you want a sunken border around the clock do this:
40 // setFrameStyle( QFrame::Panel | QFrame::Sunken ); 40 // setFrameStyle( QFrame::Panel | QFrame::Sunken );
41 setFont( QFont( "Helvetica", 10, QFont::Normal ) ); 41 setFont( QFont( "Helvetica", 10, QFont::Normal ) );
42 connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime( ) ) ); 42 connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime( ) ) );
43 connect( qApp, SIGNAL( clockChanged( bool ) ), 43 connect( qApp, SIGNAL( clockChanged( bool ) ),
44 this, SLOT( slotClockChanged( bool ) ) ); 44 this, SLOT( slotClockChanged( bool ) ) );
45 readConfig(); 45 readConfig();
46 timerId = 0; 46 timerId = 0;
47 timerEvent( 0 ); 47 timerEvent( 0 );
48 show(); 48 show();
49} 49}
50 50
51void LauncherClock::readConfig() { 51void LauncherClock::readConfig() {
52 Config config( "qpe" ); 52 Config config( "qpe" );
53 config.setGroup( "Time" ); 53 config.setGroup( "Time" );
54 ampmFormat = config.readBoolEntry( "AMPM", TRUE ); 54 ampmFormat = config.readBoolEntry( "AMPM", TRUE );
55 config.setGroup( "Date" ); 55 config.setGroup( "Date" );
56 format = config.readNumEntry("ClockApplet",0); 56 format = config.readNumEntry("ClockApplet",0);
57} 57}
58 58
59void LauncherClock::mouseReleaseEvent( QMouseEvent * ) 59void LauncherClock::mouseReleaseEvent( QMouseEvent * )
60{ 60{
61 Global::execute( "systemtime" ); 61 Global::execute( "systemtime" );
62} 62}
63 63
64 64
65void LauncherClock::timerEvent( QTimerEvent *e ) 65void LauncherClock::timerEvent( QTimerEvent *e )
66{ 66{
67 if ( !e || e->timerId() == timerId ) { 67 if ( !e || e->timerId() == timerId ) {
68 killTimer( timerId ); 68 killTimer( timerId );
69 changeTime(); 69 changeTime();
70 QTime t = QTime::currentTime(); 70 QTime t = QTime::currentTime();
71 int ms = (60 - t.second())*1000 - t.msec(); 71 int ms = (60 - t.second())*1000 - t.msec();
72 timerId = startTimer( ms ); 72 timerId = startTimer( ms );
73 } else { 73 } else {
74 QLabel::timerEvent( e ); 74 QLabel::timerEvent( e );
75 } 75 }
76} 76}
77 77
78void LauncherClock::updateTime( void ) 78void LauncherClock::updateTime( void )
79{ 79{
80 changeTime(); 80 changeTime();
81} 81}
82 82
83void LauncherClock::changeTime( void ) 83void LauncherClock::changeTime( void )
84{ 84{
85 QTime tm = QDateTime::currentDateTime().time(); 85 QTime tm = QDateTime::currentDateTime().time();
86 QString s; 86 QString s;
87 if( ampmFormat ) { 87 if( ampmFormat ) {
88 int hour = tm.hour(); 88 int hour = tm.hour();
89 if (hour == 0) 89 if (hour == 0)
90 hour = 12; 90 hour = 12;
91 if (hour > 12) 91 if (hour > 12)
92 hour -= 12; 92 hour -= 12;
93 s.sprintf( "%2d:%02d %s", hour, tm.minute(), 93 s.sprintf( "%2d:%02d %s", hour, tm.minute(),
94 (tm.hour() >= 12) ? "PM" : "AM" ); 94 (tm.hour() >= 12) ? "PM" : "AM" );
95 } else 95 } else
96 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() ); 96 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() );
97 97
98 if (format==1) { 98 if (format==1) {
99 QDate dm = QDate::currentDate(); 99 QDate dm = QDate::currentDate();
100 QString d; 100 QString d;
101 d.sprintf("%d/%d ", dm.day(), dm.month()); 101 d.sprintf("%d/%d ", dm.day(), dm.month());
102 setText( d+s ); 102 setText( d+s );
103 } else if (format==2) {
104 QDate dm = QDate::currentDate();
105 QString d;
106 d.sprintf("%d/%d ", dm.month(), dm.day());
107 setText( d+s );
103 } else { 108 } else {
104 setText( s ); 109 setText( s );
105 } 110 }
106} 111}
107 112
108void LauncherClock::slotClockChanged( bool pm ) 113void LauncherClock::slotClockChanged( bool pm )
109{ 114{
110 readConfig(); 115 readConfig();
111 updateTime(); 116 updateTime();
112} 117}