2 * Copyright (C) 2005, Mart Kelder (mart.kde@hccnet.nl)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef KORNPASSWORD_H
21 #define KORNPASSWORD_H
24 namespace KWallet
{ class Wallet
; }
29 * This class can be used to store and retrieve passwords.
30 * It uses KWallet if possible, and the configuartion files otherwise.
45 * This function gets a password for KOrn.
47 * @param box The boxnumber of the account
48 * @param account The accountnumber of the account
49 * @param fallbackConfig The configuration file if KWallet cannot be used.
50 * @return The password, or QString() if it failes.
52 static QString
readKOrnPassword( int box
, int account
, const KConfigBase
& fallbackConfig
);
54 * This function gets a password with is puts in KWallet by KMail
56 * @param accountnr The id of the KMail account
57 * @param fallbackConfig The configuration used if KWallet isn't available.
58 * @return The password, QStirng::null if it failes.
60 static QString
readKMailPassword( int accountnr
, const KConfigBase
& fallbackConfig
);
63 * This function saves a password for usage in KOrn.
65 * @param box The boxnumber of the account.
66 * @param account The accountnumber of the account.
67 * @param fallbackConfig The configuration file if KWallet isn't available.
68 * @param password The password to be stored.
70 static void writeKOrnPassword( int box
, int account
, KConfigBase
& fallbackConfig
, const QString
& password
);
73 * This function deletes a password from both KWallet and the configuration file
75 * @param box The boxnumber of the account.
76 * @param account The accountnumber of the account.
77 * @param fallbackConfig The configuration file if KWallet isn't available.
79 static void deleteKOrnPassword( int box
, int account
, KConfigBase
& fallbackConfig
);
82 * This function deletes a password from KWallet
84 * @param box The boxnumber of the account.
85 * @param account The accountnumber of the account.
87 static bool deleteKOrnPassword( int box
, int account
);
90 * This function moves a password
92 * @param boxSrc The source box number.
93 * @param accountSrc The source account number.
94 * @param configSrc The source configuration group.
95 * @param boxDest The destination box number.
96 * @param accountDest The destination account number
97 * @param configDest The destination configuration group.
99 static void moveKOrnPassword( int boxSrc
, int accountSrc
, KConfigBase
&configSrc
,
100 int boxDest
, int accountDest
, KConfigBase
&configDest
);
103 * This swaps the password from one box/account combination to another.
105 * @param box1 The box number of the first password.
106 * @param account1 The account number of the first password.
107 * @param config1 The configurationgroup of the first password.
108 * @param box2 The box number of the second password.
109 * @param account2 The account number of the second password.
110 * @param config2 The configurationgroup of the second password.
112 static void swapKOrnPassword( int box1
, int account1
, KConfigBase
&config1
, int box2
, int account2
, KConfigBase
&config2
);
115 * This swaps the Wallet password from one box/account combination to another.
117 * @param box1 The box number of the first password.
118 * @param account1 The number of accounts to be investigated
119 * @param box2 The box number of the first password.
120 * @param account2 The number of accounts to be investigated
122 static void swapKOrnWalletPassword( int box1
, int account1
,int box2
, int account2
);
125 * This swaps the password from one box to another.
127 * @param box1 The box number of the first password.
128 * @param accountnumber1 The number of accounts to be investigated
129 * @param box2 The box number of the first password.
130 * @param accountnumber2 The number of accounts to be investigated
132 static void swapKOrnWalletPasswords( int box1
, int accountnumber1
,int box2
, int accountnumber2
);
135 * This function read the password from the configuration (wallet or configuration) with UseWallet set to !newUseWalletValue,
136 * afterwards, it writes the password to the configuration with UseWallet set to newUseWalletValue
138 * @param box The box number
139 * @param account The account number
140 * @param config The configuration group
141 * @param newUseWalletValue true to transport a password from a configuration to a wallet, false the other wat around
143 static void rewritePassword( int box
, int account
, KConfigBase
&config
, bool newUseWalletValue
);
146 * If set to true, this class will try to use KWallet,
147 * if false, it will not.
149 * The default value is true.
151 * @param value The value to be set to this property.
153 static void setUseWallet( const bool value
);
157 static bool readKOrnPassword( int box
, int account
, QString
& password
);
158 static bool writeKOrnPassword( int box
, int account
, const QString
& password
);
160 static QString
KMailDecrypt( const QString
& enc
);
162 static KWallet::Wallet
*m_wallet
;
163 static bool m_openFailed
;
164 static bool m_useWallet
;
167 #endif //KORNPASSWORD_H