- 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:
13
README.md
13
README.md
@@ -90,10 +90,21 @@ When using the default or recursive folder mode we support having per folder dis
|
|||||||
"aspect" : "m",
|
"aspect" : "m",
|
||||||
"rotationSeconds" : 300,
|
"rotationSeconds" : 300,
|
||||||
"opacity" : 200,
|
"opacity" : 200,
|
||||||
"blur" : 20
|
"blur" : 20,
|
||||||
|
"times": [
|
||||||
|
{
|
||||||
|
"start": "08:00",
|
||||||
|
"end": "10:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": "17:00",
|
||||||
|
"end": "19:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
See the `Configuration File` section for details of each setting.
|
See the `Configuration File` section for details of each setting.
|
||||||
|
* `times` : times is a JSON array of start and end times in which it is valid to display this image. The time is in the format HH:MM:SS and is based on the systems local time. If `start` isn't defined then it defaults to the start of the day, if `end` isn't default it defaults to the end of the day.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QTime>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@@ -90,6 +92,28 @@ Config loadConfiguration(const std::string &configFilePath, const Config ¤
|
|||||||
userConfig.blurRadius = (int)jsonDoc["blur"].toDouble();
|
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();
|
userConfig.loadTime = QDateTime::currentDateTime();
|
||||||
return userConfig;
|
return userConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,10 +111,37 @@ ImageDetails ImageSelector::populateImageDetails(const std::string&fileName, con
|
|||||||
} else {
|
} else {
|
||||||
imageDetails.aspect = ImageAspect_Any;
|
imageDetails.aspect = ImageAspect_Any;
|
||||||
}
|
}
|
||||||
imageDetails.options = baseOptions;
|
|
||||||
|
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, baseOptions);
|
||||||
|
|
||||||
return imageDetails;
|
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)
|
bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
|
||||||
{
|
{
|
||||||
if(!QFileInfo::exists(QString(imageDetails.filename.c_str())))
|
if(!QFileInfo::exists(QString(imageDetails.filename.c_str())))
|
||||||
@@ -135,6 +162,10 @@ bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!imageInsideTimeWindow(imageDetails.options.timeWindows))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +207,6 @@ const ImageDetails RandomImageSelector::getNextImage(const ImageDisplayOptions &
|
|||||||
std::cerr << "Error: " << err << std::endl;
|
std::cerr << "Error: " << err << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
||||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, imageDetails.options);
|
|
||||||
return imageDetails;
|
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
|
current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image
|
||||||
}
|
}
|
||||||
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
std::cout << "updating image: " << imageDetails.filename << std::endl;
|
||||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, imageDetails.options);
|
|
||||||
return imageDetails;
|
return imageDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ protected:
|
|||||||
ImageDetails populateImageDetails(const std::string&filename, const ImageDisplayOptions &baseOptions);
|
ImageDetails populateImageDetails(const std::string&filename, const ImageDisplayOptions &baseOptions);
|
||||||
bool imageValidForAspect(const ImageDetails& imageDetails);
|
bool imageValidForAspect(const ImageDetails& imageDetails);
|
||||||
bool imageMatchesFilter(const ImageDetails& imageDetails);
|
bool imageMatchesFilter(const ImageDetails& imageDetails);
|
||||||
|
bool imageInsideTimeWindow(const QVector<DisplayTimeWindow> &timeWindows);
|
||||||
std::unique_ptr<PathTraverser> pathTraverser;
|
std::unique_ptr<PathTraverser> pathTraverser;
|
||||||
bool debugMode = false;
|
bool debugMode = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
#ifndef IMAGESTRUCTS_H
|
#ifndef IMAGESTRUCTS_H
|
||||||
#define IMAGESTRUCTS_H
|
#define IMAGESTRUCTS_H
|
||||||
|
|
||||||
|
#include <QTime>
|
||||||
|
#include <QVector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// possible aspect ratios of an image
|
// possible aspect ratios of an image
|
||||||
enum ImageAspect { ImageAspect_Landscape = 0, ImageAspect_Portrait, ImageAspect_Any, ImageAspect_Monitor /* match monitors aspect */ };
|
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
|
// options to consider when displaying an image
|
||||||
struct ImageDisplayOptions
|
struct ImageDisplayOptions
|
||||||
{
|
{
|
||||||
ImageAspect onlyAspect = ImageAspect_Any;
|
ImageAspect onlyAspect = ImageAspect_Any;
|
||||||
bool fitAspectAxisToWindow = false;
|
bool fitAspectAxisToWindow = false;
|
||||||
|
QVector<DisplayTimeWindow> timeWindows;
|
||||||
};
|
};
|
||||||
|
|
||||||
// details of a particular image
|
// details of a particular image
|
||||||
|
|||||||
Reference in New Issue
Block a user