From e952d1a6547aa2083b6e730a1ae3b32d76fab570 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 4 Jan 2016 22:34:30 +0100 Subject: [PATCH] Merge pull request #2767 from branch agilob:chat_window_icon * Set status icon on separate chat window, closes #2210 --- src/widget/contentdialog.cpp | 43 +++++++++++++++++++++++++++--------- src/widget/contentdialog.h | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 86e2e3cdc..4a3c31014 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -120,7 +120,7 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent) new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact())); new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact())); - connect(Core::getInstance(), &Core::usernameSet, this, &ContentDialog::updateTitleUsername); + connect(Core::getInstance(), &Core::usernameSet, this, &ContentDialog::updateTitleAndStatusIcon); Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this); } @@ -214,11 +214,9 @@ void ContentDialog::removeFriend(int friendId) FriendWidget* chatroomWidget = static_cast(std::get<1>(iter.value())); disconnect(chatroomWidget->getFriend(), &Friend::displayedNameChanged, this, &ContentDialog::updateFriendWidget); + // Need to find replacement to show here instead. if (activeChatroomWidget == chatroomWidget) - { - // Need to find replacement to show here instead. cycleContacts(true, false); - } friendLayout->removeFriendWidget(chatroomWidget, Status::Offline); friendLayout->removeFriendWidget(chatroomWidget, Status::Online); @@ -255,11 +253,9 @@ void ContentDialog::removeGroup(int groupId) GenericChatroomWidget* chatroomWidget = std::get<1>(iter.value()); + // Need to find replacement to show here instead. if (activeChatroomWidget == chatroomWidget) - { - // Need to find replacement to show here instead. cycleContacts(true, false); - } groupLayout.removeSortedWidget(chatroomWidget); chatroomWidget->deleteLater(); @@ -425,10 +421,37 @@ ContentDialog* ContentDialog::getGroupDialog(int groupId) return getDialog(groupId, groupList); } -void ContentDialog::updateTitleUsername(const QString& username) +void ContentDialog::updateTitleAndStatusIcon(const QString& username) { if (displayWidget != nullptr) + { + setWindowTitle(displayWidget->getTitle() + QStringLiteral(" - ") + username); + + // it's null when it's a groupchat + if(displayWidget->getFriend() == nullptr) + { + setWindowIcon(QIcon(":/img/group.svg")); + return; + } + + Status currentStatus = displayWidget->getFriend()->getStatus(); + + switch(currentStatus) { + case Status::Online: + setWindowIcon(QIcon(":/img/status/dot_online.svg")); + break; + case Status::Away: + setWindowIcon(QIcon(":/img/status/dot_away.svg")); + break; + case Status::Busy: + setWindowIcon(QIcon(":/img/status/dot_busy.svg")); + break; + case Status::Offline: + setWindowIcon(QIcon(":/img/status/dot_offline.svg")); + break; + } + } else setWindowTitle(username); } @@ -436,7 +459,7 @@ void ContentDialog::updateTitleUsername(const QString& username) void ContentDialog::updateTitle(GenericChatroomWidget* chatroomWidget) { displayWidget = chatroomWidget; - updateTitleUsername(Core::getInstance()->getUsername()); + updateTitleAndStatusIcon(Core::getInstance()->getUsername()); } void ContentDialog::previousContact() @@ -636,7 +659,7 @@ void ContentDialog::onGroupchatPositionChanged(bool top) void ContentDialog::retranslateUi() { - updateTitleUsername(Core::getInstance()->getUsername()); + updateTitleAndStatusIcon(Core::getInstance()->getUsername()); } void ContentDialog::saveDialogGeometry() diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 51904f087..29d67b4e7 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -72,7 +72,7 @@ signals: #endif public slots: - void updateTitleUsername(const QString& username); + void updateTitleAndStatusIcon(const QString& username); void updateTitle(GenericChatroomWidget* chatroomWidget); void previousContact(); void nextContact();