Audacity 3.2.0
AudioComPrefsPanel.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AudioComPrefsPanel.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
12#include <cassert>
13
14#include <wx/button.h>
15#include <wx/checkbox.h>
16#include <wx/radiobut.h>
17#include <wx/textctrl.h>
18
19#include "PrefsPanel.h"
20
22#include "CloudModuleSettings.h"
23#include "ExportUtils.h"
24#include "ShuttleGui.h"
25#include "UserPanel.h"
26
27#include "OAuthService.h"
28#include "ServiceConfig.h"
29#include "UserService.h"
30
31#include "TempDirectory.h"
32
33namespace
34{
35using namespace audacity::cloud::audiocom;
36
37class AudioComPrefsPanel final : public PrefsPanel
38{
39public:
40 AudioComPrefsPanel(wxWindow* parent, wxWindowID winid)
41 : PrefsPanel { parent, winid, XO("Cloud") }
42 {
44 PopulateOrExchange(S);
45
46 mSaveLocationMode = sync::SaveLocationMode.ReadEnum();
47 mExportLocationMode = sync::ExportLocationMode.ReadEnum();
48 }
49
50 bool Commit() override
51 {
53 PopulateOrExchange(S);
54
57
58 // Enum settings are not cacheable, so we need to invalidate them
59 // sync::SaveLocationMode.Invalidate();
60 // sync::ExportLocationMode.Invalidate();
62
63 return true;
64 }
65
66 void Cancel() override
67 {
68 // ChoiceSetting ignores transactions, so we need to reset the values
69 sync::SaveLocationMode.WriteEnum(mSaveLocationMode);
70 sync::ExportLocationMode.WriteEnum(mExportLocationMode);
71 }
72
74 {
75 S.SetBorder(2);
76 S.StartScroller();
77 {
78 S.SetBorder(8);
79
80 S.StartStatic(XO("Account"));
81 {
82 S.SetBorder(8);
83 S.AddWindow(
85 GetUserService(), true,
86 AudiocomTrace::PrefsPanel, S.GetParent() },
87 wxEXPAND);
88 }
89 S.EndStatic();
90
91 S.StartStatic(XO("Export behavior"));
92 {
93 S.SetBorder(8);
94 auto checkBox = S.AddCheckBox(
95 XO("S&how 'How would you like to export?' dialog"),
97 sync::CloudLocationMode::Ask);
98
99 checkBox->Bind(
100 wxEVT_CHECKBOX,
101 [this](auto& event)
102 {
104 event.IsChecked() ? sync::CloudLocationMode::Ask :
105 sync::CloudLocationMode::Local);
106 });
107 }
108 S.EndStatic();
109
110 S.StartStatic(XO("Save behavior"));
111 {
112 S.SetBorder(4);
113
114 const auto initialMode =
115 static_cast<int>(sync::SaveLocationMode.ReadEnum());
116
117 auto BindRadioButton = [](auto* button, auto mode)
118 {
119 button->Bind(
120 wxEVT_RADIOBUTTON,
121 [mode](auto& event)
122 {
124 static_cast<sync::CloudLocationMode>(mode));
125 });
126 };
127
128 S.StartInvisiblePanel(4);
129 {
130 BindRadioButton(S.AddRadioButton(
131 XO("Always &ask"),
132 static_cast<int>(sync::CloudLocationMode::Ask),
133 initialMode),
134 sync::CloudLocationMode::Ask);
135 BindRadioButton(S.AddRadioButtonToGroup(
136 XO("Always &save to cloud"),
137 static_cast<int>(sync::CloudLocationMode::Cloud),
138 initialMode),
139 sync::CloudLocationMode::Cloud);
140 BindRadioButton(S.AddRadioButtonToGroup(
141 XO("Always save to the co&mputer"),
142 static_cast<int>(sync::CloudLocationMode::Local),
143 initialMode),
144 sync::CloudLocationMode::Local);
145 }
146 S.EndInvisiblePanel();
147 }
148 S.EndStatic();
149
150 S.StartStatic(XO("Temporary Cloud files directory"));
151 {
152 S.SetBorder(8);
153 S.StartMultiColumn(3, wxEXPAND);
154 {
155 S.SetStretchyCol(1);
156
157 mCloudProjectsSavePath = S.TieTextBox(XXO("&Location:"), CloudProjectsSavePath, 30);
158 S.AddButton(XXO("&Browse..."))
159 ->Bind(wxEVT_BUTTON, [this](auto&) { Browse(); });
160 }
161 S.EndMultiColumn();
162
163 S.SetBorder(8);
164 S.StartMultiColumn(3);
165 {
166 S.NameSuffix(XO("days"))
167 .TieIntegerTextBox(
168 XXO("&Remove temporary files after:"), DaysToKeepFiles, 10);
169 S.AddFixedText(XO("days"), true);
170 }
171 S.EndMultiColumn();
172 }
173 S.EndStatic();
174 }
175 S.EndScroller();
176 }
177
179 {
180 return ComponentInterfaceSymbol { XO("Cloud") };
181 }
182
184 {
185 return XO("Preferences for Cloud");
186 }
187
188 void Browse()
189 {
190 const auto currentPath = CloudProjectsSavePath.Read();
191
193 this, XO("Choose a location to place the temporary directory"),
194 currentPath);
195 int retval = dlog.ShowModal();
196
197 if (retval != wxID_CANCEL && !dlog.GetPath().empty())
198 {
199 wxFileName tmpDirPath;
200 tmpDirPath.AssignDir(dlog.GetPath());
201
203 tmpDirPath.GetFullPath(),
204 XO("Temporary files directory cannot be on a FAT drive.")))
205 {
206 return;
207 }
208
210 dlog.GetPath(), XO("Cannot set the preference.")))
211 {
212 return;
213 }
214
215 mCloudProjectsSavePath->SetValue(
216 tmpDirPath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
217 }
218 }
219
220private:
221 wxTextCtrl* mCloudProjectsSavePath {};
223
226
227}; // class AudioComPrefsPanel
228
230 "AudioComPrefsPanel",
231 [](wxWindow* parent, wxWindowID winid, AudacityProject*) -> PrefsPanel*
232 {
233 assert(parent != nullptr);
234 return parent != nullptr ? safenew AudioComPrefsPanel(parent, winid) :
235 nullptr;
236 },
237 false,
238 // Register with an explicit ordering hint because this one might be
239 // absent
240 { "", { Registry::OrderingHint::End, {} } }
241};
242} // namespace
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46
@ eIsSavingToPrefs
Definition: ShuttleGui.h:47
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
bool WriteEnum(Enum value)
Definition: Prefs.h:546
Enum ReadEnum() const
Definition: Prefs.h:534
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
void Invalidate() override
Definition: Prefs.h:289
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Holds a msgid for the translation catalog; may also bind format arguments.
FILES_API bool WritableLocationCheck(const FilePath &path, const TranslatableString &message)
Check location on writable access and return true if checked successfully.
FILES_API bool FATFilesystemDenied(const FilePath &path, const TranslatableString &msg, const BasicUI::WindowPlacement &placement={})
EnumSetting< CloudLocationMode > SaveLocationMode
EnumSetting< CloudLocationMode > ExportLocationMode
UserService & GetUserService()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.