2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#include "settings/settings_notifications_widget.h"
|
|
|
|
|
|
|
|
#include "styles/style_settings.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-10-26 10:06:00 +00:00
|
|
|
#include "ui/effects/widget_slide_wrap.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "mainwindow.h"
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2016-10-05 18:37:48 +00:00
|
|
|
#include "boxes/notifications_box.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
2017-03-04 19:36:59 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ChangeType = Window::Notifications::ChangeType;
|
|
|
|
|
|
|
|
} // namespace
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
NotificationsWidget::NotificationsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_notify)) {
|
2016-08-22 17:16:21 +00:00
|
|
|
createControls();
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().notifications().settingsChanged(), [this](ChangeType type) {
|
2017-03-04 19:36:59 +00:00
|
|
|
if (type == ChangeType::DesktopEnabled) {
|
2016-08-27 04:49:18 +00:00
|
|
|
desktopEnabledUpdated();
|
2017-03-04 19:36:59 +00:00
|
|
|
} else if (type == ChangeType::ViewParams) {
|
2016-08-27 04:49:18 +00:00
|
|
|
viewParamUpdated();
|
2017-03-04 19:36:59 +00:00
|
|
|
} else if (type == ChangeType::SoundEnabled) {
|
2016-08-27 04:49:18 +00:00
|
|
|
_playSound->setChecked(Global::SoundNotify());
|
|
|
|
}
|
|
|
|
});
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void NotificationsWidget::createControls() {
|
2016-08-28 19:16:23 +00:00
|
|
|
style::margins margin(0, 0, 0, st::settingsSkip);
|
2016-08-22 17:16:21 +00:00
|
|
|
style::margins slidedPadding(0, margin.bottom() / 2, 0, margin.bottom() - (margin.bottom() / 2));
|
2017-07-07 11:16:37 +00:00
|
|
|
addChildRow(_desktopNotifications, margin, lang(lng_settings_desktop_notify), [this](bool) { onDesktopNotifications(); }, Global::DesktopNotify());
|
|
|
|
addChildRow(_showSenderName, margin, slidedPadding, lang(lng_settings_show_name), [this](bool) { onShowSenderName(); }, Global::NotifyView() <= dbinvShowName);
|
|
|
|
addChildRow(_showMessagePreview, margin, slidedPadding, lang(lng_settings_show_preview), [this](bool) { onShowMessagePreview(); }, Global::NotifyView() <= dbinvShowPreview);
|
2016-08-22 17:16:21 +00:00
|
|
|
if (!_showSenderName->entity()->checked()) {
|
|
|
|
_showMessagePreview->hideFast();
|
|
|
|
}
|
|
|
|
if (!_desktopNotifications->checked()) {
|
|
|
|
_showSenderName->hideFast();
|
|
|
|
_showMessagePreview->hideFast();
|
|
|
|
}
|
2017-07-07 11:16:37 +00:00
|
|
|
addChildRow(_playSound, margin, lang(lng_settings_sound_notify), [this](bool) { onPlaySound(); }, Global::SoundNotify());
|
|
|
|
addChildRow(_includeMuted, margin, lang(lng_settings_include_muted), [this](bool) { onIncludeMuted(); }, Global::IncludeMuted());
|
2016-10-03 15:07:50 +00:00
|
|
|
|
2016-10-07 14:28:37 +00:00
|
|
|
if (cPlatform() != dbipMac) {
|
|
|
|
createNotificationsControls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsWidget::createNotificationsControls() {
|
|
|
|
style::margins margin(0, 0, 0, st::settingsSkip);
|
|
|
|
style::margins slidedPadding(0, margin.bottom() / 2, 0, margin.bottom() - (margin.bottom() / 2));
|
|
|
|
|
2017-02-28 14:05:30 +00:00
|
|
|
auto nativeNotificationsLabel = QString();
|
|
|
|
if (Platform::Notifications::Supported()) {
|
2016-08-22 17:16:21 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-10-03 15:07:50 +00:00
|
|
|
nativeNotificationsLabel = lang(lng_settings_use_windows);
|
2017-02-28 14:05:30 +00:00
|
|
|
#elif defined Q_OS_LINUX64 || defined Q_OS_LINUX32 // Q_OS_WIN
|
2016-10-03 15:07:50 +00:00
|
|
|
nativeNotificationsLabel = lang(lng_settings_use_native_notifications);
|
2017-02-28 14:05:30 +00:00
|
|
|
#endif // Q_OS_WIN || Q_OS_LINUX64 || Q_OS_LINUX32
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-10-03 15:07:50 +00:00
|
|
|
if (!nativeNotificationsLabel.isEmpty()) {
|
2017-07-07 11:16:37 +00:00
|
|
|
addChildRow(_nativeNotifications, margin, nativeNotificationsLabel, [this](bool) { onNativeNotifications(); }, Global::NativeNotifications());
|
2016-10-03 15:07:50 +00:00
|
|
|
}
|
2016-10-05 18:37:48 +00:00
|
|
|
addChildRow(_advanced, margin, slidedPadding, lang(lng_settings_advanced_notifications), SLOT(onAdvanced()));
|
|
|
|
if (!nativeNotificationsLabel.isEmpty() && Global::NativeNotifications()) {
|
|
|
|
_advanced->hideFast();
|
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void NotificationsWidget::onDesktopNotifications() {
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::DesktopNotify() == _desktopNotifications->checked()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Global::SetDesktopNotify(_desktopNotifications->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(ChangeType::DesktopEnabled);
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2016-08-27 04:49:18 +00:00
|
|
|
void NotificationsWidget::desktopEnabledUpdated() {
|
|
|
|
_desktopNotifications->setChecked(Global::DesktopNotify());
|
2017-03-15 15:10:18 +00:00
|
|
|
_showSenderName->toggleAnimated(Global::DesktopNotify());
|
|
|
|
_showMessagePreview->toggleAnimated(Global::DesktopNotify() && _showSenderName->entity()->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsWidget::onShowSenderName() {
|
2016-08-27 04:49:18 +00:00
|
|
|
auto viewParam = ([this]() {
|
|
|
|
if (!_showSenderName->entity()->checked()) {
|
|
|
|
return dbinvShowNothing;
|
|
|
|
} else if (!_showMessagePreview->entity()->checked()) {
|
|
|
|
return dbinvShowName;
|
|
|
|
}
|
|
|
|
return dbinvShowPreview;
|
|
|
|
})();
|
|
|
|
if (viewParam == Global::NotifyView()) {
|
|
|
|
return;
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
Global::SetNotifyView(viewParam);
|
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(ChangeType::ViewParams);
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2016-08-27 04:49:18 +00:00
|
|
|
void NotificationsWidget::onShowMessagePreview() {
|
|
|
|
auto viewParam = ([this]() {
|
|
|
|
if (_showMessagePreview->entity()->checked()) {
|
|
|
|
return dbinvShowPreview;
|
|
|
|
} else if (_showSenderName->entity()->checked()) {
|
|
|
|
return dbinvShowName;
|
|
|
|
}
|
|
|
|
return dbinvShowNothing;
|
|
|
|
})();
|
|
|
|
if (viewParam == Global::NotifyView()) {
|
|
|
|
return;
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
|
|
|
|
Global::SetNotifyView(viewParam);
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(ChangeType::ViewParams);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 04:49:18 +00:00
|
|
|
void NotificationsWidget::viewParamUpdated() {
|
2017-03-15 15:10:18 +00:00
|
|
|
_showMessagePreview->toggleAnimated(_showSenderName->entity()->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 15:07:50 +00:00
|
|
|
void NotificationsWidget::onNativeNotifications() {
|
|
|
|
if (Global::NativeNotifications() == _nativeNotifications->checked()) {
|
2016-08-27 04:49:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-03 15:07:50 +00:00
|
|
|
Global::SetNativeNotifications(_nativeNotifications->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2016-10-05 18:37:48 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().createManager();
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2017-03-15 15:10:18 +00:00
|
|
|
_advanced->toggleAnimated(!Global::NativeNotifications());
|
2016-10-05 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsWidget::onAdvanced() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<NotificationsBox>());
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
|
|
|
|
void NotificationsWidget::onPlaySound() {
|
2016-08-27 04:49:18 +00:00
|
|
|
if (_playSound->checked() == Global::SoundNotify()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Global::SetSoundNotify(_playSound->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(ChangeType::SoundEnabled);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsWidget::onIncludeMuted() {
|
2016-08-27 04:49:18 +00:00
|
|
|
Global::SetIncludeMuted(_includeMuted->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().settingsChanged().notify(ChangeType::IncludeMuted);
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|