7
7
#include " ../lib/ArduinoInterface.h"
8
8
#include " ../lib/ADFWriter.h"
9
9
10
+ enum Tracks
11
+ {
12
+ eighty = 80 ,
13
+ eightytwo = 82 ,
14
+ };
15
+
16
+ enum ReadType
17
+ {
18
+ ADF = 1 ,
19
+ SCP = 2 ,
20
+ };
21
+
22
+ class WindowState
23
+ {
24
+ public:
25
+ Glib::ustring serialPort;
26
+ ReadType type;
27
+ Tracks tracks;
28
+ bool verify;
29
+ bool writeCompensation;
30
+ Glib::ustring readFileName;
31
+ Glib::ustring readFolder;
32
+ Glib::ustring writeFileName;
33
+ };
34
+
10
35
class MainWindow : public Gtk ::ApplicationWindow
11
36
{
12
37
public:
13
38
MainWindow (BaseObjectType *obj, Glib::RefPtr<Gtk::Builder> const &builder)
14
39
: Gtk::ApplicationWindow(obj), builder{builder}
15
40
{
41
+ get_widgets ();
16
42
std::vector<std::wstring> portList;
17
43
ArduinoFloppyReader::ArduinoInterface::enumeratePorts (portList);
18
- Gtk::ComboBoxText *portsCombo = nullptr ;
19
- builder->get_widget (" serialPortsCombo" , portsCombo);
20
44
for (std::wstring port : portList)
21
45
{
22
46
const std::string portString (port.begin (), port.end ());
23
47
Glib::ustring text = Glib::ustring (portString.c_str (), port.size ());
24
48
portsCombo->append (text);
25
49
}
26
- Gtk::Button *diagnosticsButton = nullptr ;
27
- builder->get_widget (" diagnosticsButton" , diagnosticsButton);
28
50
if (portList.size () > 0 )
29
51
{
30
52
portsCombo->set_active (0 );
31
53
diagnosticsButton->set_sensitive (true );
32
54
}
33
- diagnosticsButton->signal_clicked ().connect ([this , portsCombo ]()
55
+ diagnosticsButton->signal_clicked ().connect ([this ]()
34
56
{
35
57
Glib::ustring serial = portsCombo->get_active_text ();
36
58
run_diagnostics (serial);
37
59
});
38
- Gtk::Button *copyButton = nullptr ;
39
- builder->get_widget (" copyButton" , copyButton);
40
- Gtk::Label *cylinderCount = nullptr ;
41
- builder->get_widget (" cylinderCount" , cylinderCount);
42
- Gtk::Label *sideLabel = nullptr ;
43
- builder->get_widget (" sideLabel" , sideLabel);
44
- Gtk::Label *goodCount = nullptr ;
45
- builder->get_widget (" goodCount" , goodCount);
46
- Gtk::Label *partialCount = nullptr ;
47
- builder->get_widget (" partialCount" , partialCount);
48
60
49
- auto readerCallback = [this , cylinderCount, sideLabel, goodCount, partialCount ](const int currentTrack, const ArduinoFloppyReader::DiskSurface currentSide, const int retryCounter, const int sectorsFound, const int badSectorsFound) -> ArduinoFloppyReader::WriteResponse
61
+ auto readerCallback = [this ](const int currentTrack, const ArduinoFloppyReader::DiskSurface currentSide, const int retryCounter, const int sectorsFound, const int badSectorsFound) -> ArduinoFloppyReader::WriteResponse
50
62
{
51
63
std::string side = (currentSide == ArduinoFloppyReader::DiskSurface::dsUpper ? " Upper" : " Lower" );
52
- std::cout << " currentTrack: " << currentTrack << " side: " << side << " retryCount: " << retryCounter << std::endl;
64
+ std::cout << " currentTrack: " << currentTrack << " side: " << side << " retryCount: " << retryCounter << std::endl;
53
65
cylinderCount->set_text (Glib::ustring::sprintf (" %i" , currentTrack));
54
66
goodCount->set_text (Glib::ustring::sprintf (" %i" , sectorsFound));
55
67
partialCount->set_text (Glib::ustring::sprintf (" %i" , badSectorsFound));
@@ -59,26 +71,36 @@ class MainWindow : public Gtk::ApplicationWindow
59
71
60
72
if (retryCounter > 20 )
61
73
{
62
- // Gtk::MessageDialog dialog = Gtk::MessageDialog(*this, "Aborted", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK);
63
- // dialog.run();
64
- // dialog.hide();
74
+ if (alwaysIgnore->get_active ())
75
+ {
76
+ return ArduinoFloppyReader::WriteResponse::wrSkipBadChecksums;
77
+ }
78
+ Gtk::MessageDialog dialog = Gtk::MessageDialog (*this , " Verify error writing track.\n Disk Write Error" , false , Gtk::MESSAGE_ERROR, Gtk::BUTTONS_NONE);
79
+ dialog.add_button (" Abort" , 1 );
80
+ dialog.add_button (" Retry" , 2 );
81
+ dialog.add_button (" Ignore" , 3 );
82
+ int response = dialog.run ();
83
+ dialog.hide ();
84
+
85
+ switch (response)
86
+ {
87
+ case 1 :
88
+ return ArduinoFloppyReader::WriteResponse::wrAbort;
89
+ case 2 :
90
+ return ArduinoFloppyReader::WriteResponse::wrRetry;
91
+ case 3 :
92
+ return ArduinoFloppyReader::WriteResponse::wrSkipBadChecksums;
93
+ }
65
94
66
- return ArduinoFloppyReader::WriteResponse::wrSkipBadChecksums;
67
95
}
68
96
69
97
// Just continue
70
98
return ArduinoFloppyReader::WriteResponse::wrContinue;
71
99
};
72
100
73
- Gtk::Entry *fileEntry = nullptr ;
74
- builder->get_widget (" fileNameEntry" , fileEntry);
75
- Gtk::FileChooserButton *folderButton = nullptr ;
76
- builder->get_widget (" folderSelector" , folderButton);
77
- Gtk::ComboBoxText *typeSelector = nullptr ;
78
- builder->get_widget (" typeSelector" , typeSelector);
79
- fileEntry->signal_changed ().connect ([fileEntry, copyButton]()
101
+ fileEntry->signal_changed ().connect ([this ]()
80
102
{
81
- if (fileEntry->get_text_length () > 0 )
103
+ if (fileEntry->get_text_length () > 0 && diagnosticsButton-> get_sensitive () )
82
104
{
83
105
copyButton->set_sensitive (true );
84
106
}
@@ -87,9 +109,7 @@ class MainWindow : public Gtk::ApplicationWindow
87
109
copyButton->set_sensitive (false );
88
110
}
89
111
});
90
- Gtk::RadioButton *trackButton = nullptr ;
91
- builder->get_widget (" radio80" , trackButton);
92
- copyButton->signal_clicked ().connect ([this , fileEntry, folderButton, typeSelector, trackButton, readerCallback, portsCombo]()
112
+ copyButton->signal_clicked ().connect ([this , readerCallback]()
93
113
{
94
114
Glib::ustring folder = folderButton->get_filename ();
95
115
Glib::ustring filename = folder + " /" + fileEntry->get_buffer ()->get_text ();
@@ -110,46 +130,110 @@ class MainWindow : public Gtk::ApplicationWindow
110
130
handleResult (writer, readerResult);
111
131
});
112
132
113
- auto writerCallback = [this ](const int currentTrack, const ArduinoFloppyReader::DiskSurface currentSide, const bool isVerifyError) -> ArduinoFloppyReader::WriteResponse {
133
+ writeFolderSelector->signal_file_set ().connect ([this ]()
134
+ {
135
+ std::cout<< " got filename" << writeFolderSelector->get_filename () << std::endl;
136
+ if (this ->writeFolderSelector ->get_filename () != " " && diagnosticsButton->get_sensitive ())
137
+ {
138
+ writeButton->set_sensitive (true );
139
+ }
140
+ else
141
+ {
142
+ writeButton->set_sensitive (false );
143
+ }
144
+ });
145
+ auto writerCallback = [this ](const int currentTrack, const ArduinoFloppyReader::DiskSurface currentSide, const bool isVerifyError) -> ArduinoFloppyReader::WriteResponse
146
+ {
114
147
std::string side = (currentSide == ArduinoFloppyReader::DiskSurface::dsUpper ? " Upper" : " Lower" );
115
148
std::cout << " writing: currentTrack: " << currentTrack << " side: " << side << std::endl;
116
149
117
- // if (isVerifyError) {
118
- // switch (MessageBox(L"Verify error writing track.", L"Disk Write Error", MB_ABORTRETRYIGNORE)) {
119
- // case IDABORT: return ArduinoFloppyReader::WriteResponse::wrAbort;
120
- // case IDRETRY: return ArduinoFloppyReader::WriteResponse::wrRetry;
121
- // case IDIGNORE: return ArduinoFloppyReader::WriteResponse::wrSkipBadChecksums;
122
- // }
123
- // }
124
- // Just continue
125
- return ArduinoFloppyReader::WriteResponse::wrContinue;
126
- };
127
- Gtk::Entry *writeFileEntry = nullptr ;
128
- builder->get_widget (" writeFileEntry" , writeFileEntry);
129
- Gtk::FileChooserButton *writeFolderSelector = nullptr ;
130
- builder->get_widget (" writeFolderSelector" , writeFolderSelector);
131
- Gtk::Button *writeButton = nullptr ;
132
- builder->get_widget (" writeButton" , writeButton);
133
- writeButton->signal_clicked ().connect ([this , writeFileEntry, writeFolderSelector, writerCallback, portsCombo]()
150
+ cylinderCount->set_text (Glib::ustring::sprintf (" %i" , currentTrack));
151
+ sideLabel->set_text (side);
152
+ if (isVerifyError)
153
+ {
154
+ Gtk::MessageDialog dialog = Gtk::MessageDialog (*this , " Verify error writing track.\n Disk Write Error" , false , Gtk::MESSAGE_ERROR, Gtk::BUTTONS_NONE);
155
+ dialog.add_button (" Abort" , 1 );
156
+ dialog.add_button (" Retry" , 2 );
157
+ dialog.add_button (" Ignore" , 3 );
158
+ int response = dialog.run ();
159
+ dialog.hide ();
160
+
161
+ switch (response)
162
+ {
163
+ case 1 :
164
+ return ArduinoFloppyReader::WriteResponse::wrAbort;
165
+ case 2 :
166
+ return ArduinoFloppyReader::WriteResponse::wrRetry;
167
+ case 3 :
168
+ return ArduinoFloppyReader::WriteResponse::wrSkipBadChecksums;
169
+ }
170
+ }
171
+ // Just continue
172
+ return ArduinoFloppyReader::WriteResponse::wrContinue;
173
+ };
174
+ writeButton->signal_clicked ().connect ([this , writerCallback]()
134
175
{
135
- Glib::ustring folder = writeFolderSelector->get_filename ();
136
- Glib::ustring filename = folder + " /" + writeFileEntry->get_buffer ()->get_text ();
176
+ Glib::ustring filename = writeFolderSelector->get_filename ();
137
177
ArduinoFloppyReader::ADFWriter writer;
138
178
Glib::ustring serial = portsCombo->get_active_text ();
139
179
writer.openDevice (std::wstring (serial.begin (), serial.end ()));
140
180
ArduinoFloppyReader::ADFResult readerResult;
141
- readerResult = writer.ADFToDisk (std::wstring (filename.begin (), filename.end ()), false , false , writerCallback);
181
+ readerResult = writer.ADFToDisk (std::wstring (filename.begin (), filename.end ()), verify-> get_active (), writeCompensation-> get_active () , writerCallback);
142
182
// Handle the result
143
183
handleResult (writer, readerResult);
144
184
});
145
185
}
146
186
147
187
virtual ~MainWindow () = default ;
148
188
149
- private
150
- :
151
- Glib::RefPtr<Gtk::Builder>
152
- builder;
189
+ private:
190
+ Glib::RefPtr<Gtk::Builder> builder;
191
+ Gtk::ComboBoxText *portsCombo = nullptr ;
192
+ Gtk::Button *diagnosticsButton = nullptr ;
193
+ Gtk::Button *copyButton = nullptr ;
194
+ Gtk::Label *cylinderCount = nullptr ;
195
+ Gtk::Label *sideLabel = nullptr ;
196
+ Gtk::Label *goodCount = nullptr ;
197
+ Gtk::Label *partialCount = nullptr ;
198
+ Gtk::CheckButton *verify = nullptr ;
199
+ Gtk::CheckButton *alwaysIgnore = nullptr ;
200
+ Gtk::CheckButton *writeCompensation = nullptr ;
201
+ Gtk::FileChooserButton *writeFolderSelector = nullptr ;
202
+ Gtk::Button *writeButton = nullptr ;
203
+ Gtk::Entry *fileEntry = nullptr ;
204
+ Gtk::FileChooserButton *folderButton = nullptr ;
205
+ Gtk::ComboBoxText *typeSelector = nullptr ;
206
+ Gtk::RadioButton *trackButton = nullptr ;
207
+ Gtk::Statusbar *statusBar = nullptr ;
208
+
209
+ void get_widgets ()
210
+ {
211
+ builder->get_widget (" serialPortsCombo" , portsCombo);
212
+ builder->get_widget (" diagnosticsButton" , diagnosticsButton);
213
+ builder->get_widget (" copyButton" , copyButton);
214
+ builder->get_widget (" cylinderCount" , cylinderCount);
215
+ builder->get_widget (" sideLabel" , sideLabel);
216
+ builder->get_widget (" goodCount" , goodCount);
217
+ builder->get_widget (" partialCount" , partialCount);
218
+ builder->get_widget (" fileNameEntry" , fileEntry);
219
+ builder->get_widget (" folderSelector" , folderButton);
220
+ builder->get_widget (" typeSelector" , typeSelector);
221
+ builder->get_widget (" radio80" , trackButton);
222
+ builder->get_widget (" alwaysIgnore" , alwaysIgnore);
223
+ builder->get_widget (" verify" , verify);
224
+ builder->get_widget (" writeCompensation" , writeCompensation);
225
+ builder->get_widget (" writeFolderSelector" , writeFolderSelector);
226
+ builder->get_widget (" writeButton" , writeButton);
227
+ builder->get_widget (" statusBar" , statusBar);
228
+ }
229
+
230
+ void reset ()
231
+ {
232
+ cylinderCount->set_text (" 0" );
233
+ goodCount->set_text (" 0" );
234
+ partialCount->set_text (" 0" );
235
+ sideLabel->set_text (" Upper" );
236
+ }
153
237
154
238
void handleResult (ArduinoFloppyReader::ADFWriter writer, ArduinoFloppyReader::ADFResult readerResult)
155
239
{
@@ -214,6 +298,7 @@ private
214
298
break ;
215
299
}
216
300
}
301
+ reset ();
217
302
}
218
303
219
304
bool showQuestion (bool isQuestion, const std::string question)
@@ -260,8 +345,6 @@ private
260
345
strLine = " DIAGNOSTICS FAILED: " ;
261
346
strLine += status.c_str ();
262
347
std::cerr << strLine << std::endl;
263
- Gtk::Statusbar *statusBar = nullptr ;
264
- builder->get_widget (" statusBar" , statusBar);
265
348
statusBar->pop ();
266
349
statusBar->push (strLine);
267
350
}
0 commit comments