timezonecombo.cpp 1.85 KB
Newer Older
David Jarvie's avatar
David Jarvie committed
1 2 3
/*
 *  timezonecombo.cpp  -  time zone selection combo box
 *  Program:  kalarm
4
 *  Copyright © 2006,2008,2009,2011 by David Jarvie <djarvie@kde.org>
David Jarvie's avatar
David Jarvie committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

Laurent Montel's avatar
Laurent Montel committed
21
#include "timezonecombo.h"
22 23
#include <ksystemtimezone.h>
#include <kglobal.h>
Laurent Montel's avatar
Laurent Montel committed
24
#include <KLocalizedString>
David Jarvie's avatar
David Jarvie committed
25 26 27


TimeZoneCombo::TimeZoneCombo(QWidget* parent)
28
    : ComboBox(parent)
David Jarvie's avatar
David Jarvie committed
29
{
30 31 32 33
    QString utc = KTimeZone::utc().name();
    addItem(utc);   // put UTC at start of list
    mZoneNames << utc;
    const KTimeZones::ZoneMap zones = KSystemTimeZones::zones();
Laurent Montel's avatar
Laurent Montel committed
34 35
    KTimeZones::ZoneMap::ConstIterator end = zones.constEnd();
    for (KTimeZones::ZoneMap::ConstIterator it = zones.constBegin();  it != end;  ++it)
36 37 38
        if (it.key() != utc)
        {
            mZoneNames << it.key();
Laurent Montel's avatar
Laurent Montel committed
39
            addItem(i18n(it.key().toUtf8()).replace(QLatin1Char('_'), QLatin1Char(' ')));
40
        }
David Jarvie's avatar
David Jarvie committed
41 42
}

43
KTimeZone TimeZoneCombo::timeZone() const
David Jarvie's avatar
David Jarvie committed
44
{
45
    return KSystemTimeZones::zone(mZoneNames[currentIndex()]);
David Jarvie's avatar
David Jarvie committed
46 47
}

48
void TimeZoneCombo::setTimeZone(const KTimeZone& tz)
David Jarvie's avatar
David Jarvie committed
49
{
50 51 52 53 54
    if (!tz.isValid())
        return;
    int index = mZoneNames.indexOf(tz.name());
    if (index >= 0)
        setCurrentIndex(index);
David Jarvie's avatar
David Jarvie committed
55
}
56

57
// vim: et sw=4: