koprefs.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <time.h>
00026 #include <unistd.h>
00027
00028 #include <qdir.h>
00029 #include <qstring.h>
00030 #include <qfont.h>
00031 #include <qcolor.h>
00032 #include <qstringlist.h>
00033
00034 #include <kglobalsettings.h>
00035 #include <kglobal.h>
00036 #include <kconfig.h>
00037 #include <klocale.h>
00038 #include <kdebug.h>
00039 #include <kemailsettings.h>
00040 #include <kstaticdeleter.h>
00041 #include <kstringhandler.h>
00042
00043 #include "koprefs.h"
00044 #include <libkpimidentities/identitymanager.h>
00045 #include <libkpimidentities/identity.h>
00046 #include <libkdepim/email.h>
00047 #include <kabc/stdaddressbook.h>
00048 #include "kocore.h"
00049
00050 KOPrefs *KOPrefs::mInstance = 0;
00051 static KStaticDeleter<KOPrefs> insd;
00052
00053 QColor getTextColor(const QColor &c)
00054 {
00055 float luminance = (c.red() * 0.299) + (c.green() * 0.587) + (c.blue() * 0.114);
00056 return (luminance > 128.0) ? QColor( 0, 0 ,0 ) : QColor( 255, 255 ,255 );
00057 }
00058
00059
00060 KOPrefs::KOPrefs() :
00061 KOPrefsBase()
00062 {
00063 mCategoryColors.setAutoDelete( true );
00064 mResourceColors.setAutoDelete( true );
00065
00066 mDefaultCategoryColor = QColor(151, 235, 121);
00067
00068 mDefaultResourceColor = QColor();
00069
00070 mDefaultMonthViewFont = KGlobalSettings::generalFont();
00071
00072 mDefaultMonthViewFont.setPointSize(mDefaultMonthViewFont.pointSize()-2);
00073
00074 KConfigSkeleton::setCurrentGroup("General");
00075
00076 addItemPath("Html Export File",mHtmlExportFile,
00077 QDir::homeDirPath() + "/" + i18n("Default export file", "calendar.html"));
00078
00079 monthViewFontItem()->setDefaultValue( mDefaultMonthViewFont );
00080 eventColorItem()->setDefaultValue( mDefaultCategoryColor );
00081
00082
00083 KABC::StdAddressBook::self();
00084 KABC::Addressee mMe = KABC::StdAddressBook::self()->whoAmI();
00085 }
00086
00087
00088 KOPrefs::~KOPrefs()
00089 {
00090 kdDebug(5850) << "KOPrefs::~KOPrefs()" << endl;
00091 }
00092
00093
00094 KOPrefs *KOPrefs::instance()
00095 {
00096 if ( !mInstance ) {
00097 insd.setObject( mInstance, new KOPrefs() );
00098 mInstance->readConfig();
00099 }
00100
00101 return mInstance;
00102 }
00103
00104 void KOPrefs::usrSetDefaults()
00105 {
00106
00107
00108
00109 KEMailSettings settings;
00110 mName = settings.getSetting(KEMailSettings::RealName);
00111 mEmail = settings.getSetting(KEMailSettings::EmailAddress);
00112 fillMailDefaults();
00113
00114 mMonthViewFont = mDefaultMonthViewFont;
00115
00116 setTimeZoneIdDefault();
00117
00118 KPimPrefs::usrSetDefaults();
00119 }
00120
00121 void KOPrefs::fillMailDefaults()
00122 {
00123 QString defaultEmail = i18n("nobody@nowhere");
00124 if (mEmail.isEmpty())
00125 mEmail = defaultEmail;
00126 if ( mEmail == defaultEmail ) {
00127
00128 KEMailSettings settings;
00129 if ( !settings.getSetting( KEMailSettings::EmailAddress ).isEmpty() )
00130 mEmailControlCenter = true;
00131 }
00132 if (mName.isEmpty()) mName = i18n("Anonymous");
00133 }
00134
00135 void KOPrefs::setTimeZoneIdDefault()
00136 {
00137 QString zone;
00138
00139 char zonefilebuf[100];
00140 int len = readlink("/etc/localtime",zonefilebuf,100);
00141 if (len > 0 && len < 100) {
00142 zonefilebuf[len] = '\0';
00143 zone = zonefilebuf;
00144 zone = zone.mid(zone.find("zoneinfo/") + 9);
00145 } else {
00146 tzset();
00147 zone = tzname[0];
00148 }
00149
00150 kdDebug () << "----- time zone: " << zone << endl;
00151
00152 mTimeZoneId = zone;
00153 }
00154
00155 void KOPrefs::setCategoryDefaults()
00156 {
00157 mCustomCategories.clear();
00158
00159 mCustomCategories << i18n("Appointment") << i18n("Business")
00160 << i18n("Meeting") << i18n("Phone Call") << i18n("Education")
00161 << i18n("Holiday") << i18n("Vacation") << i18n("Special Occasion")
00162 << i18n("Personal") << i18n("Travel") << i18n("Miscellaneous")
00163 << i18n("Birthday");
00164
00165 QStringList::Iterator it;
00166 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
00167 setCategoryColor(*it,mDefaultCategoryColor);
00168 }
00169 }
00170
00171
00172 void KOPrefs::usrReadConfig()
00173 {
00174 config()->setGroup("General");
00175 mCustomCategories = config()->readListEntry("Custom Categories");
00176 if (mCustomCategories.isEmpty()) setCategoryDefaults();
00177
00178 config()->setGroup("Personal Settings");
00179 mName = config()->readEntry("user_name");
00180 mEmail = config()->readEntry("user_email");
00181 fillMailDefaults();
00182
00183
00184
00185 config()->setGroup("Category Colors");
00186 QValueList<QColor> oldCategoryColors;
00187 QStringList::Iterator it;
00188 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
00189 QColor c = config()->readColorEntry(*it, &mDefaultCategoryColor);
00190 oldCategoryColors.append( (c == QColor(196,196,196)) ?
00191 mDefaultCategoryColor : c);
00192 }
00193
00194
00195 config()->setGroup("Category Colors2");
00196 QValueList<QColor>::Iterator it2;
00197 for (it = mCustomCategories.begin(), it2 = oldCategoryColors.begin();
00198 it != mCustomCategories.end(); ++it, ++it2 ) {
00199 setCategoryColor(*it,config()->readColorEntry(*it, &*it2));
00200 }
00201
00202 config()->setGroup( "Resources Colors" );
00203 QMap<QString, QString> map = config()->entryMap( "Resources Colors" );
00204
00205 QMapIterator<QString, QString> it3;
00206 for( it3 = map.begin(); it3 != map.end(); ++it3 ) {
00207 kdDebug(5850)<< "KOPrefs::usrReadConfig: key: " << it3.key() << " value: "
00208 << it3.data()<<endl;
00209 setResourceColor( it3.key(), config()->readColorEntry( it3.key(),
00210 &mDefaultResourceColor ) );
00211 }
00212
00213
00214 if (mTimeZoneId.isEmpty()) {
00215 setTimeZoneIdDefault();
00216 }
00217
00218 config()->setGroup("FreeBusy");
00219 #if 0
00220 if( mRememberRetrievePw )
00221 mRetrievePassword = KStringHandler::obscure( config()->readEntry( "Retrieve Server Password" ) );
00222 #endif
00223 kdDebug()<<"KOPrefs::usrReadConfig()"<<endl;
00224 KPimPrefs::usrReadConfig();
00225 }
00226
00227
00228 void KOPrefs::usrWriteConfig()
00229 {
00230 config()->setGroup("General");
00231 config()->writeEntry("Custom Categories",mCustomCategories);
00232
00233 config()->setGroup("Personal Settings");
00234 config()->writeEntry("user_name",mName);
00235 config()->writeEntry("user_email",mEmail);
00236
00237 config()->setGroup("Category Colors2");
00238 QDictIterator<QColor> it(mCategoryColors);
00239 while (it.current()) {
00240 config()->writeEntry(it.currentKey(),*(it.current()));
00241 ++it;
00242 }
00243
00244 config()->setGroup( "Resources Colors" );
00245 QDictIterator<QColor> it2( mResourceColors );
00246 while( it2.current() ) {
00247 config()->writeEntry( it2.currentKey(), *( it2.current() ) );
00248 ++it2;
00249 }
00250
00251 if( !mFreeBusyPublishSavePassword ) {
00252 KConfigSkeleton::ItemPassword *i = freeBusyPublishPasswordItem();
00253 i->setValue( "" );
00254 i->writeConfig( config() );
00255 }
00256 if( !mFreeBusyRetrieveSavePassword ) {
00257 KConfigSkeleton::ItemPassword *i = freeBusyRetrievePasswordItem();
00258 i->setValue( "" );
00259 i->writeConfig( config() );
00260 }
00261
00262 #if 0
00263 if( mRememberRetrievePw )
00264 config()->writeEntry( "Retrieve Server Password", KStringHandler::obscure( mRetrievePassword ) );
00265 else
00266 config()->deleteEntry( "Retrieve Server Password" );
00267 #endif
00268
00269 KPimPrefs::usrWriteConfig();
00270 }
00271
00272 void KOPrefs::setCategoryColor(QString cat,const QColor & color)
00273 {
00274 mCategoryColors.replace( cat, new QColor( color ) );
00275 }
00276
00277 QColor *KOPrefs::categoryColor(QString cat)
00278 {
00279 QColor *color = 0;
00280
00281 if ( !cat.isEmpty() ) color = mCategoryColors[ cat ];
00282
00283 if ( color ) return color;
00284 else return &mDefaultCategoryColor;
00285 }
00286
00287 void KOPrefs::setResourceColor ( const QString &cal, const QColor &color )
00288 {
00289 kdDebug(5850)<<"KOPrefs::setResourceColor: " << cal << " color: "<<
00290 color.name()<<endl;
00291 mResourceColors.replace( cal, new QColor( color ) );
00292 }
00293
00294 QColor* KOPrefs::resourceColor( const QString &cal )
00295 {
00296 QColor *color=0;
00297 if( !cal.isEmpty() ) color = mResourceColors[cal];
00298
00299 if (color && color->isValid() )
00300 return color;
00301 else
00302 return &mDefaultResourceColor;
00303 }
00304
00305 void KOPrefs::setFullName(const QString &name)
00306 {
00307 mName = name;
00308 }
00309
00310 void KOPrefs::setEmail(const QString &email)
00311 {
00312 mEmail = email;
00313 }
00314
00315 QString KOPrefs::fullName()
00316 {
00317 if (mEmailControlCenter) {
00318 KEMailSettings settings;
00319 return KPIM::quotedName( settings.getSetting(KEMailSettings::RealName) );
00320 } else {
00321 return mName;
00322 }
00323 }
00324
00325 QString KOPrefs::email()
00326 {
00327 if (mEmailControlCenter) {
00328 KEMailSettings settings;
00329 return settings.getSetting(KEMailSettings::EmailAddress);
00330 } else {
00331 return mEmail;
00332 }
00333 }
00334
00335 QStringList KOPrefs::allEmails()
00336 {
00337
00338 QStringList lst = KOCore::self()->identityManager()->allEmails();
00339
00340 lst += mAdditionalMails;
00341
00342 lst += mMe.emails();
00343
00344
00345 return lst;
00346 }
00347
00348 QStringList KOPrefs::fullEmails()
00349 {
00350 QStringList fullEmails;
00351
00352 fullEmails << QString("%1 <%2>").arg( fullName() ).arg( email() );
00353
00354 QStringList::Iterator it;
00355
00356 KPIM::IdentityManager *idmanager = KOCore::self()->identityManager();
00357 QStringList lst = idmanager->identities();
00358 KPIM::IdentityManager::ConstIterator it1;
00359 for ( it1 = idmanager->begin() ; it1 != idmanager->end() ; ++it1 ) {
00360 fullEmails << (*it1).fullEmailAddr();
00361 }
00362
00363 lst = mAdditionalMails;
00364 for ( it = lst.begin(); it != lst.end(); ++it ) {
00365 fullEmails << QString("%1 <%2>").arg( fullName() ).arg( *it );
00366 }
00367
00368 lst = mMe.emails();
00369 for ( it = lst.begin(); it != lst.end(); ++it ) {
00370 fullEmails << mMe.fullEmail( *it );
00371 }
00372
00373
00374 return fullEmails;
00375 }
00376
00377 bool KOPrefs::thatIsMe( const QString& _email )
00378 {
00379 if ( KOCore::self()->identityManager()->thatIsMe( _email ) )
00380 return true;
00381
00382 QString email = KPIM::getEmailAddr( _email );
00383 if ( mAdditionalMails.find( email ) != mAdditionalMails.end() )
00384 return true;
00385 QStringList lst = mMe.emails();
00386 if ( lst.find( email ) != lst.end() )
00387 return true;
00388 return false;
00389 }
This file is part of the documentation for korganizer Library Version 3.3.2.