kdeui
ktimezonewidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kdialog.h>
00021 #include <kdebug.h>
00022 #include <kfile.h>
00023 #include <klistview.h>
00024 #include <klocale.h>
00025 #include <kstandarddirs.h>
00026 #include <ktimezones.h>
00027 #include <ktimezonewidget.h>
00028 #include <qpixmap.h>
00029 #include <time.h>
00030
00031 #define COLUMN_CITY 0
00032 #define COLUMN_REGION 1
00033 #define COLUMN_COMMENT 2
00034 #define COLUMN_ZONE 3
00035
00036 KTimezoneWidget::KTimezoneWidget(QWidget *parent, const char *name, KTimezones *db) :
00037 KListView(parent, name),
00038 d(0)
00039 {
00040
00041 bool userDb = (db != 0);
00042 if (!userDb)
00043 db = new KTimezones();
00044
00045 addColumn(i18n("Area"));
00046 addColumn(i18n("Region"));
00047 addColumn(i18n("Comment"));
00048
00049 const KTimezones::ZoneMap zones = db->allZones();
00050 for (KTimezones::ZoneMap::ConstIterator it = zones.begin(); it != zones.end(); ++it)
00051 {
00052 const KTimezone *zone = it.data();
00053 QString tzName = zone->name();
00054 QString comment = zone->comment();
00055 if (!comment.isEmpty())
00056 comment = i18n(comment.utf8());
00057
00058
00059
00060
00061
00062 QStringList continentCity = QStringList::split("/", displayName(zone));
00063 QListViewItem *listItem = new QListViewItem(this, continentCity[continentCity.count() - 1]);
00064 continentCity[continentCity.count() - 1] = zone->countryCode();
00065 listItem->setText(COLUMN_REGION, continentCity.join("/"));
00066 listItem->setText(COLUMN_COMMENT, comment);
00067 listItem->setText(COLUMN_ZONE, tzName);
00068
00069
00070 QString flag = locate("locale", QString("l10n/%1/flag.png").arg(zone->countryCode().lower()));
00071 if (QFile::exists(flag))
00072 listItem->setPixmap(COLUMN_REGION, QPixmap(flag));
00073 }
00074
00075 if (!userDb)
00076 delete db;
00077
00078 }
00079
00080 KTimezoneWidget::~KTimezoneWidget()
00081 {
00082
00083
00084 }
00085
00086 QString KTimezoneWidget::displayName(const KTimezone *zone)
00087 {
00088 return i18n(zone->name().utf8()).replace("_", " ");
00089 }
00090
00091 QStringList KTimezoneWidget::selection() const
00092 {
00093 QStringList selection;
00094
00095
00096 QListViewItem *listItem = firstChild();
00097 while (listItem)
00098 {
00099 if (listItem->isSelected())
00100 {
00101 selection.append(listItem->text(COLUMN_ZONE));
00102 }
00103 listItem = listItem->nextSibling();
00104 }
00105 return selection;
00106 }
00107
00108 void KTimezoneWidget::setSelected(const QString &zone, bool selected)
00109 {
00110 bool found = false;
00111
00112
00113 QListViewItem *listItem = firstChild();
00114 while (listItem)
00115 {
00116 if (listItem->text(COLUMN_ZONE) == zone)
00117 {
00118 KListView::setSelected(listItem, selected);
00119
00120
00121 listItem = selectedItem();
00122 if (listItem)
00123 ensureItemVisible(listItem);
00124 found = true;
00125 break;
00126 }
00127 listItem = listItem->nextSibling();
00128 }
00129 if (!found)
00130 kdDebug() << "No such zone: " << zone << endl;
00131 }
00132
00133 #include "ktimezonewidget.moc"