summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/settime.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/netsystemtime/settime.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/settime.cpp122
1 files changed, 77 insertions, 45 deletions
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());
+}