diff --git a/core/account.cpp b/core/account.cpp index efb4a1a..858c177 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -806,6 +806,14 @@ void Core::Account::updateInfo(const Shared::Info& info) { //TODO switch case of what kind of entity this info update is about //right now it could be only about myself vh->uploadVCard(info.getVCardRef()); + const std::list& keys = info.getActiveKeysRef(); + for (const Shared::KeyInfo& info : keys) { + qDebug() << "An attempt to save key: "; + qDebug() << "id:" << info.id; + qDebug() << "label:" << info.label; + qDebug() << "current device:" << info.currentDevice; + qDebug() << "... but it's not implemented yet, ignoring"; + } } QString Core::Account::getAvatarPath() const { diff --git a/core/account.h b/core/account.h index 47c5c7e..ea1a13d 100644 --- a/core/account.h +++ b/core/account.h @@ -67,11 +67,9 @@ #include "handlers/omemohandler.h" #endif -namespace Core -{ +namespace Core { -class Account : public QObject -{ +class Account : public QObject { Q_OBJECT friend class MessageHandler; friend class RosterHandler; diff --git a/core/handlers/rosterhandler.h b/core/handlers/rosterhandler.h index 5abc416..afbd372 100644 --- a/core/handlers/rosterhandler.h +++ b/core/handlers/rosterhandler.h @@ -41,8 +41,6 @@ #include namespace Core { - - class Account; class RosterHandler : public QObject { diff --git a/shared/info.cpp b/shared/info.cpp index 36cd4b5..35f6427 100644 --- a/shared/info.cpp +++ b/shared/info.cpp @@ -1,353 +1,384 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "info.h" -Shared::Info::Info(const QString& addr, EntryType tp): - type(tp), - address(addr), - vcard(nullptr), - activeKeys(nullptr), - inactiveKeys(nullptr) -{ +Shared::Info::Info(const QString &addr, EntryType tp): +type(tp), +address(addr), +vcard(nullptr), +activeKeys(nullptr), +inactiveKeys(nullptr) { switch (type) { - case EntryType::none: - break; - case EntryType::contact: - case EntryType::ownAccount: - vcard = new VCard(); - activeKeys = new std::list(); - inactiveKeys = new std::list(); - break; - default: - throw 352; + case EntryType::none: + break; + case EntryType::contact: + case EntryType::ownAccount: + vcard = new VCard(); + activeKeys = new std::list(); + inactiveKeys = new std::list(); + break; + default: + throw 352; } } Shared::Info::Info(): - type(EntryType::none), - address(""), - vcard(nullptr), - activeKeys(nullptr), - inactiveKeys(nullptr) -{} +type(EntryType::none), +address(""), +vcard(nullptr), +activeKeys(nullptr), +inactiveKeys(nullptr) {} -Shared::Info::Info(const Shared::Info& other): - type(other.type), - address(other.address), - vcard(nullptr), - activeKeys(nullptr), - inactiveKeys(nullptr) -{ +Shared::Info::Info(const Shared::Info &other): +type(other.type), +address(other.address), +vcard(nullptr), +activeKeys(nullptr), +inactiveKeys(nullptr) { switch (type) { - case EntryType::none: - break; - case EntryType::contact: - case EntryType::ownAccount: - vcard = new VCard(other.getVCardRef()); - activeKeys = new std::list(other.getActiveKeysRef()); - inactiveKeys = new std::list(other.getInactiveKeysRef()); - break; - default: - throw 353; + case EntryType::none: + break; + case EntryType::contact: + case EntryType::ownAccount: + vcard = new VCard(other.getVCardRef()); + activeKeys = new std::list(other.getActiveKeysRef()); + inactiveKeys = new std::list(other.getInactiveKeysRef()); + break; + default: + throw 353; } } +Shared::Info::Info(Info &&other): +type(other.type), +address(other.address), +vcard(other.vcard), +activeKeys(other.activeKeys), +inactiveKeys(other.inactiveKeys) { + other.type = EntryType::none; +} + +Shared::Info &Shared::Info::operator=(Info &&other) { + type = other.type; + address = other.address; + vcard = other.vcard; + activeKeys = other.activeKeys; + inactiveKeys = other.inactiveKeys; + + other.type = EntryType::none; + + return *this; +} + +Shared::Info &Shared::Info::operator=(const Info &other) { + type = other.type; + address = other.address; + + switch (type) { + case EntryType::none: + break; + case EntryType::contact: + case EntryType::ownAccount: + vcard = new VCard(other.getVCardRef()); + activeKeys = new std::list(other.getActiveKeysRef()); + inactiveKeys = new std::list(other.getInactiveKeysRef()); + break; + default: + throw 351; + } + + return *this; +} + Shared::Info::~Info() { turnIntoNone(); } void Shared::Info::turnIntoNone() { switch (type) { - case EntryType::none: - break; - case EntryType::contact: - case EntryType::ownAccount: - delete vcard; - vcard = nullptr; - delete activeKeys; - activeKeys = nullptr; - delete inactiveKeys; - inactiveKeys = nullptr; - break; - default: - break; + case EntryType::none: + break; + case EntryType::contact: + case EntryType::ownAccount: + delete vcard; + vcard = nullptr; + delete activeKeys; + activeKeys = nullptr; + delete inactiveKeys; + inactiveKeys = nullptr; + break; + default: + break; } type = EntryType::none; } void Shared::Info::turnIntoContact( - const Shared::VCard& crd, - const std::list& aks, - const std::list& iaks + const Shared::VCard &crd, const std::list &aks, const std::list &iaks ) { switch (type) { - case EntryType::none: - vcard = new VCard(crd); - activeKeys = new std::list(aks); - inactiveKeys = new std::list(iaks); - break; - case EntryType::contact: - case EntryType::ownAccount: - *vcard = crd; - *activeKeys = aks; - *inactiveKeys = iaks; - break; - default: - break; + case EntryType::none: + vcard = new VCard(crd); + activeKeys = new std::list(aks); + inactiveKeys = new std::list(iaks); + break; + case EntryType::contact: + case EntryType::ownAccount: + *vcard = crd; + *activeKeys = aks; + *inactiveKeys = iaks; + break; + default: + break; } type = EntryType::contact; } -void Shared::Info::turnIntoContact( - Shared::VCard* crd, - std::list* aks, - std::list* iaks -) { +void Shared::Info::turnIntoContact(Shared::VCard *crd, std::list *aks, std::list *iaks) { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - delete vcard; - delete activeKeys; - delete inactiveKeys; - [[fallthrough]]; - case EntryType::none: - vcard = crd; - activeKeys = aks; - inactiveKeys = iaks; - break; - default: - break; + case EntryType::contact: + case EntryType::ownAccount: + delete vcard; + delete activeKeys; + delete inactiveKeys; + [[fallthrough]]; + case EntryType::none: + vcard = crd; + activeKeys = aks; + inactiveKeys = iaks; + break; + default: + break; } type = EntryType::contact; } void Shared::Info::turnIntoOwnAccount( - const Shared::VCard& crd, - const std::list& aks, - const std::list& iaks -) { - switch (type) { - case EntryType::none: - vcard = new VCard(crd); - activeKeys = new std::list(aks); - inactiveKeys = new std::list(iaks); - break; - case EntryType::contact: - case EntryType::ownAccount: - *vcard = crd; - *activeKeys = aks; - *inactiveKeys = iaks; - break; - default: - break; - } - - type = EntryType::ownAccount; -} - -void Shared::Info::turnIntoOwnAccount( - Shared::VCard* crd, - std::list* aks, - std::list* iaks + const Shared::VCard &crd, const std::list &aks, const std::list &iaks ) { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - delete vcard; - delete activeKeys; - delete inactiveKeys; - [[fallthrough]]; - case EntryType::none: - vcard = crd; - activeKeys = aks; - inactiveKeys = iaks; - break; - default: - break; + case EntryType::none: + vcard = new VCard(crd); + activeKeys = new std::list(aks); + inactiveKeys = new std::list(iaks); + break; + case EntryType::contact: + case EntryType::ownAccount: + *vcard = crd; + *activeKeys = aks; + *inactiveKeys = iaks; + break; + default: + break; } type = EntryType::ownAccount; } -void Shared::Info::setAddress(const QString& addr) { - address = addr;} +void Shared::Info::turnIntoOwnAccount(Shared::VCard *crd, std::list *aks, std::list *iaks) { + switch (type) { + case EntryType::contact: + case EntryType::ownAccount: + delete vcard; + delete activeKeys; + delete inactiveKeys; + [[fallthrough]]; + case EntryType::none: + vcard = crd; + activeKeys = aks; + inactiveKeys = iaks; + break; + default: + break; + } + + type = EntryType::ownAccount; +} + +void Shared::Info::setAddress(const QString &addr) { + address = addr; +} QString Shared::Info::getAddress() const { - return address;} + return address; +} -const QString& Shared::Info::getAddressRef() const { - return address;} +const QString &Shared::Info::getAddressRef() const { + return address; +} Shared::EntryType Shared::Info::getType() const { - return type;} + return type; +} -std::list & Shared::Info::getActiveKeysRef() { +std::list &Shared::Info::getActiveKeysRef() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *activeKeys; - break; - default: - throw 354; + case EntryType::contact: + case EntryType::ownAccount: + return *activeKeys; + break; + default: + throw 354; } } -const std::list & Shared::Info::getActiveKeysRef() const { +const std::list &Shared::Info::getActiveKeysRef() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *activeKeys; - break; - default: - throw 355; + case EntryType::contact: + case EntryType::ownAccount: + return *activeKeys; + break; + default: + throw 355; } } -std::list* Shared::Info::getActiveKeys() { +std::list *Shared::Info::getActiveKeys() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return activeKeys; - break; - default: - throw 356; + case EntryType::contact: + case EntryType::ownAccount: + return activeKeys; + break; + default: + throw 356; } } -const std::list* Shared::Info::getActiveKeys() const { +const std::list *Shared::Info::getActiveKeys() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return activeKeys; - break; - default: - throw 357; + case EntryType::contact: + case EntryType::ownAccount: + return activeKeys; + break; + default: + throw 357; } } -std::list & Shared::Info::getInactiveKeysRef() { +std::list &Shared::Info::getInactiveKeysRef() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *inactiveKeys; - break; - default: - throw 358; + case EntryType::contact: + case EntryType::ownAccount: + return *inactiveKeys; + break; + default: + throw 358; } } -const std::list & Shared::Info::getInactiveKeysRef() const { +const std::list &Shared::Info::getInactiveKeysRef() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *inactiveKeys; - break; - default: - throw 359; + case EntryType::contact: + case EntryType::ownAccount: + return *inactiveKeys; + break; + default: + throw 359; } } -std::list* Shared::Info::getInactiveKeys() { +std::list *Shared::Info::getInactiveKeys() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return inactiveKeys; - break; - default: - throw 360; + case EntryType::contact: + case EntryType::ownAccount: + return inactiveKeys; + break; + default: + throw 360; } } -const std::list* Shared::Info::getInactiveKeys() const { +const std::list *Shared::Info::getInactiveKeys() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return inactiveKeys; - break; - default: - throw 361; + case EntryType::contact: + case EntryType::ownAccount: + return inactiveKeys; + break; + default: + throw 361; } } -const Shared::VCard & Shared::Info::getVCardRef() const { +const Shared::VCard &Shared::Info::getVCardRef() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *vcard; - break; - default: - throw 362; + case EntryType::contact: + case EntryType::ownAccount: + return *vcard; + break; + default: + throw 362; } } -Shared::VCard & Shared::Info::getVCardRef() { +Shared::VCard &Shared::Info::getVCardRef() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return *vcard; - break; - default: - throw 363; + case EntryType::contact: + case EntryType::ownAccount: + return *vcard; + break; + default: + throw 363; } } -const Shared::VCard * Shared::Info::getVCard() const { +const Shared::VCard *Shared::Info::getVCard() const { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return vcard; - break; - default: - throw 364; + case EntryType::contact: + case EntryType::ownAccount: + return vcard; + break; + default: + throw 364; } } -Shared::VCard * Shared::Info::getVCard() { +Shared::VCard *Shared::Info::getVCard() { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - return vcard; - break; - default: - throw 365; + case EntryType::contact: + case EntryType::ownAccount: + return vcard; + break; + default: + throw 365; } } -void Shared::Info::setActiveKeys(std::list* keys) { +void Shared::Info::setActiveKeys(std::list *keys) { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - activeKeys = keys; - break; - default: - throw 366; + case EntryType::contact: + case EntryType::ownAccount: + activeKeys = keys; + break; + default: + throw 366; } } -void Shared::Info::setVCard(Shared::VCard* card) { +void Shared::Info::setVCard(Shared::VCard *card) { switch (type) { - case EntryType::contact: - case EntryType::ownAccount: - vcard = card; - break; - default: - throw 367; + case EntryType::contact: + case EntryType::ownAccount: + vcard = card; + break; + default: + throw 367; } } - diff --git a/shared/info.h b/shared/info.h index e42eddb..d5a48b1 100644 --- a/shared/info.h +++ b/shared/info.h @@ -1,21 +1,22 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#ifndef SHARED_INFO_H -#define SHARED_INFO_H +#pragma once #include "vcard.h" #include "keyinfo.h" @@ -36,7 +37,10 @@ public: Info(); Info(const QString& address, EntryType = EntryType::none); Info(const Info& other); + Info(Info&& other); virtual ~Info(); + Info& operator = (const Info& other); + Info& operator = (Info&& other); QString getAddress() const; const QString& getAddressRef() const; @@ -90,7 +94,4 @@ private: std::list* activeKeys; std::list* inactiveKeys; }; - } - -#endif // SHARED_INFO_H diff --git a/ui/models/info/omemo/keys.cpp b/ui/models/info/omemo/keys.cpp index 5d957b1..9ef8c73 100644 --- a/ui/models/info/omemo/keys.cpp +++ b/ui/models/info/omemo/keys.cpp @@ -1,18 +1,20 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "keys.h" @@ -37,18 +39,34 @@ Models::Keys::~Keys() { delete pair.second; } -std::deque Models::Keys::modifiedKeys() const { - std::deque response(modified.size()); +std::list Models::Keys::modifiedKeys() const { + std::list response; + for (const std::pair& pair: modified) + response.push_back(*(pair.second)); - int i = 0; - for (const std::pair& pair: modified) { - response[i] = *(pair.second); - ++i; - } return response; } +std::list Models::Keys::finalKeys() const { + std::list result; + finalKeys(result); + return result; +} + +void Models::Keys::finalKeys(std::list& out) const { + for (int i = 0; i < rowCount(); ++i) + out.push_back(key(i)); +} + +const Shared::KeyInfo & Models::Keys::key(unsigned int i) const { + std::map::const_iterator itr = modified.find(i); + if (itr != modified.end()) + return*(itr->second); + else + return *(keys[i]); +} + void Models::Keys::addKey(const Shared::KeyInfo& info) { beginInsertRows(QModelIndex(), keys.size(), keys.size()); keys.push_back(new Shared::KeyInfo(info)); diff --git a/ui/models/info/omemo/keys.h b/ui/models/info/omemo/keys.h index 49948a2..1bc79de 100644 --- a/ui/models/info/omemo/keys.h +++ b/ui/models/info/omemo/keys.h @@ -1,21 +1,22 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#ifndef MODELS_KEYS_H -#define MODELS_KEYS_H +#pragma once #include @@ -23,11 +24,7 @@ namespace Models { -/** - * @todo write docs - */ -class Keys : public QAbstractListModel -{ +class Keys : public QAbstractListModel { public: Keys(QObject *parent = nullptr); ~Keys(); @@ -37,11 +34,14 @@ public: QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; + const Shared::KeyInfo& key(unsigned int i) const; QHash roleNames() const override; QModelIndex index(int row, int column, const QModelIndex & parent) const override; - std::deque modifiedKeys() const; + std::list modifiedKeys() const; + std::list finalKeys() const; + void finalKeys(std::list& out) const; enum Roles { Label = Qt::UserRole + 1, @@ -64,5 +64,3 @@ private: }; } - -#endif // MODELS_KEYS_H diff --git a/ui/widgets/info/info.cpp b/ui/widgets/info/info.cpp index 948ee27..26f63f1 100644 --- a/ui/widgets/info/info.cpp +++ b/ui/widgets/info/info.cpp @@ -114,6 +114,9 @@ void UI::Info::onButtonBoxAccepted() { contactGeneral->fillVCard(card); contactContacts->fillVCard(card); card.setDescription(description->description()); +#ifdef WITH_OMEMO + omemo->fillData(info.getActiveKeysRef()); +#endif emit saveInfo(info); emit close(); } @@ -161,7 +164,8 @@ void UI::Info::initializeDescription(const QString& descr, bool editable) { } QString UI::Info::getJid() const { - return jid;} + return jid; +} void UI::Info::clear() { if (contactGeneral != nullptr) { diff --git a/ui/widgets/info/info.h b/ui/widgets/info/info.h index 7d52693..10b7209 100644 --- a/ui/widgets/info/info.h +++ b/ui/widgets/info/info.h @@ -39,8 +39,7 @@ namespace UI { -namespace Ui -{ +namespace Ui { class Info; } diff --git a/ui/widgets/info/omemo/omemo.cpp b/ui/widgets/info/omemo/omemo.cpp index 294fbe2..baa7aa0 100644 --- a/ui/widgets/info/omemo/omemo.cpp +++ b/ui/widgets/info/omemo/omemo.cpp @@ -88,6 +88,12 @@ void UI::Omemo::setData(const std::list& keys) { deviceKeyVisibility(deviceKeyModel.rowCount() > 0); } +void UI::Omemo::fillData(std::list& out) { + deviceKeyModel.finalKeys(out); + keysModel.finalKeys(out); + unusedKeysModel.finalKeys(out); +} + const QString UI::Omemo::title() const { return m_ui->OMEMOHeading->text(); } diff --git a/ui/widgets/info/omemo/omemo.h b/ui/widgets/info/omemo/omemo.h index 75b1df2..64c2486 100644 --- a/ui/widgets/info/omemo/omemo.h +++ b/ui/widgets/info/omemo/omemo.h @@ -41,6 +41,7 @@ public: ~Omemo(); void setData(const std::list& keys); + void fillData(std::list& out); const QString title() const; private slots: