- Add support for display time windows for images in folder.options
- the times are defined in a JSON array with start and end times, if inside the window the image is valid to display
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonArray>
|
||||
#include <QDateTime>
|
||||
#include <QTime>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
@@ -90,6 +92,28 @@ Config loadConfiguration(const std::string &configFilePath, const Config ¤
|
||||
userConfig.blurRadius = (int)jsonDoc["blur"].toDouble();
|
||||
}
|
||||
|
||||
if(jsonDoc.contains("times") && jsonDoc["times"].isArray())
|
||||
{
|
||||
QJsonArray jsonArray = jsonDoc["times"].toArray();
|
||||
foreach (const QJsonValue & value, jsonArray)
|
||||
{
|
||||
QJsonObject obj = value.toObject();
|
||||
if(obj.contains("start") || obj.contains("end"))
|
||||
{
|
||||
DisplayTimeWindow window;
|
||||
if(obj.contains("start"))
|
||||
{
|
||||
window.startDisplay = QTime::fromString(obj["start"].toString());
|
||||
}
|
||||
if(obj.contains("end"))
|
||||
{
|
||||
window.endDisplay = QTime::fromString(obj["end"].toString());
|
||||
}
|
||||
userConfig.baseDisplayOptions.timeWindows.append(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userConfig.loadTime = QDateTime::currentDateTime();
|
||||
return userConfig;
|
||||
}
|
||||
|
||||
@@ -111,10 +111,37 @@ ImageDetails ImageSelector::populateImageDetails(const std::string&fileName, con
|
||||
} else {
|
||||
imageDetails.aspect = ImageAspect_Any;
|
||||
}
|
||||
imageDetails.options = baseOptions;
|
||||
|
||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, baseOptions);
|
||||
|
||||
return imageDetails;
|
||||
}
|
||||
|
||||
bool ImageSelector::imageInsideTimeWindow(const QVector<DisplayTimeWindow> &timeWindows)
|
||||
{
|
||||
if(timeWindows.count() == 0)
|
||||
{
|
||||
return true; // no specified time windows means always display
|
||||
}
|
||||
const QTime currentTime = QTime::currentTime();
|
||||
for(auto &window : timeWindows)
|
||||
{
|
||||
if(currentTime > window.startDisplay && currentTime < window.endDisplay)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(debugMode && timeWindows.count() > 0)
|
||||
{
|
||||
std::cout << "image display time outside windows: " << std::endl;
|
||||
for(auto timeWindow : timeWindows)
|
||||
{
|
||||
std::cout << "time: " << timeWindow.startDisplay.toString().toStdString() << "-" << timeWindow.endDisplay.toString().toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
|
||||
{
|
||||
if(!QFileInfo::exists(QString(imageDetails.filename.c_str())))
|
||||
@@ -135,6 +162,10 @@ bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!imageInsideTimeWindow(imageDetails.options.timeWindows))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -176,7 +207,6 @@ const ImageDetails RandomImageSelector::getNextImage(const ImageDisplayOptions &
|
||||
std::cerr << "Error: " << err << std::endl;
|
||||
}
|
||||
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, imageDetails.options);
|
||||
return imageDetails;
|
||||
}
|
||||
|
||||
@@ -221,7 +251,6 @@ const ImageDetails ShuffleImageSelector::getNextImage(const ImageDisplayOptions
|
||||
current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image
|
||||
}
|
||||
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, imageDetails.options);
|
||||
return imageDetails;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ protected:
|
||||
ImageDetails populateImageDetails(const std::string&filename, const ImageDisplayOptions &baseOptions);
|
||||
bool imageValidForAspect(const ImageDetails& imageDetails);
|
||||
bool imageMatchesFilter(const ImageDetails& imageDetails);
|
||||
bool imageInsideTimeWindow(const QVector<DisplayTimeWindow> &timeWindows);
|
||||
std::unique_ptr<PathTraverser> pathTraverser;
|
||||
bool debugMode = false;
|
||||
};
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
#ifndef IMAGESTRUCTS_H
|
||||
#define IMAGESTRUCTS_H
|
||||
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
#include <string>
|
||||
|
||||
// possible aspect ratios of an image
|
||||
enum ImageAspect { ImageAspect_Landscape = 0, ImageAspect_Portrait, ImageAspect_Any, ImageAspect_Monitor /* match monitors aspect */ };
|
||||
|
||||
struct DisplayTimeWindow
|
||||
{
|
||||
QTime startDisplay = QTime(0,0,0,0);
|
||||
QTime endDisplay = QTime(23,59,59,0);
|
||||
};
|
||||
|
||||
// options to consider when displaying an image
|
||||
struct ImageDisplayOptions
|
||||
{
|
||||
ImageAspect onlyAspect = ImageAspect_Any;
|
||||
bool fitAspectAxisToWindow = false;
|
||||
QVector<DisplayTimeWindow> timeWindows;
|
||||
};
|
||||
|
||||
// details of a particular image
|
||||
|
||||
Reference in New Issue
Block a user