1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00

Use string literals in Account class

This commit is contained in:
Joshua Goins 2023-09-16 21:22:20 -04:00
parent 8e9d1587f0
commit 83bed335db
2 changed files with 24 additions and 24 deletions

View file

@ -35,38 +35,38 @@ public:
enum class GameLicense { WindowsStandalone, WindowsSteam, macOS }; enum class GameLicense { WindowsStandalone, WindowsSteam, macOS };
Q_ENUM(GameLicense) Q_ENUM(GameLicense)
QString uuid() const; [[nodiscard]] QString uuid() const;
QString name() const; [[nodiscard]] QString name() const;
void setName(const QString &name); void setName(const QString &name);
int language() const; [[nodiscard]] int language() const;
void setLanguage(int value); void setLanguage(int value);
QString lodestoneId() const; [[nodiscard]] QString lodestoneId() const;
void setLodestoneId(const QString &id); void setLodestoneId(const QString &id);
QString avatarUrl() const; [[nodiscard]] QString avatarUrl() const;
bool isSapphire() const; [[nodiscard]] bool isSapphire() const;
void setIsSapphire(bool value); void setIsSapphire(bool value);
QString lobbyUrl() const; [[nodiscard]] QString lobbyUrl() const;
void setLobbyUrl(const QString &url); void setLobbyUrl(const QString &url);
bool rememberPassword() const; [[nodiscard]] bool rememberPassword() const;
void setRememberPassword(bool value); void setRememberPassword(bool value);
bool rememberOTP() const; [[nodiscard]] bool rememberOTP() const;
void setRememberOTP(bool value); void setRememberOTP(bool value);
bool useOTP() const; [[nodiscard]] bool useOTP() const;
void setUseOTP(bool value); void setUseOTP(bool value);
GameLicense license() const; [[nodiscard]] GameLicense license() const;
void setLicense(GameLicense license); void setLicense(GameLicense license);
bool isFreeTrial() const; [[nodiscard]] bool isFreeTrial() const;
void setIsFreeTrial(bool value); void setIsFreeTrial(bool value);
Q_INVOKABLE QString getPassword(); Q_INVOKABLE QString getPassword();
@ -74,7 +74,7 @@ public:
Q_INVOKABLE QString getOTP(); Q_INVOKABLE QString getOTP();
QDir getConfigDir() const; [[nodiscard]] QDir getConfigDir() const;
Q_SIGNALS: Q_SIGNALS:
void nameChanged(); void nameChanged();

View file

@ -173,17 +173,17 @@ void Account::setIsFreeTrial(const bool value)
QString Account::getPassword() QString Account::getPassword()
{ {
return getKeychainValue("password"); return getKeychainValue(QStringLiteral("password"));
} }
void Account::setPassword(const QString &password) void Account::setPassword(const QString &password)
{ {
setKeychainValue("password", password); setKeychainValue(QStringLiteral("password"), password);
} }
QString Account::getOTP() QString Account::getOTP()
{ {
auto otpSecret = getKeychainValue("otp-secret"); auto otpSecret = getKeychainValue(QStringLiteral("otp-secret"));
char *totp = get_totp(otpSecret.toStdString().c_str(), 6, 30, SHA1, nullptr); char *totp = get_totp(otpSecret.toStdString().c_str(), 6, 30, SHA1, nullptr);
QString totpStr(totp); QString totpStr(totp);
@ -195,7 +195,7 @@ QString Account::getOTP()
QDir Account::getConfigDir() const QDir Account::getConfigDir() const
{ {
const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QDir userDir = dataDir.absoluteFilePath("user"); const QDir userDir = dataDir.absoluteFilePath(QStringLiteral("user"));
return userDir.absoluteFilePath(m_key); return userDir.absoluteFilePath(m_key);
} }
@ -205,7 +205,7 @@ void Account::fetchAvatar()
return; return;
} }
const auto cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + "/avatars"; const auto cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars");
if (!QDir().exists(cacheLocation)) { if (!QDir().exists(cacheLocation)) {
QDir().mkpath(cacheLocation); QDir().mkpath(cacheLocation);
} }
@ -214,11 +214,11 @@ void Account::fetchAvatar()
if (!QFile(filename).exists()) { if (!QFile(filename).exists()) {
qDebug() << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from xivapi."; qDebug() << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from xivapi.";
QNetworkRequest request(QStringLiteral("https://xivapi.com/character/%1").arg(lodestoneId())); QNetworkRequest request(QStringLiteral("https://xivapi.com/character/%1").arg(lodestoneId()));
auto reply = m_launcher.mgr->get(request); const auto reply = m_launcher.mgr->get(request);
connect(reply, &QNetworkReply::finished, [this, filename, reply] { connect(reply, &QNetworkReply::finished, [this, filename, reply] {
auto document = QJsonDocument::fromJson(reply->readAll()); auto document = QJsonDocument::fromJson(reply->readAll());
if (document.isObject()) { if (document.isObject()) {
QNetworkRequest avatarRequest(document.object()["Character"].toObject()["Avatar"].toString()); const QNetworkRequest avatarRequest(document.object()[QLatin1String("Character")].toObject()[QLatin1String("Avatar")].toString());
auto avatarReply = m_launcher.mgr->get(avatarRequest); auto avatarReply = m_launcher.mgr->get(avatarRequest);
QObject::connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] { QObject::connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] {
QFile file(filename); QFile file(filename);
@ -239,9 +239,9 @@ void Account::fetchAvatar()
void Account::setKeychainValue(const QString &key, const QString &value) void Account::setKeychainValue(const QString &key, const QString &value)
{ {
auto job = new QKeychain::WritePasswordJob("Astra", this); auto job = new QKeychain::WritePasswordJob(QStringLiteral("Astra"), this);
job->setTextData(value); job->setTextData(value);
job->setKey(m_key + "-" + key); job->setKey(m_key + QStringLiteral("-") + key);
job->setInsecureFallback(m_launcher.isSteamDeck()); // The Steam Deck does not have secrets provider in Game Mode job->setInsecureFallback(m_launcher.isSteamDeck()); // The Steam Deck does not have secrets provider in Game Mode
job->start(); job->start();
} }
@ -250,8 +250,8 @@ QString Account::getKeychainValue(const QString &key)
{ {
auto loop = new QEventLoop(this); auto loop = new QEventLoop(this);
auto job = new QKeychain::ReadPasswordJob("Astra", this); auto job = new QKeychain::ReadPasswordJob(QStringLiteral("Astra"), this);
job->setKey(m_key + "-" + key); job->setKey(m_key + QStringLiteral("-") + key);
job->setInsecureFallback(m_launcher.isSteamDeck()); job->setInsecureFallback(m_launcher.isSteamDeck());
job->start(); job->start();