mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: settings overhaul
fix: use more translations
This commit is contained in:
parent
954b367d4f
commit
e21ccd6024
19 changed files with 237 additions and 140 deletions
|
@ -18,25 +18,34 @@ CustomLangPack *CustomLangPack::currentInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomLangPack::fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId) {
|
void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId) {
|
||||||
LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId));
|
LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId));
|
||||||
|
|
||||||
const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected() : MTP::ProxyData();
|
auto finalLangPackId = langPackId;
|
||||||
|
if (finalLangPackId == qsl("pt-br")) { // meh
|
||||||
|
finalLangPackId = qsl("pt");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected()
|
||||||
|
: MTP::ProxyData();
|
||||||
if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) {
|
if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) {
|
||||||
QNetworkProxy LocaleProxy = MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy));
|
QNetworkProxy LocaleProxy = MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy));
|
||||||
networkManager.setProxy(LocaleProxy);
|
networkManager.setProxy(LocaleProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
|
if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
|
||||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(langPackId));
|
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(
|
||||||
|
finalLangPackId));
|
||||||
} else {
|
} else {
|
||||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(needFallback ? langPackBaseId : langPackId));
|
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(
|
||||||
|
needFallback ? langPackBaseId : finalLangPackId));
|
||||||
}
|
}
|
||||||
_chkReply = networkManager.get(QNetworkRequest(url));
|
_chkReply = networkManager.get(QNetworkRequest(url));
|
||||||
connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError)));
|
connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError)));
|
||||||
connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
|
connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
|
||||||
LOG(("Fetching %1 lang pack...").arg(needFallback ? (langPackBaseId.isEmpty() ? langPackId : langPackBaseId) : langPackId));
|
LOG(("Fetching %1 lang pack...").arg(
|
||||||
|
needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomLangPack::fetchFinished() {
|
void CustomLangPack::fetchFinished() {
|
||||||
|
@ -51,8 +60,7 @@ void CustomLangPack::fetchFinished() {
|
||||||
needFallback = true;
|
needFallback = true;
|
||||||
_chkReply->disconnect();
|
_chkReply->disconnect();
|
||||||
fetchCustomLangPack("", langPackBaseId);
|
fetchCustomLangPack("", langPackBaseId);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
QByteArray result = _chkReply->readAll().trimmed();
|
QByteArray result = _chkReply->readAll().trimmed();
|
||||||
QJsonParseError error{};
|
QJsonParseError error{};
|
||||||
QJsonDocument str = QJsonDocument::fromJson(result, &error);
|
QJsonDocument str = QJsonDocument::fromJson(result, &error);
|
||||||
|
@ -92,7 +100,7 @@ void CustomLangPack::loadDefaultLangFile() {
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
QJsonDocument str = QJsonDocument::fromJson(file.readAll());
|
QJsonDocument str = QJsonDocument::fromJson(file.readAll());
|
||||||
QJsonObject json = str.object();
|
QJsonObject json = str.object();
|
||||||
for (const QString& key : json.keys()) {
|
for (const QString &key: json.keys()) {
|
||||||
Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8());
|
Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8());
|
||||||
}
|
}
|
||||||
Lang::GetInstance().updatePluralRules();
|
Lang::GetInstance().updatePluralRules();
|
||||||
|
@ -102,9 +110,9 @@ void CustomLangPack::loadDefaultLangFile() {
|
||||||
|
|
||||||
void CustomLangPack::parseLangFile(QJsonDocument str) {
|
void CustomLangPack::parseLangFile(QJsonDocument str) {
|
||||||
QJsonObject json = str.object();
|
QJsonObject json = str.object();
|
||||||
for (const QString& brokenKey : json.keys()) {
|
for (const QString &brokenKey: json.keys()) {
|
||||||
auto key = qsl("ayu_") + brokenKey;
|
auto key = qsl("ayu_") + brokenKey;
|
||||||
auto val = json.value(brokenKey).toString().toUtf8();
|
auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8();
|
||||||
|
|
||||||
Lang::GetInstance().resetValue(key.toUtf8());
|
Lang::GetInstance().resetValue(key.toUtf8());
|
||||||
Lang::GetInstance().applyValue(key.toUtf8(), val);
|
Lang::GetInstance().applyValue(key.toUtf8(), val);
|
||||||
|
|
|
@ -5,23 +5,31 @@
|
||||||
|
|
||||||
class CustomLangPack : public QObject {
|
class CustomLangPack : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_DISABLE_COPY(CustomLangPack)
|
Q_DISABLE_COPY(CustomLangPack)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CustomLangPack *currentInstance();
|
static CustomLangPack *currentInstance();
|
||||||
|
|
||||||
static void initInstance();
|
static void initInstance();
|
||||||
|
|
||||||
static CustomLangPack *instance;
|
static CustomLangPack *instance;
|
||||||
|
|
||||||
void fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId);
|
void fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId);
|
||||||
|
|
||||||
void loadDefaultLangFile();
|
void loadDefaultLangFile();
|
||||||
|
|
||||||
void parseLangFile(QJsonDocument str);
|
void parseLangFile(QJsonDocument str);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|
||||||
void fetchFinished();
|
void fetchFinished();
|
||||||
|
|
||||||
void fetchError(QNetworkReply::NetworkError e);
|
void fetchError(QNetworkReply::NetworkError e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CustomLangPack();
|
CustomLangPack();
|
||||||
|
|
||||||
~CustomLangPack() = default;
|
~CustomLangPack() = default;
|
||||||
|
|
||||||
QNetworkAccessManager networkManager;
|
QNetworkAccessManager networkManager;
|
||||||
|
|
|
@ -1,14 +1,57 @@
|
||||||
#include "ayu_settings.h"
|
#include "ayu_settings.h"
|
||||||
|
#include "rpl/lifetime.h"
|
||||||
|
|
||||||
namespace AyuSettings {
|
namespace AyuSettings {
|
||||||
const QString filename = "tdata/ayu_settings.json";
|
const QString filename = "tdata/ayu_settings.json";
|
||||||
const int latestMigration = 1;
|
|
||||||
std::optional<AyuGramSettings> settings = std::nullopt;
|
std::optional<AyuGramSettings> settings = std::nullopt;
|
||||||
|
|
||||||
AyuGramSettings &getInstance() {
|
rpl::variable<bool> sendReadPacketsReactive;
|
||||||
if (!settings.has_value()) {
|
rpl::variable<bool> sendOnlinePacketsReactive;
|
||||||
settings = std::optional(AyuGramSettings());
|
rpl::variable<bool> sendOfflinePacketAfterOnlineReactive;
|
||||||
|
rpl::variable<bool> sendUploadProgressReactive;
|
||||||
|
rpl::variable<bool> useScheduledMessagesReactive;
|
||||||
|
rpl::variable<bool> keepDeletedMessagesReactive;
|
||||||
|
rpl::variable<bool> keepMessagesHistoryReactive;
|
||||||
|
rpl::variable<QString> deletedMarkReactive;
|
||||||
|
rpl::variable<QString> editedMarkReactive;
|
||||||
|
rpl::variable<bool> ghostModeEnabled;
|
||||||
|
|
||||||
|
rpl::lifetime lifetime = rpl::lifetime();
|
||||||
|
|
||||||
|
void initialize() {
|
||||||
|
if (settings.has_value()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings = std::optional(AyuGramSettings());
|
||||||
|
|
||||||
|
sendReadPacketsReactive.value() | rpl::filter([=](bool val) {
|
||||||
|
return (val != settings->sendReadPackets);
|
||||||
|
}) | rpl::start_with_next([=](bool val) {
|
||||||
|
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets;
|
||||||
|
}, lifetime);
|
||||||
|
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) {
|
||||||
|
return (val != settings->sendOnlinePackets);
|
||||||
|
}) | rpl::start_with_next([=](bool val) {
|
||||||
|
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets;
|
||||||
|
}, lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void postinitialize() {
|
||||||
|
sendReadPacketsReactive = settings->sendReadPackets;
|
||||||
|
sendOnlinePacketsReactive = settings->sendOnlinePackets;
|
||||||
|
sendOfflinePacketAfterOnlineReactive = settings->sendOfflinePacketAfterOnline;
|
||||||
|
sendUploadProgressReactive = settings->sendUploadProgress;
|
||||||
|
useScheduledMessagesReactive = settings->useScheduledMessages;
|
||||||
|
keepDeletedMessagesReactive = settings->keepDeletedMessages;
|
||||||
|
keepMessagesHistoryReactive = settings->keepMessagesHistory;
|
||||||
|
deletedMarkReactive = settings->deletedMark;
|
||||||
|
editedMarkReactive = settings->editedMark;
|
||||||
|
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
AyuGramSettings &getInstance() {
|
||||||
|
initialize();
|
||||||
return settings.value();
|
return settings.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,23 +64,106 @@ namespace AyuSettings {
|
||||||
QByteArray json = file.readAll();
|
QByteArray json = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
if (!settings.has_value()) {
|
initialize();
|
||||||
settings = std::optional(AyuGramSettings());
|
|
||||||
}
|
|
||||||
settings->fromJson(json);
|
settings->fromJson(json);
|
||||||
|
postinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void save() {
|
void save() {
|
||||||
if (!settings.has_value()) {
|
initialize();
|
||||||
settings = std::optional(AyuGramSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
settings->migrationVersion = latestMigration;
|
|
||||||
QByteArray json = settings->toRawJson();
|
QByteArray json = settings->toRawJson();
|
||||||
|
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
file.write(json);
|
file.write(json);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
postinitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_sendReadPackets(bool val) {
|
||||||
|
sendReadPackets = val;
|
||||||
|
sendReadPacketsReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_sendOnlinePackets(bool val) {
|
||||||
|
sendOnlinePackets = val;
|
||||||
|
sendOnlinePacketsReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) {
|
||||||
|
sendOfflinePacketAfterOnline = val;
|
||||||
|
sendOfflinePacketAfterOnlineReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_sendUploadProgress(bool val) {
|
||||||
|
sendUploadProgress = val;
|
||||||
|
sendUploadProgressReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_useScheduledMessages(bool val) {
|
||||||
|
useScheduledMessages = val;
|
||||||
|
useScheduledMessagesReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_keepDeletedMessages(bool val) {
|
||||||
|
keepDeletedMessages = val;
|
||||||
|
keepDeletedMessagesReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_keepMessagesHistory(bool val) {
|
||||||
|
keepMessagesHistory = val;
|
||||||
|
keepMessagesHistoryReactive = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_deletedMark(QString val) {
|
||||||
|
deletedMark = std::move(val);
|
||||||
|
deletedMarkReactive = deletedMark;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_editedMark(QString val) {
|
||||||
|
editedMark = std::move(val);
|
||||||
|
editedMarkReactive = editedMark;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_sendReadPacketsReactive() {
|
||||||
|
return sendReadPacketsReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_sendOnlinePacketsReactive() {
|
||||||
|
return sendOnlinePacketsReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_sendOfflinePacketAfterOnlineReactive() {
|
||||||
|
return sendOfflinePacketAfterOnlineReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_sendUploadProgressReactive() {
|
||||||
|
return sendUploadProgressReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_useScheduledMessagesReactive() {
|
||||||
|
return useScheduledMessagesReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_keepDeletedMessagesReactive() {
|
||||||
|
return keepDeletedMessagesReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_keepMessagesHistoryReactive() {
|
||||||
|
return keepMessagesHistoryReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<QString> get_deletedMarkReactive() {
|
||||||
|
return deletedMarkReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<QString> get_editedMarkReactive() {
|
||||||
|
return editedMarkReactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::variable<bool> get_ghostModeEnabled() {
|
||||||
|
return ghostModeEnabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "rpl/producer.h"
|
||||||
|
|
||||||
#define QS_HAS_JSON
|
#define QS_HAS_JSON
|
||||||
|
|
||||||
#include <lang_auto.h>
|
#include "lang_auto.h"
|
||||||
#include "qserializer.h"
|
#include "qserializer.h"
|
||||||
|
|
||||||
namespace AyuSettings {
|
namespace AyuSettings {
|
||||||
|
@ -11,8 +13,6 @@ namespace AyuSettings {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AyuGramSettings() {
|
AyuGramSettings() {
|
||||||
migrationVersion = 0;
|
|
||||||
|
|
||||||
sendReadPackets = true;
|
sendReadPackets = true;
|
||||||
sendOnlinePackets = true;
|
sendOnlinePackets = true;
|
||||||
sendOfflinePacketAfterOnline = false;
|
sendOfflinePacketAfterOnline = false;
|
||||||
|
@ -22,13 +22,10 @@ namespace AyuSettings {
|
||||||
keepMessagesHistory = false;
|
keepMessagesHistory = false;
|
||||||
deletedMark = "🧹";
|
deletedMark = "🧹";
|
||||||
editedMark = tr::lng_edited(tr::now);
|
editedMark = tr::lng_edited(tr::now);
|
||||||
ghostMode = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QS_SERIALIZABLE
|
QS_SERIALIZABLE
|
||||||
|
|
||||||
QS_FIELD(int, migrationVersion)
|
|
||||||
|
|
||||||
QS_FIELD(bool, sendReadPackets)
|
QS_FIELD(bool, sendReadPackets)
|
||||||
|
|
||||||
QS_FIELD(bool, sendOnlinePackets)
|
QS_FIELD(bool, sendOnlinePackets)
|
||||||
|
@ -47,52 +44,16 @@ namespace AyuSettings {
|
||||||
|
|
||||||
QS_FIELD(QString, editedMark)
|
QS_FIELD(QString, editedMark)
|
||||||
|
|
||||||
QS_FIELD(bool, ghostMode)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_migrationVersion(int val) {
|
void set_sendReadPackets(bool val);
|
||||||
migrationVersion = val;
|
void set_sendOnlinePackets(bool val);
|
||||||
}
|
void set_sendOfflinePacketAfterOnline(bool val);
|
||||||
|
void set_sendUploadProgress(bool val);
|
||||||
void set_sendReadPackets(bool val) {
|
void set_useScheduledMessages(bool val);
|
||||||
sendReadPackets = val;
|
void set_keepDeletedMessages(bool val);
|
||||||
}
|
void set_keepMessagesHistory(bool val);
|
||||||
|
void set_deletedMark(QString val);
|
||||||
void set_sendOnlinePackets(bool val) {
|
void set_editedMark(QString val);
|
||||||
sendOnlinePackets = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_sendOfflinePacketAfterOnline(bool val) {
|
|
||||||
sendOfflinePacketAfterOnline = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_sendUploadProgress(bool val) {
|
|
||||||
sendUploadProgress = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_useScheduledMessages(bool val) {
|
|
||||||
useScheduledMessages = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_keepDeletedMessages(bool val) {
|
|
||||||
keepDeletedMessages = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_keepMessagesHistory(bool val) {
|
|
||||||
keepMessagesHistory = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_deletedMark(QString val) {
|
|
||||||
deletedMark = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_editedMark(QString val) {
|
|
||||||
editedMark = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_ghostMode(bool val) {
|
|
||||||
ghostMode = val;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AyuGramSettings &getInstance();
|
AyuGramSettings &getInstance();
|
||||||
|
@ -100,4 +61,17 @@ namespace AyuSettings {
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
rpl::variable<bool> get_sendReadPacketsReactive();
|
||||||
|
rpl::variable<bool> get_sendOnlinePacketsReactive();
|
||||||
|
rpl::variable<bool> get_sendOfflinePacketAfterOnlineReactive();
|
||||||
|
rpl::variable<bool> get_sendUploadProgressReactive();
|
||||||
|
rpl::variable<bool> get_useScheduledMessagesReactive();
|
||||||
|
rpl::variable<bool> get_keepDeletedMessagesReactive();
|
||||||
|
rpl::variable<bool> get_keepMessagesHistoryReactive();
|
||||||
|
rpl::variable<QString> get_deletedMarkReactive();
|
||||||
|
rpl::variable<QString> get_editedMarkReactive();
|
||||||
|
|
||||||
|
// computed fields
|
||||||
|
rpl::variable<bool> get_ghostModeEnabled();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace AyuState {
|
||||||
|
|
||||||
AyuStateVariable allowSendReadPacket;
|
AyuStateVariable allowSendReadPacket;
|
||||||
|
|
||||||
bool processVariable(AyuStateVariable& variable) {
|
bool processVariable(AyuStateVariable &variable) {
|
||||||
if (variable.resetAfter == -1) {
|
if (variable.resetAfter == -1) {
|
||||||
return variable.val;
|
return variable.val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace AyuUi {
|
namespace AyuUi {
|
||||||
ConfirmationBox::ConfirmationBox(
|
ConfirmationBox::ConfirmationBox(
|
||||||
QWidget*,
|
QWidget *,
|
||||||
not_null<Window::SessionController *> controller) : _controller(controller) {
|
not_null<Window::SessionController *> controller) : _controller(controller) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,14 @@
|
||||||
namespace AyuUi {
|
namespace AyuUi {
|
||||||
class ConfirmationBox : public Ui::BoxContent {
|
class ConfirmationBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
ConfirmationBox(QWidget*, not_null<Window::SessionController *> controller);
|
ConfirmationBox(QWidget *, not_null<Window::SessionController *> controller);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReadAllPeers();
|
void ReadAllPeers();
|
||||||
not_null<Window::SessionController*> _controller;
|
|
||||||
|
not_null<Window::SessionController *> _controller;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -75,8 +75,8 @@ void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
||||||
void EditDeletedMarkBox::save() {
|
void EditDeletedMarkBox::save() {
|
||||||
const auto settings = &AyuSettings::getInstance();
|
const auto settings = &AyuSettings::getInstance();
|
||||||
settings->deletedMark = _text->getLastText();
|
settings->set_deletedMark(_text->getLastText());
|
||||||
Local::writeSettings();
|
AyuSettings::save();
|
||||||
|
|
||||||
closeBox();
|
closeBox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,18 @@
|
||||||
|
|
||||||
class EditDeletedMarkBox : public Ui::BoxContent {
|
class EditDeletedMarkBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
EditDeletedMarkBox(QWidget*);
|
EditDeletedMarkBox(QWidget *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setInnerFocus() override;
|
void setInnerFocus() override;
|
||||||
|
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void submit();
|
void submit();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
object_ptr<Ui::InputField> _text;
|
object_ptr<Ui::InputField> _text;
|
||||||
|
|
|
@ -31,7 +31,6 @@ EditEditedMarkBox::EditEditedMarkBox(QWidget *) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EditEditedMarkBox::prepare() {
|
void EditEditedMarkBox::prepare() {
|
||||||
const auto defaultEditedMark = tr::lng_edited(tr::now);
|
const auto defaultEditedMark = tr::lng_edited(tr::now);
|
||||||
auto newHeight = st::contactPadding.top() + _text->height();
|
auto newHeight = st::contactPadding.top() + _text->height();
|
||||||
|
@ -78,8 +77,8 @@ void EditEditedMarkBox::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
||||||
void EditEditedMarkBox::save() {
|
void EditEditedMarkBox::save() {
|
||||||
const auto settings = &AyuSettings::getInstance();
|
const auto settings = &AyuSettings::getInstance();
|
||||||
settings->editedMark = _text->getLastText();
|
settings->set_editedMark(_text->getLastText());
|
||||||
Local::writeSettings();
|
AyuSettings::save();
|
||||||
|
|
||||||
closeBox();
|
closeBox();
|
||||||
}
|
}
|
|
@ -6,16 +6,18 @@
|
||||||
|
|
||||||
class EditEditedMarkBox : public Ui::BoxContent {
|
class EditEditedMarkBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
EditEditedMarkBox(QWidget*);
|
EditEditedMarkBox(QWidget *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setInnerFocus() override;
|
void setInnerFocus() override;
|
||||||
|
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void submit();
|
void submit();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
object_ptr<Ui::InputField> _text;
|
object_ptr<Ui::InputField> _text;
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace AyuUi {
|
||||||
|
|
||||||
void AyuPopupMenu::addHistoryAction(HistoryItem *item) {
|
void AyuPopupMenu::addHistoryAction(HistoryItem *item) {
|
||||||
if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) {
|
if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) {
|
||||||
_ayuSubMenu->addAction(QString("History"), [=] {
|
_ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=] {
|
||||||
auto box = Box<MessageHistoryBox>(item);
|
auto box = Box<MessageHistoryBox>(item);
|
||||||
Ui::show(std::move(box));
|
Ui::show(std::move(box));
|
||||||
}, &st::menuIconInfo);
|
}, &st::menuIconInfo);
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace AyuUi {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHistoryBox::prepare() {
|
void MessageHistoryBox::prepare() {
|
||||||
setTitle(rpl::single(QString("Message history")));
|
setTitle(tr::ayu_EditsHistoryTitle());
|
||||||
|
|
||||||
// setDimensionsToContent(st::boxWideWidth, _content);
|
// setDimensionsToContent(st::boxWideWidth, _content);
|
||||||
setDimensions(st::boxWideWidth, 900);
|
setDimensions(st::boxWideWidth, 900);
|
||||||
|
@ -53,7 +53,7 @@ namespace AyuUi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& message : messages) {
|
for (const auto &message: messages) {
|
||||||
AddSkip(_content);
|
AddSkip(_content);
|
||||||
AddDividerText(_content, rpl::single(QString::fromStdString(message.text)));
|
AddDividerText(_content, rpl::single(QString::fromStdString(message.text)));
|
||||||
AddSkip(_content);
|
AddSkip(_content);
|
||||||
|
|
|
@ -6,12 +6,16 @@
|
||||||
namespace AyuUi {
|
namespace AyuUi {
|
||||||
class MessageHistoryBox : public Ui::BoxContent {
|
class MessageHistoryBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
MessageHistoryBox(QWidget*, HistoryItem *item);
|
MessageHistoryBox(QWidget *, HistoryItem *item);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupControls();
|
void setupControls();
|
||||||
|
|
||||||
void addEditedMessagesToLayout(HistoryItem *item);
|
void addEditedMessagesToLayout(HistoryItem *item);
|
||||||
|
|
||||||
object_ptr<Ui::VerticalLayout> _content;
|
object_ptr<Ui::VerticalLayout> _content;
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace AyuDatabase {
|
||||||
c(&EditedMessage::userId) == userId and
|
c(&EditedMessage::userId) == userId and
|
||||||
c(&EditedMessage::dialogId) == dialogId and
|
c(&EditedMessage::dialogId) == dialogId and
|
||||||
c(&EditedMessage::messageId) == messageId)
|
c(&EditedMessage::messageId) == messageId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EditedMessage> getEditedMessages(HistoryItem *item) {
|
std::vector<EditedMessage> getEditedMessages(HistoryItem *item) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace AyuDatabase {
|
||||||
long userId,
|
long userId,
|
||||||
long dialogId,
|
long dialogId,
|
||||||
long messageId,
|
long messageId,
|
||||||
const QString& text,
|
const QString &text,
|
||||||
bool isDocument,
|
bool isDocument,
|
||||||
QString path,
|
QString path,
|
||||||
long date);
|
long date);
|
||||||
|
|
|
@ -35,8 +35,7 @@ namespace Settings {
|
||||||
setupContent(controller);
|
setupContent(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container,
|
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container) {
|
||||||
not_null<Window::SessionController *> controller) {
|
|
||||||
auto settings = &AyuSettings::getInstance();
|
auto settings = &AyuSettings::getInstance();
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
|
@ -150,41 +149,27 @@ namespace Settings {
|
||||||
|
|
||||||
AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
|
AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
|
||||||
|
|
||||||
auto currentDeletedMark = lifetime().make_state<rpl::variable<QString>>();
|
|
||||||
|
|
||||||
auto btn = AddButtonWithLabel(
|
auto btn = AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
tr::ayu_DeletedMarkText(),
|
tr::ayu_DeletedMarkText(),
|
||||||
currentDeletedMark->changes(),
|
AyuSettings::get_deletedMarkReactive().value(),
|
||||||
st::settingsButtonNoIcon
|
st::settingsButtonNoIcon
|
||||||
);
|
);
|
||||||
btn->addClickHandler([=]() {
|
btn->addClickHandler([=]() {
|
||||||
auto box = Box<EditDeletedMarkBox>();
|
auto box = Box<EditDeletedMarkBox>();
|
||||||
box->boxClosing() | rpl::start_with_next([=]() {
|
|
||||||
*currentDeletedMark = settings->deletedMark;
|
|
||||||
}, container->lifetime());
|
|
||||||
|
|
||||||
Ui::show(std::move(box));
|
Ui::show(std::move(box));
|
||||||
});
|
});
|
||||||
*currentDeletedMark = settings->deletedMark;
|
|
||||||
|
|
||||||
auto currentEditedMark = lifetime().make_state<rpl::variable<QString>>();
|
|
||||||
|
|
||||||
auto btn2 = AddButtonWithLabel(
|
auto btn2 = AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
rpl::single(QString("Edited mark")),
|
rpl::single(QString("Edited mark")),
|
||||||
currentEditedMark->changes(),
|
AyuSettings::get_editedMarkReactive().value(),
|
||||||
st::settingsButtonNoIcon
|
st::settingsButtonNoIcon
|
||||||
);
|
);
|
||||||
btn2->addClickHandler([=]() {
|
btn2->addClickHandler([=]() {
|
||||||
auto box = Box<EditEditedMarkBox>();
|
auto box = Box<EditEditedMarkBox>();
|
||||||
box->boxClosing() | rpl::start_with_next([=]() {
|
|
||||||
*currentEditedMark = settings->editedMark;
|
|
||||||
}, container->lifetime());
|
|
||||||
|
|
||||||
Ui::show(std::move(box));
|
Ui::show(std::move(box));
|
||||||
});
|
});
|
||||||
*currentEditedMark = settings->editedMark;
|
|
||||||
|
|
||||||
AddDividerText(container, tr::ayu_SettingsWatermark());
|
AddDividerText(container, tr::ayu_SettingsWatermark());
|
||||||
}
|
}
|
||||||
|
@ -192,7 +177,7 @@ namespace Settings {
|
||||||
void Ayu::setupContent(not_null<Window::SessionController *> controller) {
|
void Ayu::setupContent(not_null<Window::SessionController *> controller) {
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||||
|
|
||||||
SetupAyuGramSettings(content, controller);
|
SetupAyuGramSettings(content);
|
||||||
|
|
||||||
Ui::ResizeFitChild(this, content);
|
Ui::ResizeFitChild(this, content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
/*
|
|
||||||
This file is part of 64Gram Desktop,
|
|
||||||
the unofficial app based on Telegram Desktop.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/TDesktop-x64/tdesktop/blob/dev/LEGAL
|
|
||||||
*/
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
@ -12,21 +5,21 @@ https://github.com/TDesktop-x64/tdesktop/blob/dev/LEGAL
|
||||||
class BoxContent;
|
class BoxContent;
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
class Controller;
|
class Controller;
|
||||||
class SessionController;
|
|
||||||
|
class SessionController;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
class Ayu : public Section<Ayu> {
|
class Ayu : public Section<Ayu> {
|
||||||
public:
|
public:
|
||||||
Ayu(
|
Ayu(QWidget *parent, not_null<Window::SessionController *> controller);
|
||||||
QWidget *parent,
|
|
||||||
not_null<Window::SessionController *> controller);
|
|
||||||
[[nodiscard]] rpl::producer<QString> title() override;
|
[[nodiscard]] rpl::producer<QString> title() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> null);
|
void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container);
|
||||||
void setupContent(not_null<Window::SessionController *> controller);
|
void setupContent(not_null<Window::SessionController *> controller);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -843,28 +843,21 @@ void MainMenu::setupMenu() {
|
||||||
toggle);
|
toggle);
|
||||||
}, _nightThemeToggle->lifetime());
|
}, _nightThemeToggle->lifetime());
|
||||||
|
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
_ghostModeToggle = addAction(
|
_ghostModeToggle = addAction(
|
||||||
rpl::single(QString("Ghost Mode")),
|
rpl::single(QString("Ghost Mode")),
|
||||||
{ &st::menuIconFake, kIconPurple }
|
{ &st::menuIconFake, kIconPurple }
|
||||||
)->toggleOn(rpl::single((&AyuSettings::getInstance())->ghostMode));
|
)->toggleOn(AyuSettings::get_ghostModeEnabled().value());
|
||||||
|
|
||||||
_ghostModeToggle->toggledChanges(
|
_ghostModeToggle->toggledChanges(
|
||||||
) | rpl::filter([=](bool ghostMode) {
|
) | rpl::start_with_next([=](bool ghostMode) {
|
||||||
const auto settings = &AyuSettings::getInstance();
|
|
||||||
return (ghostMode != settings->ghostMode);
|
|
||||||
}) | rpl::start_with_next([=](bool ghostMode) {
|
|
||||||
const auto settings = &AyuSettings::getInstance();
|
|
||||||
settings->set_ghostMode(ghostMode);
|
|
||||||
|
|
||||||
settings->set_sendReadPackets(!ghostMode);
|
settings->set_sendReadPackets(!ghostMode);
|
||||||
settings->set_sendOnlinePackets(!ghostMode);
|
settings->set_sendOnlinePackets(!ghostMode);
|
||||||
settings->set_sendOfflinePacketAfterOnline(ghostMode);
|
|
||||||
settings->set_sendUploadProgress(!ghostMode);
|
settings->set_sendUploadProgress(!ghostMode);
|
||||||
settings->set_keepDeletedMessages(ghostMode);
|
|
||||||
settings->set_keepMessagesHistory(ghostMode);
|
settings->set_sendOfflinePacketAfterOnline(ghostMode);
|
||||||
|
|
||||||
AyuSettings::save();
|
AyuSettings::save();
|
||||||
|
|
||||||
}, _ghostModeToggle->lifetime());
|
}, _ghostModeToggle->lifetime());
|
||||||
|
|
||||||
Core::App().settings().systemDarkModeValue(
|
Core::App().settings().systemDarkModeValue(
|
||||||
|
|
Loading…
Add table
Reference in a new issue