X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fdialogs%2Fmediaimagepathmaindialog.cpp;h=be1c07dae624267627866929cb1edb570950a3ad;hb=419085d8d0c4317953729d213534a498a5a45f82;hp=99d173211b9ad982772495338dc508394a19d02c;hpb=9cdcdf4c426877fad960de49ad47b4d5df5ad301;p=emufront diff --git a/src/dialogs/mediaimagepathmaindialog.cpp b/src/dialogs/mediaimagepathmaindialog.cpp index 99d1732..be1c07d 100644 --- a/src/dialogs/mediaimagepathmaindialog.cpp +++ b/src/dialogs/mediaimagepathmaindialog.cpp @@ -5,72 +5,165 @@ // // // EmuFront is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// it under the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation and appearing in the file gpl.txt included in the +// packaging of this file. // -// Foobar is distributed in the hope that it will be useful, +// EmuFront is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with EmuFront. If not, see . #include +#include "../dataobjects/filepathobject.h" +#include "../dataobjects/emufrontfileobject.h" +#include "../db/dbfilepath.h" +#include "../utils/fileutil.h" #include "mediaimagepathmaindialog.h" #include "mediaimagepathdialog.h" -#include "../dataobjects/filepathobject.h" -#include "../db/dbmediaimagepath.h" - MediaImagePathMainDialog::MediaImagePathMainDialog(QWidget *parent) : DbObjectDialog(parent) { setWindowTitle(tr("Set media image paths")); - nameDialog = new MediaImagePathDialog(this, dynamic_cast(dbObject)); - dbManager = new DbMediaImagePath(this); + dbManager = new DbFilePath(this); + dbMediaImageContainer = new DbMediaImageContainer(this); initDataTable(); + + scanButton = new QPushButton(tr("&Scan")); + buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole); + + initEditDialog(); + hiddenColumns << DbFilePath::FilePath_Id; + hiddenColumns << DbFilePath::FilePath_SetupId; + hideColumns(); + + fileUtil = new FileUtil(this); + + initProgressDialog(); // do not move to parent class: connectSignals(); } -MediaImagePathMainDialog::~MediaImagePathMainDialog() +void MediaImagePathMainDialog::initProgressDialog() { - deleteCurrentObject(); + progressDialog = new QProgressDialog(this); + progressDialog->setWindowTitle(tr("Scanning files")); + progressDialog->setCancelButtonText(tr("Abort")); + progressDialog->setWindowModality(Qt::WindowModal); } -int MediaImagePathMainDialog::deleteObject() +void MediaImagePathMainDialog::connectSignals() { - return 0; + DbObjectDialog::connectSignals(); + connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath())); + connect(fileUtil, SIGNAL(dbUpdateFinished()), this, SLOT(hideDbUpdating())); + connect(fileUtil, SIGNAL(dbUpdateInProgress()), this, SLOT(showDbUpdating())); } -void MediaImagePathMainDialog::addObject() +void MediaImagePathMainDialog::showDbUpdating() { - deleteCurrentObject(); - dbObject = new FilePathObject; - nameDialog->setDataObject(dbObject); - activateNameDialog(); + qDebug() << "DB updating"; + // TODO: the following is not currently working + progressDialog->setWindowTitle(tr("Updating DB... please wait!")); + progressDialog->setEnabled(false); } -void MediaImagePathMainDialog::deleteCurrentObject() +void MediaImagePathMainDialog::hideDbUpdating() +{ + qDebug() << "DB update finished"; + // TODO: the following is not currently working + progressDialog->setEnabled(true); + progressDialog->setWindowTitle(tr("Scanning files")); +} + + +void MediaImagePathMainDialog::initEditDialog() { - delete dynamic_cast(dbObject); + nameDialog = new MediaImagePathDialog(this, dynamic_cast(dbObject)); + connectNameDialogSignals(); } -void MediaImagePathMainDialog::updateDb(const EmuFrontObject *) const +void MediaImagePathMainDialog::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; + } + FilePathObject *fpo = 0; + try + { + EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index); // throws EmuFrontException + if (!ob) return; + fpo = dynamic_cast(ob); + if (!fpo) return; + QStringList l; + l << "*.zip"; // TODO set filters in a global constant class + + dbMediaImageContainer->removeFromFilePath(fpo->getId()); + progressDialog->show(); + progressDialog->setEnabled(true); + + 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(); + DbFilePath *dbfp = dynamic_cast(dbManager); + if (!(dbfp && dbfp->setScanned(fpo))) + throw EmuFrontException(tr("Failed updating the last scanned time stamp for selected file path!")); + else updateList(); + } + catch (EmuFrontException s) + { + errorMessage->showMessage( s.what() ); + } + setUIEnabled(true); + delete fpo; + fpo = 0; } -void MediaImagePathMainDialog::insertDb(const EmuFrontObject *) const +EmuFrontObject* MediaImagePathMainDialog::createObject() { + return new FilePathObject(FilePathObject::FilePathType_MediaImageDir); +} +MediaImagePathMainDialog::~MediaImagePathMainDialog() +{ + deleteCurrentObject(); } -bool MediaImagePathMainDialog::deleteItem() +void MediaImagePathMainDialog::deleteCurrentObject() { - return false; + if (dbObject) { + FilePathObject* fpo = dynamic_cast(dbObject); + if (fpo) delete fpo; + else qDebug() << "Failed deleteing FilePathObject"; + dbObject = 0; + } } +void MediaImagePathMainDialog::cleanUp() +{ + deleteCurrentObject(); + if (nameDialog) { + MediaImagePathDialog *pnd = + dynamic_cast(nameDialog); + if (pnd) delete pnd; + else qDebug() << "Failed to delete MediaImagePathDialog"; + nameDialog = 0; + } +}