瀏覽代碼

More readable usage statistics display

Source commit: c4533cb909a466617c0b756072dcf365ef9b0da8
Martin Prikryl 9 年之前
父節點
當前提交
54be1dc611

+ 24 - 7
source/core/Usage.cpp

@@ -279,30 +279,47 @@ void __fastcall TUsage::SetCollect(bool value)
   }
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TUsage::Serialize() const
+UnicodeString __fastcall TUsage::Serialize(const UnicodeString & Delimiter, const UnicodeString & Filter) const
 {
   TGuard Guard(FCriticalSection);
   UnicodeString Result;
 
-  AddToList(Result, FValues->DelimitedText, L"&");
+  UnicodeString FilterUpper = Filter.UpperCase();
+  for (int Index = 0; Index < FValues->Count; Index++)
+  {
+    Serialize(Result, FValues->Names[Index], FValues->ValueFromIndex[Index], Delimiter, FilterUpper);
+  }
 
-  Serialize(Result, L"Period", FPeriodCounters);
-  Serialize(Result, L"Lifetime", FLifetimeCounters);
+  Serialize(Result, L"Period", FPeriodCounters, Delimiter, FilterUpper);
+  Serialize(Result, L"Lifetime", FLifetimeCounters, Delimiter, FilterUpper);
 
   return Result;
 }
 //---------------------------------------------------------------------------
-void __fastcall TUsage::Serialize(UnicodeString& List,
-  const UnicodeString & Name, const TCounters & Counters) const
+void __fastcall TUsage::Serialize(
+  UnicodeString & List, const UnicodeString & Name, const TCounters & Counters,
+  const UnicodeString & Delimiter, const UnicodeString & FilterUpper) const
 {
   TCounters::const_iterator i = Counters.begin();
   while (i != Counters.end())
   {
-    AddToList(List, FORMAT(L"%s%s=%d", (Name, i->first, i->second)), L"&");
+    Serialize(List, Name + i->first, IntToStr(i->second), Delimiter, FilterUpper);
     i++;
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TUsage::Serialize(
+  UnicodeString & List, const UnicodeString & Name, const UnicodeString & Value,
+  const UnicodeString & Delimiter, const UnicodeString & FilterUpper) const
+{
+  if (FilterUpper.IsEmpty() ||
+      (Name.UpperCase().Pos(FilterUpper) > 0) ||
+      (Value.UpperCase().Pos(FilterUpper) > 0))
+  {
+    AddToList(List, FORMAT(L"%s=%s", (Name, Value)), Delimiter);
+  }
+}
+//---------------------------------------------------------------------------
 int __fastcall TUsage::CalculateCounterSize(__int64 Size)
 {
   const int SizeCounterFactor = 10240;

+ 7 - 3
source/core/Usage.h

@@ -26,7 +26,7 @@ public:
   void __fastcall Default();
   void __fastcall Load(THierarchicalStorage * Storage);
   void __fastcall Save(THierarchicalStorage * Storage) const;
-  UnicodeString __fastcall Serialize() const;
+  UnicodeString __fastcall Serialize(const UnicodeString & Delimiter = L"&", const UnicodeString & Filter = L"") const;
 
   static int __fastcall CalculateCounterSize(__int64 Size);
 
@@ -49,8 +49,12 @@ private:
     const UnicodeString & Name, const TCounters & Counters) const;
   void __fastcall Inc(const UnicodeString & Key, TCounters & Counters, int Increment);
   void __fastcall SetMax(const UnicodeString & Key, int Value, TCounters & Counters);
-  void __fastcall Serialize(UnicodeString& List,
-    const UnicodeString & Name, const TCounters & Counters) const;
+  void __fastcall Serialize(
+    UnicodeString& List, const UnicodeString & Name, const TCounters & Counters,
+    const UnicodeString & Delimiter, const UnicodeString & FilterUpper) const;
+  void __fastcall Serialize(
+    UnicodeString & List, const UnicodeString & Name, const UnicodeString & Value,
+    const UnicodeString & Delimiter, const UnicodeString & FilterUpper) const;
   void __fastcall ResetLastExceptions();
   void __fastcall ResetValue(const UnicodeString & Key);
 };

+ 117 - 19
source/forms/Custom.cpp

@@ -111,6 +111,24 @@ bool __fastcall TCustomDialog::CloseQuery()
   return TForm::CloseQuery();
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomDialog::RemoveCancelButton()
+{
+  CancelButton->Visible = false;
+  OKButton->Left = CancelButton->Left;
+  OKButton->Cancel = true;
+  DebugAssert(OKButton->Width == CancelButton->Width);
+  DebugAssert(OKButton->Top == CancelButton->Top);
+}
+//---------------------------------------------------------------------------
+void __fastcall TCustomDialog::AddDialogButton(TButton * Button)
+{
+  Button->Parent = this;
+  Button->Top = OKButton->Top;
+  Button->Left = FHorizontalMargin;
+  Button->Height = OKButton->Height;
+  AddWinControl(Button);
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
 {
   TImage * Image = new TImage(this);
@@ -170,19 +188,22 @@ void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * L
   // this updates Height property to real value
   Edit->HandleNeeded();
 
-  Label->Parent = GetDefaultParent();
-  Label->Left = FIndent;
-
-  if (OneLine)
+  if (Label != NULL)
   {
-    DebugAssert(Edit->Height > Label->Height);
-    Label->Top = FPos + ((Edit->Height - Label->Height) / 2);
-  }
-  else
-  {
-    Label->Top = FPos;
+    Label->Parent = GetDefaultParent();
+    Label->Left = FIndent;
+
+    if (OneLine)
+    {
+      DebugAssert(Edit->Height > Label->Height);
+      Label->Top = FPos + ((Edit->Height - Label->Height) / 2);
+    }
+    else
+    {
+      Label->Top = FPos;
 
-    FPos += Label->Height + ScaleByTextHeight(this, 4);
+      FPos += Label->Height + ScaleByTextHeight(this, 4);
+    }
   }
 
   Edit->Top = FPos;
@@ -198,21 +219,24 @@ void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * L
 
   AdjustHeight(Edit);
 
-  if (Label->FocusControl == NULL)
-  {
-    Label->FocusControl = Edit;
-  }
-  else
+  if (Label != NULL)
   {
-    DebugAssert(Label->FocusControl == Edit);
+    if (Label->FocusControl == NULL)
+    {
+      Label->FocusControl = Edit;
+    }
+    else
+    {
+      DebugAssert(Label->FocusControl == Edit);
+    }
   }
 
   AddWinControl(Edit);
 }
 //---------------------------------------------------------------------------
-void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label)
+void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label, bool OneLine)
 {
-  AddEditLikeControl(Edit, Label, false);
+  AddEditLikeControl(Edit, Label, OneLine);
 
   TEdit * PublicEdit = reinterpret_cast<TEdit *>(Edit);
   if (PublicEdit->OnChange == NULL)
@@ -1303,3 +1327,77 @@ bool __fastcall DoCustomCommandOptionsDialog(
     new TCustomCommandOptionsDialog(Command, CustomCommandOptions, Flags, CustomCommandForOptions, Site));
   return Dialog->Execute();
 }
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+class TUsageStatisticsDialog : public TCustomDialog
+{
+public:
+  __fastcall TUsageStatisticsDialog();
+
+protected:
+  virtual void __fastcall DoChange(bool & CanSubmit);
+
+private:
+  TEdit * FilterEdit;
+  TMemo * UsageMemo;
+  TButton * ClipboardButton;
+
+  void __fastcall ClipboardButtonClick(TObject * Sender);
+};
+//---------------------------------------------------------------------------
+__fastcall TUsageStatisticsDialog::TUsageStatisticsDialog() :
+  TCustomDialog(HELP_USAGE)
+{
+  Caption = LoadStr(USAGE_CAPTION);
+  Width = ScaleByTextHeight(this, 400);
+
+  TLabel * Label = new TLabel(this);
+  // UnformatMessage is called, because previously, ** markup was used and translations may still contain that
+  Label->Caption = UnformatMessage(LoadStr(USAGE_DATA2));
+  AddText(Label);
+
+  FilterEdit = new TEdit(this);
+  FilterEdit->Width = ScaleByTextHeight(this, 250);
+  TLabel * FilterLabel = new TLabel(this);
+  FilterLabel->Caption = LoadStr(USAGE_FILTER);
+  AddEdit(FilterEdit, FilterLabel, true);
+
+  UsageMemo = new TMemo(this);
+  UsageMemo->Height = ScaleByTextHeight(this, 300);
+  UsageMemo->ScrollBars = ssVertical;
+  AddEdit(UsageMemo, NULL);
+  ReadOnlyControl(UsageMemo);
+
+  ClipboardButton = new TButton(this);
+  ClipboardButton->Caption = LoadStr(USAGE_COPY);
+  ClipboardButton->Width = ScaleByTextHeight(this, 121);
+  ClipboardButton->OnClick = ClipboardButtonClick;
+  AddDialogButton(ClipboardButton);
+
+  RemoveCancelButton();
+}
+//---------------------------------------------------------------------------
+void __fastcall TUsageStatisticsDialog::ClipboardButtonClick(TObject * /*Sender*/)
+{
+  TInstantOperationVisualizer Visualizer;
+  CopyToClipboard(UsageMemo->Lines);
+}
+//---------------------------------------------------------------------------
+void __fastcall TUsageStatisticsDialog::DoChange(bool & CanSubmit)
+{
+  TCustomDialog::DoChange(CanSubmit);
+  UnicodeString Text = Configuration->Usage->Serialize(L"\n", FilterEdit->Text);
+  bool NoUsage = Text.IsEmpty();
+  ClipboardButton->Enabled = !NoUsage;
+  if (NoUsage)
+  {
+    Text = LoadStr(USAGE_DATA_NONE2);
+  }
+  UsageMemo->Lines->Text = Text;
+}
+//---------------------------------------------------------------------------
+void __fastcall DoUsageStatisticsDialog()
+{
+  std::unique_ptr<TUsageStatisticsDialog> Dialog(new TUsageStatisticsDialog());
+  Dialog->Execute();
+}

+ 4 - 1
source/forms/Custom.h

@@ -46,7 +46,7 @@ public:
   TLabel * __fastcall CreateLabel(UnicodeString Label);
   TCheckBox * __fastcall CreateAndAddCheckBox(const UnicodeString & Caption);
   void __fastcall AddEditLikeControl(TWinControl * Edit, TLabel * Label, bool OneLine = false);
-  void __fastcall AddEdit(TCustomEdit * Edit, TLabel * Label);
+  void __fastcall AddEdit(TCustomEdit * Edit, TLabel * Label, bool OneLine = false);
   void __fastcall AddComboBox(TCustomCombo * Combo, TLabel * Label, TStrings * Items = NULL, bool OneLine = false);
   void __fastcall AddButtonControl(TButtonControl * Control);
   void __fastcall AddImage(const UnicodeString & ImageName);
@@ -55,6 +55,9 @@ public:
   void __fastcall AddText(TStaticText * Label);
   void __fastcall AddSeparator();
 
+  void __fastcall AddDialogButton(TButton * Button);
+  void __fastcall RemoveCancelButton();
+
   void __fastcall ScaleButtonControl(TButtonControl * Control);
   TWinControl * __fastcall GetDefaultParent();
   __property int HorizontalMargin = { read = FHorizontalMargin };

+ 1 - 4
source/forms/Preferences.cpp

@@ -2272,10 +2272,7 @@ void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
 //---------------------------------------------------------------------------
 void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
 {
-  std::unique_ptr<TStrings> Data(TextToStringList(GetUsageData()));
-  UnicodeString Message =
-    Data->Text.IsEmpty() ? MainInstructions(LoadStr(USAGE_DATA_NONE)) : LoadStr(USAGE_DATA2);
-  MoreMessageDialog(Message, Data.get(), qtInformation, qaOK, HELP_USAGE);
+  DoUsageStatisticsDialog();
 }
 //---------------------------------------------------------------------------
 void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)

+ 4 - 1
source/resource/TextsWin.h

@@ -231,7 +231,7 @@
 #define MASK_HELP               1521
 #define UTF8_NAME               1522
 #define USAGE_DATA2             1523
-#define USAGE_DATA_NONE         1524
+#define USAGE_DATA_NONE2        1524
 #define SHORTCUT_INFO_TIP_FOLDER 1525
 #define SHORTCUT_INFO_TIP_WORKSPACE 1526
 #define JUMPLIST_WORKSPACES     1527
@@ -591,6 +591,9 @@
 #define EXTENSION_SESSIONLOG_FILE 1980
 #define EXTENSION_SESSIONLOG_CAPTION 1981
 #define EXTENSION_SESSIONLOG_FILTER 1982
+#define USAGE_CAPTION           1983
+#define USAGE_FILTER            1984
+#define USAGE_COPY              1985
 
 // 2xxx is reserved for TextsFileZilla.h
 

+ 5 - 2
source/resource/TextsWin1.rc

@@ -232,8 +232,8 @@ BEGIN
         FILE_MASK_EX_HINT, ">size matches file larger than size\n<size matches file smaller than size\n>yyyy-mm-dd matches file modified after the date\n<yyyy-mm-dd matches file modified before the date\nExample: *.zip>1G; <2012-01-21"
         MASK_HELP, "See help for more options."
         UTF8_NAME, "UTF-8"
-        USAGE_DATA2, "**Following usage statistics data is anonymously sent to WinSCP team.**\n\nOver the time other metrics can be collected, please come back later to check or consult Help."
-        USAGE_DATA_NONE, "There is no usage statistics data collected yet. Please try again later or consult Help."
+        USAGE_DATA2, "Following usage statistics data is anonymously sent to WinSCP team.\n\nOver the time other metrics can be collected, please come back later to check or consult Help."
+        USAGE_DATA_NONE2, "There is no matching usage statistics data collected yet. Please try again later or consult Help."
         SHORTCUT_INFO_TIP_FOLDER, "Opens site folder '%s'"
         SHORTCUT_INFO_TIP_WORKSPACE, "Opens workspace '%s'"
         JUMPLIST_WORKSPACES, "Recent Workspaces"
@@ -594,6 +594,9 @@ BEGIN
         EXTENSION_SESSIONLOG_FILE, "&Session log file:"
         EXTENSION_SESSIONLOG_CAPTION, "Select file for session log"
         EXTENSION_SESSIONLOG_FILTER, "Session log files (*.log)|*.log|All files (*.*)|*.*"
+        USAGE_CAPTION, "Usage Statistics"
+        USAGE_FILTER, "&Filter:"
+        USAGE_COPY, "&Copy to Clipboard"
 
         WIN_VARIABLE_STRINGS, "WIN_VARIABLE"
         WINSCP_COPYRIGHT, "Copyright © 2000-2016 Martin Prikryl"

+ 1 - 6
source/windows/Setup.cpp

@@ -789,11 +789,6 @@ UnicodeString __fastcall CampaignUrl(UnicodeString URL)
   return AppendUrlParams(URL, Params);
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall GetUsageData()
-{
-  return Configuration->Usage->Serialize();
-}
-//---------------------------------------------------------------------------
 UnicodeString __fastcall ProgramUrl(UnicodeString URL)
 {
   TVSFixedFileInfo * FileInfo = Configuration->FixedApplicationInfo;
@@ -910,7 +905,7 @@ static bool __fastcall DoQueryUpdates(TUpdatesConfiguration & Updates, bool Coll
     {
       if (CollectUsage)
       {
-        UnicodeString Usage = GetUsageData();
+        UnicodeString Usage = Configuration->Usage->Serialize();
 
         CheckForUpdatesHTTP->Post(Usage);
       }

+ 0 - 1
source/windows/Setup.h

@@ -14,7 +14,6 @@ void __fastcall GetUpdatesMessage(UnicodeString & Message, bool & New, TQueryTyp
 bool __fastcall CheckForUpdates(bool CachedResults);
 bool __fastcall QueryUpdates(TUpdatesConfiguration & Updates);
 UnicodeString __fastcall FormatUpdatesMessage(UnicodeString Message);
-UnicodeString __fastcall GetUsageData();
 UnicodeString __fastcall GetEnableAutomaticUpdatesUrl();
 void __fastcall EnableAutomaticUpdates();
 void __fastcall RegisterForDefaultProtocols();

+ 1 - 0
source/windows/WinInterface.h

@@ -137,6 +137,7 @@ bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
 bool __fastcall DoCustomCommandOptionsDialog(
   const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags,
   TCustomCommand * CustomCommandForOptions, const UnicodeString & Site);
+void __fastcall DoUsageStatisticsDialog();
 
 // windows\UserInterface.cpp
 bool __fastcall DoMasterPasswordDialog();