safePasswords #36

Manually merged
blue merged 9 commits from safePasswords into master 2020-04-14 16:32:29 +00:00
21 changed files with 288 additions and 153 deletions
Showing only changes of commit 3477226367 - Show all commits

View File

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

View File

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

View File

@ -26,7 +26,8 @@ Core::Squawk::Squawk(QObject* parent):
QObject(parent), QObject(parent),
accounts(), accounts(),
amap(), amap(),
network() network(),
waitingForAccounts(0)
{ {
connect(&network, &NetworkAccess::fileLocalPathResponse, this, &Squawk::fileLocalPathResponse); connect(&network, &NetworkAccess::fileLocalPathResponse, this, &Squawk::fileLocalPathResponse);
connect(&network, &NetworkAccess::downloadFileProgress, this, &Squawk::downloadFileProgress); connect(&network, &NetworkAccess::downloadFileProgress, this, &Squawk::downloadFileProgress);
@ -72,21 +73,7 @@ void Core::Squawk::start()
{ {
qDebug("Starting squawk core.."); qDebug("Starting squawk core..");
QSettings settings; readSettings();
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();
network.start(); network.start();
} }
@ -98,10 +85,17 @@ void Core::Squawk::newAccountRequest(const QMap<QString, QVariant>& map)
QString password = map.value("password").toString(); QString password = map.value("password").toString();
QString resource = map.value("resource").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; QSettings settings;
unsigned int reconnects = settings.value("reconnects", 2).toUInt(); 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); Account* acc = new Account(login, server, password, name, &network);
acc->setResource(resource); acc->setResource(resource);
acc->setReconnectTimes(reconnects); acc->setReconnectTimes(reconnects);
acc->setPasswordType(passwordType);
accounts.push_back(acc); accounts.push_back(acc);
amap.insert(std::make_pair(name, 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::addContact, this, &Squawk::onAccountAddContact);
connect(acc, &Account::addGroup, this, &Squawk::onAccountAddGroup); connect(acc, &Account::addGroup, this, &Squawk::onAccountAddGroup);
connect(acc, &Account::removeGroup, this, &Squawk::onAccountRemoveGroup); 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&, const QString&>(&Account::removeContact),
connect(acc, qOverload<const QString&>(&Account::removeContact), this, qOverload<const QString&>(&Squawk::onAccountRemoveContact)); 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::changeContact, this, &Squawk::onAccountChangeContact);
connect(acc, &Account::addPresence, this, &Squawk::onAccountAddPresence); connect(acc, &Account::addPresence, this, &Squawk::onAccountAddPresence);
connect(acc, &Account::removePresence, this, &Squawk::onAccountRemovePresence); 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)}, {"state", QVariant::fromValue(Shared::ConnectionState::disconnected)},
{"offline", QVariant::fromValue(Shared::Availability::offline)}, {"offline", QVariant::fromValue(Shared::Availability::offline)},
{"error", ""}, {"error", ""},
{"avatarPath", acc->getAvatarPath()} {"avatarPath", acc->getAvatarPath()},
{"passwordType", QVariant::fromValue(passwordType)}
}; };
emit newAccount(map); emit newAccount(map);
@ -486,8 +484,6 @@ void Core::Squawk::onAccountRemoveRoomPresence(const QString& jid, const QString
emit removeRoomParticipant(acc->getName(), jid, nick); emit removeRoomParticipant(acc->getName(), jid, nick);
} }
void Core::Squawk::onAccountChangeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data) void Core::Squawk::onAccountChangeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
{ {
Account* acc = static_cast<Account*>(sender()); 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); 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: signals:
void quit(); void quit();
void ready();
void newAccount(const QMap<QString, QVariant>&); void newAccount(const QMap<QString, QVariant>&);
void changeAccount(const QString& account, const QMap<QString, QVariant>& data); void changeAccount(const QString& account, const QMap<QString, QVariant>& data);
void removeAccount(const QString& account); void removeAccount(const QString& account);
@ -109,11 +110,18 @@ private:
AccountsMap amap; AccountsMap amap;
Shared::Availability state; Shared::Availability state;
NetworkAccess network; NetworkAccess network;
uint8_t waitingForAccounts;
private:
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource);
private slots: 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 onAccountConnectionStateChanged(Shared::ConnectionState state);
void onAccountAvailabilityChanged(Shared::Availability state); void onAccountAvailabilityChanged(Shared::Availability state);
void onAccountChanged(const QMap<QString, QVariant>& data); 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 onAccountChangeRoomPresence(const QString& jid, const QString& nick, const QMap<QString, QVariant>& data);
void onAccountRemoveRoomPresence(const QString& jid, const QString& nick); void onAccountRemoveRoomPresence(const QString& jid, const QString& nick);
void onAccountChangeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data); 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::uploadFileProgress, &w, &Squawk::fileProgress);
QObject::connect(squawk, &Core::Squawk::uploadFileError, &w, &Squawk::fileError); QObject::connect(squawk, &Core::Squawk::uploadFileError, &w, &Squawk::fileError);
QObject::connect(squawk, &Core::Squawk::responseVCard, &w, &Squawk::responseVCard); QObject::connect(squawk, &Core::Squawk::responseVCard, &w, &Squawk::responseVCard);
QObject::connect(squawk, &Core::Squawk::ready, &w, &Squawk::readSettings);
coreThread->start(); coreThread->start();
w.readSettings();
int result = app.exec(); int result = app.exec();

View File

@ -35,8 +35,8 @@ enum class ConnectionState {
}; };
Q_ENUM_NS(ConnectionState) Q_ENUM_NS(ConnectionState)
static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
static const ConnectionState connectionStateHighest = ConnectionState::error; static const ConnectionState ConnectionStateHighest = ConnectionState::error;
static const ConnectionState connectionStateLowest = ConnectionState::disconnected; static const ConnectionState ConnectionStateLowest = ConnectionState::disconnected;
enum class Availability { enum class Availability {
online, online,
@ -48,8 +48,8 @@ enum class Availability {
offline offline
}; };
Q_ENUM_NS(Availability) Q_ENUM_NS(Availability)
static const Availability availabilityHighest = Availability::offline; static const Availability AvailabilityHighest = Availability::offline;
static const Availability availabilityLowest = Availability::online; static const Availability AvailabilityLowest = Availability::online;
static const std::deque<QString> availabilityThemeIcons = { static const std::deque<QString> availabilityThemeIcons = {
"user-online", "user-online",
"user-away", "user-away",
@ -59,7 +59,6 @@ static const std::deque<QString> availabilityThemeIcons = {
"user-invisible", "user-invisible",
"user-offline" "user-offline"
}; };
static const std::deque<QString> availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Invisible", "Offline"};
enum class SubscriptionState { enum class SubscriptionState {
none, none,
@ -69,10 +68,9 @@ enum class SubscriptionState {
unknown unknown
}; };
Q_ENUM_NS(SubscriptionState) Q_ENUM_NS(SubscriptionState)
static const SubscriptionState subscriptionStateHighest = SubscriptionState::unknown; static const SubscriptionState SubscriptionStateHighest = SubscriptionState::unknown;
static const SubscriptionState subscriptionStateLowest = SubscriptionState::none; 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> 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 { enum class Affiliation {
unspecified, unspecified,
@ -83,9 +81,8 @@ enum class Affiliation {
owner owner
}; };
Q_ENUM_NS(Affiliation) Q_ENUM_NS(Affiliation)
static const Affiliation affiliationHighest = Affiliation::owner; static const Affiliation AffiliationHighest = Affiliation::owner;
static const Affiliation affiliationLowest = Affiliation::unspecified; static const Affiliation AffiliationLowest = Affiliation::unspecified;
static const std::deque<QString> affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"};
enum class Role { enum class Role {
unspecified, unspecified,
@ -95,9 +92,8 @@ enum class Role {
moderator moderator
}; };
Q_ENUM_NS(Role) Q_ENUM_NS(Role)
static const Role roleHighest = Role::moderator; static const Role RoleHighest = Role::moderator;
static const Role roleLowest = Role::unspecified; static const Role RoleLowest = Role::unspecified;
static const std::deque<QString> roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"};
enum class Avatar { enum class Avatar {
empty, empty,
@ -105,10 +101,21 @@ enum class Avatar {
valid valid
}; };
Q_ENUM_NS(Avatar) 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"}; 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 #endif // SHARED_ENUMS_H

View File

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

View File

@ -21,6 +21,7 @@
#include "enums.h" #include "enums.h"
#include "message.h" #include "message.h"
#include "exception.h"
#include <map> #include <map>
@ -42,6 +43,7 @@ namespace Shared {
static QString getName(Affiliation af); static QString getName(Affiliation af);
static QString getName(Role rl); static QString getName(Role rl);
static QString getName(Message::State rl); static QString getName(Message::State rl);
static QString getName(AccountPassword ap);
const std::deque<QString> availability; const std::deque<QString> availability;
const std::deque<QString> connectionState; const std::deque<QString> connectionState;
@ -49,6 +51,7 @@ namespace Shared {
const std::deque<QString> affiliation; const std::deque<QString> affiliation;
const std::deque<QString> role; const std::deque<QString> role;
const std::deque<QString> messageState; const std::deque<QString> messageState;
const std::deque<QString> accountPassword;
template<typename T> template<typename T>
static T fromInt(int src); static T fromInt(int src);
@ -56,6 +59,19 @@ namespace Shared {
template<typename T> template<typename T>
static T fromInt(unsigned int src); 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: private:
static Global* instance; static Global* instance;
}; };

View File

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

View File

@ -65,6 +65,10 @@
<translatorcomment>Ресурс по умолчанию</translatorcomment> <translatorcomment>Ресурс по умолчанию</translatorcomment>
<translation>QXmpp</translation> <translation>QXmpp</translation>
</message> </message>
<message>
<source>Password storage</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Accounts</name> <name>Accounts</name>
@ -270,6 +274,22 @@ p, li { white-space: pre-wrap; }
<source>Delivered</source> <source>Delivered</source>
<translation>Доставлено</translation> <translation>Доставлено</translation>
</message> </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>
<context> <context>
<name>JoinConference</name> <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()), error(data.value("error").toString()),
avatarPath(data.value("avatarPath").toString()), avatarPath(data.value("avatarPath").toString()),
state(Shared::ConnectionState::disconnected), 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"); QMap<QString, QVariant>::const_iterator sItr = data.find("state");
if (sItr != data.end()) { if (sItr != data.end()) {
@ -155,6 +156,8 @@ QVariant Models::Account::data(int column) const
return resource; return resource;
case 8: case 8:
return avatarPath; return avatarPath;
case 9:
return Shared::Global::getName(passwordType);
default: default:
return QVariant(); return QVariant();
} }
@ -162,7 +165,7 @@ QVariant Models::Account::data(int column) const
int Models::Account::columnCount() const int Models::Account::columnCount() const
{ {
return 9; return 10;
} }
void Models::Account::update(const QString& field, const QVariant& value) 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()); setError(value.toString());
} else if (field == "avatarPath") { } else if (field == "avatarPath") {
setAvatarPath(value.toString()); setAvatarPath(value.toString());
} else if (field == "passwordType") {
setPasswordType(value.toUInt());
} }
} }
@ -240,3 +245,22 @@ QString Models::Account::getFullJid() const
{ {
return getBareJid() + "/" + resource; 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 #ifndef MODELS_ACCOUNT_H
#define MODELS_ACCOUNT_H #define MODELS_ACCOUNT_H
#include "item.h"
#include "shared/enums.h" #include "shared/enums.h"
#include "shared/utils.h" #include "shared/utils.h"
#include "shared/icons.h" #include "shared/icons.h"
#include "shared/global.h" #include "shared/global.h"
#include "item.h"
#include <QVariant> #include <QVariant>
#include <QIcon> #include <QIcon>
@ -60,6 +60,10 @@ namespace Models {
void setAvailability(unsigned int p_avail); void setAvailability(unsigned int p_avail);
Shared::Availability getAvailability() const; Shared::Availability getAvailability() const;
void setPasswordType(Shared::AccountPassword pt);
void setPasswordType(unsigned int pt);
Shared::AccountPassword getPasswordType() const;
QIcon getStatusIcon(bool big = false) const; QIcon getStatusIcon(bool big = false) const;
QVariant data(int column) const override; QVariant data(int column) const override;
@ -79,6 +83,7 @@ namespace Models {
QString avatarPath; QString avatarPath;
Shared::ConnectionState state; Shared::ConnectionState state;
Shared::Availability availability; Shared::Availability availability;
Shared::AccountPassword passwordType;
protected slots: protected slots:
void toOfflineState() override; void toOfflineState() override;

View File

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

View File

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

View File

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

View File

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

View File

@ -19,10 +19,17 @@
#include "account.h" #include "account.h"
#include "ui_account.h" #include "ui_account.h"
Account::Account() Account::Account():
: m_ui ( new Ui::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() Account::~Account()
@ -37,6 +44,7 @@ QMap<QString, QVariant> Account::value() const
map["server"] = m_ui->server->text(); map["server"] = m_ui->server->text();
map["name"] = m_ui->name->text(); map["name"] = m_ui->name->text();
map["resource"] = m_ui->resource->text(); map["resource"] = m_ui->resource->text();
map["passwordType"] = m_ui->passwordType->currentIndex();
return map; return map;
} }
@ -53,4 +61,5 @@ void Account::setData(const QMap<QString, QVariant>& data)
m_ui->server->setText(data.value("server").toString()); m_ui->server->setText(data.value("server").toString());
m_ui->name->setText(data.value("name").toString()); m_ui->name->setText(data.value("name").toString());
m_ui->resource->setText(data.value("resource").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 #ifndef ACCOUNT_H
#define ACCOUNT_H #define ACCOUNT_H
#include <QScopedPointer>
#include <QDialog> #include <QDialog>
#include <QScopedPointer>
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include <QVariant> #include <QVariant>
#include "shared/global.h"
namespace Ui namespace Ui
{ {
class Account; class Account;

View File

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

View File

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

View File

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