1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 //
7 // This file is part of Nestopia.
8 //
9 // Nestopia is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Nestopia is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Nestopia; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////
24 
25 #include "NstWindowParam.hpp"
26 #include "NstManagerPaths.hpp"
27 #include "NstDialogTapeRecorder.hpp"
28 #include "NstApplicationInstance.hpp"
29 
30 namespace Nestopia
31 {
32 	namespace Window
33 	{
34 		struct TapeRecorder::Handlers
35 		{
36 			static const MsgHandler::Entry<TapeRecorder> messages[];
37 			static const MsgHandler::Entry<TapeRecorder> commands[];
38 		};
39 
40 		const MsgHandler::Entry<TapeRecorder> TapeRecorder::Handlers::messages[] =
41 		{
42 			{ WM_INITDIALOG, &TapeRecorder::OnInitDialog }
43 		};
44 
45 		const MsgHandler::Entry<TapeRecorder> TapeRecorder::Handlers::commands[] =
46 		{
47 			{ IDC_TAPE_RECORDER_USE_IMAGENAME, &TapeRecorder::OnCmdUseImageName },
48 			{ IDC_TAPE_RECORDER_CLEAR,         &TapeRecorder::OnCmdClear        },
49 			{ IDC_TAPE_RECORDER_BROWSE,        &TapeRecorder::OnCmdBrowse       },
50 			{ IDOK,                            &TapeRecorder::OnCmdOk           }
51 		};
52 
TapeRecorder(const Configuration & cfg,const Managers::Paths & p)53 		TapeRecorder::TapeRecorder(const Configuration& cfg,const Managers::Paths& p)
54 		: dialog(IDD_TAPE_RECORDER,this,Handlers::messages,Handlers::commands), paths(p)
55 		{
56 			Configuration::ConstSection tapes( cfg["paths"]["tapes"] );
57 
58 			settings.useImageNaming = !tapes["use-image-name"].No();
59 			settings.customFile = tapes["file"].Str();
60 			paths.FixFile( Managers::Paths::File::TAPE, settings.customFile );
61 		}
62 
~TapeRecorder()63 		TapeRecorder::~TapeRecorder()
64 		{
65 		}
66 
Save(Configuration & cfg) const67 		void TapeRecorder::Save(Configuration& cfg) const
68 		{
69 			Configuration::Section tapes( cfg["paths"]["tapes"] );
70 
71 			tapes["use-image-name"].YesNo() = settings.useImageNaming;
72 			tapes["file"].Str() = settings.customFile;
73 		}
74 
GetCustomFile() const75 		const Path TapeRecorder::GetCustomFile() const
76 		{
77 			return Application::Instance::GetFullPath( settings.customFile );
78 		}
79 
OnInitDialog(Param &)80 		ibool TapeRecorder::OnInitDialog(Param&)
81 		{
82 			dialog.CheckBox(IDC_TAPE_RECORDER_USE_IMAGENAME).Check( settings.useImageNaming );
83 			dialog.Edit(IDC_TAPE_RECORDER_FILE) << settings.customFile.Ptr();
84 
85 			Update();
86 
87 			return true;
88 		}
89 
Update() const90 		void TapeRecorder::Update() const
91 		{
92 			const bool unchecked = !dialog.CheckBox(IDC_TAPE_RECORDER_USE_IMAGENAME).Checked();
93 
94 			dialog.Control( IDC_TAPE_RECORDER_FILE   ).Enable( unchecked );
95 			dialog.Control( IDC_TAPE_RECORDER_BROWSE ).Enable( unchecked );
96 			dialog.Control( IDC_TAPE_RECORDER_CLEAR  ).Enable( unchecked );
97 		}
98 
OnCmdUseImageName(Param & param)99 		ibool TapeRecorder::OnCmdUseImageName(Param& param)
100 		{
101 			if (param.Button().Clicked())
102 				Update();
103 
104 			return true;
105 		}
106 
OnCmdClear(Param & param)107 		ibool TapeRecorder::OnCmdClear(Param& param)
108 		{
109 			if (param.Button().Clicked())
110 				dialog.Edit(IDC_TAPE_RECORDER_FILE).Clear();
111 
112 			return true;
113 		}
114 
OnCmdBrowse(Param & param)115 		ibool TapeRecorder::OnCmdBrowse(Param& param)
116 		{
117 			if (param.Button().Clicked())
118 			{
119 				Path tmp;
120 				dialog.Edit(IDC_TAPE_RECORDER_FILE) >> tmp;
121 				dialog.Edit(IDC_TAPE_RECORDER_FILE).Try() << paths.BrowseSave( Managers::Paths::File::TAPE, Managers::Paths::SUGGEST, Application::Instance::GetFullPath(tmp) ).Ptr();
122 			}
123 
124 			return true;
125 		}
126 
OnCmdOk(Param & param)127 		ibool TapeRecorder::OnCmdOk(Param& param)
128 		{
129 			if (param.Button().Clicked())
130 			{
131 				settings.useImageNaming = dialog.CheckBox(IDC_TAPE_RECORDER_USE_IMAGENAME).Checked();
132 				dialog.Edit(IDC_TAPE_RECORDER_FILE) >> settings.customFile;
133 				paths.FixFile( Managers::Paths::File::TAPE, settings.customFile );
134 				dialog.Close();
135 			}
136 
137 			return true;
138 		}
139 	}
140 }
141