summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-06 21:14:26 (UTC)
committer zecke <zecke>2004-05-06 21:14:26 (UTC)
commita6f2e9cf92a4f7dc91696394e1fe41d7c7bb372f (patch) (unidiff)
tree092e72540b7f595e02bb9d6bde3f372a37db80c8
parent49588c7322679fe3dadf7aaad058d7df76e0d8d3 (diff)
downloadopie-a6f2e9cf92a4f7dc91696394e1fe41d7c7bb372f.zip
opie-a6f2e9cf92a4f7dc91696394e1fe41d7c7bb372f.tar.gz
opie-a6f2e9cf92a4f7dc91696394e1fe41d7c7bb372f.tar.bz2
Obey styleguide and show popups as in Qtopia
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/clockapplet/clock.cpp46
-rw-r--r--core/applets/clockapplet/clock.h2
2 files changed, 42 insertions, 6 deletions
diff --git a/core/applets/clockapplet/clock.cpp b/core/applets/clockapplet/clock.cpp
index 7d396e7..d7d326d 100644
--- a/core/applets/clockapplet/clock.cpp
+++ b/core/applets/clockapplet/clock.cpp
@@ -1,124 +1,160 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 Trolltech AS. All rights reserved.
3** 4**
4** This file is part of Qtopia Environment. 5** This file is part of Qtopia Environment.
5** 6**
6** This file may be distributed and/or modified under the terms of the 7** 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 8** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 10** packaging of this file.
10** 11**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** 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. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 16**
16** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 18** not clear to you.
18** 19**
19**********************************************************************/ 20**********************************************************************/
21// merged in the StyleFix. Applets should raise Popup!
22// by zecke@handhelds.org 6th of may 2004
20 23
21#include "clock.h" 24#include "clock.h"
22 25
23/* OPIE */ 26/* OPIE */
24#include <opie2/odebug.h> 27#include <opie2/odebug.h>
25#include <opie2/otaskbarapplet.h> 28#include <opie2/otaskbarapplet.h>
29
26#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
27#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
28#include <qpe/config.h> 32#include <qpe/config.h>
33#include <qpe/resource.h>
34
35#include <qpopupmenu.h>
29 36
30using namespace Opie::Core; 37using namespace Opie::Core;
31using namespace Opie::Ui; 38using namespace Opie::Ui;
32 39
33LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent ) 40LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent )
34{ 41{
35 // If you want a sunken border around the clock do this: 42 // If you want a sunken border around the clock do this:
36 // setFrameStyle( QFrame::Panel | QFrame::Sunken ); 43 // setFrameStyle( QFrame::Panel | QFrame::Sunken );
37 //setFont( QFont( "Helvetica", , QFont::Normal ) ); 44 //setFont( QFont( "Helvetica", , QFont::Normal ) );
38 connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime() ) ); 45 connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime() ) );
39 connect( qApp, SIGNAL( clockChanged(bool) ), 46 connect( qApp, SIGNAL( clockChanged(bool) ),
40 this, SLOT( slotClockChanged(bool) ) ); 47 this, SLOT( slotClockChanged(bool) ) );
41 readConfig(); 48 readConfig();
42 timerId = 0; 49 timerId = 0;
43 timerEvent( 0 ); 50 timerEvent( 0 );
44 show(); 51 show();
45} 52}
46 53
47int LauncherClock::position() 54int LauncherClock::position()
48{ 55{
49 return 10; 56 return 10;
50} 57}
51 58
52void LauncherClock::readConfig() { 59void LauncherClock::readConfig() {
53 Config config( "qpe" ); 60 Config config( "qpe" );
54 config.setGroup( "Time" ); 61 config.setGroup( "Time" );
55 ampmFormat = config.readBoolEntry( "AMPM", TRUE ); 62 ampmFormat = config.readBoolEntry( "AMPM", TRUE );
56 config.setGroup( "Date" ); 63 config.setGroup( "Date" );
57 format = config.readNumEntry("ClockApplet",0); 64 format = config.readNumEntry("ClockApplet",0);
58} 65}
59 66
60void LauncherClock::mouseReleaseEvent( QMouseEvent * ) 67void LauncherClock::mousePressEvent( QMouseEvent * )
61{ 68{
62 QCString setTimeApp; 69 QPopupMenu *menu = new QPopupMenu(this);
63 setTimeApp="systemtime"; 70 menu->insertItem(tr("Set time..."), 0);
64 QCopEnvelope e("QPE/Application/"+setTimeApp, "raise()"); 71 menu->insertSeparator();
72 menu->insertItem(tr("Clock.."), 1);
73
74
75 Config config( "Clock" );
76 config.setGroup( "Daily Alarm" );
77 bool alarmOn = config.readBoolEntry("Enabled", FALSE);
78 menu->insertItem(Resource::loadIconSet(alarmOn?"clockapplet/smallalarm":"clockapplet/smallalarm_off" ),
79 tr("Alarm..."), 2);
80
81
82 /* FIXME use OTaskBarApplet ### */
83 QPoint curPos = mapToGlobal( QPoint(0,0) );
84 QSize sh = menu->sizeHint();
85 switch (menu->exec( curPos-QPoint((sh.width()-width())/2,sh.height()) )) {
86 case 0:
87 Global::execute( "systemtime" );
88 break;
89 case 1: {
90 QCopEnvelope e("QPE/Application/clock", "showClock()" );
91 }
92 break;
93 case 2: {
94 QCopEnvelope e("QPE/Application/clock", "editDailyAlarm()" );
95 }
96 break;
97 default:
98 break;
99 }
100 delete menu;
65} 101}
66 102
67 103
68void LauncherClock::timerEvent( QTimerEvent *e ) 104void LauncherClock::timerEvent( QTimerEvent *e )
69{ 105{
70 if ( !e || e->timerId() == timerId ) { 106 if ( !e || e->timerId() == timerId ) {
71 killTimer( timerId ); 107 killTimer( timerId );
72 changeTime(); 108 changeTime();
73 QTime t = QTime::currentTime(); 109 QTime t = QTime::currentTime();
74 int ms = (60 - t.second())*1000 - t.msec(); 110 int ms = (60 - t.second())*1000 - t.msec();
75 timerId = startTimer( ms ); 111 timerId = startTimer( ms );
76 } else { 112 } else {
77 QLabel::timerEvent( e ); 113 QLabel::timerEvent( e );
78 } 114 }
79} 115}
80 116
81void LauncherClock::updateTime( void ) 117void LauncherClock::updateTime( void )
82{ 118{
83 changeTime(); 119 changeTime();
84} 120}
85 121
86void LauncherClock::changeTime( void ) 122void LauncherClock::changeTime( void )
87{ 123{
88 QTime tm = QDateTime::currentDateTime().time(); 124 QTime tm = QDateTime::currentDateTime().time();
89 QString s; 125 QString s;
90 if( ampmFormat ) { 126 if( ampmFormat ) {
91 int hour = tm.hour(); 127 int hour = tm.hour();
92 if (hour == 0) 128 if (hour == 0)
93 hour = 12; 129 hour = 12;
94 if (hour > 12) 130 if (hour > 12)
95 hour -= 12; 131 hour -= 12;
96 s.sprintf( "%2d:%02d %s", hour, tm.minute(), 132 s.sprintf( "%2d:%02d %s", hour, tm.minute(),
97 (tm.hour() >= 12) ? "PM" : "AM" ); 133 (tm.hour() >= 12) ? "PM" : "AM" );
98 } else 134 } else
99 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() ); 135 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() );
100 136
101 if (format==1) { 137 if (format==1) {
102 QDate dm = QDate::currentDate(); 138 QDate dm = QDate::currentDate();
103 QString d; 139 QString d;
104 d.sprintf("%d/%d ", dm.day(), dm.month()); 140 d.sprintf("%d/%d ", dm.day(), dm.month());
105 setText( d+s ); 141 setText( d+s );
106 } else if (format==2) { 142 } else if (format==2) {
107 QDate dm = QDate::currentDate(); 143 QDate dm = QDate::currentDate();
108 QString d; 144 QString d;
109 d.sprintf("%d/%d ", dm.month(), dm.day()); 145 d.sprintf("%d/%d ", dm.month(), dm.day());
110 setText( d+s ); 146 setText( d+s );
111 } else { 147 } else {
112 setText( s ); 148 setText( s );
113 } 149 }
114} 150}
115 151
116void LauncherClock::slotClockChanged( bool pm ) 152void LauncherClock::slotClockChanged( bool )
117{ 153{
118 readConfig(); 154 readConfig();
119 updateTime(); 155 updateTime();
120} 156}
121 157
122 158
123EXPORT_OPIE_APPLET_v1( LauncherClock ) 159EXPORT_OPIE_APPLET_v1( LauncherClock )
124 160
diff --git a/core/applets/clockapplet/clock.h b/core/applets/clockapplet/clock.h
index 996fb56..43639bb 100644
--- a/core/applets/clockapplet/clock.h
+++ b/core/applets/clockapplet/clock.h
@@ -1,49 +1,49 @@
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#ifndef __LAUNCHER_CLOCK_H__ 20#ifndef __LAUNCHER_CLOCK_H__
21#define __LAUNCHER_CLOCK_H__ 21#define __LAUNCHER_CLOCK_H__
22 22
23 23
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26 26
27class LauncherClock : public QLabel 27class LauncherClock : public QLabel
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 LauncherClock( QWidget *parent ); 31 LauncherClock( QWidget *parent );
32 static int position(); 32 static int position();
33 33
34protected slots: 34protected slots:
35 void updateTime( void ); 35 void updateTime( void );
36 void slotClockChanged( bool pm ); 36 void slotClockChanged( bool pm );
37 37
38protected: 38protected:
39 void mouseReleaseEvent( QMouseEvent * ); 39 void mousePressEvent( QMouseEvent * );
40 void timerEvent( QTimerEvent * ); 40 void timerEvent( QTimerEvent * );
41 void changeTime( void ); 41 void changeTime( void );
42 void readConfig(); 42 void readConfig();
43 bool ampmFormat; 43 bool ampmFormat;
44 int timerId; 44 int timerId;
45 int format; 45 int format;
46}; 46};
47 47
48 48
49#endif // __LAUNCHER_CLOCK_H__ 49#endif // __LAUNCHER_CLOCK_H__