Mercurial > minori
comparison src/dialog/settings/services.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
| author | Paper <mrpapersonic@gmail.com> | 
|---|---|
| date | Thu, 24 Aug 2023 23:11:38 -0400 | 
| parents | 1d82f6e04d7d | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 6:1d82f6e04d7d | 7:07a9095eaeed | 
|---|---|
| 1 #include "settings.h" | 1 #include "settings.h" | 
| 2 #include "anilist.h" | 2 #include "anilist.h" | 
| 3 #include "window.h" | 3 #include "session.h" | 
| 4 #include <QGroupBox> | 4 #include <QGroupBox> | 
| 5 #include <QComboBox> | 5 #include <QComboBox> | 
| 6 #include <QPushButton> | 6 #include <QPushButton> | 
| 7 #include <QSizePolicy> | 7 #include <QSizePolicy> | 
| 8 | 8 | 
| 13 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | 13 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | 
| 14 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 14 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 
| 15 | 15 | 
| 16 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | 16 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | 
| 17 | 17 | 
| 18 sync_combo_box = new QComboBox(sync_group_box); | 18 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | 
| 19 sync_combo_box->addItem(tr("AniList")); | 19 sync_combo_box->addItem(tr("AniList")); | 
| 20 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index){ | |
| 21 service = static_cast<enum AnimeListServices>(index + 1); | |
| 22 }); | |
| 23 sync_combo_box->setCurrentIndex(service - 1); | |
| 20 | 24 | 
| 21 QLabel* sync_note_label = new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box); | 25 QLabel* sync_note_label = new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box); | 
| 22 | 26 | 
| 23 QVBoxLayout* sync_layout = new QVBoxLayout; | 27 QVBoxLayout* sync_layout = new QVBoxLayout; | 
| 24 sync_layout->addWidget(sync_combo_box_label); | 28 sync_layout->addWidget(sync_combo_box_label); | 
| 41 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 45 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 
| 42 | 46 | 
| 43 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); | 47 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); | 
| 44 | 48 | 
| 45 QWidget* auth_widget = new QWidget(group_box); | 49 QWidget* auth_widget = new QWidget(group_box); | 
| 46 username_entry = new QLineEdit(QString::fromUtf8(session.config.anilist.username.c_str()), auth_widget); | 50 QLineEdit* username_entry = new QLineEdit(username, auth_widget); | 
| 51 connect(username_entry, &QLineEdit::editingFinished, this, [this, username_entry]{ | |
| 52 username = username_entry->text(); | |
| 53 }); | |
| 54 | |
| 47 QPushButton* auth_button = new QPushButton(auth_widget); | 55 QPushButton* auth_button = new QPushButton(auth_widget); | 
| 48 connect(auth_button, &QPushButton::clicked, this, [this]{ | 56 connect(auth_button, &QPushButton::clicked, this, []{ | 
| 49 AniList a; | 57 AniList a; | 
| 50 a.Authorize(); | 58 a.Authorize(); | 
| 51 }); | 59 }); | 
| 52 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | 60 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | 
| 53 | 61 | 
| 73 result->setLayout(full_layout); | 81 result->setLayout(full_layout); | 
| 74 return result; | 82 return result; | 
| 75 } | 83 } | 
| 76 | 84 | 
| 77 void SettingsPageServices::SaveInfo() { | 85 void SettingsPageServices::SaveInfo() { | 
| 78 session.config.anilist.username = username_entry->displayText().toStdString(); | 86 session.config.anilist.username = username.toStdString(); | 
| 79 session.config.service = static_cast<enum AnimeListServices>(sync_combo_box->currentIndex()+1); | 87 session.config.service = service; | 
| 80 } | 88 } | 
| 81 | 89 | 
| 82 SettingsPageServices::SettingsPageServices(QWidget* parent) | 90 SettingsPageServices::SettingsPageServices(QWidget* parent) | 
| 83 : SettingsPage(parent, tr("Services")) { | 91 : SettingsPage(parent, tr("Services")) { | 
| 92 username = QString::fromUtf8(session.config.anilist.username.c_str()); | |
| 93 service = session.config.service; | |
| 84 AddTab(CreateMainPage(), tr("Main")); | 94 AddTab(CreateMainPage(), tr("Main")); | 
| 85 AddTab(CreateAniListPage(), tr("AniList")); | 95 AddTab(CreateAniListPage(), tr("AniList")); | 
| 86 } | 96 } | 
