Mercurial > minori
annotate src/gui/dialog/settings/services.cc @ 116:254b1d2b7096
settings: add torrents page, make rss feed configurable
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 07 Nov 2023 13:52:13 -0500 |
| parents | 2004b41d4a59 |
| children | 275da698697d |
| 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> | |
| 76 | 8 #include <QLabel> |
| 9 #include <QLineEdit> | |
| 10 | 10 #include <QPushButton> |
| 11 #include <QSizePolicy> | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
12 #include <QVBoxLayout> |
| 10 | 13 |
| 14 QWidget* SettingsPageServices::CreateMainPage() { | |
| 15 QWidget* result = new QWidget(this); | |
| 16 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 17 | |
| 108 | 18 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 10 | 19 |
| 108 | 20 { |
| 21 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
| 22 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 10 | 23 |
| 108 | 24 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); |
| 25 | |
| 26 { | |
| 27 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
| 28 sync_layout->addWidget(sync_combo_box_label); | |
| 29 } | |
| 10 | 30 |
| 108 | 31 { |
| 32 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
| 33 sync_combo_box->addItem(tr("AniList")); | |
| 34 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 35 [this](int index) { service = static_cast<Anime::Services>(index + 1); }); | |
| 36 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); | |
| 37 sync_layout->addWidget(sync_combo_box); | |
| 38 } | |
| 10 | 39 |
| 108 | 40 { |
| 41 QLabel* sync_note_label = | |
| 42 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); | |
| 43 sync_layout->addWidget(sync_note_label); | |
| 44 } | |
| 10 | 45 |
| 108 | 46 full_layout->addWidget(sync_group_box); |
| 47 } | |
| 48 | |
| 10 | 49 full_layout->setSpacing(10); |
| 50 full_layout->addStretch(); | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
51 |
| 10 | 52 return result; |
| 53 } | |
| 54 | |
| 55 QWidget* SettingsPageServices::CreateAniListPage() { | |
| 56 QWidget* result = new QWidget(this); | |
| 57 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
| 58 | |
| 108 | 59 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 10 | 60 |
| 108 | 61 { |
| 62 /* Account */ | |
| 63 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
| 64 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 65 | |
| 66 QVBoxLayout* layout = new QVBoxLayout(group_box); | |
| 10 | 67 |
| 108 | 68 { |
| 69 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); | |
| 70 layout->addWidget(username_entry_label); | |
| 71 } | |
| 10 | 72 |
| 108 | 73 { |
| 74 /* Authorization */ | |
| 75 QWidget* auth_widget = new QWidget(group_box); | |
| 76 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); | |
| 10 | 77 |
| 108 | 78 { |
| 79 /* Username: this literally never gets used btw */ | |
| 80 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | |
| 81 connect(username_entry, &QLineEdit::editingFinished, this, | |
| 82 [this, username_entry] { username = username_entry->text(); }); | |
| 83 auth_layout->addWidget(username_entry); | |
| 84 } | |
| 85 | |
| 86 { | |
| 87 /* The actual auth button */ | |
| 88 QPushButton* auth_button = new QPushButton(auth_widget); | |
| 89 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
| 90 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | |
| 91 auth_layout->addWidget(auth_button); | |
| 92 } | |
| 10 | 93 |
| 108 | 94 layout->addWidget(auth_widget); |
| 95 } | |
| 10 | 96 |
| 108 | 97 { |
| 98 /* Note on creating new accounts... */ | |
| 99 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
| 100 note_label->setTextFormat(Qt::RichText); | |
| 101 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
| 102 note_label->setOpenExternalLinks(true); | |
| 103 layout->addWidget(note_label); | |
| 104 } | |
| 105 | |
| 106 full_layout->addWidget(group_box); | |
| 107 } | |
| 10 | 108 |
| 109 full_layout->setSpacing(10); | |
| 110 full_layout->addStretch(); | |
| 111 return result; | |
| 112 } | |
| 113 | |
| 114 void SettingsPageServices::SaveInfo() { | |
| 108 | 115 // see services/anilist.cc for why this is commented out |
| 116 // session.config.anilist.username = Strings::ToUtf8String(username); | |
| 10 | 117 session.config.service = service; |
| 118 } | |
| 119 | |
| 120 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
| 108 | 121 // username = QString::fromUtf8(session.config.anilist.username.c_str()); |
| 10 | 122 service = session.config.service; |
| 123 AddTab(CreateMainPage(), tr("Main")); | |
| 124 AddTab(CreateAniListPage(), tr("AniList")); | |
| 125 } |
