1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

Add new review recommendations.

Clean up extra code, remake static title, move settings to UpdateManager class.
This commit is contained in:
gera 2021-06-17 21:42:46 +03:00 committed by Paul Licameli
parent 93b9bcf470
commit 87d94fe249
11 changed files with 52 additions and 63 deletions

View File

@ -33,7 +33,6 @@ class Importer;
class CommandHandler; class CommandHandler;
class AppCommandEvent; class AppCommandEvent;
class AudacityProject; class AudacityProject;
class UpdateManager;
class AudacityApp final : public wxApp { class AudacityApp final : public wxApp {
public: public:

View File

@ -16,6 +16,7 @@
#include "ApplicationPrefs.h" #include "ApplicationPrefs.h"
#include "update/UpdateManager.h"
#include <wx/defs.h> #include <wx/defs.h>
@ -26,9 +27,6 @@
static ComponentInterfaceSymbol s_ComponentInterfaceSymbol{ XO("Application") }; static ComponentInterfaceSymbol s_ComponentInterfaceSymbol{ XO("Application") };
BoolSetting ApplicationPrefsSettings::DefaultUpdatesCheckingFlag{
L"/Update/DefaultUpdatesChecking", true };
ApplicationPrefs::ApplicationPrefs(wxWindow * parent, wxWindowID winid) ApplicationPrefs::ApplicationPrefs(wxWindow * parent, wxWindowID winid)
: PrefsPanel(parent, winid, XO("Application")) : PrefsPanel(parent, winid, XO("Application"))
{ {
@ -74,7 +72,7 @@ void ApplicationPrefs::PopulateOrExchange(ShuttleGui & S)
{ {
S.TieCheckBox( S.TieCheckBox(
XO("&Check for Updates...").Stripped(TranslatableString::Ellipses | TranslatableString::MenuCodes), XO("&Check for Updates...").Stripped(TranslatableString::Ellipses | TranslatableString::MenuCodes),
ApplicationPrefsSettings::DefaultUpdatesCheckingFlag); UpdatesCheckingSettings::DefaultUpdatesCheckingFlag);
} }
S.EndStatic(); S.EndStatic();
S.EndScroller(); S.EndScroller();

View File

@ -18,10 +18,6 @@
class ShuttleGui; class ShuttleGui;
namespace ApplicationPrefsSettings {
extern AUDACITY_DLL_API BoolSetting DefaultUpdatesCheckingFlag;
}
class ApplicationPrefs final : public PrefsPanel class ApplicationPrefs final : public PrefsPanel
{ {
public: public:

View File

@ -115,7 +115,7 @@ PrefsPanel::Factories
PathStart, PathStart,
{ {
{wxT(""), {wxT(""),
wxT("Device,Playback,Recording,Quality,GUI,Tracks,ImportExport,Directories,Warnings,Effects,KeyConfig,Mouse,Application") wxT("Device,Playback,Recording,Quality,GUI,Tracks,ImportExport,Directories,Warnings,Effects,KeyConfig,Mouse")
}, },
{wxT("/Tracks"), wxT("TracksBehaviors,Spectrum")}, {wxT("/Tracks"), wxT("TracksBehaviors,Spectrum")},
} }

View File

@ -2,7 +2,7 @@
Audacity: A Digital Audio Editor Audacity: A Digital Audio Editor
@file UpdateDataParser.cpp @file UpdateDataParser.cpp
@brief Declare a class that parse update server data format. @brief Declare a class that parses update server data format.
Anton Gerasimov Anton Gerasimov
**********************************************************************/ **********************************************************************/
@ -10,6 +10,7 @@
#include "UpdateDataParser.h" #include "UpdateDataParser.h"
#include "xml/XMLFileReader.h" #include "xml/XMLFileReader.h"
#include "MemoryX.h"
UpdateDataParser::UpdateDataParser() UpdateDataParser::UpdateDataParser()
{} {}
@ -21,11 +22,9 @@ bool UpdateDataParser::Parse(const VersionPatch::UpdateDataFormat& updateData, V
{ {
XMLFileReader xmlReader; XMLFileReader xmlReader;
mVersionPatch = versionPatch; ValueRestorer<VersionPatch*> setter{ mVersionPatch, versionPatch };
auto ok = xmlReader.ParseString(this, updateData);
mVersionPatch = nullptr;
return ok; return xmlReader.ParseString(this, updateData);
} }
wxArrayString UpdateDataParser::SplitChangelogSentences(const wxString& changelogContent) wxArrayString UpdateDataParser::SplitChangelogSentences(const wxString& changelogContent)
@ -40,11 +39,11 @@ wxArrayString UpdateDataParser::SplitChangelogSentences(const wxString& changelo
while ((pos = s.find(delimiter)) != std::string::npos) while ((pos = s.find(delimiter)) != std::string::npos)
{ {
token = s.substr(0, pos + 1); token = s.substr(0, pos + 1);
changelogSentenceList.Add(token); changelogSentenceList.Add(wxString(token).Trim());
s.erase(0, pos + delimiter.length()); s.erase(0, pos + delimiter.length());
} }
changelogSentenceList.Add(s); changelogSentenceList.Add(wxString(s).Trim());
return changelogSentenceList; return changelogSentenceList;
} }
@ -107,6 +106,8 @@ void UpdateDataParser::HandleXMLEndTag(const wxChar* tag)
mXmlParsingState == XmlParsedTags::kLinkTag) mXmlParsingState == XmlParsedTags::kLinkTag)
mXmlParsingState = XmlParsedTags::kNotUsedTag; mXmlParsingState = XmlParsedTags::kNotUsedTag;
// If it is our working OS, using "kOsTag" for keeping ready for parse state for both tags:
// <Version> and <Link>, that ordered one after another.
if (mXmlParsingState == XmlParsedTags::kVersionTag) if (mXmlParsingState == XmlParsedTags::kVersionTag)
mXmlParsingState = XmlParsedTags::kOsTag; mXmlParsingState = XmlParsedTags::kOsTag;
} }
@ -116,23 +117,23 @@ void UpdateDataParser::HandleXMLContent(const wxString& content)
if (mVersionPatch == nullptr) if (mVersionPatch == nullptr)
return; return;
wxString trimedContent(content); wxString trimmedContent(content);
switch (mXmlParsingState) switch (mXmlParsingState)
{ {
case XmlParsedTags::kDescriptionTag: case XmlParsedTags::kDescriptionTag:
trimedContent.Trim(true).Trim(false); trimmedContent.Trim(true).Trim(false);
mVersionPatch->changelog = SplitChangelogSentences(trimedContent); mVersionPatch->changelog = SplitChangelogSentences(trimmedContent);
break; break;
case XmlParsedTags::kVersionTag: case XmlParsedTags::kVersionTag:
trimedContent.Trim(true).Trim(false); trimmedContent.Trim(true).Trim(false);
mVersionPatch->version = VersionId::ParseFromString(trimedContent); mVersionPatch->version = VersionId::ParseFromString(trimmedContent);
break; break;
case XmlParsedTags::kLinkTag: case XmlParsedTags::kLinkTag:
trimedContent.Trim(true).Trim(false); trimmedContent.Trim(true).Trim(false);
mVersionPatch->download = trimedContent; mVersionPatch->download = trimmedContent;
break; break;
default: default:

View File

@ -2,7 +2,7 @@
Audacity: A Digital Audio Editor Audacity: A Digital Audio Editor
@file UpdateDataParser.h @file UpdateDataParser.h
@brief Declare a class that parse update server data format. @brief Declare a class that parses update server data format.
Anton Gerasimov Anton Gerasimov
**********************************************************************/ **********************************************************************/
@ -15,19 +15,19 @@
#include <wx/arrstr.h> #include <wx/arrstr.h>
#include <map> #include <map>
/// A class that parse update server data format. /// A class that parses update server data format.
class UpdateDataParser final : public XMLTagHandler class UpdateDataParser final : public XMLTagHandler
{ {
public: public:
UpdateDataParser(); UpdateDataParser();
~UpdateDataParser(); ~UpdateDataParser();
/// <summary> //! Parsing from update data format to VersionPatch fields.
/// Parsing from update data format to VersionPatch fields. /*!
/// </summary> @param updateData InputData.
/// <param name="updateData">Input data.</param> @param versionPath Parsed output data.
/// <param name="versionPatch">Parsed output data.</param> @return True if success.
/// <returns>True if success.</returns> */
bool Parse(const VersionPatch::UpdateDataFormat& updateData, VersionPatch* versionPatch); bool Parse(const VersionPatch::UpdateDataFormat& updateData, VersionPatch* versionPatch);
private: private:

View File

@ -2,7 +2,7 @@
Audacity: A Digital Audio Editor Audacity: A Digital Audio Editor
@file UpdateManager.cpp @file UpdateManager.cpp
@brief Declare a class that managing of updates. @brief Declare a class that handles managing of updates.
Anton Gerasimov Anton Gerasimov
**********************************************************************/ **********************************************************************/
@ -15,12 +15,16 @@
#include "Request.h" #include "Request.h"
#include "widgets/ErrorDialog.h" #include "widgets/ErrorDialog.h"
#include "prefs/ApplicationPrefs.h"
#include <wx/platinfo.h> #include <wx/platinfo.h>
#include <wx/utils.h> #include <wx/utils.h>
#include <wx/frame.h> #include <wx/frame.h>
#include <mutex>
BoolSetting UpdatesCheckingSettings::DefaultUpdatesCheckingFlag{
L"/Update/DefaultUpdatesChecking", true };
static const char* prefsUpdateScheduledTime = "/Update/UpdateScheduledTime"; static const char* prefsUpdateScheduledTime = "/Update/UpdateScheduledTime";
enum { ID_TIMER = wxID_HIGHEST + 1 }; enum { ID_TIMER = wxID_HIGHEST + 1 };
@ -30,7 +34,7 @@ BEGIN_EVENT_TABLE(UpdateManager, wxEvtHandler)
END_EVENT_TABLE() END_EVENT_TABLE()
UpdateManager::UpdateManager() UpdateManager::UpdateManager()
: mTrackingInterval( : mUpdateCheckingInterval(
std::chrono::milliseconds(std::chrono::hours(12)).count()) std::chrono::milliseconds(std::chrono::hours(12)).count())
{} {}
@ -112,15 +116,15 @@ void UpdateManager::GetUpdates()
void UpdateManager::OnTimer(wxTimerEvent& WXUNUSED(event)) void UpdateManager::OnTimer(wxTimerEvent& WXUNUSED(event))
{ {
bool updatesCheckingEnabled = ApplicationPrefsSettings::DefaultUpdatesCheckingFlag.Read(); bool updatesCheckingEnabled = UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Read();
if (updatesCheckingEnabled && IsTimeToUpdatesChecking()) if (updatesCheckingEnabled && IsTimeForUpdatesChecking())
GetUpdates(); GetUpdates();
mTimer.StartOnce(mTrackingInterval); mTimer.StartOnce(mUpdateCheckingInterval);
} }
bool UpdateManager::IsTimeToUpdatesChecking() bool UpdateManager::IsTimeForUpdatesChecking()
{ {
long long nextUpdatesCheckingTime = std::stoll( long long nextUpdatesCheckingTime = std::stoll(
gPrefs->Read(prefsUpdateScheduledTime, "0").ToStdString()); gPrefs->Read(prefsUpdateScheduledTime, "0").ToStdString());
@ -136,7 +140,7 @@ bool UpdateManager::IsTimeToUpdatesChecking()
// else this condition allow us to avoid from duplicating update notifications. // else this condition allow us to avoid from duplicating update notifications.
if (nextUpdatesCheckingTime < currentTimeInMillisec) if (nextUpdatesCheckingTime < currentTimeInMillisec)
{ {
nextUpdatesCheckingTime = currentTimeInMillisec + mTrackingInterval; nextUpdatesCheckingTime = currentTimeInMillisec + mUpdateCheckingInterval;
gPrefs->Write(prefsUpdateScheduledTime, gPrefs->Write(prefsUpdateScheduledTime,
wxString(std::to_string(nextUpdatesCheckingTime))); wxString(std::to_string(nextUpdatesCheckingTime)));

View File

@ -2,7 +2,7 @@
Audacity: A Digital Audio Editor Audacity: A Digital Audio Editor
@file UpdateManager.h @file UpdateManager.h
@brief Declare a class that managing of updates. @brief Declare a class that handles managing of updates.
Anton Gerasimov Anton Gerasimov
**********************************************************************/ **********************************************************************/
@ -18,6 +18,10 @@
#include <wx/event.h> #include <wx/event.h>
#include <wx/timer.h> #include <wx/timer.h>
namespace UpdatesCheckingSettings {
extern AUDACITY_DLL_API BoolSetting DefaultUpdatesCheckingFlag;
}
/// A class that managing of updates. /// A class that managing of updates.
/** /**
Opt-in request and show update dialog by the scheduled time. Opt-in request and show update dialog by the scheduled time.
@ -42,12 +46,12 @@ private:
VersionPatch mVersionPatch; VersionPatch mVersionPatch;
wxTimer mTimer; wxTimer mTimer;
const int mTrackingInterval; const int mUpdateCheckingInterval;
void OnTimer(wxTimerEvent& event); void OnTimer(wxTimerEvent& event);
/// Scheduling update time for avoiding multiplying update notifications. /// Scheduling update time for avoiding multiplying update notifications.
bool IsTimeToUpdatesChecking(); bool IsTimeForUpdatesChecking();
public: public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@ -7,11 +7,11 @@
Anton Gerasimov Anton Gerasimov
**********************************************************************/ **********************************************************************/
#include "update/UpdatePopupDialog.h" #include "UpdatePopupDialog.h"
#include "UpdateManager.h"
#include "ShuttleGui.h" #include "ShuttleGui.h"
#include "widgets/HelpSystem.h" #include "widgets/HelpSystem.h"
#include "prefs/ApplicationPrefs.h"
#include <wx/debug.h> #include <wx/debug.h>
#include <wx/sstream.h> #include <wx/sstream.h>
@ -45,7 +45,7 @@ UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, const VersionPatch& vers
S.Id (DontShowID).AddCheckBox ( S.Id (DontShowID).AddCheckBox (
XO ("Don't show this again at start up"), XO ("Don't show this again at start up"),
!ApplicationPrefsSettings::DefaultUpdatesCheckingFlag.Read()); !UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Read());
S.Prop(1).AddSpace(1, 0, 1); S.Prop(1).AddSpace(1, 0, 1);
@ -80,7 +80,7 @@ void UpdatePopupDialog::OnSkip (wxCommandEvent&)
void UpdatePopupDialog::OnDontShow (wxCommandEvent& event) void UpdatePopupDialog::OnDontShow (wxCommandEvent& event)
{ {
ApplicationPrefsSettings::DefaultUpdatesCheckingFlag.Write(!event.IsChecked()); UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Write(!event.IsChecked());
} }
HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent) HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)
@ -88,13 +88,10 @@ HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)
wxStringOutputStream o; wxStringOutputStream o;
wxTextOutputStream informationStr (o); wxTextOutputStream informationStr (o);
// i18n-hint Substitution of version number for %s.
static const auto title = XC("Audacity %s is available!", "update dialog")
.Format(mVersionPatch.version.GetString());
informationStr informationStr
<< wxT("<html><body><h3>") << wxT("<html><body><h3>")
<< title.Translation() // i18n-hint Substitution of version number for %s.
<< XC("Audacity %s is available!", "update dialog").Format(mVersionPatch.version.GetString()).Translation()
<< wxT("</h3><h5>") << wxT("</h3><h5>")
<< XC("Changelog", "update dialog") << XC("Changelog", "update dialog")
<< wxT("</h5><p>"); << wxT("</h5><p>");

View File

@ -12,20 +12,12 @@
#include "widgets/wxPanelWrapper.h" #include "widgets/wxPanelWrapper.h"
#include "wx/string.h" #include "wx/string.h"
#include "Project.h"
#include "VersionPatch.h" #include "VersionPatch.h"
class HtmlWindow; class HtmlWindow;
class wxWindow; class wxWindow;
class AudacityProject;
class UpdateManager;
/// Show dialog window with update information for the user. /// Show dialog window with update information for the user.
/**
Support user action behaviors as skip, download a new version,
and a checkbox that does not allow tracking version again.
*/
class UpdatePopupDialog final : public wxDialogWrapper class UpdatePopupDialog final : public wxDialogWrapper
{ {
DECLARE_DYNAMIC_CLASS (AboutDialog) DECLARE_DYNAMIC_CLASS (AboutDialog)

View File

@ -67,7 +67,5 @@ bool VersionId::operator< (const VersionId& other)
bool VersionId::operator> (const VersionId& other) bool VersionId::operator> (const VersionId& other)
{ {
if (*this == other) return false; return !(*this < other) && (*this != other);
return !(*this < other);
} }