void GeneralWidget::onUpdateAutomatically() { cSetAutoUpdate(_updateAutomatically->checked()); Local::writeSettings(); _updateRow->toggleAnimated(cAutoUpdate()); if (cAutoUpdate()) { Sandbox::startUpdateCheck(); } else { Sandbox::stopUpdate(); } }
void GeneralWidget::onUpdateAutomatically() { cSetAutoUpdate(_updateAutomatically->checked()); Local::writeSettings(); _updateRow->toggle( cAutoUpdate(), anim::type::normal); Core::UpdateChecker checker; if (cAutoUpdate()) { checker.start(); } else { checker.stop(); } }
void UpdateStateRow::onCheck() { if (!cAutoUpdate()) return; setState(State::Check); cSetLastUpdateCheck(0); Sandbox::startUpdateCheck(); }
void GeneralWidget::refreshControls() { 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 addChildRow(_updateAutomatically, marginSub, lang(lng_settings_update_automatically), SLOT(onUpdateAutomatically()), cAutoUpdate()); style::margins marginLink(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip); addChildRow(_updateRow, marginLink, slidedPadding); connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart())); if (!cAutoUpdate()) { _updateRow->hideFast(); } #endif // !TDESKTOP_DISABLE_AUTOUPDATE if (cPlatform() == dbipWindows || cSupportTray()) { addChildRow(_enableTrayIcon, marginSmall, lang(lng_settings_workmode_tray), SLOT(onEnableTrayIcon()), (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray)); if (cPlatform() == dbipWindows) { addChildRow(_enableTaskbarIcon, marginLarge, lang(lng_settings_workmode_window), SLOT(onEnableTaskbarIcon()), (cWorkMode() == dbiwmWindowOnly || cWorkMode() == dbiwmWindowAndTray)); #ifndef OS_WIN_STORE 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()); #endif // OS_WIN_STORE } } }
void Application::startUpdateCheck(bool forceWait) { updateCheckTimer.stop(); if (updateRequestId || updateThread || updateReply || !cAutoUpdate()) return; int32 updateInSecs = cLastUpdateCheck() + 3600 + (rand() % 3600) - unixtime(); bool sendRequest = (updateInSecs <= 0 || updateInSecs > 7200); if (!sendRequest && !forceWait) { QDir updates(cWorkingDir() + "tupdates"); if (updates.exists()) { QFileInfoList list = updates.entryInfoList(QDir::Files); for (QFileInfoList::iterator i = list.begin(), e = list.end(); i != e; ++i) { if (QRegularExpression("^(tupdate|tmacupd|tlinuxupd|tlinux32upd)\\d+$", QRegularExpression::CaseInsensitiveOption).match(i->fileName()).hasMatch()) { sendRequest = true; } } } } if (cManyInstance() && !cDebug()) return; // only main instance is updating if (sendRequest) { QNetworkRequest checkVersion(cUpdateURL()); if (updateReply) updateReply->deleteLater(); App::setProxySettings(updateManager); updateReply = updateManager.get(checkVersion); connect(updateReply, SIGNAL(finished()), this, SLOT(updateGotCurrent())); connect(updateReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(updateFailedCurrent(QNetworkReply::NetworkError))); // updateRequestId = MTP::send(MTPhelp_GetAppUpdate(MTP_string(cApiDeviceModel()), MTP_string(cApiSystemVersion()), MTP_string(cApiAppVersion()), MTP_string(cApiLang())), rpcDone(&Application::onAppUpdate), rpcFail(&Application::onAppUpdateFail); emit updateChecking(); } else { updateCheckTimer.start((updateInSecs + 5) * 1000); } }
void SettingsInner::onAutoUpdate() { cSetAutoUpdate(!cAutoUpdate()); App::writeConfig(); resizeEvent(0); if (cAutoUpdate()) { App::app()->startUpdateCheck(); if (_updatingState == UpdatingNone) { _checkNow.show(); } else if (_updatingState == UpdatingReady) { _restartNow.show(); } } else { App::app()->stopUpdate(); _restartNow.hide(); _checkNow.hide(); } update(); }
void UpdateStateRow::onCheck() { if (!cAutoUpdate()) return; Core::UpdateChecker checker; setState(State::Check); cSetLastUpdateCheck(0); checker.start(); }
void GeneralWidget::onUpdateAutomatically() { cSetAutoUpdate(_updateAutomatically->checked()); Local::writeSettings(); if (cAutoUpdate()) { _updateRow->slideDown(); Sandbox::startUpdateCheck(); } else { _updateRow->slideUp(); Sandbox::stopUpdate(); } }
void SettingsInner::setDownloadProgress(qint64 ready, qint64 total) { qint64 readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024)); QString readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10); QString totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10); QString res = lang(lng_settings_downloading).replace(qsl("{ready}"), readyStr).replace(qsl("{total}"), totalStr); if (_newVersionDownload != res) { _newVersionDownload = res; if (cAutoUpdate()) { update(0, _restartNow.y() - 10, width(), _restartNow.height() + 20); } } }
void SettingsInner::setUpdatingState(UpdatingState state, bool force) { if (_updatingState != state || force) { _updatingState = state; if (cAutoUpdate()) { switch (state) { case UpdatingNone: case UpdatingLatest: _checkNow.show(); _restartNow.hide(); break; case UpdatingReady: _checkNow.hide(); _restartNow.show(); break; case UpdatingCheck: case UpdatingDownload: case UpdatingFail: _checkNow.hide(); _restartNow.hide(); break; } update(0, _restartNow.y() - 10, width(), _restartNow.height() + 20); } else { _checkNow.hide(); _restartNow.hide(); } } }
SettingsInner::SettingsInner(Settings *parent) : QWidget(parent), _self(App::self()), // profile _nameCache(_self ? _self->name : QString()), _phoneText(_self ? App::formatPhone(_self->phone) : QString()), _uploadPhoto(this, lang(lng_settings_upload), st::btnSetUpload), _cancelPhoto(this, lang(lng_cancel)), _nameOver(false), _photoOver(false), a_photo(0), // notifications _desktopNotify(this, lang(lng_settings_desktop_notify), cDesktopNotify()), _soundNotify(this, lang(lng_settings_sound_notify), cSoundNotify()), // general _autoUpdate(this, lang(lng_settings_auto_update), cAutoUpdate()), _checkNow(this, lang(lng_settings_check_now)), _restartNow(this, lang(lng_settings_update_now)), _workmodeTray(this, lang(lng_settings_workmode_tray), (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray)), _workmodeWindow(this, lang(lng_settings_workmode_window), (cWorkMode() == dbiwmWindowOnly || cWorkMode() == dbiwmWindowAndTray)), _autoStart(this, lang(lng_settings_auto_start), cAutoStart()), _startMinimized(this, lang(lng_settings_start_min), cStartMinimized()), _dpiAutoScale(this, lang(lng_settings_scale_auto).replace(qsl("{cur}"), scaleLabel(cScreenScale())), (cConfigScale() == dbisAuto)), _dpiSlider(this, st::dpiSlider, dbisScaleCount - 1, cEvalScale(cConfigScale()) - 1), _dpiWidth1(st::dpiFont1->m.width(scaleLabel(dbisOne))), _dpiWidth2(st::dpiFont2->m.width(scaleLabel(dbisOneAndQuarter))), _dpiWidth3(st::dpiFont3->m.width(scaleLabel(dbisOneAndHalf))), _dpiWidth4(st::dpiFont4->m.width(scaleLabel(dbisTwo))), // chat options _replaceEmojis(this, lang(lng_settings_replace_emojis), cReplaceEmojis()), _viewEmojis(this, lang(lng_settings_view_emojis)), _enterSend(this, qsl("send_key"), 0, lang(lng_settings_send_enter), !cCtrlEnter()), _ctrlEnterSend(this, qsl("send_key"), 1, lang((cPlatform() == dbipMac) ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter), cCtrlEnter()), _dontAskDownloadPath(this, lang(lng_download_path_dont_ask), !cAskDownloadPath()), _downloadPathWidth(st::linkFont->m.width(lang(lng_download_path_label))), _downloadPathEdit(this, cDownloadPath().isEmpty() ? lang(lng_download_path_temp) : st::linkFont->m.elidedText(QDir::toNativeSeparators(cDownloadPath()), Qt::ElideRight, st::setWidth - st::setVersionLeft - _downloadPathWidth)), _downloadPathClear(this, lang(lng_download_path_clear)), _tempDirClearingWidth(st::linkFont->m.width(lang(lng_download_path_clearing))), _tempDirClearedWidth(st::linkFont->m.width(lang(lng_download_path_cleared))), _tempDirClearFailedWidth(st::linkFont->m.width(lang(lng_download_path_clear_failed))), _catsAndDogs(this, lang(lng_settings_cats_and_dogs), cCatsAndDogs()), _scrollNotActive(this, lang(lng_settings_scroll_not_active), cScrollNotActive()), // advanced _connectionType(this, lang(lng_connection_auto)), _resetSessions(this, lang(lng_settings_reset)), _logOut(this, lang(lng_settings_logout), st::btnLogout), _resetDone(false) { if (_self) { _nameText.setText(st::setNameFont, _nameCache, _textNameOptions); PhotoData *selfPhoto = _self->photoId ? App::photo(_self->photoId) : 0; if (selfPhoto && selfPhoto->date) _photoLink = TextLinkPtr(new PhotoLink(selfPhoto)); MTP::send(MTPusers_GetFullUser(_self->inputUser), rpcDone(&SettingsInner::gotFullSelf)); connect(App::main(), SIGNAL(peerPhotoChanged(PeerData *)), this, SLOT(peerUpdated(PeerData *))); connect(App::main(), SIGNAL(peerNameChanged(PeerData *, const PeerData::Names &, const PeerData::NameFirstChars &)), this, SLOT(peerUpdated(PeerData *))); } // profile connect(&_uploadPhoto, SIGNAL(clicked()), this, SLOT(onUpdatePhoto())); connect(&_cancelPhoto, SIGNAL(clicked()), this, SLOT(onUpdatePhotoCancel())); connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUpdateDone(PeerId))); connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUpdateFail(PeerId))); // notifications connect(&_desktopNotify, SIGNAL(changed()), this, SLOT(onDesktopNotify())); connect(&_soundNotify, SIGNAL(changed()), this, SLOT(onSoundNotify())); // general connect(&_autoUpdate, SIGNAL(changed()), this, SLOT(onAutoUpdate())); connect(&_checkNow, SIGNAL(clicked()), this, SLOT(onCheckNow())); connect(&_restartNow, SIGNAL(clicked()), this, SLOT(onRestartNow())); connect(&_workmodeTray, SIGNAL(changed()), this, SLOT(onWorkmodeTray())); connect(&_workmodeWindow, SIGNAL(changed()), this, SLOT(onWorkmodeWindow())); _startMinimized.setDisabled(!_autoStart.checked()); connect(&_autoStart, SIGNAL(changed()), this, SLOT(onAutoStart())); connect(&_startMinimized, SIGNAL(changed()), this, SLOT(onStartMinimized())); connect(&_dpiAutoScale, SIGNAL(changed()), this, SLOT(onScaleAuto())); connect(&_dpiSlider, SIGNAL(changed(int32)), this, SLOT(onScaleChange())); _curVersionText = lang(lng_settings_current_version).replace(qsl("{version}"), QString::fromWCharArray(AppVersionStr)) + ' '; _curVersionWidth = st::linkFont->m.width(_curVersionText); _newVersionText = lang(lng_settings_update_ready) + ' '; _newVersionWidth = st::linkFont->m.width(_newVersionText); connect(App::app(), SIGNAL(updateChecking()), this, SLOT(onUpdateChecking())); connect(App::app(), SIGNAL(updateLatest()), this, SLOT(onUpdateLatest())); connect(App::app(), SIGNAL(updateDownloading(qint64,qint64)), this, SLOT(onUpdateDownloading(qint64,qint64))); connect(App::app(), SIGNAL(updateReady()), this, SLOT(onUpdateReady())); connect(App::app(), SIGNAL(updateFailed()), this, SLOT(onUpdateFailed())); // chat options connect(&_replaceEmojis, SIGNAL(changed()), this, SLOT(onReplaceEmojis())); connect(&_viewEmojis, SIGNAL(clicked()), this, SLOT(onViewEmojis())); connect(&_enterSend, SIGNAL(changed()), this, SLOT(onEnterSend())); connect(&_ctrlEnterSend, SIGNAL(changed()), this, SLOT(onCtrlEnterSend())); connect(&_dontAskDownloadPath, SIGNAL(changed()), this, SLOT(onDontAskDownloadPath())); connect(&_downloadPathEdit, SIGNAL(clicked()), this, SLOT(onDownloadPathEdit())); connect(&_downloadPathClear, SIGNAL(clicked()), this, SLOT(onDownloadPathClear())); switch (App::wnd()->tempDirState()) { case Window::TempDirEmpty: _tempDirClearState = TempDirEmpty; break; case Window::TempDirExists: _tempDirClearState = TempDirExists; break; case Window::TempDirRemoving: _tempDirClearState = TempDirClearing; break; } connect(App::wnd(), SIGNAL(tempDirCleared()), this, SLOT(onTempDirCleared())); connect(App::wnd(), SIGNAL(tempDirClearFailed()), this, SLOT(onTempDirClearFailed())); connect(&_catsAndDogs, SIGNAL(changed()), this, SLOT(onCatsAndDogs())); connect(&_scrollNotActive, SIGNAL(changed()), this, SLOT(onScrollNotActive())); // advanced connect(&_connectionType, SIGNAL(clicked()), this, SLOT(onConnectionType())); connect(&_resetSessions, SIGNAL(clicked()), this, SLOT(onResetSessions())); connect(&_logOut, SIGNAL(clicked()), this, SLOT(onLogout())); _connectionTypeText = lang(lng_connection_type) + ' '; _connectionTypeWidth = st::linkFont->m.width(_connectionTypeText); if (App::main()) { connect(App::main(), SIGNAL(peerUpdated(PeerData*)), this, SLOT(peerUpdated(PeerData*))); } updateOnlineDisplay(); switch (App::app()->updatingState()) { case Application::UpdatingDownload: setUpdatingState(UpdatingDownload, true); setDownloadProgress(App::app()->updatingReady(), App::app()->updatingSize()); break; case Application::UpdatingReady: setUpdatingState(UpdatingReady, true); break; default: setUpdatingState(UpdatingNone, true); break; } updateConnectionType(); setMouseTracking(true); }
void SettingsInner::onCheckNow() { if (!cAutoUpdate()) return; cSetLastUpdateCheck(0); App::app()->startUpdateCheck(); }
void SettingsInner::paintEvent(QPaintEvent *e) { QPainter p(this); p.setClipRect(e->rect()); int32 top = 0; if (_self) { // profile top += st::setTop; _nameText.drawElided(p, _uploadPhoto.x() + st::setNameLeft, top + st::setNameTop, _uploadPhoto.width() - st::setNameLeft); if (!_cancelPhoto.isHidden()) { p.setFont(st::linkFont->f); p.setPen(st::black->p); p.drawText(_uploadPhoto.x() + st::setPhoneLeft, _cancelPhoto.y() + st::linkFont->ascent, lang(lng_settings_uploading_photo)); } p.setFont(st::setPhoneFont->f); p.setPen(st::setPhoneColor->p); p.drawText(_uploadPhoto.x() + st::setPhoneLeft, top + st::setPhoneTop + st::setPhoneFont->ascent, _phoneText); if (_photoLink) { p.drawPixmap(_left, top, _self->photo->pix(st::setPhotoSize)); } else { if (a_photo.current() < 1) { p.drawPixmap(QPoint(_left, top), App::sprite(), st::setPhotoImg); } if (a_photo.current() > 0) { p.setOpacity(a_photo.current()); p.drawPixmap(QPoint(_left, top), App::sprite(), st::setOverPhotoImg); p.setOpacity(1); } } top += st::setPhotoSize; if (!_errorText.isEmpty()) { p.setFont(st::setErrFont->f); p.setPen(st::setErrColor->p); p.drawText(QRect(_uploadPhoto.x(), _uploadPhoto.y() + _uploadPhoto.height() + st::setLittleSkip, _uploadPhoto.width(), st::setErrFont->height), _errorText, style::al_center); } // notifications p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_notify)); top += st::setHeaderSkip; top += _desktopNotify.height() + st::setLittleSkip; top += _soundNotify.height(); } // general p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_general)); top += st::setHeaderSkip; top += _autoUpdate.height(); QString textToDraw; if (cAutoUpdate()) { switch (_updatingState) { case UpdatingNone: textToDraw = _curVersionText; break; case UpdatingCheck: textToDraw = lang(lng_settings_update_checking); break; case UpdatingLatest: textToDraw = lang(lng_settings_latest_installed); break; case UpdatingDownload: textToDraw = _newVersionDownload; break; case UpdatingReady: textToDraw = _newVersionText; break; case UpdatingFail: textToDraw = lang(lng_settings_update_fail); break; } } else { textToDraw = _curVersionText; } p.setFont(st::linkFont->f); p.setPen(st::setVersionColor->p); p.drawText(_left + st::setVersionLeft, top + st::setVersionTop + st::linkFont->ascent, textToDraw); top += st::setVersionHeight; if (cPlatform() == dbipWindows) { top += _workmodeTray.height() + st::setLittleSkip; top += _workmodeWindow.height() + st::setSectionSkip; top += _autoStart.height() + st::setLittleSkip; top += _startMinimized.height(); } if (!cRetina()) { p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_scale_label)); top += st::setHeaderSkip; top += _dpiAutoScale.height() + st::setLittleSkip; top += _dpiSlider.height() + st::dpiFont4->height; int32 sLeft = _dpiSlider.x() + _dpiWidth1 / 2, sWidth = _dpiSlider.width(); float64 sStep = (sWidth - _dpiWidth1 / 2 - _dpiWidth4 / 2) / float64(dbisScaleCount - 2); p.setFont(st::dpiFont1->f); p.setPen((scaleIs(dbisOne) ? st::dpiActive : st::dpiInactive)->p); p.drawText(sLeft + qRound(0 * sStep) - _dpiWidth1 / 2, top - (st::dpiFont4->height - st::dpiFont1->height) / 2 - st::dpiFont1->descent, scaleLabel(dbisOne)); p.setFont(st::dpiFont2->f); p.setPen((scaleIs(dbisOneAndQuarter) ? st::dpiActive : st::dpiInactive)->p); p.drawText(sLeft + qRound(1 * sStep) - _dpiWidth2 / 2, top - (st::dpiFont4->height - st::dpiFont2->height) / 2 - st::dpiFont2->descent, scaleLabel(dbisOneAndQuarter)); p.setFont(st::dpiFont3->f); p.setPen((scaleIs(dbisOneAndHalf) ? st::dpiActive : st::dpiInactive)->p); p.drawText(sLeft + qRound(2 * sStep) - _dpiWidth3 / 2, top - (st::dpiFont4->height - st::dpiFont3->height) / 2 - st::dpiFont3->descent, scaleLabel(dbisOneAndHalf)); p.setFont(st::dpiFont4->f); p.setPen((scaleIs(dbisTwo) ? st::dpiActive : st::dpiInactive)->p); p.drawText(sLeft + qRound(3 * sStep) - _dpiWidth4 / 2, top - (st::dpiFont4->height - st::dpiFont4->height) / 2 - st::dpiFont4->descent, scaleLabel(dbisTwo)); p.setFont(st::linkFont->f); } if (_self) { // chat options p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_chat)); top += st::setHeaderSkip; top += _replaceEmojis.height() + st::setSectionSkip; top += _enterSend.height() + st::setLittleSkip; top += _ctrlEnterSend.height() + st::setSectionSkip; top += _dontAskDownloadPath.height(); if (!cAskDownloadPath()) { top += st::setLittleSkip; p.setFont(st::linkFont->f); p.setPen(st::black->p); p.drawText(_left + st::setVersionLeft, top + st::linkFont->ascent, lang(lng_download_path_label)); if (cDownloadPath().isEmpty()) { QString clearText; int32 clearWidth = 0; switch (_tempDirClearState) { case TempDirClearing: clearText = lang(lng_download_path_clearing); clearWidth = _tempDirClearingWidth; break; case TempDirCleared: clearText = lang(lng_download_path_cleared); clearWidth = _tempDirClearedWidth; break; case TempDirClearFailed: clearText = lang(lng_download_path_clear_failed); clearWidth = _tempDirClearFailedWidth; break; } if (clearWidth) { p.drawText(_left + st::setWidth - clearWidth, top + st::linkFont->ascent, clearText); } } top += _downloadPathEdit.height(); } top += st::setSectionSkip; top += _catsAndDogs.height() + st::setLittleSkip; top += _scrollNotActive.height(); } // advanced p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_advanced)); top += st::setHeaderSkip; p.setFont(st::linkFont->f); p.setPen(st::black->p); p.drawText(_left + st::setHeaderLeft, _connectionType.y() + st::linkFont->ascent, _connectionTypeText); if (_self && _resetDone) { p.drawText(_resetSessions.x(), _resetSessions.y() + st::linkFont->ascent, lang(lng_settings_reset_done)); } }