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_chat_settings_widget.h"
|
|
|
|
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "lang.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-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "mainwidget.h"
|
2016-08-28 19:16:23 +00:00
|
|
|
#include "mainwindow.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/emoji_box.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "boxes/stickers_box.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/download_path_box.h"
|
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
LabeledLink::LabeledLink(QWidget *parent, const QString &label, const QString &text, Type type, const char *slot) : TWidget(parent)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _label(this, label, Ui::FlatLabel::InitType::Simple, (type == Type::Primary) ? st::settingsPrimaryLabel : st::defaultFlatLabel)
|
2016-11-11 13:46:04 +00:00
|
|
|
, _link(this, text, (type == Type::Primary) ? st::boxLinkButton : st::defaultLinkButton) {
|
2016-08-28 19:16:23 +00:00
|
|
|
connect(_link, SIGNAL(clicked()), parent, slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabeledLink::setLink(const QString &text) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_link.create(this, text);
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::LinkButton *LabeledLink::link() const {
|
|
|
|
return _link;
|
|
|
|
}
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
int LabeledLink::naturalWidth() const {
|
|
|
|
return _label->naturalWidth() + st::normalFont->spacew + _link->naturalWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
int LabeledLink::resizeGetHeight(int newWidth) {
|
|
|
|
_label->moveToLeft(0, 0, newWidth);
|
|
|
|
_link->resizeToWidth(newWidth - st::normalFont->spacew - _label->width());
|
|
|
|
_link->moveToLeft(_label->width() + st::normalFont->spacew, 0, newWidth);
|
|
|
|
return _label->height();
|
|
|
|
}
|
|
|
|
|
2017-02-03 10:17:40 +00:00
|
|
|
#ifndef OS_WIN_STORE
|
2016-08-28 19:16:23 +00:00
|
|
|
DownloadPathState::DownloadPathState(QWidget *parent) : TWidget(parent)
|
|
|
|
, _path(this, lang(lng_download_path_label), downloadPathText(), LabeledLink::Type::Secondary, SLOT(onDownloadPath()))
|
|
|
|
, _clear(this, lang(lng_download_path_clear)) {
|
|
|
|
connect(_clear, SIGNAL(clicked()), this, SLOT(onClear()));
|
|
|
|
connect(App::wnd(), SIGNAL(tempDirCleared(int)), this, SLOT(onTempDirCleared(int)));
|
|
|
|
connect(App::wnd(), SIGNAL(tempDirClearFailed(int)), this, SLOT(onTempDirClearFailed(int)));
|
2016-08-27 04:49:18 +00:00
|
|
|
subscribe(Global::RefDownloadPathChanged(), [this]() {
|
2016-08-28 19:16:23 +00:00
|
|
|
_path->link()->setText(downloadPathText());
|
2016-08-27 04:49:18 +00:00
|
|
|
resizeToWidth(width());
|
|
|
|
});
|
2016-08-28 19:16:23 +00:00
|
|
|
switch (App::wnd()->tempDirState()) {
|
|
|
|
case MainWindow::TempDirEmpty: _state = State::Empty; break;
|
|
|
|
case MainWindow::TempDirExists: _state = State::Exists; break;
|
|
|
|
case MainWindow::TempDirRemoving: _state = State::Clearing; break;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
int DownloadPathState::resizeGetHeight(int newWidth) {
|
|
|
|
_path->resizeToWidth(qMin(newWidth, _path->naturalWidth()));
|
|
|
|
_path->moveToLeft(0, 0, newWidth);
|
|
|
|
_clear->moveToRight(0, 0, newWidth);
|
|
|
|
return _path->height();
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
void DownloadPathState::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
auto text = ([this]() -> QString {
|
|
|
|
switch (_state) {
|
|
|
|
case State::Clearing: return lang(lng_download_path_clearing);
|
|
|
|
case State::Cleared: return lang(lng_download_path_cleared);
|
|
|
|
case State::ClearFailed: return lang(lng_download_path_clear_failed);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
})();
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
p.setFont(st::linkFont);
|
2016-11-16 10:44:06 +00:00
|
|
|
p.setPen(st::windowFg);
|
2016-08-28 19:16:23 +00:00
|
|
|
p.drawTextRight(0, 0, width(), text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathState::updateControls() {
|
|
|
|
_clear->setVisible(_state == State::Exists);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DownloadPathState::downloadPathText() const {
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::DownloadPath().isEmpty()) {
|
|
|
|
return lang(lng_download_path_default);
|
|
|
|
} else if (Global::DownloadPath() == qsl("tmp")) {
|
|
|
|
return lang(lng_download_path_temp);
|
|
|
|
}
|
|
|
|
return QDir::toNativeSeparators(Global::DownloadPath());
|
|
|
|
};
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
void DownloadPathState::onDownloadPath() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<DownloadPathBox>());
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathState::onClear() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(lang(lng_sure_clear_downloads), base::lambda_guarded(this, [this] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
App::wnd()->tempDirDelete(Local::ClearManagerDownloads);
|
|
|
|
_state = State::Clearing;
|
|
|
|
updateControls();
|
|
|
|
})));
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathState::onTempDirCleared(int task) {
|
|
|
|
if (task & Local::ClearManagerDownloads) {
|
|
|
|
_state = State::Cleared;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathState::onTempDirClearFailed(int task) {
|
|
|
|
if (task & Local::ClearManagerDownloads) {
|
|
|
|
_state = State::ClearFailed;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
#endif // OS_WIN_STORE
|
2016-08-28 19:16:23 +00:00
|
|
|
|
|
|
|
ChatSettingsWidget::ChatSettingsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_chat_settings)) {
|
|
|
|
createControls();
|
|
|
|
}
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void ChatSettingsWidget::createControls() {
|
|
|
|
style::margins marginSmall(0, 0, 0, st::settingsSmallSkip);
|
|
|
|
style::margins marginSkip(0, 0, 0, st::settingsSkip);
|
|
|
|
style::margins marginSub(0, 0, 0, st::settingsSubSkip);
|
|
|
|
style::margins slidedPadding(0, marginSub.bottom() / 2, 0, marginSub.bottom() - (marginSub.bottom() / 2));
|
|
|
|
|
|
|
|
addChildRow(_replaceEmoji, marginSub, lang(lng_settings_replace_emojis), SLOT(onReplaceEmoji()), cReplaceEmojis());
|
2016-08-28 19:16:23 +00:00
|
|
|
style::margins marginList(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
|
2016-11-11 13:46:04 +00:00
|
|
|
addChildRow(_viewList, marginList, slidedPadding, lang(lng_settings_view_emojis), SLOT(onViewList()), st::defaultLinkButton);
|
2016-08-28 19:16:23 +00:00
|
|
|
if (!cReplaceEmojis()) {
|
|
|
|
_viewList->hideFast();
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2017-02-03 10:17:40 +00:00
|
|
|
#ifndef OS_WIN_STORE
|
|
|
|
auto pathMargin = marginSub;
|
|
|
|
#else // OS_WIN_STORE
|
|
|
|
auto pathMargin = marginSkip;
|
|
|
|
#endif // OS_WIN_STORE
|
|
|
|
addChildRow(_dontAskDownloadPath, pathMargin, lang(lng_download_path_dont_ask), SLOT(onDontAskDownloadPath()), !Global::AskDownloadPath());
|
|
|
|
|
|
|
|
#ifndef OS_WIN_STORE
|
2016-08-28 19:16:23 +00:00
|
|
|
style::margins marginPath(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
|
|
|
|
addChildRow(_downloadPath, marginPath, slidedPadding);
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::AskDownloadPath()) {
|
|
|
|
_downloadPath->hideFast();
|
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
#endif // OS_WIN_STORE
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
auto group = std::make_shared<Ui::RadioenumGroup<SendByType>>(cCtrlEnter() ? SendByType::CtrlEnter : SendByType::Enter);
|
|
|
|
addChildRow(_sendByEnter, marginSmall, group, SendByType::Enter, lang(lng_settings_send_enter));
|
|
|
|
addChildRow(_sendByCtrlEnter, marginSkip, group, SendByType::CtrlEnter, lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter));
|
|
|
|
group->setChangedCallback([this](SendByType value) {
|
2017-03-18 11:55:04 +00:00
|
|
|
sendByChanged(value);
|
|
|
|
});
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
addChildRow(_automaticMediaDownloadSettings, marginSmall, lang(lng_media_auto_settings), SLOT(onAutomaticMediaDownloadSettings()));
|
|
|
|
addChildRow(_manageStickerSets, marginSmall, lang(lng_stickers_you_have), SLOT(onManageStickerSets()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSettingsWidget::onReplaceEmoji() {
|
|
|
|
cSetReplaceEmojis(_replaceEmoji->checked());
|
|
|
|
Local::writeUserSettings();
|
|
|
|
|
2017-03-15 15:10:18 +00:00
|
|
|
_viewList->toggleAnimated(_replaceEmoji->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSettingsWidget::onViewList() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<EmojiBox>());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSettingsWidget::onDontAskDownloadPath() {
|
2016-08-27 04:49:18 +00:00
|
|
|
Global::SetAskDownloadPath(!_dontAskDownloadPath->checked());
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeUserSettings();
|
2017-02-03 10:17:40 +00:00
|
|
|
#ifndef OS_WIN_STORE
|
2017-03-15 15:10:18 +00:00
|
|
|
_downloadPath->toggleAnimated(_dontAskDownloadPath->checked());
|
2017-02-03 10:17:40 +00:00
|
|
|
#endif // OS_WIN_STORE
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
void ChatSettingsWidget::sendByChanged(SendByType value) {
|
|
|
|
cSetCtrlEnter(value == SendByType::CtrlEnter);
|
2017-03-18 11:55:04 +00:00
|
|
|
if (App::main()) App::main()->ctrlEnterSubmitUpdated();
|
|
|
|
Local::writeUserSettings();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSettingsWidget::onAutomaticMediaDownloadSettings() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<AutoDownloadBox>());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void ChatSettingsWidget::onManageStickerSets() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<StickersBox>(StickersBox::Section::Installed));
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|