LogSettings.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "LogSettings.h"
  6. #include <CoreMain.h>
  7. #include <TextsWin.h>
  8. #include <VCLCommon.h>
  9. #include <Tools.h>
  10. #include "CustomWinConfiguration.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "ComboEdit"
  14. #pragma link "UpDownEdit"
  15. #ifndef NO_RESOURCES
  16. #pragma resource "*.dfm"
  17. #endif
  18. TLoggingFrame *LoggingFrame;
  19. //---------------------------------------------------------------------------
  20. __fastcall TLoggingFrame::TLoggingFrame(TComponent* Owner)
  21. : TFrame(Owner)
  22. {
  23. FEnableLogWindow = true;
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TLoggingFrame::Init()
  27. {
  28. InstallPathWordBreakProc(LogFileNameEdit2);
  29. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT2));
  30. // anchors does not apply for some reason to this particular control
  31. LogFileNameHintText->Left = LogFileNameEdit2->Left + LogFileNameEdit2->Width -
  32. LogFileNameHintText->Width;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TLoggingFrame::LoadConfiguration()
  36. {
  37. //Log tab
  38. LoggingOffButton->Checked = !Configuration->Logging;
  39. LoggingOnButton->Checked = Configuration->Logging && !Configuration->LogActions;
  40. LoggingActionsButton->Checked = Configuration->Logging && Configuration->LogActions;
  41. LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
  42. LogToFileCheck->Checked = Configuration->LogToFile;
  43. LogFileNameEdit2->Text = Configuration->LogFileName;
  44. if (Configuration->LogFileAppend)
  45. LogFileAppendButton->Checked = True;
  46. else
  47. LogFileOverwriteButton->Checked = True;
  48. LogShowWindowCheck->Checked = (CustomWinConfiguration->LogView == lvWindow);
  49. if (Configuration->LogWindowComplete)
  50. LogWindowCompleteButton->Checked = True;
  51. else
  52. LogWindowLinesButton->Checked = True;
  53. if (!Configuration->LogWindowComplete)
  54. LogWindowLinesEdit->AsInteger = Configuration->LogWindowLines;
  55. else
  56. LogWindowLinesEdit->AsInteger = 500;
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TLoggingFrame::SaveConfiguration()
  60. {
  61. Configuration->BeginUpdate();
  62. try
  63. {
  64. Configuration->Logging = LoggingOnButton->Checked || LoggingActionsButton->Checked;
  65. Configuration->LogActions = LoggingActionsButton->Checked;
  66. Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
  67. Configuration->LogToFile = LogToFileCheck->Checked;
  68. if (LogToFileCheck->Checked)
  69. {
  70. Configuration->LogFileName = LogFileNameEdit2->Text;
  71. }
  72. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  73. if (EnableLogWindow)
  74. {
  75. CustomWinConfiguration->LogView = LogShowWindowCheck->Checked ? lvWindow : lvNone;
  76. Configuration->LogWindowComplete = LogWindowCompleteButton->Checked;
  77. if (!LogWindowCompleteButton->Checked)
  78. {
  79. Configuration->LogWindowLines = LogWindowLinesEdit->AsInteger;
  80. }
  81. }
  82. }
  83. __finally
  84. {
  85. Configuration->EndUpdate();
  86. }
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TLoggingFrame::UpdateControls()
  90. {
  91. if (!LoggingOnButton->Checked && !LoggingActionsButton->Checked)
  92. {
  93. EnableControl(LoggingGroup, False);
  94. }
  95. else
  96. {
  97. LoggingGroup->Enabled = True;
  98. EnableControl(LogProtocolCombo, LoggingOnButton->Checked);
  99. EnableControl(LogProtocolLabel, LogProtocolCombo->Enabled);
  100. EnableControl(LogToFileCheck, True);
  101. EnableControl(LogFileNameEdit2, LogToFileCheck->Checked);
  102. EnableControl(LogFileNameHintText, LogFileNameEdit2->Enabled);
  103. EnableControl(LogFileAppendButton, LogFileNameEdit2->Enabled && LoggingOnButton->Checked);
  104. EnableControl(LogFileOverwriteButton, LogFileNameEdit2->Enabled && LoggingOnButton->Checked);
  105. EnableControl(LogFilePanel, LogToFileCheck->Checked);
  106. EnableControl(LogShowWindowCheck, True && EnableLogWindow);
  107. EnableControl(LogWindowCompleteButton, LogShowWindowCheck->Checked && EnableLogWindow);
  108. EnableControl(LogWindowLinesButton, LogShowWindowCheck->Checked && EnableLogWindow);
  109. EnableControl(LogWindowLinesText, LogShowWindowCheck->Checked && EnableLogWindow);
  110. EnableControl(LogWindowLinesEdit, LogShowWindowCheck->Checked &&
  111. LogWindowLinesButton->Checked && EnableLogWindow);
  112. }
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TLoggingFrame::LogToFileCheckChange(TObject * /*Sender*/)
  116. {
  117. if (LogToFileCheck->Checked && LogFileNameEdit2->Text.IsEmpty())
  118. {
  119. LogFileNameEdit2->Text =
  120. IncludeTrailingBackslash(SystemTemporaryDirectory()) + "!s." + GetLogFileExt();
  121. }
  122. UpdateControls();
  123. }
  124. //---------------------------------------------------------------------------
  125. void __fastcall TLoggingFrame::DataChange(TObject * /*Sender*/)
  126. {
  127. UpdateControls();
  128. }
  129. //---------------------------------------------------------------------------
  130. AnsiString __fastcall TLoggingFrame::GetLogFileExt()
  131. {
  132. return (LoggingOnButton->Checked ? "log" : "xml");
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TLoggingFrame::SetEnableLogWindow(bool value)
  136. {
  137. if (EnableLogWindow != value)
  138. {
  139. FEnableLogWindow = value;
  140. UpdateControls();
  141. }
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TLoggingFrame::LogFileNameEdit2BeforeDialog(TObject * /*Sender*/,
  145. AnsiString & Name, bool & /*Action*/)
  146. {
  147. FBeforeDialogPath = Name;
  148. Name = ExpandEnvironmentVariables(Name);
  149. LogFileNameEdit2->DefaultExt = GetLogFileExt();
  150. }
  151. //---------------------------------------------------------------------------
  152. void __fastcall TLoggingFrame::LogFileNameEdit2AfterDialog(TObject * /*Sender*/,
  153. AnsiString & Name, bool & /*Action*/)
  154. {
  155. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  156. {
  157. Name = FBeforeDialogPath;
  158. }
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TLoggingFrame::LogFileNameEdit2CreateEditDialog(
  162. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  163. {
  164. USEDPARAM(DialogKind);
  165. assert(DialogKind == dkOpen);
  166. Dialog = CreateOpenDialog(dynamic_cast<TComponent *>(Sender));
  167. }
  168. //---------------------------------------------------------------------------
  169. void __fastcall TLoggingFrame::LoggingButtonClick(TObject * /*Sender*/)
  170. {
  171. if (LoggingOnButton->Checked || LoggingActionsButton->Checked)
  172. {
  173. AnsiString Ext = ExtractFileExt(LogFileNameEdit2->Text);
  174. if (AnsiSameText(Ext, ".log") || AnsiSameText(Ext, ".xml"))
  175. {
  176. AnsiString NewExt = AnsiString(".") + GetLogFileExt();
  177. if (!AnsiSameText(Ext, NewExt))
  178. {
  179. LogFileNameEdit2->Text = ChangeFileExt(LogFileNameEdit2->Text, NewExt);
  180. }
  181. }
  182. }
  183. UpdateControls();
  184. }
  185. //---------------------------------------------------------------------------