File: ProfileProxy.h

package info (click to toggle)
freespace2-launcher-wxlauncher 0.11.0%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: buster
  • size: 2,368 kB
  • sloc: cpp: 13,446; python: 797; makefile: 12; sh: 12
file content (142 lines) | stat: -rw-r--r-- 4,559 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 Copyright (C) 2012-2015 wxLauncher Team
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef PROFILEPROXY_H
#define PROFILEPROXY_H

#include <wx/wx.h>
#include <wx/event.h>

#include <map>
#include <vector>

#include "datastructures/FlagFileData.h"
#include "apis/EventHandlers.h"

/* ProfileProxy - a high-level API for the data in the current profile.
   Other classes should use the ProfileProxy instead of the ProfileManager
   whenever possible. */

/** Indicates the proxy has reset itself. */
LAUNCHER_DECLARE_EVENT_TYPE(EVT_PROXY_RESET);

/** Indicates the proxy has successfully processed flag data from the flag file
 and profile. */
LAUNCHER_DECLARE_EVENT_TYPE(EVT_PROXY_FLAG_DATA_READY);

WX_DECLARE_STRING_HASH_MAP(int, FlagStringToIndexMap);

class ProfileProxy: public wxEvtHandler {
public:
	static ProfileProxy* GetProxy();
	static bool Initialize();
	static void DeInitialize();
	static bool IsInitialized();

	void RegisterProxyReset(wxEvtHandler *handler);
	void UnRegisterProxyReset(wxEvtHandler *handler);
	
	void RegisterProxyFlagDataReady(wxEvtHandler *handler);
	void UnRegisterProxyFlagDataReady(wxEvtHandler *handler);
	
	virtual ~ProfileProxy();

	void OnFlagFileProcessingStatusChanged(wxCommandEvent &event);
	
	/** Indicates whether the proxy has processed flag data for the current
	 profile's FSO binary and flag line. */
	bool IsFlagDataReady() const { return this->isFlagDataReady; }
	
	/** Sets a flag from the flag list. */
	void SetFlag(const wxString& flag, bool isChecked);
	
	/** Gets the enabled flag list flags as individual flag strings. */
	std::vector<wxString> GetEnabledFlags() const;
	
	/** Gets the enabled flag list flags as a single string. */
	wxString GetEnabledFlagsString() const;
	
	/** Gets the custom flags. */
	const wxString& GetCustomFlags() const { return this->customFlags; }
	
	/** Sets the custom flags. */
	void SetCustomFlags(const wxString& customFlags, bool updateTextCtrl = true);
	
	/** Indicates whether the current profile has a lighting preset entry. */
	bool HasLightingPreset() const;
	
	/** Gets the name of the selected lighting preset.
	   Returns an empty string if no lighting preset is in the profile
	 or if the preset name stored in the profile is empty. */
	wxString GetLightingPresetName() const;
	
	/** Sets the current lighting preset. */
	void SetLightingPreset(const wxString& presetName);
	
	/** Prepends the current lighting preset to custom flags
	 The profile must have a non-empty lighting preset name.*/
	void CopyPresetToCustomFlags();
	
	/** Returns whether the current profile has been initialized. */
	bool IsProfileInitialized() const;
	
	/** Finishes initialization of the current profile.
	 The profile must not already be initialized. */
	void FinishProfileInitialization() const;
	
private:
	static ProfileProxy* proxy;
	ProfileProxy();
	
	EventHandlers resetEventHandlers;
	EventHandlers readyEventHandlers;

	void GenerateProxyReset();
	void GenerateProxyFlagDataReady();
	
	/** Writes both flag list flags and custom flags to profile. */
	void WriteFlagLineToProfile() const;
	
	/** Processes data extracted from the flag file. */
	void ProcessFlagData(const ProxyFlagData& data);
	
	/** Process the current profile's flag line,
	 using the data extracted from the flag file. */
	void ProcessFlagLine();
	
	/** Returns all indices (if any) where flag is found in enabledFlags. */
	std::vector<int> FindInEnabledFlags(const wxString& flag) const;
	
	/** Verifies that the flag is either not in enabledFlags or at its flagIndex.
	 Returns an empty string on success, an error message otherwise. */
	wxString VerifyEnabledFlagsForFlag(const wxString& flag, int flagIndex) const;
	
	void Reset();
	
	std::map<int, wxString> enabledFlags; // ordered, flagIndex to flagString
	
	FlagStringToIndexMap flagMap;
	
	wxString customFlags;
	
	bool isFlagDataReady;
	
	DECLARE_EVENT_TABLE()
};

#endif