diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-06 15:57:02 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-06 15:57:02 -0600 |
commit | 2c2fbd828ca474671bb9e03681b30b115d8d6035 (patch) | |
tree | 526a9da418f8d3d7ccf515c37048d3dfc80f2843 /libtdepim/kpimprefs.cpp | |
parent | f0610eece3676b6fe99f42cf4ef2b19a39a5c4e8 (diff) | |
download | tdepim-2c2fbd828ca474671bb9e03681b30b115d8d6035.tar.gz tdepim-2c2fbd828ca474671bb9e03681b30b115d8d6035.zip |
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'libtdepim/kpimprefs.cpp')
-rw-r--r-- | libtdepim/kpimprefs.cpp | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/libtdepim/kpimprefs.cpp b/libtdepim/kpimprefs.cpp new file mode 100644 index 000000000..478ed7047 --- /dev/null +++ b/libtdepim/kpimprefs.cpp @@ -0,0 +1,187 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <config.h> + +#include <time.h> +#include <unistd.h> +#include <stdlib.h> + +#include <tqstring.h> + +#include <kstandarddirs.h> +#include <kglobal.h> +#include <kconfig.h> +#include <klocale.h> +#include <kdebug.h> + +#include "kpimprefs.h" + +KPimPrefs::KPimPrefs( const TQString &name ) + : KConfigSkeleton( name ) +{ +} + +KPimPrefs::~KPimPrefs() +{ +} + +void KPimPrefs::usrSetDefaults() +{ + setCategoryDefaults(); +} + +void KPimPrefs::usrReadConfig() +{ + kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl; + + config()->setGroup("General"); + mCustomCategories = config()->readListEntry( "Custom Categories" ); + if ( mCustomCategories.isEmpty() ) setCategoryDefaults(); + mCustomCategories.sort(); +} + +const TQString KPimPrefs::timezone() +{ + TQString zone = ""; + + // Read TimeZoneId from korganizerrc. + KConfig korgcfg( locate( "config", "korganizerrc" ) ); + korgcfg.setGroup( "Time & Date" ); + TQString tz( korgcfg.readEntry( "TimeZoneId" ) ); + if ( !tz.isEmpty() ) { + zone = tz; + kdDebug(5300) << "timezone from korganizerrc is " << zone << endl; + } + + // If timezone not found in KOrg, use the system's default timezone. + if ( zone.isEmpty() ) { + char zonefilebuf[ PATH_MAX ]; + + int len = readlink( "/etc/localtime", zonefilebuf, PATH_MAX ); + if ( len > 0 && len < PATH_MAX ) { + zone = TQString::fromLocal8Bit( zonefilebuf, len ); + zone = zone.mid( zone.find( "zoneinfo/" ) + 9 ); + kdDebug(5300) << "system timezone from /etc/localtime is " << zone + << endl; + } else { + tzset(); + zone = tzname[ 0 ]; + kdDebug(5300) << "system timezone from tzset() is " << zone << endl; + } + } + + return( zone ); +} + +TQDateTime KPimPrefs::utcToLocalTime( const TQDateTime &_dt, + const TQString &timeZoneId ) +{ + TQDateTime dt(_dt); +// kdDebug() << "--- UTC: " << dt.toString() << endl; + + int yearCorrection = 0; + // The timezone conversion only works for dates > 1970 + // For dates < 1970 we adjust the date to be in 1970, + // do the correction there and then re-adjust back. + // Actually, we use 1971 to prevent errors around + // January 1, 1970 + int year = dt.date().year(); + if (year < 1971) + { + yearCorrection = 1971 - year; + dt = dt.addYears(yearCorrection); +// kdDebug() << "--- Adjusted UTC: " << dt.toString() << endl; + } + + TQCString origTz = getenv("TZ"); + + setenv( "TZ", "UTC", 1 ); + time_t utcTime = dt.toTime_t(); + + setenv( "TZ", timeZoneId.local8Bit(), 1 ); + struct tm *local = localtime( &utcTime ); + + if ( origTz.isNull() ) { + unsetenv( "TZ" ); + } else { + setenv( "TZ", origTz, 1 ); + } + tzset(); + + TQDateTime result( TQDate( local->tm_year + 1900 - yearCorrection, + local->tm_mon + 1, local->tm_mday ), + TQTime( local->tm_hour, local->tm_min, local->tm_sec ) ); + +// kdDebug() << "--- LOCAL: " << result.toString() << endl; + return result; +} + +TQDateTime KPimPrefs::localTimeToUtc( const TQDateTime &_dt, + const TQString &timeZoneId ) +{ + TQDateTime dt(_dt); +// kdDebug() << "--- LOCAL: " << dt.toString() << endl; + + int yearCorrection = 0; + // The timezone conversion only works for dates > 1970 + // For dates < 1970 we adjust the date to be in 1970, + // do the correction there and then re-adjust back. + // Actually, we use 1971 to prevent errors around + // January 1, 1970 + + int year = dt.date().year(); + if (year < 1971) + { + yearCorrection = 1971 - year; + dt = dt.addYears(yearCorrection); +// kdDebug() << "--- Adjusted LOCAL: " << dt.toString() << endl; + } + + TQCString origTz = getenv("TZ"); + + setenv( "TZ", timeZoneId.local8Bit(), 1 ); + time_t localTime = dt.toTime_t(); + + setenv( "TZ", "UTC", 1 ); + struct tm *utc = gmtime( &localTime ); + + if ( origTz.isNull() ) { + unsetenv( "TZ" ); + } else { + setenv( "TZ", origTz, 1 ); + } + tzset(); + + TQDateTime result( TQDate( utc->tm_year + 1900 - yearCorrection, + utc->tm_mon + 1, utc->tm_mday ), + TQTime( utc->tm_hour, utc->tm_min, utc->tm_sec ) ); + +// kdDebug() << "--- UTC: " << result.toString() << endl; + + return result; +} + +void KPimPrefs::usrWriteConfig() +{ + config()->setGroup( "General" ); + config()->writeEntry( "Custom Categories", mCustomCategories ); +} |