Mercurial > minori
annotate src/gui/dialog/settings/services.cc @ 324:5d3c9b31aa6e
anime: add completed date member
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 12 Jun 2024 23:03:22 -0400 |
parents | d928ec7b6a0d |
children |
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); |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
96 connect(auth_button, &QPushButton::clicked, this, [auth_button, email, password] { |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
97 if (Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), Strings::ToUtf8String(password->text()))) |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
98 auth_button->setText(tr("Re-authorize...")); |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
99 else |
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
100 auth_button->setText(tr("Authorize...")); |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
101 }); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
102 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
|
103 : tr("Re-authorize...")); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
104 credentials_grid_layout->addWidget(auth_button, 1, 2); |
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 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
107 credentials_grid_layout->setContentsMargins(0, 0, 0, 0); |
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 group_box_layout->addWidget(credentials_grid); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
110 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
111 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
112 { |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
113 /* Note on password storing */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
114 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
|
115 note_label->setTextFormat(Qt::RichText); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
116 note_label->setWordWrap(true); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
117 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
118 note_label->setOpenExternalLinks(true); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
119 group_box_layout->addWidget(note_label); |
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->addWidget(group_box); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
123 } |
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 full_layout->setSpacing(10); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
126 full_layout->addStretch(); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
127 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
128 return result; |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
129 } |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
130 |
10 | 131 QWidget* SettingsPageServices::CreateAniListPage() { |
132 QWidget* result = new QWidget(this); | |
133 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
134 | |
108 | 135 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 136 |
108 | 137 { |
138 /* Account */ | |
139 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
140 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
141 | |
142 QVBoxLayout* layout = new QVBoxLayout(group_box); | |
10 | 143 |
108 | 144 { |
145 /* Authorization */ | |
146 QWidget* auth_widget = new QWidget(group_box); | |
147 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); | |
10 | 148 |
108 | 149 { |
150 QPushButton* auth_button = new QPushButton(auth_widget); | |
151 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
258 | 152 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") |
153 : tr("Re-authorize...")); | |
108 | 154 auth_layout->addWidget(auth_button); |
155 } | |
10 | 156 |
108 | 157 layout->addWidget(auth_widget); |
158 } | |
10 | 159 |
108 | 160 { |
161 /* Note on creating new accounts... */ | |
258 | 162 QLabel* note_label = |
163 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
108 | 164 note_label->setTextFormat(Qt::RichText); |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
165 note_label->setWordWrap(true); |
108 | 166 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
167 note_label->setOpenExternalLinks(true); | |
168 layout->addWidget(note_label); | |
169 } | |
258 | 170 |
108 | 171 full_layout->addWidget(group_box); |
172 } | |
10 | 173 |
174 full_layout->setSpacing(10); | |
175 full_layout->addStretch(); | |
176 return result; | |
177 } | |
178 | |
179 void SettingsPageServices::SaveInfo() { | |
108 | 180 // see services/anilist.cc for why this is commented out |
10 | 181 session.config.service = service; |
182 } | |
183 | |
184 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
185 service = session.config.service; | |
186 AddTab(CreateMainPage(), tr("Main")); | |
317
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
187 AddTab(CreateKitsuPage(), tr("Kitsu")); |
10 | 188 AddTab(CreateAniListPage(), tr("AniList")); |
189 } |