Mercurial > minori
comparison src/gui/dialog/settings/services.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 10 Sep 2023 03:59:16 -0400 |
parents | src/dialog/settings/services.cpp@07a9095eaeed |
children | 4b198a111713 |
comparison
equal
deleted
inserted
replaced
8:b1f73678ef61 | 9:5c0397762b53 |
---|---|
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, | |
22 [this](int index) { service = static_cast<Anime::Services>(index + 1); }); | |
23 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); | |
24 | |
25 QLabel* sync_note_label = | |
26 new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box); | |
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 | |
49 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); | |
50 | |
51 QWidget* auth_widget = new QWidget(group_box); | |
52 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | |
53 connect(username_entry, &QLineEdit::editingFinished, this, | |
54 [this, username_entry] { username = username_entry->text(); }); | |
55 | |
56 QPushButton* auth_button = new QPushButton(auth_widget); | |
57 connect(auth_button, &QPushButton::clicked, this, [] { AniList::Authorize(); }); | |
58 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | |
59 | |
60 QHBoxLayout* auth_layout = new QHBoxLayout; | |
61 auth_layout->addWidget(username_entry); | |
62 auth_layout->addWidget(auth_button); | |
63 auth_widget->setLayout(auth_layout); | |
64 | |
65 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
66 note_label->setTextFormat(Qt::RichText); | |
67 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
68 note_label->setOpenExternalLinks(true); | |
69 | |
70 QVBoxLayout* layout = new QVBoxLayout; | |
71 layout->addWidget(username_entry_label); | |
72 layout->addWidget(auth_widget); | |
73 layout->addWidget(note_label); | |
74 group_box->setLayout(layout); | |
75 | |
76 QVBoxLayout* full_layout = new QVBoxLayout; | |
77 full_layout->addWidget(group_box); | |
78 full_layout->setSpacing(10); | |
79 full_layout->addStretch(); | |
80 result->setLayout(full_layout); | |
81 return result; | |
82 } | |
83 | |
84 void SettingsPageServices::SaveInfo() { | |
85 session.config.anilist.username = username.toStdString(); | |
86 session.config.service = service; | |
87 } | |
88 | |
89 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
90 username = QString::fromUtf8(session.config.anilist.username.c_str()); | |
91 service = session.config.service; | |
92 AddTab(CreateMainPage(), tr("Main")); | |
93 AddTab(CreateAniListPage(), tr("AniList")); | |
94 } |