Mercurial > minori
annotate src/gui/dialog/settings/services.cpp @ 51:75c804f713b2
window: add about window,
*: use tr() when applicable (useful for i18n)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 25 Sep 2023 20:29:26 -0400 |
parents | 619cbd6e69f9 |
children | 3d2decf093bb |
rev | line source |
---|---|
10 | 1 #include "core/anime.h" |
2 #include "core/session.h" | |
3 #include "gui/dialog/settings.h" | |
4 #include "services/anilist.h" | |
5 #include <QComboBox> | |
6 #include <QGroupBox> | |
7 #include <QPushButton> | |
8 #include <QSizePolicy> | |
9 | |
10 QWidget* SettingsPageServices::CreateMainPage() { | |
11 QWidget* result = new QWidget(this); | |
12 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
13 | |
14 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
15 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
16 | |
17 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
18 | |
19 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
20 sync_combo_box->addItem(tr("AniList")); | |
21 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
15 | 22 [this](int index) { service = static_cast<Anime::Services>(index + 1); }); |
10 | 23 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
24 | |
25 QLabel* sync_note_label = | |
15 | 26 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); |
10 | 27 |
28 QVBoxLayout* sync_layout = new QVBoxLayout; | |
29 sync_layout->addWidget(sync_combo_box_label); | |
30 sync_layout->addWidget(sync_combo_box); | |
31 sync_layout->addWidget(sync_note_label); | |
32 sync_group_box->setLayout(sync_layout); | |
33 | |
34 QVBoxLayout* full_layout = new QVBoxLayout; | |
35 full_layout->addWidget(sync_group_box); | |
36 full_layout->setSpacing(10); | |
37 full_layout->addStretch(); | |
38 result->setLayout(full_layout); | |
39 return result; | |
40 } | |
41 | |
42 QWidget* SettingsPageServices::CreateAniListPage() { | |
43 QWidget* result = new QWidget(this); | |
44 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
45 | |
46 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
47 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
48 | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
49 /* this is outdated! usernames are retrieved through a request to AniList now. |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
50 although that's a bit... erm... cancerous, maybe this method IS useful. IDK */ |
10 | 51 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); |
52 | |
53 QWidget* auth_widget = new QWidget(group_box); | |
54 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | |
55 connect(username_entry, &QLineEdit::editingFinished, this, | |
15 | 56 [this, username_entry] { username = username_entry->text(); }); |
10 | 57 |
58 QPushButton* auth_button = new QPushButton(auth_widget); | |
59 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
60 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | |
61 | |
62 QHBoxLayout* auth_layout = new QHBoxLayout; | |
63 auth_layout->addWidget(username_entry); | |
64 auth_layout->addWidget(auth_button); | |
65 auth_widget->setLayout(auth_layout); | |
66 | |
67 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
68 note_label->setTextFormat(Qt::RichText); | |
69 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
70 note_label->setOpenExternalLinks(true); | |
71 | |
72 QVBoxLayout* layout = new QVBoxLayout; | |
73 layout->addWidget(username_entry_label); | |
74 layout->addWidget(auth_widget); | |
75 layout->addWidget(note_label); | |
76 group_box->setLayout(layout); | |
77 | |
78 QVBoxLayout* full_layout = new QVBoxLayout; | |
79 full_layout->addWidget(group_box); | |
80 full_layout->setSpacing(10); | |
81 full_layout->addStretch(); | |
82 result->setLayout(full_layout); | |
83 return result; | |
84 } | |
85 | |
86 void SettingsPageServices::SaveInfo() { | |
87 session.config.anilist.username = username.toStdString(); | |
88 session.config.service = service; | |
89 } | |
90 | |
91 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
92 username = QString::fromUtf8(session.config.anilist.username.c_str()); | |
93 service = session.config.service; | |
94 AddTab(CreateMainPage(), tr("Main")); | |
95 AddTab(CreateAniListPage(), tr("AniList")); | |
96 } |