00001 #include <set>
00002 #include <mythuitextedit.h>
00003
00004 #include <mythcontext.h>
00005 #include <mythuibuttonlist.h>
00006 #include <mythuibutton.h>
00007 #include <mythuitext.h>
00008 #include <mythuitextedit.h>
00009 #include <mythlogging.h>
00010
00011 #include "config.h"
00012 #include "galleryfilter.h"
00013 #include "galleryutil.h"
00014
00015 GalleryFilter::GalleryFilter(bool loaddefaultsettings) :
00016 m_dirFilter(""), m_typeFilter(kTypeFilterAll),
00017 m_sort(kSortOrderUnsorted),
00018 m_changed_state(0)
00019 {
00020
00021 if (loaddefaultsettings)
00022 {
00023 m_dirFilter = gCoreContext->GetSetting("GalleryFilterDirectory", "");
00024 m_typeFilter = gCoreContext->GetNumSetting("GalleryFilterType",
00025 kTypeFilterAll);
00026 m_sort = gCoreContext->GetNumSetting("GallerySortOrder",
00027 kSortOrderUnsorted);
00028 }
00029 }
00030
00031 GalleryFilter::GalleryFilter(const GalleryFilter &gfs) :
00032 m_changed_state(0)
00033 {
00034 *this = gfs;
00035 }
00036
00037 GalleryFilter & GalleryFilter::operator=(const GalleryFilter &gfs)
00038 {
00039 if (m_dirFilter != gfs.m_dirFilter)
00040 {
00041 m_dirFilter = gfs.m_dirFilter;
00042 m_changed_state = true;
00043 }
00044
00045 if (m_typeFilter != gfs.m_typeFilter)
00046 {
00047 m_typeFilter = gfs.m_typeFilter;
00048 m_changed_state = true;
00049 }
00050
00051 if (m_sort != gfs.m_sort)
00052 {
00053 m_sort = gfs.m_sort;
00054 m_changed_state = true;
00055 }
00056
00057 return *this;
00058 }
00059
00060 void GalleryFilter::saveAsDefault()
00061 {
00062 gCoreContext->SaveSetting("GalleryFilterDirectory", m_dirFilter);
00063 gCoreContext->SaveSetting("GalleryFilterType", m_typeFilter);
00064 gCoreContext->SaveSetting("GallerySortOrder", m_sort);
00065 }
00066
00067 bool GalleryFilter::TestFilter(const QString& dir, const GalleryFilter& flt,
00068 int *dirCount, int *imageCount, int *movieCount)
00069 {
00070 QStringList splitFD;
00071 const QFileInfo *fi;
00072
00073 QDir d(dir);
00074 QString currDir = d.absolutePath();
00075 QFileInfoList list = d.entryInfoList(GalleryUtil::GetMediaFilter(),
00076 QDir::Files | QDir::AllDirs,
00077 (QDir::SortFlag)flt.getSort());
00078
00079 if (list.isEmpty())
00080 return false;
00081
00082 if (!flt.getDirFilter().isEmpty())
00083 splitFD = flt.getDirFilter().split(":");
00084
00085 for (QFileInfoList::const_iterator it = list.begin();
00086 it != list.end(); ++it)
00087 {
00088 fi = &(*it);
00089 if (fi->fileName() == "." || fi->fileName() == "..")
00090 continue;
00091
00092
00093 if ((fi->fileName().indexOf(".thumb.") > 0) ||
00094 (fi->fileName().indexOf(".sized.") > 0) ||
00095 (fi->fileName().indexOf(".highlight.") > 0))
00096 continue;
00097
00098
00099 if (fi->isDir())
00100 {
00101 if (!splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
00102 continue;
00103
00104
00105 (*dirCount)++;
00106 GalleryFilter::TestFilter(QDir::cleanPath(fi->absoluteFilePath()),
00107 flt, dirCount, imageCount, movieCount);
00108 }
00109 else
00110 {
00111 if (GalleryUtil::IsImage(fi->absoluteFilePath()) &&
00112 flt.getTypeFilter() != kTypeFilterMoviesOnly)
00113 (*imageCount)++;
00114 else if (GalleryUtil::IsMovie(fi->absoluteFilePath()) &&
00115 flt.getTypeFilter() != kTypeFilterImagesOnly)
00116 (*movieCount)++;
00117 }
00118 }
00119
00120 return true;
00121 }
00122
00123
00124 void GalleryFilter::dumpFilter(QString src)
00125 {
00126 LOG(VB_GENERAL, LOG_DEBUG, QString("Dumping GalleryFilter from: %1")
00127 .arg(src));
00128 LOG(VB_GENERAL, LOG_DEBUG, QString("directory fiter: %1")
00129 .arg(m_dirFilter));
00130 LOG(VB_GENERAL, LOG_DEBUG, QString("type filter: %1")
00131 .arg(m_typeFilter));
00132 LOG(VB_GENERAL, LOG_DEBUG, QString("sort options: %1")
00133 .arg(m_sort));
00134 }
00135
00136
00137
00138