Debian Codegraph @

components/extension/youtube/config.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2021 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include "config.h"
14 #include "converter.h"
15
16 using namespace smooth::GUI::Dialogs;
17
18 const String BoCA::ConfigureYouTube::ConfigID = "YouTube";
19
20 BoCA::ConfigureYouTube::ConfigureYouTube()
21 {
22 const Config *config = Config::Get();
23 I18n *i18n = I18n::Get();
24
25 i18n->SetContext("Extensions::Video Downloader::Configuration");
26
27 autoDownload = config->GetIntValue(ConfigID, "AutoDownload", False);
28 maxDownloads = config->GetIntValue(ConfigID, "MaxDownloads", 8);
29 keepVideoFiles = config->GetIntValue(ConfigID, "SaveVideoFiles", False);
30
31 String videoOutputDir = config->GetStringValue(ConfigID, "VideoOutputDir", S::System::System::GetPersonalFilesDirectory(S::System::PersonalFilesMovies));
32
33 group_auto = new GroupBox(i18n->TranslateString("Automatization"), Point(7, 11), Size(344, 41));
34
35 check_auto_download = new CheckBox(i18n->TranslateString("Automatically download URLs copied to clipboard"), Point(10, 14), Size(324, 0), &autoDownload);
36
37 group_auto->Add(check_auto_download);
38
39 group_downloads = new GroupBox(i18n->TranslateString("Downloads"), Point(7, 64), Size(344, 41));
40
41 text_max_downloads = new Text(i18n->AddColon(i18n->TranslateString("Maximum number of simultaneous downloads")), Point(10, 14));
42
43 edit_max_downloads = new EditBox(String::FromInt(maxDownloads), Point(text_max_downloads->GetUnscaledTextWidth() + 17, 11), Size(18, 0), 2);
44 edit_max_downloads->onInput.Connect(&ConfigureYouTube::EditMaxDownloads, this);
45 edit_max_downloads->SetFlags(EDB_NUMERIC);
46
47 arrows_max_downloads = new Arrows(Point(edit_max_downloads->GetX() + 18, 11), Size(0, 20), OR_VERT, &maxDownloads, 1, 32);
48 arrows_max_downloads->onValueChange.Connect(&ConfigureYouTube::ArrowsMaxDownloads, this);
49
50 group_downloads->Add(text_max_downloads);
51 group_downloads->Add(edit_max_downloads);
52 group_downloads->Add(arrows_max_downloads);
53
54 group_files = new GroupBox(i18n->TranslateString("Video files"), Point(7, 117), Size(344, 96));
55
56 check_keep = new CheckBox(i18n->TranslateString("Save downloaded video files"), Point(10, 14), Size(236, 0), &keepVideoFiles);
57 check_keep->onAction.Connect(&ConfigureYouTube::ToggleKeepFiles, this);
58
59 if (config->GetIntValue(ConfigID, "DisableSaveOption", False)) check_keep->Deactivate();
60
61 edit_dir = new EditBox(videoOutputDir, Point(10, 39), Size(236, 0), 0);
62
63 button_browse = new Button(i18n->TranslateString("Select"), Point(90, 38), Size(0, 0));
64 button_browse->SetOrientation(OR_UPPERRIGHT);
65 button_browse->onAction.Connect(&ConfigureYouTube::SelectOutputDir, this);
66
67 text_format = new Text(i18n->AddColon(i18n->TranslateString("Output format")), Point(10, 70));
68
69 combo_format = new ComboBox(Point(17 + text_format->GetUnscaledTextWidth(), 67), Size(317 - text_format->GetUnscaledTextWidth(), 0));
70 combo_format->AddEntry(i18n->TranslateString("keep original format"));
71
72 Array<Converter *> &converters = Converter::Get();
73
74 foreach (Converter *converter, converters)
75 {
76 const AS::FileFormat &format = converter->GetFormat();
77
78 combo_format->AddEntry(format.GetName().Append(" (*.").Append(format.GetExtensions().GetFirst()).Append(")"));
79 }
80
81 combo_format->SelectNthEntry(config->GetIntValue(ConfigID, "OutputFormat", -1) + 1);
82
83 group_files->Add(check_keep);
84 group_files->Add(edit_dir);
85 group_files->Add(button_browse);
86 group_files->Add(text_format);
87 group_files->Add(combo_format);
88
89 check_auto_download->SetWidth(Math::Max(324, check_auto_download->GetUnscaledTextWidth() + 21));
90 check_keep->SetWidth(check_auto_download->GetWidth() - 88);
91 edit_dir->SetWidth(check_keep->GetWidth());
92 combo_format->SetWidth(check_auto_download->GetWidth() - 7 - text_format->GetUnscaledTextWidth());
93
94 group_auto->SetWidth(check_auto_download->GetWidth() + 20);
95 group_downloads->SetWidth(group_auto->GetWidth());
96 group_files->SetWidth(group_auto->GetWidth());
97
98 Add(group_auto);
99 Add(group_downloads);
100 Add(group_files);
101
102 ToggleKeepFiles();
103
104 SetSize(Size(group_auto->GetWidth() + 14, 220));
105 }
106
107 BoCA::ConfigureYouTube::~ConfigureYouTube()
108 {
109 DeleteObject(group_auto);
110 DeleteObject(check_auto_download);
111
112 DeleteObject(group_downloads);
113 DeleteObject(text_max_downloads);
114 DeleteObject(edit_max_downloads);
115 DeleteObject(arrows_max_downloads);
116
117 DeleteObject(group_files);
118 DeleteObject(check_keep);
119
120 DeleteObject(edit_dir);
121 DeleteObject(button_browse);
122
123 DeleteObject(text_format);
124 DeleteObject(combo_format);
125 }
126
127 Void BoCA::ConfigureYouTube::EditMaxDownloads()
128 {
129 arrows_max_downloads->SetValue(edit_max_downloads->GetText().ToInt());
130 }
131
132 Void BoCA::ConfigureYouTube::ArrowsMaxDownloads()
133 {
134 edit_max_downloads->SetText(String::FromInt(maxDownloads));
135 }
136
137 Void BoCA::ConfigureYouTube::ToggleKeepFiles()
138 {
139 if (keepVideoFiles)
140 {
141 edit_dir->Activate();
142 button_browse->Activate();
143
144 if (Converter::Get().Length() > 0)
145 {
146 text_format->Activate();
147 combo_format->Activate();
148 }
149 else
150 {
151 text_format->Deactivate();
152 combo_format->Deactivate();
153 }
154 }
155 else
156 {
157 edit_dir->Deactivate();
158 button_browse->Deactivate();
159
160 text_format->Deactivate();
161 combo_format->Deactivate();
162 }
163 }
164
165 Void BoCA::ConfigureYouTube::SelectOutputDir()
166 {
167 I18n *i18n = I18n::Get();
168
169 i18n->SetContext("Extensions::Video Downloader::Configuration");
170
171 DirSelection dialog;
172
173 dialog.SetParentWindow(GetContainerWindow());
174 dialog.SetCaption(i18n->AddColon(i18n->TranslateString("Select the folder to save downloaded video files to")));
175 dialog.SetDirName(edit_dir->GetText());
176
177 if (dialog.ShowDialog() == Success())
178 {
179 edit_dir->SetText(dialog.GetDirName());
180 }
181 }
182
183 Int BoCA::ConfigureYouTube::SaveSettings()
184 {
185 Config *config = Config::Get();
186
187 String videoOutputDir = edit_dir->GetText();
188
189 if (!videoOutputDir.EndsWith(Directory::GetDirectoryDelimiter())) videoOutputDir.Append(Directory::GetDirectoryDelimiter());
190
191 config->SetStringValue(ConfigID, "VideoOutputDir", videoOutputDir);
192
193 config->SetIntValue(ConfigID, "AutoDownload", autoDownload);
194 config->SetIntValue(ConfigID, "MaxDownloads", maxDownloads);
195 config->SetIntValue(ConfigID, "SaveVideoFiles", keepVideoFiles);
196 config->SetIntValue(ConfigID, "OutputFormat", combo_format->GetSelectedEntryNumber() - 1);
197
198 return Success();
199 }