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_general_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"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "mainwindow.h"
|
2016-08-27 17:52:05 +00:00
|
|
|
#include "application.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "boxes/languagebox.h"
|
|
|
|
#include "boxes/confirmbox.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "boxes/aboutbox.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "langloaderplain.h"
|
2016-08-27 17:52:05 +00:00
|
|
|
#include "autoupdater.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2016-08-27 17:52:05 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
UpdateStateRow::UpdateStateRow(QWidget *parent) : TWidget(parent)
|
|
|
|
, _check(this, lang(lng_settings_check_now))
|
|
|
|
, _restart(this, lang(lng_settings_update_now)) {
|
|
|
|
connect(_check, SIGNAL(clicked()), this, SLOT(onCheck()));
|
|
|
|
connect(_restart, SIGNAL(clicked()), this, SIGNAL(restart()));
|
|
|
|
|
|
|
|
Sandbox::connect(SIGNAL(updateChecking()), this, SLOT(onChecking()));
|
|
|
|
Sandbox::connect(SIGNAL(updateLatest()), this, SLOT(onLatest()));
|
|
|
|
Sandbox::connect(SIGNAL(updateProgress(qint64, qint64)), this, SLOT(onDownloading(qint64, qint64)));
|
|
|
|
Sandbox::connect(SIGNAL(updateFailed()), this, SLOT(onFailed()));
|
|
|
|
Sandbox::connect(SIGNAL(updateReady()), this, SLOT(onReady()));
|
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
_versionText = lng_settings_current_version_label(lt_version, currentVersionText());
|
|
|
|
|
2016-08-27 17:52:05 +00:00
|
|
|
switch (Sandbox::updatingState()) {
|
|
|
|
case Application::UpdatingDownload:
|
|
|
|
setState(State::Download, true);
|
|
|
|
setDownloadProgress(Sandbox::updatingReady(), Sandbox::updatingSize());
|
|
|
|
break;
|
|
|
|
case Application::UpdatingReady: setState(State::Ready, true); break;
|
|
|
|
default: setState(State::None, true); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int UpdateStateRow::resizeGetHeight(int newWidth) {
|
|
|
|
auto labelWidth = [](const QString &label) {
|
|
|
|
return st::linkFont->width(label) + st::linkFont->spacew;
|
|
|
|
};
|
2016-12-26 22:46:36 +00:00
|
|
|
auto checkLeft = (_state == State::Latest) ? labelWidth(lang(lng_settings_latest_installed)) : labelWidth(_versionText);
|
2016-08-27 17:52:05 +00:00
|
|
|
auto restartLeft = labelWidth(lang(lng_settings_update_ready));
|
|
|
|
|
|
|
|
_check->resizeToWidth(qMin(newWidth, _check->naturalWidth()));
|
2016-08-28 19:16:23 +00:00
|
|
|
_check->moveToLeft(checkLeft, 0, newWidth);
|
2016-08-27 17:52:05 +00:00
|
|
|
|
|
|
|
_restart->resizeToWidth(qMin(newWidth, _restart->naturalWidth()));
|
2016-08-28 19:16:23 +00:00
|
|
|
_restart->moveToLeft(restartLeft, 0, newWidth);
|
2016-08-27 17:52:05 +00:00
|
|
|
|
|
|
|
return _check->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
auto text = ([this]() -> QString {
|
|
|
|
switch (_state) {
|
|
|
|
case State::Check: return lang(lng_settings_update_checking);
|
|
|
|
case State::Latest: return lang(lng_settings_latest_installed);
|
|
|
|
case State::Download: return _downloadText;
|
|
|
|
case State::Ready: return lang(lng_settings_update_ready);
|
|
|
|
case State::Fail: return lang(lng_settings_update_fail);
|
2016-12-26 22:46:36 +00:00
|
|
|
default: return _versionText;
|
2016-08-27 17:52:05 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
p.setFont(st::linkFont);
|
2016-12-26 22:46:36 +00:00
|
|
|
p.setPen((_state == State::None) ? st::windowFg : st::settingsUpdateFg);
|
2016-08-27 17:52:05 +00:00
|
|
|
p.drawTextLeft(0, 0, width(), text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onCheck() {
|
|
|
|
if (!cAutoUpdate()) return;
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
setState(State::Check);
|
2016-08-27 17:52:05 +00:00
|
|
|
cSetLastUpdateCheck(0);
|
|
|
|
Sandbox::startUpdateCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::setState(State state, bool force) {
|
|
|
|
if (_state != state || force) {
|
|
|
|
_state = state;
|
|
|
|
switch (state) {
|
2016-08-28 19:16:23 +00:00
|
|
|
case State::None: _check->show(); _restart->hide(); break;
|
2016-08-27 17:52:05 +00:00
|
|
|
case State::Ready: _check->hide(); _restart->show(); break;
|
|
|
|
case State::Check:
|
|
|
|
case State::Download:
|
2016-08-28 19:16:23 +00:00
|
|
|
case State::Latest:
|
2016-08-27 17:52:05 +00:00
|
|
|
case State::Fail: _check->hide(); _restart->hide(); break;
|
|
|
|
}
|
|
|
|
resizeToWidth(width());
|
|
|
|
sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::setDownloadProgress(qint64 ready, qint64 total) {
|
|
|
|
auto readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024));
|
|
|
|
auto readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10);
|
|
|
|
auto totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10);
|
|
|
|
auto result = lng_settings_downloading(lt_ready, readyStr, lt_total, totalStr);
|
|
|
|
if (_downloadText != result) {
|
|
|
|
_downloadText = result;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onChecking() {
|
|
|
|
setState(State::Check);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onLatest() {
|
|
|
|
setState(State::Latest);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onDownloading(qint64 ready, qint64 total) {
|
|
|
|
setState(State::Download);
|
|
|
|
setDownloadProgress(ready, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onReady() {
|
|
|
|
setState(State::Ready);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateStateRow::onFailed() {
|
|
|
|
setState(State::Fail);
|
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-08-27 17:52:05 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_general))
|
2016-11-11 13:46:04 +00:00
|
|
|
, _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) {
|
2016-08-27 04:49:18 +00:00
|
|
|
connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage()));
|
2016-08-27 17:52:05 +00:00
|
|
|
subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); });
|
2016-08-19 17:26:31 +00:00
|
|
|
refreshControls();
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
int GeneralWidget::resizeGetHeight(int newWidth) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_changeLanguage->moveToRight(contentLeft(), st::settingsBlockMarginTop + st::settingsBlockTitleTop + st::settingsBlockTitleFont->ascent - st::defaultLinkButton.font->ascent, newWidth);
|
2016-08-22 17:16:21 +00:00
|
|
|
return BlockWidget::resizeGetHeight(newWidth);
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
void GeneralWidget::refreshControls() {
|
2016-08-22 17:16:21 +00:00
|
|
|
style::margins marginSub(0, 0, 0, st::settingsSubSkip);
|
|
|
|
style::margins marginLarge(0, 0, 0, st::settingsLargeSkip);
|
|
|
|
style::margins marginSmall(0, 0, 0, st::settingsSmallSkip);
|
|
|
|
style::margins slidedPadding(0, marginSmall.bottom() / 2, 0, marginSmall.bottom() - (marginSmall.bottom() / 2));
|
|
|
|
|
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
2016-12-26 22:46:36 +00:00
|
|
|
addChildRow(_updateAutomatically, marginSub, lang(lng_settings_update_automatically), SLOT(onUpdateAutomatically()), cAutoUpdate());
|
2016-08-28 19:16:23 +00:00
|
|
|
style::margins marginLink(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
|
2016-08-27 17:52:05 +00:00
|
|
|
addChildRow(_updateRow, marginLink, slidedPadding);
|
|
|
|
connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart()));
|
2016-10-07 07:58:34 +00:00
|
|
|
if (!cAutoUpdate()) {
|
|
|
|
_updateRow->hideFast();
|
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-08-22 17:16:21 +00:00
|
|
|
|
|
|
|
if (cPlatform() == dbipWindows || cSupportTray()) {
|
2017-03-04 19:36:59 +00:00
|
|
|
auto workMode = Global::WorkMode().value();
|
|
|
|
addChildRow(_enableTrayIcon, marginSmall, lang(lng_settings_workmode_tray), SLOT(onEnableTrayIcon()), (workMode == dbiwmTrayOnly || workMode == dbiwmWindowAndTray));
|
2017-02-03 20:07:26 +00:00
|
|
|
if (cPlatform() == dbipWindows) {
|
2017-03-04 19:36:59 +00:00
|
|
|
addChildRow(_enableTaskbarIcon, marginLarge, lang(lng_settings_workmode_window), SLOT(onEnableTaskbarIcon()), (workMode == dbiwmWindowOnly || workMode == dbiwmWindowAndTray));
|
2017-02-03 10:17:40 +00:00
|
|
|
|
|
|
|
#ifndef OS_WIN_STORE
|
2017-02-03 20:07:26 +00:00
|
|
|
addChildRow(_autoStart, marginSmall, lang(lng_settings_auto_start), SLOT(onAutoStart()), cAutoStart());
|
|
|
|
addChildRow(_startMinimized, marginLarge, slidedPadding, lang(lng_settings_start_min), SLOT(onStartMinimized()), (cStartMinimized() && !Global::LocalPasscode()));
|
|
|
|
subscribe(Global::RefLocalPasscodeChanged(), [this] {
|
|
|
|
_startMinimized->entity()->setChecked(cStartMinimized() && !Global::LocalPasscode());
|
|
|
|
});
|
|
|
|
if (!cAutoStart()) {
|
|
|
|
_startMinimized->hideFast();
|
|
|
|
}
|
|
|
|
addChildRow(_addInSendTo, marginSmall, lang(lng_settings_add_sendto), SLOT(onAddInSendTo()), cSendToMenu());
|
2017-02-03 10:17:40 +00:00
|
|
|
#endif // OS_WIN_STORE
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
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 GeneralWidget::chooseCustomLang() {
|
|
|
|
auto filter = qsl("Language files (*.strings)");
|
|
|
|
auto title = qsl("Choose language .strings file");
|
2017-02-28 15:43:03 +00:00
|
|
|
FileDialog::GetOpenPath(title, filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
|
|
|
if (result.paths.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2017-02-28 15:43:03 +00:00
|
|
|
_testLanguage = QFileInfo(result.paths.front()).absoluteFilePath();
|
|
|
|
LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
|
|
|
if (loader.errors().isEmpty()) {
|
|
|
|
LangLoaderResult result = loader.found();
|
|
|
|
auto text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)),
|
|
|
|
save = result.value(lng_box_ok, langOriginal(lng_box_ok)),
|
|
|
|
cancel = result.value(lng_cancel, langOriginal(lng_cancel));
|
|
|
|
Ui::show(Box<ConfirmBox>(text, save, cancel, base::lambda_guarded(this, [this] {
|
|
|
|
cSetLangFile(_testLanguage);
|
|
|
|
cSetLang(languageTest);
|
|
|
|
Local::writeSettings();
|
|
|
|
onRestart();
|
|
|
|
})));
|
|
|
|
} else {
|
|
|
|
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()));
|
|
|
|
}
|
|
|
|
}));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralWidget::onChangeLanguage() {
|
|
|
|
if ((_changeLanguage->clickModifiers() & Qt::ShiftModifier) && (_changeLanguage->clickModifiers() & Qt::AltModifier)) {
|
|
|
|
chooseCustomLang();
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<LanguageBox>());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 17:52:05 +00:00
|
|
|
void GeneralWidget::onRestart() {
|
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
checkReadyUpdate();
|
2016-10-28 12:44:28 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
App::restart();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
void GeneralWidget::onUpdateAutomatically() {
|
2016-08-27 17:52:05 +00:00
|
|
|
cSetAutoUpdate(_updateAutomatically->checked());
|
|
|
|
Local::writeSettings();
|
2017-03-15 15:10:18 +00:00
|
|
|
_updateRow->toggleAnimated(cAutoUpdate());
|
2016-08-27 17:52:05 +00:00
|
|
|
if (cAutoUpdate()) {
|
|
|
|
Sandbox::startUpdateCheck();
|
|
|
|
} else {
|
|
|
|
Sandbox::stopUpdate();
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-08-22 17:16:21 +00:00
|
|
|
|
|
|
|
void GeneralWidget::onEnableTrayIcon() {
|
2016-08-31 20:06:52 +00:00
|
|
|
if ((!_enableTrayIcon->checked() || cPlatform() != dbipWindows) && _enableTaskbarIcon && !_enableTaskbarIcon->checked()) {
|
2016-08-22 17:16:21 +00:00
|
|
|
_enableTaskbarIcon->setChecked(true);
|
|
|
|
} else {
|
|
|
|
updateWorkmode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralWidget::onEnableTaskbarIcon() {
|
|
|
|
if (!_enableTrayIcon->checked() && !_enableTaskbarIcon->checked()) {
|
|
|
|
_enableTrayIcon->setChecked(true);
|
|
|
|
} else {
|
|
|
|
updateWorkmode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralWidget::updateWorkmode() {
|
2017-03-04 19:36:59 +00:00
|
|
|
auto newMode = (_enableTrayIcon->checked() && (!_enableTaskbarIcon || _enableTaskbarIcon->checked())) ? dbiwmWindowAndTray : (_enableTrayIcon->checked() ? dbiwmTrayOnly : dbiwmWindowOnly);
|
|
|
|
if (Global::WorkMode().value() != newMode && (newMode == dbiwmWindowAndTray || newMode == dbiwmTrayOnly)) {
|
2016-08-22 17:16:21 +00:00
|
|
|
cSetSeenTrayTooltip(false);
|
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
Global::RefWorkMode().set(newMode);
|
2016-08-22 17:16:21 +00:00
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
#if !defined OS_WIN_STORE
|
2016-08-22 17:16:21 +00:00
|
|
|
void GeneralWidget::onAutoStart() {
|
|
|
|
cSetAutoStart(_autoStart->checked());
|
|
|
|
if (cAutoStart()) {
|
|
|
|
psAutoStart(true);
|
|
|
|
Local::writeSettings();
|
|
|
|
} else {
|
|
|
|
psAutoStart(false);
|
|
|
|
if (_startMinimized->entity()->checked()) {
|
|
|
|
_startMinimized->entity()->setChecked(false);
|
|
|
|
} else {
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 15:10:18 +00:00
|
|
|
_startMinimized->toggleAnimated(cAutoStart());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralWidget::onStartMinimized() {
|
2017-01-01 16:45:20 +00:00
|
|
|
auto checked = _startMinimized->entity()->checked();
|
|
|
|
if (Global::LocalPasscode()) {
|
|
|
|
if (checked) {
|
|
|
|
_startMinimized->entity()->setChecked(false);
|
|
|
|
Ui::show(Box<InformBox>(lang(lng_error_start_minimized_passcoded)));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cStartMinimized() != checked) {
|
|
|
|
cSetStartMinimized(checked);
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
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 GeneralWidget::onAddInSendTo() {
|
|
|
|
cSetSendToMenu(_addInSendTo->checked());
|
|
|
|
psSendToMenu(_addInSendTo->checked());
|
|
|
|
Local::writeSettings();
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
2017-02-03 20:07:26 +00:00
|
|
|
#endif // !OS_WIN_STORE
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
} // namespace Settings
|