annotate src/gui/dialog/settings/services.cpp @ 44:619cbd6e69f9

filesystem: fix CreateDirectories function
author Paper <mrpapersonic@gmail.com>
date Fri, 22 Sep 2023 13:52:11 -0400
parents cde8f67a7c7d
children 3d2decf093bb
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"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
3 #include "gui/dialog/settings.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 #include "services/anilist.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5 #include <QComboBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 #include <QGroupBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 #include <QPushButton>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
8 #include <QSizePolicy>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
9
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 QWidget* SettingsPageServices::CreateMainPage() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
11 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
12 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 QGroupBox* sync_group_box = new QGroupBox(tr("Synchronization"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 sync_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 QLabel* sync_combo_box_label = new QLabel(tr("Active service and metadata provider:"), sync_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19 QComboBox* sync_combo_box = new QComboBox(sync_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 sync_combo_box->addItem(tr("AniList"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
21 connect(sync_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
22 [this](int index) { service = static_cast<Anime::Services>(index + 1); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
23 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
24
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
25 QLabel* sync_note_label =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
26 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
28 QVBoxLayout* sync_layout = new QVBoxLayout;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
29 sync_layout->addWidget(sync_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30 sync_layout->addWidget(sync_combo_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 sync_layout->addWidget(sync_note_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
32 sync_group_box->setLayout(sync_layout);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
33
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
34 QVBoxLayout* full_layout = new QVBoxLayout;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
35 full_layout->addWidget(sync_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
36 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
37 full_layout->addStretch();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
38 result->setLayout(full_layout);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
40 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42 QWidget* SettingsPageServices::CreateAniListPage() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
43 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
44 result->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
46 QGroupBox* group_box = new QGroupBox(tr("Account"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
47 group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
48
44
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
49 /* this is outdated! usernames are retrieved through a request to AniList now.
619cbd6e69f9 filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
50 although that's a bit... erm... cancerous, maybe this method IS useful. IDK */
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51 QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 QWidget* auth_widget = new QWidget(group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54 QLineEdit* username_entry = new QLineEdit(username, auth_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
55 connect(username_entry, &QLineEdit::editingFinished, this,
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
56 [this, username_entry] { username = username_entry->text(); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58 QPushButton* auth_button = new QPushButton(auth_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
59 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); });
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
60 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize..."));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
61
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
62 QHBoxLayout* auth_layout = new QHBoxLayout;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63 auth_layout->addWidget(username_entry);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
64 auth_layout->addWidget(auth_button);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
65 auth_widget->setLayout(auth_layout);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
66
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
67 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
68 note_label->setTextFormat(Qt::RichText);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
69 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
70 note_label->setOpenExternalLinks(true);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
71
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
72 QVBoxLayout* layout = new QVBoxLayout;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
73 layout->addWidget(username_entry_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
74 layout->addWidget(auth_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
75 layout->addWidget(note_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
76 group_box->setLayout(layout);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78 QVBoxLayout* full_layout = new QVBoxLayout;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 full_layout->addWidget(group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
80 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
81 full_layout->addStretch();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 result->setLayout(full_layout);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
83 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
84 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
85
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
86 void SettingsPageServices::SaveInfo() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
87 session.config.anilist.username = username.toStdString();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
88 session.config.service = service;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
89 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
91 SettingsPageServices::SettingsPageServices(QWidget* parent) : SettingsPage(parent, tr("Services")) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
92 username = QString::fromUtf8(session.config.anilist.username.c_str());
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
93 service = session.config.service;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
94 AddTab(CreateMainPage(), tr("Main"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
95 AddTab(CreateAniListPage(), tr("AniList"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
96 }