00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include <config.h>
00023
00024
#include <time.h>
00025
#include <unistd.h>
00026
#include <stdlib.h>
00027
00028
#include <qstring.h>
00029
00030
#include <kstandarddirs.h>
00031
#include <kglobal.h>
00032
#include <kconfig.h>
00033
#include <klocale.h>
00034
#include <kdebug.h>
00035
00036
#include "kpimprefs.h"
00037
00038 KPimPrefs::KPimPrefs(
const QString &name )
00039 : KConfigSkeleton( name )
00040 {
00041 }
00042
00043 KPimPrefs::~KPimPrefs()
00044 {
00045 }
00046
00047
void KPimPrefs::usrSetDefaults()
00048 {
00049 setCategoryDefaults();
00050 }
00051
00052
void KPimPrefs::usrReadConfig()
00053 {
00054 kdDebug(5300) <<
"KPimPrefs::usrReadConfig()" << endl;
00055
00056 config()->setGroup(
"General");
00057 mCustomCategories = config()->readListEntry(
"Custom Categories" );
00058
if ( mCustomCategories.isEmpty() ) setCategoryDefaults();
00059 }
00060
00061
const QString KPimPrefs::timezone()
00062 {
00063
QString zone =
"";
00064
00065
00066 KConfig korgcfg( locate(
"config",
"korganizerrc" ) );
00067 korgcfg.setGroup(
"Time & Date" );
00068
QString tz( korgcfg.readEntry(
"TimeZoneId" ) );
00069
if ( !tz.isEmpty() ) {
00070 zone = tz;
00071 kdDebug(5300) <<
"timezone from korganizerrc is " << zone << endl;
00072 }
00073
00074
00075
if ( zone.isEmpty() ) {
00076
char zonefilebuf[ PATH_MAX ];
00077
00078
int len = readlink(
"/etc/localtime", zonefilebuf, PATH_MAX );
00079
if ( len > 0 && len < PATH_MAX ) {
00080 zone = QString::fromLocal8Bit( zonefilebuf, len );
00081 zone = zone.mid( zone.find(
"zoneinfo/" ) + 9 );
00082 kdDebug(5300) <<
"system timezone from /etc/localtime is " << zone
00083 << endl;
00084 }
else {
00085 tzset();
00086 zone = tzname[ 0 ];
00087 kdDebug(5300) <<
"system timezone from tzset() is " << zone << endl;
00088 }
00089 }
00090
00091
return( zone );
00092 }
00093
00094
QDateTime KPimPrefs::utcToLocalTime(
const QDateTime &dt,
00095
const QString &timeZoneId )
00096 {
00097
00098
00099
QCString origTz = getenv(
"TZ");
00100
00101 setenv(
"TZ",
"UTC", 1 );
00102 time_t utcTime = dt.toTime_t();
00103
00104 setenv(
"TZ", timeZoneId.local8Bit(), 1 );
00105
struct tm *local = localtime( &utcTime );
00106
00107
if ( origTz.isNull() ) {
00108 unsetenv(
"TZ" );
00109 }
else {
00110 setenv(
"TZ", origTz, 1 );
00111 }
00112 tzset();
00113
00114
QDateTime result(
QDate( local->tm_year + 1900, local->tm_mon + 1,
00115 local->tm_mday ),
00116
QTime( local->tm_hour, local->tm_min, local->tm_sec ) );
00117
00118
return result;
00119 }
00120
00121
QDateTime KPimPrefs::localTimeToUtc(
const QDateTime &dt,
00122
const QString &timeZoneId )
00123 {
00124
00125
00126
QCString origTz = getenv(
"TZ");
00127
00128 setenv(
"TZ", timeZoneId.local8Bit(), 1 );
00129 time_t localTime = dt.toTime_t();
00130
00131 setenv(
"TZ",
"UTC", 1 );
00132
struct tm *utc = gmtime( &localTime );
00133
00134
if ( origTz.isNull() ) {
00135 unsetenv(
"TZ" );
00136 }
else {
00137 setenv(
"TZ", origTz, 1 );
00138 }
00139 tzset();
00140
00141
QDateTime result(
QDate( utc->tm_year + 1900, utc->tm_mon + 1,
00142 utc->tm_mday ),
00143
QTime( utc->tm_hour, utc->tm_min, utc->tm_sec ) );
00144
00145
00146
00147
return result;
00148 }
00149
00150
void KPimPrefs::usrWriteConfig()
00151 {
00152 config()->setGroup(
"General" );
00153 config()->writeEntry(
"Custom Categories", mCustomCategories );
00154 }