Skip to content

Commit

Permalink
Add chat name / account name / unread count title settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Feb 3, 2023
1 parent eb64ffc commit 94b4898
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 34 deletions.
4 changes: 4 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_workmode_tray" = "Show tray icon";
"lng_settings_workmode_window" = "Show taskbar icon";
"lng_settings_close_to_taskbar" = "Close to taskbar";
"lng_settings_window_system" = "Window title";
"lng_settings_title_chat_name" = "Show chat name";
"lng_settings_title_account_name" = "Show active account";
"lng_settings_title_total_count" = "Total unread count";
"lng_settings_native_frame" = "Use system window frame";
"lng_settings_auto_start" = "Launch Telegram when system starts";
"lng_settings_start_min" = "Launch minimized";
Expand Down
12 changes: 12 additions & 0 deletions Telegram/SourceFiles/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ Application::Application(not_null<Launcher*> launcher)
passcodeLockChanges(
) | rpl::start_with_next([=] {
_notifications->updateAll();
updateWindowTitles();
}, _lifetime);

settings().windowTitleContentChanges(
) | rpl::start_with_next([=] {
updateWindowTitles();
}, _lifetime);

_domain->activeSessionChanges(
Expand Down Expand Up @@ -1067,6 +1073,12 @@ void Application::preventOrInvoke(Fn<void()> &&callback) {
_lastActivePrimaryWindow->preventOrInvoke(std::move(callback));
}

void Application::updateWindowTitles() {
enumerateWindows([](not_null<Window::Controller*> window) {
window->widget()->updateTitle();
});
}

void Application::lockByPasscode() {
enumerateWindows([&](not_null<Window::Controller*> w) {
_passcodeLock = true;
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class Application final : public QObject {
void startSystemDarkModeViewer();
void startTray();

void updateWindowTitles();
void setLastActiveWindow(Window::Controller *window);
void showAccount(not_null<Main::Account*> account);
void enumerateWindows(
Expand Down
22 changes: 20 additions & 2 deletions Telegram/SourceFiles/core/core_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ QByteArray Settings::serialize() const {
+ sizeof(qint32) * 7
+ (skipLanguages.size() * sizeof(quint64))
+ sizeof(qint32)
+ sizeof(quint64);
+ sizeof(quint64)
+ sizeof(qint32) * 3;

auto result = QByteArray();
result.reserve(size);
Expand Down Expand Up @@ -287,7 +288,10 @@ QByteArray Settings::serialize() const {

stream
<< qint32(_translateChatEnabled.current() ? 1 : 0)
<< quint64(QLocale::Language(_translateToRaw.current()));
<< quint64(QLocale::Language(_translateToRaw.current()))
<< qint32(_windowTitleContent.current().hideChatName ? 1 : 0)
<< qint32(_windowTitleContent.current().hideAccountName ? 1 : 0)
<< qint32(_windowTitleContent.current().hideTotalUnread ? 1 : 0);
}
return result;
}
Expand Down Expand Up @@ -387,6 +391,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
qint32 rememberedDeleteMessageOnlyForYou = _rememberedDeleteMessageOnlyForYou ? 1 : 0;
qint32 translateChatEnabled = _translateChatEnabled.current() ? 1 : 0;
quint64 translateToRaw = _translateToRaw.current();
qint32 hideChatName = _windowTitleContent.current().hideChatName ? 1 : 0;
qint32 hideAccountName = _windowTitleContent.current().hideAccountName ? 1 : 0;
qint32 hideTotalUnread = _windowTitleContent.current().hideTotalUnread ? 1 : 0;

stream >> themesAccentColors;
if (!stream.atEnd()) {
Expand Down Expand Up @@ -606,6 +613,12 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
>> translateChatEnabled
>> translateToRaw;
}
if (!stream.atEnd()) {
stream
>> hideChatName
>> hideAccountName
>> hideTotalUnread;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()"));
Expand Down Expand Up @@ -791,6 +804,11 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
_rememberedDeleteMessageOnlyForYou = (rememberedDeleteMessageOnlyForYou == 1);
_translateChatEnabled = (translateChatEnabled == 1);
_translateToRaw = int(QLocale::Language(translateToRaw));
_windowTitleContent = WindowTitleContent{
.hideChatName = (hideChatName == 1),
.hideAccountName = (hideAccountName == 1),
.hideTotalUnread = (hideTotalUnread == 1),
};
}

QString Settings::getSoundPath(const QString &key) const {
Expand Down
20 changes: 20 additions & 0 deletions Telegram/SourceFiles/core/core_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ struct WindowPosition {
int h = 0;
};

struct WindowTitleContent {
bool hideChatName : 1 = false;
bool hideAccountName : 1 = false;
bool hideTotalUnread : 1 = false;

friend inline constexpr auto operator<=>(
WindowTitleContent,
WindowTitleContent) = default;
};

constexpr auto kRecentEmojiLimit = 42;

struct RecentEmojiDocument {
Expand Down Expand Up @@ -598,6 +608,15 @@ class Settings final {
[[nodiscard]] rpl::producer<bool> systemDarkModeEnabledChanges() const {
return _systemDarkModeEnabled.changes();
}
[[nodiscard]] WindowTitleContent windowTitleContent() const {
return _windowTitleContent.current();
}
[[nodiscard]] rpl::producer<WindowTitleContent> windowTitleContentChanges() const {
return _windowTitleContent.changes();
}
void setWindowTitleContent(WindowTitleContent content) {
_windowTitleContent = content;
}
[[nodiscard]] const WindowPosition &windowPosition() const {
return _windowPosition;
}
Expand Down Expand Up @@ -837,6 +856,7 @@ class Settings final {
rpl::variable<bool> _nativeWindowFrame = false;
rpl::variable<std::optional<bool>> _systemDarkMode = std::nullopt;
rpl::variable<bool> _systemDarkModeEnabled = false;
rpl::variable<WindowTitleContent> _windowTitleContent;
WindowPosition _windowPosition; // per-window
bool _disableOpenGL = false;
rpl::variable<WorkMode> _workMode = WorkMode::WindowAndTray;
Expand Down
10 changes: 10 additions & 0 deletions Telegram/SourceFiles/main/main_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ Account *Domain::maybeLastOrSomeAuthedAccount() {
return result;
}

int Domain::accountsAuthedCount() const {
auto result = 0;
for (const auto &[index, account] : _accounts) {
if (account->sessionExists()) {
++result;
}
}
return result;
}

rpl::producer<Account*> Domain::activeValue() const {
return _active.value();
}
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/main/main_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Domain final {
[[nodiscard]] rpl::producer<Account*> activeValue() const;
[[nodiscard]] rpl::producer<> accountsChanges() const;
[[nodiscard]] Account *maybeLastOrSomeAuthedAccount();
[[nodiscard]] int accountsAuthedCount() const;

// Expects(started());
[[nodiscard]] Account &active() const;
Expand Down
138 changes: 115 additions & 23 deletions Telegram/SourceFiles/settings/settings_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,85 @@ void SetupSpellchecker(
#endif // !TDESKTOP_DISABLE_SPELLCHECK
}

void SetupWindowTitleContent(
Window::SessionController *controller,
not_null<Ui::VerticalLayout*> container) {
const auto checkbox = [&](rpl::producer<QString> &&label, bool checked) {
return object_ptr<Ui::Checkbox>(
container,
std::move(label),
checked,
st::settingsCheckbox);
};
const auto addCheckbox = [&](
rpl::producer<QString> &&label,
bool checked) {
return container->add(
checkbox(std::move(label), checked),
st::settingsCheckboxPadding);
};
const auto settings = &Core::App().settings();
if (controller) {
const auto content = [=] {
return settings->windowTitleContent();
};
const auto showChatName = addCheckbox(
tr::lng_settings_title_chat_name(),
!content().hideChatName);
showChatName->checkedChanges(
) | rpl::filter([=](bool checked) {
return (checked == content().hideChatName);
}) | rpl::start_with_next([=](bool checked) {
auto updated = content();
updated.hideChatName = !checked;
settings->setWindowTitleContent(updated);
Core::App().saveSettingsDelayed();
}, showChatName->lifetime());

if (Core::App().domain().accountsAuthedCount() > 1) {
const auto showAccountName = addCheckbox(
tr::lng_settings_title_account_name(),
!content().hideAccountName);
showAccountName->checkedChanges(
) | rpl::filter([=](bool checked) {
return (checked == content().hideAccountName);
}) | rpl::start_with_next([=](bool checked) {
auto updated = content();
updated.hideAccountName = !checked;
settings->setWindowTitleContent(updated);
Core::App().saveSettingsDelayed();
}, showAccountName->lifetime());
}

const auto showTotalUnread = addCheckbox(
tr::lng_settings_title_total_count(),
!content().hideTotalUnread);
showTotalUnread->checkedChanges(
) | rpl::filter([=](bool checked) {
return (checked == content().hideTotalUnread);
}) | rpl::start_with_next([=](bool checked) {
auto updated = content();
updated.hideTotalUnread = !checked;
settings->setWindowTitleContent(updated);
Core::App().saveSettingsDelayed();
}, showTotalUnread->lifetime());
}

if (Ui::Platform::NativeWindowFrameSupported()) {
const auto nativeFrame = addCheckbox(
tr::lng_settings_native_frame(),
Core::App().settings().nativeWindowFrame());

nativeFrame->checkedChanges(
) | rpl::filter([](bool checked) {
return (checked != Core::App().settings().nativeWindowFrame());
}) | rpl::start_with_next([=](bool checked) {
Core::App().settings().setNativeWindowFrame(checked);
Core::App().saveSettingsDelayed();
}, nativeFrame->lifetime());
}
}

void SetupSystemIntegrationContent(
Window::SessionController *controller,
not_null<Ui::VerticalLayout*> container) {
Expand Down Expand Up @@ -469,20 +548,6 @@ void SetupSystemIntegrationContent(
}, closeToTaskbar->lifetime());
#endif // Q_OS_MAC

if (Ui::Platform::NativeWindowFrameSupported()) {
const auto nativeFrame = addCheckbox(
tr::lng_settings_native_frame(),
Core::App().settings().nativeWindowFrame());

nativeFrame->checkedChanges(
) | rpl::filter([](bool checked) {
return (checked != Core::App().settings().nativeWindowFrame());
}) | rpl::start_with_next([=](bool checked) {
Core::App().settings().setNativeWindowFrame(checked);
Core::App().saveSettingsDelayed();
}, nativeFrame->lifetime());
}

if (Platform::AutostartSupported() && controller) {
const auto minimizedToggled = [=] {
return cStartMinimized()
Expand Down Expand Up @@ -560,20 +625,39 @@ void SetupSystemIntegrationContent(
}
}

void SetupSystemIntegrationOptions(
template <typename Fill>
void CheckNonEmptyOptions(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
not_null<Ui::VerticalLayout*> container,
Fill fill) {
auto wrap = object_ptr<Ui::VerticalLayout>(container);
SetupSystemIntegrationContent(controller, wrap.data());
fill(controller, wrap.data());
if (wrap->count() > 0) {
container->add(object_ptr<Ui::OverrideMargins>(
container,
std::move(wrap)));

AddSkip(container, st::settingsCheckboxesSkip);
}
}

void SetupSystemIntegrationOptions(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
CheckNonEmptyOptions(
controller,
container,
SetupSystemIntegrationContent);
}

void SetupWindowTitleOptions(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
CheckNonEmptyOptions(
controller,
container,
SetupWindowTitleContent);
}

void SetupAnimations(not_null<Ui::VerticalLayout*> container) {
AddButton(
container,
Expand Down Expand Up @@ -731,10 +815,19 @@ void SetupPerformance(
#endif // Q_OS_WIN
}

void SetupWindowTitle(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::lng_settings_window_system());
SetupWindowTitleOptions(controller, container);
AddSkip(container);
}

void SetupSystemIntegration(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
Fn<void(Type)> showOther) {
not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::lng_settings_system_integration());
Expand Down Expand Up @@ -785,9 +878,8 @@ void Advanced::setupContent(not_null<Window::SessionController*> controller) {
addDivider();
SetupDataStorage(controller, content);
SetupAutoDownload(controller, content);
SetupSystemIntegration(controller, content, [=](Type type) {
_showOther.fire_copy(type);
});
SetupWindowTitle(controller, content);
SetupSystemIntegration(controller, content);
empty = false;

AddDivider(content);
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/settings/settings_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ bool HasUpdate();
void SetupUpdate(
not_null<Ui::VerticalLayout*> container,
Fn<void(Type)> showOther);
void SetupWindowTitleContent(
Window::SessionController *controller,
not_null<Ui::VerticalLayout*> container);
void SetupSystemIntegrationContent(
Window::SessionController *controller,
not_null<Ui::VerticalLayout*> container);
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/settings/settings_intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ object_ptr<Ui::RpWidget> CreateIntroSettings(
SetupSystemIntegrationContent(
window->sessionController(),
wrap.data());
SetupWindowTitleContent(
window->sessionController(),
wrap.data());
if (wrap->count() > 0) {
AddDivider(result);
AddSkip(result);
Expand Down
Loading

0 comments on commit 94b4898

Please sign in to comment.