Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

formattabwidget.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
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         // Time format selector
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         // 12/24 hour selector
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         // Date format selector
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         // Week starts on selector
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         // Initialize values
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() ) ); //ISO8601
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         //dateButton->setDateFormat( df );
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         // Send initial configuration options
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                 // Write settings to config file
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         // Make rest of system aware of new settings
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 }

Generated on Sat Nov 5 16:17:48 2005 for OPIE by  doxygen 1.4.2