diff src/gui/dialog/settings/services.cc @ 317:b1f4d1867ab1

services: VERY initial Kitsu support it only supports user authentication for now, but it's definitely a start.
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 04:07:10 -0400
parents 657fda1b9cac
children d928ec7b6a0d
line wrap: on
line diff
--- a/src/gui/dialog/settings/services.cc	Tue Jun 11 15:11:09 2024 -0400
+++ b/src/gui/dialog/settings/services.cc	Wed Jun 12 04:07:10 2024 -0400
@@ -4,6 +4,7 @@
 #include "gui/dialog/settings.h"
 #include "gui/translate/anime.h"
 #include "services/anilist.h"
+#include "services/kitsu.h"
 #include <QComboBox>
 #include <QGroupBox>
 #include <QLabel>
@@ -59,6 +60,71 @@
 	return result;
 }
 
+QWidget* SettingsPageServices::CreateKitsuPage() {
+	QWidget* result = new QWidget(this);
+	result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
+
+	QVBoxLayout* full_layout = new QVBoxLayout(result);
+
+	{
+		/* Account */
+		QGroupBox* group_box = new QGroupBox(tr("Account"), result);
+		group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+
+		QVBoxLayout* group_box_layout = new QVBoxLayout(group_box);
+
+		{
+			QWidget* credentials_grid = new QWidget(group_box);
+			QGridLayout* credentials_grid_layout = new QGridLayout(credentials_grid);
+
+			/* E-mail */
+			QLabel* email_label = new QLabel(tr("&E-mail"), credentials_grid);
+			QLineEdit* email = new QLineEdit(credentials_grid);
+			email_label->setBuddy(email);
+			credentials_grid_layout->addWidget(email_label, 0, 0);
+			credentials_grid_layout->addWidget(email, 1, 0);
+
+			QLabel* password_label = new QLabel(tr("&Password:"), credentials_grid);
+			QLineEdit* password = new QLineEdit(credentials_grid);
+			password->setEchoMode(QLineEdit::Password);
+			password_label->setBuddy(password);
+			credentials_grid_layout->addWidget(password_label, 0, 1);
+			credentials_grid_layout->addWidget(password, 1, 1);
+
+			{
+				QPushButton* auth_button = new QPushButton(credentials_grid);
+				connect(auth_button, &QPushButton::clicked, this, [email, password] {
+					Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), Strings::ToUtf8String(password->text()));
+				});
+				auth_button->setText(session.config.auth.kitsu.access_token.empty() ? tr("Authorize...")
+				                                                                    : tr("Re-authorize..."));
+				credentials_grid_layout->addWidget(auth_button, 1, 2);
+			}
+
+			credentials_grid_layout->setContentsMargins(0, 0, 0, 0);
+
+			group_box_layout->addWidget(credentials_grid);
+		}
+
+		{
+			/* Note on password storing */
+			QLabel* note_label = new QLabel(tr("Your e-mail and password are never stored by Minori and will only be used to authorize with Kitsu.\nFor more information, see <a href=\"https://kitsu.docs.apiary.io/#introduction/authentication\">Kitsu's API documentation</a>"), group_box);
+			note_label->setTextFormat(Qt::RichText);
+			note_label->setWordWrap(true);
+			note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
+			note_label->setOpenExternalLinks(true);
+			group_box_layout->addWidget(note_label);
+		}
+
+		full_layout->addWidget(group_box);
+	}
+
+	full_layout->setSpacing(10);
+	full_layout->addStretch();
+
+	return result;
+}
+
 QWidget* SettingsPageServices::CreateAniListPage() {
 	QWidget* result = new QWidget(this);
 	result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
@@ -93,6 +159,7 @@
 			QLabel* note_label =
 			    new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box);
 			note_label->setTextFormat(Qt::RichText);
+			note_label->setWordWrap(true);
 			note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
 			note_label->setOpenExternalLinks(true);
 			layout->addWidget(note_label);
@@ -114,5 +181,6 @@
 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) {
 	service = session.config.service;
 	AddTab(CreateMainPage(), tr("Main"));
+	AddTab(CreateKitsuPage(), tr("Kitsu"));
 	AddTab(CreateAniListPage(), tr("AniList"));
 }