GlosSIConfig: User configurable steamgridDB API key

Fuck this!
pull/192/head
Peter Repukat 2 years ago
parent 45bd68e595
commit 6ee8317f77

@ -164,7 +164,6 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="ExeImageProvider.h" /> <ClInclude Include="ExeImageProvider.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="steamgrid_api_keys.h" />
<ClInclude Include="UWPFetch.h" /> <ClInclude Include="UWPFetch.h" />
<ClInclude Include="WinEventFilter.h" /> <ClInclude Include="WinEventFilter.h" />
</ItemGroup> </ItemGroup>

@ -105,9 +105,6 @@
<ClInclude Include="ExeImageProvider.h"> <ClInclude Include="ExeImageProvider.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="steamgrid_api_keys.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="manifest.xml"> <Xml Include="manifest.xml">

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,0,2045006300001 FILEVERSION 0,1,1,002004500680
PRODUCTVERSION 0,1,0,2045006300001 PRODUCTVERSION 0,1,1,002004500680
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - Config" VALUE "FileDescription", "GlosSI - Config"
VALUE "FileVersion", "0.1.0.2-45-g63fdab1" VALUE "FileVersion", "0.1.1.0-2-g45bd68e"
VALUE "InternalName", "GlosSIConfig" VALUE "InternalName", "GlosSIConfig"
VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSIConfig.exe" VALUE "OriginalFilename", "GlosSIConfig.exe"
VALUE "ProductName", "GlosSI" VALUE "ProductName", "GlosSI"
VALUE "ProductVersion", "0.1.0.2-45-g63fdab1" VALUE "ProductVersion", "0.1.1.0-2-g45bd68e"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

@ -36,7 +36,6 @@ limitations under the License.
#include "ExeImageProvider.h" #include "ExeImageProvider.h"
#include "ExeImageProvider.h" #include "ExeImageProvider.h"
#include "../version.hpp" #include "../version.hpp"
#include "steamgrid_api_keys.h"
UIModel::UIModel() : QObject(nullptr) UIModel::UIModel() : QObject(nullptr)
{ {
@ -375,6 +374,7 @@ QVariantMap UIModel::getDefaultConf() const
{"version", 1}, {"version", 1},
{"extendedLogging", false}, {"extendedLogging", false},
{"snapshotNotify", false}, {"snapshotNotify", false},
{"steamgridApiKey", QJsonValue::Null},
{"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}}, {"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}},
{"devices", {"devices",
QJsonObject{ QJsonObject{
@ -489,8 +489,11 @@ void UIModel::loadSteamGridImages()
std::filesystem::path path = QCoreApplication::applicationDirPath().toStdWString(); std::filesystem::path path = QCoreApplication::applicationDirPath().toStdWString();
path /= "steamgrid.exe"; path /= "steamgrid.exe";
auto api_key = getDefaultConf().value("steamgridApiKey").toString();
steamgrid_output_.clear();
steamgrid_proc_.setProgram(path.string().c_str()); steamgrid_proc_.setProgram(path.string().c_str());
steamgrid_proc_.setArguments({"-nonsteamonly", "--onlymissingartwork", "--steamgriddb", steamgridb_key}); steamgrid_proc_.setArguments({"-nonsteamonly", "--onlymissingartwork", "--steamgriddb", api_key});
connect(&steamgrid_proc_, &QProcess::readyReadStandardOutput, this, &UIModel::onSteamGridReadReady); connect(&steamgrid_proc_, &QProcess::readyReadStandardOutput, this, &UIModel::onSteamGridReadReady);
steamgrid_proc_.start(); steamgrid_proc_.start();
steamgrid_proc_.write("\n"); steamgrid_proc_.write("\n");
@ -678,8 +681,12 @@ void UIModel::onAvailFilesResponse(QNetworkReply* reply)
void UIModel::onSteamGridReadReady() void UIModel::onSteamGridReadReady()
{ {
steamgrid_output_.push_back(QString::fromLocal8Bit(steamgrid_proc_.readAllStandardOutput())); const auto output = QString::fromLocal8Bit(steamgrid_proc_.readAllStandardOutput());
steamgrid_output_.push_back(output);
emit steamgridOutputChanged(); emit steamgridOutputChanged();
if (output.toLower().contains("token is missing or invalid")) {
steamgrid_proc_.kill();
}
} }
void UIModel::writeTarget(const QJsonObject& json, const QString& name) const void UIModel::writeTarget(const QJsonObject& json, const QString& name) const
@ -693,7 +700,10 @@ void UIModel::writeTarget(const QJsonObject& json, const QString& name) const
return; return;
} }
file.write(QString(QJsonDocument(json).toJson(QJsonDocument::Indented)).toStdString().data()); auto json_ob = QJsonDocument(json).object();
json_ob.remove("steamgridApiKey");
file.write(QString(QJsonDocument(json_ob).toJson(QJsonDocument::Indented)).toStdString().data());
file.close(); file.close();
} }

@ -29,6 +29,8 @@ CollapsiblePane {
property var shortcutInfo: ({}) property var shortcutInfo: ({})
readonly property bool isAppSettings: subTitle != ""
content: content:
Column { Column {
spacing: 16 spacing: 16

@ -81,6 +81,25 @@ Item {
config.snapshotNotify = checked config.snapshotNotify = checked
} }
} }
}
Row {
leftPadding: 12
Row {
spacing: 16
Label {
topPadding: 8
id: apiKeyLabel
font.bold: true
text: qsTr("SteamGridDB-API-Key")
}
FluentTextInput {
width: 128
id: apiKeyInput
placeholderText: qsTr("...")
text: config.steamgridApiKey
onTextChanged: config.steamgridApiKey = text
}
}
} }
} }
} }

@ -40,6 +40,7 @@ Dialog {
property real backdropOpacity: 1.0 property real backdropOpacity: 1.0
property bool loading: true property bool loading: true
property bool hasTokenError: false
onOpened: function() { onOpened: function() {
@ -80,25 +81,55 @@ Dialog {
font.bold: true font.bold: true
} }
BusyIndicator { Item {
id: busyIndicator id: topContentContainer
running: visible
anchors.top: titlelabel.bottom anchors.top: titlelabel.bottom
anchors.topMargin: 8 anchors.topMargin: 8
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
opacity: loading ? 1 : 0 anchors.left: parent.left
height: loading ? 72 : 0 anchors.right: parent.right
Behavior on opacity { height: loading || hasTokenError ? 72 : 0
NumberAnimation {
duration: 350 BusyIndicator {
easing.type: Easing.InOutQuad id: busyIndicator
} running: visible
} anchors.horizontalCenter: parent.horizontalCenter
visible: loading opacity: loading ? 1 : 0
height: loading ? 72 : 0
Behavior on opacity {
NumberAnimation {
duration: 350
easing.type: Easing.InOutQuad
}
}
visible: loading
}
Label {
id: tokenErrorInfo
anchors.horizontalCenter: parent.horizontalCenter
opacity: hasTokenError ? 1 : 0
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.Wrap
font.bold: true
color: "yellow"
textFormat: TextEdit.RichText
onLinkActivated: Qt.openUrlExternally(link)
Behavior on opacity {
NumberAnimation {
duration: 350
easing.type: Easing.InOutQuad
}
}
visible: hasTokenError
text: qsTr("Please go to <a href=\"https://www.steamgriddb.com/profile/preferences/api\">SteamGridDB</a> and gerenate a new API token. Then paste it into the settings dialog.")
}
} }
ListView { ListView {
anchors.top: busyIndicator.bottom anchors.top: topContentContainer.bottom
anchors.topMargin: 16 anchors.topMargin: 16
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 16 anchors.bottomMargin: 16
@ -110,9 +141,10 @@ Dialog {
model: uiModel.steamgridOutput model: uiModel.steamgridOutput
ScrollBar.vertical: ScrollBar { ScrollBar.vertical: ScrollBar {
} }
onCountChanged: { onCountChanged: function() {
listview.positionViewAtIndex(listview.count - 1, ListView.Visible) listview.positionViewAtIndex(listview.count - 1, ListView.Visible);
loading = !listview.model[listview.count - 1].includes("Press enter") hasTokenError = listview.model.some((l) => l.includes("missing or invalid"));
loading = !(listview.model.some((l) => l.includes("Press enter")) || hasTokenError);
} }
Behavior on opacity { Behavior on opacity {

Loading…
Cancel
Save