Mercurial > minori
diff src/dialog/settings/services.cpp @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 16 Aug 2023 00:49:17 -0400 |
parents | |
children | 07a9095eaeed |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialog/settings/services.cpp Wed Aug 16 00:49:17 2023 -0400 @@ -0,0 +1,86 @@ +#include "settings.h" +#include "anilist.h" +#include "window.h" +#include <QGroupBox> +#include <QComboBox> +#include <QPushButton> +#include <QSizePolicy> + +QWidget* SettingsPageServices::CreateMainPage() { + QWidget* result = new QWidget(this); + result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + + QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); + sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + + QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); + + sync_combo_box = new QComboBox(sync_group_box); + sync_combo_box->addItem(tr("AniList")); + + QLabel* sync_note_label = new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box); + + QVBoxLayout* sync_layout = new QVBoxLayout; + sync_layout->addWidget(sync_combo_box_label); + sync_layout->addWidget(sync_combo_box); + sync_layout->addWidget(sync_note_label); + sync_group_box->setLayout(sync_layout); + + QVBoxLayout* full_layout = new QVBoxLayout; + full_layout->addWidget(sync_group_box); + full_layout->addStretch(); + result->setLayout(full_layout); + return result; +} + +QWidget* SettingsPageServices::CreateAniListPage() { + QWidget* result = new QWidget(this); + result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + QGroupBox* group_box = new QGroupBox(tr("Account"), result); + group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + + QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box); + + QWidget* auth_widget = new QWidget(group_box); + username_entry = new QLineEdit(QString::fromUtf8(session.config.anilist.username.c_str()), auth_widget); + QPushButton* auth_button = new QPushButton(auth_widget); + connect(auth_button, &QPushButton::clicked, this, [this]{ + AniList a; + a.Authorize(); + }); + auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); + + QHBoxLayout* auth_layout = new QHBoxLayout; + auth_layout->addWidget(username_entry); + auth_layout->addWidget(auth_button); + auth_widget->setLayout(auth_layout); + + QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); + note_label->setTextFormat(Qt::RichText); + note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); + note_label->setOpenExternalLinks(true); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(username_entry_label); + layout->addWidget(auth_widget); + layout->addWidget(note_label); + group_box->setLayout(layout); + + QVBoxLayout* full_layout = new QVBoxLayout; + full_layout->addWidget(group_box); + full_layout->addStretch(); + result->setLayout(full_layout); + return result; +} + +void SettingsPageServices::SaveInfo() { + session.config.anilist.username = username_entry->displayText().toStdString(); + session.config.service = static_cast<enum AnimeListServices>(sync_combo_box->currentIndex()+1); +} + +SettingsPageServices::SettingsPageServices(QWidget* parent) + : SettingsPage(parent, tr("Services")) { + AddTab(CreateMainPage(), tr("Main")); + AddTab(CreateAniListPage(), tr("AniList")); +}