an idea how to manage info object better

This commit is contained in:
Blue 2023-03-01 22:32:41 +03:00
parent ec362cef55
commit 6f32e99593
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
12 changed files with 390 additions and 63 deletions

View file

@ -412,7 +412,7 @@ void Squawk::onRosterContextMenu(const QPoint& point) {
}
void Squawk::responseInfo(const Shared::Info& info) {
std::map<QString, UI::Info*>::const_iterator itr = infoWidgets.find(info.jid);
std::map<QString, UI::Info*>::const_iterator itr = infoWidgets.find(info.getAddressRef());
if (itr != infoWidgets.end()) {
itr->second->setData(info);
itr->second->hideProgress();

View file

@ -30,7 +30,6 @@ UI::ContactGeneral::ContactGeneral(QWidget* parent):
currentAvatarType(Shared::Avatar::empty),
currentAvatarPath(""),
currentJid(""),
editable(false),
avatarDiablog(nullptr)
{
m_ui->setupUi(this);
@ -74,6 +73,9 @@ void UI::ContactGeneral::setEditable(bool edit) {
m_ui->avatarButton->setMenu(nullptr);
}
}
m_ui->actionSetAvatar->setEnabled(edit);
m_ui->actionClearAvatar->setEnabled(false); //need to unlock it explicitly after the type of avatar is clear!
}
void UI::ContactGeneral::deleteAvatarDialog() {
@ -92,7 +94,7 @@ void UI::ContactGeneral::initializeActions() {
connect(setAvatar, &QAction::triggered, this, &UI::ContactGeneral::onSetAvatar);
connect(clearAvatar, &QAction::triggered, this, &UI::ContactGeneral::onClearAvatar);
setAvatar->setEnabled(editable);
setAvatar->setEnabled(false);
clearAvatar->setEnabled(false);
}
@ -138,7 +140,7 @@ void UI::ContactGeneral::updateAvatar() {
qreal aspectRatio = w / h;
m_ui->avatarButton->setIconSize(QSize(height * aspectRatio, height));
m_ui->avatarButton->setIcon(QIcon(currentAvatarPath));
m_ui->actionClearAvatar->setEnabled(editable);
m_ui->actionClearAvatar->setEnabled(m_ui->actionSetAvatar->isEnabled()); //I assume that if set avatar is enabled then we can also clear
break;
}
}

View file

@ -67,7 +67,6 @@ private:
Shared::Avatar currentAvatarType;
QString currentAvatarPath;
QString currentJid;
bool editable;
QFileDialog* avatarDiablog;
static const std::set<QString> supportedTypes;

View file

@ -45,17 +45,19 @@ UI::Info::~Info() {
void UI::Info::setData(const Shared::Info& info) {
bool editable = false;
switch (info.type) {
switch (info.getType()) {
case Shared::EntryType::ownAccount:
editable = true;
[[fallthrough]];
case Shared::EntryType::contact: {
QDateTime receivingTime = info.vcard.getReceivingTime();
const Shared::VCard card = info.getVCardRef();
QDateTime receivingTime = card.getReceivingTime();
m_ui->receivingTimeLabel->show();
m_ui->receivingTimeLabel->setText(tr("Received %1 at %2").arg(receivingTime.date().toString()).arg(receivingTime.time().toString()));
initializeContactGeneral(jid, info.vcard, editable);
initializeContactContacts(jid, info.vcard, editable);
initializeDescription(info.vcard.getDescription(), editable);
type = info.type;
initializeContactGeneral(jid, card, editable);
initializeContactContacts(jid, card, editable);
initializeDescription(card.getDescription(), editable);
type = info.getType();
}
break;
default:
@ -99,11 +101,13 @@ void UI::Info::initializeButtonBox() {
void UI::Info::onButtonBoxAccepted() {
if (type == Shared::EntryType::ownAccount) {
Shared::Info info;
contactGeneral->fillVCard(info.vcard);
contactContacts->fillVCard(info.vcard);
info.vcard.setDescription(description->description());
Shared::Info info(jid, Shared::EntryType::ownAccount);
Shared::VCard& card = info.getVCardRef();
contactGeneral->fillVCard(card);
contactContacts->fillVCard(card);
card.setDescription(description->description());
emit saveInfo(info);
emit close();
}
}