1
0
forked from blue/squawk

some further thinking of info widget

This commit is contained in:
Blue 2023-02-21 23:27:28 +03:00
parent e4a2728ef8
commit ec362cef55
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
5 changed files with 64 additions and 48 deletions

View File

@ -187,7 +187,7 @@ void Core::VCardHandler::onOwnVCardReceived(const QXmppVCardIq& card) {
ownVCardRequestInProgress = false;
Shared::Info info(acc->getBareJid(), Shared::EntryType::contact, true);
Shared::Info info(acc->getBareJid(), Shared::EntryType::ownAccount, true);
initializeVCard(info.vcard, card);
if (avatarType.size() > 0) {
@ -203,7 +203,7 @@ void Core::VCardHandler::onOwnVCardReceived(const QXmppVCardIq& card) {
void Core::VCardHandler::handleOffline() {
pendingVCardRequests.clear();
for (const QString& jid : pendingVCardRequests) {
Shared::Info info(jid, Shared::EntryType::contact);
Shared::Info info(jid, Shared::EntryType::none);
emit acc->infoReady(info); //need to show it better in the future, like with an error
}
pendingVCardRequests.clear();

View File

@ -119,6 +119,8 @@ static const AccountPassword AccountPasswordHighest = AccountPassword::kwallet;
static const AccountPassword AccountPasswordLowest = AccountPassword::plain;
enum class EntryType {
none,
ownAccount,
contact,
conference,
presence,
@ -126,7 +128,7 @@ enum class EntryType {
};
Q_ENUM_NS(EntryType)
static const EntryType EntryTypeHighest = EntryType::participant;
static const EntryType EntryTypeLowest = EntryType::contact;
static const EntryType EntryTypeLowest = EntryType::none;
enum class Support {
unknown,

View File

@ -422,7 +422,7 @@ void Squawk::responseInfo(const Shared::Info& info) {
void Squawk::onInfoClosed() {
UI::Info* info = static_cast<UI::Info*>(sender());
std::map<QString, UI::Info*>::const_iterator itr = infoWidgets.find(info->jid);
std::map<QString, UI::Info*>::const_iterator itr = infoWidgets.find(info->getJid());
if (itr == infoWidgets.end()) {
qDebug() << "Info widget has been closed but can not be found among other opened vCards, application is most probably going to crash";
return;
@ -437,12 +437,7 @@ void Squawk::onActivateInfo(const QString& account, const QString& jid) {
info = itr->second;
} else {
info = new UI::Info(jid);
// TODO need to handle it somewhere else
// if (edition) {
// card->setWindowTitle(tr("%1 account card").arg(account));
// } else {
// card->setWindowTitle(tr("%1 contact card").arg(jid));
// }
info->setWindowTitle(tr("Information about %1").arg(jid));
info->setAttribute(Qt::WA_DeleteOnClose);
infoWidgets.insert(std::make_pair(jid, info));

View File

@ -20,6 +20,7 @@
UI::Info::Info(const QString& p_jid, QWidget* parent):
QWidget(parent),
jid(p_jid),
type(Shared::EntryType::none),
m_ui(new Ui::Info()),
contactGeneral(nullptr),
contactContacts(nullptr),
@ -30,36 +31,39 @@ UI::Info::Info(const QString& p_jid, QWidget* parent):
{
m_ui->setupUi(this);
m_ui->buttonBox->hide();
m_ui->title->setText(tr("%1 info").arg(p_jid));
m_ui->receivingTimeLabel->hide();
initializeOverlay();
initializeButtonBox();
}
UI::Info::~Info() {
if (contactGeneral != nullptr)
contactGeneral->deleteLater();
if (contactContacts != nullptr)
contactContacts->deleteLater();
if (description != nullptr)
description->deleteLater();
clear();
overlay->deleteLater();
}
void UI::Info::setData(const Shared::Info& info) {
bool editable = false;
switch (info.type) {
case Shared::EntryType::contact:
initializeContactGeneral(info);
initializeContactContacts(info);
initializeDescription(info);
case Shared::EntryType::ownAccount:
editable = true;
case Shared::EntryType::contact: {
QDateTime receivingTime = info.vcard.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;
}
break;
default:
clear();
break;
}
if (!info.editable)
if (!editable)
m_ui->buttonBox->hide();
else
m_ui->buttonBox->show();
@ -77,10 +81,7 @@ void UI::Info::initializeOverlay() {
overlay->setAutoFillBackground(true);
overlay->setGraphicsEffect(opacity);
progressLabel->setAlignment(Qt::AlignCenter);
QFont pf = progressLabel->font();
pf.setBold(true);
pf.setPointSize(26);
progressLabel->setFont(pf);
progressLabel->setFont(Shared::Global::getInstance()->titleFont);
progressLabel->setWordWrap(true);
nl->addStretch();
nl->addWidget(progress);
@ -97,16 +98,13 @@ void UI::Info::initializeButtonBox() {
}
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
if (type == Shared::EntryType::ownAccount) {
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);
}
}
void UI::Info::showProgress(const QString& line) {
@ -124,30 +122,49 @@ void UI::Info::hideProgress() {
progress->stop();
}
void UI::Info::initializeContactGeneral(const Shared::Info& info) {
void UI::Info::initializeContactGeneral(const QString& jid, const Shared::VCard& card, bool editable) {
if (contactGeneral == nullptr) {
contactGeneral = new ContactGeneral;
m_ui->tabWidget->addTab(contactGeneral, contactGeneral->title());
}
contactGeneral->setVCard(info.jid, info.vcard, info.editable);
contactGeneral->setVCard(jid, card, editable);
}
void UI::Info::initializeContactContacts(const Shared::Info& info) {
void UI::Info::initializeContactContacts(const QString& jid, const Shared::VCard& card, bool editable) {
if (contactContacts == nullptr) {
contactContacts = new ContactContacts;
m_ui->tabWidget->addTab(contactContacts, contactContacts->title());
}
contactContacts->setVCard(info.jid, info.vcard, info.editable);
contactContacts->setVCard(jid, card, editable);
}
void UI::Info::initializeDescription(const Shared::Info& info) {
void UI::Info::initializeDescription(const QString& descr, bool editable) {
if (description == nullptr) {
description = new Description;
m_ui->tabWidget->addTab(description, description->title());
}
description->setDescription(info.vcard.getDescription());
description->setEditable(info.editable);
description->setDescription(descr);
description->setEditable(editable);
}
QString UI::Info::getJid() const {
return jid;}
void UI::Info::clear() {
if (contactGeneral != nullptr) {
contactGeneral->deleteLater();
contactGeneral = nullptr;
}
if (contactContacts != nullptr) {
contactContacts->deleteLater();
contactContacts = nullptr;
}
if (description != nullptr) {
description->deleteLater();
description = nullptr;
}
type = Shared::EntryType::none;
}

View File

@ -23,6 +23,7 @@
#include <QLabel>
#include <shared/info.h>
#include <shared/global.h>
#include "ui/utils/progress.h"
@ -42,13 +43,11 @@ public:
Info(const QString& jid, QWidget* parent = nullptr);
~Info();
QString getJid() const;
void setData(const Shared::Info& info);
void showProgress(const QString& = "");
void hideProgress();
public:
QString jid;
signals:
void saveInfo(const Shared::Info& info);
@ -56,13 +55,16 @@ private slots:
void onButtonBoxAccepted();
private:
void initializeContactGeneral(const Shared::Info& info);
void initializeContactContacts(const Shared::Info& info);
void initializeDescription(const Shared::Info& info);
void initializeContactGeneral(const QString& jid, const Shared::VCard& card, bool editable);
void initializeContactContacts(const QString& jid, const Shared::VCard& card, bool editable);
void initializeDescription(const QString& description, bool editable);
void initializeOverlay();
void initializeButtonBox();
void clear();
private:
QString jid;
Shared::EntryType type;
QScopedPointer<Ui::Info> m_ui;
ContactGeneral* contactGeneral;
ContactContacts* contactContacts;