mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Show current chat name in the window title.
This commit is contained in:
@@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/sandbox.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "base/options.h"
|
||||
@@ -49,16 +50,8 @@ namespace {
|
||||
|
||||
constexpr auto kSaveWindowPositionTimeout = crl::time(1000);
|
||||
|
||||
base::options::toggle ShowChatNameInNewWindow({
|
||||
.id = kOptionShowChatNameInNewWindow,
|
||||
.name = "Chat name in window title",
|
||||
.description = "Show chat name in the additional windows titles.",
|
||||
});
|
||||
|
||||
} // namespace
|
||||
|
||||
const char kOptionShowChatNameInNewWindow[] = "show-chat-name-in-new-window";
|
||||
|
||||
const QImage &Logo() {
|
||||
static const auto result = QImage(u":/gui/art/logo_256.png"_q);
|
||||
return result;
|
||||
@@ -329,7 +322,9 @@ MainWindow::MainWindow(not_null<Controller*> controller)
|
||||
|
||||
Core::App().unreadBadgeChanges(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateUnreadCounter();
|
||||
updateTitle();
|
||||
unreadCounterChangedHook();
|
||||
Core::App().tray().updateIconCounters();
|
||||
}, lifetime());
|
||||
|
||||
Core::App().settings().workModeChanges(
|
||||
@@ -421,18 +416,6 @@ bool MainWindow::computeIsActive() const {
|
||||
return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized);
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowIcon() {
|
||||
const auto session = sessionController()
|
||||
? &sessionController()->session()
|
||||
: nullptr;
|
||||
const auto supportIcon = session && session->supportMode();
|
||||
if (supportIcon != _usingSupportIcon || _icon.isNull()) {
|
||||
_icon = CreateIcon(session);
|
||||
_usingSupportIcon = supportIcon;
|
||||
}
|
||||
setWindowIcon(_icon);
|
||||
}
|
||||
|
||||
QRect MainWindow::desktopRect() const {
|
||||
const auto now = crl::now();
|
||||
if (!_monitorLastGot || now >= _monitorLastGot + crl::time(1000)) {
|
||||
@@ -446,7 +429,6 @@ void MainWindow::init() {
|
||||
createWinId();
|
||||
|
||||
initHook();
|
||||
updateWindowIcon();
|
||||
|
||||
// Non-queued activeChanged handlers must use QtSignalProducer.
|
||||
connect(
|
||||
@@ -478,7 +460,8 @@ void MainWindow::init() {
|
||||
refreshTitleWidget();
|
||||
|
||||
initGeometry();
|
||||
updateUnreadCounter();
|
||||
updateTitle();
|
||||
updateWindowIcon();
|
||||
}
|
||||
|
||||
void MainWindow::handleStateChanged(Qt::WindowState state) {
|
||||
@@ -522,7 +505,8 @@ void MainWindow::showFromTray() {
|
||||
updateGlobalMenu();
|
||||
});
|
||||
activate();
|
||||
updateUnreadCounter();
|
||||
unreadCounterChangedHook();
|
||||
Core::App().tray().updateIconCounters();
|
||||
}
|
||||
|
||||
void MainWindow::quitFromTray() {
|
||||
@@ -801,30 +785,34 @@ void MainWindow::updateControlsGeometry() {
|
||||
_body->setGeometry(bodyLeft, bodyTop, bodyWidth, inner.height() - (bodyTop - inner.y()));
|
||||
}
|
||||
|
||||
void MainWindow::updateUnreadCounter() {
|
||||
void MainWindow::updateTitle() {
|
||||
if (Core::Quitting()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ShowChatNameInNewWindow.value() && singlePeer()) {
|
||||
const auto peer = singlePeer();
|
||||
const auto history = peer->owner().history(peer);
|
||||
const auto name = peer->isSelf()
|
||||
? tr::lng_saved_messages(tr::now)
|
||||
: peer->name();
|
||||
const auto counter = history->unreadCount();
|
||||
setTitle((counter > 0)
|
||||
? u"(%1) %2 \u2013 Telegram"_q.arg(QString::number(counter), name)
|
||||
: u"%1 \u2013 Telegram"_q.arg(name));
|
||||
} else {
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
setTitle((counter > 0)
|
||||
? u"Telegram (%1)"_q.arg(counter)
|
||||
: u"Telegram"_q);
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
const auto basic = (counter > 0)
|
||||
? u"Telegram (%1)"_q.arg(counter)
|
||||
: u"Telegram"_q;
|
||||
const auto session = _controller->sessionController();
|
||||
const auto key = session ? session->activeChatCurrent() : Dialogs::Key();
|
||||
const auto thread = key ? key.thread() : nullptr;
|
||||
if (!thread) {
|
||||
setTitle(basic);
|
||||
return;
|
||||
}
|
||||
|
||||
Core::App().tray().updateIconCounters();
|
||||
unreadCounterChangedHook();
|
||||
const auto history = thread->owningHistory();
|
||||
const auto topic = thread->asTopic();
|
||||
const auto name = topic
|
||||
? topic->title()
|
||||
: history->peer->isSelf()
|
||||
? tr::lng_saved_messages(tr::now)
|
||||
: history->peer->name();
|
||||
const auto threadCounter = thread->chatListBadgesState().unreadCounter;
|
||||
const auto primary = (threadCounter > 0)
|
||||
? u"(%1) %2"_q.arg(threadCounter).arg(name)
|
||||
: name;
|
||||
setTitle(primary + u" \u2013 "_q + basic);
|
||||
}
|
||||
|
||||
QRect MainWindow::computeDesktopRect() const {
|
||||
|
Reference in New Issue
Block a user