first moves to safe pasword storing, preparing the structure

This commit is contained in:
Blue 2020-04-04 19:40:32 +03:00
parent ddfb3419cc
commit 3477226367
21 changed files with 288 additions and 153 deletions

View File

@ -53,7 +53,8 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
avatarType(),
ownVCardRequestInProgress(false),
network(p_net),
pendingStateMessages()
pendingStateMessages(),
passwordType(Shared::AccountPassword::plain)
{
config.setUser(p_login);
config.setDomain(p_server);
@ -266,6 +267,11 @@ QString Core::Account::getServer() const
return config.domain();
}
Shared::AccountPassword Core::Account::getPasswordType() const
{
return passwordType;
}
void Core::Account::onRosterReceived()
{
vm->requestClientVCard(); //TODO need to make sure server actually supports vCards
@ -296,6 +302,11 @@ void Core::Account::onRosterItemAdded(const QString& bareJid)
}
}
void Core::Account::setPasswordType(Shared::AccountPassword pt)
{
passwordType = pt;
}
void Core::Account::onRosterItemChanged(const QString& bareJid)
{
std::map<QString, Contact*>::const_iterator itr = contacts.find(bareJid);

View File

@ -55,7 +55,13 @@ class Account : public QObject
{
Q_OBJECT
public:
Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, NetworkAccess* p_net, QObject* parent = 0);
Account(
const QString& p_login,
const QString& p_server,
const QString& p_password,
const QString& p_name,
NetworkAccess* p_net,
QObject* parent = 0);
~Account();
void connect();
@ -70,6 +76,7 @@ public:
QString getResource() const;
QString getAvatarPath() const;
Shared::Availability getAvailability() const;
Shared::AccountPassword getPasswordType() const;
void setName(const QString& p_name);
void setLogin(const QString& p_login);
@ -77,6 +84,7 @@ public:
void setPassword(const QString& p_password);
void setResource(const QString& p_resource);
void setAvailability(Shared::Availability avail);
void setPasswordType(Shared::AccountPassword pt);
QString getFullJid() const;
void sendMessage(Shared::Message data);
void sendMessage(const Shared::Message& data, const QString& path);
@ -158,6 +166,7 @@ private:
bool ownVCardRequestInProgress;
NetworkAccess* network;
std::map<QString, QString> pendingStateMessages;
Shared::AccountPassword passwordType;
private slots:
void onClientConnected();

View File

@ -26,7 +26,8 @@ Core::Squawk::Squawk(QObject* parent):
QObject(parent),
accounts(),
amap(),
network()
network(),
waitingForAccounts(0)
{
connect(&network, &NetworkAccess::fileLocalPathResponse, this, &Squawk::fileLocalPathResponse);
connect(&network, &NetworkAccess::downloadFileProgress, this, &Squawk::downloadFileProgress);
@ -72,21 +73,7 @@ void Core::Squawk::start()
{
qDebug("Starting squawk core..");
QSettings settings;
settings.beginGroup("core");
int size = settings.beginReadArray("accounts");
for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
addAccount(
settings.value("login").toString(),
settings.value("server").toString(),
settings.value("password").toString(),
settings.value("name").toString(),
settings.value("resource").toString()
);
}
settings.endArray();
settings.endGroup();
readSettings();
network.start();
}
@ -98,10 +85,17 @@ void Core::Squawk::newAccountRequest(const QMap<QString, QVariant>& map)
QString password = map.value("password").toString();
QString resource = map.value("resource").toString();
addAccount(login, server, password, name, resource);
addAccount(login, server, password, name, resource, Shared::AccountPassword::plain);
}
void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource)
void Core::Squawk::addAccount(
const QString& login,
const QString& server,
const QString& password,
const QString& name,
const QString& resource,
Shared::AccountPassword passwordType
)
{
QSettings settings;
unsigned int reconnects = settings.value("reconnects", 2).toUInt();
@ -109,6 +103,7 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
Account* acc = new Account(login, server, password, name, &network);
acc->setResource(resource);
acc->setReconnectTimes(reconnects);
acc->setPasswordType(passwordType);
accounts.push_back(acc);
amap.insert(std::make_pair(name, acc));
@ -119,8 +114,10 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
connect(acc, &Account::addContact, this, &Squawk::onAccountAddContact);
connect(acc, &Account::addGroup, this, &Squawk::onAccountAddGroup);
connect(acc, &Account::removeGroup, this, &Squawk::onAccountRemoveGroup);
connect(acc, qOverload<const QString&, const QString&>(&Account::removeContact), this, qOverload<const QString&, const QString&>(&Squawk::onAccountRemoveContact));
connect(acc, qOverload<const QString&>(&Account::removeContact), this, qOverload<const QString&>(&Squawk::onAccountRemoveContact));
connect(acc, qOverload<const QString&, const QString&>(&Account::removeContact),
this, qOverload<const QString&, const QString&>(&Squawk::onAccountRemoveContact));
connect(acc, qOverload<const QString&>(&Account::removeContact),
this, qOverload<const QString&>(&Squawk::onAccountRemoveContact));
connect(acc, &Account::changeContact, this, &Squawk::onAccountChangeContact);
connect(acc, &Account::addPresence, this, &Squawk::onAccountAddPresence);
connect(acc, &Account::removePresence, this, &Squawk::onAccountRemovePresence);
@ -149,7 +146,8 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
{"state", QVariant::fromValue(Shared::ConnectionState::disconnected)},
{"offline", QVariant::fromValue(Shared::Availability::offline)},
{"error", ""},
{"avatarPath", acc->getAvatarPath()}
{"avatarPath", acc->getAvatarPath()},
{"passwordType", QVariant::fromValue(passwordType)}
};
emit newAccount(map);
@ -486,8 +484,6 @@ void Core::Squawk::onAccountRemoveRoomPresence(const QString& jid, const QString
emit removeRoomParticipant(acc->getName(), jid, nick);
}
void Core::Squawk::onAccountChangeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
{
Account* acc = static_cast<Account*>(sender());
@ -574,3 +570,49 @@ void Core::Squawk::uploadVCard(const QString& account, const Shared::VCard& card
itr->second->uploadVCard(card);
}
void Core::Squawk::readSettings()
{
QSettings settings;
settings.beginGroup("core");
int size = settings.beginReadArray("accounts");
waitingForAccounts = size;
for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
parseAccount(
settings.value("login").toString(),
settings.value("server").toString(),
settings.value("password", "").toString(),
settings.value("name").toString(),
settings.value("resource").toString(),
Shared::Global::fromInt<Shared::AccountPassword>(settings.value("passwordType", static_cast<int>(Shared::AccountPassword::plain)).toInt())
);
}
settings.endArray();
settings.endGroup();
}
void Core::Squawk::accountReady()
{
--waitingForAccounts;
if (waitingForAccounts == 0) {
emit ready();
}
}
void Core::Squawk::parseAccount(
const QString& login,
const QString& server,
const QString& password,
const QString& name,
const QString& resource,
Shared::AccountPassword passwordType
)
{
switch (passwordType) {
case Shared::AccountPassword::plain:
addAccount(login, server, password, name, resource, passwordType);
accountReady();
break;
}
}

View File

@ -45,6 +45,7 @@ public:
signals:
void quit();
void ready();
void newAccount(const QMap<QString, QVariant>&);
void changeAccount(const QString& account, const QMap<QString, QVariant>& data);
void removeAccount(const QString& account);
@ -109,11 +110,18 @@ private:
AccountsMap amap;
Shared::Availability state;
NetworkAccess network;
private:
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource);
uint8_t waitingForAccounts;
private slots:
void addAccount(
const QString& login,
const QString& server,
const QString& password,
const QString& name,
const QString& resource,
Shared::AccountPassword passwordType
);
void onAccountConnectionStateChanged(Shared::ConnectionState state);
void onAccountAvailabilityChanged(Shared::Availability state);
void onAccountChanged(const QMap<QString, QVariant>& data);
@ -135,6 +143,18 @@ private slots:
void onAccountChangeRoomPresence(const QString& jid, const QString& nick, const QMap<QString, QVariant>& data);
void onAccountRemoveRoomPresence(const QString& jid, const QString& nick);
void onAccountChangeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
private:
void readSettings();
void accountReady();
void parseAccount(
const QString& login,
const QString& server,
const QString& password,
const QString& name,
const QString& resource,
Shared::AccountPassword passwordType
);
};
}

View File

@ -146,9 +146,9 @@ int main(int argc, char *argv[])
QObject::connect(squawk, &Core::Squawk::uploadFileProgress, &w, &Squawk::fileProgress);
QObject::connect(squawk, &Core::Squawk::uploadFileError, &w, &Squawk::fileError);
QObject::connect(squawk, &Core::Squawk::responseVCard, &w, &Squawk::responseVCard);
QObject::connect(squawk, &Core::Squawk::ready, &w, &Squawk::readSettings);
coreThread->start();
w.readSettings();
int result = app.exec();

View File

@ -35,8 +35,8 @@ enum class ConnectionState {
};
Q_ENUM_NS(ConnectionState)
static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
static const ConnectionState connectionStateHighest = ConnectionState::error;
static const ConnectionState connectionStateLowest = ConnectionState::disconnected;
static const ConnectionState ConnectionStateHighest = ConnectionState::error;
static const ConnectionState ConnectionStateLowest = ConnectionState::disconnected;
enum class Availability {
online,
@ -48,8 +48,8 @@ enum class Availability {
offline
};
Q_ENUM_NS(Availability)
static const Availability availabilityHighest = Availability::offline;
static const Availability availabilityLowest = Availability::online;
static const Availability AvailabilityHighest = Availability::offline;
static const Availability AvailabilityLowest = Availability::online;
static const std::deque<QString> availabilityThemeIcons = {
"user-online",
"user-away",
@ -59,7 +59,6 @@ static const std::deque<QString> availabilityThemeIcons = {
"user-invisible",
"user-offline"
};
static const std::deque<QString> availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Invisible", "Offline"};
enum class SubscriptionState {
none,
@ -69,10 +68,9 @@ enum class SubscriptionState {
unknown
};
Q_ENUM_NS(SubscriptionState)
static const SubscriptionState subscriptionStateHighest = SubscriptionState::unknown;
static const SubscriptionState subscriptionStateLowest = SubscriptionState::none;
static const SubscriptionState SubscriptionStateHighest = SubscriptionState::unknown;
static const SubscriptionState SubscriptionStateLowest = SubscriptionState::none;
static const std::deque<QString> subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"};
static const std::deque<QString> subscriptionStateNames = {"None", "From", "To", "Both", "Unknown"};
enum class Affiliation {
unspecified,
@ -83,9 +81,8 @@ enum class Affiliation {
owner
};
Q_ENUM_NS(Affiliation)
static const Affiliation affiliationHighest = Affiliation::owner;
static const Affiliation affiliationLowest = Affiliation::unspecified;
static const std::deque<QString> affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"};
static const Affiliation AffiliationHighest = Affiliation::owner;
static const Affiliation AffiliationLowest = Affiliation::unspecified;
enum class Role {
unspecified,
@ -95,9 +92,8 @@ enum class Role {
moderator
};
Q_ENUM_NS(Role)
static const Role roleHighest = Role::moderator;
static const Role roleLowest = Role::unspecified;
static const std::deque<QString> roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"};
static const Role RoleHighest = Role::moderator;
static const Role RoleLowest = Role::unspecified;
enum class Avatar {
empty,
@ -105,10 +101,21 @@ enum class Avatar {
valid
};
Q_ENUM_NS(Avatar)
static const Avatar AvatarHighest = Avatar::valid;
static const Avatar AvatarLowest = Avatar::empty;
static const std::deque<QString> messageStateNames = {"Pending", "Sent", "Delivered", "Error"};
static const std::deque<QString> messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
enum class AccountPassword {
plain,
jammed,
kwallet,
alwaysAsk
};
Q_ENUM_NS(AccountPassword)
static const AccountPassword AccountPasswordHighest = AccountPassword::alwaysAsk;
static const AccountPassword AccountPasswordLowest = AccountPassword::plain;
}
#endif // SHARED_ENUMS_H

View File

@ -65,6 +65,12 @@ Shared::Global::Global():
tr("Sent"),
tr("Delivered"),
tr("Error")
}),
accountPassword({
tr("Plain"),
tr("Jammed"),
tr("KWallet"),
tr("Always Ask")
})
{
if (instance != 0) {
@ -81,90 +87,56 @@ Shared::Global * Shared::Global::getInstance()
QString Shared::Global::getName(Message::State rl)
{
return instance->messageState[int(rl)];
return instance->messageState[static_cast<int>(rl)];
}
QString Shared::Global::getName(Shared::Affiliation af)
{
return instance->affiliation[int(af)];
return instance->affiliation[static_cast<int>(af)];
}
QString Shared::Global::getName(Shared::Availability av)
{
return instance->availability[int(av)];
return instance->availability[static_cast<int>(av)];
}
QString Shared::Global::getName(Shared::ConnectionState cs)
{
return instance->connectionState[int(cs)];
return instance->connectionState[static_cast<int>(cs)];
}
QString Shared::Global::getName(Shared::Role rl)
{
return instance->role[int(rl)];
return instance->role[static_cast<int>(rl)];
}
QString Shared::Global::getName(Shared::SubscriptionState ss)
{
return instance->subscriptionState[int(ss)];
return instance->subscriptionState[static_cast<int>(ss)];
}
template<>
Shared::Availability Shared::Global::fromInt(int src)
QString Shared::Global::getName(Shared::AccountPassword ap)
{
if (src < static_cast<int>(Shared::availabilityLowest) && src > static_cast<int>(Shared::availabilityHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::Availability>(src);
return instance->accountPassword[static_cast<int>(ap)];
}
template<>
Shared::Availability Shared::Global::fromInt(unsigned int src)
{
if (src < static_cast<int>(Shared::availabilityLowest) && src > static_cast<int>(Shared::availabilityHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::Availability>(src);
}
#define FROM_INT_INPL(Enum) \
template<> \
Enum Shared::Global::fromInt(int src) \
{ \
if (src < static_cast<int>(Enum##Lowest) && src > static_cast<int>(Enum##Highest)) { \
throw EnumOutOfRange(#Enum); \
} \
return static_cast<Enum>(src); \
} \
template<> \
Enum Shared::Global::fromInt(unsigned int src) {return fromInt<Enum>(static_cast<int>(src));}
template<>
Shared::ConnectionState Shared::Global::fromInt(int src)
{
if (src < static_cast<int>(Shared::connectionStateLowest) && src > static_cast<int>(Shared::connectionStateHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::ConnectionState>(src);
}
template<>
Shared::ConnectionState Shared::Global::fromInt(unsigned int src)
{
if (src < static_cast<int>(Shared::connectionStateLowest) && src > static_cast<int>(Shared::connectionStateHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::ConnectionState>(src);
}
template<>
Shared::SubscriptionState Shared::Global::fromInt(int src)
{
if (src < static_cast<int>(Shared::subscriptionStateLowest) && src > static_cast<int>(Shared::subscriptionStateHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::SubscriptionState>(src);
}
template<>
Shared::SubscriptionState Shared::Global::fromInt(unsigned int src)
{
if (src < static_cast<int>(Shared::subscriptionStateLowest) && src > static_cast<int>(Shared::subscriptionStateHighest)) {
qDebug("An attempt to set invalid availability to Squawk core, skipping");
}
return static_cast<Shared::SubscriptionState>(src);
}
FROM_INT_INPL(Shared::Message::State)
FROM_INT_INPL(Shared::Affiliation)
FROM_INT_INPL(Shared::ConnectionState)
FROM_INT_INPL(Shared::Role)
FROM_INT_INPL(Shared::SubscriptionState)
FROM_INT_INPL(Shared::AccountPassword)
FROM_INT_INPL(Shared::Avatar)
FROM_INT_INPL(Shared::Availability)

View File

@ -21,6 +21,7 @@
#include "enums.h"
#include "message.h"
#include "exception.h"
#include <map>
@ -42,6 +43,7 @@ namespace Shared {
static QString getName(Affiliation af);
static QString getName(Role rl);
static QString getName(Message::State rl);
static QString getName(AccountPassword ap);
const std::deque<QString> availability;
const std::deque<QString> connectionState;
@ -49,6 +51,7 @@ namespace Shared {
const std::deque<QString> affiliation;
const std::deque<QString> role;
const std::deque<QString> messageState;
const std::deque<QString> accountPassword;
template<typename T>
static T fromInt(int src);
@ -56,6 +59,19 @@ namespace Shared {
template<typename T>
static T fromInt(unsigned int src);
class EnumOutOfRange:
public Utils::Exception
{
public:
EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {}
std::string getMessage() const{
return "An attempt to get enum " + name + " from integer out of range of that enum";
}
private:
std::string name;
};
private:
static Global* instance;
};

View File

@ -46,6 +46,8 @@ public:
delivered,
error
};
static const State StateHighest = State::error;
static const State StateLowest = State::pending;
Message(Type p_type);
Message();

View File

@ -65,6 +65,10 @@
<translatorcomment>Ресурс по умолчанию</translatorcomment>
<translation>QXmpp</translation>
</message>
<message>
<source>Password storage</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Accounts</name>
@ -270,6 +274,22 @@ p, li { white-space: pre-wrap; }
<source>Delivered</source>
<translation>Доставлено</translation>
</message>
<message>
<source>Plain</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Jammed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>KWallet</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Always Ask</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>JoinConference</name>

View File

@ -28,7 +28,8 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
error(data.value("error").toString()),
avatarPath(data.value("avatarPath").toString()),
state(Shared::ConnectionState::disconnected),
availability(Shared::Availability::offline)
availability(Shared::Availability::offline),
passwordType(Shared::AccountPassword::plain)
{
QMap<QString, QVariant>::const_iterator sItr = data.find("state");
if (sItr != data.end()) {
@ -155,6 +156,8 @@ QVariant Models::Account::data(int column) const
return resource;
case 8:
return avatarPath;
case 9:
return Shared::Global::getName(passwordType);
default:
return QVariant();
}
@ -162,7 +165,7 @@ QVariant Models::Account::data(int column) const
int Models::Account::columnCount() const
{
return 9;
return 10;
}
void Models::Account::update(const QString& field, const QVariant& value)
@ -185,6 +188,8 @@ void Models::Account::update(const QString& field, const QVariant& value)
setError(value.toString());
} else if (field == "avatarPath") {
setAvatarPath(value.toString());
} else if (field == "passwordType") {
setPasswordType(value.toUInt());
}
}
@ -240,3 +245,22 @@ QString Models::Account::getFullJid() const
{
return getBareJid() + "/" + resource;
}
Shared::AccountPassword Models::Account::getPasswordType() const
{
return passwordType;
}
void Models::Account::setPasswordType(Shared::AccountPassword pt)
{
if (passwordType != pt) {
passwordType = pt;
changed(9);
}
}
void Models::Account::setPasswordType(unsigned int pt)
{
setPasswordType(Shared::Global::fromInt<Shared::AccountPassword>(pt));
}

View File

@ -19,11 +19,11 @@
#ifndef MODELS_ACCOUNT_H
#define MODELS_ACCOUNT_H
#include "item.h"
#include "shared/enums.h"
#include "shared/utils.h"
#include "shared/icons.h"
#include "shared/global.h"
#include "item.h"
#include <QVariant>
#include <QIcon>
@ -60,6 +60,10 @@ namespace Models {
void setAvailability(unsigned int p_avail);
Shared::Availability getAvailability() const;
void setPasswordType(Shared::AccountPassword pt);
void setPasswordType(unsigned int pt);
Shared::AccountPassword getPasswordType() const;
QIcon getStatusIcon(bool big = false) const;
QVariant data(int column) const override;
@ -79,6 +83,7 @@ namespace Models {
QString avatarPath;
Shared::ConnectionState state;
Shared::Availability availability;
Shared::AccountPassword passwordType;
protected slots:
void toOfflineState() override;

View File

@ -58,11 +58,11 @@ QVariant Models::Participant::data(int column) const
{
switch (column) {
case 4:
return static_cast<uint8_t>(affiliation);
return QVariant::fromValue(affiliation);
case 5:
return static_cast<uint8_t>(role);
return QVariant::fromValue(role);
case 6:
return static_cast<quint8>(getAvatarState());
return QVariant::fromValue(getAvatarState());
case 7:
return getAvatarPath();
default:
@ -100,12 +100,7 @@ void Models::Participant::setAffiliation(Shared::Affiliation p_aff)
void Models::Participant::setAffiliation(unsigned int aff)
{
if (aff <= static_cast<uint8_t>(Shared::affiliationHighest)) {
Shared::Affiliation affil = static_cast<Shared::Affiliation>(aff);
setAffiliation(affil);
} else {
qDebug() << "An attempt to set wrong affiliation" << aff << "to the room participant" << name;
}
setAffiliation(Shared::Global::fromInt<Shared::Affiliation>(aff));
}
Shared::Role Models::Participant::getRole() const
@ -123,12 +118,7 @@ void Models::Participant::setRole(Shared::Role p_role)
void Models::Participant::setRole(unsigned int p_role)
{
if (p_role <= static_cast<uint8_t>(Shared::roleHighest)) {
Shared::Role r = static_cast<Shared::Role>(p_role);
setRole(r);
} else {
qDebug() << "An attempt to set wrong role" << p_role << "to the room participant" << name;
}
setRole(Shared::Global::fromInt<Shared::Role>(p_role));
}
QString Models::Participant::getAvatarPath() const
@ -158,11 +148,4 @@ void Models::Participant::setAvatarState(Shared::Avatar p_state)
}
void Models::Participant::setAvatarState(unsigned int p_state)
{
if (p_state <= static_cast<quint8>(Shared::Avatar::valid)) {
Shared::Avatar state = static_cast<Shared::Avatar>(p_state);
setAvatarState(state);
} else {
qDebug() << "An attempt to set invalid avatar state" << p_state << "to the room participant" << name << ", skipping";
}
}
{setAvatarState(Shared::Global::fromInt<Shared::Avatar>(p_state));}

View File

@ -20,6 +20,7 @@
#define MODELS_PARTICIPANT_H
#include "abstractparticipant.h"
#include "shared/global.h"
namespace Models {

View File

@ -41,7 +41,7 @@ Squawk::Squawk(QWidget *parent) :
m_ui->roster->header()->setStretchLastSection(false);
m_ui->roster->header()->setSectionResizeMode(0, QHeaderView::Stretch);
for (int i = static_cast<int>(Shared::availabilityLowest); i < static_cast<int>(Shared::availabilityHighest) + 1; ++i) {
for (int i = static_cast<int>(Shared::AvailabilityLowest); i < static_cast<int>(Shared::AvailabilityHighest) + 1; ++i) {
Shared::Availability av = static_cast<Shared::Availability>(i);
m_ui->comboBox->addItem(Shared::availabilityIcon(av), Shared::Global::getName(av));
}
@ -71,7 +71,7 @@ Squawk::~Squawk() {
void Squawk::onAccounts()
{
if (accounts == 0) {
accounts = new Accounts(rosterModel.accountsModel, this);
accounts = new Accounts(rosterModel.accountsModel);
accounts->setAttribute(Qt::WA_DeleteOnClose);
connect(accounts, &Accounts::destroyed, this, &Squawk::onAccountsClosed);
connect(accounts, &Accounts::newAccount, this, &Squawk::newAccountRequest);

View File

@ -52,7 +52,6 @@ public:
explicit Squawk(QWidget *parent = nullptr);
~Squawk() override;
void readSettings();
void writeSettings();
signals:
@ -82,6 +81,7 @@ signals:
void uploadVCard(const QString& account, const Shared::VCard& card);
public slots:
void readSettings();
void newAccount(const QMap<QString, QVariant>& account);
void changeAccount(const QString& account, const QMap<QString, QVariant>& data);
void removeAccount(const QString& account);

View File

@ -19,10 +19,17 @@
#include "account.h"
#include "ui_account.h"
Account::Account()
: m_ui ( new Ui::Account )
Account::Account():
QDialog(),
m_ui(new Ui::Account)
{
m_ui->setupUi ( this );
m_ui->setupUi (this);
for (int i = static_cast<int>(Shared::AccountPasswordLowest); i < static_cast<int>(Shared::AccountPasswordHighest) + 1; ++i) {
Shared::AccountPassword ap = static_cast<Shared::AccountPassword>(i);
m_ui->passwordType->addItem(Shared::Global::getName(ap));
}
m_ui->passwordType->setCurrentIndex(static_cast<int>(Shared::AccountPassword::plain));
}
Account::~Account()
@ -37,6 +44,7 @@ QMap<QString, QVariant> Account::value() const
map["server"] = m_ui->server->text();
map["name"] = m_ui->name->text();
map["resource"] = m_ui->resource->text();
map["passwordType"] = m_ui->passwordType->currentIndex();
return map;
}
@ -53,4 +61,5 @@ void Account::setData(const QMap<QString, QVariant>& data)
m_ui->server->setText(data.value("server").toString());
m_ui->name->setText(data.value("name").toString());
m_ui->resource->setText(data.value("resource").toString());
m_ui->passwordType->setCurrentIndex(data.value("passwordType").toInt());
}

View File

@ -19,12 +19,14 @@
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <QScopedPointer>
#include <QDialog>
#include <QScopedPointer>
#include <QMap>
#include <QString>
#include <QVariant>
#include "shared/global.h"
namespace Ui
{
class Account;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>395</width>
<height>272</height>
<width>438</width>
<height>342</height>
</rect>
</property>
<property name="windowTitle">
@ -114,14 +114,14 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Resource</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="resource">
<property name="toolTip">
<string>A resource name like &quot;Home&quot; or &quot;Work&quot;</string>
@ -131,6 +131,16 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Password storage</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="passwordType"/>
</item>
</layout>
</item>
<item>

View File

@ -22,6 +22,7 @@
#include <QDebug>
Accounts::Accounts(Models::Accounts* p_model, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::Accounts),
model(p_model),
editing(false),
@ -40,7 +41,7 @@ Accounts::Accounts(Models::Accounts* p_model, QWidget *parent) :
Accounts::~Accounts() = default;
void Accounts::onAddButton(bool clicked)
void Accounts::onAddButton()
{
Account* acc = new Account();
connect(acc, &Account::accepted, this, &Accounts::onAccountAccepted);
@ -70,7 +71,7 @@ void Accounts::onAccountRejected()
editing = false;
}
void Accounts::onEditButton(bool clicked)
void Accounts::onEditButton()
{
Account* acc = new Account();
@ -80,7 +81,8 @@ void Accounts::onEditButton(bool clicked)
{"password", mAcc->getPassword()},
{"server", mAcc->getServer()},
{"name", mAcc->getName()},
{"resource", mAcc->getResource()}
{"resource", mAcc->getResource()},
{"passwordType", QVariant::fromValue(mAcc->getPasswordType())}
});
acc->lockId();
connect(acc, &Account::accepted, this, &Accounts::onAccountAccepted);
@ -89,7 +91,7 @@ void Accounts::onEditButton(bool clicked)
acc->exec();
}
void Accounts::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
void Accounts::onSelectionChanged()
{
int selectionSize = m_ui->tableView->selectionModel()->selection().size();
if (selectionSize == 0) {
@ -131,7 +133,7 @@ void Accounts::updateConnectButton()
}
}
void Accounts::onConnectButton(bool clicked)
void Accounts::onConnectButton()
{
QItemSelectionModel* sm = m_ui->tableView->selectionModel();
int selectionSize = sm->selection().size();
@ -145,7 +147,7 @@ void Accounts::onConnectButton(bool clicked)
}
}
void Accounts::onDeleteButton(bool clicked)
void Accounts::onDeleteButton()
{
QItemSelectionModel* sm = m_ui->tableView->selectionModel();
int selectionSize = sm->selection().size();

View File

@ -46,13 +46,13 @@ signals:
void removeAccount(const QString&);
private slots:
void onAddButton(bool clicked = 0);
void onEditButton(bool clicked = 0);
void onConnectButton(bool clicked = 0);
void onDeleteButton(bool clicked = 0);
void onAddButton();
void onEditButton();
void onConnectButton();
void onDeleteButton();
void onAccountAccepted();
void onAccountRejected();
void onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void onSelectionChanged();
void updateConnectButton();
private: