Fixed bugs: dialogs remained disabled (signals were not attached to
[emufront] / src / dialogs / platformdialog.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
11 //
12 // EmuFront 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 EmuFront.  If not, see <http://www.gnu.org/licenses/>.
19
20 #include <QtGui>
21 #include "../db/dbplatform.h"
22 #include "../dataobjects/platform.h"
23 #include "platformdialog.h"
24 #include "platformnamedialog.h"
25
26 PlatformDialog::PlatformDialog(QWidget *parent)
27     : EmuFrontFileObjectDialog(parent)
28 {
29     setWindowTitle(tr("Set emulated platforms"));
30     dbManager = new DbPlatform(this);
31     initDataTable();
32     initEditDialog();
33     setColumnsHidden();
34     hideColumns();
35
36     // do not move to parent class:
37     connectSignals();
38 }
39
40 PlatformDialog::~PlatformDialog()
41 {
42     qDebug() << "PlatformDialog destructor.";
43     deleteCurrentObject();
44 }
45
46 void PlatformDialog::initEditDialog()
47 {
48     nameDialog = new PlatformNameDialog(this, dynamic_cast<Platform*>(dbObject));
49     connectNameDialogSignals();
50 }
51
52 EmuFrontObject* PlatformDialog::createObject()
53 {
54     qDebug() << "PlatformDialog creating a Platform object.";
55     return new Platform;
56 }
57
58 void PlatformDialog::deleteCurrentObject()
59 {
60     if (dbObject) {
61         qDebug() << "PlatformDialog deleting a Platform object.";
62         Platform *plf = dynamic_cast<Platform*>(dbObject);
63         if (plf) delete plf;
64         else qDebug() << "Failed deleting Platform";
65         dbObject = 0;
66     }
67 }
68
69 void PlatformDialog::cleanUp()
70 {
71     deleteCurrentObject();
72     if (nameDialog) {
73         PlatformNameDialog *pnd =
74             dynamic_cast<PlatformNameDialog*>(nameDialog);
75         if (pnd) delete pnd;
76         else qDebug() << "Failed to delete PlatformNameDialog";
77         nameDialog = 0;
78     }
79 }