1
0
forked from blue/squawk
squawk/shared/info.cpp

376 lines
9.3 KiB
C++
Raw Normal View History

2023-11-17 00:08:40 +00:00
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* 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 <http://www.gnu.org/licenses/>.
*/
2023-01-30 17:52:26 +00:00
#include "info.h"
2023-11-18 00:52:33 +00:00
Shared::Info::Info (const QString& addr, EntryType tp):
type(tp),
address(addr),
vcard(nullptr),
activeKeys(nullptr),
inactiveKeys(nullptr)
{
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::none:
break;
case EntryType::contact:
case EntryType::ownAccount:
vcard = new VCard();
activeKeys = new std::list<KeyInfo>();
inactiveKeys = new std::list<KeyInfo>();
break;
default:
throw 352;
}
}
2023-02-01 15:56:00 +00:00
2023-11-18 00:52:33 +00:00
Shared::Info::Info ():
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)
{
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::none:
break;
case EntryType::contact:
case EntryType::ownAccount:
vcard = new VCard(other.getVCardRef());
activeKeys = new std::list<KeyInfo>(other.getActiveKeysRef());
inactiveKeys = new std::list<KeyInfo>(other.getInactiveKeysRef());
break;
default:
throw 353;
}
}
2023-01-30 17:52:26 +00:00
2023-11-18 00:52:33 +00:00
Shared::Info::Info (Info&& other):
type(other.type),
address(other.address),
vcard(other.vcard),
activeKeys(other.activeKeys),
inactiveKeys(other.inactiveKeys)
{
2023-11-17 00:08:40 +00:00
other.type = EntryType::none;
}
2023-11-18 00:52:33 +00:00
Shared::Info& Shared::Info::operator = (Info&& other) {
2023-11-17 00:08:40 +00:00
type = other.type;
address = other.address;
vcard = other.vcard;
activeKeys = other.activeKeys;
inactiveKeys = other.inactiveKeys;
other.type = EntryType::none;
return *this;
}
2023-11-18 00:52:33 +00:00
Shared::Info& Shared::Info::operator = (const Info& other) {
2023-11-17 00:08:40 +00:00
type = other.type;
address = other.address;
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::none:
break;
case EntryType::contact:
case EntryType::ownAccount:
vcard = new VCard(other.getVCardRef());
activeKeys = new std::list<KeyInfo>(other.getActiveKeysRef());
inactiveKeys = new std::list<KeyInfo>(other.getInactiveKeysRef());
break;
default:
throw 351;
2023-11-17 00:08:40 +00:00
}
return *this;
}
2023-11-18 00:52:33 +00:00
Shared::Info::~Info ()
{
turnIntoNone();
}
2023-11-18 00:52:33 +00:00
void Shared::Info::turnIntoNone () {
switch (type) {
2023-11-18 00:52:33 +00:00
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;
}
2023-11-18 00:52:33 +00:00
void Shared::Info::turnIntoContact (const Shared::VCard& crd, const std::list<KeyInfo>& aks, const std::list<KeyInfo>& iaks) {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::none:
vcard = new VCard(crd);
activeKeys = new std::list<KeyInfo>(aks);
inactiveKeys = new std::list<KeyInfo>(iaks);
break;
case EntryType::contact:
case EntryType::ownAccount:
*vcard = crd;
*activeKeys = aks;
*inactiveKeys = iaks;
break;
default:
break;
}
type = EntryType::contact;
}
2023-11-18 00:52:33 +00:00
void Shared::Info::turnIntoContact (Shared::VCard* crd, std::list<KeyInfo>* aks, std::list<KeyInfo>* iaks) {
switch (type) {
2023-11-18 00:52:33 +00:00
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;
}
2023-11-18 00:52:33 +00:00
void Shared::Info::turnIntoOwnAccount (const Shared::VCard& crd, const std::list<KeyInfo>& aks, const std::list<KeyInfo>& iaks) {
2023-11-17 00:08:40 +00:00
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::none:
vcard = new VCard(crd);
activeKeys = new std::list<KeyInfo>(aks);
inactiveKeys = new std::list<KeyInfo>(iaks);
break;
case EntryType::contact:
case EntryType::ownAccount:
*vcard = crd;
*activeKeys = aks;
*inactiveKeys = iaks;
break;
default:
break;
}
type = EntryType::ownAccount;
}
2023-11-18 00:52:33 +00:00
void Shared::Info::turnIntoOwnAccount (Shared::VCard* crd, std::list<KeyInfo>* aks, std::list<KeyInfo>* iaks) {
switch (type) {
2023-11-18 00:52:33 +00:00
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;
}
2023-11-18 00:52:33 +00:00
void Shared::Info::setAddress (const QString& addr) {
2023-11-17 00:08:40 +00:00
address = addr;
}
2023-11-18 00:52:33 +00:00
QString Shared::Info::getAddress () const {
2023-11-17 00:08:40 +00:00
return address;
}
2023-11-18 00:52:33 +00:00
const QString& Shared::Info::getAddressRef () const {
2023-11-17 00:08:40 +00:00
return address;
}
2023-11-18 00:52:33 +00:00
Shared::EntryType Shared::Info::getType () const {
2023-11-17 00:08:40 +00:00
return type;
}
2023-11-18 00:52:33 +00:00
std::list<Shared::KeyInfo>& Shared::Info::getActiveKeysRef () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *activeKeys;
break;
default:
throw 354;
}
}
2023-11-18 00:52:33 +00:00
const std::list<Shared::KeyInfo>& Shared::Info::getActiveKeysRef () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *activeKeys;
break;
default:
throw 355;
}
}
2023-11-18 00:52:33 +00:00
std::list<Shared::KeyInfo>* Shared::Info::getActiveKeys () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return activeKeys;
break;
default:
throw 356;
}
}
2023-11-18 00:52:33 +00:00
const std::list<Shared::KeyInfo>* Shared::Info::getActiveKeys () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return activeKeys;
break;
default:
throw 357;
}
}
2023-11-18 00:52:33 +00:00
std::list<Shared::KeyInfo>& Shared::Info::getInactiveKeysRef () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *inactiveKeys;
break;
default:
throw 358;
}
}
2023-11-18 00:52:33 +00:00
const std::list<Shared::KeyInfo>& Shared::Info::getInactiveKeysRef () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *inactiveKeys;
break;
default:
throw 359;
}
}
2023-11-18 00:52:33 +00:00
std::list<Shared::KeyInfo>* Shared::Info::getInactiveKeys () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return inactiveKeys;
break;
default:
throw 360;
}
}
2023-11-18 00:52:33 +00:00
const std::list<Shared::KeyInfo>* Shared::Info::getInactiveKeys () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return inactiveKeys;
break;
default:
throw 361;
}
}
2023-11-18 00:52:33 +00:00
const Shared::VCard& Shared::Info::getVCardRef () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *vcard;
break;
default:
throw 362;
}
}
2023-11-18 00:52:33 +00:00
Shared::VCard& Shared::Info::getVCardRef () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return *vcard;
break;
default:
throw 363;
}
}
2023-11-18 00:52:33 +00:00
const Shared::VCard* Shared::Info::getVCard () const {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return vcard;
break;
default:
throw 364;
}
}
2023-11-18 00:52:33 +00:00
Shared::VCard* Shared::Info::getVCard () {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
return vcard;
break;
default:
throw 365;
}
}
2023-11-18 00:52:33 +00:00
void Shared::Info::setActiveKeys (std::list<KeyInfo>* keys) {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
activeKeys = keys;
break;
default:
throw 366;
}
}
2023-11-18 00:52:33 +00:00
void Shared::Info::setVCard (Shared::VCard* card) {
switch (type) {
2023-11-18 00:52:33 +00:00
case EntryType::contact:
case EntryType::ownAccount:
vcard = card;
break;
default:
throw 367;
}
}