2
Copyright (C) 2007 Bruno Virlet <bruno.virlet@gmail.com>
3
Copyright 2008-2009 Allen Winter <winter@kde.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program; if not, write to the Free Software Foundation, Inc.,
17
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "ktimezonecombobox.h"
22
#include <KCalCore/ICalTimeZones>
27
#include <KSystemTimeZone>
29
using namespace IncidenceEditorNG;
31
class KTimeZoneComboBox::Private
34
Private( KTimeZoneComboBox *parent )
35
: mParent( parent ), mAdditionalZones( 0 )
39
KTimeZoneComboBox *const mParent;
41
const KCalCore::ICalTimeZones *mAdditionalZones;
44
void KTimeZoneComboBox::Private::fillComboBox()
47
// Read all system time zones
49
const KTimeZones::ZoneMap timezones = KSystemTimeZones::zones();
50
for ( KTimeZones::ZoneMap::ConstIterator it=timezones.begin(); it != timezones.end(); ++it ) {
51
mZones.append( it.key().toUtf8() );
55
// Prepend the list of additional timezones
56
if ( mAdditionalZones ) {
57
const KCalCore::ICalTimeZones::ZoneMap calzones = mAdditionalZones->zones();
58
for ( KCalCore::ICalTimeZones::ZoneMap::ConstIterator it=calzones.begin();
59
it != calzones.end(); ++it ) {
60
kDebug() << "Prepend timezone " << it.key().toUtf8();
61
mZones.prepend( it.key().toUtf8() );
64
// Prepend UTC and Floating, for convenience
65
mZones.prepend( "UTC" ); // do not use i18n here
66
mZones.prepend( "Floating" ); // do not use i18n here
68
// Put translated zones into the combobox
69
foreach ( const QString &z, mZones ) {
70
mParent->addItem( i18n( z.toUtf8() ).replace( '_', ' ' ) );
74
KTimeZoneComboBox::KTimeZoneComboBox( QWidget *parent )
75
: KComboBox( parent ), d( new KTimeZoneComboBox::Private( this ) )
77
KGlobal::locale()->insertCatalog( "timezones4" ); // for translated timezones
81
KTimeZoneComboBox::KTimeZoneComboBox( const KCalCore::ICalTimeZones *zones, QWidget *parent )
82
: KComboBox( parent ), d( new KTimeZoneComboBox::Private( this ) )
84
d->mAdditionalZones = zones;
85
KGlobal::locale()->insertCatalog( "timezones4" ); // for translated timezones
89
void KTimeZoneComboBox::setAdditionalTimeZones( const KCalCore::ICalTimeZones *zones )
91
d->mAdditionalZones = zones;
95
KTimeZoneComboBox::~KTimeZoneComboBox()
100
void KTimeZoneComboBox::selectTimeSpec( const KDateTime::Spec &spec )
102
int nCurrentlySet = -1;
105
foreach ( const QString &z, d->mZones ) {
106
if ( z == spec.timeZone().name() ) {
113
if ( nCurrentlySet == -1 ) {
114
if ( spec.isUtc() ) {
115
setCurrentIndex( 1 ); // UTC
117
setCurrentIndex( 0 ); // Floating event
120
setCurrentIndex( nCurrentlySet );
124
KDateTime::Spec KTimeZoneComboBox::selectedTimeSpec() const
126
KDateTime::Spec spec;
127
if ( currentIndex() == 0 ) { // Floating event
128
spec = KDateTime::Spec( KDateTime::ClockTime );
130
else if ( currentIndex() == 1 ) { // UTC
131
spec.setType( KDateTime::UTC );
133
spec.setType( KSystemTimeZones::zone( d->mZones[currentIndex()] ) );
139
void KTimeZoneComboBox::selectLocalTimeSpec()
141
selectTimeSpec( KDateTime::Spec( KSystemTimeZones::local() ) );
144
void KTimeZoneComboBox::setFloating( bool floating, const KDateTime::Spec &spec )
147
selectTimeSpec( KDateTime::Spec( KDateTime::ClockTime ) );
149
if ( spec.isValid() ) {
150
selectTimeSpec( spec );
152
selectLocalTimeSpec();