/[pcsx2_0.9.7]/trunk/pcsx2/gui/RecentIsoList.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/RecentIsoList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 5332 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "AppCoreThread.h"
18 #include "RecentIsoList.h"
19 #include "IsoDropTarget.h"
20 #include "Utilities/IniInterface.h"
21
22 extern wxString GetMsg_IsoImageChanged();
23
24 // FIXME : This needs to handle removed/missing ISOs somehow, although I'm not sure the
25 // best approach. I think I'd prefer for missing entries to only be removed when they
26 // are selected. This also means we'll need to add some sort of "no current selection"
27 // menu option that's defaulted to when a selection is deemed missing (since just randomly
28 // selecting another iso would be undesirable).
29
30
31 RecentIsoManager::RecentIsoManager( wxMenu* menu )
32 : m_Menu( menu )
33 , m_MaxLength( g_Conf->RecentIsoCount )
34 {
35 m_cursel = 0;
36 m_Separator = NULL;
37
38 IniLoader loader;
39 LoadListFrom(loader);
40
41 Connect( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(RecentIsoManager::OnChangedSelection) );
42 }
43
44 RecentIsoManager::~RecentIsoManager() throw()
45 {
46 Disconnect( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(RecentIsoManager::OnChangedSelection) );
47 }
48
49 void RecentIsoManager::OnChangedSelection( wxCommandEvent& evt )
50 {
51 uint cnt = m_Items.size();
52 uint i=0;
53 for( ; i<cnt; ++i )
54 {
55 if( (m_Items[i].ItemPtr != NULL) && (m_Items[i].ItemPtr->GetId() == evt.GetId()) ) break;
56 }
57
58 if( i >= m_Items.size() )
59 {
60 evt.Skip();
61 return;
62 }
63
64 m_cursel = i;
65
66 ScopedCoreThreadPopup stopped_core;
67
68 #ifdef __LINUX__
69 // Likely not what was intended, but it compiles for the moment...
70 SwapOrReset_Iso( NULL, stopped_core, m_Items[i].Filename, GetMsg_IsoImageChanged());
71 #else
72 // Getting a window from the menu?
73 SwapOrReset_Iso( m_Menu->GetWindow(), stopped_core, m_Items[i].Filename, GetMsg_IsoImageChanged());
74 #endif
75
76 stopped_core.AllowResume();
77 }
78
79 void RecentIsoManager::RemoveAllFromMenu()
80 {
81 if( m_Menu == NULL ) return;
82
83 int cnt = m_Items.size();
84 for( int i=0; i<cnt; ++i )
85 {
86 RecentItem& curitem( m_Items[i] );
87 if( curitem.ItemPtr == NULL ) continue;
88 m_Menu->Destroy( curitem.ItemPtr );
89 curitem.ItemPtr = NULL;
90 }
91
92 if( m_Separator != NULL )
93 {
94 m_Menu->Destroy( m_Separator );
95 m_Separator = NULL;
96 }
97 }
98
99 void RecentIsoManager::Clear()
100 {
101 RemoveAllFromMenu();
102 m_Items.clear();
103 Repopulate();
104 }
105
106 void RecentIsoManager::Repopulate()
107 {
108 int cnt = m_Items.size();
109 if( cnt <= 0 ) return;
110
111 m_Separator = m_Menu->AppendSeparator();
112
113 for( int i=0; i<cnt; ++i )
114 InsertIntoMenu( i );
115 }
116
117 void RecentIsoManager::Add( const wxString& src )
118 {
119 if( src.IsEmpty() ) return;
120
121 wxString normalized( Path::Normalize( src ) );
122
123 int cnt = m_Items.size();
124
125 if( cnt <= 0 )
126 {
127 pxAssert( m_Separator == NULL );
128 m_Separator = m_Menu->AppendSeparator();
129 }
130 else
131 {
132 for( int i=0; i<cnt; ++i )
133 {
134 if( m_Items[i].Filename == normalized )
135 {
136 m_cursel = i;
137 if( m_Items[i].ItemPtr != NULL )
138 m_Items[i].ItemPtr->Check();
139 return;
140 }
141 }
142 }
143
144 m_Items.push_back( RecentItem( normalized ) );
145 InsertIntoMenu( m_cursel = (m_Items.size()-1) );
146
147 while( m_Items.size() > m_MaxLength )
148 {
149 m_Items.erase( m_Items.begin() );
150 }
151 }
152
153 void RecentIsoManager::InsertIntoMenu( int id )
154 {
155 if( m_Menu == NULL ) return;
156 RecentItem& curitem( m_Items[id] );
157 curitem.ItemPtr = m_Menu->Append( wxID_ANY, Path::GetFilename(curitem.Filename), curitem.Filename, wxITEM_RADIO );
158
159 if( m_cursel == id )
160 curitem.ItemPtr->Check();
161 }
162
163 void RecentIsoManager::LoadListFrom( IniInterface& ini )
164 {
165 if (!ini.IsOk()) return;
166
167 ini.GetConfig().SetRecordDefaults( false );
168
169 RemoveAllFromMenu();
170
171 m_MaxLength = g_Conf->RecentIsoCount;
172 ScopedIniGroup groupie( ini, L"RecentIso" );
173 for( uint i=0; i<m_MaxLength; ++i )
174 {
175 wxString loadtmp;
176 ini.Entry( pxsFmt( L"Filename%02d", i ), loadtmp );
177 if( !loadtmp.IsEmpty() ) Add( loadtmp );
178 }
179 Add( g_Conf->CurrentIso );
180
181 ini.GetConfig().SetRecordDefaults( true );
182 }
183
184 void RecentIsoManager::AppStatusEvent_OnSettingsApplied()
185 {
186 // TODO : Implement application of Recent Iso List "maximum" history option
187 }
188
189 void RecentIsoManager::AppStatusEvent_OnSettingsLoadSave( const AppSettingsEventInfo& evt )
190 {
191 IniInterface& ini( evt.GetIni() );
192
193 if( ini.IsSaving() )
194 {
195 // Wipe existing recent iso list if we're saving, because our size might have changed
196 // and that could leave some residual entries in the config.
197
198 ini.GetConfig().SetRecordDefaults( false );
199
200 ini.GetConfig().DeleteGroup( L"RecentIso" );
201 ScopedIniGroup groupie( ini, L"RecentIso" );
202
203 int cnt = m_Items.size();
204 for( int i=0; i<cnt; ++i )
205 {
206 ini.Entry( pxsFmt( L"Filename%02d", i ), m_Items[i].Filename );
207 }
208
209 ini.GetConfig().SetRecordDefaults( true );
210 }
211 else
212 {
213 LoadListFrom(ini);
214 }
215 }

  ViewVC Help
Powered by ViewVC 1.1.22