From 3477226367ea44ce5e9ebddd8d29952706b749d0 Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 4 Apr 2020 19:40:32 +0300 Subject: [PATCH] first moves to safe pasword storing, preparing the structure --- core/account.cpp | 13 +++++- core/account.h | 11 ++++- core/squawk.cpp | 88 ++++++++++++++++++++++++++---------- core/squawk.h | 26 +++++++++-- main.cpp | 2 +- shared/enums.h | 37 ++++++++------- shared/global.cpp | 94 ++++++++++++++------------------------- shared/global.h | 16 +++++++ shared/message.h | 2 + translations/squawk.ru.ts | 20 +++++++++ ui/models/account.cpp | 28 +++++++++++- ui/models/account.h | 7 ++- ui/models/participant.cpp | 29 +++--------- ui/models/participant.h | 1 + ui/squawk.cpp | 4 +- ui/squawk.h | 2 +- ui/widgets/account.cpp | 15 +++++-- ui/widgets/account.h | 4 +- ui/widgets/account.ui | 18 ++++++-- ui/widgets/accounts.cpp | 14 +++--- ui/widgets/accounts.h | 10 ++--- 21 files changed, 288 insertions(+), 153 deletions(-) diff --git a/core/account.cpp b/core/account.cpp index 37a8c16..ec92e96 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -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::const_iterator itr = contacts.find(bareJid); diff --git a/core/account.h b/core/account.h index 1688fc9..386835c 100644 --- a/core/account.h +++ b/core/account.h @@ -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 pendingStateMessages; + Shared::AccountPassword passwordType; private slots: void onClientConnected(); diff --git a/core/squawk.cpp b/core/squawk.cpp index 387c685..e8dd1ae 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -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& 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(&Account::removeContact), this, qOverload(&Squawk::onAccountRemoveContact)); - connect(acc, qOverload(&Account::removeContact), this, qOverload(&Squawk::onAccountRemoveContact)); + connect(acc, qOverload(&Account::removeContact), + this, qOverload(&Squawk::onAccountRemoveContact)); + connect(acc, qOverload(&Account::removeContact), + this, qOverload(&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& data) { Account* acc = static_cast(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(settings.value("passwordType", static_cast(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; + } +} diff --git a/core/squawk.h b/core/squawk.h index 29e5b8c..6d5f7d9 100644 --- a/core/squawk.h +++ b/core/squawk.h @@ -45,6 +45,7 @@ public: signals: void quit(); + void ready(); void newAccount(const QMap&); void changeAccount(const QString& account, const QMap& 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& data); @@ -135,6 +143,18 @@ private slots: void onAccountChangeRoomPresence(const QString& jid, const QString& nick, const QMap& data); void onAccountRemoveRoomPresence(const QString& jid, const QString& nick); void onAccountChangeMessage(const QString& jid, const QString& id, const QMap& 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 + ); }; } diff --git a/main.cpp b/main.cpp index 25de512..eeb7138 100644 --- a/main.cpp +++ b/main.cpp @@ -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(); diff --git a/shared/enums.h b/shared/enums.h index 158695c..bf55377 100644 --- a/shared/enums.h +++ b/shared/enums.h @@ -35,8 +35,8 @@ enum class ConnectionState { }; Q_ENUM_NS(ConnectionState) static const std::deque 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 availabilityThemeIcons = { "user-online", "user-away", @@ -59,7 +59,6 @@ static const std::deque availabilityThemeIcons = { "user-invisible", "user-offline" }; -static const std::deque 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 subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"}; -static const std::deque 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 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 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 messageStateNames = {"Pending", "Sent", "Delivered", "Error"}; static const std::deque 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 diff --git a/shared/global.cpp b/shared/global.cpp index 4d3399a..81bee3f 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -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(rl)]; } QString Shared::Global::getName(Shared::Affiliation af) { - return instance->affiliation[int(af)]; + return instance->affiliation[static_cast(af)]; } QString Shared::Global::getName(Shared::Availability av) { - return instance->availability[int(av)]; + return instance->availability[static_cast(av)]; } QString Shared::Global::getName(Shared::ConnectionState cs) { - return instance->connectionState[int(cs)]; + return instance->connectionState[static_cast(cs)]; } QString Shared::Global::getName(Shared::Role rl) { - return instance->role[int(rl)]; + return instance->role[static_cast(rl)]; } QString Shared::Global::getName(Shared::SubscriptionState ss) { - return instance->subscriptionState[int(ss)]; + return instance->subscriptionState[static_cast(ss)]; } -template<> -Shared::Availability Shared::Global::fromInt(int src) +QString Shared::Global::getName(Shared::AccountPassword ap) { - if (src < static_cast(Shared::availabilityLowest) && src > static_cast(Shared::availabilityHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(src); + return instance->accountPassword[static_cast(ap)]; } -template<> -Shared::Availability Shared::Global::fromInt(unsigned int src) -{ - if (src < static_cast(Shared::availabilityLowest) && src > static_cast(Shared::availabilityHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(src); -} +#define FROM_INT_INPL(Enum) \ +template<> \ +Enum Shared::Global::fromInt(int src) \ +{ \ + if (src < static_cast(Enum##Lowest) && src > static_cast(Enum##Highest)) { \ + throw EnumOutOfRange(#Enum); \ + } \ + return static_cast(src); \ +} \ +template<> \ +Enum Shared::Global::fromInt(unsigned int src) {return fromInt(static_cast(src));} -template<> -Shared::ConnectionState Shared::Global::fromInt(int src) -{ - if (src < static_cast(Shared::connectionStateLowest) && src > static_cast(Shared::connectionStateHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(src); -} - -template<> -Shared::ConnectionState Shared::Global::fromInt(unsigned int src) -{ - if (src < static_cast(Shared::connectionStateLowest) && src > static_cast(Shared::connectionStateHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(src); -} - -template<> -Shared::SubscriptionState Shared::Global::fromInt(int src) -{ - if (src < static_cast(Shared::subscriptionStateLowest) && src > static_cast(Shared::subscriptionStateHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(src); -} - -template<> -Shared::SubscriptionState Shared::Global::fromInt(unsigned int src) -{ - if (src < static_cast(Shared::subscriptionStateLowest) && src > static_cast(Shared::subscriptionStateHighest)) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); - } - - return static_cast(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) diff --git a/shared/global.h b/shared/global.h index ef61611..3ea6147 100644 --- a/shared/global.h +++ b/shared/global.h @@ -21,6 +21,7 @@ #include "enums.h" #include "message.h" +#include "exception.h" #include @@ -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 availability; const std::deque connectionState; @@ -49,6 +51,7 @@ namespace Shared { const std::deque affiliation; const std::deque role; const std::deque messageState; + const std::deque accountPassword; template static T fromInt(int src); @@ -56,6 +59,19 @@ namespace Shared { template 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; }; diff --git a/shared/message.h b/shared/message.h index 98ef206..4a0d661 100644 --- a/shared/message.h +++ b/shared/message.h @@ -46,6 +46,8 @@ public: delivered, error }; + static const State StateHighest = State::error; + static const State StateLowest = State::pending; Message(Type p_type); Message(); diff --git a/translations/squawk.ru.ts b/translations/squawk.ru.ts index 37686fb..8a733f2 100644 --- a/translations/squawk.ru.ts +++ b/translations/squawk.ru.ts @@ -65,6 +65,10 @@ Ресурс по умолчанию QXmpp + + Password storage + + Accounts @@ -270,6 +274,22 @@ p, li { white-space: pre-wrap; } Delivered Доставлено + + Plain + + + + Jammed + + + + KWallet + + + + Always Ask + + JoinConference diff --git a/ui/models/account.cpp b/ui/models/account.cpp index 8d9774e..c581439 100644 --- a/ui/models/account.cpp +++ b/ui/models/account.cpp @@ -28,7 +28,8 @@ Models::Account::Account(const QMap& 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::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(pt)); +} + diff --git a/ui/models/account.h b/ui/models/account.h index 428b049..d2bb79f 100644 --- a/ui/models/account.h +++ b/ui/models/account.h @@ -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 #include @@ -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; diff --git a/ui/models/participant.cpp b/ui/models/participant.cpp index 3939888..dc42c07 100644 --- a/ui/models/participant.cpp +++ b/ui/models/participant.cpp @@ -58,11 +58,11 @@ QVariant Models::Participant::data(int column) const { switch (column) { case 4: - return static_cast(affiliation); + return QVariant::fromValue(affiliation); case 5: - return static_cast(role); + return QVariant::fromValue(role); case 6: - return static_cast(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(Shared::affiliationHighest)) { - Shared::Affiliation affil = static_cast(aff); - setAffiliation(affil); - } else { - qDebug() << "An attempt to set wrong affiliation" << aff << "to the room participant" << name; - } + setAffiliation(Shared::Global::fromInt(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(Shared::roleHighest)) { - Shared::Role r = static_cast(p_role); - setRole(r); - } else { - qDebug() << "An attempt to set wrong role" << p_role << "to the room participant" << name; - } + setRole(Shared::Global::fromInt(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(Shared::Avatar::valid)) { - Shared::Avatar state = static_cast(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(p_state));} diff --git a/ui/models/participant.h b/ui/models/participant.h index a93cb6d..6666d84 100644 --- a/ui/models/participant.h +++ b/ui/models/participant.h @@ -20,6 +20,7 @@ #define MODELS_PARTICIPANT_H #include "abstractparticipant.h" +#include "shared/global.h" namespace Models { diff --git a/ui/squawk.cpp b/ui/squawk.cpp index ad002c3..6822dd2 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -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(Shared::availabilityLowest); i < static_cast(Shared::availabilityHighest) + 1; ++i) { + for (int i = static_cast(Shared::AvailabilityLowest); i < static_cast(Shared::AvailabilityHighest) + 1; ++i) { Shared::Availability av = static_cast(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); diff --git a/ui/squawk.h b/ui/squawk.h index adfff1d..64459ab 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -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& account); void changeAccount(const QString& account, const QMap& data); void removeAccount(const QString& account); diff --git a/ui/widgets/account.cpp b/ui/widgets/account.cpp index d42cca8..d417d4f 100644 --- a/ui/widgets/account.cpp +++ b/ui/widgets/account.cpp @@ -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(Shared::AccountPasswordLowest); i < static_cast(Shared::AccountPasswordHighest) + 1; ++i) { + Shared::AccountPassword ap = static_cast(i); + m_ui->passwordType->addItem(Shared::Global::getName(ap)); + } + m_ui->passwordType->setCurrentIndex(static_cast(Shared::AccountPassword::plain)); } Account::~Account() @@ -37,6 +44,7 @@ QMap 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& 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()); } diff --git a/ui/widgets/account.h b/ui/widgets/account.h index 2f41430..9732224 100644 --- a/ui/widgets/account.h +++ b/ui/widgets/account.h @@ -19,12 +19,14 @@ #ifndef ACCOUNT_H #define ACCOUNT_H -#include #include +#include #include #include #include +#include "shared/global.h" + namespace Ui { class Account; diff --git a/ui/widgets/account.ui b/ui/widgets/account.ui index bfd0926..28cb389 100644 --- a/ui/widgets/account.ui +++ b/ui/widgets/account.ui @@ -6,8 +6,8 @@ 0 0 - 395 - 272 + 438 + 342 @@ -114,14 +114,14 @@ - + Resource - + A resource name like "Home" or "Work" @@ -131,6 +131,16 @@ + + + + Password storage + + + + + + diff --git a/ui/widgets/accounts.cpp b/ui/widgets/accounts.cpp index e6c3da1..626915e 100644 --- a/ui/widgets/accounts.cpp +++ b/ui/widgets/accounts.cpp @@ -22,6 +22,7 @@ #include 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(); diff --git a/ui/widgets/accounts.h b/ui/widgets/accounts.h index 31dc9ee..9fd0b57 100644 --- a/ui/widgets/accounts.h +++ b/ui/widgets/accounts.h @@ -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: