×
Namespaces

Variants
Actions
(Difference between revisions)

How to get list of Time Zones in Qt Maemo application

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan")
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
[[Category:Maemo]][[Category:Qt]]
 
[[Category:Maemo]][[Category:Qt]]
{{ArticleMetaData
+
{{ArticleMetaData <!-- v1.2 -->
|id=
+
|platform=Maemo
+
|devices=Nokia N900
+
|category=Qt, GTK
+
|subcategory=Maemo
+
|creationdate=November 25, 2009
+
|keywords=TimeZone
+
 
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia N900
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= Maemo
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Avis]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= TimeZone
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20091125
 +
|author= [[User:Avis]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Maemo
 
}}
 
}}
  
Line 23: Line 30:
  
 
==Project .pro file==
 
==Project .pro file==
<code cpp>
+
<code cpp-qt>
 
// Maemo specific config
 
// Maemo specific config
 
maemo5 {
 
maemo5 {
Line 34: Line 41:
  
 
==Packing in DEB - control file==
 
==Packing in DEB - control file==
<code cpp>
+
<code cpp-qt>
 
// in source section add for Build-depends line
 
// in source section add for Build-depends line
 
libtime-dev, libcityinfo-dev
 
libtime-dev, libcityinfo-dev
Line 40: Line 47:
  
 
==Header==
 
==Header==
<code cpp>
+
<code cpp-qt>
 
#include <cityinfo.h>
 
#include <cityinfo.h>
 
#include <clockd/libtime.h>
 
#include <clockd/libtime.h>
Line 47: Line 54:
 
==Source==
 
==Source==
  
<code cpp>
+
<code cpp-qt>
 
// get the refence to QComboBox for filling
 
// get the refence to QComboBox for filling
 
void SampleWisget::fillTimeZones(QComboBox* &aBox)
 
void SampleWisget::fillTimeZones(QComboBox* &aBox)

Revision as of 04:17, 11 October 2012

Article Metadata
Tested with
Devices(s): Nokia N900
Compatibility
Platform(s): Maemo
Symbian
Article
Keywords: TimeZone
Created: Avis (25 Nov 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This example shows how to get list of Time Zones in Qt Maemo application using GTK functions (as there are no Qt classes for this operation)

Project .pro file

// Maemo specific config
maemo5 {
LIBS += libtime.so
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0 libcityinfo0-0
INCLUDEPATH += .
}

Packing in DEB - control file

// in source section add for Build-depends line
libtime-dev, libcityinfo-dev

Header

#include <cityinfo.h>
#include <clockd/libtime.h>

Source

// get the refence to QComboBox for filling
void SampleWisget::fillTimeZones(QComboBox* &aBox)
{
int ret = 0;
char current_tz[32];
// get current Time Zone
ret = time_get_timezone(&current_tz[0],32);
// convert from char* to QString
QString defTZ = QString::fromUtf8(current_tz);
// clear the list
aBox->clear();
// get list of Cities
Cityinfo **cities = cityinfo_get_all();
// cycle throug all Cities
for (int i = 0; cities && cities[i]; ++i) {
// get next city params
QString name = QString::fromUtf8(cityinfo_get_name(cities[i]));
QString country = QString::fromUtf8(cityinfo_get_country(cities[i]));
QString zone = ":" + QString::fromUtf8(cityinfo_get_zone(cities[i]));
 
QString timeoffset;
QString sign;
// get time offset from UTC for current city
int offset = time_get_utc_offset(cityinfo_get_zone(cities[i]));
// define sign for offset
if (offset > 0)
sign = "";
else
sign = "+";
// some offset not rounded to hours, so check this and form QString in form
// City Name + Country + Time Offset
if((offset % 3600)==0)
timeoffset = QString("%2, %1, (UTC %3)").arg(name).arg(country).arg(sign+QString::number(-offset/3600));
else
timeoffset = QString("%2, %1, (UTC %3:%4)").arg(name).arg(country).arg(sign+QString::number(-offset/3600)).arg("30");
// add new record to list (formed QString - to text field, and real offset in seconds - to User field)
aBox->addItem(timeoffset,-offset);
// if current city time offset is equal to those got from system - store it's offset
if (zone == defTZ)
defTZ = timeoffset;
}
// free unneded city list
cityinfo_free_all(cities);
// sort the list alphabetically (by the City Name)
aBox->model()->sort(0);
// loking for stored time offest in sorted list
int k = aBox->findText(defTZ);
// setting list position to the city with time offset, which we get in the beginning
aBox->setCurrentIndex(k);
}


Postconditions

The Qt widget with QComboBox filled with TimeZones.

--Avis 9:28, 30 November 2010 (UTC)

108 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×