2018-01-03 10:23:14 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-07-19 15:25:50 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
This code is in Public Domain, see license terms in .github/CONTRIBUTING.md
|
|
|
|
Copyright (C) 2017, Nicholas Guriev <guriev-ns@ya.ru>
|
|
|
|
*/
|
2017-07-19 15:25:50 +00:00
|
|
|
#include "boxes/mute_settings_box.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-04-09 17:48:29 +00:00
|
|
|
#include "data/data_session.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "data/data_peer.h"
|
2017-07-19 15:25:50 +00:00
|
|
|
#include "ui/special_buttons.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-07-19 15:25:50 +00:00
|
|
|
|
2017-12-04 17:46:03 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kForeverHours = 24 * 365;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-06-08 19:26:23 +00:00
|
|
|
MuteSettingsBox::MuteSettingsBox(QWidget *parent, not_null<PeerData*> peer)
|
|
|
|
: _peer(peer) {
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:25:50 +00:00
|
|
|
void MuteSettingsBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_disable_notifications_from_tray());
|
2017-12-04 17:46:03 +00:00
|
|
|
auto y = 0;
|
2017-07-19 15:25:50 +00:00
|
|
|
|
|
|
|
object_ptr<Ui::FlatLabel> info(this, st::boxLabel);
|
2019-06-19 15:09:03 +00:00
|
|
|
info->setText(tr::lng_mute_box_tip(tr::now));
|
2017-07-19 15:25:50 +00:00
|
|
|
info->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
y += info->height() + st::boxLittleSkip;
|
|
|
|
|
2017-12-04 17:46:03 +00:00
|
|
|
const auto icon = object_ptr<Ui::UserpicButton>(
|
2017-11-13 13:19:14 +00:00
|
|
|
this,
|
|
|
|
_peer,
|
|
|
|
Ui::UserpicButton::Role::Custom,
|
|
|
|
st::mutePhotoButton);
|
2017-07-19 15:25:50 +00:00
|
|
|
icon->setPointerCursor(false);
|
|
|
|
icon->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
|
|
|
|
object_ptr<Ui::FlatLabel> title(this, st::muteChatTitle);
|
2019-09-13 06:06:02 +00:00
|
|
|
title->setText(_peer->name);
|
2017-09-20 19:44:22 +00:00
|
|
|
title->moveToLeft(
|
|
|
|
st::boxPadding.left() + st::muteChatTitleLeft,
|
|
|
|
y + (icon->height() / 2) - (title->height() / 2));
|
2017-07-19 15:25:50 +00:00
|
|
|
// the icon is always higher than this chat title
|
|
|
|
y += icon->height() + st::boxMediumSkip;
|
|
|
|
|
2017-12-04 17:46:03 +00:00
|
|
|
// in fact, this is mute only for 1 year
|
|
|
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(kForeverHours);
|
2017-07-19 15:25:50 +00:00
|
|
|
y += st::boxOptionListPadding.top();
|
2017-12-04 17:46:03 +00:00
|
|
|
for (const auto hours : { 1, 4, 18, 72, kForeverHours }) {
|
|
|
|
const auto text = [&] {
|
|
|
|
if (hours < 24) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_mute_duration_hours(tr::now, lt_count, hours);
|
2017-12-04 17:46:03 +00:00
|
|
|
} else if (hours < kForeverHours) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_mute_duration_days(tr::now, lt_count, hours / 24);
|
2017-12-04 17:46:03 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_mute_duration_forever(tr::now);
|
2017-12-04 17:46:03 +00:00
|
|
|
}
|
|
|
|
}();
|
|
|
|
object_ptr<Ui::Radiobutton> option(this, group, hours, text);
|
2017-07-19 15:25:50 +00:00
|
|
|
option->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
y += option->heightNoMargins() + st::boxOptionListSkip;
|
|
|
|
}
|
2017-12-04 17:46:03 +00:00
|
|
|
y += st::boxOptionListPadding.bottom()
|
|
|
|
- st::boxOptionListSkip
|
|
|
|
+ st::defaultCheckbox.margin.bottom();
|
2017-07-19 15:25:50 +00:00
|
|
|
|
2018-06-08 19:26:23 +00:00
|
|
|
_save = [=] {
|
|
|
|
const auto muteForSeconds = group->value() * 3600;
|
2020-02-21 07:58:50 +00:00
|
|
|
_peer->owner().updateNotifySettings(
|
2017-12-04 17:46:03 +00:00
|
|
|
_peer,
|
|
|
|
muteForSeconds);
|
2017-07-19 15:25:50 +00:00
|
|
|
closeBox();
|
2018-06-08 19:26:23 +00:00
|
|
|
};
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_box_ok(), _save);
|
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2017-07-19 15:25:50 +00:00
|
|
|
|
|
|
|
setDimensions(st::boxWidth, y);
|
|
|
|
}
|
2018-06-08 19:26:23 +00:00
|
|
|
|
|
|
|
void MuteSettingsBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
|
|
if (_save) {
|
|
|
|
_save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:25:50 +00:00
|
|
|
// vi: ts=4 tw=80
|