mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 22:57:11 +02:00
Save Celsius/Fahrenheit in Settings.
This commit is contained in:
parent
6a8a85e395
commit
3eeb01be61
6 changed files with 61 additions and 27 deletions
|
@ -220,7 +220,7 @@ QByteArray Settings::serialize() const {
|
|||
+ Serialize::bytearraySize(ivPosition)
|
||||
+ Serialize::stringSize(noWarningExtensions)
|
||||
+ Serialize::stringSize(_customFontFamily)
|
||||
+ sizeof(qint32) * 2;
|
||||
+ sizeof(qint32) * 3;
|
||||
|
||||
auto result = QByteArray();
|
||||
result.reserve(size);
|
||||
|
@ -372,7 +372,8 @@ QByteArray Settings::serialize() const {
|
|||
qRound(_dialogsNoChatWidthRatio.current() * 1000000),
|
||||
0,
|
||||
1000000))
|
||||
<< qint32(_systemUnlockEnabled ? 1 : 0);
|
||||
<< qint32(_systemUnlockEnabled ? 1 : 0)
|
||||
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2);
|
||||
}
|
||||
|
||||
Ensures(result.size() == size);
|
||||
|
@ -493,6 +494,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
QByteArray ivPosition;
|
||||
QString customFontFamily = _customFontFamily;
|
||||
qint32 systemUnlockEnabled = _systemUnlockEnabled ? 1 : 0;
|
||||
qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2;
|
||||
|
||||
stream >> themesAccentColors;
|
||||
if (!stream.atEnd()) {
|
||||
|
@ -793,6 +795,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
if (!stream.atEnd()) {
|
||||
stream >> systemUnlockEnabled;
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream >> weatherInCelsius;
|
||||
}
|
||||
if (stream.status() != QDataStream::Ok) {
|
||||
LOG(("App Error: "
|
||||
"Bad data for Core::Settings::constructFromSerialized()"));
|
||||
|
@ -1001,6 +1006,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
}
|
||||
_customFontFamily = customFontFamily;
|
||||
_systemUnlockEnabled = (systemUnlockEnabled == 1);
|
||||
_weatherInCelsius = !weatherInCelsius
|
||||
? std::optional<bool>()
|
||||
: (weatherInCelsius == 1);
|
||||
}
|
||||
|
||||
QString Settings::getSoundPath(const QString &key) const {
|
||||
|
|
|
@ -891,6 +891,13 @@ public:
|
|||
_systemUnlockEnabled = enabled;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<bool> weatherInCelsius() const {
|
||||
return _weatherInCelsius;
|
||||
}
|
||||
void setWeatherInCelsius(bool value) {
|
||||
_weatherInCelsius = value;
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool ThirdColumnByDefault();
|
||||
[[nodiscard]] static float64 DefaultDialogsWidthRatio();
|
||||
|
||||
|
@ -1022,6 +1029,7 @@ private:
|
|||
WindowPosition _ivPosition;
|
||||
QString _customFontFamily;
|
||||
bool _systemUnlockEnabled = false;
|
||||
std::optional<bool> _weatherInCelsius;
|
||||
|
||||
bool _tabbedReplacedWithInfo = false; // per-window
|
||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "media/stories/media_stories_controller.h"
|
||||
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/power_save_blocker.h"
|
||||
#include "base/qt_signal_producer.h"
|
||||
#include "base/unixtime.h"
|
||||
|
@ -128,6 +129,13 @@ struct SameDayRange {
|
|||
int(base::SafeRound(asin * point.x() + acos * point.y())));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool ResolveWeatherInCelsius() {
|
||||
const auto saved = Core::App().settings().weatherInCelsius();
|
||||
return saved.value_or(!ranges::contains(
|
||||
std::array{ u"US"_q, u"BS"_q, u"KY"_q, u"LR"_q, u"BZ"_q },
|
||||
Platform::SystemCountry().toUpper()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class Controller::PhotoPlayback final {
|
||||
|
@ -284,7 +292,8 @@ Controller::Controller(not_null<Delegate*> delegate)
|
|||
, _slider(std::make_unique<Slider>(this))
|
||||
, _replyArea(std::make_unique<ReplyArea>(this))
|
||||
, _reactions(std::make_unique<Reactions>(this))
|
||||
, _recentViews(std::make_unique<RecentViews>(this)) {
|
||||
, _recentViews(std::make_unique<RecentViews>(this))
|
||||
, _weatherInCelsius(ResolveWeatherInCelsius()){
|
||||
initLayout();
|
||||
|
||||
using namespace rpl::mappers;
|
||||
|
@ -1272,16 +1281,16 @@ ClickHandlerPtr Controller::lookupAreaHandler(QPoint point) const {
|
|||
});
|
||||
}
|
||||
for (const auto &weather : _weatherAreas) {
|
||||
auto widget = _reactions->makeWeatherAreaWidget(weather);
|
||||
const auto raw = widget.get();
|
||||
_areas.push_back({
|
||||
.original = weather.area.geometry,
|
||||
.radiusOriginal = weather.area.radius,
|
||||
.rotation = weather.area.rotation,
|
||||
.handler = std::make_shared<LambdaClickHandler>([=] {
|
||||
raw->toggleMode();
|
||||
toggleWeatherMode();
|
||||
}),
|
||||
.view = std::move(widget),
|
||||
.view = _reactions->makeWeatherAreaWidget(
|
||||
weather,
|
||||
_weatherInCelsius.value()),
|
||||
});
|
||||
}
|
||||
rebuildActiveAreas(*layout);
|
||||
|
@ -1300,6 +1309,13 @@ ClickHandlerPtr Controller::lookupAreaHandler(QPoint point) const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Controller::toggleWeatherMode() const {
|
||||
const auto now = !_weatherInCelsius.current();
|
||||
Core::App().settings().setWeatherInCelsius(now);
|
||||
Core::App().saveSettingsDelayed();
|
||||
_weatherInCelsius = now;
|
||||
}
|
||||
|
||||
void Controller::maybeMarkAsRead(const Player::TrackState &state) {
|
||||
const auto length = state.length;
|
||||
const auto position = Player::IsStoppedAtEnd(state.state)
|
||||
|
|
|
@ -229,6 +229,7 @@ private:
|
|||
void updatePlayingAllowed();
|
||||
void setPlayingAllowed(bool allowed);
|
||||
void rebuildActiveAreas(const Layout &layout) const;
|
||||
void toggleWeatherMode() const;
|
||||
|
||||
void hideSiblings();
|
||||
void showSiblings(not_null<Main::Session*> session);
|
||||
|
@ -307,6 +308,7 @@ private:
|
|||
std::vector<Data::UrlArea> _urlAreas;
|
||||
std::vector<Data::WeatherArea> _weatherAreas;
|
||||
mutable std::vector<ActiveArea> _areas;
|
||||
mutable rpl::variable<bool> _weatherInCelsius;
|
||||
|
||||
std::vector<CachedSource> _cachedSourcesList;
|
||||
int _cachedSourceIndex = -1;
|
||||
|
|
|
@ -75,7 +75,6 @@ public:
|
|||
void setAreaGeometry(QRect geometry, float64 radius) override;
|
||||
void updateReactionsCount(int count) override;
|
||||
void playEffect() override;
|
||||
void toggleMode() override;
|
||||
bool contains(QPoint point) override;
|
||||
|
||||
private:
|
||||
|
@ -137,12 +136,12 @@ public:
|
|||
WeatherView(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session,
|
||||
const Data::WeatherArea &data);
|
||||
const Data::WeatherArea &data,
|
||||
rpl::producer<bool> weatherInCelsius);
|
||||
|
||||
void setAreaGeometry(QRect geometry, float64 radius) override;
|
||||
void updateReactionsCount(int count) override;
|
||||
void playEffect() override;
|
||||
void toggleMode() override;
|
||||
bool contains(QPoint point) override;
|
||||
|
||||
private:
|
||||
|
@ -349,10 +348,6 @@ void ReactionView::playEffect() {
|
|||
}
|
||||
}
|
||||
|
||||
void ReactionView::toggleMode() {
|
||||
Unexpected("ReactionView::toggleMode.");
|
||||
}
|
||||
|
||||
bool ReactionView::contains(QPoint point) {
|
||||
const auto circle = _apiGeometry;
|
||||
const auto radius = std::min(circle.width(), circle.height()) / 2;
|
||||
|
@ -537,7 +532,8 @@ void ReactionView::cacheBackground() {
|
|||
WeatherView::WeatherView(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session,
|
||||
const Data::WeatherArea &data)
|
||||
const Data::WeatherArea &data,
|
||||
rpl::producer<bool> weatherInCelsius)
|
||||
: RpWidget(parent)
|
||||
, _session(session)
|
||||
, _data(data)
|
||||
|
@ -546,6 +542,12 @@ WeatherView::WeatherView(
|
|||
watchForSticker();
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
show();
|
||||
|
||||
std::move(weatherInCelsius) | rpl::start_with_next([=](bool celsius) {
|
||||
_celsius = celsius;
|
||||
_background = {};
|
||||
update();
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void WeatherView::watchForSticker() {
|
||||
|
@ -565,7 +567,7 @@ void WeatherView::watchForSticker() {
|
|||
) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||
setStickerFrom(document);
|
||||
update();
|
||||
}, _lifetime);
|
||||
}, lifetime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -598,12 +600,6 @@ void WeatherView::playEffect() {
|
|||
Unexpected("WeatherView::playEffect.");
|
||||
}
|
||||
|
||||
void WeatherView::toggleMode() {
|
||||
_celsius = !_celsius;
|
||||
_background = {};
|
||||
update();
|
||||
}
|
||||
|
||||
bool WeatherView::contains(QPoint point) {
|
||||
const auto geometry = _rect.translated(pos()).toRect();
|
||||
const auto angle = -_data.area.rotation;
|
||||
|
@ -683,7 +679,7 @@ void WeatherView::setStickerFrom(not_null<DocumentData*> document) {
|
|||
}
|
||||
_sticker->setRepaintCallback([=] { update(); });
|
||||
update();
|
||||
}, _lifetime);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void WeatherView::cacheBackground() {
|
||||
|
@ -1087,12 +1083,15 @@ auto Reactions::makeSuggestedReactionWidget(
|
|||
reaction);
|
||||
}
|
||||
|
||||
auto Reactions::makeWeatherAreaWidget(const Data::WeatherArea &data)
|
||||
auto Reactions::makeWeatherAreaWidget(
|
||||
const Data::WeatherArea &data,
|
||||
rpl::producer<bool> weatherInCelsius)
|
||||
-> std::unique_ptr<StoryAreaView> {
|
||||
return std::make_unique<WeatherView>(
|
||||
_controller->wrap(),
|
||||
&_controller->uiShow()->session(),
|
||||
data);
|
||||
data,
|
||||
std::move(weatherInCelsius));
|
||||
}
|
||||
|
||||
void Reactions::setReplyFieldState(
|
||||
|
|
|
@ -49,7 +49,6 @@ public:
|
|||
virtual void setAreaGeometry(QRect geometry, float64 radius) = 0;
|
||||
virtual void updateReactionsCount(int count) = 0;
|
||||
virtual void playEffect() = 0;
|
||||
virtual void toggleMode() = 0;
|
||||
virtual bool contains(QPoint point) = 0;
|
||||
};
|
||||
|
||||
|
@ -83,7 +82,9 @@ public:
|
|||
[[nodiscard]] auto makeSuggestedReactionWidget(
|
||||
const Data::SuggestedReaction &reaction)
|
||||
-> std::unique_ptr<StoryAreaView>;
|
||||
[[nodiscard]] auto makeWeatherAreaWidget(const Data::WeatherArea &data)
|
||||
[[nodiscard]] auto makeWeatherAreaWidget(
|
||||
const Data::WeatherArea &data,
|
||||
rpl::producer<bool> weatherInCelsius)
|
||||
-> std::unique_ptr<StoryAreaView>;
|
||||
|
||||
void setReplyFieldState(
|
||||
|
|
Loading…
Add table
Reference in a new issue