• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
ktimezonewidget.cpp
1 /*
2  Copyright (C) 2005, S.R.Haque <srhaque@iee.org>.
3  This file is part of the KDE project
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2, as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <kdialog.h>
21 #include <kdebug.h>
22 #include <tdefile.h>
23 #include <tdelistview.h>
24 #include <tdelocale.h>
25 #include <kstandarddirs.h>
26 #include <ktimezones.h>
27 #include <ktimezonewidget.h>
28 #include <tqpixmap.h>
29 #include <time.h>
30 
31 #define COLUMN_CITY 0
32 #define COLUMN_REGION 1
33 #define COLUMN_COMMENT 2
34 #define COLUMN_ZONE 3
35 
36 KTimezoneWidget::KTimezoneWidget(TQWidget *parent, const char *name, KTimezones *db) :
37  TDEListView(parent, name),
38  d(0)
39 {
40  // If the user did not provide a timezone database, we'll use the system default.
41  bool userDb = (db != 0);
42  if (!userDb)
43  db = new KTimezones();
44 
45  addColumn(i18n("Area"));
46  addColumn(i18n("Region"));
47  addColumn(i18n("Comment"));
48 
49  const KTimezones::ZoneMap zones = db->allZones();
50  for (KTimezones::ZoneMap::ConstIterator it = zones.begin(); it != zones.end(); ++it)
51  {
52  const KTimezone *zone = it.data();
53  TQString tzName = zone->name();
54  TQString comment = zone->comment();
55  if (!comment.isEmpty())
56  comment = i18n(comment.utf8());
57 
58  // Convert:
59  //
60  // "Europe/London", "GB" -> "London", "Europe/GB".
61  // "UTC", "" -> "UTC", "".
62  TQStringList continentCity = TQStringList::split("/", displayName(zone));
63  TQListViewItem *listItem = new TQListViewItem(this, continentCity[continentCity.count() - 1]);
64  continentCity[continentCity.count() - 1] = zone->countryCode();
65  listItem->setText(COLUMN_REGION, continentCity.join("/"));
66  listItem->setText(COLUMN_COMMENT, comment);
67  listItem->setText(COLUMN_ZONE, tzName); /* store complete path in ListView */
68 
69  // Locate the flag from /l10n/%1/flag.png.
70  TQString flag = locate("locale", TQString("l10n/%1/flag.png").arg(zone->countryCode().lower()));
71  if (TQFile::exists(flag))
72  listItem->setPixmap(COLUMN_REGION, TQPixmap(flag));
73  }
74 
75  if (!userDb)
76  delete db;
77 
78 }
79 
80 KTimezoneWidget::~KTimezoneWidget()
81 {
82  // FIXME when needed:
83  // delete d;
84 }
85 
86 TQString KTimezoneWidget::displayName(const KTimezone *zone)
87 {
88  return i18n(zone->name().utf8()).replace("_", " ");
89 }
90 
91 TQStringList KTimezoneWidget::selection() const
92 {
93  TQStringList selection;
94 
95  // Loop through all entries.
96  TQListViewItem *listItem = firstChild();
97  while (listItem)
98  {
99  if (listItem->isSelected())
100  {
101  selection.append(listItem->text(COLUMN_ZONE));
102  }
103  listItem = listItem->nextSibling();
104  }
105  return selection;
106 }
107 
108 void KTimezoneWidget::setSelected(const TQString &zone, bool selected)
109 {
110  bool found = false;
111 
112  // Loop through all entries.
113  TQListViewItem *listItem = firstChild();
114  while (listItem)
115  {
116  if (listItem->text(COLUMN_ZONE) == zone)
117  {
118  TDEListView::setSelected(listItem, selected);
119 
120  // Ensure the selected item is visible as appropriate.
121  listItem = selectedItem();
122  if (listItem)
123  ensureItemVisible(listItem);
124  found = true;
125  break;
126  }
127  listItem = listItem->nextSibling();
128  }
129  if (!found)
130  kdDebug() << "No such zone: " << zone << endl;
131 }
132 
133 #include "ktimezonewidget.moc"
KTimezones
KTimezone
kdDebug
kdbgstream kdDebug(int area=0)
KTimezone::countryCode
TQString countryCode() const
KTimezoneWidget::displayName
static TQString displayName(const KTimezone *zone)
Format a timezone name in a standardised manner.
Definition: ktimezonewidget.cpp:86
KTimezoneWidget::~KTimezoneWidget
virtual ~KTimezoneWidget()
Destroys the timezone selection widget.
Definition: ktimezonewidget.cpp:80
tdelocale.h
KTimezone::name
TQString name() const
KTimezones::allZones
const ZoneMap allZones()
TDEListView
This Widget extends the functionality of TQListView to honor the system wide settings for Single Clic...
Definition: tdelistview.h:84
KTimezone::comment
TQString comment() const
KTimezoneWidget::selection
TQStringList selection() const
Returns the currently selected timezones.
Definition: ktimezonewidget.cpp:91
TDEListView::addColumn
virtual int addColumn(const TQString &label, int width=-1)
Reimplemented for full width support.
Definition: tdelistview.cpp:2177
KTimezoneWidget::KTimezoneWidget
KTimezoneWidget(TQWidget *parent=0, const char *name=0, KTimezones *db=0)
Constructs a timezone selection widget.
Definition: ktimezonewidget.cpp:36
KTimezoneWidget::setSelected
void setSelected(const TQString &zone, bool selected)
Select/deselect the named timezone.
Definition: ktimezonewidget.cpp:108
endl
kndbgstream & endl(kndbgstream &s)
locate
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.