30 #include <kstandarddirs.h>
31 #include <tdeglobal.h>
32 #include <tdeconfig.h>
33 #include <tdelocale.h>
36 #include "kpimprefs.h"
38 KPimPrefs::KPimPrefs(
const TQString &name )
39 : TDEConfigSkeleton( name )
43 KPimPrefs::~KPimPrefs()
47 void KPimPrefs::usrSetDefaults()
49 setCategoryDefaults();
52 void KPimPrefs::usrReadConfig()
54 kdDebug(5300) <<
"KPimPrefs::usrReadConfig()" << endl;
56 config()->setGroup(
"General");
57 mCustomCategories = config()->readListEntry(
"Custom Categories" );
58 if ( mCustomCategories.isEmpty() ) setCategoryDefaults();
59 mCustomCategories.sort();
62 const TQString KPimPrefs::timezone()
67 TDEConfig korgcfg( locate(
"config",
"korganizerrc" ) );
68 korgcfg.setGroup(
"Time & Date" );
69 TQString tz( korgcfg.readEntry(
"TimeZoneId" ) );
70 if ( !tz.isEmpty() ) {
72 kdDebug(5300) <<
"timezone from korganizerrc is " << zone << endl;
76 if ( zone.isEmpty() ) {
77 char zonefilebuf[ PATH_MAX ];
79 int len = readlink(
"/etc/localtime", zonefilebuf, PATH_MAX );
80 if ( len > 0 && len < PATH_MAX ) {
81 zone = TQString::fromLocal8Bit( zonefilebuf, len );
82 zone = zone.mid( zone.find(
"zoneinfo/" ) + 9 );
83 kdDebug(5300) <<
"system timezone from /etc/localtime is " << zone
88 kdDebug(5300) <<
"system timezone from tzset() is " << zone << endl;
95 TQDateTime KPimPrefs::utcToLocalTime(
const TQDateTime &_dt,
96 const TQString &timeZoneId )
101 int yearCorrection = 0;
107 int year = dt.date().year();
110 yearCorrection = 1971 - year;
111 dt = dt.addYears(yearCorrection);
115 TQCString origTz = getenv(
"TZ");
117 setenv(
"TZ",
"UTC", 1 );
118 time_t utcTime = dt.toTime_t();
120 setenv(
"TZ", timeZoneId.local8Bit(), 1 );
121 struct tm *local = localtime( &utcTime );
123 if ( origTz.isNull() ) {
126 setenv(
"TZ", origTz, 1 );
130 TQDateTime result( TQDate( local->tm_year + 1900 - yearCorrection,
131 local->tm_mon + 1, local->tm_mday ),
132 TQTime( local->tm_hour, local->tm_min, local->tm_sec ) );
138 TQDateTime KPimPrefs::localTimeToUtc(
const TQDateTime &_dt,
139 const TQString &timeZoneId )
144 int yearCorrection = 0;
151 int year = dt.date().year();
154 yearCorrection = 1971 - year;
155 dt = dt.addYears(yearCorrection);
159 TQCString origTz = getenv(
"TZ");
161 setenv(
"TZ", timeZoneId.local8Bit(), 1 );
162 time_t localTime = dt.toTime_t();
164 setenv(
"TZ",
"UTC", 1 );
165 struct tm *utc = gmtime( &localTime );
167 if ( origTz.isNull() ) {
170 setenv(
"TZ", origTz, 1 );
174 TQDateTime result( TQDate( utc->tm_year + 1900 - yearCorrection,
175 utc->tm_mon + 1, utc->tm_mday ),
176 TQTime( utc->tm_hour, utc->tm_min, utc->tm_sec ) );
183 void KPimPrefs::usrWriteConfig()
185 config()->setGroup(
"General" );
186 config()->writeEntry(
"Custom Categories", mCustomCategories );