"Fossies" - the Fresh Open Source Software Archive

Member "tdesktop-2.6.1/Telegram/SourceFiles/boxes/mute_settings_box.cpp" (24 Feb 2021, 2792 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mute_settings_box.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2 This file is part of Telegram Desktop,
    3 the official desktop application for the Telegram messaging service.
    4 
    5 This code is in Public Domain, see license terms in .github/CONTRIBUTING.md
    6 Copyright (C) 2017, Nicholas Guriev <guriev-ns@ya.ru>
    7 */
    8 #include "boxes/mute_settings_box.h"
    9 
   10 #include "lang/lang_keys.h"
   11 #include "main/main_session.h"
   12 #include "data/data_session.h"
   13 #include "data/data_peer.h"
   14 #include "ui/special_buttons.h"
   15 #include "ui/widgets/checkbox.h"
   16 #include "ui/widgets/labels.h"
   17 #include "app.h"
   18 #include "styles/style_layers.h"
   19 #include "styles/style_boxes.h"
   20 
   21 namespace {
   22 
   23 constexpr auto kForeverHours = 24 * 365;
   24 
   25 } // namespace
   26 
   27 MuteSettingsBox::MuteSettingsBox(QWidget *parent, not_null<PeerData*> peer)
   28 : _peer(peer) {
   29 }
   30 
   31 void MuteSettingsBox::prepare() {
   32     setTitle(tr::lng_disable_notifications_from_tray());
   33     auto y = 0;
   34 
   35     object_ptr<Ui::FlatLabel> info(this, st::boxLabel);
   36     info->setText(tr::lng_mute_box_tip(tr::now));
   37     info->moveToLeft(st::boxPadding.left(), y);
   38     y += info->height() + st::boxLittleSkip;
   39 
   40     const auto icon = object_ptr<Ui::UserpicButton>(
   41         this,
   42         _peer,
   43         Ui::UserpicButton::Role::Custom,
   44         st::mutePhotoButton);
   45     icon->setPointerCursor(false);
   46     icon->moveToLeft(st::boxPadding.left(), y);
   47 
   48     object_ptr<Ui::FlatLabel> title(this, st::muteChatTitle);
   49     title->setText(_peer->name);
   50     title->moveToLeft(
   51         st::boxPadding.left() + st::muteChatTitleLeft,
   52         y + (icon->height() / 2) - (title->height() / 2));
   53     // the icon is always higher than this chat title
   54     y += icon->height() + st::boxMediumSkip;
   55 
   56     // in fact, this is mute only for 1 year
   57     const auto group = std::make_shared<Ui::RadiobuttonGroup>(kForeverHours);
   58     y += st::boxOptionListPadding.top();
   59     for (const auto hours : { 1, 4, 18, 72, kForeverHours }) {
   60         const auto text = [&] {
   61             if (hours < 24) {
   62                 return tr::lng_mute_duration_hours(tr::now, lt_count, hours);
   63             } else if (hours < kForeverHours) {
   64                 return tr::lng_mute_duration_days(tr::now, lt_count, hours / 24);
   65             } else {
   66                 return tr::lng_mute_duration_forever(tr::now);
   67             }
   68         }();
   69         object_ptr<Ui::Radiobutton> option(this, group, hours, text);
   70         option->moveToLeft(st::boxPadding.left(), y);
   71         y += option->heightNoMargins() + st::boxOptionListSkip;
   72     }
   73     y += st::boxOptionListPadding.bottom()
   74         - st::boxOptionListSkip
   75         + st::defaultCheckbox.margin.bottom();
   76 
   77     _save = [=] {
   78         const auto muteForSeconds = group->value() * 3600;
   79         _peer->owner().updateNotifySettings(
   80             _peer,
   81             muteForSeconds);
   82         closeBox();
   83     };
   84     addButton(tr::lng_box_ok(), _save);
   85     addButton(tr::lng_cancel(), [this] { closeBox(); });
   86 
   87     setDimensions(st::boxWidth, y);
   88 }
   89 
   90 void MuteSettingsBox::keyPressEvent(QKeyEvent *e) {
   91     if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
   92         if (_save) {
   93             _save();
   94         }
   95     }
   96 }
   97 
   98 // vi: ts=4 tw=80