From 9695b3f8343a04e71fea697fc8c280cdafe85465 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 20 Jun 2010 23:08:20 +0100 Subject: Show total unread count in tab title. Resolves: #448 diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index dd63c8d..5473823 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -55,6 +55,7 @@ void QtChatTabs::addTab(QtTabbable* tab) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); tabs_->addTab(tab, tab->windowTitle()); connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated())); + connect(tab, SIGNAL(countUpdated()), this, SLOT(handleTabTitleUpdated())); connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing())); connect(tab, SIGNAL(windowOpening()), this, SLOT(handleWidgetShown())); connect(tab, SIGNAL(wantsToActivate()), this, SLOT(handleWantsToActivate())); @@ -136,7 +137,7 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) { if (index < 0) { return; } - tabs_->setTabText(index, widget->windowTitle()); + tabs_->setTabText(index, tabbable->getCount() > 0 ? QString("(%1) %2").arg(tabbable->getCount()).arg(tabbable->windowTitle()) : tabbable->windowTitle()); QColor tabTextColor; bool flash = false; switch (tabbable->getWidgetAlertState()) { @@ -145,9 +146,13 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) { default : tabTextColor = QColor(); } tabs_->tabBar()->setTabTextColor(index, tabTextColor); - if (widget == tabs_->currentWidget()) { - setWindowTitle(widget->windowTitle()); + int unread = 0; + for (int i = 0; i < tabs_->count(); i++) { + unread += qobject_cast(tabs_->widget(i))->getCount(); } + + QtTabbable* current = qobject_cast(tabs_->currentWidget()); + setWindowTitle(unread > 0 ? QString("(%1) %2").arg(unread).arg(current->windowTitle()) : current->windowTitle()); if (flash) { #ifndef SWIFTEN_PLATFORM_MACOSX diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 0c297b2..fcc1308 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -198,6 +198,7 @@ void QtChatWindow::showEvent(QShowEvent* event) { void QtChatWindow::setUnreadMessageCount(int count) { unreadCount_ = count; updateTitleWithUnreadCount(); + emit countUpdated(); } void QtChatWindow::setContactChatState(ChatState::ChatStateType state) { @@ -221,7 +222,7 @@ void QtChatWindow::setName(const String& name) { } void QtChatWindow::updateTitleWithUnreadCount() { - setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2").arg(unreadCount_).arg(contact_) : contact_); + setWindowTitle(contact_); emit titleUpdated(); } @@ -255,6 +256,10 @@ void QtChatWindow::addMessage(const String &message, const String &senderName, b previousMessageWasSystem_ = false; } +int QtChatWindow::getCount() { + return unreadCount_; +} + void QtChatWindow::addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional& label, const String& avatarPath, const boost::posix_time::ptime& time) { addMessage(" *" + message + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time); } diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 44d79a1..00d7f25 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -46,6 +46,7 @@ namespace Swift { void setContactChatState(ChatState::ChatStateType state); void setRosterModel(Roster* roster); void setTabComplete(TabComplete* completer); + int getCount(); protected slots: void qAppFocusChanged(QWidget* old, QWidget* now); diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h index dd87142..9309841 100644 --- a/Swift/QtUI/QtTabbable.h +++ b/Swift/QtUI/QtTabbable.h @@ -17,11 +17,13 @@ namespace Swift { ~QtTabbable(); bool isWidgetSelected(); virtual AlertType getWidgetAlertState() {return NoActivity;}; + virtual int getCount() {return 0;} protected: QtTabbable() : QWidget() {}; signals: void titleUpdated(); + void countUpdated(); void windowClosing(); void windowOpening(); void wantsToActivate(); -- cgit v0.10.2-6-g49f6