| 1 |
/* |
| 2 |
Copyright (C) 2012-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 |
#ifndef PROFILEPROXY_H |
| 20 |
#define PROFILEPROXY_H |
| 21 |
|
| 22 |
#include <wx/wx.h> |
| 23 |
#include <wx/event.h> |
| 24 |
|
| 25 |
#include <map> |
| 26 |
#include <vector> |
| 27 |
|
| 28 |
#include "datastructures/FlagFileData.h" |
| 29 |
#include "apis/EventHandlers.h" |
| 30 |
|
| 31 |
/* ProfileProxy - a high-level API for the data in the current profile. |
| 32 |
Other classes should use the ProfileProxy instead of the ProfileManager |
| 33 |
whenever possible. */ |
| 34 |
|
| 35 |
/** Indicates the proxy has reset itself. */ |
| 36 |
LAUNCHER_DECLARE_EVENT_TYPE(EVT_PROXY_RESET); |
| 37 |
|
| 38 |
/** Indicates the proxy has successfully processed flag data from the flag file |
| 39 |
and profile. */ |
| 40 |
LAUNCHER_DECLARE_EVENT_TYPE(EVT_PROXY_FLAG_DATA_READY); |
| 41 |
|
| 42 |
WX_DECLARE_STRING_HASH_MAP(int, FlagStringToIndexMap); |
| 43 |
|
| 44 |
class ProfileProxy: public wxEvtHandler { |
| 45 |
public: |
| 46 |
static ProfileProxy* GetProxy(); |
| 47 |
static bool Initialize(); |
| 48 |
static void DeInitialize(); |
| 49 |
static bool IsInitialized(); |
| 50 |
|
| 51 |
void RegisterProxyReset(wxEvtHandler *handler); |
| 52 |
void UnRegisterProxyReset(wxEvtHandler *handler); |
| 53 |
|
| 54 |
void RegisterProxyFlagDataReady(wxEvtHandler *handler); |
| 55 |
void UnRegisterProxyFlagDataReady(wxEvtHandler *handler); |
| 56 |
|
| 57 |
virtual ~ProfileProxy(); |
| 58 |
|
| 59 |
void OnFlagFileProcessingStatusChanged(wxCommandEvent &event); |
| 60 |
|
| 61 |
/** Indicates whether the proxy has processed flag data for the current |
| 62 |
profile's FSO binary and flag line. */ |
| 63 |
bool IsFlagDataReady() const { return this->isFlagDataReady; } |
| 64 |
|
| 65 |
/** Sets a flag from the flag list. */ |
| 66 |
void SetFlag(const wxString& flag, bool isChecked); |
| 67 |
|
| 68 |
/** Gets the enabled flag list flags as individual flag strings. */ |
| 69 |
std::vector<wxString> GetEnabledFlags() const; |
| 70 |
|
| 71 |
/** Gets the enabled flag list flags as a single string. */ |
| 72 |
wxString GetEnabledFlagsString() const; |
| 73 |
|
| 74 |
/** Gets the custom flags. */ |
| 75 |
const wxString& GetCustomFlags() const { return this->customFlags; } |
| 76 |
|
| 77 |
/** Sets the custom flags. */ |
| 78 |
void SetCustomFlags(const wxString& customFlags, bool updateTextCtrl = true); |
| 79 |
|
| 80 |
/** Indicates whether the current profile has a lighting preset entry. */ |
| 81 |
bool HasLightingPreset() const; |
| 82 |
|
| 83 |
/** Gets the name of the selected lighting preset. |
| 84 |
Returns an empty string if no lighting preset is in the profile |
| 85 |
or if the preset name stored in the profile is empty. */ |
| 86 |
wxString GetLightingPresetName() const; |
| 87 |
|
| 88 |
/** Sets the current lighting preset. */ |
| 89 |
void SetLightingPreset(const wxString& presetName); |
| 90 |
|
| 91 |
/** Prepends the current lighting preset to custom flags |
| 92 |
The profile must have a non-empty lighting preset name.*/ |
| 93 |
void CopyPresetToCustomFlags(); |
| 94 |
|
| 95 |
/** Returns whether the current profile has been initialized. */ |
| 96 |
bool IsProfileInitialized() const; |
| 97 |
|
| 98 |
/** Finishes initialization of the current profile. |
| 99 |
The profile must not already be initialized. */ |
| 100 |
void FinishProfileInitialization() const; |
| 101 |
|
| 102 |
private: |
| 103 |
static ProfileProxy* proxy; |
| 104 |
ProfileProxy(); |
| 105 |
|
| 106 |
EventHandlers resetEventHandlers; |
| 107 |
EventHandlers readyEventHandlers; |
| 108 |
|
| 109 |
void GenerateProxyReset(); |
| 110 |
void GenerateProxyFlagDataReady(); |
| 111 |
|
| 112 |
/** Writes both flag list flags and custom flags to profile. */ |
| 113 |
void WriteFlagLineToProfile() const; |
| 114 |
|
| 115 |
/** Processes data extracted from the flag file. */ |
| 116 |
void ProcessFlagData(const ProxyFlagData& data); |
| 117 |
|
| 118 |
/** Process the current profile's flag line, |
| 119 |
using the data extracted from the flag file. */ |
| 120 |
void ProcessFlagLine(); |
| 121 |
|
| 122 |
/** Returns all indices (if any) where flag is found in enabledFlags. */ |
| 123 |
std::vector<int> FindInEnabledFlags(const wxString& flag) const; |
| 124 |
|
| 125 |
/** Verifies that the flag is either not in enabledFlags or at its flagIndex. |
| 126 |
Returns an empty string on success, an error message otherwise. */ |
| 127 |
wxString VerifyEnabledFlagsForFlag(const wxString& flag, int flagIndex) const; |
| 128 |
|
| 129 |
void Reset(); |
| 130 |
|
| 131 |
std::map<int, wxString> enabledFlags; // ordered, flagIndex to flagString |
| 132 |
|
| 133 |
FlagStringToIndexMap flagMap; |
| 134 |
|
| 135 |
wxString customFlags; |
| 136 |
|
| 137 |
bool isFlagDataReady; |
| 138 |
|
| 139 |
DECLARE_EVENT_TABLE() |
| 140 |
}; |
| 141 |
|
| 142 |
#endif |