mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Hide application/x-trash files following showHidenFiles
BUG: 3212
This commit is contained in:
parent
9c614949d6
commit
7f3967cf38
|
@ -105,6 +105,8 @@ KFileItemModel::KFileItemModel(QObject *parent)
|
||||||
connect(m_resortAllItemsTimer, &QTimer::timeout, this, &KFileItemModel::resortAllItems);
|
connect(m_resortAllItemsTimer, &QTimer::timeout, this, &KFileItemModel::resortAllItems);
|
||||||
|
|
||||||
connect(GeneralSettings::self(), &GeneralSettings::sortingChoiceChanged, this, &KFileItemModel::slotSortingChoiceChanged);
|
connect(GeneralSettings::self(), &GeneralSettings::sortingChoiceChanged, this, &KFileItemModel::slotSortingChoiceChanged);
|
||||||
|
|
||||||
|
setShowTrashMime(m_dirLister->showHiddenFiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
KFileItemModel::~KFileItemModel()
|
KFileItemModel::~KFileItemModel()
|
||||||
|
@ -238,6 +240,27 @@ bool KFileItemModel::sortHiddenLast() const
|
||||||
return m_sortHiddenLast;
|
return m_sortHiddenLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KFileItemModel::setShowTrashMime(bool show)
|
||||||
|
{
|
||||||
|
const auto trashMime = QStringLiteral("application/x-trash");
|
||||||
|
QStringList excludeFilter = m_filter.excludeMimeTypes();
|
||||||
|
bool wasShown = !excludeFilter.contains(trashMime);
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
if (!wasShown) {
|
||||||
|
excludeFilter.removeAll(trashMime);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (wasShown) {
|
||||||
|
excludeFilter.append(trashMime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasShown != show) {
|
||||||
|
setExcludeMimeTypeFilter(excludeFilter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KFileItemModel::setShowHiddenFiles(bool show)
|
void KFileItemModel::setShowHiddenFiles(bool show)
|
||||||
{
|
{
|
||||||
#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
|
#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
|
||||||
|
@ -245,6 +268,7 @@ void KFileItemModel::setShowHiddenFiles(bool show)
|
||||||
#else
|
#else
|
||||||
m_dirLister->setShowHiddenFiles(show);
|
m_dirLister->setShowHiddenFiles(show);
|
||||||
#endif
|
#endif
|
||||||
|
setShowTrashMime(show);
|
||||||
m_dirLister->emitChanges();
|
m_dirLister->emitChanges();
|
||||||
if (show) {
|
if (show) {
|
||||||
dispatchPendingItemsToInsert();
|
dispatchPendingItemsToInsert();
|
||||||
|
@ -740,6 +764,20 @@ QStringList KFileItemModel::mimeTypeFilters() const
|
||||||
return m_filter.mimeTypes();
|
return m_filter.mimeTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KFileItemModel::setExcludeMimeTypeFilter(const QStringList &filters)
|
||||||
|
{
|
||||||
|
if (m_filter.excludeMimeTypes() != filters) {
|
||||||
|
dispatchPendingItemsToInsert();
|
||||||
|
m_filter.setExcludeMimeTypes(filters);
|
||||||
|
applyFilters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList KFileItemModel::excludeMimeTypeFilter() const
|
||||||
|
{
|
||||||
|
return m_filter.excludeMimeTypes();
|
||||||
|
}
|
||||||
|
|
||||||
void KFileItemModel::applyFilters()
|
void KFileItemModel::applyFilters()
|
||||||
{
|
{
|
||||||
// ===STEP 1===
|
// ===STEP 1===
|
||||||
|
@ -1823,7 +1861,7 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem &item,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_requestRole[IsHiddenRole]) {
|
if (m_requestRole[IsHiddenRole]) {
|
||||||
data.insert(sharedValue("isHidden"), item.isHidden());
|
data.insert(sharedValue("isHidden"), item.isHidden() || item.mimetype() == QStringLiteral("application/x-trash"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_requestRole[NameRole]) {
|
if (m_requestRole[NameRole]) {
|
||||||
|
|
|
@ -182,6 +182,9 @@ public:
|
||||||
void setMimeTypeFilters(const QStringList &filters);
|
void setMimeTypeFilters(const QStringList &filters);
|
||||||
QStringList mimeTypeFilters() const;
|
QStringList mimeTypeFilters() const;
|
||||||
|
|
||||||
|
void setExcludeMimeTypeFilter(const QStringList &filters);
|
||||||
|
QStringList excludeMimeTypeFilter() const;
|
||||||
|
|
||||||
struct RoleInfo {
|
struct RoleInfo {
|
||||||
QByteArray role;
|
QByteArray role;
|
||||||
QString translation;
|
QString translation;
|
||||||
|
@ -199,6 +202,9 @@ public:
|
||||||
*/
|
*/
|
||||||
static QList<RoleInfo> rolesInformation();
|
static QList<RoleInfo> rolesInformation();
|
||||||
|
|
||||||
|
/** set to true to hide application/x-trash files */
|
||||||
|
void setShowTrashMime(bool show);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* Is emitted if the loading of a directory has been started. It is
|
* Is emitted if the loading of a directory has been started. It is
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <KFileItem>
|
#include <KFileItem>
|
||||||
|
|
||||||
KFileItemModelFilter::KFileItemModelFilter()
|
KFileItemModelFilter::KFileItemModelFilter()
|
||||||
|
@ -56,15 +58,25 @@ QStringList KFileItemModelFilter::mimeTypes() const
|
||||||
return m_mimeTypes;
|
return m_mimeTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KFileItemModelFilter::setExcludeMimeTypes(const QStringList &types)
|
||||||
|
{
|
||||||
|
m_excludeMimeTypes = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList KFileItemModelFilter::excludeMimeTypes() const
|
||||||
|
{
|
||||||
|
return m_excludeMimeTypes;
|
||||||
|
}
|
||||||
|
|
||||||
bool KFileItemModelFilter::hasSetFilters() const
|
bool KFileItemModelFilter::hasSetFilters() const
|
||||||
{
|
{
|
||||||
return (!m_pattern.isEmpty() || !m_mimeTypes.isEmpty());
|
return (!m_pattern.isEmpty() || !m_mimeTypes.isEmpty() || !m_excludeMimeTypes.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KFileItemModelFilter::matches(const KFileItem &item) const
|
bool KFileItemModelFilter::matches(const KFileItem &item) const
|
||||||
{
|
{
|
||||||
const bool hasPatternFilter = !m_pattern.isEmpty();
|
const bool hasPatternFilter = !m_pattern.isEmpty();
|
||||||
const bool hasMimeTypesFilter = !m_mimeTypes.isEmpty();
|
const bool hasMimeTypesFilter = !m_mimeTypes.isEmpty() || !m_excludeMimeTypes.isEmpty();
|
||||||
|
|
||||||
// If no filter is set, return true.
|
// If no filter is set, return true.
|
||||||
if (!hasPatternFilter && !hasMimeTypesFilter) {
|
if (!hasPatternFilter && !hasMimeTypesFilter) {
|
||||||
|
@ -95,10 +107,18 @@ bool KFileItemModelFilter::matchesPattern(const KFileItem &item) const
|
||||||
|
|
||||||
bool KFileItemModelFilter::matchesType(const KFileItem &item) const
|
bool KFileItemModelFilter::matchesType(const KFileItem &item) const
|
||||||
{
|
{
|
||||||
for (const QString &mimeType : qAsConst(m_mimeTypes)) {
|
bool excluded = std::any_of(m_excludeMimeTypes.constBegin(), m_excludeMimeTypes.constEnd(), [item](const QString &excludeMimetype) {
|
||||||
if (item.mimetype() == mimeType) {
|
return item.mimetype() == excludeMimetype;
|
||||||
return true;
|
});
|
||||||
}
|
if (excluded) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool included = std::any_of(m_mimeTypes.constBegin(), m_mimeTypes.constEnd(), [item](const QString &mimeType) {
|
||||||
|
return item.mimetype() == mimeType;
|
||||||
|
});
|
||||||
|
if (included) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_mimeTypes.isEmpty();
|
return m_mimeTypes.isEmpty();
|
||||||
|
|
|
@ -44,6 +44,13 @@ public:
|
||||||
void setMimeTypes(const QStringList &types);
|
void setMimeTypes(const QStringList &types);
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of mimetypes that are used for comparison and excluded with the
|
||||||
|
* item in KFileItemModelFilter::matchesMimeType.
|
||||||
|
*/
|
||||||
|
void setExcludeMimeTypes(const QStringList &types);
|
||||||
|
QStringList excludeMimeTypes() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return True if either the pattern or mimetype filters has been set.
|
* @return True if either the pattern or mimetype filters has been set.
|
||||||
*/
|
*/
|
||||||
|
@ -73,5 +80,6 @@ private:
|
||||||
// faster comparison in matches().
|
// faster comparison in matches().
|
||||||
QString m_pattern; // Property set by setPattern().
|
QString m_pattern; // Property set by setPattern().
|
||||||
QStringList m_mimeTypes; // Property set by setMimeTypes()
|
QStringList m_mimeTypes; // Property set by setMimeTypes()
|
||||||
|
QStringList m_excludeMimeTypes; // Property set by setExcludeMimeTypes()
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue