tdesktop/Telegram/SourceFiles/main/main_app_config.h

68 lines
1.7 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"
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);
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);
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));
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;
2019-08-01 14:50:24 +00:00
void refresh();
private:
2019-08-01 14:50:24 +00:00
void refreshDelayed();
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;
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;
base::flat_map<QString, MTPJSONValue> _data;
2019-11-27 09:45:23 +00:00
rpl::event_stream<> _refreshed;
rpl::lifetime _lifetime;
2019-08-01 14:50:24 +00:00
};
} // namespace Main