Added file name filter to "Add folder (recursively)" function.

This commit is contained in:
LoRd_MuldeR 2015-05-14 13:55:09 +02:00
parent 7a13711440
commit cda221f991
2 changed files with 47 additions and 10 deletions

View File

@ -863,7 +863,7 @@ void MainWindow::addFiles(const QStringList &files)
/* /*
* Add folder to source list * Add folder to source list
*/ */
void MainWindow::addFolder(const QString &path, bool recursive, bool delayed) void MainWindow::addFolder(const QString &path, bool recursive, bool delayed, QString filter)
{ {
QFileInfoList folderInfoList; QFileInfoList folderInfoList;
folderInfoList << QFileInfo(path); folderInfoList << QFileInfo(path);
@ -887,9 +887,12 @@ void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
QDir currentDir(folderInfoList.takeFirst().canonicalFilePath()); QDir currentDir(folderInfoList.takeFirst().canonicalFilePath());
QFileInfoList fileInfoList = currentDir.entryInfoList(QDir::Files | QDir::NoSymLinks); QFileInfoList fileInfoList = currentDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
while(!fileInfoList.isEmpty()) for(QFileInfoList::ConstIterator iter = fileInfoList.constBegin(); iter != fileInfoList.constEnd(); iter++)
{ {
fileList << fileInfoList.takeFirst().canonicalFilePath(); if(filter.isEmpty() || (iter->suffix().compare(filter, Qt::CaseInsensitive) == 0))
{
fileList << iter->canonicalFilePath();
}
} }
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@ -2365,11 +2368,45 @@ void MainWindow::openFolderActionActivated(void)
} }
} }
if(!selectedFolder.isEmpty()) if(selectedFolder.isEmpty())
{ {
m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath()); return;
addFolder(selectedFolder, action->data().toBool());
} }
QRegExp regExp("\\((.+)\\)", Qt::CaseInsensitive);
const QStringList supportedTypes = DecoderRegistry::getSupportedTypes();
QStringList filterItems("*.*");
for(QStringList::ConstIterator iter = supportedTypes.constBegin(); iter != supportedTypes.constEnd(); iter++)
{
if(regExp.lastIndexIn(*iter) >= 0)
{
const QStringList extensions = regExp.cap(1).split(' ', QString::SkipEmptyParts);
for(QStringList::ConstIterator iter2 = extensions.constBegin(); iter2 != extensions.constEnd(); iter2++)
{
if(!filterItems.contains((*iter2), Qt::CaseInsensitive)) filterItems << (*iter2);
}
}
}
bool okay;
QString filterStr = QInputDialog::getItem(this, tr("Filter Files"), tr("Select filename filter:"), filterItems, 0, false, &okay).trimmed();
if(!okay)
{
return;
}
QRegExp regExp2("\\*\\.([A-Za-z0-9]+)", Qt::CaseInsensitive);
if(regExp2.lastIndexIn(filterStr) >= 0)
{
filterStr = regExp2.cap(1).trimmed();
}
else
{
filterStr.clear();
}
m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
addFolder(selectedFolder, action->data().toBool(), false, filterStr);
); );
} }
} }

View File

@ -206,7 +206,7 @@ private:
Ui::MainWindow *ui; //for Qt UIC Ui::MainWindow *ui; //for Qt UIC
void addFiles(const QStringList &files); void addFiles(const QStringList &files);
void addFolder(const QString &path, bool recursive = false, bool delayed = false); void addFolder(const QString &path, bool recursive = false, bool delayed = false, QString filter = QString());
bool checkForUpdates(void); bool checkForUpdates(void);
void initializeTranslation(void); void initializeTranslation(void);
void refreshFavorites(void); void refreshFavorites(void);