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/>.
21 #include "filepatheditview.h"
22 #include "filepathmodel.h"
24 #include "setupmodel.h"
25 #include "comboboxdelegate.h"
26 #include "filesystembrowsedelegate.h"
27 #include "dbmediaimagecontainer.h"
30 FilePathEditView::FilePathEditView(QWidget *parent) :
31 EmuFrontEditView(parent)
33 scanButton = new QPushButton(tr("&Scan"));
34 buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole);
35 fileUtil = new FileUtil(this);
38 dbMediaImageContainer = new DbMediaImageContainer(this);
40 model = new FilePathModel(this);
41 objectList->setModel(model);
42 SetupModel *stupMdl = new SetupModel(this);
43 ComboBoxDelegate *setupDelegate = new ComboBoxDelegate(
46 SetupModel::Setup_Name,
49 objectList->setItemDelegateForColumn(FilePathModel::FilePath_SetupId, setupDelegate);
50 FileSystemBrowseDelegate *fsBrowseDelegate = new FileSystemBrowseDelegate(this);
51 objectList->setItemDelegateForColumn(FilePathModel::FilePath_Name, fsBrowseDelegate);
55 void FilePathEditView::initProgressDialog()
57 progressDialog = new QProgressDialog(this);
58 progressDialog->setWindowTitle(tr("Scanning files"));
59 progressDialog->setCancelButtonText(tr("Abort"));
60 progressDialog->setWindowModality(Qt::WindowModal);
63 void FilePathEditView::connectSignals()
65 EmuFrontEditView::connectSignals();
66 connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath()));
69 void FilePathEditView::beginScanFilePath()
71 QModelIndex index = objectList->currentIndex();
72 if (!index.isValid()) return;
74 if (QMessageBox::question(this,
76 tr("Do you want to continue? "
77 "If you have tons of huge files this may take even hours! "
78 "If you are low on battery power, consider carefully!"),
79 QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No)
82 FilePathModel *fpModel = qobject_cast<FilePathModel*>(model);
83 FilePathObject *fpo = fpModel->getFilePathObject(index);
85 errorMessage->showMessage(tr("Failed creating a file path object of selected file path."));
91 l << "*.zip"; // TODO set filters in a global constant class
93 // Remove old instances scanned from this file path
94 dbMediaImageContainer->removeFromFilePath(fpo->getId());
96 progressDialog->show();
98 //setUIEnabled(false);
99 int count = fileUtil->scanFilePath(fpo, l, dbMediaImageContainer, progressDialog);
100 progressDialog->hide();
103 msgBox.setText(tr("Scanned %1 files to database.").arg(count)); msgBox.exec();
104 fpModel->setScanned(fpo->getId());
107 catch (EmuFrontException s)
109 errorMessage->showMessage( s.what() );
111 //setUIEnabled(true);