![]() |
Home · All Namespaces · All Classes |
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of systemui. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 00020 #include "clock.h" 00021 #include <MLocale> 00022 00023 Clock::Clock(QGraphicsItem *parent) : 00024 MWidgetController(new ClockModel, parent), 00025 locale(new MLocale()) 00026 { 00027 // Set the initial 24 hour mode 00028 updateLocaleSettings(); 00029 00030 #ifdef HAVE_QMSYSTEM 00031 // Be interested in changes to system time 00032 connect(&qmTime, SIGNAL(timeOrSettingsChanged(MeeGo::QmTimeWhatChanged)), 00033 this, SLOT(updateSettings(MeeGo::QmTimeWhatChanged))); 00034 #endif 00035 00036 // Be interested in changes to 24h mode 00037 connect(locale.data(), SIGNAL(settingsChanged()), 00038 this, SLOT(updateLocaleSettings())); 00039 locale->connectSettings(); 00040 00041 // Configure the timer 00042 timer.setSingleShot(true); 00043 connect(&timer, SIGNAL(timeout()), this, SLOT(updateModelAndSetupTimer())); 00044 updateModelAndSetupTimer(); 00045 } 00046 00047 00048 Clock::~Clock() 00049 { 00050 } 00051 00052 void Clock::updateModelAndSetupTimer() 00053 { 00054 // Set the current time to the model 00055 QDateTime currentTime = QDateTime::currentDateTime(); 00056 model()->setTime(currentTime); 00057 00058 // Calculate the time for the next update 00059 QDateTime nextUpdateTime = currentTime.addSecs(60); 00060 QTime time = nextUpdateTime.time(); 00061 time.setHMS(time.hour(), time.minute(), 0); 00062 nextUpdateTime.setTime(time); 00063 00064 // Set the time of the next update and start the timer. The extra one second is used for rounding up to make sure that we always hit the next minute, not the current one. 00065 timer.start((currentTime.secsTo(nextUpdateTime) + 1) * 1000); 00066 } 00067 00068 #ifdef HAVE_QMSYSTEM 00069 void Clock::updateSettings(MeeGo::QmTimeWhatChanged whatChanged) 00070 { 00071 if (whatChanged == MeeGo::QmTimeTimeChanged) { 00072 // Set the time when it was changed (set by the user) 00073 updateModelAndSetupTimer(); 00074 } 00075 } 00076 #endif 00077 00078 void Clock::updateLocaleSettings() 00079 { 00080 MLocale::TimeFormat24h currentFormat = locale->timeFormat24h(); 00081 if (currentFormat == MLocale::LocaleDefaultTimeFormat24h) { 00082 currentFormat = locale->defaultTimeFormat24h(); 00083 } 00084 model()->setTimeFormat24h( 00085 MLocale::TwentyFourHourTimeFormat24h == currentFormat); 00086 } 00087 00088 void Clock::setShortDisplay(bool isShort) { 00089 // Set the short display model field 00090 model()->setShortDisplay(isShort); 00091 } 00092 00093 void Clock::enterDisplayEvent() 00094 { 00095 timer.stop(); 00096 updateModelAndSetupTimer(); 00097 } 00098 00099 void Clock::exitDisplayEvent() 00100 { 00101 timer.stop(); 00102 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:19:34 Doxygen 1.7.1 |
MeeGo Touch |
