📄 settime.cpp
字号:
myTv.tv_sec = TimeConversion::toUTC( dt ); myTv.tv_usec = 0; if ( myTv.tv_sec != -1 ) ::settimeofday( &myTv, 0 ); Global::writeHWClock(); // Should leave updating alarms to datebook, rather than screw it up // via duplicated functionality. // DateBookDB is flawed, it should not be used anywhere. } else { qWarning( "Invalid date/time" ); } // set the timezone for everyone else...#ifndef QT_NO_COP QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); setTimeZone << tz->currentZone();#endif } // AM/PM setting and notify time changed#ifndef QT_NO_COP if ( ampmChange ) { QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); setClock << ampmCombo->currentItem(); }#endif // Notify everyone what day we prefer to start the week on.#ifndef QT_NO_COP if ( monSunChange ) { QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); setWeek << weekStartCombo->currentItem(); }#endif // Notify everyone what date format to use#ifndef QT_NO_COP QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); setDateFormat << date_formats[dateFormatCombo->currentItem()];#endif // Restore screensaver#ifndef QT_NO_COP QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); enableScreenSaver << -1 << -1 << -1;#endif QDialog::accept();}void SetDateTime::done(int r){ QDialog::done(r); close();}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 ); } date->setDate( d ); tzChanged = TRUE;}void SetDateTime::formatChanged(int i){ date->setDateFormat(date_formats[i]);}void SetDateTime::weekStartChanged(int s){ date->setWeekStartsMonday(s==1);}void SetDateTime::dateChange( const QDate & ){ dateChanged = TRUE;}//===========================================================================static const int ValueAM = 0;static const int ValuePM = 1;SetTime::SetTime( QWidget *parent, const char *name ) : QWidget( parent, name ){ use12hourTime = FALSE; QTime currTime = QTime::currentTime(); hour = currTime.hour(); minute = currTime.minute(); QHBoxLayout *hb2 = new QHBoxLayout( this ); hb2->setSpacing( 3 ); QLabel *l = new QLabel( tr("Time"), this ); // l->setAlignment( AlignRight | AlignVCenter ); hb2->addWidget( l ); sbHour = new QSpinBox( this ); sbHour->setMinimumWidth( 30 ); if(use12hourTime) { sbHour->setMinValue(1); sbHour->setMaxValue( 12 ); int show_hour = hour; if (hour > 12) show_hour -= 12; if (show_hour == 0) show_hour = 12; sbHour->setValue( show_hour ); } else { sbHour->setMinValue( 0 ); sbHour->setMaxValue( 23 ); sbHour->setValue( hour ); } sbHour->setWrapping(TRUE); connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); hb2->addWidget( sbHour ); hb2->addStretch( 1 ); l = new QLabel( tr(":"), this ); //l->setAlignment( AlignRight | AlignVCenter ); hb2->addWidget( l ); sbMin = new QSpinBox( this ); sbMin->setMinValue( 0 ); sbMin->setMaxValue( 59 ); sbMin->setWrapping(TRUE); sbMin->setValue( minute ); minuteChanged(minute); sbMin->setMinimumWidth( 30 ); connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); hb2->addWidget( sbMin ); hb2->addStretch( 1 ); ampm = new QComboBox( this ); ampm->insertItem( tr("AM"), ValueAM ); ampm->insertItem( tr("PM"), ValuePM ); connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); hb2->addWidget( ampm ); hb2->addStretch( 1 ); userChanged = FALSE;}QTime SetTime::time() const{ return QTime( hour, minute, 0 );}void SetTime::focusInEvent( QFocusEvent *e ){ QWidget::focusInEvent( e ); sbHour->setFocus();#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) { if( sbHour->isModalEditing() ) sbHour->setModalEditing( TRUE ); }#endif}void SetTime::hourChanged( int value ){ if(use12hourTime) { int realhour = value; if (realhour == 12) realhour = 0; if (ampm->currentItem() == ValuePM ) realhour += 12; hour = realhour; } else hour = value; userChanged = TRUE;}void SetTime::minuteChanged( int value ){ sbMin->setPrefix( value <= 9 ? "0" : "" ); minute = value; userChanged = TRUE;}void SetTime::show12hourTime( int on ){ bool uc = userChanged; use12hourTime = on; ampm->setEnabled(on); int show_hour = hour; if ( on ) { /* this might change the value of hour */ sbHour->setMinValue(1); sbHour->setMaxValue( 12 ); /* so use one we saved earlier */ if (show_hour >= 12) { show_hour -= 12; ampm->setCurrentItem( ValuePM ); } else { ampm->setCurrentItem( ValueAM ); } if (show_hour == 0) show_hour = 12; } else { sbHour->setMinValue( 0 ); sbHour->setMaxValue( 23 ); } sbHour->setValue( show_hour ); userChanged = uc;}void SetTime::checkedPM( int c ){ int show_hour = sbHour->value(); if (show_hour == 12) show_hour = 0; if ( c == ValuePM ) show_hour += 12; hour = show_hour; userChanged = TRUE;}void SetTime::slotTzChange( const QString &tz ){ // set the TZ, get the time and leave gracefully... QString strSave; strSave = getenv( "TZ" ); setenv( "TZ", tz, 1 ); QTime t = QTime::currentTime(); // reset the time. if ( !strSave.isNull() ) { setenv( "TZ", strSave, 1 ); } // just set the spinboxes and let it propagate 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() ); userChanged = TRUE;}/*SetDate::SetDate( QWidget *parent, const char *name ) : QWidget( parent, name ){ QHBoxLayout *hb = new QHBoxLayout( this ); dbm = new DateBookMonth( this ); hb->addWidget( dbm );}QDate SetDate::date() const{ return dbm->selectedDate();}void SetDate::slotTzChange( 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 ); } dbm->setDate( d.year(), d.month(), d.day() );}void SetDate::slotWeekChange( int startOnMonday ){ dbm->slotWeekChange( startOnMonday );}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -