3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
23 #include "filepathobject.h"
24 #include "emufrontfileobject.h"
25 #include "dbfilepath.h"
27 #include "mediaimagepathmaindialog.h"
28 #include "mediaimagepathdialog.h"
30 MediaImagePathMainDialog::MediaImagePathMainDialog(QWidget *parent)
31 : DbObjectDialog(parent)
33 setWindowTitle(tr("Set media image paths"));
34 dbManager = new DbFilePath(this);
35 dbMediaImageContainer = new DbMediaImageContainer(this);
38 scanButton = new QPushButton(tr("&Scan"));
39 buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole);
42 hiddenColumns << DbFilePath::FilePath_Id;
43 hiddenColumns << DbFilePath::FilePath_SetupId;
46 fileUtil = new FileUtil(this);
49 // do not move to parent class:
53 void MediaImagePathMainDialog::initProgressDialog()
55 progressDialog = new QProgressDialog(this);
56 progressDialog->setWindowTitle(tr("Scanning files"));
57 progressDialog->setCancelButtonText(tr("Abort"));
58 progressDialog->setWindowModality(Qt::WindowModal);
61 void MediaImagePathMainDialog::connectSignals()
63 DbObjectDialog::connectSignals();
64 connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath()));
67 void MediaImagePathMainDialog::initEditDialog()
69 nameDialog = new MediaImagePathDialog(this, dynamic_cast<FilePathObject*>(dbObject));
70 connectNameDialogSignals();
73 void MediaImagePathMainDialog::beginScanFilePath()
75 QModelIndex index = objectList->currentIndex();
76 if (!index.isValid()) return;
77 if (QMessageBox::question(this,
79 tr("Do you want to continue? "
80 "If you have tons of huge files this may take even hours! "
81 "If you are low on battery power, consider carefully!"),
82 QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No) {
85 FilePathObject *fpo = 0;
88 EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index); // throws EmuFrontException
90 fpo = dynamic_cast<FilePathObject*>(ob);
93 l << "*.zip"; // TODO set filters in a global constant class
95 dbMediaImageContainer->removeFromFilePath(fpo->getId());
97 progressDialog->show();
100 int count = fileUtil->scanFilePath(fpo, l, dbMediaImageContainer, progressDialog);
101 progressDialog->hide();
104 msgBox.setText(tr("Scanned %1 files to database.").arg(count));
106 DbFilePath *dbfp = dynamic_cast<DbFilePath*>(dbManager);
107 if (!(dbfp && dbfp->setScanned(fpo)))
108 throw EmuFrontException(tr("Failed updating the last scanned time stamp for selected file path!"));
111 catch (EmuFrontException s)
113 errorMessage->showMessage( s.what() );
120 EmuFrontObject* MediaImagePathMainDialog::createObject()
122 return new FilePathObject(FilePathObject::FilePathType_MediaImageDir);
125 MediaImagePathMainDialog::~MediaImagePathMainDialog()
127 deleteCurrentObject();
130 void MediaImagePathMainDialog::deleteCurrentObject()
133 FilePathObject* fpo = dynamic_cast<FilePathObject*>(dbObject);
135 else qDebug() << "Failed deleteing FilePathObject";
140 void MediaImagePathMainDialog::cleanUp()
142 deleteCurrentObject();
144 MediaImagePathDialog *pnd =
145 dynamic_cast<MediaImagePathDialog*>(nameDialog);
147 else qDebug() << "Failed to delete MediaImagePathDialog";