X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fviews%2Ffilepatheditview.cpp;h=24504ed39e100a0b51b30165b2baaee59f5a4bdc;hb=6bd5521ba6eedac17d194df82eda4e36de2ccb20;hp=b03adea666929a4c7387965e055fcd651464efad;hpb=e19eaf49bd199c59cfd9d9d5ad2c12f6ebd4addd;p=emufront diff --git a/src/views/filepatheditview.cpp b/src/views/filepatheditview.cpp index b03adea..24504ed 100644 --- a/src/views/filepatheditview.cpp +++ b/src/views/filepatheditview.cpp @@ -20,14 +20,23 @@ */ #include "filepatheditview.h" #include "filepathmodel.h" +#include "fileutil.h" #include "setupmodel.h" #include "comboboxdelegate.h" #include "filesystembrowsedelegate.h" +#include "dbmediaimagecontainer.h" #include FilePathEditView::FilePathEditView(QWidget *parent) : EmuFrontEditView(parent) { + scanButton = new QPushButton(tr("&Scan")); + buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole); + fileUtil = new FileUtil(this); + initProgressDialog(); + + dbMediaImageContainer = new DbMediaImageContainer(this); + model = new FilePathModel(this); objectList->setModel(model); SetupModel *stupMdl = new SetupModel(this); @@ -42,3 +51,65 @@ FilePathEditView::FilePathEditView(QWidget *parent) : objectList->setItemDelegateForColumn(FilePathModel::FilePath_Name, fsBrowseDelegate); postInit(); } + +void FilePathEditView::initProgressDialog() +{ + progressDialog = new QProgressDialog(this); + progressDialog->setWindowTitle(tr("Scanning files")); + progressDialog->setCancelButtonText(tr("Abort")); + progressDialog->setWindowModality(Qt::WindowModal); +} + +void FilePathEditView::connectSignals() +{ + EmuFrontEditView::connectSignals(); + connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath())); +} + +void FilePathEditView::beginScanFilePath() +{ + QModelIndex index = objectList->currentIndex(); + if (!index.isValid()) return; + + if (QMessageBox::question(this, + tr("Confirm"), + tr("Do you want to continue? " + "If you have tons of huge files this may take even hours! " + "If you are low on battery power, consider carefully!"), + QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No) + { return; } + + FilePathModel *fpModel = qobject_cast(model); + FilePathObject *fpo = fpModel->getFilePathObject(index); + if (!fpo) { + errorMessage->showMessage(tr("Failed creating a file path object of selected file path.")); + return; + } + try + { + QStringList l; + l << "*.zip"; // TODO set filters in a global constant class + + // Remove old instances scanned from this file path + dbMediaImageContainer->removeFromFilePath(fpo->getId()); + + progressDialog->show(); + + //setUIEnabled(false); + int count = fileUtil->scanFilePath(fpo, l, dbMediaImageContainer, progressDialog); + progressDialog->hide(); + + QMessageBox msgBox; + msgBox.setText(tr("Scanned %1 files to database.").arg(count)); msgBox.exec(); + fpModel->setScanned(fpo->getId()); + //updateList(); + } + catch (EmuFrontException s) + { + errorMessage->showMessage( s.what() ); + } + //setUIEnabled(true); + delete fpo; + fpo = 0; +} +