Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add mythgallery filtering/sorting support

Refs #9880

Signed-off-by: Gavin Hurlbut <ghurlbut@mythtv.org>
  • Loading branch information...
commit e12b31414145c6265bf62dfb59738f04b80ac8ac 1 parent e41e314
Trisooma authored Beirdo committed
View
134 mythplugins/mythgallery/mythgallery/galleryfilter.cpp
@@ -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;
+}
View
90 mythplugins/mythgallery/mythgallery/galleryfilter.h
@@ -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 */
View
284 mythplugins/mythgallery/mythgallery/galleryfilterdlg.cpp
@@ -0,0 +1,284 @@
+/* ============================================================
+ * File : galleryfilterdlg.cpp
+ * Description :
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published bythe Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "galleryfilter.h"
+
+using namespace std;
+
+// Qt headers
+#include <QApplication>
+#include <QEvent>
+//#include <QDir>
+//#include <QMatrix>
+#include <QList>
+//#include <QFileInfo>
+
+// MythTV headers
+#include <mythtv/util.h>
+#include <mythtv/mythdbcon.h>
+#include <mythtv/libmythui/mythuibuttonlist.h>
+//#include <mythtv/httpcomms.h>
+#include <mythtv/mythcontext.h>
+#include <mythtv/libmythdb/mythverbose.h>
+//#include <mythtv/libmythui/mythmainwindow.h>
+//#include <mythtv/libmythui/mythprogressdialog.h>
+//#include <mythtv/mythmediamonitor.h>
+
+// MythGallery headers
+//#include "galleryutil.h"
+//#include "gallerysettings.h"
+#include "galleryfilterdlg.h"
+#include "galleryfilter.h"
+//#include "thumbgenerator.h"
+//#include "iconview.h"
+//#include "singleview.h"
+//#include "glsingleview.h"
+
+#define LOC QString("GalleryFilterDlg:")
+#define LOC_ERR QString("GalleryFilterDlg, Error:")
+
+class FilterScanThread : public QThread
+{
+ public:
+ FilterScanThread(const QString& dir, const GalleryFilter& flt,
+ int *dirCount, int *imageCount, int *movieCount);
+ virtual void run();
+
+ private:
+ GalleryFilter m_filter;
+ QString m_dir;
+ int *m_dirCount;
+ int *m_imgCount;
+ int *m_movCount;
+};
+
+FilterScanThread::FilterScanThread(const QString& dir, const GalleryFilter& flt,
+ int *dirCount, int *imageCount, int *movieCount)
+{
+ m_dir = dir;
+ m_filter = flt;
+ m_dirCount = dirCount;
+ m_imgCount = imageCount;
+ m_movCount = movieCount;
+}
+
+void FilterScanThread::run()
+{
+ GalleryFilter::TestFilter(m_dir, m_filter, m_dirCount, m_imgCount, m_movCount);
+}
+
+GalleryFilterDialog::GalleryFilterDialog(MythScreenStack *parent, QString name, GalleryFilter *filter)
+ : MythScreenType(parent, name)
+{
+ m_settingsOriginal = filter;
+ m_settingsOriginal->dumpFilter("GalleryFilterDialog:ctor (original)");
+ m_settingsTemp = new GalleryFilter();
+ *m_settingsTemp = *filter;
+ m_settingsTemp->dumpFilter("GalleryFilterDialog:ctor (temporary)");
+ m_photoDir = gCoreContext->GetSetting("GalleryDir", "");
+ m_scanning = false;
+}
+
+GalleryFilterDialog::~GalleryFilterDialog()
+{
+ delete m_settingsTemp;
+}
+
+bool GalleryFilterDialog::Create()
+{
+ if (!LoadWindowFromXML("gallery-ui.xml", "filter", this))
+ return false;
+
+ bool err = false;
+
+ UIUtilE::Assign(this, m_dirFilter, "dirfilter_text", &err);
+ UIUtilE::Assign(this, m_typeFilter, "typefilter_select", &err);
+ UIUtilE::Assign(this, m_sortList, "sort_select", &err);
+ UIUtilE::Assign(this, m_checkButton, "check_button", &err);
+ UIUtilE::Assign(this, m_doneButton, "done_button", &err);
+ UIUtilE::Assign(this, m_saveButton, "save_button", &err);
+ UIUtilE::Assign(this, m_numImagesText, "numimages_text", &err);
+
+ if (err)
+ {
+ VERBOSE(VB_IMPORTANT, "Cannot load screen 'filter'");
+ return false;
+ }
+
+ BuildFocusList();
+
+ fillWidgets();
+
+ connect(m_dirFilter, SIGNAL(valueChanged()), SLOT(setDirFilter()));
+ connect(m_typeFilter, SIGNAL(itemSelected(MythUIButtonListItem*)),
+ SLOT(setTypeFilter(MythUIButtonListItem*)));
+ connect(m_sortList, SIGNAL(itemSelected(MythUIButtonListItem*)),
+ SLOT(setSort(MythUIButtonListItem*)));
+ connect(m_checkButton, SIGNAL(Clicked()), SLOT(updateFilter()));
+ connect(m_saveButton, SIGNAL(Clicked()), SLOT(saveAsDefault()));
+ connect(m_doneButton, SIGNAL(Clicked()), SLOT(saveAndExit()));
+
+ SetFocusWidget(m_dirFilter);
+
+ return true;
+}
+
+void GalleryFilterDialog::fillWidgets()
+{
+ // Directory filter
+ m_dirFilter->SetText(m_settingsTemp->getDirFilter(), false);
+
+ // Type Filter
+ new MythUIButtonListItem(m_typeFilter, QObject::tr("All"),
+ kTypeFilterAll);
+ new MythUIButtonListItem(m_typeFilter, QObject::tr("Images only"),
+ kTypeFilterImagesOnly);
+ new MythUIButtonListItem(m_typeFilter, QObject::tr("Movies only"),
+ kTypeFilterMoviesOnly);
+ m_typeFilter->SetValueByData(m_settingsTemp->getTypeFilter());
+ m_numImagesText->SetText("Filter result : (unknown)");
+
+ // Sort order
+ new MythUIButtonListItem(m_sortList, QObject::tr("Unsorted"),
+ kSortOrderUnsorted);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Name (A-Z alpha)"),
+ kSortOrderNameAsc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Reverse Name (Z-A alpha)"),
+ kSortOrderNameDesc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Mod Time (oldest first)"),
+ kSortOrderModTimeAsc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Reverse Mod Time (most recent first)"),
+ kSortOrderModTimeDesc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Extension (A-Z alpha)"),
+ kSortOrderExtAsc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Reverse Extension (Z-A alpha)"),
+ kSortOrderExtDesc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Filesize (smallest first)"),
+ kSortOrderSizeAsc);
+ new MythUIButtonListItem(m_sortList, QObject::tr("Reverse Filesize (largest first)"),
+ kSortOrderSizeDesc);
+ m_sortList->SetValueByData(m_settingsTemp->getSort());
+}
+
+void GalleryFilterDialog::updateFilter()
+{
+ if (m_scanning)
+ {
+ m_numImagesText->SetText("-- please be patient --");
+ return;
+ }
+ else
+ {
+ m_scanning = true;
+ }
+
+ int dir_count = 0;
+ int img_count = 0;
+ int mov_count = 0;
+
+ m_numImagesText->SetText("-- scanning current filter --");
+
+ FilterScanThread *fltScan = new FilterScanThread(m_photoDir, *m_settingsTemp, &dir_count, &img_count, &mov_count);
+ fltScan->start();
+
+ while (!fltScan->isFinished())
+ {
+ usleep(500);
+ qApp->processEvents();
+ }
+
+ if (dir_count + img_count + mov_count == 0)
+ {
+ m_numImagesText->SetText(QString(tr("No files / directories found")));
+ }
+ else
+ {
+ if (dir_count > 0)
+ {
+ if (img_count + mov_count == 0)
+ m_numImagesText->SetText(QString(tr("Filter result : %1 directories found but no files"))
+ .arg(dir_count));
+ else {
+ if (img_count == 0)
+ m_numImagesText->SetText(QString(tr("Filter result : %1 directories, %2 movie(s) found"))
+ .arg(dir_count)
+ .arg(mov_count));
+ else if (mov_count == 0)
+ m_numImagesText->SetText(QString(tr("Filter result : %1 directories, %2 image(s) found"))
+ .arg(dir_count)
+ .arg(img_count));
+ else
+ m_numImagesText->SetText(QString(tr("Filter result : %1 directories, %2 image(s) and %3 movie(s) found"))
+ .arg(dir_count)
+ .arg(img_count)
+ .arg(mov_count));
+ }
+
+ }
+ else
+ {
+ if (img_count > 0 && mov_count > 0)
+ m_numImagesText->SetText(QString(tr("Filter result : %1 image(s) and %2 movie(s) found"))
+ .arg(img_count)
+ .arg(mov_count));
+ else if (mov_count == 0)
+ m_numImagesText->SetText(QString(tr("Filter result : %1 image(s) found"))
+ .arg(img_count));
+ else
+ m_numImagesText->SetText(QString(tr("Filter result : %1 movie(s) found"))
+ .arg(mov_count));
+ }
+ }
+
+ m_scanning = false;
+}
+
+void GalleryFilterDialog::setDirFilter(void)
+{
+ m_settingsTemp->setDirFilter(m_dirFilter->GetText());
+}
+
+void GalleryFilterDialog::setTypeFilter(MythUIButtonListItem *item)
+{
+ m_settingsTemp->setTypeFilter(item->GetData().toInt());
+}
+
+void GalleryFilterDialog::setSort(MythUIButtonListItem *item)
+{
+ m_settingsTemp->setSort(item->GetData().toInt());
+}
+
+void GalleryFilterDialog::saveAsDefault()
+{
+ // Save defaults from temp settings
+ m_settingsTemp->saveAsDefault();
+ saveAndExit();
+}
+
+void GalleryFilterDialog::saveAndExit()
+{
+ *m_settingsOriginal = *m_settingsTemp;
+
+ m_settingsOriginal->dumpFilter("GalleryFilterDialog::saveAndExit()");
+
+ if (m_settingsOriginal->getChangedState() > 0)
+ {
+ emit filterChanged();
+ }
+
+ Close();
+}
View
78 mythplugins/mythgallery/mythgallery/galleryfilterdlg.h
@@ -0,0 +1,78 @@
+/* ============================================================
+ * File : galleryfilterdlg.h
+ * Description :
+ *
+
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published bythe Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef GALLERYFILTERDLG_H
+#define GALLERYFILTERDLG_H
+
+// Qt headers
+#include <QThread>
+
+// MythTV headers
+#include <mythtv/libmythui/mythscreentype.h>
+#include <mythtv/libmythui/mythuitext.h>
+#include <mythtv/libmythui/mythuibutton.h>
+#include <mythtv/libmythui/mythuibuttonlist.h>
+#include <mythtv/libmythui/mythuiimage.h>
+#include <mythtv/libmythui/mythdialogbox.h>
+#include <mythtv/mythmedia.h>
+
+#include "galleryfilter.h"
+
+using namespace std;
+
+class GalleryFilter;
+class GalleryFilterDialog : public MythScreenType
+{
+
+ Q_OBJECT
+
+ public:
+ GalleryFilterDialog(MythScreenStack *parent, QString name, GalleryFilter *filter);
+ ~GalleryFilterDialog();
+
+ bool Create();
+
+ signals:
+ void filterChanged();
+
+ public slots:
+ void saveAndExit();
+ void saveAsDefault();
+ void updateFilter();
+ void setDirFilter(void);
+ void setTypeFilter(MythUIButtonListItem *item);
+ void setSort(MythUIButtonListItem *item);
+
+ private:
+ void fillWidgets();
+
+ bool m_scanning;
+ QString m_photoDir;
+ GalleryFilter *m_settingsOriginal;
+ GalleryFilter *m_settingsTemp;
+
+ MythUITextEdit *m_dirFilter;
+ MythUIButtonList *m_typeFilter;
+ MythUIText *m_numImagesText;
+ MythUIButtonList *m_sortList;
+ MythUIButton *m_checkButton;
+ MythUIButton *m_saveButton;
+ MythUIButton *m_doneButton;
+};
+
+#endif /* GALLERYFILTERDLG_H */
View
29 mythplugins/mythgallery/mythgallery/gallerysettings.cpp
@@ -8,9 +8,31 @@
// mythgallery
#include "config.h"
#include "gallerysettings.h"
+#include "galleryfilter.h"
// General Settings
+static HostLineEdit *MythGalleryFilter()
+{
+ HostLineEdit *gc = new HostLineEdit("GalleryFilterDirectory");
+ gc->setLabel(QObject::tr("Directory filter"));
+ gc->setValue("");
+ gc->setHelpText(QObject::tr("Enter direcory names to be excluded in browser. "
+ "(multiple entries delimited with ':')"));
+ return gc;
+};
+
+static HostComboBox *MythGalleryFilterType()
+{
+ HostComboBox *gc = new HostComboBox("GalleryFilterType");
+ gc->setLabel(QObject::tr("Type filter"));
+ gc->addSelection("All", QString::number(kTypeFilterAll));
+ gc->addSelection("Images only", QString::number(kTypeFilterImagesOnly));
+ gc->addSelection("Movies only", QString::number(kTypeFilterMoviesOnly));
+ gc->setHelpText(QObject::tr("This is the type filter for the displayed "
+ "thumbnails."));
+ return gc;
+};
static HostLineEdit *MythGalleryDir()
{
HostLineEdit *gc = new HostLineEdit("GalleryDir");
@@ -38,10 +60,15 @@ static HostComboBox *MythGallerySortOrder()
{
HostComboBox *gc = new HostComboBox("GallerySortOrder");
gc->setLabel(QObject::tr("Sort order when browsing"));
+ gc->addSelection("Unsorted", QString::number(QDir::Unsorted));
gc->addSelection("Name (A-Z alpha)", QString::number(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase));
gc->addSelection("Reverse Name (Z-A alpha)", QString::number(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed));
gc->addSelection("Mod Time (earliest first)", QString::number(QDir::Time | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed));
gc->addSelection("Reverse Mod Time (most recent first)", QString::number(QDir::Time | QDir::DirsFirst | QDir::IgnoreCase));
+ gc->addSelection("Extension (A-Z alpha)", QString::number(QDir::Size | QDir::DirsFirst | QDir::IgnoreCase));
+ gc->addSelection("Reverse Extension (Z-A alpha", QString::number(QDir::Size | QDir::Reversed | QDir::DirsFirst | QDir::IgnoreCase));
+ gc->addSelection("Filesize (smallest first)", QString::number(QDir::Type | QDir::DirsFirst | QDir::IgnoreCase));
+ gc->addSelection("Reverse Filesize (largest first)", QString::number(QDir::Type | QDir::Reversed | QDir::DirsFirst | QDir::IgnoreCase));
gc->setHelpText(QObject::tr("This is the sort order for the displayed "
"picture thumbnails."));
return gc;
@@ -229,6 +256,8 @@ GallerySettings::GallerySettings()
general->addChild(MythGalleryImportDirs());
general->addChild(MythGalleryAutoLoad());
general->addChild(MythGalleryMoviePlayerCmd());
+ general->addChild(MythGalleryFilter());
+ general->addChild(MythGalleryFilterType());
addChild(general);
GalleryConfigurationGroup* config = new GalleryConfigurationGroup();
View
26 mythplugins/mythgallery/mythgallery/galleryutil.cpp
@@ -210,12 +210,13 @@ long GalleryUtil::GetNaturalRotation(const QString &filePathString)
}
bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir,
- int sortorder, bool recurse,
+ const GalleryFilter& flt, bool recurse,
ThumbHash *itemHash, ThumbGenerator* thumbGen)
{
QString blah = dir;
QDir d(blah);
QString currDir = d.absolutePath();
+ QStringList splitFD;
bool isGallery;
QFileInfoList gList = d.entryInfoList(QStringList("serial*.dat"),
@@ -228,7 +229,7 @@ bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir,
QFileInfoList list = d.entryInfoList(GetMediaFilter(),
QDir::Files | QDir::AllDirs,
- (QDir::SortFlag)sortorder);
+ (QDir::SortFlag)flt.getSort());
if (list.isEmpty())
return false;
@@ -242,6 +243,11 @@ bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir,
thumbGen->setDirectory(currDir, isGallery);
}
+ if (!flt.getDirFilter().isEmpty())
+ {
+ splitFD = flt.getDirFilter().split(":");
+ }
+
while (it != list.end())
{
fi = &(*it);
@@ -256,14 +262,26 @@ bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir,
(fi->fileName().indexOf(".highlight.") > 0)))
continue;
+ // skip filtered directory
+ if (fi->isDir() && !splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
+ {
+ continue;
+ }
+
if (fi->isDir() && recurse)
{
- GalleryUtil::LoadDirectory(
+ LoadDirectory(
itemList, QDir::cleanPath(fi->absoluteFilePath()),
- sortorder, true, itemHash, thumbGen);
+ flt, true, itemHash, thumbGen);
}
else
{
+ if ((GalleryUtil::IsImage(fi->absoluteFilePath())
+ && flt.getTypeFilter() == kTypeFilterMoviesOnly)
+ || (GalleryUtil::IsMovie(fi->absoluteFilePath())
+ && flt.getTypeFilter() == kTypeFilterImagesOnly))
+ continue;
+
ThumbItem *item = new ThumbItem(
fi->fileName(),
QDir::cleanPath(fi->absoluteFilePath()), fi->isDir());
View
8 mythplugins/mythgallery/mythgallery/galleryutil.h
@@ -17,8 +17,8 @@
*
* ============================================================ */
-#ifndef EXIFUTIL_H
-#define EXIFUTIL_H
+#ifndef GALLERYUTIL_H
+#define GALLERYUTIL_H
#include <QFileInfo>
@@ -45,7 +45,7 @@ class GalleryUtil
static QString GetCaption(const QString &filePath);
static bool LoadDirectory(ThumbList &itemList, const QString &dir,
- int sortorder, bool recurse,
+ const GalleryFilter& flt, bool recurse,
ThumbHash *itemHash, ThumbGenerator *thumbGen);
static QSize ScaleToDest(const QSize &sz, const QSize &dest, ScaleMax scaleMax);
@@ -67,4 +67,4 @@ class GalleryUtil
const QString &newName);
};
-#endif /* EXIFUTIL_H */
+#endif /* GALLERYUTIL_H */
View
34 mythplugins/mythgallery/mythgallery/iconview.cpp
@@ -47,6 +47,7 @@ using namespace std;
// MythGallery headers
#include "galleryutil.h"
#include "gallerysettings.h"
+#include "galleryfilter.h"
#include "thumbgenerator.h"
#include "iconview.h"
#include "singleview.h"
@@ -107,6 +108,7 @@ IconView::IconView(MythScreenStack *parent, const char *name,
: MythScreenType(parent, name)
{
m_galleryDir = galleryDir;
+ m_galleryFilter = new GalleryFilter();
m_isGallery = false;
m_showDevices = false;
@@ -146,7 +148,11 @@ IconView::~IconView()
delete m_thumbGen;
m_thumbGen = NULL;
}
-
+ if (m_galleryFilter)
+ {
+ delete m_galleryFilter;
+ m_galleryFilter = NULL;
+ }
if (m_childCountThread)
{
delete m_childCountThread;
@@ -238,7 +244,7 @@ void IconView::LoadDirectory(const QString &dir)
m_itemHash.clear();
m_imageList->Reset();
- m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, m_sortorder,
+ m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, *m_galleryFilter,
false, &m_itemHash, m_thumbGen);
if (m_thumbGen && !m_thumbGen->isRunning())
@@ -797,9 +803,12 @@ void IconView::customEvent(QEvent *event)
HandleSubMenuMark();
break;
case 4:
- HandleSubMenuFile();
+ HandleSubMenuFilter();
break;
case 5:
+ HandleSubMenuFile();
+ break;
+ case 6:
HandleSettings();
break;
}
@@ -871,6 +880,11 @@ void IconView::customEvent(QEvent *event)
}
+void IconView::reloadData()
+{
+ LoadDirectory(m_galleryDir);
+}
+
void IconView::HandleMainMenu(void)
{
QString label = tr("Gallery Options");
@@ -890,6 +904,7 @@ void IconView::HandleMainMenu(void)
m_menuPopup->AddButton(tr("Random"));
m_menuPopup->AddButton(tr("Meta Data Menu"));
m_menuPopup->AddButton(tr("Marking Menu"));
+ m_menuPopup->AddButton(tr("Filter / Sort Menu"));
m_menuPopup->AddButton(tr("File Menu"));
m_menuPopup->AddButton(tr("Settings"));
// if (m_showDevices)
@@ -937,6 +952,19 @@ void IconView::HandleSubMenuMark(void)
m_menuPopup->AddButton(tr("Clear Marked"));
}
+void IconView::HandleSubMenuFilter(void)
+{
+ MythScreenStack *mainStack = GetScreenStack();
+
+ GalleryFilterDialog *filterdialog = new GalleryFilterDialog(mainStack,
+ "galleryfilter", m_galleryFilter);
+
+ if (filterdialog->Create())
+ mainStack->AddScreen(filterdialog);
+
+ connect(filterdialog, SIGNAL(filterChanged()), SLOT(reloadData()));
+}
+
void IconView::HandleSubMenuFile(void)
{
QString label = tr("File Options");
View
7 mythplugins/mythgallery/mythgallery/iconview.h
@@ -36,6 +36,8 @@
#include <mythmedia.h>
// MythGallery headers
+#include "galleryfilter.h"
+#include "galleryfilterdlg.h"
#include "thumbview.h"
using namespace std;
@@ -77,6 +79,7 @@ class IconView : public MythScreenType
void HandleMainMenu(void);
void HandleSubMenuMetadata(void);
void HandleSubMenuMark(void);
+ void HandleSubMenuFilter(void);
void HandleSubMenuFile(void);
private slots:
@@ -116,6 +119,7 @@ class IconView : public MythScreenType
QStringList m_itemMarked;
QString m_galleryDir;
vector<int> m_history;
+ GalleryFilter *m_galleryFilter;
MythUIButtonList *m_imageList;
MythUIText *m_captionText;
@@ -142,6 +146,9 @@ class IconView : public MythScreenType
QString m_errorStr;
+ protected slots:
+ void reloadData();
+
public slots:
void mediaStatusChanged(MythMediaStatus oldStatus, MythMediaDevice *pMedia);
void HandleItemSelect(MythUIButtonListItem *);
View
2  mythplugins/mythgallery/mythgallery/mythgallery.pro
@@ -19,11 +19,13 @@ INCLUDEPATH += $${PREFIX}/include/mythtv
# Input
HEADERS += iconview.h singleview.h
HEADERS += imageview.h
+HEADERS += galleryfilter.h galleryfilterdlg.h
HEADERS += gallerysettings.h dbcheck.h
HEADERS += galleryutil.h
HEADERS += thumbgenerator.h thumbview.h
SOURCES += iconview.cpp singleview.cpp
SOURCES += imageview.cpp
+SOURCES += galleryfilter.cpp galleryfilterdlg.cpp
SOURCES += gallerysettings.cpp dbcheck.cpp
SOURCES += galleryutil.cpp
SOURCES += thumbgenerator.cpp thumbview.cpp
View
63 mythplugins/mythgallery/theme/default-wide/gallery-ui.xml
@@ -115,4 +115,67 @@
</window>
+ <window name="filter">
+
+ <textarea name="title" from="basetextarea">
+ <area>20,50,1260,30</area>
+ <value>Filter/sort images</value>
+ <align>hcenter,vcenter</align>
+ <font>baselarge</font>
+ </textarea>
+
+ <!-- Filter: labels -->
+ <textarea name="filter_text" from="basetextarea">
+ <area>10,107,180,34</area>
+ <value>Directory filter :</value>
+ <align>right,top</align>
+ </textarea>
+
+ <textarea name="type_filter" from="filter_text">
+ <position>10,161</position>
+ <value>Type filter :</value>
+ </textarea>
+
+ <textarea name="numimages_text" from="basetextarea">
+ <area>200,255,1260,30</area>
+ <value>NumImages_Text</value>
+ <align>left,top</align>
+ </textarea>
+
+ <!-- Sort: labels -->
+ <textarea name="sort_text" from="basetextarea">
+ <area>10,319,180,34</area>
+ <value>Sort by :</value>
+ <align>right,top</align>
+ </textarea>
+
+ <!-- Widgets -->
+ <textedit name="dirfilter_text" from="basetextedit">
+ <position>200,100</position>
+ </textedit>
+
+ <buttonlist name="typefilter_select" from="baseselector">
+ <position>200,154</position>
+ </buttonlist>
+
+ <button name="check_button" from="basebutton">
+ <position>200,200</position>
+ <value>Check Filter</value>
+ </button>
+
+ <buttonlist name="sort_select" from="baseselector">
+ <position>200,312</position>
+ </buttonlist>
+
+ <button name="done_button" from="basebutton">
+ <position>670,505</position>
+ <value>Done</value>
+ </button>
+
+ <button name="save_button" from="basebutton">
+ <position>490,505</position>
+ <value>Save as default</value>
+ </button>
+
+ </window>
</mythuitheme>
View
63 mythplugins/mythgallery/theme/default/gallery-ui.xml
@@ -112,4 +112,67 @@
</textarea>
</window>
+ <window name="filter">
+
+ <textarea name="title" from="basetextarea">
+ <area>20,50,770,30</area>
+ <value>Filter/sort images</value>
+ <align>hcenter,vcenter</align>
+ <font>baselarge</font>
+ </textarea>
+
+ <!-- Filter: labels -->
+ <textarea name="filter_text" from="basetextarea">
+ <area>10,107,180,34</area>
+ <value>Directory filter :</value>
+ <align>right,top</align>
+ </textarea>
+
+ <textarea name="type_filter" from="filter_text">
+ <position>10,161</position>
+ <value>Type filter :</value>
+ </textarea>
+
+ <textarea name="numimages_text" from="basetextarea">
+ <area>200,255,770,30</area>
+ <value>NumImages_Text</value>
+ <align>left,top</align>
+ </textarea>
+
+ <!-- Sort: labels -->
+ <textarea name="sort_text" from="basetextarea">
+ <area>10,319,180,34</area>
+ <value>Sort by :</value>
+ <align>right,top</align>
+ </textarea>
+
+ <!-- Widgets -->
+ <textedit name="dirfilter_text" from="basetextedit">
+ <position>200,100</position>
+ </textedit>
+
+ <buttonlist name="typefilter_select" from="baseselector">
+ <position>200,154</position>
+ </buttonlist>
+
+ <button name="check_button" from="basebutton">
+ <position>200,200</position>
+ <value>Check Filter</value>
+ </button>
+
+ <buttonlist name="sort_select" from="baseselector">
+ <position>200,312</position>
+ </buttonlist>
+
+ <button name="done_button" from="basebutton">
+ <position>380,505</position>
+ <value>Done</value>
+ </button>
+
+ <button name="save_button" from="basebutton">
+ <position>200,505</position>
+ <value>Save as default</value>
+ </button>
+
+ </window>
</mythuitheme>
Please sign in to comment.
Something went wrong with that request. Please try again.