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