Mercurial > minori
annotate src/gui/dialog/settings/services.cpp @ 68:2417121d894e
*: normalize usage of layouts
before, I used them two ways, once was by setting the layout later
by using setLayout(QWidget), and the other was just using the constructor.
I find the constructor to be easier to read, so I chose that one.
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Mon, 02 Oct 2023 21:33:25 -0400 |
| parents | 26721c28bf22 |
| children | 5ccb99bfa605 |
| 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> | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
10 #include <QVBoxLayout> |
|
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
11 #include <QLabel> |
|
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
12 #include <QPushButton> |
|
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
13 #include <QLineEdit> |
| 10 | 14 |
| 15 QWidget* SettingsPageServices::CreateMainPage() { | |
| 16 QWidget* result = new QWidget(this); | |
| 17 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 18 | |
| 19 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
| 20 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 21 | |
| 22 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
| 23 | |
| 24 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
| 25 sync_combo_box->addItem(tr("AniList")); | |
| 26 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 15 | 27 [this](int index) { service = static_cast<Anime::Services>(index + 1); }); |
| 10 | 28 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
| 29 | |
| 30 QLabel* sync_note_label = | |
| 15 | 31 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); |
| 10 | 32 |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
33 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); |
| 10 | 34 sync_layout->addWidget(sync_combo_box_label); |
| 35 sync_layout->addWidget(sync_combo_box); | |
| 36 sync_layout->addWidget(sync_note_label); | |
| 37 | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
38 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 10 | 39 full_layout->addWidget(sync_group_box); |
| 40 full_layout->setSpacing(10); | |
| 41 full_layout->addStretch(); | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
42 |
| 10 | 43 return result; |
| 44 } | |
| 45 | |
| 46 QWidget* SettingsPageServices::CreateAniListPage() { | |
| 47 QWidget* result = new QWidget(this); | |
| 48 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
| 49 | |
| 50 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
| 51 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 52 | |
|
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
53 /* this is outdated! usernames are retrieved through a request to AniList now. |
| 63 | 54 although that's a bit... erm... cancerous, maybe this method IS useful. IDK */ |
| 10 | 55 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); |
| 56 | |
| 57 QWidget* auth_widget = new QWidget(group_box); | |
| 58 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | |
| 59 connect(username_entry, &QLineEdit::editingFinished, this, | |
| 15 | 60 [this, username_entry] { username = username_entry->text(); }); |
| 10 | 61 |
| 62 QPushButton* auth_button = new QPushButton(auth_widget); | |
| 63 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
| 64 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | |
| 65 | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
66 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); |
| 10 | 67 auth_layout->addWidget(username_entry); |
| 68 auth_layout->addWidget(auth_button); | |
| 69 | |
| 70 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
| 71 note_label->setTextFormat(Qt::RichText); | |
| 72 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
| 73 note_label->setOpenExternalLinks(true); | |
| 74 | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
75 QVBoxLayout* layout = new QVBoxLayout(group_box); |
| 10 | 76 layout->addWidget(username_entry_label); |
| 77 layout->addWidget(auth_widget); | |
| 78 layout->addWidget(note_label); | |
| 79 | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
80 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 10 | 81 full_layout->addWidget(group_box); |
| 82 full_layout->setSpacing(10); | |
| 83 full_layout->addStretch(); | |
| 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 } |
