Mercurial > minori
annotate 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 |
rev | line source |
---|---|
10 | 1 #include "core/anime.h" |
2 #include "core/session.h" | |
65
26721c28bf22
*: avoid usage of (to|from)StdString
Paper <mrpapersonic@gmail.com>
parents:
63
diff
changeset
|
3 #include "core/strings.h" |
10 | 4 #include "gui/dialog/settings.h" |
279 | 5 #include "gui/translate/anime.h" |
10 | 6 #include "services/anilist.h" |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
7 #include "services/kitsu.h" |
10 | 8 #include <QComboBox> |
9 #include <QGroupBox> | |
76 | 10 #include <QLabel> |
11 #include <QLineEdit> | |
10 | 12 #include <QPushButton> |
13 #include <QSizePolicy> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
14 #include <QVBoxLayout> |
10 | 15 |
16 QWidget* SettingsPageServices::CreateMainPage() { | |
17 QWidget* result = new QWidget(this); | |
18 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
19 | |
108 | 20 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 21 |
108 | 22 { |
23 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
24 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
10 | 25 |
108 | 26 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); |
27 | |
28 { | |
29 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
30 sync_layout->addWidget(sync_combo_box_label); | |
31 } | |
10 | 32 |
108 | 33 { |
34 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
279 | 35 for (const auto& service : Anime::Services) |
36 sync_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(service)), static_cast<int>(service)); | |
37 | |
108 | 38 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
279 | 39 [this, sync_combo_box](int index) { |
40 service = static_cast<Anime::Service>(sync_combo_box->itemData(index).toInt()); | |
41 }); | |
42 | |
43 /* this is evil */ | |
108 | 44 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
45 sync_layout->addWidget(sync_combo_box); | |
46 } | |
10 | 47 |
108 | 48 { |
258 | 49 QLabel* sync_note_label = new QLabel( |
50 tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); | |
108 | 51 sync_layout->addWidget(sync_note_label); |
52 } | |
10 | 53 |
108 | 54 full_layout->addWidget(sync_group_box); |
55 } | |
258 | 56 |
10 | 57 full_layout->setSpacing(10); |
58 full_layout->addStretch(); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
59 |
10 | 60 return result; |
61 } | |
62 | |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
63 QWidget* SettingsPageServices::CreateKitsuPage() { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
64 QWidget* result = new QWidget(this); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
65 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
66 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
67 QVBoxLayout* full_layout = new QVBoxLayout(result); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
68 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
69 { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
70 /* Account */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
71 QGroupBox* group_box = new QGroupBox(tr("Account"), result); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
72 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
73 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
74 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
75 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
76 { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
77 QWidget* credentials_grid = new QWidget(group_box); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
78 QGridLayout* credentials_grid_layout = new QGridLayout(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
79 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
80 /* E-mail */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
81 QLabel* email_label = new QLabel(tr("&E-mail"), credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
82 QLineEdit* email = new QLineEdit(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
83 email_label->setBuddy(email); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
84 credentials_grid_layout->addWidget(email_label, 0, 0); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
85 credentials_grid_layout->addWidget(email, 1, 0); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
86 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
87 QLabel* password_label = new QLabel(tr("&Password:"), credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
88 QLineEdit* password = new QLineEdit(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
89 password->setEchoMode(QLineEdit::Password); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
90 password_label->setBuddy(password); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
91 credentials_grid_layout->addWidget(password_label, 0, 1); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
92 credentials_grid_layout->addWidget(password, 1, 1); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
93 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
94 { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
95 QPushButton* auth_button = new QPushButton(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
96 connect(auth_button, &QPushButton::clicked, this, [email, password] { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
97 Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), Strings::ToUtf8String(password->text())); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
98 }); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
99 auth_button->setText(session.config.auth.kitsu.access_token.empty() ? tr("Authorize...") |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
100 : tr("Re-authorize...")); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
101 credentials_grid_layout->addWidget(auth_button, 1, 2); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
102 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
103 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
104 credentials_grid_layout->setContentsMargins(0, 0, 0, 0); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
105 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
106 group_box_layout->addWidget(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
107 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
108 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
109 { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
110 /* Note on password storing */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
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); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
112 note_label->setTextFormat(Qt::RichText); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
113 note_label->setWordWrap(true); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
114 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
115 note_label->setOpenExternalLinks(true); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
116 group_box_layout->addWidget(note_label); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
117 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
118 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
119 full_layout->addWidget(group_box); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
120 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
121 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
122 full_layout->setSpacing(10); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
123 full_layout->addStretch(); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
124 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
125 return result; |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
126 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
127 |
10 | 128 QWidget* SettingsPageServices::CreateAniListPage() { |
129 QWidget* result = new QWidget(this); | |
130 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
131 | |
108 | 132 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 133 |
108 | 134 { |
135 /* Account */ | |
136 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
137 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
138 | |
139 QVBoxLayout* layout = new QVBoxLayout(group_box); | |
10 | 140 |
108 | 141 { |
142 /* Authorization */ | |
143 QWidget* auth_widget = new QWidget(group_box); | |
144 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); | |
10 | 145 |
108 | 146 { |
147 QPushButton* auth_button = new QPushButton(auth_widget); | |
148 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
258 | 149 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") |
150 : tr("Re-authorize...")); | |
108 | 151 auth_layout->addWidget(auth_button); |
152 } | |
10 | 153 |
108 | 154 layout->addWidget(auth_widget); |
155 } | |
10 | 156 |
108 | 157 { |
158 /* Note on creating new accounts... */ | |
258 | 159 QLabel* note_label = |
160 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
108 | 161 note_label->setTextFormat(Qt::RichText); |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
162 note_label->setWordWrap(true); |
108 | 163 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
164 note_label->setOpenExternalLinks(true); | |
165 layout->addWidget(note_label); | |
166 } | |
258 | 167 |
108 | 168 full_layout->addWidget(group_box); |
169 } | |
10 | 170 |
171 full_layout->setSpacing(10); | |
172 full_layout->addStretch(); | |
173 return result; | |
174 } | |
175 | |
176 void SettingsPageServices::SaveInfo() { | |
108 | 177 // see services/anilist.cc for why this is commented out |
10 | 178 session.config.service = service; |
179 } | |
180 | |
181 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
182 service = session.config.service; | |
183 AddTab(CreateMainPage(), tr("Main")); | |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
184 AddTab(CreateKitsuPage(), tr("Kitsu")); |
10 | 185 AddTab(CreateAniListPage(), tr("AniList")); |
186 } |