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 "prefs/PrefsPanel.h"
20
22#include "CloudModuleSettings.h"
23#include "ShuttleGui.h"
24#include "UserPanel.h"
25
26#include "OAuthService.h"
27#include "ServiceConfig.h"
28#include "UserService.h"
29
30#include "TempDirectory.h"
31
32namespace
33{
34using namespace audacity::cloud::audiocom;
35
36class AudioComPrefsPanel final : public PrefsPanel
37{
38public:
39 AudioComPrefsPanel(wxWindow* parent, wxWindowID winid)
40 : PrefsPanel { parent, winid, XO("Cloud") }
41 {
43 PopulateOrExchange(S);
44
45 mSaveLocationMode = sync::SaveLocationMode.ReadEnum();
46 mExportLocationMode = sync::ExportLocationMode.ReadEnum();
47 }
48
49 bool Commit() override
50 {
52 PopulateOrExchange(S);
53
56
57 // Enum settings are not cacheable, so we need to invalidate them
58 // sync::SaveLocationMode.Invalidate();
59 // sync::ExportLocationMode.Invalidate();
61
62 return true;
63 }
64
65 void Cancel() override
66 {
67 // ChoiceSetting ignores transactions, so we need to reset the values
68 sync::SaveLocationMode.WriteEnum(mSaveLocationMode);
69 sync::ExportLocationMode.WriteEnum(mExportLocationMode);
70 }
71
73 {
74 S.SetBorder(2);
75 S.StartScroller();
76 {
77 S.SetBorder(8);
78
79 S.StartStatic(XO("Account"));
80 {
81 S.SetBorder(8);
82 S.AddWindow(
84 GetUserService(), true, S.GetParent() },
85 wxEXPAND);
86 }
87 S.EndStatic();
88
89 S.StartStatic(XO("Export behavior"));
90 {
91 S.SetBorder(8);
92 auto checkBox = S.AddCheckBox(
93 XO("S&how 'How would you like to export?' dialog"),
95 sync::CloudLocationMode::Ask);
96
97 checkBox->Bind(
98 wxEVT_CHECKBOX,
99 [this](auto& event)
100 {
102 event.IsChecked() ? sync::CloudLocationMode::Ask :
103 sync::CloudLocationMode::Local);
104 });
105 }
106 S.EndStatic();
107
108 S.StartStatic(XO("Save behavior"));
109 {
110 S.SetBorder(4);
111
112 const auto initialMode =
113 static_cast<int>(sync::SaveLocationMode.ReadEnum());
114
115 auto BindRadioButton = [](auto* button, auto mode)
116 {
117 button->Bind(
118 wxEVT_RADIOBUTTON,
119 [mode](auto& event)
120 {
122 static_cast<sync::CloudLocationMode>(mode));
123 });
124 };
125
126 S.StartInvisiblePanel(4);
127 {
128 BindRadioButton(S.AddRadioButton(
129 XO("Always &ask"),
130 static_cast<int>(sync::CloudLocationMode::Ask),
131 initialMode),
132 sync::CloudLocationMode::Ask);
133 BindRadioButton(S.AddRadioButtonToGroup(
134 XO("Always &save to cloud"),
135 static_cast<int>(sync::CloudLocationMode::Cloud),
136 initialMode),
137 sync::CloudLocationMode::Cloud);
138 BindRadioButton(S.AddRadioButtonToGroup(
139 XO("Always save to the co&mputer"),
140 static_cast<int>(sync::CloudLocationMode::Local),
141 initialMode),
142 sync::CloudLocationMode::Local);
143 }
144 S.EndInvisiblePanel();
145 }
146 S.EndStatic();
147
148 S.StartStatic(XO("Temporary Cloud files directory"));
149 {
150 S.SetBorder(8);
151 S.StartMultiColumn(3, wxEXPAND);
152 {
153 S.SetStretchyCol(1);
154
155 mCloudProjectsSavePath = S.TieTextBox(XXO("&Location:"), CloudProjectsSavePath, 30);
156 S.AddButton(XXO("&Browse..."))
157 ->Bind(wxEVT_BUTTON, [this](auto&) { Browse(); });
158 }
159 S.EndMultiColumn();
160
161 S.SetBorder(8);
162 S.StartMultiColumn(3);
163 {
164 S.NameSuffix(XO("days"))
165 .TieIntegerTextBox(
166 XXO("&Remove temporary files after:"), DaysToKeepFiles, 10);
167 S.AddFixedText(XO("days"), true);
168 }
169 S.EndMultiColumn();
170 }
171 S.EndStatic();
172 }
173 S.EndScroller();
174 }
175
177 {
178 return ComponentInterfaceSymbol { XO("Cloud") };
179 }
180
182 {
183 return XO("Preferences for Cloud");
184 }
185
186 void Browse()
187 {
188 const auto currentPath = CloudProjectsSavePath.Read();
189
191 this, XO("Choose a location to place the temporary directory"),
192 currentPath);
193 int retval = dlog.ShowModal();
194
195 if (retval != wxID_CANCEL && !dlog.GetPath().empty())
196 {
197 wxFileName tmpDirPath;
198 tmpDirPath.AssignDir(dlog.GetPath());
199
201 tmpDirPath.GetFullPath(),
202 XO("Temporary files directory cannot be on a FAT drive.")))
203 {
204 return;
205 }
206
208 dlog.GetPath(), XO("Cannot set the preference.")))
209 {
210 return;
211 }
212
213 mCloudProjectsSavePath->SetValue(
214 tmpDirPath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
215 }
216 }
217
218private:
219 wxTextCtrl* mCloudProjectsSavePath {};
221
224
225}; // class AudioComPrefsPanel
226
228 "AudioComPrefsPanel",
229 [](wxWindow* parent, wxWindowID winid, AudacityProject*) -> PrefsPanel*
230 {
231 assert(parent != nullptr);
232 return parent != nullptr ? safenew AudioComPrefsPanel(parent, winid) :
233 nullptr;
234 },
235 false,
236 // Register with an explicit ordering hint because this one might be
237 // absent
238 { "", { Registry::OrderingHint::End, {} } }
239};
240} // 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.