2 Copyright 2009 Olivier Trichet <nive@nivalis.org>
4 Permission to use, copy, modify, and distribute this software
5 and its documentation for any purpose and without fee is hereby
6 granted, provided that the above copyright notice appear in all
7 copies and that both that the copyright notice and this
8 permission notice and warranty disclaimer appear in supporting
9 documentation, and that the name of the author not be used in
10 advertising or publicity pertaining to distribution of the
11 software without specific, written prior permission.
13 The author disclaim all warranties with regard to this
14 software, including all implied warranties of merchantability
15 and fitness. In no event shall the author be liable for any
16 special, indirect or consequential damages or any damages
17 whatsoever resulting from loss of use, data or profits, whether
18 in an action of contract, negligence or other tortious action,
19 arising out of or in connection with the use or performance of
25 #include "knaccountmanager.h"
26 #include "knglobals.h"
27 #include "knnntpaccount.h"
30 #include <KIconLoader>
32 #include <KPIMIdentities/Identity>
33 #include <KPIMIdentities/IdentityManager>
34 #include <KPIMIdentities/Signature>
35 #include <KStandardDirs>
42 void Startup::loadLibrariesIconsAndTranslations() const
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" );
56 void Startup::updateDataAndConfiguration() const
58 KConfig
*conf
= KNGlobals::self()->config();
59 KConfigGroup
cg( conf
, "GENERAL" );
60 QList
<int> updateIds
= cg
.readEntry( "KNode::Utilities::Startup::updateId", QList
<int>() );
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";
75 cg
= KConfigGroup( KNGlobals::self()->config(), "IDENTITY" );
76 convertPre45Identity( cg
);
78 // Server accounts and groups identities
79 QDir
dir( KStandardDirs::locateLocal( "data", "knode/", false/*create*/ ) );
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
109 KPIMIdentities::IdentityManager
* im
= KNGlobals::self()->identityManager();
111 // Load the identity from cg
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 ) ) {
124 // output of a command execution
125 signature
.setUrl( cg
.readEntry( "sigFile" ), true/*isExecutable*/ );
128 signature
.setUrl( cg
.readEntry( "sigFile" ), false/*isExecutable*/ );
131 } else if ( !cg
.readEntry( "sigText" ).trimmed().isEmpty() ) {
132 signature
.setText( cg
.readEntry( "sigText" ) );
134 identity
.setSignature( signature
);
136 // Save to the new backend
137 if ( // Is identity empty ?
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
146 // If an identity (even created by another application) has the
147 // same information as currently store in KNode, we reused it.
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() ) );
172 // Ensure that this new identity is seen by the Iterator above in the next call of this method.
174 kDebug() << "Adding a new identity named " << identity
.identityName();
176 cg
.writeEntry( "identity", identity
.uoid() );
178 kDebug() << "Empty identity found";
183 // cg.deleteEntry( "Name" );
184 // cg.deleteEntry( "Email" );
185 // cg.deleteEntry( "Org" );
186 // cg.deleteEntry( "Reply-To" );
187 // cg.deleteEntry( "Mail-Copies-To" );
188 // cg.deleteEntry( "SigningKey" );
189 // cg.deleteEntry( "UseSigFile" );
190 // cg.deleteEntry( "sigFile" );
191 // cg.deleteEntry( "UseSigGenerator" );
192 // cg.deleteEntry( "sigText" );
195 } // namespace Utilities