• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
  • utils
startup.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2009 Olivier Trichet <nive@nivalis.org>
3 
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.
12 
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
20  this software.
21 */
22 
23 #include "startup.h"
24 
25 #include "knaccountmanager.h"
26 #include "knglobals.h"
27 #include "knnntpaccount.h"
28 
29 #include <KDebug>
30 #include <KIconLoader>
31 #include <KLocale>
32 #include <KPIMIdentities/Identity>
33 #include <KPIMIdentities/IdentityManager>
34 #include <KPIMIdentities/Signature>
35 #include <KStandardDirs>
36 #include <QDir>
37 
38 
39 namespace KNode {
40 namespace Utilities {
41 
42 void Startup::loadLibrariesIconsAndTranslations() const
43 {
44  KIconLoader::global()->addAppDir( "knode" );
45  KIconLoader::global()->addAppDir( "libkdepim" );
46 
47  KGlobal::locale()->insertCatalog( "libkdepim" );
48  KGlobal::locale()->insertCatalog( "libkpgp" );
49  KGlobal::locale()->insertCatalog( "libmessagecomposer" );
50  KGlobal::locale()->insertCatalog( "libmessageviewer" );
51 
52 }
53 
54 
55 
56 void Startup::updateDataAndConfiguration() const
57 {
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();
63  updateIds << 1;
64  }
65  cg.writeEntry( "KNode::Utilities::Startup::updateId", updateIds );
66 }
67 
68 void Startup::convertPre45Identities() const
69 {
70  KSharedConfigPtr conf;
71  KConfigGroup cg;
72 
73  // Global identity
74  kDebug() << "Converting global identity";
75  cg = KConfigGroup( KNGlobals::self()->config(), "IDENTITY" );
76  convertPre45Identity( cg );
77 
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 );
83  // server account
84  QFile f( serverDir.absolutePath() + "/info" );
85  kDebug() << "Reading" << f.fileName();
86  if ( f.exists() ) {
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 );
91 
92  // groups
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 );
101  }
102  }
103  }
104  }
105 }
106 
107 void Startup::convertPre45Identity( KConfigGroup &cg ) const
108 {
109  KPIMIdentities::IdentityManager* im = KNGlobals::self()->identityManager();
110 
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() );
119 
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*/ );
126  } else {
127  // content of a file
128  signature.setUrl( cg.readEntry( "sigFile" ), false/*isExecutable*/ );
129  }
130  }
131  } else if ( !cg.readEntry( "sigText" ).trimmed().isEmpty() ) {
132  signature.setText( cg.readEntry( "sigText" ) );
133  }
134  identity.setSignature( signature );
135 
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
145  ) {
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);
152  isDuplicate = (
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()
160  );
161  if ( isDuplicate ) {
162  break;
163  }
164  ++it;
165  }
166 
167  if ( isDuplicate ) {
168  identity = (*it);
169  kDebug() << "An identity containing the same information was found : " << identity.identityName();
170  } else {
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.
173  im->commit();
174  kDebug() << "Adding a new identity named " << identity.identityName();
175  }
176  cg.writeEntry( "identity", identity.uoid() );
177  } else {
178  kDebug() << "Empty identity found";
179  }
180 
181  // Delete old entry
182  // TODO: readd this
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" );
193 }
194 
195 } // namespace Utilities
196 } // namespace KNode
KNGlobals::config
KConfig * config()
Returns KNode's main configuration.
Definition: knglobals.cpp:88
knaccountmanager.h
KNGlobals::self
static KNGlobals * self()
Return the KNGlobals instance.
Definition: knglobals.cpp:72
knnntpaccount.h
KNode::Utilities::Startup::updateDataAndConfiguration
void updateDataAndConfiguration() const
Updates internal data at startup.
Definition: startup.cpp:56
KNGlobals::identityManager
KPIMIdentities::IdentityManager * identityManager()
Returns the identity manager.
Definition: knglobals.cpp:167
startup.h
knglobals.h
QList< int >
KNode::Utilities::Startup::loadLibrariesIconsAndTranslations
void loadLibrariesIconsAndTranslations() const
Loads translation catalogs and icons directories for imported libraries.
Definition: startup.cpp:42
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal