summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/formattabwidget.cpp
Unidiff
Diffstat (limited to 'noncore/settings/netsystemtime/formattabwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/formattabwidget.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/noncore/settings/netsystemtime/formattabwidget.cpp b/noncore/settings/netsystemtime/formattabwidget.cpp
new file mode 100644
index 0000000..daa020f
--- a/dev/null
+++ b/noncore/settings/netsystemtime/formattabwidget.cpp
@@ -0,0 +1,168 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "formattabwidget.h"
30
31#include <qpe/config.h>
32
33#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
34#include <qpe/qcopenvelope_qws.h>
35#endif
36
37#include <qcombobox.h>
38#include <qlabel.h>
39#include <qlayout.h>
40#include <qscrollview.h>
41#include <qtimer.h>
42
43FormatTabWidget::FormatTabWidget( QWidget *parent )
44 : QWidget( parent, 0x0, 0 )
45{
46 QVBoxLayout *tmpvb = new QVBoxLayout( this );
47 QScrollView *sv = new QScrollView( this );
48 tmpvb->addWidget( sv, 0, 0 );
49 sv->setResizePolicy( QScrollView::AutoOneFit );
50 sv->setFrameStyle( QFrame::NoFrame );
51 QWidget *container = new QWidget( sv->viewport() );
52 sv->addChild( container );
53
54 QGridLayout *layout = new QGridLayout( container );
55 layout->setMargin( 2 );
56 layout->setSpacing( 4 );
57
58 // Time format selector
59 layout->addWidget( new QLabel( tr( "Time format" ), container ), 0, 0 );
60 cbAppletFormat = new QComboBox( container );
61 cbAppletFormat->insertItem( tr( "hh:mm" ), 0 );
62 cbAppletFormat->insertItem( tr( "D/M hh:mm" ), 1 );
63 cbAppletFormat->insertItem( tr( "M/D hh:mm" ), 2 );
64 layout->addWidget( cbAppletFormat, 0, 1 );
65
66 // 12/24 hour selector
67 layout->addWidget( new QLabel( tr( "12/24 hour" ), container ), 1, 0 );
68 cbAmpm = new QComboBox( container );
69 cbAmpm->insertItem( tr( "24 hour" ), 0 );
70 cbAmpm->insertItem( tr( "12 hour" ), 1 );
71 connect( cbAmpm, SIGNAL(activated(int)), this, SIGNAL(show12HourTime(int)) );
72 layout->addWidget( cbAmpm, 1, 1 );
73
74 // Date format selector
75 layout->addWidget( new QLabel( tr( "Date format" ), container ), 2, 0 );
76 cbDateFormat = new QComboBox( container );
77 connect( cbDateFormat, SIGNAL(activated(int)), this, SLOT(slotDateFormatChanged(int)) );
78 layout->addWidget( cbDateFormat, 2, 1 );
79
80 // Week starts on selector
81 layout->addWidget( new QLabel( tr( "Weeks start on" ), container ), 3, 0 );
82 cbWeekStart = new QComboBox( container );
83 cbWeekStart->insertItem( tr( "Sunday" ), 0 );
84 cbWeekStart->insertItem( tr( "Monday" ), 1 );
85 connect( cbWeekStart, SIGNAL(activated(int)), this, SIGNAL(weekStartChanged(int)) );
86 layout->addWidget( cbWeekStart, 3, 1 );
87
88 // Initialize values
89 Config config( "qpe" );
90 config.setGroup( "Date" );
91 cbAppletFormat->setCurrentItem( config.readNumEntry( "ClockApplet", 0 ) );
92
93 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
94 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
95 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
96
97 int currentdf = 0;
98 date_formats[0] = DateFormat( '/', DateFormat::MonthDayYear );
99 cbDateFormat->insertItem( tr( date_formats[0].toNumberString() ) );
100 date_formats[1] = DateFormat( '.', DateFormat::DayMonthYear );
101 if ( df == date_formats[1] )
102 currentdf = 1;
103 cbDateFormat->insertItem( tr( date_formats[1].toNumberString() ) );
104 date_formats[2] = DateFormat( '-', DateFormat::YearMonthDay, DateFormat::DayMonthYear );
105 if ( df == date_formats[2] )
106 currentdf = 2;
107 cbDateFormat->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
108 date_formats[3] = DateFormat( '/', DateFormat::DayMonthYear );
109 if ( df == date_formats[3] )
110 currentdf = 3;
111 cbDateFormat->insertItem( tr( date_formats[3].toNumberString() ) );
112
113 cbDateFormat->setCurrentItem( currentdf );
114 //dateButton->setDateFormat( df );
115
116 config.setGroup( "Time" );
117 cbAmpm->setCurrentItem( config.readBoolEntry( "AMPM" ) ? 1 : 0 );
118 cbWeekStart->setCurrentItem( config.readBoolEntry( "MONDAY" ) ? 1 : 0 );
119
120 // Send initial configuration options
121 QTimer::singleShot( 1200, this, SLOT(sendOptions()) );
122}
123
124FormatTabWidget::~FormatTabWidget()
125{
126}
127
128void FormatTabWidget::saveSettings( bool commit )
129{
130 int ampm = cbAmpm->currentItem();
131 int weekstart = cbWeekStart->currentItem();
132 DateFormat df = date_formats[cbDateFormat->currentItem()];
133 int appletformat = cbAppletFormat->currentItem();
134
135 if ( commit )
136 {
137 // Write settings to config file
138 Config config("qpe");
139 config.setGroup( "Time" );
140 config.writeEntry( "AMPM", ampm );
141 config.writeEntry( "MONDAY", weekstart );
142 config.setGroup( "Date" );
143 config.writeEntry( "Separator", QString( df.separator() ) );
144 config.writeEntry( "ShortOrder", df.shortOrder() );
145 config.writeEntry( "LongOrder", df.longOrder() );
146 config.writeEntry( "ClockApplet", appletformat );
147 }
148
149 // Make rest of system aware of new settings
150 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
151 setClock << ampm;
152 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
153 setWeek << weekstart;
154 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
155 setDateFormat << df;
156}
157
158void FormatTabWidget::slotDateFormatChanged( int selected )
159{
160 emit dateFormatChanged( date_formats[selected] );
161}
162
163void FormatTabWidget::sendOptions()
164{
165 emit show12HourTime( cbAmpm->currentItem() );
166 emit dateFormatChanged( date_formats[cbDateFormat->currentItem()] );
167 emit weekStartChanged( cbWeekStart->currentItem() );
168}