NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
PackageRepoBrowser Class Reference

This class represents a simple browser for the package repository with an install and uninstall capability. More...

#include <pluginrepodialog.hpp>

Inheritance diagram for PackageRepoBrowser:
Collaboration diagram for PackageRepoBrowser:

Public Member Functions

 PackageRepoBrowser (wxWindow *parent, NumeReTerminal *terminal, IconManager *icons)
 PackageRepositoryBrowser constructor. Starts the file loading task. More...
 
void DetectInstalledPackages ()
 Detect installed packages by loading the list of installed and comparing them to the loaded contents from the repository. More...
 
- Public Member Functions inherited from ViewerFrame
 ViewerFrame (wxWindow *parent, const wxString &title)
 
void OnKeyDown (wxKeyEvent &event)
 This event handler closes the frame, if the user presses ESC. More...
 
void OnFocus (wxFocusEvent &event)
 This event handler passes the keyboard focus down to the first child in the window list, if the frame gets keyboard focus. More...
 
void OnEnter (wxMouseEvent &event)
 This event handler get the keyboard focus, if the user enters with the mouse. More...
 
void OnClose (wxCloseEvent &event)
 This event handler informs all child windows that this frame will now close. It furthermore automatically unregisters itself in the opened window list. More...
 
 DECLARE_EVENT_TABLE ()
 

Private Types

enum  ThreadTask { TASK_NONE , TASK_LOADREPO , TASK_LOADFILES }
 

Private Member Functions

void StartThread (ThreadTask task)
 Start a new thread with the passed task. More...
 
virtual wxThread::ExitCode Entry ()
 Secondary thread worker function. More...
 
void OnThreadUpdate (wxThreadEvent &event)
 Thread update event handler. Will trigger the actual installation, if the files were loaded successfully. More...
 
void OnClose (wxCloseEvent &event)
 OnClose event handler. Will terminate the thread, if it's running. More...
 
std::vector< std::string > getRepoList (const std::string &sRepoUrl)
 This member function fetches the repository main page as HTML and extracts the list of item links in it. These may be files and folders. More...
 
void populatePackageList (const std::string &sUrl)
 Gets an URL and retrieve its counterpart from the repository. If the link does not reference a file but a folder, a recursion is started to resolve the contents of the folder. More...
 
void OnInstall (wxCommandEvent &event)
 Button event handler linked to the "install/update" button. More...
 
void OnUninstall (wxCommandEvent &event)
 Button event handler linked to the "uninstall" button. More...
 
void OnItemSelect (wxTreeEvent &event)
 Item select event handler to enable or disable the buttons depending on the state of the package or whether the actual package headline was selected. More...
 
std::string createSalt ()
 Simple function to make the URL more unique to avoid server caching (which might resolve in a very delated update of the package list as the server will respond with the already cached contents rather than the current file versions). More...
 
bool isInstallable (const wxTreeItemId &item)
 Returns, whether the current item is an installable package (not already installed). More...
 
bool isUpdateable (const wxTreeItemId &item)
 Returns, whether the current item is an updateable package (already installed but newer version available). More...
 
std::string getEntry (const wxTreeItemId &item, const std::string &sIdentifier)
 Returns the value of the selected identifier or an empty string, if the identifier cannot be found. More...
 
std::string getUrl (const wxTreeItemId &item)
 Return the package URL. More...
 
std::string getDependencies (const wxTreeItemId &item)
 Return the package dependencies. More...
 
wxTreeItemId findPackage (const std::string &sPackageFileName)
 Find a package entry from its file name. The returned ID must be checked for validness via wxTreeItemId::IsOk() to detect, if the package has been found. More...
 
void resolveDependencies (std::string sDepList, std::vector< std::string > &vDeps)
 This member function resolves the dependencies of a selected file using a recursion. Only files, which are updateable or installable are returned. Dependencies, which are not part of the repository, are ignored. More...
 
bool getFileFromRepo (const std::string &sUrl)
 Returns the contents of the passed URL as a file and writes it to its counterpart in the <SCRIPTPATH>/packages directory. More...
 

Private Attributes

NumeReTerminalm_terminal
 
IconManagerm_icons
 
std::string m_scriptPath
 
std::string m_fileNameToInstall
 
wxcode::wxTreeListCtrl * m_listCtrl
 
wxButton * m_installButton
 
wxButton * m_uninstallButton
 
wxGauge * m_progress
 
wxStaticText * m_statusText
 
ThreadTask m_task
 
bool m_filesLoaded
 
std::vector< std::string > m_vUrls
 

Detailed Description

This class represents a simple browser for the package repository with an install and uninstall capability.

Definition at line 37 of file pluginrepodialog.hpp.

Member Enumeration Documentation

◆ ThreadTask

Enumerator
TASK_NONE 
TASK_LOADREPO 
TASK_LOADFILES 

Definition at line 53 of file pluginrepodialog.hpp.

Constructor & Destructor Documentation

◆ PackageRepoBrowser()

PackageRepoBrowser::PackageRepoBrowser ( wxWindow *  parent,
NumeReTerminal terminal,
IconManager icons 
)

PackageRepositoryBrowser constructor. Starts the file loading task.

Parameters
parentwxWindow*
terminalNumeReTerminal*
iconsIconManager*

Definition at line 316 of file pluginrepodialog.cpp.

References GroupPanel::AddStaticText(), GroupPanel::CreateButton(), GroupPanel::CreateGauge(), GroupPanel::createGroup(), GroupPanel::CreateWxcTreeListCtrl(), IconManager::GetImageList(), GroupPanel::getMainSizer(), NumeReTerminal::getPathSettings(), ID_REPODLG_INSTALL, ID_REPODLG_UNINSTALL, m_filesLoaded, m_icons, m_installButton, m_listCtrl, m_progress, m_scriptPath, m_statusText, m_terminal, m_uninstallButton, SCRIPTPATH, StartThread(), TASK_LOADREPO, WINDOWHEIGHT, and WINDOWWIDTH.

Here is the call graph for this function:

Member Function Documentation

◆ createSalt()

std::string PackageRepoBrowser::createSalt ( )
private

Simple function to make the URL more unique to avoid server caching (which might resolve in a very delated update of the package list as the server will respond with the already cached contents rather than the current file versions).

Returns
std::string

Definition at line 974 of file pluginrepodialog.cpp.

Referenced by getRepoList(), and populatePackageList().

◆ DetectInstalledPackages()

void PackageRepoBrowser::DetectInstalledPackages ( )

Detect installed packages by loading the list of installed and comparing them to the loaded contents from the repository.

Returns
void

Definition at line 360 of file pluginrepodialog.cpp.

References CHANGELOGLENGTH, getEntry(), IconManager::GetIconIndex(), NumeReTerminal::getInstalledPackages(), INSTALLEDCOLOUR, INSTALLEDCOLUMN, LOCALCOLOUR, m_icons, m_listCtrl, m_progress, m_statusText, m_terminal, NEWERCOLOUR, OUTDATEDVERSIONCOLOUR, PACKAGCOLUMN, replaceAll(), REPOCOLUMN, sVersion, UPDATECOLOUR, and versionToInt().

Referenced by Entry().

Here is the call graph for this function:

◆ Entry()

wxThread::ExitCode PackageRepoBrowser::Entry ( )
privatevirtual

Secondary thread worker function.

Returns
wxThread::ExitCode

Definition at line 561 of file pluginrepodialog.cpp.

References DetectInstalledPackages(), getFileFromRepo(), getRepoList(), m_filesLoaded, m_listCtrl, m_progress, m_statusText, m_task, m_vUrls, populatePackageList(), REPO_LOCATION, TASK_LOADFILES, TASK_LOADREPO, TASK_NONE, and url::Error::what().

Here is the call graph for this function:

◆ findPackage()

wxTreeItemId PackageRepoBrowser::findPackage ( const std::string &  sPackageFileName)
private

Find a package entry from its file name. The returned ID must be checked for validness via wxTreeItemId::IsOk() to detect, if the package has been found.

Parameters
sPackageFileNameconst std::string&
Returns
wxTreeItemId

Definition at line 1075 of file pluginrepodialog.cpp.

References getUrl(), and m_listCtrl.

Referenced by OnInstall(), and resolveDependencies().

Here is the call graph for this function:

◆ getDependencies()

std::string PackageRepoBrowser::getDependencies ( const wxTreeItemId &  item)
private

Return the package dependencies.

Parameters
itemconst wxTreeItemId&
Returns
std::string

Definition at line 1059 of file pluginrepodialog.cpp.

References DEPENDENCIES, and getEntry().

Referenced by OnInstall(), and resolveDependencies().

Here is the call graph for this function:

◆ getEntry()

std::string PackageRepoBrowser::getEntry ( const wxTreeItemId &  item,
const std::string &  sIdentifier 
)
private

Returns the value of the selected identifier or an empty string, if the identifier cannot be found.

Parameters
itemconst wxTreeItemId&
sIdentifierconst std::string&
Returns
std::string

Definition at line 1019 of file pluginrepodialog.cpp.

References m_listCtrl, and REPOCOLUMN.

Referenced by DetectInstalledPackages(), getDependencies(), and getUrl().

◆ getFileFromRepo()

bool PackageRepoBrowser::getFileFromRepo ( const std::string &  sUrl)
private

Returns the contents of the passed URL as a file and writes it to its counterpart in the <SCRIPTPATH>/packages directory.

Parameters
sUrlconst std::string&
Returns
bool

Definition at line 1132 of file pluginrepodialog.cpp.

References url::get(), m_scriptPath, and date::detail::trunc().

Referenced by Entry().

Here is the call graph for this function:

◆ getRepoList()

std::vector< std::string > PackageRepoBrowser::getRepoList ( const std::string &  sRepoUrl)
private

This member function fetches the repository main page as HTML and extracts the list of item links in it. These may be files and folders.

Parameters
sRepoUrlconst std::string&
Returns
std::vector<std::string>

Definition at line 701 of file pluginrepodialog.cpp.

References createSalt(), and url::get().

Referenced by Entry(), and populatePackageList().

Here is the call graph for this function:

◆ getUrl()

std::string PackageRepoBrowser::getUrl ( const wxTreeItemId &  item)
private

Return the package URL.

Parameters
itemconst wxTreeItemId&
Returns
std::string

Definition at line 1046 of file pluginrepodialog.cpp.

References getEntry(), and REPO_URL.

Referenced by findPackage(), and OnInstall().

Here is the call graph for this function:

◆ isInstallable()

bool PackageRepoBrowser::isInstallable ( const wxTreeItemId &  item)
private

Returns, whether the current item is an installable package (not already installed).

Parameters
itemconst wxTreeItemId&
Returns
bool

Definition at line 988 of file pluginrepodialog.cpp.

References m_listCtrl.

Referenced by OnItemSelect(), and resolveDependencies().

◆ isUpdateable()

bool PackageRepoBrowser::isUpdateable ( const wxTreeItemId &  item)
private

Returns, whether the current item is an updateable package (already installed but newer version available).

Parameters
itemconst wxTreeItemId&
Returns
bool

Definition at line 1003 of file pluginrepodialog.cpp.

References m_listCtrl, and UPDATECOLOUR.

Referenced by OnItemSelect(), and resolveDependencies().

◆ OnClose()

void PackageRepoBrowser::OnClose ( wxCloseEvent &  event)
private

OnClose event handler. Will terminate the thread, if it's running.

Parameters
eventwxCloseEvent&
Returns
void

Definition at line 679 of file pluginrepodialog.cpp.

References m_task, and TASK_NONE.

◆ OnInstall()

void PackageRepoBrowser::OnInstall ( wxCommandEvent &  event)
private

Button event handler linked to the "install/update" button.

Parameters
eventwxCommandEvent&
Returns
void

Definition at line 871 of file pluginrepodialog.cpp.

References findPackage(), getDependencies(), getUrl(), INSTALLEDCOLOUR, INSTALLEDCOLUMN, m_fileNameToInstall, m_filesLoaded, m_installButton, m_listCtrl, m_vUrls, resolveDependencies(), StartThread(), and TASK_LOADFILES.

Here is the call graph for this function:

◆ OnItemSelect()

void PackageRepoBrowser::OnItemSelect ( wxTreeEvent &  event)
private

Item select event handler to enable or disable the buttons depending on the state of the package or whether the actual package headline was selected.

Parameters
eventwxTreeEvent&
Returns
void

Definition at line 943 of file pluginrepodialog.cpp.

References isInstallable(), isUpdateable(), m_installButton, m_listCtrl, m_task, m_uninstallButton, OUTDATEDVERSIONCOLOUR, and TASK_NONE.

Here is the call graph for this function:

◆ OnThreadUpdate()

void PackageRepoBrowser::OnThreadUpdate ( wxThreadEvent &  event)
private

Thread update event handler. Will trigger the actual installation, if the files were loaded successfully.

Parameters
eventwxThreadEvent&
Returns
void

Definition at line 645 of file pluginrepodialog.cpp.

References INSTALLEDCOLUMN, m_fileNameToInstall, m_filesLoaded, m_listCtrl, m_progress, m_terminal, and NumeReTerminal::pass_command().

Here is the call graph for this function:

◆ OnUninstall()

void PackageRepoBrowser::OnUninstall ( wxCommandEvent &  event)
private

Button event handler linked to the "uninstall" button.

Parameters
eventwxCommandEvent&
Returns
void

Definition at line 917 of file pluginrepodialog.cpp.

References INSTALLEDCOLUMN, m_installButton, m_listCtrl, m_terminal, m_uninstallButton, and NumeReTerminal::pass_command().

Here is the call graph for this function:

◆ populatePackageList()

void PackageRepoBrowser::populatePackageList ( const std::string &  sUrl)
private

Gets an URL and retrieve its counterpart from the repository. If the link does not reference a file but a folder, a recursion is started to resolve the contents of the folder.

Parameters
sUrlconst std::string&
Returns
void

Definition at line 740 of file pluginrepodialog.cpp.

References CHANGELOGLENGTH, createSalt(), DEPENDENCIES, url::get(), IconManager::GetIconIndex(), getRepoList(), getTagValue(), m_icons, m_listCtrl, PACKAGCOLUMN, populatePackageList(), replaceAll(), REPO_URL, and REPOCOLUMN.

Referenced by Entry(), and populatePackageList().

Here is the call graph for this function:

◆ resolveDependencies()

void PackageRepoBrowser::resolveDependencies ( std::string  sDepList,
std::vector< std::string > &  vDeps 
)
private

This member function resolves the dependencies of a selected file using a recursion. Only files, which are updateable or installable are returned. Dependencies, which are not part of the repository, are ignored.

Parameters
sDepListstd::string
vDepsstd::vector<std::string>&
Returns
void

Definition at line 1107 of file pluginrepodialog.cpp.

References findPackage(), getDependencies(), getNextArgument(), isInstallable(), isUpdateable(), and resolveDependencies().

Referenced by OnInstall(), and resolveDependencies().

Here is the call graph for this function:

◆ StartThread()

void PackageRepoBrowser::StartThread ( ThreadTask  task)
private

Start a new thread with the passed task.

Parameters
taskThreadTask
Returns
void

Definition at line 540 of file pluginrepodialog.cpp.

References m_task.

Referenced by OnInstall(), and PackageRepoBrowser().

Member Data Documentation

◆ m_fileNameToInstall

std::string PackageRepoBrowser::m_fileNameToInstall
private

Definition at line 43 of file pluginrepodialog.hpp.

Referenced by OnInstall(), and OnThreadUpdate().

◆ m_filesLoaded

bool PackageRepoBrowser::m_filesLoaded
private

Definition at line 61 of file pluginrepodialog.hpp.

Referenced by Entry(), OnInstall(), OnThreadUpdate(), and PackageRepoBrowser().

◆ m_icons

IconManager* PackageRepoBrowser::m_icons
private

◆ m_installButton

wxButton* PackageRepoBrowser::m_installButton
private

Definition at line 46 of file pluginrepodialog.hpp.

Referenced by OnInstall(), OnItemSelect(), OnUninstall(), and PackageRepoBrowser().

◆ m_listCtrl

wxcode::wxTreeListCtrl* PackageRepoBrowser::m_listCtrl
private

◆ m_progress

wxGauge* PackageRepoBrowser::m_progress
private

◆ m_scriptPath

std::string PackageRepoBrowser::m_scriptPath
private

Definition at line 42 of file pluginrepodialog.hpp.

Referenced by getFileFromRepo(), and PackageRepoBrowser().

◆ m_statusText

wxStaticText* PackageRepoBrowser::m_statusText
private

Definition at line 51 of file pluginrepodialog.hpp.

Referenced by DetectInstalledPackages(), Entry(), and PackageRepoBrowser().

◆ m_task

ThreadTask PackageRepoBrowser::m_task
private

Definition at line 60 of file pluginrepodialog.hpp.

Referenced by Entry(), OnClose(), OnItemSelect(), and StartThread().

◆ m_terminal

NumeReTerminal* PackageRepoBrowser::m_terminal
private

◆ m_uninstallButton

wxButton* PackageRepoBrowser::m_uninstallButton
private

Definition at line 47 of file pluginrepodialog.hpp.

Referenced by OnItemSelect(), OnUninstall(), and PackageRepoBrowser().

◆ m_vUrls

std::vector<std::string> PackageRepoBrowser::m_vUrls
private

Definition at line 62 of file pluginrepodialog.hpp.

Referenced by Entry(), and OnInstall().


The documentation for this class was generated from the following files: