Mercurial > minori
annotate src/gui/dialog/settings/services.cpp @ 65:26721c28bf22
*: avoid usage of (to|from)StdString
in Qt5 (and probably Qt6 as well) these functions are only
available (or even usable) if Qt and Minori were built with the
*same standard headers*, which may not be the case in some
circumstances. hence, we'll use our own conversion functions,
which we probably should use anyway.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:26:35 -0400 |
parents | 3d2decf093bb |
children | 2417121d894e |
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" |
5 #include "services/anilist.h" | |
6 #include <QComboBox> | |
7 #include <QGroupBox> | |
8 #include <QPushButton> | |
9 #include <QSizePolicy> | |
10 | |
11 QWidget* SettingsPageServices::CreateMainPage() { | |
12 QWidget* result = new QWidget(this); | |
13 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
14 | |
15 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
16 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
17 | |
18 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
19 | |
20 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
21 sync_combo_box->addItem(tr("AniList")); | |
22 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
15 | 23 [this](int index) { service = static_cast<Anime::Services>(index + 1); }); |
10 | 24 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
25 | |
26 QLabel* sync_note_label = | |
15 | 27 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); |
10 | 28 |
29 QVBoxLayout* sync_layout = new QVBoxLayout; | |
30 sync_layout->addWidget(sync_combo_box_label); | |
31 sync_layout->addWidget(sync_combo_box); | |
32 sync_layout->addWidget(sync_note_label); | |
33 sync_group_box->setLayout(sync_layout); | |
34 | |
35 QVBoxLayout* full_layout = new QVBoxLayout; | |
36 full_layout->addWidget(sync_group_box); | |
37 full_layout->setSpacing(10); | |
38 full_layout->addStretch(); | |
39 result->setLayout(full_layout); | |
40 return result; | |
41 } | |
42 | |
43 QWidget* SettingsPageServices::CreateAniListPage() { | |
44 QWidget* result = new QWidget(this); | |
45 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
46 | |
47 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
48 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
49 | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
50 /* this is outdated! usernames are retrieved through a request to AniList now. |
63 | 51 although that's a bit... erm... cancerous, maybe this method IS useful. IDK */ |
10 | 52 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); |
53 | |
54 QWidget* auth_widget = new QWidget(group_box); | |
55 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | |
56 connect(username_entry, &QLineEdit::editingFinished, this, | |
15 | 57 [this, username_entry] { username = username_entry->text(); }); |
10 | 58 |
59 QPushButton* auth_button = new QPushButton(auth_widget); | |
60 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
61 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | |
62 | |
63 QHBoxLayout* auth_layout = new QHBoxLayout; | |
64 auth_layout->addWidget(username_entry); | |
65 auth_layout->addWidget(auth_button); | |
66 auth_widget->setLayout(auth_layout); | |
67 | |
68 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
69 note_label->setTextFormat(Qt::RichText); | |
70 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
71 note_label->setOpenExternalLinks(true); | |
72 | |
73 QVBoxLayout* layout = new QVBoxLayout; | |
74 layout->addWidget(username_entry_label); | |
75 layout->addWidget(auth_widget); | |
76 layout->addWidget(note_label); | |
77 group_box->setLayout(layout); | |
78 | |
79 QVBoxLayout* full_layout = new QVBoxLayout; | |
80 full_layout->addWidget(group_box); | |
81 full_layout->setSpacing(10); | |
82 full_layout->addStretch(); | |
83 result->setLayout(full_layout); | |
84 return result; | |
85 } | |
86 | |
87 void SettingsPageServices::SaveInfo() { | |
65
26721c28bf22
*: avoid usage of (to|from)StdString
Paper <mrpapersonic@gmail.com>
parents:
63
diff
changeset
|
88 session.config.anilist.username = Strings::ToUtf8String(username); |
10 | 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 } |