MythTV  master
galleryfilter.cpp
Go to the documentation of this file.
1 #include <set>
2 #include <mythuitextedit.h>
3 
4 #include <mythcontext.h>
5 #include <mythuibuttonlist.h>
6 #include <mythuibutton.h>
7 #include <mythuitext.h>
8 #include <mythuitextedit.h>
9 #include <mythlogging.h>
10 
11 #include "config.h"
12 #include "galleryfilter.h"
13 #include "galleryutil.h"
14 
15 GalleryFilter::GalleryFilter(bool loaddefaultsettings)
16 {
17  // do nothing yet
18  if (loaddefaultsettings)
19  {
20  m_dirFilter = gCoreContext->GetSetting("GalleryFilterDirectory", "");
21  m_typeFilter = gCoreContext->GetNumSetting("GalleryFilterType",
23  m_sort = gCoreContext->GetNumSetting("GallerySortOrder",
25  }
26 }
27 
29 {
30  *this = gfs;
31 }
32 
34 {
35  if (m_dirFilter != gfs.m_dirFilter)
36  {
38  m_changed_state = true;
39  }
40 
41  if (m_typeFilter != gfs.m_typeFilter)
42  {
44  m_changed_state = true;
45  }
46 
47  if (m_sort != gfs.m_sort)
48  {
49  m_sort = gfs.m_sort;
50  m_changed_state = true;
51  }
52 
53  return *this;
54 }
55 
57 {
58  gCoreContext->SaveSetting("GalleryFilterDirectory", m_dirFilter);
59  gCoreContext->SaveSetting("GalleryFilterType", m_typeFilter);
60  gCoreContext->SaveSetting("GallerySortOrder", m_sort);
61 }
62 
63 bool GalleryFilter::TestFilter(const QString& dir, const GalleryFilter& flt,
64  int *dirCount, int *imageCount, int *movieCount)
65 {
66  QStringList splitFD;
67 
68  QDir d(dir);
69  QString currDir = d.absolutePath();
70  QFileInfoList list = d.entryInfoList(GalleryUtil::GetMediaFilter(),
71  QDir::Files | QDir::AllDirs |
72  QDir::NoDotAndDotDot,
73  (QDir::SortFlag)flt.getSort());
74 
75  if (list.isEmpty())
76  return false;
77 
78  if (!flt.getDirFilter().isEmpty())
79  splitFD = flt.getDirFilter().split(":");
80 
81  for (QFileInfoList::const_iterator it = list.begin();
82  it != list.end(); ++it)
83  {
84  const QFileInfo *fi = &(*it);
85 
86  // remove these already-resized pictures.
87  if ((fi->fileName().indexOf(".thumb.") > 0) ||
88  (fi->fileName().indexOf(".sized.") > 0) ||
89  (fi->fileName().indexOf(".highlight.") > 0))
90  continue;
91 
92  // skip filtered directory
93  if (fi->isDir())
94  {
95  if (!splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
96  continue;
97 
98  // add directory
99  (*dirCount)++;
100  GalleryFilter::TestFilter(QDir::cleanPath(fi->absoluteFilePath()),
101  flt, dirCount, imageCount, movieCount);
102  }
103  else
104  {
105  if (GalleryUtil::IsImage(fi->absoluteFilePath()) &&
107  (*imageCount)++;
108  else if (GalleryUtil::IsMovie(fi->absoluteFilePath()) &&
110  (*movieCount)++;
111  }
112  }
113 
114  return true;
115 }
116 
117 
118 void GalleryFilter::dumpFilter(const QString& src)
119 {
120  LOG(VB_GENERAL, LOG_DEBUG, QString("Dumping GalleryFilter from: %1")
121  .arg(src));
122  LOG(VB_GENERAL, LOG_DEBUG, QString("directory fiter: %1")
123  .arg(m_dirFilter));
124  LOG(VB_GENERAL, LOG_DEBUG, QString("type filter: %1")
125  .arg(m_typeFilter));
126  LOG(VB_GENERAL, LOG_DEBUG, QString("sort options: %1")
127  .arg(m_sort));
128 }
129 
130 /*
131  * vim:ts=4:sw=4:ai:et:si:sts=4
132  */
void dumpFilter(const QString &src)
GalleryFilter & operator=(const GalleryFilter &gfs)
void SaveSetting(const QString &key, int newValue)
void saveAsDefault()
int getTypeFilter() const
Definition: galleryfilter.h:52
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static bool IsMovie(const QString &filePath)
static bool IsImage(const QString &filePath)
static QStringList GetMediaFilter(void)
Definition: galleryutil.cpp:95
GalleryFilter(bool loaddefaultsettings=true)
static const uint16_t * d
QString GetSetting(const QString &key, const QString &defaultval="")
bool m_changed_state
Definition: galleryfilter.h:79
QString getDirFilter() const
Definition: galleryfilter.h:45
QString m_dirFilter
Definition: galleryfilter.h:75
int GetNumSetting(const QString &key, int defaultval=0)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
int getSort() const
Definition: galleryfilter.h:59
static bool TestFilter(const QString &dir, const GalleryFilter &flt, int *dirCount, int *imageCount, int *movieCount)