[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    tags/kdepim/pe5.20091201/kdelibs/kdecore/date
From:       Till Adam <adam () kde ! org>
Date:       2009-12-05 20:15:45
Message-ID: 1260044145.319710.14334.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1059113 by tilladam:

Make timezones work on unicode builds as well, where TCHAR is wchar_t, not char.

 M  +30 -9     ktimezone_win.cpp  


--- tags/kdepim/pe5.20091201/kdelibs/kdecore/date/ktimezone_win.cpp #1059112:1059113
@@ -50,7 +50,35 @@
     };
 }
 
+// TCHAR can be either uchar, or wchar_t:
+static inline QString tchar_to_qstring( const char * str ) {
+    return QString::fromLocal8Bit( str );
+}
+static inline QString tchar_to_qstring( const wchar_t * str ) {
+    return QString::fromUtf16( reinterpret_cast<const ushort*>( str ) );
+}
 
+// since we can't overload on the return type, we have to pass in a disambiguation token
+
+static inline TCHAR * _qstring_to_tchar( const char* t, const QString&s )
+{
+    return reinterpret_cast<TCHAR*>( s.toLocal8Bit().data() );
+}
+
+static inline TCHAR * _qstring_to_tchar( const wchar_t* t, const QString&s )
+{
+    return reinterpret_cast<TCHAR*>( const_cast<ushort*>( s.utf16()) );
+}
+
+static inline TCHAR* qstring_to_tchar( const QString& s) 
+{
+    TCHAR * t;
+    return _qstring_to_tchar( t, s );
+}
+
+
+
+
 static const TCHAR timeZonesKey[] = TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones");
 static inline QDateTime systemtime_to_qdatetime( const SYSTEMTIME & st ) {
     return QDateTime( QDate( st.wYear, st.wMonth, st.wDay ),
@@ -272,13 +300,14 @@
 {
 }
 
+
 KTimeZoneData* KSystemTimeZoneSourceWindows::parse(const KTimeZone &zone) const
 {
     KSystemTimeZoneDataWindows* data = new KSystemTimeZoneDataWindows();
 
     std::basic_string<TCHAR> path( timeZonesKey );
     path += TEXT( "\\" );
-    path += reinterpret_cast<TCHAR*>( zone.name().toLocal8Bit().data() );
+    path += qstring_to_tchar( zone.name() );
 
     HKEY key;
     if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_READ, &key ) != ERROR_SUCCESS ) {
@@ -391,14 +420,6 @@
 
 static const int MAX_KEY_LENGTH = 255;
 
-// TCHAR can be either uchar, or wchar_t:
-static inline QString tchar_to_qstring( TCHAR * ustr ) {
-    const char * str = reinterpret_cast<const char*>( ustr );
-    return QString::fromLocal8Bit( str );
-}
-static inline QString tchar_to_qstring( const wchar_t * str ) {
-    return QString::fromUtf16( reinterpret_cast<const ushort*>( str ) );
-}
 
 static QStringList list_key( HKEY key ) {
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic