-rw-r--r-- | noncore/settings/netsystemtime/TODO | 3 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/main.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 56 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 2 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.cpp | 12 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.h | 9 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 2 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 122 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.h | 8 |
9 files changed, 134 insertions, 82 deletions
diff --git a/noncore/settings/netsystemtime/TODO b/noncore/settings/netsystemtime/TODO new file mode 100644 index 0000000..fb003a2 --- a/dev/null +++ b/noncore/settings/netsystemtime/TODO @@ -0,0 +1,3 @@ +- handle hour > 24 in SetTime::slotClockTick +- improve tz setting + atm the tz gets written to the system as soon as changed... diff --git a/noncore/settings/netsystemtime/main.cpp b/noncore/settings/netsystemtime/main.cpp index c6d5f9a..80fbcb8 100644 --- a/noncore/settings/netsystemtime/main.cpp +++ b/noncore/settings/netsystemtime/main.cpp @@ -1,16 +1,16 @@ #include <stdio.h> #include "ntp.h" #include <qpe/qpeapplication.h> int main( int argc, char ** argv ) { - printf("This is netsystemtime\n"); + printf("This is netsystemtime "); printf("$Id$\n"); QPEApplication a( argc, argv ); Ntp mw; a.showMainWidget( &mw ); return a.exec(); } diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index c7e3b52..53dbe46 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp @@ -39,33 +39,32 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) ntpSrvs.setGroup(QString::number(i)); ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); } if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); Config cfg("ntp",Config::User); cfg.setGroup("settings"); SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); //make tab order - + TabWidgetMain->removePage( tabMain ); TabWidgetMain->removePage( tabManualSetTime ); TabWidgetMain->removePage( TabSettings ); TabWidgetMain->removePage( tabPredict ); TabWidgetMain->removePage( tabNtp ); TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); - TabWidgetMain->insertTab( tabManualSetTime, tr( "Manual" ) ); TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); bool advMode = cfg.readBoolEntry("advancedFeatures", false ); showAdvancedFeatures(advMode); CheckBoxAdvSettings->setChecked( advMode ); connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), SLOT( showAdvancedFeatures( bool ) ) ); @@ -87,24 +86,27 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) connect ( ntpProcess, SIGNAL(processExited(OProcess*)), this, SLOT(ntpFinished(OProcess*))); connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); slotCheckNtp(-1); readLookups(); } Ntp::~Ntp() { delete ntpProcess; +} + +void Ntp::saveConfig(){ int srvCount = ComboNtpSrv->count(); bool serversChanged = true; QString edit = ComboNtpSrv->currentText(); for (int i = 0; i < srvCount; i++){ if ( edit == ComboNtpSrv->text(i)) serversChanged = false; } if (serversChanged){ Config ntpSrvs("/etc/ntpservers",Config::File); ntpSrvs.setGroup("servers"); ntpSrvs.writeEntry("count", srvCount); for (int i = 0; i < srvCount; i++){ qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); @@ -190,38 +192,28 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) _ntpOutput += lineStr; } lineStrOld = lineStr; } void Ntp::ntpFinished(OProcess *p) { qDebug("p->exitStatus() %i",p->exitStatus()); if (p->exitStatus()!=0 || !p->normalExit()) { if ( isVisible() && _interactive ){ QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); - TabWidgetMain->showPage( tabManualSetTime ); } - +// slotCheckNtp(-1); return; } - - Global::writeHWClock(); - // since time has changed quickly load in the datebookdb - // to allow the alarm server to get a better grip on itself - // (example re-trigger alarms for when we travel back in time) - DateBookDB db; - - // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); - // timeApplet << ""; Config cfg("ntp",Config::User); cfg.setGroup("lookups"); int lastLookup = cfg.readNumEntry("time",0); int lookupCount = cfg.readNumEntry("count",0); bool lastNtp = cfg.readBoolEntry("lastNtp",false); int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); cfg.writeEntry("time", time); float timeShift = getTimeShift(); if (timeShift == 0.0) return; int secsSinceLast = time - lastLookup; @@ -297,50 +289,52 @@ void Ntp::readLookups() void Ntp::preditctTime() { Config cfg("ntp",Config::User); cfg.setGroup("lookups"); int lastTime = cfg.readNumEntry("time",0); cfg.writeEntry("lastNtp",true); setenv( "TZ", tz->currentZone(), 1 ); int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); int corr = int((now - lastTime) * _shiftPerSec); TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); predictedTime = QDateTime::currentDateTime().addSecs(corr); TextLabelPredTime->setText(predictedTime.toString()); - TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); +// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); } void Ntp::setPredictTime() { + qDebug("Ntp::setPredictTime"); preditctTime(); - setTime( predictedTime ); + timeButton->setTime( predictedTime ); } void Ntp::slotCheckNtp(int i) { + qDebug(" Ntp::slotCheckNtp(%i)",i); if (i == 0) { - TextLabelMainPredTime->hide(); +// TextLabelMainPredTime->hide(); ButtonSetTime->setText( tr("Get time from network") ); connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); if ( ntpDelayElapsed() ) - { - slotRunNtp(); - disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); - connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); - }else{ - disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); - connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); - } - }else{ + { + slotRunNtp(); + disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); + connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); + }else{ + disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); + connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); + } + }else{ preditctTime(); ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); } } void Ntp::slotProbeNtpServer() { ntpSock->connectToHost( getNtpServer() ,123); } @@ -409,12 +403,24 @@ void Ntp::showAdvancedFeatures(bool advMode) TextLabel1_2_2->hide(); TextLabel2_3->hide(); TextLabel3_3_2->hide(); TextLabel1_2->hide(); SpinBoxMinLookupDelay->hide(); TextLabel2->hide(); TextLabel3_3->hide(); SpinBoxNtpDelay->hide(); Line1->hide(); }; TabWidgetMain->show(); } + + +void Ntp::accept( ){ + qDebug("accepted"); + //SetTimeDate + commitTime(); + writeSettings(); + updateSystem(); + // Ntp + saveConfig(); + qApp->quit(); +}
\ No newline at end of file diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index 15cddbd..a4573f8 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h @@ -11,42 +11,44 @@ class QCopChannel; class Ntp : public SetDateTime { Q_OBJECT public: Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~Ntp(); public slots: void setDocument (const QString &); protected: + virtual void accept( ); QDateTime predictedTime; void makeChannel(); protected slots: void receive(const QCString &msg, const QByteArray &arg); private: QString _ntpOutput; float _shiftPerSec; int _lookupDiff; OProcess *ntpProcess; QTimer *ntpTimer; QSocket *ntpSock; QCopChannel *channel; bool _interactive; float getTimeShift(); void readLookups(); void ntpOutPut(QString); bool ntpDelayElapsed(); QString getNtpServer(); + void saveConfig(); private slots: void slotTimerRunNtp(); void slotButtonRunNtp(); void slotRunNtp(); void getNtpOutput(OProcess *proc, char *buffer, int buflen); void ntpFinished(OProcess*); void preditctTime(); void slotCheckNtp(int); void setPredictTime(); void showAdvancedFeatures(bool); void slotProbeNtpServer(); void slotNtpDelayChanged(int); diff --git a/noncore/settings/netsystemtime/ntpbase.cpp b/noncore/settings/netsystemtime/ntpbase.cpp index 0a7a57e..878c158 100644 --- a/noncore/settings/netsystemtime/ntpbase.cpp +++ b/noncore/settings/netsystemtime/ntpbase.cpp @@ -1,42 +1,46 @@ /**************************************************************************** ** Form implementation generated from reading ui file 'ntpbase.ui' ** -** Created: Sun Nov 10 17:59:14 2002 +** Created: Sat Nov 16 15:49:54 2002 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ #include "ntpbase.h" #include <qcheckbox.h> #include <qcombobox.h> #include <qframe.h> #include <qlabel.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qspinbox.h> #include <qtable.h> #include <qtabwidget.h> +#include <qwidget.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> /* * Constructs a NtpBase which is a child of 'parent', with the * name 'name' and widget flags set to 'f' + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. */ -NtpBase::NtpBase( QWidget* parent, const char* name, WFlags fl ) - : QWidget( parent, name, fl ) +NtpBase::NtpBase( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "NtpBase" ); resize( 317, 411 ); setCaption( tr( "Network Time" ) ); NtpBaseLayout = new QGridLayout( this ); NtpBaseLayout->setSpacing( 2 ); NtpBaseLayout->setMargin( 2 ); TabWidgetMain = new QTabWidget( this, "TabWidgetMain" ); tabMain = new QWidget( TabWidgetMain, "tabMain" ); @@ -308,24 +312,24 @@ NtpBase::NtpBase( QWidget* parent, const char* name, WFlags fl ) */ NtpBase::~NtpBase() { // no need to delete child widgets, Qt does it all for us } /* * Main event handler. Reimplemented to handle application * font changes */ bool NtpBase::event( QEvent* ev ) { - bool ret = QWidget::event( ev ); + bool ret = QDialog::event( ev ); if ( ev->type() == QEvent::ApplicationFontChange ) { QFont MultiLineEditntpOutPut_font( MultiLineEditntpOutPut->font() ); MultiLineEditntpOutPut_font.setPointSize( 7 ); MultiLineEditntpOutPut->setFont( MultiLineEditntpOutPut_font ); QFont TableLookups_font( TableLookups->font() ); TableLookups_font.setPointSize( 8 ); TableLookups->setFont( TableLookups_font ); } return ret; } diff --git a/noncore/settings/netsystemtime/ntpbase.h b/noncore/settings/netsystemtime/ntpbase.h index 543cac1..68599c9 100644 --- a/noncore/settings/netsystemtime/ntpbase.h +++ b/noncore/settings/netsystemtime/ntpbase.h @@ -1,44 +1,45 @@ /**************************************************************************** ** Form interface generated from reading ui file 'ntpbase.ui' ** -** Created: Sun Nov 10 17:58:48 2002 +** Created: Sat Nov 16 15:49:32 2002 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ #ifndef NTPBASE_H #define NTPBASE_H #include <qvariant.h> -#include <qwidget.h> +#include <qdialog.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QCheckBox; class QComboBox; class QFrame; class QLabel; class QMultiLineEdit; class QPushButton; class QSpinBox; class QTabWidget; class QTable; +class QWidget; -class NtpBase : public QWidget +class NtpBase : public QDialog { Q_OBJECT public: - NtpBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + NtpBase( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); ~NtpBase(); QTabWidget* TabWidgetMain; QWidget* tabMain; QFrame* FrameSystemTime; QWidget* tabNtp; QPushButton* runNtp; QWidget* FrameNtp; QLabel* TextLabel1; QLabel* TextLabelStartTime; QLabel* TextLabel3; QLabel* TextLabelTimeShift; diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui index 6c38588..8c106be 100644 --- a/noncore/settings/netsystemtime/ntpbase.ui +++ b/noncore/settings/netsystemtime/ntpbase.ui @@ -1,16 +1,16 @@ <!DOCTYPE UI><UI> <class>NtpBase</class> <widget> - <class>QWidget</class> + <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>NtpBase</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>317</width> <height>411</height> </rect> diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 949fcb3..36166ae 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp @@ -26,77 +26,83 @@ #include <qpe/datebookdb.h> #include <qpe/datebookmonth.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qpe/timeconversion.h> #include <qpe/tzselect.h> #include <qpe/timestring.h> #include <qpe/qpedialog.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif +#include <qtimer.h> #include <qbuttongroup.h> #include <qcheckbox.h> #include <qlabel.h> #include <qlayout.h> #include <qradiobutton.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qwindowsystem_qws.h> #include <qcombobox.h> #include <sys/time.h> #include <time.h> #include <stdlib.h> #include <stdio.h> SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) - : NtpBase( parent, name, f ) + : NtpBase( parent, name, true, f ) { - // setCaption( tr("Set System Time") ); + setCaption( tr("System Time") ); -// QVBoxLayout *vb = new QVBoxLayout( this, 5 ); QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); - QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 ); - TextLabelMainPredTime = new QLabel( FrameSystemTime ); - vb->addWidget( TextLabelMainPredTime, 1, 0 ); +// TextLabelMainPredTime = new QLabel( FrameSystemTime ); +// vb->addWidget( TextLabelMainPredTime, 1, 0 ); - QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); + timeButton = new SetTime( FrameSystemTime ); + vb->addWidget( timeButton ); + + QHBoxLayout *db = new QHBoxLayout( vb ); + QLabel *dateLabel = new QLabel( tr("Date"), FrameSystemTime ); + db->addWidget( dateLabel, 1 ); + dateButton = new DateButton( TRUE, FrameSystemTime ); + db->addWidget( dateButton, 2 ); + ButtonSetTime = new QPushButton( FrameSystemTime ); + vb->addWidget( ButtonSetTime, 1, 0 ); + + QFrame *hline = new QFrame( FrameSystemTime ); + hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); + vb->addWidget( hline ); + + QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); + QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); lblZone->setMaximumSize( lblZone->sizeHint() ); hb->addWidget( lblZone ); tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); tz->setMinimumSize( tz->sizeHint() ); - hb->addWidget( tz ); - - timeButton = new SetTime( FrameSetTime ); - vb2->addWidget( timeButton ); - - QHBoxLayout *db = new QHBoxLayout( vb2 ); - QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime ); - db->addWidget( dateLabel, 1 ); - dateButton = new DateButton( TRUE, FrameSetTime ); - db->addWidget( dateButton, 2 ); - - QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); - vb2->addItem( spacer ); + hb->addWidget( tz ); - QFrame *hline = new QFrame( FrameSystemTime ); + hline = new QFrame( FrameSystemTime ); hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); vb->addWidget( hline ); + + QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); + vb->addItem( spacer ); Config config("qpe"); config.setGroup( "Time" ); QHBoxLayout *hb1 = new QHBoxLayout( vb ); QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); hb1->addWidget( l, 1 ); ampmCombo = new QComboBox( FrameSystemTime ); ampmCombo->insertItem( tr("24 hour"), 0 ); @@ -170,53 +176,49 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) clockAppletCombo = new QComboBox( FrameSystemTime ); clockAppletCombo->insertItem( tr("hh:mm"), 0 ); clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); hb4->addWidget( clockAppletCombo, 2 ); int clockApplet = config.readNumEntry("ClockApplet",0); clockAppletCombo->setCurrentItem( clockApplet ); vb->addStretch( 0 ); - hline = new QFrame( FrameSystemTime ); - hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); - vb->addWidget( hline ); +// hline = new QFrame( FrameSystemTime ); +// hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); +// vb->addWidget( hline ); +// +// ButtonSetTime = new QPushButton( FrameSystemTime ); +// vb->addWidget( ButtonSetTime, 1, 0 ); - ButtonSetTime = new QPushButton( FrameSystemTime ); - vb->addWidget( ButtonSetTime, 1, 0 ); - - QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), - this, SLOT(commitTime())); QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), timeButton, SLOT( slotTzChange( const QString& ) ) ); QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), SLOT( tzChange( const QString& ) ) ); - QObject::connect( weekStartCombo, SIGNAL( activated ( int )), - SLOT(updateSystem(int ) )); - QObject::connect( ampmCombo, SIGNAL( activated ( int )), - SLOT(updateSystem(int ) )); - QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), - SLOT(updateSystem(int ) )); - QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), - SLOT(updateSystem(int ) )); +// QObject::connect( weekStartCombo, SIGNAL( activated ( int )), +// SLOT(updateSystem(int ) )); +// QObject::connect( ampmCombo, SIGNAL( activated ( int )), +// SLOT(updateSystem(int ) )); +// QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), +// SLOT(updateSystem(int ) )); +// QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), +// SLOT(updateSystem(int ) )); } SetDateTime::~SetDateTime() { - writeSettings(); - } void SetDateTime::writeSettings() { Config config("qpe"); config.setGroup( "Time" ); config.writeEntry( "AMPM", ampmCombo->currentItem() ); config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); config.setGroup( "Date" ); DateFormat df = date_formats[dateFormatCombo->currentItem()]; config.writeEntry( "Separator", QString(df.separator())); config.writeEntry( "ShortOrder", df.shortOrder()); @@ -267,33 +269,33 @@ void SetDateTime::setTime(QDateTime dt) Global::writeHWClock(); // since time has changed quickly load in the datebookdb // to allow the alarm server to get a better grip on itself // (example re-trigger alarms for when we travel back in time) DateBookDB db; //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); //timeApplet << ""; // Restore screensaver QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); enableScreenSaver << -1 << -1 << -1; } -void SetDateTime::updateSystem(int i) +void SetDateTime::updateSystem() { // really turn off the screensaver before doing anything { // Needs to be encased in { } so that it deconstructs and sends QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); disableScreenSaver << 0 << 0 << 0; } - qDebug("SetDateTime::updateSystem(int %i)",i); + qDebug("SetDateTime::updateSystem()"); writeSettings(); // set the timezone for everyone else... QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); setTimeZone << tz->currentZone(); // AM/PM setting and notify time changed QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); setClock << ampmCombo->currentItem(); // Notify everyone what day we prefer to start the week on. QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); @@ -314,48 +316,52 @@ void SetDateTime::updateSystem(int i) } void SetDateTime::tzChange( const QString &tz ) { // set the TZ get the time and leave gracefully... QString strSave; strSave = getenv( "TZ" ); setenv( "TZ", tz, 1 ); QDate d = QDate::currentDate(); // reset the time. if ( !strSave.isNull() ) { - setenv( "TZ", strSave, 1 ); + setenv( "TZ", strSave, 1 ); } dateButton->setDate( d ); updateSystem(); } void SetDateTime::formatChanged(int i) { dateButton->setDateFormat(date_formats[i]); } static const int ValueAM = 0; static const int ValuePM = 1; SetTime::SetTime( QWidget *parent, const char *name ) : QWidget( parent, name ) { + clock = new QTimer(this, "clock" ); + connect(clock, SIGNAL( timeout() ), SLOT(slotClockTick()) ); + clock->start( 1000 * 60 ); + use12hourTime = FALSE; - QTime currTime = QTime::currentTime(); - hour = currTime.hour(); - minute = currTime.minute(); + _time = QDateTime::currentDateTime(); + hour = _time.time().hour(); + minute = _time.time().minute(); QHBoxLayout *hb2 = new QHBoxLayout( this ); hb2->setSpacing( 3 ); QLabel *l = new QLabel( tr("Hour"), this ); // l->setAlignment( AlignRight | AlignVCenter ); hb2->addWidget( l ); sbHour = new QSpinBox( this ); sbHour->setMinimumWidth( 30 ); if(use12hourTime) { sbHour->setMinValue(1); @@ -490,13 +496,39 @@ void SetTime::slotTzChange( const QString &tz ) } else { ampm->setCurrentItem( ValueAM ); } if (show_hour == 0) show_hour = 12; sbHour->setValue( show_hour ); } else { sbHour->setValue( t.hour() ); } sbMin->setValue( t.minute() ); } +void SetTime::setTime( QDateTime dt ) +{ + _time = dt; + QTime t = dt.time(); + // just set the spinboxes and let it propage through + if(use12hourTime) { + int show_hour = t.hour(); + if (t.hour() >= 12) { + show_hour -= 12; + ampm->setCurrentItem( ValuePM ); + } else { + ampm->setCurrentItem( ValueAM ); + } + if (show_hour == 0) + show_hour = 12; + sbHour->setValue( show_hour ); + } else { + sbHour->setValue( t.hour() ); + } + sbMin->setValue( t.minute() ); +} +void SetTime::slotClockTick() +{ + setTime( _time.addSecs(60) ); + qDebug("SetTime::slotClockTick %s",_time.toString().latin1()); +} diff --git a/noncore/settings/netsystemtime/settime.h b/noncore/settings/netsystemtime/settime.h index 778cb9c..3c3a162 100644 --- a/noncore/settings/netsystemtime/settime.h +++ b/noncore/settings/netsystemtime/settime.h @@ -32,67 +32,71 @@ class QSpinBox; class QLabel; class TimeZoneSelector; class DateBookMonth; class QComboBox; class SetTime : public QWidget { Q_OBJECT public: SetTime( QWidget *parent=0, const char *name=0 ); QTime time() const; + void setTime( QDateTime ); public slots: void slotTzChange( const QString& tz ); void show12hourTime( int ); protected slots: + void slotClockTick(); void hourChanged( int value ); void minuteChanged( int value ); void checkedPM( int ); protected: int hour; int minute; bool use12hourTime; + QDateTime _time; + QTimer *clock; QComboBox *ampm; QSpinBox *sbHour; QSpinBox *sbMin; }; class DateButton; class SetDateTime : public NtpBase { Q_OBJECT public: SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 ); ~SetDateTime(); protected slots: void commitTime(); void tzChange( const QString &tz ); void formatChanged(int); - void updateSystem(int i=0); + void updateSystem(); protected: void setTime(QDateTime dt); void writeSettings(); SetTime *timeButton; DateButton *dateButton; TimeZoneSelector *tz; QComboBox *weekStartCombo; QComboBox *ampmCombo; QComboBox *dateFormatCombo; QComboBox *clockAppletCombo; QPushButton *ButtonSetTime; - QLabel *TextLabelMainPredTime; + // QLabel *TextLabelMainPredTime; DateFormat date_formats[4]; }; #endif |