2023-01-01 17:25:51 +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-02-01 15:56:00 +00:00
|
|
|
#include "info.h"
|
|
|
|
#include "ui_info.h"
|
2023-01-01 17:25:51 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
UI::Info::Info(const QString& p_jid, QWidget* parent):
|
2023-02-01 15:56:00 +00:00
|
|
|
QWidget(parent),
|
2023-02-20 18:12:32 +00:00
|
|
|
jid(p_jid),
|
2023-02-02 18:39:38 +00:00
|
|
|
m_ui(new Ui::Info()),
|
|
|
|
contactGeneral(nullptr),
|
|
|
|
contactContacts(nullptr),
|
|
|
|
description(nullptr),
|
|
|
|
overlay(new QWidget()),
|
|
|
|
progress(new Progress(100)),
|
|
|
|
progressLabel(new QLabel())
|
2023-01-01 17:25:51 +00:00
|
|
|
{
|
2023-02-01 15:56:00 +00:00
|
|
|
m_ui->setupUi(this);
|
2023-02-20 18:12:32 +00:00
|
|
|
m_ui->buttonBox->hide();
|
2023-01-01 17:25:51 +00:00
|
|
|
|
2023-02-02 18:39:38 +00:00
|
|
|
initializeOverlay();
|
2023-02-20 18:12:32 +00:00
|
|
|
initializeButtonBox();
|
2023-02-02 18:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::Info::~Info() {
|
|
|
|
if (contactGeneral != nullptr)
|
|
|
|
contactGeneral->deleteLater();
|
|
|
|
|
|
|
|
if (contactContacts != nullptr)
|
|
|
|
contactContacts->deleteLater();
|
|
|
|
|
|
|
|
if (description != nullptr)
|
|
|
|
description->deleteLater();
|
|
|
|
|
|
|
|
overlay->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Info::setData(const Shared::Info& info) {
|
|
|
|
switch (info.type) {
|
|
|
|
case Shared::EntryType::contact:
|
|
|
|
initializeContactGeneral(info);
|
|
|
|
initializeContactContacts(info);
|
2023-02-20 18:12:32 +00:00
|
|
|
initializeDescription(info);
|
2023-02-02 18:39:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-02-20 18:12:32 +00:00
|
|
|
|
|
|
|
if (!info.editable)
|
|
|
|
m_ui->buttonBox->hide();
|
|
|
|
else
|
|
|
|
m_ui->buttonBox->show();
|
|
|
|
|
2023-02-02 18:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Info::initializeOverlay() {
|
|
|
|
QGridLayout* gr = static_cast<QGridLayout*>(layout());
|
|
|
|
gr->addWidget(overlay, 0, 0, 4, 1);
|
|
|
|
QVBoxLayout* nl = new QVBoxLayout();
|
|
|
|
QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect();
|
|
|
|
opacity->setOpacity(0.8);
|
|
|
|
overlay->setLayout(nl);
|
|
|
|
overlay->setBackgroundRole(QPalette::Base);
|
|
|
|
overlay->setAutoFillBackground(true);
|
|
|
|
overlay->setGraphicsEffect(opacity);
|
|
|
|
progressLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
QFont pf = progressLabel->font();
|
|
|
|
pf.setBold(true);
|
|
|
|
pf.setPointSize(26);
|
|
|
|
progressLabel->setFont(pf);
|
|
|
|
progressLabel->setWordWrap(true);
|
|
|
|
nl->addStretch();
|
|
|
|
nl->addWidget(progress);
|
|
|
|
nl->addWidget(progressLabel);
|
|
|
|
nl->addStretch();
|
|
|
|
overlay->hide();
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void UI::Info::initializeButtonBox() {
|
|
|
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &UI::Info::onButtonBoxAccepted);
|
|
|
|
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &UI::Info::close);
|
|
|
|
|
|
|
|
m_ui->buttonBox->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Info::onButtonBoxAccepted() {
|
|
|
|
//TODO this is not good, since I don't exactly know what am I editing it's bad to assume there even going to be a vcard
|
|
|
|
Shared::Info info;
|
|
|
|
if (contactGeneral != nullptr)
|
|
|
|
contactGeneral->fillVCard(info.vcard);
|
|
|
|
if (contactContacts != nullptr)
|
|
|
|
contactContacts->fillVCard(info.vcard);
|
|
|
|
if (description != nullptr)
|
|
|
|
info.vcard.setDescription(description->description());
|
|
|
|
|
|
|
|
emit saveInfo(info);
|
|
|
|
}
|
2023-01-03 15:27:03 +00:00
|
|
|
|
2023-02-02 18:39:38 +00:00
|
|
|
void UI::Info::showProgress(const QString& line) {
|
2023-02-20 18:12:32 +00:00
|
|
|
if (line.size() > 0)
|
|
|
|
progressLabel->setText(line);
|
|
|
|
else
|
|
|
|
progressLabel->setText(tr("Requesting information about %1").arg(jid));
|
|
|
|
|
2023-02-02 18:39:38 +00:00
|
|
|
overlay->show();
|
|
|
|
progress->start();
|
2023-02-01 15:56:00 +00:00
|
|
|
}
|
2023-01-01 17:25:51 +00:00
|
|
|
|
2023-02-02 18:39:38 +00:00
|
|
|
void UI::Info::hideProgress() {
|
|
|
|
overlay->hide();
|
|
|
|
progress->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Info::initializeContactGeneral(const Shared::Info& info) {
|
|
|
|
if (contactGeneral == nullptr) {
|
|
|
|
contactGeneral = new ContactGeneral;
|
|
|
|
m_ui->tabWidget->addTab(contactGeneral, contactGeneral->title());
|
|
|
|
}
|
|
|
|
contactGeneral->setVCard(info.jid, info.vcard, info.editable);
|
|
|
|
}
|
2023-02-20 18:12:32 +00:00
|
|
|
|
|
|
|
void UI::Info::initializeContactContacts(const Shared::Info& info) {
|
|
|
|
if (contactContacts == nullptr) {
|
|
|
|
contactContacts = new ContactContacts;
|
|
|
|
m_ui->tabWidget->addTab(contactContacts, contactContacts->title());
|
|
|
|
}
|
|
|
|
contactContacts->setVCard(info.jid, info.vcard, info.editable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Info::initializeDescription(const Shared::Info& info) {
|
|
|
|
if (description == nullptr) {
|
|
|
|
description = new Description;
|
|
|
|
m_ui->tabWidget->addTab(description, description->title());
|
|
|
|
}
|
|
|
|
|
|
|
|
description->setDescription(info.vcard.getDescription());
|
|
|
|
description->setEditable(info.editable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|