30 #include <KIconLoader>
32 #include <KPIMIdentities/Identity>
33 #include <KPIMIdentities/IdentityManager>
34 #include <KPIMIdentities/Signature>
35 #include <KStandardDirs>
44 KIconLoader::global()->addAppDir(
"knode" );
45 KIconLoader::global()->addAppDir(
"libkdepim" );
47 KGlobal::locale()->insertCatalog(
"libkdepim" );
48 KGlobal::locale()->insertCatalog(
"libkpgp" );
49 KGlobal::locale()->insertCatalog(
"libmessagecomposer" );
50 KGlobal::locale()->insertCatalog(
"libmessageviewer" );
59 KConfigGroup cg( conf,
"GENERAL" );
61 if ( !updateIds.contains( 1 ) ) {
62 convertPre45Identities();
65 cg.writeEntry(
"KNode::Utilities::Startup::updateId", updateIds );
68 void Startup::convertPre45Identities()
const
70 KSharedConfigPtr conf;
74 kDebug() <<
"Converting global identity";
76 convertPre45Identity( cg );
79 QDir dir( KStandardDirs::locateLocal(
"data",
"knode/",
false ) );
80 QStringList serverPaths = dir.entryList( QStringList(
"nntp.*" ), QDir::Dirs );
81 foreach (
const QString &subPath, serverPaths ) {
82 QDir serverDir( dir.absolutePath() +
'/' + subPath );
84 QFile f( serverDir.absolutePath() +
"/info" );
85 kDebug() <<
"Reading" << f.fileName();
87 conf = KSharedConfig::openConfig( f.fileName(), KConfig::SimpleConfig );
88 cg = KConfigGroup( conf, QString() );
89 kDebug() <<
"Converting identity of account from" << f.fileName() <<
':' << cg.readEntry(
"server" );
90 convertPre45Identity( cg );
93 QStringList grpInfos = serverDir.entryList( QStringList(
"*.grpinfo" ), QDir::Files );
94 foreach (
const QString &grpInfo, grpInfos ) {
95 QFile infoFile( serverDir.absolutePath() +
'/' + grpInfo );
96 if ( infoFile.exists() ) {
97 conf = KSharedConfig::openConfig( infoFile.fileName(), KConfig::SimpleConfig );
98 cg = KConfigGroup( conf, QString() );
99 kDebug() <<
"Converting identity of group from" << infoFile.fileName();
100 convertPre45Identity( cg );
107 void Startup::convertPre45Identity( KConfigGroup &cg )
const
112 KPIMIdentities::Identity identity;
113 identity.setFullName( cg.readEntry(
"Name" ).trimmed() );
114 identity.setPrimaryEmailAddress( cg.readEntry(
"Email" ).trimmed() );
115 identity.setOrganization( cg.readEntry(
"Org" ).trimmed() );
116 identity.setReplyToAddr( cg.readEntry(
"Reply-To" ).trimmed() );
117 identity.setProperty(
"Mail-Copies-To", cg.readEntry(
"Mail-Copies-To" ).trimmed() );
118 identity.setPGPSigningKey( cg.readEntry(
"SigningKey" ).toLatin1() );
120 KPIMIdentities::Signature signature;
121 if ( cg.readEntry(
"UseSigFile",
false ) ) {
122 if ( !cg.readEntry(
"sigFile" ).trimmed().isEmpty() ) {
123 if ( cg.readEntry(
"UseSigGenerator",
false ) ) {
125 signature.setUrl( cg.readEntry(
"sigFile" ),
true );
128 signature.setUrl( cg.readEntry(
"sigFile" ),
false );
131 }
else if ( !cg.readEntry(
"sigText" ).trimmed().isEmpty() ) {
132 signature.setText( cg.readEntry(
"sigText" ) );
134 identity.setSignature( signature );
138 !identity.fullName().isEmpty()
139 || !identity.primaryEmailAddress().isEmpty()
140 || !identity.organization().isEmpty()
141 || !identity.replyToAddr().isEmpty()
142 || !identity.property(
"Mail-Copies-To" ).toString().isEmpty()
143 || !identity.pgpSigningKey().isEmpty()
144 || identity.signature().type() != KPIMIdentities::Signature::Disabled
148 bool isDuplicate =
false;
149 KPIMIdentities::IdentityManager::ConstIterator it = im->begin();
150 while ( it != im->end() ) {
151 KPIMIdentities::Identity otherId = (*it);
153 identity.fullName() == otherId.fullName()
154 && identity.primaryEmailAddress() == otherId.primaryEmailAddress()
155 && identity.organization() == otherId.organization()
156 && identity.replyToAddr() == otherId.replyToAddr()
157 && identity.property(
"Mail-Copies-To" ).toString() == otherId.property(
"Mail-Copies-To" ).toString()
158 && identity.pgpSigningKey() == otherId.pgpSigningKey()
159 && identity.signature() == otherId.signature()
169 kDebug() <<
"An identity containing the same information was found : " << identity.identityName();
171 identity = im->newFromExisting( identity, im->makeUnique( identity.fullName() ) );
174 kDebug() <<
"Adding a new identity named " << identity.identityName();
176 cg.writeEntry(
"identity", identity.uoid() );
178 kDebug() <<
"Empty identity found";
KConfig * config()
Returns KNode's main configuration.
static KNGlobals * self()
Return the KNGlobals instance.
void updateDataAndConfiguration() const
Updates internal data at startup.
KPIMIdentities::IdentityManager * identityManager()
Returns the identity manager.
void loadLibrariesIconsAndTranslations() const
Loads translation catalogs and icons directories for imported libraries.