NCBI C++ ToolKit
app_packages_dlg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: app_packages_dlg.cpp 47464 2023-04-20 00:19:10Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 #include "wx/imaglist.h"
36 ////@end includes
37 
43 
44 #include <corelib/ncbidll.hpp>
45 
46 #include <wx/sizer.h>
47 #include <wx/button.h>
48 #include <wx/bitmap.h>
49 #include <wx/icon.h>
50 #include <wx/checkbox.h>
51 #include <wx/msgdlg.h>
52 #include <wx/sstream.h>
53 #include <wx/txtstrm.h>
54 
56 
57 ////@begin XPM images
58 ////@end XPM images
59 
60 IMPLEMENT_DYNAMIC_CLASS( CAppPackagesDlg, CDialog )
61 
62 BEGIN_EVENT_TABLE( CAppPackagesDlg, CDialog )
63 
64 ////@begin CAppPackagesDlg event table entries
65  EVT_LIST_ITEM_SELECTED( ID_LISTCTRL1, CAppPackagesDlg::OnPackageSelected )
68  EVT_BUTTON( wxID_OK, CAppPackagesDlg::OnOkClick )
69 ////@end CAppPackagesDlg event table entries
70 
72 
73 CAppPackagesDlg::CAppPackagesDlg() : m_PkgManager()
74 {
75  Init();
76 }
77 
78 CAppPackagesDlg::CAppPackagesDlg( wxWindow* parent, CPkgManager* pkgManager, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
79  : m_PkgManager(pkgManager)
80 {
81  Init();
82  Create(parent, id, caption, pos, size, style);
83 }
84 
85 bool CAppPackagesDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin CAppPackagesDlg creation
88  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
89  CDialog::Create( parent, id, caption, pos, size, style );
90 
92  if (GetSizer())
93  {
94  GetSizer()->SetSizeHints(this);
95  }
96  Centre();
97 ////@end CAppPackagesDlg creation
98  return true;
99 }
100 
102 {
103 ////@begin CAppPackagesDlg destruction
104 ////@end CAppPackagesDlg destruction
105 }
106 
108 {
109 ////@begin CAppPackagesDlg member initialisation
110  m_PkgList = NULL;
111  m_PkgInfo = NULL;
112  m_PkgEnable = NULL;
113 ////@end CAppPackagesDlg member initialisation
114 }
115 
117 {
118 ////@begin CAppPackagesDlg content construction
119  // Generated by DialogBlocks, 13/05/2019 15:23:06 (unregistered)
120 
121  CAppPackagesDlg* itemCDialog1 = this;
122 
123  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
124  itemCDialog1->SetSizer(itemBoxSizer2);
125 
126  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
127  itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 0);
128 
129  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
130  itemBoxSizer3->Add(itemBoxSizer4, 2, wxGROW|wxALL, 0);
131 
132  m_PkgList = new wxListCtrl( itemCDialog1, ID_LISTCTRL1, wxDefaultPosition, wxDLG_UNIT(itemCDialog1, wxSize(120, 110)), wxLC_REPORT|wxLC_SINGLE_SEL );
133  itemBoxSizer4->Add(m_PkgList, 1, wxGROW|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
134 
135  wxCheckBox* itemCheckBox6 = new wxCheckBox( itemCDialog1, ID_CHECKBOX1, _("Show invalid packages"), wxDefaultPosition, wxDefaultSize, 0 );
136  itemCheckBox6->SetValue(false);
137  itemBoxSizer4->Add(itemCheckBox6, 0, wxALIGN_LEFT|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
138 
139  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxVERTICAL);
140  itemBoxSizer3->Add(itemBoxSizer7, 3, wxGROW|wxALL, 0);
141 
142  m_PkgInfo = new wxTextCtrl( itemCDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
143  itemBoxSizer7->Add(m_PkgInfo, 1, wxGROW|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
144 
145  m_PkgEnable = new wxCheckBox( itemCDialog1, ID_CHECKBOX2, _("Enable"), wxDefaultPosition, wxDefaultSize, 0 );
146  m_PkgEnable->SetValue(false);
147  itemBoxSizer7->Add(m_PkgEnable, 0, wxALIGN_LEFT|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
148 
149  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemCDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
150  itemBoxSizer2->Add(itemStaticLine10, 0, wxGROW|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
151 
152  wxStdDialogButtonSizer* itemStdDialogButtonSizer11 = new wxStdDialogButtonSizer;
153 
154  itemBoxSizer2->Add(itemStdDialogButtonSizer11, 0, wxALIGN_RIGHT|wxALL, wxDLG_UNIT(itemCDialog1, wxSize(5, -1)).x);
155  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
156  itemStdDialogButtonSizer11->AddButton(itemButton12);
157 
158  wxButton* itemButton13 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
159  itemStdDialogButtonSizer11->AddButton(itemButton13);
160 
161  itemStdDialogButtonSizer11->Realize();
162 
163 ////@end CAppPackagesDlg content construction
164 
165  m_PkgList->InsertColumn(0, wxT("Package"));
166  m_PkgList->InsertColumn(1, wxT("Status"));
167 
168  x_LoadPkgList(true);
169 }
170 
171 void CAppPackagesDlg::x_LoadPkgList(bool firstTime)
172 {
173  m_CurPkg.clear();
174 
175  wxCheckBox* itemCheckBox1 = (wxCheckBox*)FindWindow(ID_CHECKBOX1);
176  bool showInvalid = itemCheckBox1->GetValue();
177 
178  m_PkgList->DeleteAllItems();
179  m_PkgInfo->ChangeValue(wxT(""));
180  wxCheckBox* itemCheckBox2 = (wxCheckBox*)FindWindow(ID_CHECKBOX2);
181  itemCheckBox2->Enable(false);
182  itemCheckBox2->SetValue(false);
183 
184  long pkg_num = 0;
186  const CPackageInfo& pkg_info = it->second;
187  if (!showInvalid && pkg_info.m_State == CPackageInfo::eNotValid)
188  continue;
189 
190  const objects::CGuiPkgManifest* manifest = pkg_info.m_Manifest.GetPointer();
191  if (manifest) {
192  long index = m_PkgList->InsertItem(m_PkgList->GetItemCount(),
193  ToWxString(manifest->GetName()));
194 
195  switch(pkg_info.m_State) {
197  m_PkgList->SetItem(index, 1, wxT("Not loaded"));
198  break;
199  case CPackageInfo::eLoaded :
200  m_PkgList->SetItem(index, 1, wxT("Loaded"));
201  break;
203  m_PkgList->SetItem(index, 1, wxT("Not valid"));
204  break;
205  default :
206  m_PkgList->SetItem(index, 1, wxT("Undefined"));
207  break;
208  }
209 
210  m_PkgList->SetItemData(index, pkg_num);
211 
212  if (firstTime && pkg_info.m_State == CPackageInfo::eLoaded)
213  m_EnabledPkgs.insert(it->first);
214  }
215  else {
216  long index = m_PkgList->InsertItem(0, ToWxString(it->first));
217  m_PkgList->SetItem(index, 1, wxT("App"));
218  m_PkgList->SetItemData(index, pkg_num);
219  }
220  ++pkg_num;
221  }
222  m_PkgList->SetColumnWidth(0, wxLIST_AUTOSIZE);
223 }
224 
226 {
227  return true;
228 }
229 wxBitmap CAppPackagesDlg::GetBitmapResource( const wxString& name )
230 {
231  // Bitmap retrieval
232 ////@begin CAppPackagesDlg bitmap retrieval
233  wxUnusedVar(name);
234  return wxNullBitmap;
235 ////@end CAppPackagesDlg bitmap retrieval
236 }
237 wxIcon CAppPackagesDlg::GetIconResource( const wxString& name )
238 {
239  // Icon retrieval
240 ////@begin CAppPackagesDlg icon retrieval
241  wxUnusedVar(name);
242  return wxNullIcon;
243 ////@end CAppPackagesDlg icon retrieval
244 }
245 
246 void CAppPackagesDlg::OnPackageSelected( wxListEvent& event )
247 {
248  auto index = event.GetIndex();
249  int pkg_num = (int)m_PkgList->GetItemData(index);
250  string pkg_name;
251  const CPackageInfo* pkg_info = m_PkgManager->GetPkgInfo(pkg_num, pkg_name);
252 
253  m_CurPkg = pkg_name;
254 
255  string version = "Version: ";
256  string descr = "Description: ";
257  wxCheckBox* itemCheckBox = (wxCheckBox*)FindWindow(ID_CHECKBOX2);
258 
259  if (!pkg_info) {
260  m_PkgInfo->ChangeValue(wxT(""));
261  itemCheckBox->SetValue(false);
262  itemCheckBox->Enable(false);
263  }
264  else {
265  wxStringOutputStream strstr;
266  wxTextOutputStream os(strstr);
267  x_DumpPkgInfo(os, pkg_name, *pkg_info);
268  m_PkgInfo->ChangeValue(strstr.GetString());
269 
270  const objects::CGuiPkgManifest* manifest = pkg_info->m_Manifest.GetPointer();
271  if (!manifest) { // Application
272  itemCheckBox->Enable(false);
273  itemCheckBox->SetValue(true);
274  }
275  else {
276  switch(pkg_info->m_State) {
278  case CPackageInfo::eLoaded :
279  itemCheckBox->Enable(true);
280  itemCheckBox->SetValue(m_EnabledPkgs.find(m_CurPkg) != m_EnabledPkgs.end());
281  break;
282  default :
283  itemCheckBox->Enable(false);
284  itemCheckBox->SetValue(false);
285  break;
286  }
287  }
288  }
289 }
290 
291 #if wxUSE_UNICODE
292 inline wxTextOutputStream& operator <<( wxTextOutputStream& os, const string& str )
293 {
294  return os << wxString::FromAscii(str.c_str());
295 }
296 #endif
297 
298 void CAppPackagesDlg::x_DumpPkgInfo(wxTextOutputStream& os, const string& name, const CPackageInfo& pkg_info)
299 {
300  const objects::CGuiPkgManifest* manifest = pkg_info.m_Manifest.GetPointer();
301 
302  if (!manifest) { // Application entry
303  os << wxT("Package: ") << name << endl;
304  os << wxT("Description: ") << name << wxT(" application") << endl;
305  os << wxT("Version: ") << wxString::Format(wxT("%02d.%02d.%04d"),
306  (int)pkg_info.m_VerMajor,
307  (int)pkg_info.m_VerMinor,
308  (int)pkg_info.m_VerPatch) << endl;
309  }
310  else {
311  os << wxT("Package: ") << manifest->GetName() << endl;
312  os << wxT("Description: ") << manifest->GetDescription() << endl;
313  os << wxT("Version: ");
314 
315  if (pkg_info.m_State == CPackageInfo::eLoaded)
316  os << wxString::Format(wxT("%02d.%02d.%04d"),
317  (int)pkg_info.m_VerMajor,
318  (int)pkg_info.m_VerMinor,
319  (int)pkg_info.m_VerPatch);
320  else
321  os << manifest->GetVersion();
322 
323  os << endl << endl;
324 
325  if (pkg_info.m_State != CPackageInfo::eValidated &&
326  pkg_info.m_State != CPackageInfo::eLoaded) {
327  os << wxT("ERROR: ") << pkg_info.m_ErrMsg;
328  os << endl << endl;
329  }
330 
331  os << wxT("Dll: ") << string(NCBI_PLUGIN_PREFIX) << manifest->GetMainDll() << string(NCBI_PLUGIN_SUFFIX) << endl;
332  os << wxT("Dir: ") << pkg_info.m_Dir << endl;
333  os << wxT("Depends on: ") << endl;
334  const objects::CGuiPkgManifest::TGuiPkgDependency& deps = manifest->GetGuiPkgDependency();
335  ITERATE(objects::CGuiPkgManifest::TGuiPkgDependency, it2, deps) {
336  const objects::CGuiDependentPkg& pkg = (*it2)->GetGuiDependentPkg();
337  os << wxT(" ") << pkg.GetName() << wxT(" ") << pkg.GetVersion() << endl;
338  }
339  }
340 }
341 
342 void CAppPackagesDlg::OnShowInvalidPkgs( wxCommandEvent& WXUNUSED(event) )
343 {
344  x_LoadPkgList();
345 }
346 
347 void CAppPackagesDlg::OnEnablePkg( wxCommandEvent& event )
348 {
349  if (event.IsChecked()) {
350  vector<string> basePkgs;
351  m_PkgManager->GetBasePkgs(m_CurPkg, basePkgs);
353  ITERATE(vector<string>, it, basePkgs)
354  m_EnabledPkgs.insert(*it);
355  }
356  else {
357  vector<string> dependents;
358  m_PkgManager->GetDependentPkgs(m_CurPkg, dependents);
360  ITERATE(vector<string>, it, dependents)
361  m_EnabledPkgs.erase(*it);
362  }
363 }
364 
365 void CAppPackagesDlg::OnOkClick( wxCommandEvent& event )
366 {
367  vector<string> loadPkgs;
368  back_insert_iterator<vector<string> > dest(loadPkgs);
370  m_PkgManager->SetPackagesToLoad(loadPkgs);
371 
372  wxMessageBox(wxT("Changes will take effect when you restart Genome Workbench."),
373  SYMBOL_CAPPPACKAGESDLG_TITLE, wxOK|wxICON_INFORMATION);
374 
375  event.Skip();
376 }
377 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
#define ID_CHECKBOX2
CDialog.
Definition: dialog.hpp:47
CPkgManager - application Package Manager.
Definition: pkg_manager.hpp:85
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
CNcbiOstream & operator<<(CNcbiOstream &out, const CEquivRange &range)
Definition: equiv_range.cpp:96
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_PLUGIN_SUFFIX
Definition: ncbidll.hpp:67
#define NCBI_PLUGIN_PREFIX
Definition: ncbidll.hpp:57
CConstRef< objects::CGuiPkgManifest > m_Manifest
Definition: pkg_manager.hpp:77
wxCheckBox * m_PkgEnable
void OnShowInvalidPkgs(wxCommandEvent &event)
void GetDependentPkgs(const string &pkg_name, vector< string > &dependents) const
wxString m_Dir
Definition: pkg_manager.hpp:71
static void x_DumpPkgInfo(wxTextOutputStream &os, const string &name, const CPackageInfo &pkg_info)
size_t m_VerMinor
Definition: pkg_manager.hpp:74
void OnOkClick(wxCommandEvent &event)
const CPackageInfo * GetPkgInfo(int index, string &pkg_name) const
wxTextCtrl * m_PkgInfo
bool Create(wxWindow *parent, wxWindowID id=ID_CAPPPACKAGESDLG, const wxString &caption=_("Configure Packages"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
static bool ShowToolTips()
void x_LoadPkgList(bool firstTime=false)
void OnPackageSelected(wxListEvent &event)
void GetBasePkgs(const string &pkg_name, vector< string > &basePkgs) const
void SetPackagesToLoad(const vector< string > &packages)
size_t m_VerMajor
Definition: pkg_manager.hpp:73
string m_ErrMsg
Definition: pkg_manager.hpp:76
wxListCtrl * m_PkgList
size_t m_VerPatch
Definition: pkg_manager.hpp:75
CPkgManager * m_PkgManager
set< string > m_EnabledPkgs
#define ID_LISTCTRL1
Definition: diag_panel.hpp:69
wxIcon GetIconResource(const wxString &name)
EPackageState m_State
Definition: pkg_manager.hpp:72
#define SYMBOL_CAPPPACKAGESDLG_TITLE
void OnEnablePkg(wxCommandEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const string version
version string
Definition: variables.hpp:66
const struct ncbi::grid::netcache::search::fields::SIZE size
Define class Dll and for Portable DLL handling.
Format
Definition: njn_ioutil.hpp:52
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
#define ID_CHECKBOX1
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:57:35 2024 by modify_doxy.py rev. 669887