annotate src/gui/dialog/settings/services.cc @ 241:06d6c351925c

*: reorganize resources, +docs, build translations with autotools
author Paper <paper@paper.us.eu.org>
date Mon, 22 Jan 2024 16:36:19 -0500
parents ff0061e75f0f
children 862d0d8619f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/anime.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 #include "gui/dialog/settings.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5 #include "services/anilist.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 #include <QComboBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 #include <QGroupBox>
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
8 #include <QLabel>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
9 #include <QLineEdit>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 #include <QPushButton>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
11 #include <QSizePolicy>
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 65
diff changeset
12 #include <QVBoxLayout>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 QWidget* SettingsPageServices::CreateMainPage() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
18 QVBoxLayout* full_layout = new QVBoxLayout(result);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
20 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
21 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
22 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
23
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
24 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
25
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
26 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
27 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
28 sync_layout->addWidget(sync_combo_box_label);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
29 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
31 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
32 QComboBox* sync_combo_box = new QComboBox(sync_group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
33 sync_combo_box->addItem(tr("AniList"));
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
34 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
35 [this](int index) { service = static_cast<Anime::Services>(index + 1); });
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
36 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
37 sync_layout->addWidget(sync_combo_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
38 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
40 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
41 QLabel* sync_note_label =
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
42 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
43 sync_layout->addWidget(sync_note_label);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
44 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
46 full_layout->addWidget(sync_group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
47 }
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
48
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 full_layout->addStretch();
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 65
diff changeset
51
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
55 QWidget* SettingsPageServices::CreateAniListPage() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
56 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
59 QVBoxLayout* full_layout = new QVBoxLayout(result);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
60
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
61 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
62 /* Account */
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
63 QGroupBox* group_box = new QGroupBox(tr("Account"), result);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
64 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
65
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
66 QVBoxLayout* layout = new QVBoxLayout(group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
67
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
68 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
69 /* Authorization */
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
70 QWidget* auth_widget = new QWidget(group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
71 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
72
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
73 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
74 QPushButton* auth_button = new QPushButton(auth_widget);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
75 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); });
120
275da698697d config: template-ify INI
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
76 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize..."));
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
77 auth_layout->addWidget(auth_button);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
78 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
80 layout->addWidget(auth_widget);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
81 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
83 {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
84 /* Note on creating new accounts... */
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
85 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
86 note_label->setTextFormat(Qt::RichText);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
87 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
88 note_label->setOpenExternalLinks(true);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
89 layout->addWidget(note_label);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
90 }
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
91
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
92 full_layout->addWidget(group_box);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
93 }
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
94
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
95 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
96 full_layout->addStretch();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
97 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
98 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
99
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
100 void SettingsPageServices::SaveInfo() {
108
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
101 // see services/anilist.cc for why this is commented out
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
102 session.config.service = service;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
103 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
104
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
105 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
106 service = session.config.service;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
107 AddTab(CreateMainPage(), tr("Main"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108 AddTab(CreateAniListPage(), tr("AniList"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
109 }