1 #include "ExternalToolsPage.hpp"
2 
3 #include "Application.hpp"
4 #include "util/Helpers.hpp"
5 #include "util/LayoutCreator.hpp"
6 #include "util/RemoveScrollAreaBackground.hpp"
7 
8 #include <QFormLayout>
9 #include <QGroupBox>
10 #include <QLabel>
11 
12 #define STREAMLINK_QUALITY \
13     "Choose", "Source", "High", "Medium", "Low", "Audio only"
14 
15 namespace chatterino {
16 
ExternalToolsPage()17 ExternalToolsPage::ExternalToolsPage()
18 {
19     LayoutCreator<ExternalToolsPage> layoutCreator(this);
20 
21     auto scroll = layoutCreator.emplace<QScrollArea>();
22     auto widget = scroll.emplaceScrollAreaWidget();
23     removeScrollAreaBackground(scroll.getElement(), widget.getElement());
24 
25     auto layout = widget.setLayoutType<QVBoxLayout>();
26 
27     {
28         auto group = layout.emplace<QGroupBox>("Streamlink");
29         auto groupLayout = group.setLayoutType<QFormLayout>();
30 
31         auto description = new QLabel(
32             "Streamlink is a command-line utility that pipes video streams "
33             "from various "
34             "services into a video player, such as VLC. Make sure to edit the "
35             "configuration file before you use it!");
36         description->setWordWrap(true);
37         description->setStyleSheet("color: #bbb");
38 
39         auto links = new QLabel(
40             formatRichNamedLink("https://streamlink.github.io/", "Website") +
41             " " +
42             formatRichNamedLink(
43                 "https://github.com/streamlink/streamlink/releases/latest",
44                 "Download"));
45         links->setTextFormat(Qt::RichText);
46         links->setTextInteractionFlags(Qt::TextBrowserInteraction |
47                                        Qt::LinksAccessibleByKeyboard |
48                                        Qt::LinksAccessibleByMouse);
49         links->setOpenExternalLinks(true);
50 
51         groupLayout->setWidget(0, QFormLayout::SpanningRole, description);
52         groupLayout->setWidget(1, QFormLayout::SpanningRole, links);
53 
54         auto customPathCb =
55             this->createCheckBox("Use custom path (Enable if using "
56                                  "non-standard streamlink installation path)",
57                                  getSettings()->streamlinkUseCustomPath);
58         groupLayout->setWidget(2, QFormLayout::SpanningRole, customPathCb);
59 
60         auto customPath = this->createLineEdit(getSettings()->streamlinkPath);
61         customPath->setPlaceholderText(
62             "Path to folder where Streamlink executable can be found");
63         groupLayout->addRow("Custom streamlink path:", customPath);
64         groupLayout->addRow(
65             "Preferred quality:",
66             this->createComboBox({STREAMLINK_QUALITY},
67                                  getSettings()->preferredQuality));
68         groupLayout->addRow(
69             "Additional options:",
70             this->createLineEdit(getSettings()->streamlinkOpts));
71 
72         getSettings()->streamlinkUseCustomPath.connect(
73             [=](const auto &value, auto) {
74                 customPath->setEnabled(value);
75             },
76             this->managedConnections_);
77     }
78     layout->addSpacing(16);
79 
80     {
81         auto group = layout.emplace<QGroupBox>("Custom stream player");
82         auto groupLayout = group.setLayoutType<QFormLayout>();
83 
84         const auto description = new QLabel(
85             "You can open Twitch streams directly in any video player that "
86             "has built-in Twitch support and has own URI Scheme.\nE.g.: "
87             "IINA for macOS and Potplayer (with extension) for "
88             "Windows.\n\nWith this value set, you will get the option to "
89             "\"Open in custom player\" when "
90             "right-clicking a channel header.");
91         description->setWordWrap(true);
92         description->setStyleSheet("color: #bbb");
93 
94         groupLayout->setWidget(0, QFormLayout::SpanningRole, description);
95 
96         auto lineEdit = this->createLineEdit(getSettings()->customURIScheme);
97         lineEdit->setPlaceholderText("custom-player-scheme://");
98         groupLayout->addRow("Custom stream player URI Scheme:", lineEdit);
99     }
100     layout->addSpacing(16);
101 
102     {
103         auto group = layout.emplace<QGroupBox>("Image Uploader");
104         auto groupLayout = group.setLayoutType<QFormLayout>();
105 
106         const auto description = new QLabel(
107             "You can set custom host for uploading images, like "
108             "imgur.com or s-ul.eu.<br>Check " +
109             formatRichNamedLink("https://chatterino.com/help/image-uploader",
110                                 "this guide") +
111             " for help.");
112         description->setWordWrap(true);
113         description->setStyleSheet("color: #bbb");
114         description->setTextFormat(Qt::RichText);
115         description->setTextInteractionFlags(Qt::TextBrowserInteraction |
116                                              Qt::LinksAccessibleByKeyboard |
117                                              Qt::LinksAccessibleByMouse);
118         description->setOpenExternalLinks(true);
119 
120         groupLayout->setWidget(0, QFormLayout::SpanningRole, description);
121 
122         groupLayout->addRow(this->createCheckBox(
123             "Enable image uploader", getSettings()->imageUploaderEnabled));
124         groupLayout->addRow(
125             this->createCheckBox("Ask for confirmation when uploading an image",
126                                  getSettings()->askOnImageUpload));
127 
128         groupLayout->addRow(
129             "Request URL: ",
130             this->createLineEdit(getSettings()->imageUploaderUrl));
131         groupLayout->addRow(
132             "Form field: ",
133             this->createLineEdit(getSettings()->imageUploaderFormField));
134         groupLayout->addRow(
135             "Extra Headers: ",
136             this->createLineEdit(getSettings()->imageUploaderHeaders));
137         groupLayout->addRow(
138             "Image link: ",
139             this->createLineEdit(getSettings()->imageUploaderLink));
140         groupLayout->addRow(
141             "Deletion link: ",
142             this->createLineEdit(getSettings()->imageUploaderDeletionLink));
143     }
144 
145     layout->addStretch(1);
146 }
147 
148 }  // namespace chatterino
149