qtkeychain/keychain.h

106 lines
3.3 KiB
C
Raw Normal View History

2011-10-27 16:15:46 +00:00
/******************************************************************************
* Copyright (C) 2011 Frank Osterfeld <frank.osterfeld@gmail.com> *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. For licensing and distribution *
* details, check the accompanying file 'COPYING'. *
*****************************************************************************/
2011-10-27 16:14:37 +00:00
#ifndef KEYCHAIN_H
#define KEYCHAIN_H
2011-10-27 16:15:46 +00:00
#include <QtCore/QString>
2011-10-27 16:14:37 +00:00
2011-10-27 19:17:54 +00:00
namespace QKeychain {
2011-10-27 18:46:23 +00:00
/**
*
*/
2011-10-27 16:14:37 +00:00
class Keychain {
public:
2011-10-27 18:46:23 +00:00
/**
* Creates a Keychain object.
*
* @param service The service name of your service/application. Used as identifier,
* to disambiguate and avoid clashes with other applications.
*/
2011-10-27 16:14:37 +00:00
explicit Keychain( const QString& service );
2011-10-27 18:46:23 +00:00
/**
* Destructor
*/
2011-10-27 16:14:37 +00:00
~Keychain();
2011-10-27 18:46:23 +00:00
/**
* Error codes
*/
2011-10-27 16:15:46 +00:00
enum Error {
2011-10-27 18:46:23 +00:00
NoError=0, /*< No error occurred, operation was successful */
PasswordNotFound, /*< For the given account no password was found */
CouldNotDeletePassword, /*< Could not delete existing password */
AccessDeniedByUser, /*< User denied access to keychain */
AccessDenied, /*< Access denied for other reasons */
EntryAlreadyExists, /*< There is already a password for the given account and overwriting was not enforced */
OtherError /*< Something else went wrong (errorString() might provide details) */
2011-10-27 16:15:46 +00:00
};
2011-10-27 18:46:23 +00:00
/**
* Overwrite mode when writing passwords to the keychain
*/
2011-10-27 16:15:46 +00:00
enum OverwriteMode {
2011-10-27 18:46:23 +00:00
DoNotOverwrite, /*< Do not overwrite existing entries */
ForceOverwrite /*< Replace old passowrd by new one */
2011-10-27 16:15:46 +00:00
};
2011-10-27 18:46:23 +00:00
/**
* The service name used as identifier.
*/
2011-10-27 16:14:37 +00:00
QString service() const;
2011-10-27 18:46:23 +00:00
/**
* The error code of the last operation.
*/
2011-10-27 16:15:46 +00:00
Error error() const;
2011-10-27 18:46:23 +00:00
/**
* Human-readable error description of the last operation.
*/
2011-10-27 16:15:46 +00:00
QString errorString() const;
2011-10-27 16:14:37 +00:00
2011-10-27 18:46:23 +00:00
/**
* Stores a @p password in the keychain, for a given @p account.
* error() and errorString() hold the result of the write operation.
*
* @param account the account to store a password for
* @param the password to store
* @param om Whether to overwrite existing passwords
*/
2011-10-27 16:15:46 +00:00
void writePassword( const QString& account,
const QString& password,
OverwriteMode om=DoNotOverwrite );
2011-10-27 18:46:23 +00:00
/**
* Reads the @p password for an @p account from the keychain.
* error() and errorString() hold the result of the read operation.
*
* @param account the account ot read the password for
*/
2011-10-27 16:15:46 +00:00
QString readPassword( const QString& account );
2011-10-27 18:46:23 +00:00
/**
* Deletes the @p password for an @p account from the keychain.
* error() and errorString() hold the result of the read operation.
*
* @param account The account to delete the password for
*/
2011-10-27 16:15:46 +00:00
void deletePassword( const QString& account );
2011-10-27 16:14:37 +00:00
private:
class Private;
Private* const d;
Q_DISABLE_COPY(Keychain)
};
2011-10-27 19:17:54 +00:00
}
2011-10-27 16:14:37 +00:00
#endif