Commit be884de4 authored by Artyom Kirnev's avatar Artyom Kirnev
Browse files

tiny clean up

parent 157a2cc8
......@@ -234,7 +234,7 @@ void KateSQLView::slotConnectionCreate()
m_manager->createConnection(c);
if (m_manager->storeCredentials(c) != 0) {
if (m_manager->storeCredentials(c) != SQLManager::K_WALLET_CONNECTION_SUCCESSFUL) {
qDebug() << "Connection credentials not saved";
}
}
......@@ -261,7 +261,7 @@ void KateSQLView::slotConnectionEdit()
m_manager->removeConnection(previousName);
m_manager->createConnection(c);
if (m_manager->storeCredentials(c) != 0) {
if (m_manager->storeCredentials(c) != SQLManager::K_WALLET_CONNECTION_SUCCESSFUL) {
qDebug() << "Connection credentials not saved";
}
}
......
......@@ -124,7 +124,7 @@ bool SQLManager::isValidAndOpen(const QString &connection)
QString password;
int ret = readCredentials(connection, password);
if (ret != 0) {
if (ret != SQLManager::K_WALLET_CONNECTION_SUCCESSFUL) {
qDebug() << "Can't retrieve password from kwallet. returned code" << ret;
} else {
db.setPassword(password);
......@@ -176,13 +176,12 @@ Wallet *SQLManager::openWallet()
return m_wallet;
}
// return 0 on success, -1 on error, -2 on user reject
int SQLManager::storeCredentials(const Connection &conn)
{
Wallet *wallet = openWallet();
if (!wallet) { // user reject
return -2;
return SQLManager::K_WALLET_CONNECTION_REJECTED_BY_USER;
}
QMap<QString, QString> map;
......@@ -200,18 +199,17 @@ int SQLManager::storeCredentials(const Connection &conn)
map[QStringLiteral("hostname")] = conn.hostname.toUpper();
map[QStringLiteral("port")] = QString::number(conn.port);
}
const int result = (wallet->writeMap(conn.name, map) == 0) ? 0 : -1;
const int result = (wallet->writeMap(conn.name, map) == SQLManager::K_WALLET_CONNECTION_SUCCESSFUL) ? SQLManager::K_WALLET_CONNECTION_SUCCESSFUL : SQLManager::K_WALLET_CONNECTION_ERROR;
return result;
}
// return 0 on success, -1 on error or not found, -2 on user reject
// if success, password contain the password
int SQLManager::readCredentials(const QString &name, QString &password)
{
Wallet *wallet = openWallet();
if (!wallet) { // user reject
return -2;
return SQLManager::K_WALLET_CONNECTION_REJECTED_BY_USER;
}
QMap<QString, QString> map;
......@@ -219,11 +217,11 @@ int SQLManager::readCredentials(const QString &name, QString &password)
if (wallet->readMap(name, map) == 0) {
if (!map.isEmpty()) {
password = map.value(QStringLiteral("password"));
return 0;
return SQLManager::K_WALLET_CONNECTION_SUCCESSFUL;
}
}
return -1;
return SQLManager::K_WALLET_CONNECTION_ERROR;
}
ConnectionModel *SQLManager::connectionModel()
......
......@@ -32,6 +32,9 @@ public:
KWallet::Wallet *openWallet();
int storeCredentials(const Connection &conn);
int readCredentials(const QString &name, QString &password);
static const int K_WALLET_CONNECTION_SUCCESSFUL = 0;
static const int K_WALLET_CONNECTION_ERROR = -1;
static const int K_WALLET_CONNECTION_REJECTED_BY_USER = -2;
public Q_SLOTS:
void removeConnection(const QString &name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment