]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/configdialog.cpp
1c8936796b0cd9b82eb2bbb35aed7406e0841786
[virtualjaguar] / src / gui / configdialog.cpp
1 //
2 // configdialog.cpp - Configuration dialog
3 //
4 // by James Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  01/29/2010  Created this file
12 // JLH  06/23/2011  Added initial implementation
13 // JLH  10/14/2011  Fixed possibly missing final slash in paths
14 //
15
16 #include "configdialog.h"
17
18 #include "alpinetab.h"
19 #include "controllertab.h"
20 #include "controllerwidget.h"
21 #include "generaltab.h"
22 #include "settings.h"
23
24
25 ConfigDialog::ConfigDialog(QWidget * parent/*= 0*/): QDialog(parent)
26 {
27         tabWidget = new QTabWidget;
28         generalTab = new GeneralTab(this);
29         controllerTab1 = new ControllerTab(this);
30         controllerTab2 = new ControllerTab(this);
31
32         if (vjs.hardwareTypeAlpine)
33                 alpineTab = new AlpineTab(this);
34
35         tabWidget->addTab(generalTab, tr("General"));
36         tabWidget->addTab(controllerTab1, tr("Controller #1"));
37         tabWidget->addTab(controllerTab2, tr("Controller #2"));
38
39         if (vjs.hardwareTypeAlpine)
40                 tabWidget->addTab(alpineTab, tr("Alpine"));
41
42         buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
43
44         connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
45         connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
46
47         QVBoxLayout * mainLayout = new QVBoxLayout;
48         mainLayout->addWidget(tabWidget);
49         mainLayout->addWidget(buttonBox);
50         setLayout(mainLayout);
51
52         setWindowTitle(tr("Virtual Jaguar Settings"));
53
54         LoadDialogFromSettings();
55 //      controllerTab1->UpdateLabel();                          // Now it's safe to do this... ;-)
56 //      controllerTab2->UpdateLabel();                          // Now it's safe to do this... ;-)
57 }
58
59
60 ConfigDialog::~ConfigDialog()
61 {
62 }
63
64
65 void ConfigDialog::LoadDialogFromSettings(void)
66 {
67 //      generalTab->edit1->setText(vjs.jagBootPath);
68 //      generalTab->edit2->setText(vjs.CDBootPath);
69         generalTab->edit3->setText(vjs.EEPROMPath);
70         generalTab->edit4->setText(vjs.ROMPath);
71
72         generalTab->useBIOS->setChecked(vjs.useJaguarBIOS);
73         generalTab->useGPU->setChecked(vjs.GPUEnabled);
74         generalTab->useDSP->setChecked(vjs.DSPEnabled);
75         generalTab->useFullScreen->setChecked(vjs.fullscreen);
76 //      generalTab->useHostAudio->setChecked(vjs.audioEnabled);
77
78         if (vjs.hardwareTypeAlpine)
79         {
80                 alpineTab->edit1->setText(vjs.alpineROMPath);
81                 alpineTab->edit2->setText(vjs.absROMPath);
82                 alpineTab->writeROM->setChecked(vjs.allowWritesToROM);
83         }
84
85         for(int i=0; i<21; i++)
86         {
87                 controllerTab1->controllerWidget->keys[i] = vjs.p1KeyBindings[i];
88                 controllerTab2->controllerWidget->keys[i] = vjs.p2KeyBindings[i];
89         }
90 }
91
92
93 void ConfigDialog::UpdateVJSettings(void)
94 {
95 //      strcpy(vjs.jagBootPath, generalTab->edit1->text().toAscii().data());
96 //      strcpy(vjs.CDBootPath,  generalTab->edit2->text().toAscii().data());
97         strcpy(vjs.EEPROMPath,  CheckForTrailingSlash(
98                 generalTab->edit3->text()).toAscii().data());
99         strcpy(vjs.ROMPath,     CheckForTrailingSlash(
100                 generalTab->edit4->text()).toAscii().data());
101
102         vjs.useJaguarBIOS = generalTab->useBIOS->isChecked();
103         vjs.GPUEnabled    = generalTab->useGPU->isChecked();
104         vjs.DSPEnabled    = generalTab->useDSP->isChecked();
105         vjs.fullscreen    = generalTab->useFullScreen->isChecked();
106 //      vjs.audioEnabled  = generalTab->useHostAudio->isChecked();
107
108         if (vjs.hardwareTypeAlpine)
109         {
110                 strcpy(vjs.alpineROMPath, alpineTab->edit1->text().toAscii().data());
111                 strcpy(vjs.absROMPath,    alpineTab->edit2->text().toAscii().data());
112                 vjs.allowWritesToROM = alpineTab->writeROM->isChecked();
113         }
114
115         for(int i=0; i<21; i++)
116         {
117                 vjs.p1KeyBindings[i] = controllerTab1->controllerWidget->keys[i];
118                 vjs.p2KeyBindings[i] = controllerTab2->controllerWidget->keys[i];
119         }
120 }
121
122
123 QString ConfigDialog::CheckForTrailingSlash(QString s)
124 {
125         if (!s.endsWith('/') && !s.endsWith('\\'))
126                 s.append('/');
127
128         return s;
129 }