[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim] pimactivity: Compile identitymanageractivity
From: Montel Laurent <montel () kde ! org>
Date: 2013-04-30 19:16:42
Message-ID: 20130430191642.3D39FA603F () git ! kde ! org
[Download RAW message or body]
Git commit 39a53b24f8672d17b8087d27485e141a9deece17 by Montel Laurent.
Committed on 30/04/2013 at 21:16.
Pushed by mlaurent into branch 'master'.
Compile identitymanageractivity
M +6 -1 pimactivity/CMakeLists.txt
M +282 -247 pimactivity/pimwidgets/identity/identitymanageractivity.cpp
M +29 -43 pimactivity/pimwidgets/identity/identitymanageractivity.h
A +8 -0 pimactivity/pimwidgets/identity/org.kde.pim.IdentityManagerActivity.xml
http://commits.kde.org/kdepim/39a53b24f8672d17b8087d27485e141a9deece17
diff --git a/pimactivity/CMakeLists.txt b/pimactivity/CMakeLists.txt
index 8b50d34..9f253ab 100644
--- a/pimactivity/CMakeLists.txt
+++ b/pimactivity/CMakeLists.txt
@@ -17,23 +17,28 @@ set(libpimactivity_SRCS
configureactivitywidget.cpp
pimwidgets/mailtransport/transportcomboboxactivity.cpp
pimwidgets/identity/identitycomboboxactivity.cpp
+ pimwidgets/identity/identitymanageractivity.cpp
widgets/configurecollections.cpp
widgets/configuremailtransport.cpp
widgets/activitywarning.cpp
widgets/abstractconfigurewidget.cpp
)
+qt4_add_dbus_adaptor(libpimactivity_SRCS \
pimwidgets/identity/org.kde.pim.IdentityManagerActivity.xml \
pimwidgets/identity/identitymanageractivity.h PimActivity::IdentityManagerActivity ) \
+ kde4_add_library(pimactivity ${LIBRARY_TYPE} ${libpimactivity_SRCS})
set_target_properties(pimactivity PROPERTIES VERSION ${GENERIC_LIB_VERSION} \
SOVERSION ${GENERIC_LIB_SOVERSION})
target_link_libraries(pimactivity
${KDE4_KDEUI_LIBS}
+ ${KDE4_KIO_LIBS}
${KACTIVITIES_LIBRARY}
${KDEPIMLIBS_KPIMIDENTITIES_LIBS}
${KDEPIMLIBS_MAILTRANSPORT_LIBS}
${KDEPIMLIBS_KMIME_LIBS}
- ${KDEPIMLIBS_AKONADI_LIBS}
+ ${KDEPIMLIBS_AKONADI_LIBS}
+ ${KDEPIMLIBS_KPIMUTILS_LIBS}
akonadi_next
)
diff --git a/pimactivity/pimwidgets/identity/identitymanageractivity.cpp \
b/pimactivity/pimwidgets/identity/identitymanageractivity.cpp index 1c586d9..dd922a5 \
100644
--- a/pimactivity/pimwidgets/identity/identitymanageractivity.cpp
+++ b/pimactivity/pimwidgets/identity/identitymanageractivity.cpp
@@ -41,66 +41,274 @@ static const char configKeyDefaultIdentity[] = "Default \
Identity"; #include <assert.h>
#include <krandom.h>
-#include "IdentityManagerActivityadaptor.h"
+#include "identitymanageractivityadaptor.h"
+
+namespace PimActivity {
+
+class IdentityManagerActivityPrivate
+{
+public:
+ IdentityManagerActivityPrivate(ActivityManager *manager, IdentityManagerActivity \
*qq) + : readOnly(false),
+ activityManager(manager),
+ q(qq)
+ {
+ config = new KConfig( QLatin1String("emailidentities") );
+ }
+ ~IdentityManagerActivityPrivate()
+ {
+ delete config;
+ }
+
+ QStringList groupList( KConfig *conf ) const
+ {
+ return conf->groupList().filter( QRegExp( QLatin1String("^Identity #\\d+$") \
) ); + }
+
+ void writeConfig() const
+ {
+ const QStringList identitiesList = groupList( config );
+ QStringList::const_iterator groupEnd = identitiesList.constEnd();
+ for ( QStringList::const_iterator group = identitiesList.constBegin();
+ group != groupEnd; ++group ) {
+ config->deleteGroup( *group );
+ }
+ int i = 0;
+ IdentityManagerActivity::ConstIterator end = identities.constEnd();
+ for ( IdentityManagerActivity::ConstIterator it = identities.constBegin();
+ it != end; ++it, ++i ) {
+ KConfigGroup cg( config, QString::fromLatin1( "Identity #%1" ).arg( i ) \
); + ( *it ).writeConfig( cg );
+ if ( ( *it ).isDefault() ) {
+ // remember which one is default:
+ KConfigGroup general( config, "General" );
+ general.writeEntry( configKeyDefaultIdentity, ( *it ).uoid() );
+
+ // Also write the default identity to emailsettings
+ KEMailSettings es;
+ es.setSetting( KEMailSettings::RealName, ( *it ).fullName() );
+ es.setSetting( KEMailSettings::EmailAddress, ( *it \
).primaryEmailAddress() ); + es.setSetting( \
KEMailSettings::Organization, ( *it ).organization() ); + \
es.setSetting( KEMailSettings::ReplyToAddress, ( *it ).replyToAddr() ); + \
} + }
+ config->sync();
+ }
+
+ void readConfig( KConfig *conf )
+ {
+ identities.clear();
+
+ const QStringList identitiesList = groupList( conf );
+ if ( identitiesList.isEmpty() ) {
+ return; // nothing to be done...
+ }
+
+ KConfigGroup general( conf, "General" );
+ uint defaultIdentity = general.readEntry( configKeyDefaultIdentity, 0 );
+ bool haveDefault = false;
+ QStringList::const_iterator groupEnd = identitiesList.constEnd();
+ for ( QStringList::const_iterator group = identitiesList.constBegin();
+ group != groupEnd; ++group ) {
+ KConfigGroup configGroup( conf, *group );
+ identities << KPIMIdentities::Identity();
+ identities.last().readConfig( configGroup );
+ if ( !haveDefault && identities.last().uoid() == defaultIdentity ) {
+ haveDefault = true;
+ identities.last().setIsDefault( true );
+ }
+ }
+
+ if ( !haveDefault ) {
+ kWarning( 5325 ) << "IdentityManagerActivity: There was no default \
identity." + << "Marking first one as default.";
+ identities.first().setIsDefault( true );
+ }
+ qSort( identities );
+
+ shadowIdentities = identities;
+ }
+
+
+ void createDefaultIdentity()
+ {
+ QString fullName, emailAddress;
+ bool done = false;
+
+ // Check if the application has any settings
+ q->createDefaultIdentity( fullName, emailAddress );
+
+ // If not, then use the kcontrol settings
+ if ( fullName.isEmpty() && emailAddress.isEmpty() ) {
+ KEMailSettings emailSettings;
+ fullName = emailSettings.getSetting( KEMailSettings::RealName );
+ emailAddress = emailSettings.getSetting( KEMailSettings::EmailAddress );
+
+ if ( !fullName.isEmpty() && !emailAddress.isEmpty() ) {
+ q->newFromControlCenter( i18nc( "use default address from control \
center", + "Default" ) );
+ done = true;
+ } else {
+ // If KEmailSettings doesn't have name and address, generate \
something from KUser + KUser user;
+ if ( fullName.isEmpty() ) {
+ fullName = user.property( KUser::FullName ).toString();
+ }
+ if ( emailAddress.isEmpty() ) {
+ emailAddress = user.loginName();
+ if ( !emailAddress.isEmpty() ) {
+ KConfigGroup general( config, "General" );
+ QString defaultdomain = general.readEntry( "Default domain" \
); + if ( !defaultdomain.isEmpty() ) {
+ emailAddress += QLatin1Char('@') + defaultdomain;
+ } else {
+ emailAddress.clear();
+ }
+ }
+ }
+ }
+ }
+
+ if ( !done ) {
+ // Default identity name
+ QString name( i18nc( "Default name for new email accounts/identities.", \
"Unnamed" ) ); +
+ if ( !emailAddress.isEmpty() ) {
+ // If we have an email address, create a default identity name from \
it + QString idName = emailAddress;
+ int pos = idName.indexOf( QLatin1Char('@') );
+ if ( pos != -1 ) {
+ name = idName.mid( pos + 1, -1 );
+ }
+
+ // Make the name a bit more human friendly
+ name.replace( QLatin1Char('.'), QLatin1Char(' ') );
+ pos = name.indexOf( QLatin1Char(' ') );
+ if ( pos != 0 ) {
+ name[pos + 1] = name[pos + 1].toUpper();
+ }
+ name[0] = name[0].toUpper();
+ } else if ( !fullName.isEmpty() ) {
+ // If we have a full name, create a default identity name from it
+ name = fullName;
+ }
+ shadowIdentities << KPIMIdentities::Identity( name, fullName, \
emailAddress ); + }
+
+ shadowIdentities.last().setIsDefault( true );
+ shadowIdentities.last().setUoid( newUoid() );
+ if ( readOnly ) { // commit won't do it in readonly mode
+ identities = shadowIdentities;
+ }
+ }
+
+ int newUoid()
+ {
+ int uoid;
+
+ // determine the UOIDs of all saved identities
+ QList<uint> usedUOIDs;
+ QList<KPIMIdentities::Identity>::ConstIterator end( identities.constEnd() );
+ for ( QList<KPIMIdentities::Identity>::ConstIterator it = \
identities.constBegin(); + it != end; ++it ) {
+ usedUOIDs << ( *it ).uoid();
+ }
+
+ if ( q->hasPendingChanges() ) {
+ // add UOIDs of all shadow identities. Yes, we will add a lot of \
duplicate + // UOIDs, but avoiding duplicate UOIDs isn't worth the effort.
+ QList<KPIMIdentities::Identity>::ConstIterator endShadow( \
shadowIdentities.constEnd() ); + for ( \
QList<KPIMIdentities::Identity>::ConstIterator it = shadowIdentities.constBegin(); + \
it != endShadow; ++it ) { + usedUOIDs << ( *it ).uoid();
+ }
+ }
+
+ usedUOIDs << 0; // no UOID must be 0 because this value always refers to the
+ // default identity
+
+ do {
+ uoid = KRandom::random();
+ } while ( usedUOIDs.indexOf( uoid ) != -1 );
+
+ return uoid;
+ }
+
+ /** The list that will be seen by everyoe */
+ QList<KPIMIdentities::Identity> identities;
+ /** The list that will be seen by the config dialog */
+ QList<KPIMIdentities::Identity> shadowIdentities;
+
+ KConfig *config;
+ bool readOnly;
+ ActivityManager *activityManager;
+ IdentityManagerActivity *q;
+};
-using namespace PimActivity;
static QString newDBusObjectName()
{
static int s_count = 0;
- QString name( "/KPIMIDENTITIES_IdentityManagerActivity" );
+ QString name = QLatin1String( "/KPIMIDENTITIES_IdentityManagerActivity" );
if ( s_count++ ) {
- name += '_';
+ name += QLatin1Char('_');
name += QString::number( s_count );
}
return name;
}
-IdentityManagerActivity::IdentityManagerActivity( bool readonly, QObject *parent,
- const char *name )
- : QObject( parent )
+IdentityManagerActivity::IdentityManagerActivity(ActivityManager *manager, bool \
readonly, QObject *parent, + const \
char *name ) + : QObject( parent ),
+ d(new IdentityManagerActivityPrivate(manager, this))
{
- setObjectName( name );
- KGlobal::locale()->insertCatalog( "libkpimidentities" );
+ setObjectName( QLatin1String(name) );
+ KGlobal::locale()->insertCatalog( QLatin1String("libkpimidentities") );
new IdentityManagerActivityAdaptor( this );
QDBusConnection dbus = QDBusConnection::sessionBus();
const QString dbusPath = newDBusObjectName();
setProperty( "uniqueDBusPath", dbusPath );
- const QString dbusInterface = "org.kde.pim.IdentityManagerActivity";
+ const QString dbusInterface = \
QLatin1String("org.kde.pim.IdentityManagerActivity"); dbus.registerObject( dbusPath, \
this );
- dbus.connect( QString(), QString(), dbusInterface, "identitiesChanged", this,
+ dbus.connect( QString(), QString(), dbusInterface, \
QLatin1String("identitiesChanged"), this, SLOT(slotIdentitiesChanged(QString)) );
- mReadOnly = readonly;
- mConfig = new KConfig( "emailidentities" );
- readConfig( mConfig );
- if ( mIdentities.isEmpty() ) {
+ d->readOnly = readonly;
+
+ d->readConfig( d->config );
+ if ( d->identities.isEmpty() ) {
kDebug( 5325 ) << "emailidentities is empty -> convert from kmailrc";
// No emailidentities file, or an empty one due to broken conversion
// (kconf_update bug in kdelibs <= 3.2.2)
// => convert it, i.e. read settings from kmailrc
- KConfig kmailConf( "kmailrc" );
- readConfig( &kmailConf );
+ KConfig kmailConf( QLatin1String("kmailrc") );
+ d->readConfig( &kmailConf );
}
// we need at least a default identity:
- if ( mIdentities.isEmpty() ) {
+ if ( d->identities.isEmpty() ) {
kDebug( 5325 ) << "IdentityManagerActivity: No identity found. Creating \
default.";
- createDefaultIdentity();
+ d->createDefaultIdentity();
commit();
}
// Migration: people without settings in kemailsettings should get some
if ( KEMailSettings().getSetting( KEMailSettings::EmailAddress ).isEmpty() ) {
- writeConfig();
+ d->writeConfig();
}
}
IdentityManagerActivity::~IdentityManagerActivity()
{
+ delete d;
kWarning( hasPendingChanges(), 5325 )
<< "IdentityManagerActivity: There were uncommitted changes!";
- delete mConfig;
}
+PimActivity::ActivityManager *IdentityManagerActivity::activityManager() const
+{
+ return d->activityManager;
+}
+
+
QString IdentityManagerActivity::makeUnique( const QString &name ) const
{
int suffix = 1;
@@ -122,25 +330,25 @@ bool IdentityManagerActivity::isUnique( const QString &name ) \
const void IdentityManagerActivity::commit()
{
// early out:
- if ( !hasPendingChanges() || mReadOnly ) {
+ if ( !hasPendingChanges() || d->readOnly ) {
return;
}
QList<uint> seenUOIDs;
- QList<Identity>::ConstIterator end = mIdentities.constEnd();
- for ( QList<Identity>::ConstIterator it = mIdentities.constBegin();
+ QList<KPIMIdentities::Identity>::ConstIterator end = d->identities.constEnd();
+ for ( QList<KPIMIdentities::Identity>::ConstIterator it = \
d->identities.constBegin(); it != end; ++it ) {
seenUOIDs << ( *it ).uoid();
}
QList<uint> changedUOIDs;
// find added and changed identities:
- for ( QList<Identity>::ConstIterator it = mShadowIdentities.constBegin();
- it != mShadowIdentities.constEnd(); ++it ) {
+ for ( QList<KPIMIdentities::Identity>::ConstIterator it = \
d->shadowIdentities.constBegin(); + it != d->shadowIdentities.constEnd(); \
++it ) { int index = seenUOIDs.indexOf( ( *it ).uoid() );
if ( index != -1 ) {
uint uoid = seenUOIDs.at( index );
- const Identity &orig = identityForUoid( uoid ); // look up in \
mIdentities + const KPIMIdentities::Identity &orig = identityForUoid( uoid \
); // look up in identities if ( *it != orig ) {
// changed identity
kDebug( 5325 ) << "emitting changed() for identity" << uoid;
@@ -162,10 +370,10 @@ void IdentityManagerActivity::commit()
emit deleted( *it );
}
- mIdentities = mShadowIdentities;
- writeConfig();
+ d->identities = d->shadowIdentities;
+ d->writeConfig();
- // now that mIdentities has all the new info, we can emit the added/changed
+ // now that identities has all the new info, we can emit the added/changed
// signals that ship a uoid. This is because the slots might use
// identityForUoid(uoid)...
QList<uint>::ConstIterator changedEnd( changedUOIDs.constEnd() );
@@ -185,19 +393,19 @@ void IdentityManagerActivity::commit()
void IdentityManagerActivity::rollback()
{
- mShadowIdentities = mIdentities;
+ d->shadowIdentities = d->identities;
}
bool IdentityManagerActivity::hasPendingChanges() const
{
- return mIdentities != mShadowIdentities;
+ return d->identities != d->shadowIdentities;
}
QStringList IdentityManagerActivity::identities() const
{
QStringList result;
- ConstIterator end = mIdentities.constEnd();
- for ( ConstIterator it = mIdentities.constBegin();
+ ConstIterator end = d->identities.constEnd();
+ for ( ConstIterator it = d->identities.constBegin();
it != end; ++it ) {
result << ( *it ).identityName();
}
@@ -207,8 +415,8 @@ QStringList IdentityManagerActivity::identities() const
QStringList IdentityManagerActivity::shadowIdentities() const
{
QStringList result;
- ConstIterator end = mShadowIdentities.constEnd();
- for ( ConstIterator it = mShadowIdentities.constBegin();
+ ConstIterator end = d->shadowIdentities.constEnd();
+ for ( ConstIterator it = d->shadowIdentities.constBegin();
it != end; ++it ) {
result << ( *it ).identityName();
}
@@ -217,112 +425,42 @@ QStringList IdentityManagerActivity::shadowIdentities() const
void IdentityManagerActivity::sort()
{
- qSort( mShadowIdentities );
+ qSort( d->shadowIdentities );
}
-void IdentityManagerActivity::writeConfig() const
+QList<KPIMIdentities::Identity>::ConstIterator IdentityManagerActivity::begin() \
const {
- const QStringList identities = groupList( mConfig );
- QStringList::const_iterator groupEnd = identities.constEnd();
- for ( QStringList::const_iterator group = identities.constBegin();
- group != groupEnd; ++group ) {
- mConfig->deleteGroup( *group );
- }
- int i = 0;
- ConstIterator end = mIdentities.constEnd();
- for ( ConstIterator it = mIdentities.constBegin();
- it != end; ++it, ++i ) {
- KConfigGroup cg( mConfig, QString::fromLatin1( "Identity #%1" ).arg( i ) );
- ( *it ).writeConfig( cg );
- if ( ( *it ).isDefault() ) {
- // remember which one is default:
- KConfigGroup general( mConfig, "General" );
- general.writeEntry( configKeyDefaultIdentity, ( *it ).uoid() );
-
- // Also write the default identity to emailsettings
- KEMailSettings es;
- es.setSetting( KEMailSettings::RealName, ( *it ).fullName() );
- es.setSetting( KEMailSettings::EmailAddress, ( *it \
).primaryEmailAddress() );
- es.setSetting( KEMailSettings::Organization, ( *it ).organization() );
- es.setSetting( KEMailSettings::ReplyToAddress, ( *it ).replyToAddr() );
- }
- }
- mConfig->sync();
-
+ return d->identities.constBegin();
}
-void IdentityManagerActivity::readConfig( KConfig *config )
+QList<KPIMIdentities::Identity>::ConstIterator IdentityManagerActivity::end() const
{
- mIdentities.clear();
-
- const QStringList identities = groupList( config );
- if ( identities.isEmpty() ) {
- return; // nothing to be done...
- }
-
- KConfigGroup general( config, "General" );
- uint defaultIdentity = general.readEntry( configKeyDefaultIdentity, 0 );
- bool haveDefault = false;
- QStringList::const_iterator groupEnd = identities.constEnd();
- for ( QStringList::const_iterator group = identities.constBegin();
- group != groupEnd; ++group ) {
- KConfigGroup configGroup( config, *group );
- mIdentities << Identity();
- mIdentities.last().readConfig( configGroup );
- if ( !haveDefault && mIdentities.last().uoid() == defaultIdentity ) {
- haveDefault = true;
- mIdentities.last().setIsDefault( true );
- }
- }
-
- if ( !haveDefault ) {
- kWarning( 5325 ) << "IdentityManagerActivity: There was no default \
identity."
- << "Marking first one as default.";
- mIdentities.first().setIsDefault( true );
- }
- qSort( mIdentities );
-
- mShadowIdentities = mIdentities;
-}
-
-QStringList IdentityManagerActivity::groupList( KConfig *config ) const
-{
- return config->groupList().filter( QRegExp( "^Identity #\\d+$" ) );
-}
-
-IdentityManagerActivity::ConstIterator IdentityManagerActivity::begin() const
-{
- return mIdentities.begin();
-}
-
-IdentityManagerActivity::ConstIterator IdentityManagerActivity::end() const
-{
- return mIdentities.end();
+ return d->identities.constEnd();
}
IdentityManagerActivity::Iterator IdentityManagerActivity::modifyBegin()
{
- return mShadowIdentities.begin();
+ return d->shadowIdentities.begin();
}
IdentityManagerActivity::Iterator IdentityManagerActivity::modifyEnd()
{
- return mShadowIdentities.end();
+ return d->shadowIdentities.end();
}
-const Identity &IdentityManagerActivity::identityForUoid( uint uoid ) const
+const KPIMIdentities::Identity &IdentityManagerActivity::identityForUoid( uint uoid \
) const {
for ( ConstIterator it = begin(); it != end(); ++it ) {
if ( ( *it ).uoid() == uoid ) {
return ( *it );
}
}
- return Identity::null();
+ return KPIMIdentities::Identity::null();
}
-const Identity &IdentityManagerActivity::identityForUoidOrDefault( uint uoid ) const
+const KPIMIdentities::Identity &IdentityManagerActivity::identityForUoidOrDefault( \
uint uoid ) const {
- const Identity &ident = identityForUoid( uoid );
+ const KPIMIdentities::Identity &ident = identityForUoid( uoid );
if ( ident.isNull() ) {
return defaultIdentity();
} else {
@@ -330,20 +468,19 @@ const Identity \
&IdentityManagerActivity::identityForUoidOrDefault( uint uoid ) c }
}
-const Identity &IdentityManagerActivity::identityForAddress(
- const QString &addresses ) const
+const KPIMIdentities::Identity &IdentityManagerActivity::identityForAddress( const \
QString &addresses ) const {
const QStringList addressList = KPIMUtils::splitAddressList( addresses );
foreach ( const QString &fullAddress, addressList ) {
const QString addrSpec = KPIMUtils::extractEmailAddress( fullAddress \
).toLower(); for ( ConstIterator it = begin(); it != end(); ++it ) {
- const Identity &identity = *it;
+ const KPIMIdentities::Identity &identity = *it;
if ( identity.matchesEmailAddress( addrSpec ) ) {
return identity;
}
}
}
- return Identity::null();
+ return KPIMIdentities::Identity::null();
}
bool IdentityManagerActivity::thatIsMe( const QString &addressList ) const
@@ -351,7 +488,7 @@ bool IdentityManagerActivity::thatIsMe( const QString \
&addressList ) const return !identityForAddress( addressList ).isNull();
}
-Identity &IdentityManagerActivity::modifyIdentityForName( const QString &name )
+KPIMIdentities::Identity &IdentityManagerActivity::modifyIdentityForName( const \
QString &name ) {
for ( Iterator it = modifyBegin(); it != modifyEnd(); ++it ) {
if ( ( *it ).identityName() == name ) {
@@ -365,7 +502,7 @@ Identity &IdentityManagerActivity::modifyIdentityForName( const \
QString &name ) return newFromScratch( name );
}
-Identity &IdentityManagerActivity::modifyIdentityForUoid( uint uoid )
+KPIMIdentities::Identity &IdentityManagerActivity::modifyIdentityForUoid( uint uoid \
) {
for ( Iterator it = modifyBegin(); it != modifyEnd(); ++it ) {
if ( ( *it ).uoid() == uoid ) {
@@ -379,7 +516,7 @@ Identity &IdentityManagerActivity::modifyIdentityForUoid( uint \
uoid ) return newFromScratch( i18n( "Unnamed" ) );
}
-const Identity &IdentityManagerActivity::defaultIdentity() const
+const KPIMIdentities::Identity &IdentityManagerActivity::defaultIdentity() const
{
for ( ConstIterator it = begin(); it != end(); ++it ) {
if ( ( *it ).isDefault() ) {
@@ -387,7 +524,7 @@ const Identity &IdentityManagerActivity::defaultIdentity() const
}
}
- if ( mIdentities.isEmpty() ) {
+ if ( d->identities.isEmpty() ) {
kFatal( 5325 ) << "IdentityManagerActivity: No default identity found!";
} else {
kWarning( 5325 ) << "IdentityManagerActivity: No default identity found!";
@@ -399,8 +536,8 @@ bool IdentityManagerActivity::setAsDefault( uint uoid )
{
// First, check if the identity actually exists:
bool found = false;
- for ( ConstIterator it = mShadowIdentities.constBegin();
- it != mShadowIdentities.constEnd(); ++it ) {
+ for ( ConstIterator it = d->shadowIdentities.constBegin();
+ it != d->shadowIdentities.constEnd(); ++it ) {
if ( ( *it ).uoid() == uoid ) {
found = true;
break;
@@ -423,16 +560,16 @@ bool IdentityManagerActivity::setAsDefault( uint uoid )
bool IdentityManagerActivity::removeIdentity( const QString &name )
{
- if ( mShadowIdentities.size() <= 1 ) {
+ if ( d->shadowIdentities.size() <= 1 ) {
return false;
}
for ( Iterator it = modifyBegin(); it != modifyEnd(); ++it ) {
if ( ( *it ).identityName() == name ) {
bool removedWasDefault = ( *it ).isDefault();
- mShadowIdentities.erase( it );
- if ( removedWasDefault && !mShadowIdentities.isEmpty() ) {
- mShadowIdentities.first().setIsDefault( true );
+ d->shadowIdentities.erase( it );
+ if ( removedWasDefault && !d->shadowIdentities.isEmpty() ) {
+ d->shadowIdentities.first().setIsDefault( true );
}
return true;
}
@@ -445,9 +582,9 @@ bool IdentityManagerActivity::removeIdentityForced( const QString \
&name ) for ( Iterator it = modifyBegin(); it != modifyEnd(); ++it ) {
if ( ( *it ).identityName() == name ) {
bool removedWasDefault = ( *it ).isDefault();
- mShadowIdentities.erase( it );
- if ( removedWasDefault && !mShadowIdentities.isEmpty() ) {
- mShadowIdentities.first().setIsDefault( true );
+ d->shadowIdentities.erase( it );
+ if ( removedWasDefault && !d->shadowIdentities.isEmpty() ) {
+ d->shadowIdentities.first().setIsDefault( true );
}
return true;
}
@@ -455,139 +592,36 @@ bool IdentityManagerActivity::removeIdentityForced( const \
QString &name ) return false;
}
-Identity &IdentityManagerActivity::newFromScratch( const QString &name )
+KPIMIdentities::Identity &IdentityManagerActivity::newFromScratch( const QString \
&name ) {
- return newFromExisting( Identity( name ) );
+ return newFromExisting( KPIMIdentities::Identity( name ) );
}
-Identity &IdentityManagerActivity::newFromControlCenter( const QString &name )
+KPIMIdentities::Identity &IdentityManagerActivity::newFromControlCenter( const \
QString &name ) {
KEMailSettings es;
es.setProfile( es.defaultProfileName() );
return
- newFromExisting( Identity( name,
+ newFromExisting( KPIMIdentities::Identity( name,
es.getSetting( KEMailSettings::RealName ),
es.getSetting( KEMailSettings::EmailAddress \
),
es.getSetting( KEMailSettings::Organization \
),
es.getSetting( KEMailSettings::ReplyToAddress \
) ) ); }
-Identity &IdentityManagerActivity::newFromExisting( const Identity &other, const \
QString &name ) +KPIMIdentities::Identity &IdentityManagerActivity::newFromExisting( \
const KPIMIdentities::Identity &other, const QString &name ) {
- mShadowIdentities << other;
- Identity &result = mShadowIdentities.last();
+ d->shadowIdentities << other;
+ KPIMIdentities::Identity &result = d->shadowIdentities.last();
result.setIsDefault( false ); // we don't want two default identities!
- result.setUoid( newUoid() ); // we don't want two identies w/ same UOID
+ result.setUoid( d->newUoid() ); // we don't want two identies w/ same UOID
if ( !name.isNull() ) {
result.setIdentityName( name );
}
return result;
}
-void IdentityManagerActivity::createDefaultIdentity()
-{
- QString fullName, emailAddress;
- bool done = false;
-
- // Check if the application has any settings
- createDefaultIdentity( fullName, emailAddress );
-
- // If not, then use the kcontrol settings
- if ( fullName.isEmpty() && emailAddress.isEmpty() ) {
- KEMailSettings emailSettings;
- fullName = emailSettings.getSetting( KEMailSettings::RealName );
- emailAddress = emailSettings.getSetting( KEMailSettings::EmailAddress );
-
- if ( !fullName.isEmpty() && !emailAddress.isEmpty() ) {
- newFromControlCenter( i18nc( "use default address from control center",
- "Default" ) );
- done = true;
- } else {
- // If KEmailSettings doesn't have name and address, generate something \
from KUser
- KUser user;
- if ( fullName.isEmpty() ) {
- fullName = user.property( KUser::FullName ).toString();
- }
- if ( emailAddress.isEmpty() ) {
- emailAddress = user.loginName();
- if ( !emailAddress.isEmpty() ) {
- KConfigGroup general( mConfig, "General" );
- QString defaultdomain = general.readEntry( "Default domain" );
- if ( !defaultdomain.isEmpty() ) {
- emailAddress += '@' + defaultdomain;
- } else {
- emailAddress.clear();
- }
- }
- }
- }
- }
-
- if ( !done ) {
- // Default identity name
- QString name( i18nc( "Default name for new email accounts/identities.", \
"Unnamed" ) );
-
- if ( !emailAddress.isEmpty() ) {
- // If we have an email address, create a default identity name from it
- QString idName = emailAddress;
- int pos = idName.indexOf( '@' );
- if ( pos != -1 ) {
- name = idName.mid( pos + 1, -1 );
- }
-
- // Make the name a bit more human friendly
- name.replace( '.', ' ' );
- pos = name.indexOf( ' ' );
- if ( pos != 0 ) {
- name[pos + 1] = name[pos + 1].toUpper();
- }
- name[0] = name[0].toUpper();
- } else if ( !fullName.isEmpty() ) {
- // If we have a full name, create a default identity name from it
- name = fullName;
- }
- mShadowIdentities << Identity( name, fullName, emailAddress );
- }
-
- mShadowIdentities.last().setIsDefault( true );
- mShadowIdentities.last().setUoid( newUoid() );
- if ( mReadOnly ) { // commit won't do it in readonly mode
- mIdentities = mShadowIdentities;
- }
-}
-
-int IdentityManagerActivity::newUoid()
-{
- int uoid;
-
- // determine the UOIDs of all saved identities
- QList<uint> usedUOIDs;
- QList<Identity>::ConstIterator end( mIdentities.constEnd() );
- for ( QList<Identity>::ConstIterator it = mIdentities.constBegin();
- it != end; ++it ) {
- usedUOIDs << ( *it ).uoid();
- }
-
- if ( hasPendingChanges() ) {
- // add UOIDs of all shadow identities. Yes, we will add a lot of duplicate
- // UOIDs, but avoiding duplicate UOIDs isn't worth the effort.
- QList<Identity>::ConstIterator endShadow( mShadowIdentities.constEnd() );
- for ( QList<Identity>::ConstIterator it = mShadowIdentities.constBegin();
- it != endShadow; ++it ) {
- usedUOIDs << ( *it ).uoid();
- }
- }
-
- usedUOIDs << 0; // no UOID must be 0 because this value always refers to the
- // default identity
-
- do {
- uoid = KRandom::random();
- } while ( usedUOIDs.indexOf( uoid ) != -1 );
-
- return uoid;
-}
QStringList IdentityManagerActivity::allEmails() const
{
@@ -613,10 +647,11 @@ void IdentityManagerActivity::slotIdentitiesChanged( const \
QString &id ) arg( QDBusConnection::sessionBus().baseService() ).
arg( property( "uniqueDBusPath" ).toString() );
if ( id != ourIdentifier ) {
- mConfig->reparseConfiguration();
+ d->config->reparseConfiguration();
Q_ASSERT( !hasPendingChanges() );
- readConfig( mConfig );
+ d->readConfig( d->config );
emit changed();
}
}
+}
diff --git a/pimactivity/pimwidgets/identity/identitymanageractivity.h \
b/pimactivity/pimwidgets/identity/identitymanageractivity.h index 0e1b429..d5296e3 \
100644
--- a/pimactivity/pimwidgets/identity/identitymanageractivity.h
+++ b/pimactivity/pimwidgets/identity/identitymanageractivity.h
@@ -22,21 +22,23 @@
#define IDENTITYMANAGERACTIVITY_H
#include "pimactivity_export.h"
-#include <kconfiggroup.h>
-#include <QtCore/QObject>
-class KConfigBase;
-class KConfig;
+#include <QObject>
+
class QStringList;
+namespace KPIMIdentities {
+class Identity;
+}
+
namespace PimActivity
{
-
-class Identity;
/**
* @short Manages the list of identities.
* @author Marc Mutz <mutz@kde.org>
**/
+class ActivityManager;
+class IdentityManagerActivityPrivate;
class PIMACTIVITY_EXPORT IdentityManagerActivity : public QObject
{
Q_OBJECT
@@ -49,13 +51,13 @@ public:
* the default identity created here will not be saved.
* It is assumed that a minimum of one identity is always present.
*/
- explicit IdentityManagerActivity( bool readonly = false, QObject *parent=0,
- const char *name=0 );
+ explicit IdentityManagerActivity( ActivityManager *manager, bool readonly = \
false, QObject *parent=0, const char *name=0 ); virtual ~IdentityManagerActivity();
-public:
- typedef QList<Identity>::Iterator Iterator;
- typedef QList<Identity>::ConstIterator ConstIterator;
+ PimActivity::ActivityManager *activityManager() const;
+
+ typedef QList<KPIMIdentities::Identity>::Iterator Iterator;
+ typedef QList<KPIMIdentities::Identity>::ConstIterator ConstIterator;
/**
* Typedef for STL style iterator
@@ -106,7 +108,7 @@ public:
or @ref Identity::null if no such identity exists.
@param addresses the string of addresses to scan for matches
**/
- const Identity &identityForAddress( const QString &addresses ) const;
+ const KPIMIdentities::Identity &identityForAddress( const QString &addresses ) \
const;
/** @return true if @p addressList contains any of our addresses,
false otherwise.
@@ -119,7 +121,7 @@ public:
uoid or @ref Identity::null if not found.
@param uoid the Unique Object Identifier to find identity with
**/
- const Identity &identityForUoid( uint uoid ) const;
+ const KPIMIdentities::Identity &identityForUoid( uint uoid ) const;
/** Convenience menthod.
@@ -127,10 +129,10 @@ public:
uoid or the default identity if not found.
@param uoid the Unique Object Identifier to find identity with
**/
- const Identity &identityForUoidOrDefault( uint uoid ) const;
+ const KPIMIdentities::Identity &identityForUoidOrDefault( uint uoid ) const;
/** @return the default identity */
- const Identity &defaultIdentity() const;
+ const KPIMIdentities::Identity &defaultIdentity() const;
/** Sets the identity with Unique Object Identifier (UOID) @p uoid
to be new the default identity. As usual, use @ref commit to
@@ -146,13 +148,13 @@ public:
see this change, use @ref commit.
@param identityName the identity name to return modifiable reference
**/
- Identity &modifyIdentityForName( const QString &identityName );
+ KPIMIdentities::Identity &modifyIdentityForName( const QString &identityName );
/** @return the identity with Unique Object Identifier (UOID) @p uoid.
This method returns a reference to the identity that can
be modified. To let others see this change, use @ref commit.
**/
- Identity &modifyIdentityForUoid( uint uoid );
+ KPIMIdentities::Identity &modifyIdentityForUoid( uint uoid );
/** Removes the identity with name @p identityName
Will return false if the identity is not found,
@@ -172,17 +174,17 @@ public:
*/
bool removeIdentityForced( const QString &identityName );
- ConstIterator begin() const;
- ConstIterator end() const;
+ QList<KPIMIdentities::Identity>::ConstIterator begin() const;
+ QList<KPIMIdentities::Identity>::ConstIterator end() const;
/// Iterator used by the configuration dialog, which works on a separate list
/// of identities, for modification. Changes are made effective by commit().
Iterator modifyBegin();
Iterator modifyEnd();
- Identity &newFromScratch( const QString &name );
- Identity &newFromControlCenter( const QString &name );
- Identity &newFromExisting( const Identity &other,
- const QString &name=QString() );
+ KPIMIdentities::Identity &newFromScratch( const QString &name );
+ KPIMIdentities::Identity &newFromControlCenter( const QString &name );
+ KPIMIdentities::Identity &newFromExisting( const KPIMIdentities::Identity \
&other, + const QString &name=QString() \
);
/** Returns the list of all email addresses (only name@host) from all
identities */
@@ -207,6 +209,8 @@ Q_SIGNALS:
/** Emitted on @ref commit() for each new identity */
void added( const KPIMIdentities::Identity &ident );
+ void identitiesChanged( const QString &id );
+
protected:
/**
* This is called when no identity has been defined, so we need to
@@ -220,31 +224,13 @@ protected:
protected Q_SLOTS:
void slotRollback();
-protected:
- /** The list that will be seen by everyone */
- QList<Identity> mIdentities;
- /** The list that will be seen by the config dialog */
- QList<Identity> mShadowIdentities;
-
-Q_SIGNALS:
- void identitiesChanged( const QString &id );
-
private Q_SLOTS:
// Connected to the DBus signal
void slotIdentitiesChanged( const QString &id );
private:
- void writeConfig() const;
- void readConfig( KConfig *config );
- QStringList groupList( KConfig *config ) const;
- void createDefaultIdentity();
-
- // returns a new Unique Object Identifier
- int newUoid();
-
-private:
- KConfig *mConfig;
- bool mReadOnly;
+ friend class IdentityManagerActivityPrivate;
+ IdentityManagerActivityPrivate * const d;
};
} // namespace
diff --git a/pimactivity/pimwidgets/identity/org.kde.pim.IdentityManagerActivity.xml \
b/pimactivity/pimwidgets/identity/org.kde.pim.IdentityManagerActivity.xml new file \
mode 100644 index 0000000..fcd7fb5
--- /dev/null
+++ b/pimactivity/pimwidgets/identity/org.kde.pim.IdentityManagerActivity.xml
@@ -0,0 +1,8 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" \
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node>
+ <interface name="org.kde.pim.IdentityManagerActivity">
+ <signal name="identitiesChanged">
+ <arg name="id" type="s" direction="out"/>
+ </signal>
+ </interface>
+</node>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic