Commit a8bf1a6d authored by Karel Slaný's avatar Karel Slaný

Implemented QDir::isEmpty() for Qt < Qt-5.9.

parent 8d3c76de
......@@ -22,6 +22,9 @@
*/
#include <QDir>
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
#include <QDirIterator>
#endif /* < Qt-5.9 */
#include <QFileDialog>
#include <QMessageBox>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
......@@ -333,6 +336,26 @@ QString normalisedDir(const QString &nativeDir, QWidget *parent = Q_NULLPTR)
return normDir;
}
/*!
* @brief Implements QDir::isEmpty() for Qt < Qt-5.9.
*
* @param[in] dir Directory.
* @param[in] filters Filters.
* @return Count == 0 with default filters.
*/
static inline
bool isEmptyDir(const QDir &dir,
QDir::Filters filters = QDir::Filters(QDir::AllEntries | QDir::NoDotAndDotDot))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
return dir.isEmpty(filters);
#else /* < Qt-5.9 */
/* Equivalent to \c{count() == 0} with filters. */
const QDirIterator it(dir.path(), dir.nameFilters(), filters);
return !it.hasNext();
#endif /* >= Qt-5.9 */
}
void DlgBackup::backupSelected(void)
{
const QString normDir(normalisedDir(m_ui->directoryLine->text(), this));
......@@ -341,7 +364,7 @@ void DlgBackup::backupSelected(void)
return;
}
if (!QDir(normDir).isEmpty()) {
if (!isEmptyDir(QDir(normDir))) {
QMessageBox::StandardButton reply = QMessageBox::question(this,
tr("Directory not empty"),
tr("The directory '%1' is not empty. Some of the existing data may be overwritten. Do you want to proceed?")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment