28 #include <KMime/HeaderParsing>
30 #include <KPIMIdentities/Identity>
31 #include <KPIMIdentities/IdentityManager>
33 #include <KPIMUtils/Email>
35 #include <KEMailSettings>
36 #include <KSystemTimeZone>
38 using namespace CalendarSupport;
45 Private(
KCalPrefs *qq ) : mDefaultCalendarId( -1 ), q( qq )
47 mDefaultCategoryColor = QColor( 151, 235, 121 );
53 delete mCategoryConfig;
56 KDateTime::Spec mTimeSpec;
57 Akonadi::Entity::Id mDefaultCalendarId;
60 QHash<QString,QColor> mCategoryColors;
61 QColor mDefaultCategoryColor;
77 static bool firstCall =
true;
81 globalPrefs->readConfig();
92 KEMailSettings settings;
93 QString tmp = settings.getSetting( KEMailSettings::RealName );
94 if ( !tmp.isEmpty() ) {
97 tmp = settings.getSetting( KEMailSettings::EmailAddress );
98 if ( !tmp.isEmpty() ) {
105 KConfigSkeleton::usrSetDefaults();
110 return KSystemTimeZones::local();
120 return d->mDefaultCalendarId;
125 d->mDefaultCalendarId = id;
130 KTimeZone zone = KSystemTimeZones::local();
131 if ( !zone.isValid() ) {
132 kError() <<
"KSystemTimeZones::local() return 0";
136 kDebug () <<
"----- time zone:" << zone.name();
149 KEMailSettings settings;
150 if ( !settings.getSetting( KEMailSettings::EmailAddress ).isEmpty() ) {
158 KConfigGroup generalConfig( config(),
"General" );
160 if ( !d->mTimeSpec.isValid() ) {
164 KConfigGroup defaultCalendarConfig( config(),
"Calendar" );
165 d->mDefaultCalendarId = defaultCalendarConfig.readEntry(
"Default Calendar", -1 );
168 d->mCategoryColors = d->mCategoryConfig->readColors();
170 config()->setGroup(
"FreeBusy" );
171 if ( mRememberRetrievePw ) {
172 d->mRetrievePassword =
173 KStringHandler::obscure( config()->readEntry(
"Retrieve Server Password" ) );
177 KConfigSkeleton::usrReadConfig();
183 KConfigGroup generalConfig( config(),
"General" );
184 d->mCategoryConfig->setColors( d->mCategoryColors );
187 if ( mRememberRetrievePw ) {
188 config()->writeEntry(
"Retrieve Server Password",
189 KStringHandler::obscure( d->mRetrievePassword ) );
191 config()->deleteEntry(
"Retrieve Server Password" );
195 KConfigGroup defaultCalendarConfig( config(),
"Calendar" );
198 KConfigSkeleton::usrWriteConfig();
205 KEMailSettings settings;
206 tusername = settings.getSetting( KEMailSettings::RealName );
212 tusername = KPIMUtils::quoteNameIfNecessary( tusername );
214 QString tname, temail;
217 KPIMUtils::extractEmailAddressAndName( tusername, temail, tname );
224 KEMailSettings settings;
225 return settings.getSetting( KEMailSettings::EmailAddress );
248 fullEmails << QString::fromUtf8(
"%1 <%2>" ).arg(
fullName() ).arg(
email() );
250 QStringList::Iterator it;
253 QStringList lst = idmanager->identities();
254 KPIMIdentities::IdentityManager::ConstIterator it1;
255 for ( it1 = idmanager->begin(); it1 != idmanager->end(); ++it1 ) {
256 fullEmails << (*it1).fullEmailAddr();
260 for ( it = lst.begin(); it != lst.end(); ++it ) {
261 fullEmails << QString::fromUtf8(
"%1 <%2>" ).arg(
fullName() ).arg( *it );
285 const QByteArray tmp = _email.toUtf8();
286 const char *cursor = tmp.constData();
287 const char *end = tmp.data() + tmp.length();
288 KMime::Types::Mailbox mbox;
289 KMime::HeaderParsing::parseMailbox( cursor, end, mbox );
290 const QString
email = mbox.addrSpec().asString();
292 if ( this->
email() == email ) {
296 CalendarSupport::IdentityManager::ConstIterator it;
299 if ( (*it).matchesEmailAddress( email ) ) {
313 d->mCategoryColors.insert( cat, color );
320 if ( !cat.isEmpty() ) {
321 color = d->mCategoryColors.value( cat );
324 return color.isValid() ? color : d->mDefaultCategoryColor;
329 return d->mCategoryColors[ cat ].isValid();
void setTimeSpec(const KDateTime::Spec &spec)
QStringList fullEmails()
Returns all email addresses together with the full username for the user.
QString userEmail() const
Get E&mail address.
void usrWriteConfig()
Write preferences to config file.
QColor categoryColor(const QString &cat) const
void setUserName(const QString &v)
Set Full &name.
void usrSetDefaults()
Set preferences to default values.
QStringList allEmails()
Returns all email addresses for the user.
KPIMIdentities::IdentityManager * identityManager()
bool thatIsMe(const QString &email)
Return true if the given email belongs to the user.
Akonadi::Entity::Id defaultCalendarId() const
void setCategoryColor(const QString &cat, const QColor &color)
void setDefaultCalendarId(const Akonadi::Entity::Id)
void setUserEmail(const QString &v)
Set E&mail address.
KCalPrefs()
Constructor disabled for public.
static KCalPrefs * instance()
Get instance of KCalPrefs.
ItemString * userEmailItem()
Get Item object corresponding to UserEmail()
QStringList mAdditionalMails
bool hasCategoryColor(const QString &cat) const
void setTimeZoneDefault()
void usrReadConfig()
Read preferences from config file.
QString userName() const
Get Full &name.
KDateTime::Spec timeSpec()
void fillMailDefaults()
Fill empty mail fields with default values.