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/>.
22 #include "filepatheditview.h"
23 #include "filepathmodel.h"
25 #include "setupmodel.h"
26 #include "comboboxdelegate.h"
27 #include "filesystembrowsedelegate.h"
30 FilePathEditView::FilePathEditView(SetupModel *supModel, QWidget *parent) :
31 EmuFrontEditView(parent)
33 setWindowTitle(tr("Set media image paths"));
34 scanButton = new QPushButton(tr("&Scan"));
35 buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole);
36 fileUtil = new FileUtil(this);
39 model = new FilePathModel(this);
40 objectList->setModel(model);
41 ComboBoxDelegate *setupDelegate = new ComboBoxDelegate(
44 SetupModel::Setup_Name,
47 objectList->setItemDelegateForColumn(FilePathModel::FilePath_SetupId, setupDelegate);
48 FileSystemBrowseDelegate *fsBrowseDelegate = new FileSystemBrowseDelegate(this);
49 objectList->setItemDelegateForColumn(FilePathModel::FilePath_Name, fsBrowseDelegate);
53 void FilePathEditView::initProgressDialog()
55 progressDialog = new QProgressDialog(this);
56 progressDialog->setWindowTitle(tr("Scanning files"));
57 progressDialog->setCancelButtonText(tr("Abort"));
58 progressDialog->setWindowModality(Qt::WindowModal);
61 void FilePathEditView::connectSignals()
63 EmuFrontEditView::connectSignals();
64 connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath()));
67 void FilePathEditView::beginScanFilePath()
69 QModelIndex index = objectList->currentIndex();
70 if (!index.isValid()) return;
72 if (QMessageBox::question(this,
74 tr("Do you want to continue? "
75 "Re-scanning file path removes old entries for selected path. "
76 "If you have tons of huge files this may take even hours! "
77 "If you are low on battery power, consider carefully!"),
78 QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No)
81 FilePathModel *fpModel = qobject_cast<FilePathModel*>(model);
82 FilePathObject *fpo = fpModel->getFilePathObject(index);
84 errorMessage->showMessage(tr("Failed creating a file path object of selected file path."));
90 l << "*.zip"; // TODO set filters in a global constant class
92 progressDialog->show();
93 //setUIEnabled(false);
94 int count = fileUtil->scanFilePath(fpo, l, progressDialog);
95 progressDialog->hide();
98 msgBox.setText(tr("Scanned %1 files to database.").arg(count)); msgBox.exec();
99 fpModel->setScanned(fpo->getId());
102 catch (EmuFrontException s)
104 errorMessage->showMessage( s.what() );
106 //setUIEnabled(true);