From ec362cef553f0397065e6004495f0f4cd6a3f22f Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 21 Feb 2023 23:27:28 +0300 Subject: [PATCH] some further thinking of info widget --- core/handlers/vcardhandler.cpp | 4 +- shared/enums.h | 4 +- ui/squawk.cpp | 9 +--- ui/widgets/info/info.cpp | 81 ++++++++++++++++++++-------------- ui/widgets/info/info.h | 14 +++--- 5 files changed, 64 insertions(+), 48 deletions(-) diff --git a/core/handlers/vcardhandler.cpp b/core/handlers/vcardhandler.cpp index c9e7170..ca8b29b 100644 --- a/core/handlers/vcardhandler.cpp +++ b/core/handlers/vcardhandler.cpp @@ -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(); diff --git a/shared/enums.h b/shared/enums.h index 9eb9e5e..46d954a 100644 --- a/shared/enums.h +++ b/shared/enums.h @@ -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, diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 9702357..2c969da 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -422,7 +422,7 @@ void Squawk::responseInfo(const Shared::Info& info) { void Squawk::onInfoClosed() { UI::Info* info = static_cast(sender()); - std::map::const_iterator itr = infoWidgets.find(info->jid); + std::map::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)); diff --git a/ui/widgets/info/info.cpp b/ui/widgets/info/info.cpp index f7d7a97..e951e97 100644 --- a/ui/widgets/info/info.cpp +++ b/ui/widgets/info/info.cpp @@ -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 - Shared::Info info; - if (contactGeneral != nullptr) + if (type == Shared::EntryType::ownAccount) { + Shared::Info info; contactGeneral->fillVCard(info.vcard); - if (contactContacts != nullptr) contactContacts->fillVCard(info.vcard); - if (description != nullptr) info.vcard.setDescription(description->description()); - - emit saveInfo(info); + 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; +} diff --git a/ui/widgets/info/info.h b/ui/widgets/info/info.h index 461242f..14829e7 100644 --- a/ui/widgets/info/info.h +++ b/ui/widgets/info/info.h @@ -23,6 +23,7 @@ #include #include +#include #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 m_ui; ContactGeneral* contactGeneral; ContactContacts* contactContacts;