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

@ -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: