diff --git a/README.md b/README.md index 19e2a6b..84d5602 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,21 @@ When using the default or recursive folder mode we support having per folder dis "aspect" : "m", "rotationSeconds" : 300, "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. +* `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 diff --git a/src/appconfig.cpp b/src/appconfig.cpp index d27bf7f..022e8fc 100644 --- a/src/appconfig.cpp +++ b/src/appconfig.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include #include #include @@ -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; } diff --git a/src/imageselector.cpp b/src/imageselector.cpp index 7cdaf2d..22bcd75 100644 --- a/src/imageselector.cpp +++ b/src/imageselector.cpp @@ -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 &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; } diff --git a/src/imageselector.h b/src/imageselector.h index 128f93b..fa46fd2 100644 --- a/src/imageselector.h +++ b/src/imageselector.h @@ -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 &timeWindows); std::unique_ptr pathTraverser; bool debugMode = false; }; diff --git a/src/imagestructs.h b/src/imagestructs.h index 672528c..ce937fc 100644 --- a/src/imagestructs.h +++ b/src/imagestructs.h @@ -1,16 +1,25 @@ #ifndef IMAGESTRUCTS_H #define IMAGESTRUCTS_H +#include +#include #include // 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 timeWindows; }; // details of a particular image