| 1 |
/* |
| 2 |
Copyright (C) 2009-2015 wxLauncher Team |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "apis/TCManager.h" |
| 20 |
#include "apis/ProfileManager.h" |
| 21 |
|
| 22 |
#include "global/MemoryDebugging.h" |
| 23 |
|
| 24 |
/** \class TCManager |
| 25 |
TCManager is used to pickup CurrentProfileChanged events from ProMan and |
| 26 |
send the approriate messages to the controls that care. It also sends |
| 27 |
out events when the binary or root folder get changed by user controls |
| 28 |
so that other controls that are affected (like ModList) get notified in all |
| 29 |
cases and will be able to update the information. */ |
| 30 |
|
| 31 |
/** Contructor. Static class does nothing. */ |
| 32 |
TCManager::TCManager() { |
| 33 |
wxLogDebug(_T("TCManager is at %p."), this); |
| 34 |
if (ProMan::IsInitialized()) { |
| 35 |
ProMan::GetProfileManager()->AddEventHandler(this); |
| 36 |
} |
| 37 |
} |
| 38 |
/** Destructor. Static class does nothing. */ |
| 39 |
TCManager::~TCManager() { |
| 40 |
if (ProMan::IsInitialized()) { |
| 41 |
ProMan::GetProfileManager()->RemoveEventHandler(this); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
TCManager* TCManager::manager = NULL; |
| 46 |
EventHandlers TCManager::TCChangedHandlers; |
| 47 |
EventHandlers TCManager::TCBinaryChangedHandlers; |
| 48 |
EventHandlers TCManager::TCActiveModChangedHandlers; |
| 49 |
EventHandlers TCManager::TCFredBinaryChangedHandlers; |
| 50 |
|
| 51 |
void TCManager::Initialize() { |
| 52 |
if ( !IsInitialized() ) { |
| 53 |
manager = new TCManager(); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void TCManager::DeInitialize() { |
| 58 |
if ( IsInitialized()) { |
| 59 |
delete manager; |
| 60 |
manager = NULL; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
bool TCManager::IsInitialized() { |
| 65 |
return manager != NULL; |
| 66 |
} |
| 67 |
|
| 68 |
TCManager* TCManager::Get() { |
| 69 |
return manager; |
| 70 |
} |
| 71 |
|
| 72 |
/////////////////////////////////////////////////////////////////////////////// |
| 73 |
///// Events |
| 74 |
BEGIN_EVENT_TABLE(TCManager, wxEvtHandler) |
| 75 |
EVT_COMMAND(wxID_ANY, EVT_CURRENT_PROFILE_CHANGED, TCManager::CurrentProfileChanged) |
| 76 |
END_EVENT_TABLE() |
| 77 |
|
| 78 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_TC_CHANGED); |
| 79 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_TC_BINARY_CHANGED); |
| 80 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_TC_ACTIVE_MOD_CHANGED); |
| 81 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_TC_FRED_BINARY_CHANGED); |
| 82 |
|
| 83 |
void TCManager::RegisterTCBinaryChanged(wxEvtHandler *handler) { |
| 84 |
wxASSERT_MSG(TCBinaryChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 85 |
wxString::Format( |
| 86 |
_T("RegisterTCBinaryChanged(): Handler at %p already registered."), |
| 87 |
handler)); |
| 88 |
TCBinaryChangedHandlers.Append(handler); |
| 89 |
} |
| 90 |
void TCManager::UnRegisterTCBinaryChanged(wxEvtHandler *handler) { |
| 91 |
wxASSERT_MSG(TCBinaryChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 92 |
wxString::Format( |
| 93 |
_T("UnRegisterTCBinaryChanged(): Handler at %p not registered."), |
| 94 |
handler)); |
| 95 |
TCBinaryChangedHandlers.DeleteObject(handler); |
| 96 |
} |
| 97 |
void TCManager::RegisterTCChanged(wxEvtHandler *handler) { |
| 98 |
wxASSERT_MSG(TCChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 99 |
wxString::Format( |
| 100 |
_T("RegisterTCChanged(): Handler at %p already registered."), |
| 101 |
handler)); |
| 102 |
TCChangedHandlers.Append(handler); |
| 103 |
} |
| 104 |
void TCManager::UnRegisterTCChanged(wxEvtHandler *handler) { |
| 105 |
wxASSERT_MSG(TCChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 106 |
wxString::Format( |
| 107 |
_T("UnRegisterTCChanged(): Handler at %p not registered."), |
| 108 |
handler)); |
| 109 |
TCChangedHandlers.DeleteObject(handler); |
| 110 |
} |
| 111 |
void TCManager::RegisterTCActiveModChanged(wxEvtHandler *handler) { |
| 112 |
wxASSERT_MSG(TCActiveModChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 113 |
wxString::Format( |
| 114 |
_T("RegisterTCActiveModChanged(): Handler at %p already registered."), |
| 115 |
handler)); |
| 116 |
TCActiveModChangedHandlers.Append(handler); |
| 117 |
} |
| 118 |
void TCManager::UnRegisterTCActiveModChanged(wxEvtHandler *handler) { |
| 119 |
wxASSERT_MSG(TCActiveModChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 120 |
wxString::Format( |
| 121 |
_T("UnRegisterTCActiveModChanged(): Handler at %p not registered."), |
| 122 |
handler)); |
| 123 |
TCActiveModChangedHandlers.DeleteObject(handler); |
| 124 |
} |
| 125 |
void TCManager::RegisterTCFredBinaryChanged(wxEvtHandler *handler) { |
| 126 |
wxASSERT_MSG(TCFredBinaryChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 127 |
wxString::Format( |
| 128 |
_T("RegisterTCFredBinaryChanged(): Handler at %p already registered."), |
| 129 |
handler)); |
| 130 |
TCFredBinaryChangedHandlers.Append(handler); |
| 131 |
} |
| 132 |
void TCManager::UnRegisterTCFredBinaryChanged(wxEvtHandler *handler) { |
| 133 |
wxASSERT_MSG(TCFredBinaryChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 134 |
wxString::Format( |
| 135 |
_T("UnRegisterTCFredBinaryChanged(): Handler at %p not registered."), |
| 136 |
handler)); |
| 137 |
TCFredBinaryChangedHandlers.DeleteObject(handler); |
| 138 |
} |
| 139 |
void TCManager::GenerateTCChanged() { |
| 140 |
wxCommandEvent event(EVT_TC_CHANGED, wxID_NONE); |
| 141 |
wxLogDebug(_T("Generating EVT_TC_CHANGED event")); |
| 142 |
EventHandlers::iterator iter = TCChangedHandlers.begin(); |
| 143 |
while (iter != TCChangedHandlers.end()) { |
| 144 |
wxEvtHandler* current = *iter; |
| 145 |
current->AddPendingEvent(event); |
| 146 |
wxLogDebug(_T(" Sent EVT_TC_CHANGED event to %p"), current); |
| 147 |
iter++; |
| 148 |
} |
| 149 |
} |
| 150 |
void TCManager::GenerateTCBinaryChanged() { |
| 151 |
wxCommandEvent event(EVT_TC_BINARY_CHANGED, wxID_NONE); |
| 152 |
wxLogDebug(_T("Generating EVT_TC_BINARY_CHANGED event")); |
| 153 |
EventHandlers::iterator iter = TCBinaryChangedHandlers.begin(); |
| 154 |
while (iter != TCBinaryChangedHandlers.end()) { |
| 155 |
wxEvtHandler* current = *iter; |
| 156 |
current->AddPendingEvent(event); |
| 157 |
wxLogDebug(_T(" Sent EVT_TC_BINARY_CHANGED event to %p"), current); |
| 158 |
iter++; |
| 159 |
} |
| 160 |
} |
| 161 |
void TCManager::GenerateTCActiveModChanged() { |
| 162 |
wxCommandEvent event(EVT_TC_ACTIVE_MOD_CHANGED, wxID_NONE); |
| 163 |
wxLogDebug(_T("Generating EVT_TC_ACTIVE_MOD_CHANGED event")); |
| 164 |
EventHandlers::iterator iter = TCActiveModChangedHandlers.begin(); |
| 165 |
while (iter != TCActiveModChangedHandlers.end()) { |
| 166 |
wxEvtHandler* current = *iter; |
| 167 |
current->AddPendingEvent(event); |
| 168 |
wxLogDebug(_T(" Sent EVT_TC_ACTIVE_MOD_CHANGED event to %p"), current); |
| 169 |
iter++; |
| 170 |
} |
| 171 |
} |
| 172 |
void TCManager::GenerateTCFredBinaryChanged() { |
| 173 |
wxCommandEvent event(EVT_TC_FRED_BINARY_CHANGED, wxID_NONE); |
| 174 |
wxLogDebug(_T("Generating EVT_TC_FRED_BINARY_CHANGED event")); |
| 175 |
EventHandlers::iterator iter = TCFredBinaryChangedHandlers.begin(); |
| 176 |
while (iter != TCFredBinaryChangedHandlers.end()) { |
| 177 |
wxEvtHandler* current = *iter; |
| 178 |
current->AddPendingEvent(event); |
| 179 |
wxLogDebug(_T(" Sent EVT_TC_FRED_BINARY_CHANGED event to %p"), current); |
| 180 |
iter++; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
void TCManager::CurrentProfileChanged(wxCommandEvent &WXUNUSED(event)) { |
| 185 |
|
| 186 |
TCManager::GenerateTCChanged(); |
| 187 |
// it's assumed that BasicSettingsPage::OnTCChanged() (which is called on an EVT_TC_CHANGED event) |
| 188 |
// calls TCManager::GenerateTCBinaryChanged() unconditionally, so no need to explicitly call it here |
| 189 |
// it's also assumed that BasicSettingsPage::OnTCChanged() calls TCManager::GenerateTCFredBinaryChanged() |
| 190 |
// unconditionally if FRED launching is enabled |
| 191 |
} |