Permalink
Browse files

Add mythgallery filtering/sorting support

Refs #9880

Signed-off-by: Gavin Hurlbut <ghurlbut@mythtv.org>
  • Loading branch information...
Trisooma authored and Beirdo committed Jul 26, 2011
1 parent e41e314 commit e12b31414145c6265bf62dfb59738f04b80ac8ac
@@ -0,0 +1,134 @@
+
+#include <set>
+#include <mythtv/libmythui/mythuitextedit.h>
+
+#include "galleryfilter.h"
+
+#include <mythtv/mythcontext.h>
+
+#include <mythtv/libmythui/mythuibuttonlist.h>
+#include <mythtv/libmythui/mythuibutton.h>
+#include <mythtv/libmythui/mythuitext.h>
+#include <mythtv/libmythui/mythuitextedit.h>
+
+#include "config.h"
+#include "galleryfilter.h"
+#include "galleryutil.h"
+
+#define LOC QString("GalleryFilter:")
+#define LOC_ERR QString("GalleryFilter, Error:")
+
+GalleryFilter::GalleryFilter(bool loaddefaultsettings) :
+ m_dirFilter(""), m_typeFilter(kTypeFilterAll),
+ m_sort(kSortOrderUnsorted),
+ m_changed_state(0)
+{
+ // do nothing yet
+ if (loaddefaultsettings)
+ {
+ m_dirFilter = gCoreContext->GetSetting("GalleryFilterDirectory", "");
+ m_typeFilter = gCoreContext->GetNumSetting("GalleryFilterType", kTypeFilterAll);
+ m_sort = gCoreContext->GetNumSetting("GallerySortOrder", kSortOrderUnsorted);
+ }
+}
+
+GalleryFilter::GalleryFilter(const GalleryFilter &gfs) :
+ m_changed_state(0)
+{
+ *this = gfs;
+}
+
+GalleryFilter &
+GalleryFilter::operator=(const GalleryFilter &gfs)
+{
+ if (m_dirFilter != gfs.m_dirFilter)
+ {
+ m_dirFilter = gfs.m_dirFilter;
+ m_changed_state = true;
+ }
+
+ if (m_typeFilter != gfs.m_typeFilter)
+ {
+ m_typeFilter = gfs.m_typeFilter;
+ m_changed_state = true;
+ }
+
+ if (m_sort != gfs.m_sort)
+ {
+ m_sort = gfs.m_sort;
+ m_changed_state = true;
+ }
+
+ return *this;
+}
+
+void GalleryFilter::saveAsDefault()
+{
+ gCoreContext->SaveSetting("GalleryFilterDirectory", m_dirFilter);
+ gCoreContext->SaveSetting("GalleryFilterType", m_typeFilter);
+ gCoreContext->SaveSetting("GallerySortOrder", m_sort);
+}
+
+bool GalleryFilter::TestFilter(const QString& dir, const GalleryFilter& flt,
+ int *dirCount, int *imageCount, int *movieCount)
+{
+ QStringList splitFD;
+ const QFileInfo *fi;
+
+ QDir d(dir);
+ QString currDir = d.absolutePath();
+ QFileInfoList list = d.entryInfoList(GalleryUtil::GetMediaFilter(),
+ QDir::Files | QDir::AllDirs,
+ (QDir::SortFlag)flt.getSort());
+
+ if (list.isEmpty())
+ return false;
+
+ if (!flt.getDirFilter().isEmpty())
+ {
+ splitFD = flt.getDirFilter().split(":");
+ }
+
+
+ for (QFileInfoList::const_iterator it = list.begin(); it != list.end(); it++)
+ {
+ fi = &(*it);
+ if (fi->fileName() == "."
+ || fi->fileName() == "..")
+ {
+ continue;
+ }
+
+ // remove these already-resized pictures.
+ if ((fi->fileName().indexOf(".thumb.") > 0) ||
+ (fi->fileName().indexOf(".sized.") > 0) ||
+ (fi->fileName().indexOf(".highlight.") > 0))
+ {
+ continue;
+ }
+
+ // skip filtered directory
+ if (fi->isDir())
+ {
+ if (!splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
+ {
+ continue;
+ }
+ // add directory
+ (*dirCount)++;
+ GalleryFilter::TestFilter(QDir::cleanPath(fi->absoluteFilePath()), flt,
+ dirCount, imageCount, movieCount);
+ }
+ else
+ {
+ if (GalleryUtil::IsImage(fi->absoluteFilePath())
+ && flt.getTypeFilter() != kTypeFilterMoviesOnly)
+ (*imageCount)++;
+ else if (GalleryUtil::IsMovie(fi->absoluteFilePath())
+ && flt.getTypeFilter() != kTypeFilterImagesOnly)
+ (*movieCount)++;
+ }
+ }
+
+ return true;
+}
@@ -0,0 +1,90 @@
+#ifndef GALLERYFILTER_H
+#define GALLERYFILTER_H
+
+// qt
+#include <QDir>
+
+#include <mythtv/libmythui/mythscreentype.h>
+#include <mythtv/libmythdb/mythverbose.h>
+
+enum SortOrder {
+ kSortOrderUnsorted = QDir::Unsorted,
+ kSortOrderNameAsc = QDir::Name + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderNameDesc = QDir::Name + QDir::Reversed + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderModTimeAsc = QDir::Time + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderModTimeDesc = QDir::Time + QDir::Reversed + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderExtAsc = QDir::Size + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderExtDesc = QDir::Size + QDir::Reversed + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderSizeAsc = QDir::Type + QDir::DirsFirst + QDir::IgnoreCase,
+ kSortOrderSizeDesc = QDir::Type + QDir::Reversed + QDir::DirsFirst + QDir::IgnoreCase
+};
+Q_DECLARE_METATYPE(SortOrder)
+
+enum TypeFilter {
+ kTypeFilterAll = 0,
+ kTypeFilterImagesOnly = 1,
+ kTypeFilterMoviesOnly = 2
+};
+Q_DECLARE_METATYPE(TypeFilter)
+
+class GalleryFilter
+{
+ public:
+ static bool TestFilter(const QString& dir, const GalleryFilter& flt,
+ int *dirCount, int *imageCount, int *movieCount);
+
+ GalleryFilter(bool loaddefaultsettings = true);
+ GalleryFilter(const GalleryFilter &gfs);
+ GalleryFilter &operator=(const GalleryFilter &gfs);
+
+ void saveAsDefault();
+
+ QString getDirFilter() const { return m_dirFilter; }
+ void setDirFilter(QString dirFilter)
+ {
+ m_changed_state = 1;
+ m_dirFilter = dirFilter;
+ }
+
+ int getTypeFilter() const { return m_typeFilter; }
+ void setTypeFilter(int typeFilter)
+ {
+ m_changed_state = 1;
+ m_typeFilter = typeFilter;
+ }
+
+ int getSort() const { return m_sort; }
+ void setSort(int sort)
+ {
+ m_changed_state = 1;
+ m_sort = sort;
+ }
+
+ unsigned int getChangedState()
+ {
+ unsigned int ret = m_changed_state;
+ m_changed_state = 0;
+ return ret;
+ }
+ void dumpFilter(QString src)
+ {
+ VERBOSE(VB_EXTRA, QString("Dumping GalleryFilter from: %1")
+ .arg(src));
+ VERBOSE(VB_EXTRA, QString("directory fiter: %1")
+ .arg(m_dirFilter));
+ VERBOSE(VB_EXTRA, QString("type filter: %1")
+ .arg(m_typeFilter));
+ VERBOSE(VB_EXTRA, QString("sort options: %1")
+ .arg(m_sort));
+ }
+
+
+ private:
+ QString m_dirFilter;
+ int m_typeFilter;
+ int m_sort;
+
+ unsigned int m_changed_state;
+};
+
+#endif /* GALLERYFILTER_H */
Oops, something went wrong.

0 comments on commit e12b314

Please sign in to comment.