french -> French
[kdepim.git] / importwizard / importwizardutil.cpp
blob4483713d9d9e2b6c2868cec501e72bedc82aae13
1 /*
2 Copyright (c) 2012-2013 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "importwizardutil.h"
19 #include <KSharedConfig>
20 #include <KConfigGroup>
21 #include <QColor>
22 #include <Nepomuk2/Tag>
23 #include <Nepomuk2/Variant>
24 #include "messagetag.h"
25 #include <QDebug>
26 #include <kwallet.h>
30 void ImportWizardUtil::mergeLdap(const ldapStruct &ldap)
32 KSharedConfigPtr ldapConfig = KSharedConfig::openConfig( QLatin1String( "kabldaprc" ) );
33 int numberOfLdapSelected = 0;
34 KConfigGroup grp;
35 if (ldapConfig->hasGroup(QLatin1String("LDAP"))) {
36 grp = ldapConfig->group(QLatin1String("LDAP"));
37 numberOfLdapSelected = grp.readEntry(QLatin1String("NumSelectedHosts"),0);
38 grp.writeEntry(QLatin1String("NumSelectedHosts"),(numberOfLdapSelected+1));
39 } else {
40 grp = ldapConfig->group(QLatin1String("LDAP"));
41 grp.writeEntry(QLatin1String("NumSelectedHosts"),1);
43 KConfigGroup ldapSeach = ldapConfig->group(QLatin1String("LDAPSearch"));
44 ldapSeach.writeEntry(QLatin1String("SearchType"), 0);
46 const int port = ldap.port;
47 if (port!=-1)
48 grp.writeEntry(QString::fromLatin1("SelectedPort%1").arg(numberOfLdapSelected),port);
49 grp.writeEntry(QString::fromLatin1("SelectedHost%1").arg(numberOfLdapSelected),ldap.ldapUrl.host());
50 if (ldap.useSSL) {
51 grp.writeEntry(QString::fromLatin1("SelectedSecurity%1").arg(numberOfLdapSelected),QString::fromLatin1("SSL"));
52 } else if (ldap.useTLS){
53 grp.writeEntry(QString::fromLatin1("SelectedSecurity%1").arg(numberOfLdapSelected),QString::fromLatin1("TLS"));
54 } else {
55 grp.writeEntry(QString::fromLatin1("SelectedSecurity%1").arg(numberOfLdapSelected),QString::fromLatin1("None"));
58 if (ldap.saslMech == QLatin1String("GSSAPI")) {
59 grp.writeEntry(QString::fromLatin1("SelectedMech%1").arg(numberOfLdapSelected),QString::fromLatin1("GSSAPI"));
60 grp.writeEntry(QString::fromLatin1("SelectedAuth%1").arg(numberOfLdapSelected),QString::fromLatin1("SASL"));
61 } else if (ldap.saslMech.isEmpty()) {
62 grp.writeEntry(QString::fromLatin1("SelectedMech%1").arg(numberOfLdapSelected),QString::fromLatin1("PLAIN"));
63 grp.writeEntry(QString::fromLatin1("SelectedAuth%1").arg(numberOfLdapSelected),QString::fromLatin1("Simple"));
64 } else {
65 qDebug()<<" Mech SASL undefined"<<ldap.saslMech;
67 grp.writeEntry(QString::fromLatin1("SelectedVersion%1").arg(numberOfLdapSelected),QString::number(3));
68 grp.writeEntry(QString::fromLatin1("SelectedBind%1").arg(numberOfLdapSelected),ldap.dn);
69 //TODO: Verify selectedbase
70 grp.writeEntry(QString::fromLatin1("SelectedBase%1").arg(numberOfLdapSelected),ldap.ldapUrl.path());
71 if (ldap.timeout != -1) {
72 grp.writeEntry(QString::fromLatin1("SelectedTimeLimit%1").arg(numberOfLdapSelected),ldap.timeout);
74 if (ldap.limit != -1) {
75 grp.writeEntry(QString::fromLatin1("SelectedSizeLimit%1").arg(numberOfLdapSelected),ldap.limit);
77 if (!ldap.password.isEmpty()) {
78 storeInKWallet(QString::fromLatin1("SelectedPwdBind%1").arg(numberOfLdapSelected), ImportWizardUtil::Ldap, ldap.password);
80 grp.sync();
83 void ImportWizardUtil::addNepomukTag(const QList<tagStruct>& tagList)
85 const int listSize(tagList.size());
86 for(int i = 0; i<listSize; ++i) {
87 Nepomuk2::Tag nepomukTag( tagList.at(i).name );
88 nepomukTag.setLabel( tagList.at(i).name );
89 if ( tagList.at(i).color.isValid() ) {
90 const QString colorName = tagList.at(i).color.name();
91 nepomukTag.setProperty( Vocabulary::MessageTag::textColor(), colorName );
96 void ImportWizardUtil::storeInKWallet(const QString &name, ImportWizardUtil::ResourceType type, const QString &password)
98 KWallet::Wallet * wallet = 0;
99 switch(type) {
100 case Imap:
101 wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0 );
102 if ( wallet && wallet->isOpen() ) {
103 if ( !wallet->hasFolder( QLatin1String("imap") ) )
104 wallet->createFolder( QLatin1String("imap") );
105 wallet->setFolder( QLatin1String("imap") );
106 wallet->writePassword( name+QLatin1String("rc"), password );
108 break;
109 case Pop3:
110 wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0);
111 if ( wallet && wallet->isOpen() ) {
112 if ( !wallet->hasFolder( QLatin1String("pop3") ) ) {
113 wallet->createFolder( QLatin1String("pop3") );
115 wallet->setFolder( QLatin1String("pop3") );
116 wallet->writePassword( name, password );
118 break;
119 case Ldap:
120 wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 );
121 if ( wallet && wallet->isOpen() ) {
122 if ( !wallet->hasFolder( QLatin1String("ldapclient") ) ) {
123 wallet->createFolder( QLatin1String("ldapclient") );
125 wallet->setFolder( QLatin1String("ldapclient") );
126 wallet->writePassword(name, password );
129 delete wallet;