tdesktop/Telegram/SourceFiles/main/main_app_config.h

106 lines
2.9 KiB
C
Raw Normal View History

2019-08-01 14:50:24 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2019-11-27 09:45:23 +00:00
#include "mtproto/sender.h"
#include "base/algorithm.h"
2019-11-27 09:45:23 +00:00
namespace Ui {
struct ColorIndicesCompressed;
} // namespace Ui
2019-08-01 14:50:24 +00:00
namespace Main {
2019-11-27 09:45:23 +00:00
class Account;
2019-08-01 14:50:24 +00:00
class AppConfig final {
public:
2019-11-27 09:45:23 +00:00
explicit AppConfig(not_null<Account*> account);
~AppConfig();
2019-08-01 14:50:24 +00:00
void start();
2019-08-01 14:50:24 +00:00
template <typename Type>
2019-11-27 09:45:23 +00:00
[[nodiscard]] Type get(const QString &key, Type fallback) const {
2019-08-01 14:50:24 +00:00
if constexpr (std::is_same_v<Type, double>) {
return getDouble(key, fallback);
} else if constexpr (std::is_same_v<Type, int>) {
return int(base::SafeRound(getDouble(key, double(fallback))));
2019-11-27 09:45:23 +00:00
} else if constexpr (std::is_same_v<Type, QString>) {
return getString(key, fallback);
} else if constexpr (std::is_same_v<Type, std::vector<QString>>) {
return getStringArray(key, std::move(fallback));
} else if constexpr (std::is_same_v<Type, std::vector<int>>) {
return getIntArray(key, std::move(fallback));
} else if constexpr (std::is_same_v<
Type,
std::vector<std::map<QString, QString>>>) {
2020-07-09 17:38:26 +00:00
return getStringMapArray(key, std::move(fallback));
2020-03-18 10:07:11 +00:00
} else if constexpr (std::is_same_v<Type, bool>) {
return getBool(key, fallback);
2019-08-01 14:50:24 +00:00
}
}
2019-11-27 09:45:23 +00:00
[[nodiscard]] rpl::producer<> refreshed() const;
2020-07-03 16:53:24 +00:00
[[nodiscard]] rpl::producer<> value() const;
[[nodiscard]] bool suggestionCurrent(const QString &key) const;
[[nodiscard]] rpl::producer<> suggestionRequested(
const QString &key) const;
void dismissSuggestion(const QString &key);
2019-11-27 09:45:23 +00:00
[[nodiscard]] auto colorIndicesValue() const
-> rpl::producer<Ui::ColorIndicesCompressed>;
2019-08-01 14:50:24 +00:00
void refresh();
private:
2019-08-01 14:50:24 +00:00
void refreshDelayed();
void parseColorIndices();
2019-08-01 14:50:24 +00:00
2019-11-27 09:45:23 +00:00
template <typename Extractor>
[[nodiscard]] auto getValue(
const QString &key,
Extractor &&extractor) const;
2020-03-18 10:07:11 +00:00
[[nodiscard]] bool getBool(
const QString &key,
bool fallback) const;
2019-11-27 09:45:23 +00:00
[[nodiscard]] double getDouble(
const QString &key,
double fallback) const;
[[nodiscard]] QString getString(
const QString &key,
const QString &fallback) const;
[[nodiscard]] std::vector<QString> getStringArray(
const QString &key,
std::vector<QString> &&fallback) const;
2020-07-09 17:38:26 +00:00
[[nodiscard]] std::vector<std::map<QString, QString>> getStringMapArray(
const QString &key,
std::vector<std::map<QString, QString>> &&fallback) const;
[[nodiscard]] std::vector<int> getIntArray(
const QString &key,
std::vector<int> &&fallback) const;
2019-08-01 14:50:24 +00:00
2019-11-27 09:45:23 +00:00
const not_null<Account*> _account;
std::optional<MTP::Sender> _api;
2019-08-01 14:50:24 +00:00
mtpRequestId _requestId = 0;
2023-03-01 07:55:33 +00:00
int32 _hash = 0;
2019-08-01 14:50:24 +00:00
base::flat_map<QString, MTPJSONValue> _data;
2019-11-27 09:45:23 +00:00
rpl::event_stream<> _refreshed;
2020-07-03 16:53:24 +00:00
base::flat_set<QString> _dismissedSuggestions;
rpl::event_stream<> _colorIndicesChanged;
std::unique_ptr<Ui::ColorIndicesCompressed> _colorIndicesCurrent;
2019-11-27 09:45:23 +00:00
rpl::lifetime _lifetime;
2019-08-01 14:50:24 +00:00
};
} // namespace Main