ImportSessions.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ImportSessions.h"
  5. #include <Configuration.h>
  6. #include <ScpMain.h>
  7. #include <VCLCommon.h>
  8. //---------------------------------------------------------------------
  9. #pragma resource "*.dfm"
  10. //---------------------------------------------------------------------
  11. Boolean __fastcall DoImportSessionsDialog(TStoredSessionList *SessionList)
  12. {
  13. Boolean Result;
  14. TImportSessionsDialog *ImportSessionsDialog;
  15. TStoredSessionList *ImportSessionList;
  16. try {
  17. ImportSessionsDialog = new TImportSessionsDialog(Application);
  18. ImportSessionList = new TStoredSessionList(true);
  19. ImportSessionList->Load(Configuration->PuttySessionsKey);
  20. ImportSessionList->SelectSessionsToImport(SessionList, True);
  21. ImportSessionsDialog->SessionList = ImportSessionList;
  22. Result = (ImportSessionsDialog->ShowModal() == mrOk);
  23. if (Result)
  24. SessionList->Import(ImportSessionsDialog->SessionList, True);
  25. } __finally {
  26. delete ImportSessionsDialog;
  27. delete ImportSessionList;
  28. }
  29. return Result;
  30. }
  31. //---------------------------------------------------------------------
  32. __fastcall TImportSessionsDialog::TImportSessionsDialog(TComponent* AOwner)
  33. : TForm(AOwner)
  34. {
  35. UseSystemSettings(this);
  36. }
  37. //---------------------------------------------------------------------
  38. void __fastcall TImportSessionsDialog::UpdateControls()
  39. {
  40. Boolean Checked = False;
  41. for (Integer Index = 0; Index < SessionListView->Items->Count; Index ++)
  42. if (SessionListView->Items->Item[Index]->Checked) Checked = True;
  43. EnableControl(OKButton, Checked);
  44. AdjustListColumnsWidth(SessionListView);
  45. }
  46. //---------------------------------------------------------------------
  47. void __fastcall TImportSessionsDialog::SetSessionList(TStoredSessionList *value)
  48. {
  49. if (FSessionList != value)
  50. {
  51. FSessionList = value;
  52. LoadSessions();
  53. }
  54. }
  55. //---------------------------------------------------------------------
  56. void TImportSessionsDialog::LoadSessions()
  57. {
  58. SessionListView->Items->BeginUpdate();
  59. try {
  60. SessionListView->Items->Clear();
  61. if (FSessionList)
  62. for (int Index = 0; Index < FSessionList->Count; Index++)
  63. {
  64. TListItem *Item;
  65. TSessionData *Session =
  66. (TSessionData*)FSessionList->AtObject(Index);
  67. Item = SessionListView->Items->Add();
  68. Item->Data = Session;
  69. Item->Caption = Session->Name;
  70. Item->SubItems->Add(Session->ProtocolStr);
  71. Item->Checked = Session->Selected;
  72. }
  73. } __finally {
  74. SessionListView->Items->EndUpdate();
  75. }
  76. UpdateControls();
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TImportSessionsDialog::FormClose(TObject * /*Sender*/,
  80. TCloseAction & /*Action*/)
  81. {
  82. for (Integer Index = 0; Index < SessionListView->Items->Count; Index++)
  83. ((TSessionData*)SessionListView->Items->Item[Index]->Data)->Selected =
  84. SessionListView->Items->Item[Index]->Checked;
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TImportSessionsDialog::SessionListViewInfoTip(
  88. TObject * /*Sender*/, TListItem * Item, AnsiString & InfoTip)
  89. {
  90. InfoTip = ((TSessionData*)Item->Data)->InfoTip;
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TImportSessionsDialog::SessionListViewMouseDown(
  94. TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState /*Shift*/,
  95. int /*X*/, int /*Y*/)
  96. {
  97. UpdateControls();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TImportSessionsDialog::SessionListViewKeyUp(
  101. TObject * /*Sender*/, WORD & /*Key*/, TShiftState /*Shift*/)
  102. {
  103. UpdateControls();
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TImportSessionsDialog::FormShow(TObject * /*Sender*/)
  107. {
  108. UpdateControls();
  109. }
  110. //---------------------------------------------------------------------------