author | paule <paule> | 2007-01-14 03:02:55 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-14 03:02:55 (UTC) |
commit | ca67251af3f46d685afac8dc6bfe452799c2546e (patch) (side-by-side diff) | |
tree | 3e7ae7ed8d06e97c5556b52c5cf3826426cedd9b | |
parent | 81de0baf254bd2d935d0fdf035143e5510354fa7 (diff) | |
download | opie-ca67251af3f46d685afac8dc6bfe452799c2546e.zip opie-ca67251af3f46d685afac8dc6bfe452799c2546e.tar.gz opie-ca67251af3f46d685afac8dc6bfe452799c2546e.tar.bz2 |
When selecting a time zone, warn the user if the time zone file in /usr/share/zoneinfo for the selected time zone is missing
-rw-r--r-- | noncore/settings/netsystemtime/timetabwidget.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp index bcfbdf7..895514b 100644 --- a/noncore/settings/netsystemtime/timetabwidget.cpp +++ b/noncore/settings/netsystemtime/timetabwidget.cpp @@ -21,64 +21,66 @@ ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "timetabwidget.h" #include <opie2/oresource.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/datebookmonth.h> #include <qpe/global.h> #include <qpe/tzselect.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #include <qcombobox.h> #include <qdatetime.h> #include <qframe.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> #include <qscrollview.h> #include <qspinbox.h> +#include <qmessagebox.h> +#include <qfile.h> #include <stdlib.h> #include <sys/time.h> static const int ValueAM = 0; static const int ValuePM = 1; TimeTabWidget::TimeTabWidget( QWidget *parent ) : QWidget( parent, 0x0, 0 ) { // Synchronize HW clock to systemtime // This app will update systemtime // - if Cancel is clicked, will reset systemtime to HW clock's time // - if Ok is clicked, will leave systemtime as is system("/sbin/hwclock --systohc --utc"); QVBoxLayout *tmpvb = new QVBoxLayout( this ); QScrollView *sv = new QScrollView( this ); tmpvb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Hours layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); sbHour = new QSpinBox( container ); sbHour->setWrapping( TRUE ); @@ -248,62 +250,69 @@ void TimeTabWidget::slotUse12HourTime( int i ) } if ( show_hour == 0 ) show_hour = 12; } else { sbHour->setMinValue( 0 ); sbHour->setMaxValue( 23 ); if ( cbAmpm->currentItem() == ValuePM ) { show_hour += 12; if ( show_hour == 24 ) show_hour = 0; } } sbHour->setValue( show_hour ); } void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) { btnDate->setDateFormat( df ); } void TimeTabWidget::slotWeekStartChanged( int monday ) { btnDate->setWeekStartsMonday( monday ); } void TimeTabWidget::slotTZChanged( const QString &newtz ) { - // If controls have a valid date & time, update systemtime - int hour = sbHour->value(); - if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) - hour += 12; - QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); - setSystemTime( dt ); - QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); - setTimeZone << newtz; - - // Set system timezone - QString currtz = getenv( "TZ" ); - setenv( "TZ", newtz, 1 ); - - // Get new date/time - hour = sbHour->value(); - if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) - hour += 12; - dt = QDateTime::currentDateTime(); - - // Reset system timezone - if ( !currtz.isNull() ) - { - setenv( "TZ", currtz, 1 ); + // Check timezone has a valid file in /usr/share/zoneinfo + if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) { + QMessageBox::warning(this, tr("Time zone file missing"), + (tr("There is no time zone file for the\nselected time zone (%1).\nYou will need to install it before the\nsystem time zone can be set correctly.")).arg(newtz)); } + else { + // If controls have a valid date & time, update systemtime + int hour = sbHour->value(); + if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) + hour += 12; + QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); + setSystemTime( dt ); + QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); + setTimeZone << newtz; - // Set controls to new time - setDateTime( dt ); + // Set system timezone + QString currtz = getenv( "TZ" ); + setenv( "TZ", newtz, 1 ); - emit tzChanged( newtz ); + // Get new date/time + hour = sbHour->value(); + if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) + hour += 12; + dt = QDateTime::currentDateTime(); + + // Reset system timezone + if ( !currtz.isNull() ) + { + setenv( "TZ", currtz, 1 ); + } + + // Set controls to new time + setDateTime( dt ); + + emit tzChanged( newtz ); + } } |