Mercurial > minori
annotate src/gui/dialog/settings/services.cc @ 301:b1f625b0227c
*: convert all files CRLF -> LF
some files were in DOS format, others were in unix. now everything
(that at least is under our control) should all be the same format
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 13 May 2024 15:04:51 -0400 |
parents | 657fda1b9cac |
children | b1f4d1867ab1 |
rev | line source |
---|---|
10 | 1 #include "core/anime.h" |
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 | 4 #include "gui/dialog/settings.h" |
279 | 5 #include "gui/translate/anime.h" |
10 | 6 #include "services/anilist.h" |
7 #include <QComboBox> | |
8 #include <QGroupBox> | |
76 | 9 #include <QLabel> |
10 #include <QLineEdit> | |
10 | 11 #include <QPushButton> |
12 #include <QSizePolicy> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
13 #include <QVBoxLayout> |
10 | 14 |
15 QWidget* SettingsPageServices::CreateMainPage() { | |
16 QWidget* result = new QWidget(this); | |
17 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
18 | |
108 | 19 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 20 |
108 | 21 { |
22 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result); | |
23 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
10 | 24 |
108 | 25 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); |
26 | |
27 { | |
28 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box); | |
29 sync_layout->addWidget(sync_combo_box_label); | |
30 } | |
10 | 31 |
108 | 32 { |
33 QComboBox* sync_combo_box = new QComboBox(sync_group_box); | |
279 | 34 for (const auto& service : Anime::Services) |
35 sync_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(service)), static_cast<int>(service)); | |
36 | |
108 | 37 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
279 | 38 [this, sync_combo_box](int index) { |
39 service = static_cast<Anime::Service>(sync_combo_box->itemData(index).toInt()); | |
40 }); | |
41 | |
42 /* this is evil */ | |
108 | 43 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
44 sync_layout->addWidget(sync_combo_box); | |
45 } | |
10 | 46 |
108 | 47 { |
258 | 48 QLabel* sync_note_label = new QLabel( |
49 tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); | |
108 | 50 sync_layout->addWidget(sync_note_label); |
51 } | |
10 | 52 |
108 | 53 full_layout->addWidget(sync_group_box); |
54 } | |
258 | 55 |
10 | 56 full_layout->setSpacing(10); |
57 full_layout->addStretch(); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
58 |
10 | 59 return result; |
60 } | |
61 | |
62 QWidget* SettingsPageServices::CreateAniListPage() { | |
63 QWidget* result = new QWidget(this); | |
64 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
65 | |
108 | 66 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 67 |
108 | 68 { |
69 /* Account */ | |
70 QGroupBox* group_box = new QGroupBox(tr("Account"), result); | |
71 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
72 | |
73 QVBoxLayout* layout = new QVBoxLayout(group_box); | |
10 | 74 |
108 | 75 { |
76 /* Authorization */ | |
77 QWidget* auth_widget = new QWidget(group_box); | |
78 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); | |
10 | 79 |
108 | 80 { |
81 QPushButton* auth_button = new QPushButton(auth_widget); | |
82 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | |
258 | 83 auth_button->setText(session.config.auth.anilist.auth_token.empty() ? tr("Authorize...") |
84 : tr("Re-authorize...")); | |
108 | 85 auth_layout->addWidget(auth_button); |
86 } | |
10 | 87 |
108 | 88 layout->addWidget(auth_widget); |
89 } | |
10 | 90 |
108 | 91 { |
92 /* Note on creating new accounts... */ | |
258 | 93 QLabel* note_label = |
94 new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | |
108 | 95 note_label->setTextFormat(Qt::RichText); |
96 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | |
97 note_label->setOpenExternalLinks(true); | |
98 layout->addWidget(note_label); | |
99 } | |
258 | 100 |
108 | 101 full_layout->addWidget(group_box); |
102 } | |
10 | 103 |
104 full_layout->setSpacing(10); | |
105 full_layout->addStretch(); | |
106 return result; | |
107 } | |
108 | |
109 void SettingsPageServices::SaveInfo() { | |
108 | 110 // see services/anilist.cc for why this is commented out |
10 | 111 session.config.service = service; |
112 } | |
113 | |
114 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) { | |
115 service = session.config.service; | |
116 AddTab(CreateMainPage(), tr("Main")); | |
117 AddTab(CreateAniListPage(), tr("AniList")); | |
118 } |