diff options
author | Arno <arno@disconnect.de> | 2017-12-28 13:24:30 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-12-28 13:24:30 +0100 |
commit | 0e1e44409e8cc225210f3e22f6deb18d62ee8298 (patch) | |
tree | 7007f454d54e8691d009ce80b3c7c958753eb8fd | |
parent | c6c4900e4cf9aa69b2de3c9c5af701800c0c25de (diff) | |
download | SheMov-0e1e44409e8cc225210f3e22f6deb18d62ee8298.tar.gz SheMov-0e1e44409e8cc225210f3e22f6deb18d62ee8298.tar.bz2 SheMov-0e1e44409e8cc225210f3e22f6deb18d62ee8298.zip |
Guess if the file was reencoded
It's really simple: If we have a file with the same name, but another
extension, add it as FT_ORIGIN to the list.
-rw-r--r-- | newmoviewizard.cpp | 30 | ||||
-rw-r--r-- | newmoviewizard.h | 1 | ||||
-rw-r--r-- | shemov.cpp | 1 |
3 files changed, 32 insertions, 0 deletions
diff --git a/newmoviewizard.cpp b/newmoviewizard.cpp index 427f1ad..8a4e961 100644 --- a/newmoviewizard.cpp +++ b/newmoviewizard.cpp @@ -25,6 +25,8 @@ #include <QHeaderView> #include <QSortFilterProxyModel> #include <QJsonObject> +#include <QRegularExpression> +#include <QDirIterator> #include "newmoviewizard.h" #include "smtreeitem.h" @@ -511,6 +513,34 @@ void MovieInfoPage::addOld(){ oldFileDlg->deleteLater(); } +void MovieInfoPage::guessOld(const QString &fullPath){ + QFileInfo fi(fullPath); + QString baseName = fi.baseName(); + QRegularExpression fnRe(baseName); + QModelIndex parent; + QDirIterator it(fi.dir()); + QList<QVariant> itemData; + while(it.hasNext()){ + QFileInfo curFi = it.next(); + QString curBaseName = curFi.baseName(); + for(int i = 0; i < mFileModel->rowCount(mFileModel->rootIndex()); ++i){ + QModelIndex curIdx = mFileModel->index(i, WizardTreeModel::FileName, mFileModel->rootIndex()); + if(curIdx.isValid()){ + if(fnRe.match(curBaseName).hasMatch()){ + if(curFi.absoluteFilePath() != fi.absoluteFilePath()){ + parent = curIdx; + itemData << curFi.fileName() << curFi.size() << FT_ORIGIN << QVariant() << curFi.absoluteFilePath(); + mOrigins << curFi.absoluteFilePath(); + mFileModel->appendRow(itemData, parent); + break; + } + } + } + } + } + mFileView->expandAll(); +} + void MovieInfoPage::addFiles(){ QSettings s; QString startDir = s.value("paths/addfilespath", QDir::homePath()).toString(); diff --git a/newmoviewizard.h b/newmoviewizard.h index d02cd62..d2deda3 100644 --- a/newmoviewizard.h +++ b/newmoviewizard.h @@ -61,6 +61,7 @@ class MovieInfoPage : public QWizardPage { public slots: void initCompleters(); + void guessOld(const QString &fullPath); private slots: void extractTitle(); @@ -300,6 +300,7 @@ void SheMov::newMovieWizardWithFiles(){ mNewMovieWizard->infoPage()->setCurrentDir(mFSWidget->currentDir()); foreach(QModelIndex sel, selected){ mNewMovieWizard->infoPage()->addFile(sel.data(SmDirModel::FullPathRole).toString()); + mNewMovieWizard->infoPage()->guessOld(sel.data(SmDirModel::FullPathRole).toString()); } QSettings s; bool autoAddCovers = s.value("ui/autoaddcovers", false).toBool(); |