comparison 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
comparison
equal deleted inserted replaced
316:180714442770 317:b1f4d1867ab1
2 #include "core/session.h" 2 #include "core/session.h"
3 #include "core/strings.h" 3 #include "core/strings.h"
4 #include "gui/dialog/settings.h" 4 #include "gui/dialog/settings.h"
5 #include "gui/translate/anime.h" 5 #include "gui/translate/anime.h"
6 #include "services/anilist.h" 6 #include "services/anilist.h"
7 #include "services/kitsu.h"
7 #include <QComboBox> 8 #include <QComboBox>
8 #include <QGroupBox> 9 #include <QGroupBox>
9 #include <QLabel> 10 #include <QLabel>
10 #include <QLineEdit> 11 #include <QLineEdit>
11 #include <QPushButton> 12 #include <QPushButton>
57 full_layout->addStretch(); 58 full_layout->addStretch();
58 59
59 return result; 60 return result;
60 } 61 }
61 62
63 QWidget* SettingsPageServices::CreateKitsuPage() {
64 QWidget* result = new QWidget(this);
65 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
66
67 QVBoxLayout* full_layout = new QVBoxLayout(result);
68
69 {
70 /* Account */
71 QGroupBox* group_box = new QGroupBox(tr("Account"), result);
72 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
73
74 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box);
75
76 {
77 QWidget* credentials_grid = new QWidget(group_box);
78 QGridLayout* credentials_grid_layout = new QGridLayout(credentials_grid);
79
80 /* E-mail */
81 QLabel* email_label = new QLabel(tr("&E-mail"), credentials_grid);
82 QLineEdit* email = new QLineEdit(credentials_grid);
83 email_label->setBuddy(email);
84 credentials_grid_layout->addWidget(email_label, 0, 0);
85 credentials_grid_layout->addWidget(email, 1, 0);
86
87 QLabel* password_label = new QLabel(tr("&Password:"), credentials_grid);
88 QLineEdit* password = new QLineEdit(credentials_grid);
89 password->setEchoMode(QLineEdit::Password);
90 password_label->setBuddy(password);
91 credentials_grid_layout->addWidget(password_label, 0, 1);
92 credentials_grid_layout->addWidget(password, 1, 1);
93
94 {
95 QPushButton* auth_button = new QPushButton(credentials_grid);
96 connect(auth_button, &QPushButton::clicked, this, [email, password] {
97 Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), Strings::ToUtf8String(password->text()));
98 });
99 auth_button->setText(session.config.auth.kitsu.access_token.empty() ? tr("Authorize...")
100 : tr("Re-authorize..."));
101 credentials_grid_layout->addWidget(auth_button, 1, 2);
102 }
103
104 credentials_grid_layout->setContentsMargins(0, 0, 0, 0);
105
106 group_box_layout->addWidget(credentials_grid);
107 }
108
109 {
110 /* Note on password storing */
111 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);
112 note_label->setTextFormat(Qt::RichText);
113 note_label->setWordWrap(true);
114 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
115 note_label->setOpenExternalLinks(true);
116 group_box_layout->addWidget(note_label);
117 }
118
119 full_layout->addWidget(group_box);
120 }
121
122 full_layout->setSpacing(10);
123 full_layout->addStretch();
124
125 return result;
126 }
127
62 QWidget* SettingsPageServices::CreateAniListPage() { 128 QWidget* SettingsPageServices::CreateAniListPage() {
63 QWidget* result = new QWidget(this); 129 QWidget* result = new QWidget(this);
64 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); 130 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
65 131
66 QVBoxLayout* full_layout = new QVBoxLayout(result); 132 QVBoxLayout* full_layout = new QVBoxLayout(result);
91 { 157 {
92 /* Note on creating new accounts... */ 158 /* Note on creating new accounts... */
93 QLabel* note_label = 159 QLabel* note_label =
94 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); 160 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box);
95 note_label->setTextFormat(Qt::RichText); 161 note_label->setTextFormat(Qt::RichText);
162 note_label->setWordWrap(true);
96 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); 163 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
97 note_label->setOpenExternalLinks(true); 164 note_label->setOpenExternalLinks(true);
98 layout->addWidget(note_label); 165 layout->addWidget(note_label);
99 } 166 }
100 167
112 } 179 }
113 180
114 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { 181 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) {
115 service = session.config.service; 182 service = session.config.service;
116 AddTab(CreateMainPage(), tr("Main")); 183 AddTab(CreateMainPage(), tr("Main"));
184 AddTab(CreateKitsuPage(), tr("Kitsu"));
117 AddTab(CreateAniListPage(), tr("AniList")); 185 AddTab(CreateAniListPage(), tr("AniList"));
118 } 186 }