1 /*  Copyright 2005 Guillaume Duhamel
2 	Copyright 2005-2006, 2013 Theo Berkau
3 	Copyright 2008 Filipe Azevedo <pasnox@gmail.com>
4 
5 	This file is part of Yabause.
6 
7 	Yabause is free software; you can redistribute it and/or modify
8 	it under the terms of the GNU General Public License as published by
9 	the Free Software Foundation; either version 2 of the License, or
10 	(at your option) any later version.
11 
12 	Yabause is distributed in the hope that it will be useful,
13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 	GNU General Public License for more details.
16 
17 	You should have received a copy of the GNU General Public License
18 	along with Yabause; if not, write to the Free Software
19 	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
20 */
21 #include "UISettings.h"
22 #include "../Settings.h"
23 #include "../CommonDialogs.h"
24 #include "UIPortManager.h"
25 
26 #include <QDir>
27 #include <QList>
28 #include <QDesktopWidget>
29 
30 extern "C" {
31 extern M68K_struct* M68KCoreList[];
32 extern SH2Interface_struct* SH2CoreList[];
33 extern PerInterface_struct* PERCoreList[];
34 extern CDInterface* CDCoreList[];
35 extern SoundInterface_struct* SNDCoreList[];
36 extern VideoInterface_struct* VIDCoreList[];
37 extern OSD_struct* OSDCoreList[];
38 }
39 
40 struct Item
41 {
ItemItem42 	Item( const QString& i, const QString& n, bool e=true, bool s=true, bool z=false)
43 	{ id = i; Name = n; enableFlag = e; saveFlag = s; ipFlag = z; }
44 
45 	QString id;
46 	QString Name;
47 	bool enableFlag;
48 	bool saveFlag;
49 	bool ipFlag;
50 };
51 
52 typedef QList<Item> Items;
53 
54 const Items mRegions = Items()
55 	<< Item( "Auto" , "Auto-detect" )
56 	<< Item( "J" , "Japan (NTSC)" )
57 	<< Item( "T", "Asia (NTSC)" )
58 	<< Item( "U", "North America (NTSC)" )
59 	<< Item( "B", "Central/South America (NTSC)" )
60 	<< Item( "K", "Korea (NTSC)" )
61 	<< Item( "A", "Asia (PAL)" )
62 	<< Item( "E", "Europe + others (PAL)" )
63 	<< Item( "L", "Central/South America (PAL)" );
64 
65 const Items mCartridgeTypes = Items()
66 	<< Item( "0", "None", false, false )
67 	<< Item( "1", "Pro Action Replay", true, false )
68 	<< Item( "2", "4 Mbit Backup Ram", true, true )
69 	<< Item( "3", "8 Mbit Backup Ram", true, true )
70 	<< Item( "4", "16 Mbit Backup Ram", true, true )
71 	<< Item( "5", "32 Mbit Backup Ram", true, true )
72 	<< Item( "6", "8 Mbit Dram", false, false )
73 	<< Item( "7", "32 Mbit Dram", false, false )
74 	<< Item( "8", "Netlink", false, false, true )
75 	<< Item( "9", "16 Mbit ROM", true, false )
76 	<< Item( "10", "Japanese Modem", false, false, true );
77 
78 const Items mVideoFormats = Items()
79 	<< Item( "0", "NTSC" )
80 	<< Item( "1", "PAL" );
81 
UISettings(QList<supportedRes_struct> * supportedResolutions,QList<translation_struct> * translations,QWidget * p)82 UISettings::UISettings( QList <supportedRes_struct> *supportedResolutions, QList <translation_struct> *translations, QWidget* p )
83 	: QDialog( p )
84 {
85 	// setup dialog
86 	setupUi( this );
87 
88 	QRect maxWinRect = QApplication::desktop()->availableGeometry();
89 
90 
91 	leWinWidth->setValidator(new QIntValidator(0, maxWinRect.width(), leWinWidth));
92 	leWinHeight->setValidator(new QIntValidator(0, maxWinRect.height(), leWinHeight));
93 
94 	QString ipNum("(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])");
95 	leCartridgeModemIP->setValidator(new QRegExpValidator(QRegExp("^" + ipNum + "\\." + ipNum + "\\." + ipNum + "\\." + ipNum + "$"), leCartridgeModemIP));
96 	leCartridgeModemPort->setValidator(new QIntValidator(1, 65535, leCartridgeModemPort));
97 
98 	pmPort1->setPort( 1 );
99 	pmPort1->loadSettings();
100 	pmPort2->setPort( 2 );
101 	pmPort2->loadSettings();
102 
103 	if ( p && !p->isFullScreen() )
104 	{
105 		setWindowFlags( Qt::Sheet );
106 	}
107 
108 	setupCdDrives();
109 
110 	// load cores informations
111 	loadCores();
112 
113 	supportedRes = *supportedResolutions;
114 	loadSupportedResolutions();
115 
116 #ifdef HAVE_LIBMINI18N
117 	trans = *translations;
118 	loadTranslations();
119 #else
120    lTranslation->hide();
121 	cbTranslation->hide();
122 #endif
123 
124 	loadShortcuts();
125 
126 	// load settings
127 	loadSettings();
128 
129 	// connections
130 	foreach ( QToolButton* tb, findChildren<QToolButton*>() )
131 	{
132 		connect( tb, SIGNAL( clicked() ), this, SLOT( tbBrowse_clicked() ) );
133 	}
134 
135 	// retranslate widgets
136 	QtYabause::retranslateWidget( this );
137 }
138 
requestFile(const QString & c,QLineEdit * e,const QString & filters)139 void UISettings::requestFile( const QString& c, QLineEdit* e, const QString& filters )
140 {
141 	const QString s = CommonDialogs::getOpenFileName( e->text(), c, filters );
142 	if ( !s.isNull() )
143 		e->setText( s );
144 }
145 
requestNewFile(const QString & c,QLineEdit * e,const QString & filters)146 void UISettings::requestNewFile( const QString& c, QLineEdit* e, const QString& filters )
147 {
148 	const QString s = CommonDialogs::getSaveFileName( e->text(), c, filters );
149 	if ( !s.isNull() )
150 		e->setText( s );
151 }
152 
requestFolder(const QString & c,QLineEdit * e)153 void UISettings::requestFolder( const QString& c, QLineEdit* e )
154 {
155 	const QString s = CommonDialogs::getExistingDirectory( e->text(), c );
156 	if ( !s.isNull() )
157 		e->setText( s );
158 }
159 
getCdDriveList()160 QStringList getCdDriveList()
161 {
162 	QStringList list;
163 
164 #if defined Q_OS_WIN
165 	foreach( QFileInfo drive, QDir::drives () )
166 	{
167 		LPCWSTR driveString = (LPCWSTR)drive.filePath().utf16();
168 		if (GetDriveTypeW(driveString) == DRIVE_CDROM)
169 			list.append(drive.filePath());
170 	}
171 #elif defined Q_OS_LINUX
172 	FILE * f = fopen("/proc/sys/dev/cdrom/info", "r");
173 	char buffer[1024];
174 	char drive_name[10];
175 	char drive_path[255];
176 
177 	if (f != NULL) {
178 		while (fgets(buffer, 1024, f) != NULL) {
179 			if (sscanf(buffer, "drive name:%s", drive_name) == 1) {
180 				sprintf(drive_path, "/dev/%s", drive_name);
181 
182 				list.append(drive_path);
183 			}
184 		}
185 		fclose(f);
186 	}
187 #elif defined Q_OS_MAC
188 #endif
189 	return list;
190 }
191 
setupCdDrives()192 void UISettings::setupCdDrives()
193 {
194 	QStringList list=getCdDriveList();
195 	foreach(QString string, list)
196 		cbCdDrive->addItem(string);
197 }
198 
on_leBios_textChanged(const QString & text)199 void UISettings::on_leBios_textChanged(const QString & text)
200 {
201 	if (QFileInfo(text).exists())
202 		cbEnableBiosEmulation->setEnabled(true);
203 	else
204 		cbEnableBiosEmulation->setEnabled(false);
205 }
206 
tbBrowse_clicked()207 void UISettings::tbBrowse_clicked()
208 {
209 	// get toolbutton sender
210 	QToolButton* tb = qobject_cast<QToolButton*>( sender() );
211 
212 	if ( tb == tbBios )
213 		requestFile( QtYabause::translate( "Choose a bios file" ), leBios );
214 	else if ( tb == tbCdRom )
215 	{
216 		if ( cbCdRom->currentText().contains( "dummy", Qt::CaseInsensitive ) )
217 		{
218 			CommonDialogs::information( QtYabause::translate( "The dummies cores don't need configuration." ) );
219 			return;
220 		}
221 		else if ( cbCdRom->currentText().contains( "iso", Qt::CaseInsensitive ) )
222 			requestFile( QtYabause::translate( "Select your iso/cue/bin file" ), leCdRom, QtYabause::translate( "CD Images (*.iso *.cue *.bin *.mds *.ccd)" ) );
223 		else
224 			requestFolder( QtYabause::translate( "Choose a cdrom drive/mount point" ), leCdRom );
225 	}
226 	else if ( tb == tbSaveStates )
227 		requestFolder( QtYabause::translate( "Choose a folder to store save states" ), leSaveStates );
228 	else if ( tb == tbCartridge )
229 	{
230 		if (mCartridgeTypes[cbCartridge->currentIndex()].saveFlag)
231 			requestNewFile( QtYabause::translate( "Choose a cartridge file" ), leCartridge );
232 		else
233 			requestFile( QtYabause::translate( "Choose a cartridge file" ), leCartridge );
234 	}
235 	else if ( tb == tbMemory )
236 		requestNewFile( QtYabause::translate( "Choose a memory file" ), leMemory );
237 	else if ( tb == tbSH1ROM )
238 		requestFile( QtYabause::translate( "Choose a sh1 rom" ), leSH1ROM );
239 	else if ( tb == tbMpegROM )
240 		requestFile( QtYabause::translate( "Choose a mpeg rom" ), leMpegROM );
241 }
242 
on_cbInput_currentIndexChanged(int id)243 void UISettings::on_cbInput_currentIndexChanged( int id )
244 {
245 	PerInterface_struct* core = QtYabause::getPERCore( cbInput->itemData( id ).toInt() );
246         core->Init();
247 
248 	Q_ASSERT( core );
249 
250 	pmPort1->setCore( core );
251 	pmPort2->setCore( core );
252 }
253 
on_cbCdRom_currentIndexChanged(int id)254 void UISettings::on_cbCdRom_currentIndexChanged( int id )
255 {
256 	CDInterface* core = QtYabause::getCDCore( cbCdRom->itemData( id ).toInt() );
257 
258 	Q_ASSERT( core );
259 
260 	switch (core->id)
261 	{
262 		case CDCORE_DUMMY:
263 			cbCdDrive->setVisible(false);
264 			leCdRom->setVisible(false);
265 			tbCdRom->setVisible(false);
266 			break;
267 		case CDCORE_ISO:
268 			cbCdDrive->setVisible(false);
269 			leCdRom->setVisible(true);
270 			tbCdRom->setVisible(true);
271 			break;
272 		case CDCORE_ARCH:
273 			cbCdDrive->setVisible(true);
274 			leCdRom->setVisible(false);
275 			tbCdRom->setVisible(false);
276 			break;
277 		default: break;
278 	}
279 }
280 
on_cbClockSync_stateChanged(int state)281 void UISettings::on_cbClockSync_stateChanged( int state )
282 {
283 	dteBaseTime->setVisible( state == Qt::Checked );
284 }
285 
on_cbCartridge_currentIndexChanged(int id)286 void UISettings::on_cbCartridge_currentIndexChanged( int id )
287 {
288 	leCartridge->setVisible(mCartridgeTypes[id].enableFlag);
289 	tbCartridge->setVisible(mCartridgeTypes[id].enableFlag);
290 	lCartridgeModemIP->setVisible(mCartridgeTypes[id].ipFlag);
291 	leCartridgeModemIP->setVisible(mCartridgeTypes[id].ipFlag);
292 	lCartridgeModemPort->setVisible(mCartridgeTypes[id].ipFlag);
293 	leCartridgeModemPort->setVisible(mCartridgeTypes[id].ipFlag);
294 }
295 
loadCores()296 void UISettings::loadCores()
297 {
298 	// CD Drivers
299 	for ( int i = 0; CDCoreList[i] != NULL; i++ )
300 		cbCdRom->addItem( QtYabause::translate( CDCoreList[i]->Name ), CDCoreList[i]->id );
301 
302 	// VDI Drivers
303 	for ( int i = 0; VIDCoreList[i] != NULL; i++ )
304 		cbVideoCore->addItem( QtYabause::translate( VIDCoreList[i]->Name ), VIDCoreList[i]->id );
305 
306 #if YAB_PORT_OSD
307 	// OSD Drivers
308 	for ( int i = 0; OSDCoreList[i] != NULL; i++ )
309 		cbOSDCore->addItem( QtYabause::translate( OSDCoreList[i]->Name ), OSDCoreList[i]->id );
310 #else
311 	delete cbOSDCore;
312 	delete lOSDCore;
313 #endif
314 
315 	// Video Formats
316 	foreach ( const Item& it, mVideoFormats )
317 		cbVideoFormat->addItem( QtYabause::translate( it.Name ), it.id );
318 
319 	// SND Drivers
320 	for ( int i = 0; SNDCoreList[i] != NULL; i++ )
321 		cbSoundCore->addItem( QtYabause::translate( SNDCoreList[i]->Name ), SNDCoreList[i]->id );
322 
323 	// Cartridge Types
324 	foreach ( const Item& it, mCartridgeTypes )
325 		cbCartridge->addItem( QtYabause::translate( it.Name ), it.id );
326 
327 	// Input Drivers
328 	for ( int i = 0; PERCoreList[i] != NULL; i++ )
329 		cbInput->addItem( QtYabause::translate( PERCoreList[i]->Name ), PERCoreList[i]->id );
330 
331 	// Regions
332 	foreach ( const Item& it, mRegions )
333 		cbRegion->addItem( QtYabause::translate( it.Name ), it.id );
334 
335 	// SH2 Interpreters
336 	for ( int i = 0; SH2CoreList[i] != NULL; i++ )
337 	{
338 		cbSH1Interpreter->addItem( QtYabause::translate( SH2CoreList[i]->Name ), SH2CoreList[i]->id );
339 		cbSH2Interpreter->addItem( QtYabause::translate( SH2CoreList[i]->Name ), SH2CoreList[i]->id );
340 	}
341 
342    //68k cores
343    for (int i = 0; M68KCoreList[i] != NULL; i++)
344       cb68kCore->addItem(QtYabause::translate(M68KCoreList[i]->Name), M68KCoreList[i]->id);
345 
346 	cbAspectRatio->addItem( QtYabause::translate( "Fit to window" ), 0 );
347 	cbAspectRatio->addItem( QtYabause::translate( "Fixed aspect ratio: 4:3" ), 1 );
348 	cbAspectRatio->addItem( QtYabause::translate( "Fixed aspect ratio: 16:9" ), 2 );
349 }
350 
loadSupportedResolutions()351 void UISettings::loadSupportedResolutions()
352 {
353 	if (supportedRes.count() == 0)
354 	{
355 		lFullScreenResolution->setVisible(false);
356 		cbFullscreenResolution->setVisible(false);
357 		return;
358 	}
359 
360 	// Load supported screen resolutions
361 	for (int i = 0; i < this->supportedRes.count(); i++)
362 	{
363 		QString text = QString("%1x%2").arg(QString::number(this->supportedRes[i].width),
364 			QString::number (this->supportedRes[i].height));
365 		if (cbFullscreenResolution->findText(text) != -1)
366 			continue;
367 		cbFullscreenResolution->addItem(text, i);
368 	}
369 }
370 
loadTranslations()371 void UISettings::loadTranslations()
372 {
373 	cbTranslation->addItem(QString::fromUtf8(_("Use System Locale")), "");
374 	cbTranslation->addItem("English", "#");
375 	for (int i = 0; i < this->trans.count(); i++)
376 		cbTranslation->addItem(trans[i].name.left(1).toUpper()+trans[i].name.mid(1), trans[i].file);
377 
378 }
379 
loadShortcuts()380 void UISettings::loadShortcuts()
381 {
382 	QList<QAction *> actions = parent()->findChildren<QAction *>();
383 	foreach ( QAction* action, actions )
384 	{
385 		if (action->text().isEmpty())
386 			continue;
387 
388 		actionsList.append(action);
389 	}
390 
391 	int row=0;
392 	twShortcuts->setRowCount(actionsList.count());
393 	foreach ( QAction* action, actionsList )
394 	{
395 		QTableWidgetItem *tblItem = new QTableWidgetItem(QString::fromUtf8(_(action->text().toUtf8())));
396 		tblItem->setFlags(tblItem->flags() ^ Qt::ItemIsEditable);
397 		twShortcuts->setItem(row, 0, tblItem);
398 		tblItem = new QTableWidgetItem(action->shortcut().toString());
399 		twShortcuts->setItem(row, 1, tblItem);
400 		row++;
401 	}
402 	QHeaderView *headerView = twShortcuts->horizontalHeader();
403 #if QT_VERSION >= 0x04FF00
404 	headerView->setSectionResizeMode(QHeaderView::Stretch);
405 	headerView->setSectionResizeMode(1, QHeaderView::Interactive);
406 #else
407 	headerView->setResizeMode(QHeaderView::Stretch);
408 	headerView->setResizeMode(1, QHeaderView::Interactive);
409 #endif
410 }
411 
applyShortcuts()412 void UISettings::applyShortcuts()
413 {
414 	for (int row = 0; row < (int)actionsList.size(); ++row)
415 	{
416 		QAction *action = actionsList[row];
417 		action->setShortcut(QKeySequence(twShortcuts->item(row, 1)->text()));
418 	}
419 }
420 
loadSettings()421 void UISettings::loadSettings()
422 {
423 	// get settings pointer
424 	Settings* s = QtYabause::settings();
425 
426 	// general
427 	leBios->setText( s->value( "General/Bios" ).toString() );
428 	cbEnableBiosEmulation->setChecked( s->value( "General/EnableEmulatedBios" ).toBool() );
429 	cbCdRom->setCurrentIndex( cbCdRom->findData( s->value( "General/CdRom", QtYabause::defaultCDCore().id ).toInt() ) );
430 	leCdRom->setText( s->value( "General/CdRomISO" ).toString() );
431 	if (s->value( "General/CdRom", QtYabause::defaultCDCore().id ).toInt() == CDCORE_ARCH)
432 		cbCdDrive->setCurrentIndex(leCdRom->text().isEmpty() ? 0 : cbCdDrive->findText(leCdRom->text()));
433 
434 	leSaveStates->setText( s->value( "General/SaveStates", getDataDirPath() ).toString() );
435 #ifdef HAVE_LIBMINI18N
436 	int i;
437 	if ((i=cbTranslation->findData(s->value( "General/Translation" ).toString())) != -1)
438 		cbTranslation->setCurrentIndex(i);
439 	else
440 		cbTranslation->setCurrentIndex(0);
441 #endif
442 	cbEnableFrameSkipLimiter->setChecked( s->value( "General/EnableFrameSkipLimiter" ).toBool() );
443 	cbShowFPS->setChecked( s->value( "General/ShowFPS" ).toBool() );
444 	cbAutostart->setChecked( s->value( "autostart" ).toBool() );
445 
446 	bool clocksync = s->value( "General/ClockSync" ).toBool();
447 	cbClockSync->setChecked( clocksync );
448 	dteBaseTime->setVisible( clocksync );
449 
450 	QString dt = s->value( "General/FixedBaseTime" ).toString();
451 	if (!dt.isEmpty())
452 		dteBaseTime->setDateTime( QDateTime::fromString( dt,Qt::ISODate) );
453 	else
454 		dteBaseTime->setDateTime( QDateTime(QDate(1998, 1, 1), QTime(12, 0, 0)) );
455 
456 	int numThreads = QThread::idealThreadCount();
457 	cbEnableMultiThreading->setChecked(s->value( "General/EnableMultiThreading", numThreads <= 1 ? false : true ).toBool());
458 	sbNumberOfThreads->setValue(s->value( "General/NumThreads", numThreads < 0 ? 1 : numThreads ).toInt());
459 
460 	// video
461 	cbVideoCore->setCurrentIndex( cbVideoCore->findData( s->value( "Video/VideoCore", QtYabause::defaultVIDCore().id ).toInt() ) );
462 #if YAB_PORT_OSD
463 	cbOSDCore->setCurrentIndex( cbOSDCore->findData( s->value( "Video/OSDCore", QtYabause::defaultOSDCore().id ).toInt() ) );
464 #endif
465 
466 	cbAspectRatio->setCurrentIndex( s->value( "Video/AspectRatio", 0 ).toInt() );
467 	leWinWidth->setText( s->value( "Video/WindowWidth", s->value( "Video/Width", 640 ) ).toString() );
468 	leWinHeight->setText( s->value( "Video/WindowHeight", s->value( "Video/Height", 480 ) ).toString() );
469 	QString text = QString("%1x%2").arg(s->value( "Video/FullscreenWidth", s->value( "Video/Width", 640 ) ).toString(),
470 										s->value( "Video/FullscreenHeight", s->value( "Video/Height", 480 ) ).toString());
471 	cbFullscreenResolution->setCurrentIndex(cbFullscreenResolution->findText(text));
472 	cbBilinear->setChecked( s->value( "Video/Bilinear", false ).toBool() );
473 	cbFullscreen->setChecked( s->value( "Video/Fullscreen", false ).toBool() );
474 	cbVideoFormat->setCurrentIndex( cbVideoFormat->findData( s->value( "Video/VideoFormat", mVideoFormats.at( 0 ).id ).toInt() ) );
475 
476    cbEnableIntegerPixelScaling->setChecked(s->value("Video/EnableIntegerPixelScaling", false).toBool());
477    sbIntegerPixelScalingMultiplier->setValue(s->value("Video/IntegerPixelScalingMultiplier", 2).toInt());
478 
479 	// sound
480 	cbSoundCore->setCurrentIndex( cbSoundCore->findData( s->value( "Sound/SoundCore", QtYabause::defaultSNDCore().id ).toInt() ) );
481    cbNewScsp->setChecked(s->value("Sound/NewScsp", true).toBool());
482    cbScspDspDynarec->setChecked(s->value("Sound/EnableScspDspDynarec", true).toBool());
483 
484 	// cartridge/memory
485 	cbCartridge->setCurrentIndex( cbCartridge->findData( s->value( "Cartridge/Type", mCartridgeTypes.at( 0 ).id ).toInt() ) );
486 	leCartridge->setText( s->value( "Cartridge/Path" ).toString() );
487 	leCartridgeModemIP->setText( s->value( "Cartridge/ModemIP", QString("127.0.0.1") ).toString() );
488 	leCartridgeModemPort->setText( s->value( "Cartridge/ModemPort", QString("1337") ).toString() );
489 	leMemory->setText( s->value( "Memory/Path", getDataDirPath().append( "/bkram.bin" ) ).toString() );
490 	leSH1ROM->setText( s->value( "SH1ROM/Path" ).toString() );
491 	leMpegROM->setText( s->value( "MpegROM/Path" ).toString() );
492 
493 	// input
494 	cbInput->setCurrentIndex( cbInput->findData( s->value( "Input/PerCore", QtYabause::defaultPERCore().id ).toInt() ) );
495 	sGunMouseSensitivity->setValue(s->value( "Input/GunMouseSensitivity", 100).toInt() );
496 
497 	// advanced
498 	cbRegion->setCurrentIndex( cbRegion->findData( s->value( "Advanced/Region", mRegions.at( 0 ).id ).toString() ) );
499 	cbSH1Interpreter->setCurrentIndex( cbSH1Interpreter->findData( s->value( "Advanced/SH1Interpreter", QtYabause::defaultSH2Core().id ).toInt() ) );
500 	cbEnableCDBlockLLE->setChecked( s->value( "Advanced/EnableCDBlockLLE" ).toBool() );
501    cbEnableSh2DmaTiming->setChecked(s->value("Advanced/EnableSh2DmaTiming").toBool());
502    cbEnableScuDmaTiming->setChecked(s->value("Advanced/EnableScuDmaTiming").toBool());
503    cbEnableSh2Cache->setChecked(s->value("Advanced/EnableSh2Cache").toBool());
504 	cbSH2Interpreter->setCurrentIndex( cbSH2Interpreter->findData( s->value( "Advanced/SH2Interpreter", QtYabause::defaultSH2Core().id ).toInt() ) );
505    cb68kCore->setCurrentIndex(cb68kCore->findData(s->value("Advanced/68kCore", QtYabause::default68kCore().id).toInt()));
506    cbScuDspDynarec->setChecked(s->value("Advanced/EnableScuDspDynarec", false).toBool());
507 
508 	// view
509 	bgShowMenubar->setId( rbMenubarNever, BD_NEVERHIDE );
510 	bgShowMenubar->setId( rbMenubarFullscreen, BD_HIDEFS );
511 	bgShowMenubar->setId( rbMenubarAlways, BD_ALWAYSHIDE );
512 	bgShowMenubar->setId( rbMenubarFullscreenHover, BD_SHOWONFSHOVER );
513 	bgShowMenubar->button( s->value( "View/Menubar", BD_SHOWONFSHOVER ).toInt() )->setChecked( true );
514 
515 	bgShowToolbar->setId( rbToolbarNever, BD_NEVERHIDE );
516 	bgShowToolbar->setId( rbToolbarFullscreen, BD_HIDEFS );
517 	bgShowToolbar->setId( rbToolbarAlways, BD_ALWAYSHIDE );
518 	bgShowToolbar->button( s->value( "View/Toolbar", BD_HIDEFS ).toInt() )->setChecked( true );
519 
520 	bgShowLogWindow->setId( rbLogWindowNever, 0 );
521 	bgShowLogWindow->setId( rbLogWindowMessage, 1 );
522 	bgShowLogWindow->button( s->value( "View/LogWindow", 0 ).toInt() )->setChecked( true );
523 }
524 
saveSettings()525 void UISettings::saveSettings()
526 {
527 	// get settings pointer
528 	Settings* s = QtYabause::settings();
529 
530 	// general
531 	s->setValue( "General/Bios", leBios->text() );
532 	s->setValue( "General/EnableEmulatedBios", cbEnableBiosEmulation->isChecked() );
533 	s->setValue( "General/CdRom", cbCdRom->itemData( cbCdRom->currentIndex() ).toInt() );
534 	CDInterface* core = QtYabause::getCDCore( cbCdRom->itemData( cbCdRom->currentIndex() ).toInt() );
535 	if ( core->id == CDCORE_ARCH )
536 		s->setValue( "General/CdRomISO", cbCdDrive->currentText() );
537 	else
538 		s->setValue( "General/CdRomISO", leCdRom->text() );
539 	s->setValue( "General/SaveStates", leSaveStates->text() );
540 #ifdef HAVE_LIBMINI18N
541 	s->setValue( "General/Translation", cbTranslation->itemData(cbTranslation->currentIndex()).toString() );
542 #endif
543 	s->setValue( "General/EnableFrameSkipLimiter", cbEnableFrameSkipLimiter->isChecked() );
544 	s->setValue( "General/ShowFPS", cbShowFPS->isChecked() );
545 	s->setValue( "autostart", cbAutostart->isChecked() );
546 
547 	// video
548 	s->setValue( "Video/VideoCore", cbVideoCore->itemData( cbVideoCore->currentIndex() ).toInt() );
549 #if YAB_PORT_OSD
550 	s->setValue( "Video/OSDCore", cbOSDCore->itemData( cbOSDCore->currentIndex() ).toInt() );
551 #endif
552 	// Move Outdated window/fullscreen keys
553 	s->remove("Video/Width");
554 	s->remove("Video/Height");
555 
556 	// Save new version of keys
557 	s->setValue( "Video/WindowWidth", leWinWidth->text() );
558 	s->setValue( "Video/WindowHeight", leWinHeight->text() );
559 	s->setValue( "Video/AspectRatio", cbAspectRatio->currentIndex() );
560 
561 	if (supportedRes.count() > 0)
562 	{
563 		supportedRes_struct res = supportedRes[cbFullscreenResolution->itemData(cbFullscreenResolution->currentIndex()).toInt()];
564 		s->setValue( "Video/FullscreenWidth", res.width );
565 		s->setValue( "Video/FullscreenHeight", res.height );
566 	}
567 
568 	s->setValue( "Video/Fullscreen", cbFullscreen->isChecked() );
569 	s->setValue( "Video/Bilinear", cbBilinear->isChecked() );
570 	s->setValue( "Video/VideoFormat", cbVideoFormat->itemData( cbVideoFormat->currentIndex() ).toInt() );
571 
572    s->setValue("Video/EnableIntegerPixelScaling", cbEnableIntegerPixelScaling->isChecked());
573    s->setValue("Video/IntegerPixelScalingMultiplier", sbIntegerPixelScalingMultiplier->value());
574 
575 	s->setValue( "General/ClockSync", cbClockSync->isChecked() );
576 	s->setValue( "General/FixedBaseTime", dteBaseTime->dateTime().toString(Qt::ISODate));
577 
578 	s->setValue( "General/EnableMultiThreading", cbEnableMultiThreading->isChecked() );
579 	s->setValue( "General/NumThreads", sbNumberOfThreads->value());
580 
581 	// sound
582 	s->setValue( "Sound/SoundCore", cbSoundCore->itemData( cbSoundCore->currentIndex() ).toInt() );
583    s->setValue( "Sound/NewScsp", cbNewScsp->isChecked());
584    s->setValue("Sound/EnableScspDspDynarec", cbScspDspDynarec->isChecked());
585 
586 	// cartridge/memory
587 	s->setValue( "Cartridge/Type", cbCartridge->itemData( cbCartridge->currentIndex() ).toInt() );
588 	s->setValue( "Cartridge/Path", leCartridge->text() );
589 	s->setValue( "Cartridge/ModemIP", leCartridgeModemIP->text() );
590 	s->setValue( "Cartridge/ModemPort", leCartridgeModemPort->text() );
591 	s->setValue( "Memory/Path", leMemory->text() );
592 	s->setValue( "SH1ROM/Path", leSH1ROM->text() );
593 	s->setValue( "MpegROM/Path", leMpegROM->text() );
594 
595 	// input
596 	s->setValue( "Input/PerCore", cbInput->itemData( cbInput->currentIndex() ).toInt() );
597 	s->setValue( "Input/GunMouseSensitivity", sGunMouseSensitivity->value() );
598 
599 	// advanced
600 	s->setValue( "Advanced/Region", cbRegion->itemData( cbRegion->currentIndex() ).toString() );
601 	s->setValue( "Advanced/SH1Interpreter", cbSH1Interpreter->itemData( cbSH1Interpreter->currentIndex() ).toInt() );
602 	s->setValue( "Advanced/EnableCDBlockLLE", cbEnableCDBlockLLE->isChecked() );
603    s->setValue("Advanced/EnableSh2DmaTiming", cbEnableSh2DmaTiming->isChecked());
604    s->setValue("Advanced/EnableScuDmaTiming", cbEnableScuDmaTiming->isChecked());
605    s->setValue("Advanced/EnableSh2Cache", cbEnableSh2Cache->isChecked());
606 	s->setValue( "Advanced/SH2Interpreter", cbSH2Interpreter->itemData( cbSH2Interpreter->currentIndex() ).toInt() );
607    s->setValue("Advanced/68kCore", cb68kCore->itemData(cb68kCore->currentIndex()).toInt());
608    s->setValue("Advanced/EnableScuDspDynarec", cbScuDspDynarec->isChecked());
609 
610 	// view
611 	s->setValue( "View/Menubar", bgShowMenubar->checkedId() );
612 	s->setValue( "View/Toolbar", bgShowToolbar->checkedId() );
613 	s->setValue( "View/LogWindow", bgShowLogWindow->checkedId() );
614 
615 	// shortcuts
616 	applyShortcuts();
617 	s->beginGroup("Shortcuts");
618 	QList<QAction *> actions = parent()->findChildren<QAction *>();
619 	foreach ( QAction* action, actions )
620 	{
621 		if (action->text().isEmpty())
622 			continue;
623 
624 		QString accelText = QString(action->shortcut().toString());
625 		s->setValue(action->text(), accelText);
626 	}
627 	s->endGroup();
628 }
629 
accept()630 void UISettings::accept()
631 {
632 	saveSettings();
633 	QDialog::accept();
634 }
635