comparison 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
comparison
equal deleted inserted replaced
5:51ae25154b70 6:1d82f6e04d7d
1 #include "settings.h"
2 #include "anilist.h"
3 #include "window.h"
4 #include <QGroupBox>
5 #include <QComboBox>
6 #include <QPushButton>
7 #include <QSizePolicy>
8
9 QWidget* SettingsPageServices::CreateMainPage() {
10 QWidget* result = new QWidget(this);
11 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
12
13 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result);
14 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
15
16 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box);
17
18 sync_combo_box = new QComboBox(sync_group_box);
19 sync_combo_box->addItem(tr("AniList"));
20
21 QLabel* sync_note_label = new QLabel(tr("Note: Weeaboo is unable to synchronize multiple services at the same time."), sync_group_box);
22
23 QVBoxLayout* sync_layout = new QVBoxLayout;
24 sync_layout->addWidget(sync_combo_box_label);
25 sync_layout->addWidget(sync_combo_box);
26 sync_layout->addWidget(sync_note_label);
27 sync_group_box->setLayout(sync_layout);
28
29 QVBoxLayout* full_layout = new QVBoxLayout;
30 full_layout->addWidget(sync_group_box);
31 full_layout->addStretch();
32 result->setLayout(full_layout);
33 return result;
34 }
35
36 QWidget* SettingsPageServices::CreateAniListPage() {
37 QWidget* result = new QWidget(this);
38 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
39
40 QGroupBox* group_box = new QGroupBox(tr("Account"), result);
41 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
42
43 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box);
44
45 QWidget* auth_widget = new QWidget(group_box);
46 username_entry = new QLineEdit(QString::fromUtf8(session.config.anilist.username.c_str()), auth_widget);
47 QPushButton* auth_button = new QPushButton(auth_widget);
48 connect(auth_button, &QPushButton::clicked, this, [this]{
49 AniList a;
50 a.Authorize();
51 });
52 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize..."));
53
54 QHBoxLayout* auth_layout = new QHBoxLayout;
55 auth_layout->addWidget(username_entry);
56 auth_layout->addWidget(auth_button);
57 auth_widget->setLayout(auth_layout);
58
59 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box);
60 note_label->setTextFormat(Qt::RichText);
61 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
62 note_label->setOpenExternalLinks(true);
63
64 QVBoxLayout* layout = new QVBoxLayout;
65 layout->addWidget(username_entry_label);
66 layout->addWidget(auth_widget);
67 layout->addWidget(note_label);
68 group_box->setLayout(layout);
69
70 QVBoxLayout* full_layout = new QVBoxLayout;
71 full_layout->addWidget(group_box);
72 full_layout->addStretch();
73 result->setLayout(full_layout);
74 return result;
75 }
76
77 void SettingsPageServices::SaveInfo() {
78 session.config.anilist.username = username_entry->displayText().toStdString();
79 session.config.service = static_cast<enum AnimeListServices>(sync_combo_box->currentIndex()+1);
80 }
81
82 SettingsPageServices::SettingsPageServices(QWidget* parent)
83 : SettingsPage(parent, tr("Services")) {
84 AddTab(CreateMainPage(), tr("Main"));
85 AddTab(CreateAniListPage(), tr("AniList"));
86 }