00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "formattabwidget.h"
00032
00033 #include <qpe/config.h>
00034
00035 #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
00036 #include <qpe/qcopenvelope_qws.h>
00037 #endif
00038
00039 #include <qcombobox.h>
00040 #include <qlabel.h>
00041 #include <qlayout.h>
00042 #include <qscrollview.h>
00043 #include <qtimer.h>
00044
00045 FormatTabWidget::FormatTabWidget( QWidget *parent )
00046 : QWidget( parent, 0x0, 0 )
00047 {
00048 QVBoxLayout *tmpvb = new QVBoxLayout( this );
00049 QScrollView *sv = new QScrollView( this );
00050 tmpvb->addWidget( sv, 0, 0 );
00051 sv->setResizePolicy( QScrollView::AutoOneFit );
00052 sv->setFrameStyle( QFrame::NoFrame );
00053 QWidget *container = new QWidget( sv->viewport() );
00054 sv->addChild( container );
00055
00056 QGridLayout *layout = new QGridLayout( container );
00057 layout->setMargin( 2 );
00058 layout->setSpacing( 4 );
00059
00060
00061 layout->addWidget( new QLabel( tr( "Time format" ), container ), 0, 0 );
00062 cbAppletFormat = new QComboBox( container );
00063 cbAppletFormat->insertItem( tr( "hh:mm" ), 0 );
00064 cbAppletFormat->insertItem( tr( "D/M hh:mm" ), 1 );
00065 cbAppletFormat->insertItem( tr( "M/D hh:mm" ), 2 );
00066 layout->addWidget( cbAppletFormat, 0, 1 );
00067
00068
00069 layout->addWidget( new QLabel( tr( "12/24 hour" ), container ), 1, 0 );
00070 cbAmpm = new QComboBox( container );
00071 cbAmpm->insertItem( tr( "24 hour" ), 0 );
00072 cbAmpm->insertItem( tr( "12 hour" ), 1 );
00073 connect( cbAmpm, SIGNAL(activated(int)), this, SIGNAL(show12HourTime(int)) );
00074 layout->addWidget( cbAmpm, 1, 1 );
00075
00076
00077 layout->addWidget( new QLabel( tr( "Date format" ), container ), 2, 0 );
00078 cbDateFormat = new QComboBox( container );
00079 connect( cbDateFormat, SIGNAL(activated(int)), this, SLOT(slotDateFormatChanged(int)) );
00080 layout->addWidget( cbDateFormat, 2, 1 );
00081
00082
00083 layout->addWidget( new QLabel( tr( "Weeks start on" ), container ), 3, 0 );
00084 cbWeekStart = new QComboBox( container );
00085 cbWeekStart->insertItem( tr( "Sunday" ), 0 );
00086 cbWeekStart->insertItem( tr( "Monday" ), 1 );
00087 connect( cbWeekStart, SIGNAL(activated(int)), this, SIGNAL(weekStartChanged(int)) );
00088 layout->addWidget( cbWeekStart, 3, 1 );
00089
00090
00091 Config config( "qpe" );
00092 config.setGroup( "Date" );
00093 cbAppletFormat->setCurrentItem( config.readNumEntry( "ClockApplet", 0 ) );
00094
00095 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
00096 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
00097 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
00098
00099 int currentdf = 0;
00100 date_formats[0] = DateFormat( '/', DateFormat::MonthDayYear );
00101 cbDateFormat->insertItem( tr( date_formats[0].toNumberString() ) );
00102 date_formats[1] = DateFormat( '.', DateFormat::DayMonthYear );
00103 if ( df == date_formats[1] )
00104 currentdf = 1;
00105 cbDateFormat->insertItem( tr( date_formats[1].toNumberString() ) );
00106 date_formats[2] = DateFormat( '-', DateFormat::YearMonthDay, DateFormat::DayMonthYear );
00107 if ( df == date_formats[2] )
00108 currentdf = 2;
00109 cbDateFormat->insertItem( tr( date_formats[2].toNumberString() ) );
00110 date_formats[3] = DateFormat( '/', DateFormat::DayMonthYear );
00111 if ( df == date_formats[3] )
00112 currentdf = 3;
00113 cbDateFormat->insertItem( tr( date_formats[3].toNumberString() ) );
00114
00115 cbDateFormat->setCurrentItem( currentdf );
00116
00117
00118 config.setGroup( "Time" );
00119 cbAmpm->setCurrentItem( config.readBoolEntry( "AMPM", FALSE ) ? 1 : 0 );
00120 cbWeekStart->setCurrentItem( config.readBoolEntry( "MONDAY", TRUE ) ? 1 : 0 );
00121
00122
00123 QTimer::singleShot( 1200, this, SLOT(sendOptions()) );
00124 }
00125
00126 FormatTabWidget::~FormatTabWidget()
00127 {
00128 }
00129
00130 void FormatTabWidget::saveSettings( bool commit )
00131 {
00132 int ampm = cbAmpm->currentItem();
00133 int weekstart = cbWeekStart->currentItem();
00134 DateFormat df = date_formats[cbDateFormat->currentItem()];
00135 int appletformat = cbAppletFormat->currentItem();
00136
00137 if ( commit )
00138 {
00139
00140 Config config("qpe");
00141 config.setGroup( "Time" );
00142 config.writeEntry( "AMPM", ampm );
00143 config.writeEntry( "MONDAY", weekstart );
00144 config.setGroup( "Date" );
00145 config.writeEntry( "Separator", QString( df.separator() ) );
00146 config.writeEntry( "ShortOrder", df.shortOrder() );
00147 config.writeEntry( "LongOrder", df.longOrder() );
00148 config.writeEntry( "ClockApplet", appletformat );
00149 }
00150
00151
00152 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
00153 setClock << ampm;
00154 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
00155 setWeek << weekstart;
00156 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
00157 setDateFormat << df;
00158 }
00159
00160 void FormatTabWidget::slotDateFormatChanged( int selected )
00161 {
00162 emit dateFormatChanged( date_formats[selected] );
00163 }
00164
00165 void FormatTabWidget::sendOptions()
00166 {
00167 emit show12HourTime( cbAmpm->currentItem() );
00168 emit dateFormatChanged( date_formats[cbDateFormat->currentItem()] );
00169 emit weekStartChanged( cbWeekStart->currentItem() );
00170 }