Mercurial > minori
comparison src/gui/dialog/settings/services.cc @ 393:963047512d34
*: clang-format
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 07 Nov 2025 07:16:15 -0500 |
| parents | d928ec7b6a0d |
| children |
comparison
equal
deleted
inserted
replaced
| 392:a72d6d7b3568 | 393:963047512d34 |
|---|---|
| 11 #include <QLineEdit> | 11 #include <QLineEdit> |
| 12 #include <QPushButton> | 12 #include <QPushButton> |
| 13 #include <QSizePolicy> | 13 #include <QSizePolicy> |
| 14 #include <QVBoxLayout> | 14 #include <QVBoxLayout> |
| 15 | 15 |
| 16 QWidget* SettingsPageServices::CreateMainPage() { | 16 QWidget *SettingsPageServices::CreateMainPage() |
| 17 QWidget* result = new QWidget(this); | 17 { |
| 18 QWidget *result = new QWidget(this); | |
| 18 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 19 | 20 |
| 20 QVBoxLayout* full_layout = new QVBoxLayout(result); | 21 QVBoxLayout *full_layout = new QVBoxLayout(result); |
| 21 | 22 |
| 22 { | 23 { |
| 23 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | 24 QGroupBox *sync_group_box = new QGroupBox(tr("Synchronization"), result); |
| 24 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 25 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 25 | 26 |
| 26 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); | 27 QVBoxLayout *sync_layout = new QVBoxLayout(sync_group_box); |
| 27 | 28 |
| 28 { | 29 { |
| 29 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | 30 QLabel *sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); |
| 30 sync_layout->addWidget(sync_combo_box_label); | 31 sync_layout->addWidget(sync_combo_box_label); |
| 31 } | 32 } |
| 32 | 33 |
| 33 { | 34 { |
| 34 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | 35 QComboBox *sync_combo_box = new QComboBox(sync_group_box); |
| 35 for (const auto& service : Anime::Services) | 36 for (const auto &service : Anime::Services) |
| 36 sync_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(service)), static_cast<int>(service)); | 37 sync_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(service)), |
| 38 static_cast<int>(service)); | |
| 37 | 39 |
| 38 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | 40 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
| 39 [this, sync_combo_box](int index) { | 41 [this, sync_combo_box](int index) { |
| 40 service = static_cast<Anime::Service>(sync_combo_box->itemData(index).toInt()); | 42 service = static_cast<Anime::Service>(sync_combo_box->itemData(index).toInt()); |
| 41 }); | 43 }); |
| 42 | 44 |
| 43 /* this is evil */ | 45 /* this is evil */ |
| 44 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); | 46 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
| 45 sync_layout->addWidget(sync_combo_box); | 47 sync_layout->addWidget(sync_combo_box); |
| 46 } | 48 } |
| 47 | 49 |
| 48 { | 50 { |
| 49 QLabel* sync_note_label = new QLabel( | 51 QLabel *sync_note_label = new QLabel( |
| 50 tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); | 52 tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); |
| 51 sync_layout->addWidget(sync_note_label); | 53 sync_layout->addWidget(sync_note_label); |
| 52 } | 54 } |
| 53 | 55 |
| 54 full_layout->addWidget(sync_group_box); | 56 full_layout->addWidget(sync_group_box); |
| 58 full_layout->addStretch(); | 60 full_layout->addStretch(); |
| 59 | 61 |
| 60 return result; | 62 return result; |
| 61 } | 63 } |
| 62 | 64 |
| 63 QWidget* SettingsPageServices::CreateKitsuPage() { | 65 QWidget *SettingsPageServices::CreateKitsuPage() |
| 64 QWidget* result = new QWidget(this); | 66 { |
| 67 QWidget *result = new QWidget(this); | |
| 65 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | 68 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
| 66 | 69 |
| 67 QVBoxLayout* full_layout = new QVBoxLayout(result); | 70 QVBoxLayout *full_layout = new QVBoxLayout(result); |
| 68 | 71 |
| 69 { | 72 { |
| 70 /* Account */ | 73 /* Account */ |
| 71 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | 74 QGroupBox *group_box = new QGroupBox(tr("Account"), result); |
| 72 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 75 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 73 | 76 |
| 74 QVBoxLayout* group_box_layout = new QVBoxLayout(group_box); | 77 QVBoxLayout *group_box_layout = new QVBoxLayout(group_box); |
| 75 | 78 |
| 76 { | 79 { |
| 77 QWidget* credentials_grid = new QWidget(group_box); | 80 QWidget *credentials_grid = new QWidget(group_box); |
| 78 QGridLayout* credentials_grid_layout = new QGridLayout(credentials_grid); | 81 QGridLayout *credentials_grid_layout = new QGridLayout(credentials_grid); |
| 79 | 82 |
| 80 /* E-mail */ | 83 /* E-mail */ |
| 81 QLabel* email_label = new QLabel(tr("&E-mail"), credentials_grid); | 84 QLabel *email_label = new QLabel(tr("&E-mail"), credentials_grid); |
| 82 QLineEdit* email = new QLineEdit(credentials_grid); | 85 QLineEdit *email = new QLineEdit(credentials_grid); |
| 83 email_label->setBuddy(email); | 86 email_label->setBuddy(email); |
| 84 credentials_grid_layout->addWidget(email_label, 0, 0); | 87 credentials_grid_layout->addWidget(email_label, 0, 0); |
| 85 credentials_grid_layout->addWidget(email, 1, 0); | 88 credentials_grid_layout->addWidget(email, 1, 0); |
| 86 | 89 |
| 87 QLabel* password_label = new QLabel(tr("&Password:"), credentials_grid); | 90 QLabel *password_label = new QLabel(tr("&Password:"), credentials_grid); |
| 88 QLineEdit* password = new QLineEdit(credentials_grid); | 91 QLineEdit *password = new QLineEdit(credentials_grid); |
| 89 password->setEchoMode(QLineEdit::Password); | 92 password->setEchoMode(QLineEdit::Password); |
| 90 password_label->setBuddy(password); | 93 password_label->setBuddy(password); |
| 91 credentials_grid_layout->addWidget(password_label, 0, 1); | 94 credentials_grid_layout->addWidget(password_label, 0, 1); |
| 92 credentials_grid_layout->addWidget(password, 1, 1); | 95 credentials_grid_layout->addWidget(password, 1, 1); |
| 93 | 96 |
| 94 { | 97 { |
| 95 QPushButton* auth_button = new QPushButton(credentials_grid); | 98 QPushButton *auth_button = new QPushButton(credentials_grid); |
| 96 connect(auth_button, &QPushButton::clicked, this, [auth_button, email, password] { | 99 connect(auth_button, &QPushButton::clicked, this, [auth_button, email, password] { |
| 97 if (Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), Strings::ToUtf8String(password->text()))) | 100 if (Services::Kitsu::AuthorizeUser(Strings::ToUtf8String(email->text()), |
| 101 Strings::ToUtf8String(password->text()))) | |
| 98 auth_button->setText(tr("Re-authorize...")); | 102 auth_button->setText(tr("Re-authorize...")); |
| 99 else | 103 else |
| 100 auth_button->setText(tr("Authorize...")); | 104 auth_button->setText(tr("Authorize...")); |
| 101 }); | 105 }); |
| 102 auth_button->setText(session.config.auth.kitsu.access_token.empty() ? tr("Authorize...") | 106 auth_button->setText(session.config.auth.kitsu.access_token.empty() ? tr("Authorize...") |
| 109 group_box_layout->addWidget(credentials_grid); | 113 group_box_layout->addWidget(credentials_grid); |
| 110 } | 114 } |
| 111 | 115 |
| 112 { | 116 { |
| 113 /* Note on password storing */ | 117 /* Note on password storing */ |
| 114 QLabel* note_label = new QLabel(tr("Your e-mail and password are never stored by Minori and will only be used to authorize with Kitsu.\nFor more information, see <a href=\"https://kitsu.docs.apiary.io/#introduction/authentication\">Kitsu's API documentation</a>"), group_box); | 118 QLabel *note_label = new QLabel( |
| 119 tr("Your e-mail and password are never stored by Minori and will only be used to authorize with " | |
| 120 "Kitsu.\nFor more information, see <a " | |
| 121 "href=\"https://kitsu.docs.apiary.io/#introduction/authentication\">Kitsu's API documentation</a>"), | |
| 122 group_box); | |
| 115 note_label->setTextFormat(Qt::RichText); | 123 note_label->setTextFormat(Qt::RichText); |
| 116 note_label->setWordWrap(true); | 124 note_label->setWordWrap(true); |
| 117 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | 125 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 118 note_label->setOpenExternalLinks(true); | 126 note_label->setOpenExternalLinks(true); |
| 119 group_box_layout->addWidget(note_label); | 127 group_box_layout->addWidget(note_label); |
| 126 full_layout->addStretch(); | 134 full_layout->addStretch(); |
| 127 | 135 |
| 128 return result; | 136 return result; |
| 129 } | 137 } |
| 130 | 138 |
| 131 QWidget* SettingsPageServices::CreateAniListPage() { | 139 QWidget *SettingsPageServices::CreateAniListPage() |
| 132 QWidget* result = new QWidget(this); | 140 { |
| 141 QWidget *result = new QWidget(this); | |
| 133 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | 142 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
| 134 | 143 |
| 135 QVBoxLayout* full_layout = new QVBoxLayout(result); | 144 QVBoxLayout *full_layout = new QVBoxLayout(result); |
| 136 | 145 |
| 137 { | 146 { |
| 138 /* Account */ | 147 /* Account */ |
| 139 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | 148 QGroupBox *group_box = new QGroupBox(tr("Account"), result); |
| 140 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 149 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 141 | 150 |
| 142 QVBoxLayout* layout = new QVBoxLayout(group_box); | 151 QVBoxLayout *layout = new QVBoxLayout(group_box); |
| 143 | 152 |
| 144 { | 153 { |
| 145 /* Authorization */ | 154 /* Authorization */ |
| 146 QWidget* auth_widget = new QWidget(group_box); | 155 QWidget *auth_widget = new QWidget(group_box); |
| 147 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); | 156 QHBoxLayout *auth_layout = new QHBoxLayout(auth_widget); |
| 148 | 157 |
| 149 { | 158 { |
| 150 QPushButton* auth_button = new QPushButton(auth_widget); | 159 QPushButton *auth_button = new QPushButton(auth_widget); |
| 151 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | 160 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); |
| 152 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") | 161 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") |
| 153 : tr("Re-authorize...")); | 162 : tr("Re-authorize...")); |
| 154 auth_layout->addWidget(auth_button); | 163 auth_layout->addWidget(auth_button); |
| 155 } | 164 } |
| 157 layout->addWidget(auth_widget); | 166 layout->addWidget(auth_widget); |
| 158 } | 167 } |
| 159 | 168 |
| 160 { | 169 { |
| 161 /* Note on creating new accounts... */ | 170 /* Note on creating new accounts... */ |
| 162 QLabel* note_label = | 171 QLabel *note_label = |
| 163 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | 172 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); |
| 164 note_label->setTextFormat(Qt::RichText); | 173 note_label->setTextFormat(Qt::RichText); |
| 165 note_label->setWordWrap(true); | 174 note_label->setWordWrap(true); |
| 166 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | 175 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 167 note_label->setOpenExternalLinks(true); | 176 note_label->setOpenExternalLinks(true); |
| 174 full_layout->setSpacing(10); | 183 full_layout->setSpacing(10); |
| 175 full_layout->addStretch(); | 184 full_layout->addStretch(); |
| 176 return result; | 185 return result; |
| 177 } | 186 } |
| 178 | 187 |
| 179 void SettingsPageServices::SaveInfo() { | 188 void SettingsPageServices::SaveInfo() |
| 189 { | |
| 180 // see services/anilist.cc for why this is commented out | 190 // see services/anilist.cc for why this is commented out |
| 181 session.config.service = service; | 191 session.config.service = service; |
| 182 } | 192 } |
| 183 | 193 |
| 184 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | 194 SettingsPageServices::SettingsPageServices(QWidget *parent) : SettingsPage(parent, tr("Services")) |
| 195 { | |
| 185 service = session.config.service; | 196 service = session.config.service; |
| 186 AddTab(CreateMainPage(), tr("Main")); | 197 AddTab(CreateMainPage(), tr("Main")); |
| 187 AddTab(CreateKitsuPage(), tr("Kitsu")); | 198 AddTab(CreateKitsuPage(), tr("Kitsu")); |
| 188 AddTab(CreateAniListPage(), tr("AniList")); | 199 AddTab(CreateAniListPage(), tr("AniList")); |
| 189 } | 200 } |
