- Add a new Log() function to replace ad-hoc std::cout calls wrapped in debugMode checks

- Remove debugMode from classes that don't need it (i.e all of them)
This commit is contained in:
Alfred Reynolds
2021-08-26 12:13:09 +12:00
parent 833e7ef915
commit be8f615c21
16 changed files with 105 additions and 131 deletions

View File

@@ -1,4 +1,5 @@
#include "appconfig.h" #include "appconfig.h"
#include "logger.h"
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
@@ -47,7 +48,7 @@ void SetJSONBool(bool &value, QJsonObject jsonDoc, const char *key) {
} }
} }
Config loadConfiguration(const std::string &configFilePath, const Config &currentConfig, bool debugMode) { Config loadConfiguration(const std::string &configFilePath, const Config &currentConfig) {
QString jsonFile(configFilePath.c_str()); QString jsonFile(configFilePath.c_str());
QDir directory; QDir directory;
if(!directory.exists(jsonFile)) if(!directory.exists(jsonFile))
@@ -57,10 +58,7 @@ Config loadConfiguration(const std::string &configFilePath, const Config &curren
Config userConfig = currentConfig; Config userConfig = currentConfig;
if(debugMode) Log( "Found options file: ", jsonFile.toStdString() );
{
std::cout << "Found options file: " << jsonFile.toStdString() << std::endl;
}
QString val; QString val;
QFile file; QFile file;
@@ -222,7 +220,7 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
return commandLineConfig; return commandLineConfig;
} }
AppConfig loadedConfig = loadConfiguration(jsonFile.toStdString(), commandLineConfig, commandLineConfig.debugMode); AppConfig loadedConfig = loadConfiguration(jsonFile.toStdString(), commandLineConfig);
QString val; QString val;
QFile file; QFile file;
@@ -273,12 +271,12 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
return loadedConfig; return loadedConfig;
} }
Config getConfigurationForFolder(const std::string &folderPath, const Config &currentConfig, bool debugMode) { Config getConfigurationForFolder(const std::string &folderPath, const Config &currentConfig) {
QDir directory(folderPath.c_str()); QDir directory(folderPath.c_str());
QString jsonFile = directory.filePath(QString("options.json")); QString jsonFile = directory.filePath(QString("options.json"));
if(directory.exists(jsonFile)) if(directory.exists(jsonFile))
{ {
return loadConfiguration(jsonFile.toStdString(), currentConfig, debugMode ); return loadConfiguration(jsonFile.toStdString(), currentConfig );
} }
return currentConfig; return currentConfig;
} }

View File

@@ -77,7 +77,7 @@ struct AppConfig : public Config {
}; };
AppConfig loadAppConfiguration(const AppConfig &commandLineConfig); AppConfig loadAppConfiguration(const AppConfig &commandLineConfig);
Config getConfigurationForFolder(const std::string &folderPath, const Config &currentConfig, bool debugMode); Config getConfigurationForFolder(const std::string &folderPath, const Config &currentConfig);
ImageAspect parseAspectFromString(char aspect); ImageAspect parseAspectFromString(char aspect);
QString getAppConfigFilePath(const std::string &configPath); QString getAppConfigFilePath(const std::string &configPath);

View File

@@ -1,6 +1,7 @@
#include "imageselector.h" #include "imageselector.h"
#include "pathtraverser.h" #include "pathtraverser.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "logger.h"
#include <QDirIterator> #include <QDirIterator>
#include <QTimer> #include <QTimer>
#include <QApplication> #include <QApplication>
@@ -21,11 +22,6 @@ ImageSelector::ImageSelector() {}
ImageSelector::~ImageSelector(){} ImageSelector::~ImageSelector(){}
void ImageSelector::setDebugMode(bool debugModeIn)
{
debugMode = debugModeIn;
}
int ReadExifTag(ExifData* exifData, ExifTag tag, bool shortRead = false) int ReadExifTag(ExifData* exifData, ExifTag tag, bool shortRead = false)
{ {
int value = -1; int value = -1;
@@ -133,12 +129,12 @@ bool ImageSelector::imageInsideTimeWindow(const QVector<DisplayTimeWindow> &time
return true; return true;
} }
} }
if(debugMode && timeWindows.count() > 0) if(ShouldLog() && timeWindows.count() > 0)
{ {
std::cout << "image display time outside windows: " << std::endl; Log( "image display time outside window: ");
for(auto &timeWindow : timeWindows) for(auto &timeWindow : timeWindows)
{ {
std::cout << "time: " << timeWindow.startDisplay.toString().toStdString() << "-" << timeWindow.endDisplay.toString().toStdString() << std::endl; Log("time: ", timeWindow.startDisplay.toString().toStdString(), "-", timeWindow.endDisplay.toString().toStdString());
} }
} }
return false; return false;
@@ -151,19 +147,13 @@ bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
if(!QFileInfo::exists(QString(imageDetails.filename.c_str()))) if(!QFileInfo::exists(QString(imageDetails.filename.c_str())))
{ {
if(debugMode) Log("file not found: ", imageDetails.filename);
{
std::cout << "file not found: " << imageDetails.filename << std::endl;
}
return false; return false;
} }
if(!imageValidForAspect(imageDetails)) if(!imageValidForAspect(imageDetails))
{ {
if(debugMode) Log("image aspect ratio doesn't match filter '", imageDetails.options.onlyAspect, "' : ", imageDetails.filename);
{
std::cout << "image aspect ratio doesn't match filter '" << imageDetails.options.onlyAspect << "' : " << imageDetails.filename << std::endl;
}
return false; return false;
} }
@@ -217,10 +207,7 @@ const ImageDetails RandomImageSelector::getNextImage(const ImageDisplayOptions &
unsigned int RandomImageSelector::selectRandom(const QStringList& images) const unsigned int RandomImageSelector::selectRandom(const QStringList& images) const
{ {
if(debugMode) Log("images: ", images.size());
{
std::cout << "images: " << images.size() << std::endl;
}
if (images.size() == 0) if (images.size() == 0)
{ {
throw std::string("No jpg images found in given folder"); throw std::string("No jpg images found in given folder");
@@ -335,11 +322,11 @@ void SortedImageSelector::reloadImagesIfEmpty()
{ {
images = pathTraverser->getImages(); images = pathTraverser->getImages();
std::sort(images.begin(), images.end()); std::sort(images.begin(), images.end());
if(debugMode) if(ShouldLog())
{ {
std::cout << "read " << images.size() << " images." << std::endl; Log( "read ", images.size(), " images.");
for (int i = 0;i <images.size();i++){ for (int i = 0;i <images.size();i++){
std::cout << images[i].toStdString() << std::endl; Log(images[i].toStdString());
} }
} }
} }

View File

@@ -17,15 +17,13 @@ public:
ImageSelector(); // use case for when you don't own your own traverser ImageSelector(); // use case for when you don't own your own traverser
virtual ~ImageSelector(); virtual ~ImageSelector();
virtual const ImageDetails getNextImage(const ImageDisplayOptions &baseOptions) = 0; virtual const ImageDetails getNextImage(const ImageDisplayOptions &baseOptions) = 0;
void setDebugMode(bool debugModeIn);
protected: 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); bool imageInsideTimeWindow(const QVector<DisplayTimeWindow> &timeWindows);
std::unique_ptr<PathTraverser> pathTraverser; std::unique_ptr<PathTraverser> pathTraverser;
bool debugMode = false;
}; };
class RandomImageSelector : public ImageSelector class RandomImageSelector : public ImageSelector

View File

@@ -23,7 +23,7 @@ void ImageSwitcher::updateImage()
{ {
if(reloadConfigIfNeeded) if(reloadConfigIfNeeded)
{ {
reloadConfigIfNeeded(window, this, selector.get()); reloadConfigIfNeeded(window, this);
} }
ImageDetails imageDetails = selector->getNextImage(window.getBaseOptions()); ImageDetails imageDetails = selector->getNextImage(window.getBaseOptions());
if (imageDetails.filename == "") if (imageDetails.filename == "")
@@ -52,7 +52,7 @@ void ImageSwitcher::scheduleImageUpdate()
QTimer::singleShot(100, this, SLOT(updateImage())); QTimer::singleShot(100, this, SLOT(updateImage()));
} }
void ImageSwitcher::setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector)> reloadConfigIfNeededIn) void ImageSwitcher::setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloadConfigIfNeededIn)
{ {
reloadConfigIfNeeded = reloadConfigIfNeededIn; reloadConfigIfNeeded = reloadConfigIfNeededIn;
} }

View File

@@ -16,7 +16,7 @@ public:
ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::unique_ptr<ImageSelector>& selector); ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::unique_ptr<ImageSelector>& selector);
void start(); void start();
void scheduleImageUpdate(); void scheduleImageUpdate();
void setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector)> reloadConfigIfNeededIn); void setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloadConfigIfNeededIn);
void setRotationTime(unsigned int timeoutMsec); void setRotationTime(unsigned int timeoutMsec);
void setImageSelector(std::unique_ptr<ImageSelector>& selector); void setImageSelector(std::unique_ptr<ImageSelector>& selector);
@@ -29,7 +29,7 @@ private:
QTimer timer; QTimer timer;
const unsigned int timeoutNoContent = 5 * 1000; // 5 sec const unsigned int timeoutNoContent = 5 * 1000; // 5 sec
QTimer timerNoContent; QTimer timerNoContent;
std::function<void(MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector)> reloadConfigIfNeeded; std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloadConfigIfNeeded;
}; };
#endif // IMAGESWITCHER_H #endif // IMAGESWITCHER_H

14
src/logger.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include "logger.h"
static bool shouldLog = false;
void SetupLogger(bool shouldLogIn)
{
shouldLog = shouldLogIn;
}
bool ShouldLog()
{
return shouldLog;
}

20
src/logger.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <iostream>
#include <string_view>
#include <sstream>
void SetupLogger(bool shouldLog);
bool ShouldLog();
template <typename ...Args>
void Log(Args&& ...args) {
if(!ShouldLog())
return;
std::ostringstream stream;
(stream << ... << std::forward<Args>(args)) << std::endl;
std::cout << stream.str();
}
#endif // LOGGER_H

View File

@@ -4,6 +4,7 @@
#include "pathtraverser.h" #include "pathtraverser.h"
#include "overlay.h" #include "overlay.h"
#include "appconfig.h" #include "appconfig.h"
#include "logger.h"
#include <QApplication> #include <QApplication>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
@@ -123,30 +124,28 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig)
w.setBackgroundOpacity(appConfig.backgroundOpacity); w.setBackgroundOpacity(appConfig.backgroundOpacity);
} }
std::unique_ptr<Overlay> o = std::unique_ptr<Overlay>(new Overlay(appConfig.overlay)); std::unique_ptr<Overlay> o = std::unique_ptr<Overlay>(new Overlay(appConfig.overlay));
o->setDebugMode(appConfig.debugMode);
w.setDebugMode(appConfig.debugMode);
w.setOverlay(o); w.setOverlay(o);
w.setBaseOptions(appConfig.baseDisplayOptions); w.setBaseOptions(appConfig.baseDisplayOptions);
} }
std::unique_ptr<ImageSelector> GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn, const bool debugMode) std::unique_ptr<ImageSelector> GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn)
{ {
std::unique_ptr<PathTraverser> pathTraverser; std::unique_ptr<PathTraverser> pathTraverser;
if (!path.rssFeedURL.empty()) if (!path.rssFeedURL.empty())
{ {
pathTraverser = std::unique_ptr<PathTraverser>(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn, debugMode)); pathTraverser = std::unique_ptr<PathTraverser>(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn));
} }
else if (!path.imageList.empty()) else if (!path.imageList.empty())
{ {
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList, debugMode)); pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList));
} }
else if (path.recursive) else if (path.recursive)
{ {
pathTraverser = std::unique_ptr<PathTraverser>(new RecursivePathTraverser(path.path, debugMode)); pathTraverser = std::unique_ptr<PathTraverser>(new RecursivePathTraverser(path.path));
} }
else else
{ {
pathTraverser = std::unique_ptr<PathTraverser>(new DefaultPathTraverser(path.path, debugMode)); pathTraverser = std::unique_ptr<PathTraverser>(new DefaultPathTraverser(path.path));
} }
std::unique_ptr<ImageSelector> selector; std::unique_ptr<ImageSelector> selector;
@@ -170,14 +169,14 @@ std::unique_ptr<ImageSelector> GetSelectorForApp(const AppConfig& appConfig, QNe
{ {
if(appConfig.paths.count()==1) if(appConfig.paths.count()==1)
{ {
return GetSelectorForConfig(appConfig.paths[0], networkManagerIn, appConfig.debugMode); return GetSelectorForConfig(appConfig.paths[0], networkManagerIn);
} }
else else
{ {
std::unique_ptr<ListImageSelector> listSelector(new ListImageSelector()); std::unique_ptr<ListImageSelector> listSelector(new ListImageSelector());
for(const auto &path : appConfig.paths) for(const auto &path : appConfig.paths)
{ {
auto selector = GetSelectorForConfig(path, networkManagerIn, appConfig.debugMode); auto selector = GetSelectorForConfig(path, networkManagerIn);
listSelector->AddImageSelector(selector, path.exclusive, path.baseDisplayOptions); listSelector->AddImageSelector(selector, path.exclusive, path.baseDisplayOptions);
} }
// new things // new things
@@ -186,7 +185,7 @@ std::unique_ptr<ImageSelector> GetSelectorForApp(const AppConfig& appConfig, QNe
} }
void ReloadConfigIfNeeded(AppConfig &appConfig, MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector, QNetworkAccessManager& networkManager) void ReloadConfigIfNeeded(AppConfig &appConfig, MainWindow &w, ImageSwitcher *switcher, QNetworkAccessManager& networkManager)
{ {
QString jsonFile = getAppConfigFilePath(appConfig.configPath); QString jsonFile = getAppConfigFilePath(appConfig.configPath);
QDir directory; QDir directory;
@@ -207,7 +206,6 @@ void ReloadConfigIfNeeded(AppConfig &appConfig, MainWindow &w, ImageSwitcher *sw
switcher->setImageSelector(selector); switcher->setImageSelector(selector);
} }
selector->setDebugMode(appConfig.debugMode);
switcher->setRotationTime(appConfig.rotationSeconds * 1000); switcher->setRotationTime(appConfig.rotationSeconds * 1000);
} }
} }
@@ -231,12 +229,9 @@ int main(int argc, char *argv[])
usage(argv[0]); usage(argv[0]);
return 1; return 1;
} }
SetupLogger(appConfig.debugMode);
if(appConfig.debugMode) Log( "Rotation Time: ", appConfig.rotationSeconds );
{ Log( "Overlay input: ", appConfig.overlay );
std::cout << "Rotation Time: " << appConfig.rotationSeconds << std::endl;
std::cout << "Overlay input: " << appConfig.overlay << std::endl;
}
QNetworkAccessManager webCtrl; QNetworkAccessManager webCtrl;
@@ -246,11 +241,10 @@ int main(int argc, char *argv[])
w.show(); w.show();
std::unique_ptr<ImageSelector> selector = GetSelectorForApp(appConfig, webCtrl); std::unique_ptr<ImageSelector> selector = GetSelectorForApp(appConfig, webCtrl);
selector->setDebugMode(appConfig.debugMode);
ImageSwitcher switcher(w, appConfig.rotationSeconds * 1000, selector); ImageSwitcher switcher(w, appConfig.rotationSeconds * 1000, selector);
w.setImageSwitcher(&switcher); w.setImageSwitcher(&switcher);
std::function<void(MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector)> reloader = [&appConfig, &webCtrl](MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector) { ReloadConfigIfNeeded(appConfig, w, switcher, selector, webCtrl); }; std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloader = [&appConfig, &webCtrl](MainWindow &w, ImageSwitcher *switcher) { ReloadConfigIfNeeded(appConfig, w, switcher, webCtrl); };
switcher.setConfigFileReloader(reloader); switcher.setConfigFileReloader(reloader);
switcher.start(); switcher.start();
return a.exec(); return a.exec();

View File

@@ -2,6 +2,7 @@
#include "overlay.h" #include "overlay.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "imageswitcher.h" #include "imageswitcher.h"
#include "logger.h"
#include <QLabel> #include <QLabel>
#include <QPixmap> #include <QPixmap>
#include <QBitmap> #include <QBitmap>
@@ -130,10 +131,7 @@ void MainWindow::checkWindowSize()
QSize screenSize = screen->geometry().size(); QSize screenSize = screen->geometry().size();
if(size() != screenSize) if(size() != screenSize)
{ {
if(debugMode) Log("Resizing Window", screenSize.width(), "," , screenSize.height() );
{
std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl;
}
setFixedSize(screenSize); setFixedSize(screenSize);
updateImage(true); updateImage(true);
} }
@@ -144,10 +142,7 @@ void MainWindow::checkWindowSize()
ImageAspect newAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait; ImageAspect newAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait;
if (newAspect != baseImageOptions.onlyAspect) if (newAspect != baseImageOptions.onlyAspect)
{ {
if(debugMode) Log("Changing image orientation to ", newAspect);
{
std::cout << "Changing image orientation to " << newAspect << std::endl;
}
baseImageOptions.onlyAspect = newAspect; baseImageOptions.onlyAspect = newAspect;
currentImage.filename = ""; currentImage.filename = "";
warn("Monitor aspect changed, updating image..."); warn("Monitor aspect changed, updating image...");
@@ -237,10 +232,7 @@ void MainWindow::updateImage(bool immediately)
p.load( currentImage.filename.c_str() ); p.load( currentImage.filename.c_str() );
} }
if(debugMode) Log("size:", p.width(), "x", p.height(), "(window:", width(), ",", height(), ")");
{
std::cout << "size:" << p.width() << "x" << p.height() << "(window:" << width() << "," << height() << ")" << std::endl;
}
QPixmap rotated = getRotatedPixmap(p); QPixmap rotated = getRotatedPixmap(p);
QPixmap scaled = getScaledPixmap(rotated); QPixmap scaled = getScaledPixmap(rotated);
@@ -253,7 +245,7 @@ void MainWindow::updateImage(bool immediately)
drawText(background, overlay->getMarginTopRight(), overlay->getFontsizeTopRight(), overlay->getRenderedTopRight(currentImage.filename).c_str(), Qt::AlignTop|Qt::AlignRight); drawText(background, overlay->getMarginTopRight(), overlay->getFontsizeTopRight(), overlay->getRenderedTopRight(currentImage.filename).c_str(), Qt::AlignTop|Qt::AlignRight);
drawText(background, overlay->getMarginBottomLeft(), overlay->getFontsizeBottomLeft(), overlay->getRenderedBottomLeft(currentImage.filename).c_str(), Qt::AlignBottom|Qt::AlignLeft); drawText(background, overlay->getMarginBottomLeft(), overlay->getFontsizeBottomLeft(), overlay->getRenderedBottomLeft(currentImage.filename).c_str(), Qt::AlignBottom|Qt::AlignLeft);
drawText(background, overlay->getMarginBottomRight(), overlay->getFontsizeBottomRight(), overlay->getRenderedBottomRight(currentImage.filename).c_str(), Qt::AlignBottom|Qt::AlignRight); drawText(background, overlay->getMarginBottomRight(), overlay->getFontsizeBottomRight(), overlay->getRenderedBottomRight(currentImage.filename).c_str(), Qt::AlignBottom|Qt::AlignRight);
if (debugMode) if (ShouldLog())
{ {
// draw a thumbnail version of the source image in the bottom left, to check for cropping issues // draw a thumbnail version of the source image in the bottom left, to check for cropping issues
QPainter pt(&background); QPainter pt(&background);
@@ -288,7 +280,6 @@ void MainWindow::updateImage(bool immediately)
} }
void MainWindow::drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment) { void MainWindow::drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment) {
//std::cout << "text: " << text.toStdString() << " margin: " << margin << " fontsize: " << fontsize<< std::endl;
QPainter pt(&image); QPainter pt(&image);
pt.setPen(QPen(Qt::white)); pt.setPen(QPen(Qt::white));
pt.setFont(QFont("Sans", fontsize, QFont::Bold)); pt.setFont(QFont("Sans", fontsize, QFont::Bold));
@@ -426,11 +417,6 @@ void MainWindow::setImageSwitcher(ImageSwitcher *switcherIn)
switcher = switcherIn; switcher = switcherIn;
} }
void MainWindow::setDebugMode(bool debugModeIn)
{
debugMode = debugModeIn;
}
const ImageDisplayOptions &MainWindow::getBaseOptions() const ImageDisplayOptions &MainWindow::getBaseOptions()
{ {
return baseImageOptions; return baseImageOptions;

View File

@@ -30,7 +30,6 @@ public:
void setBackgroundOpacity(unsigned int opacity); void setBackgroundOpacity(unsigned int opacity);
void warn(std::string text); void warn(std::string text);
void setOverlay(std::unique_ptr<Overlay> &overlay); void setOverlay(std::unique_ptr<Overlay> &overlay);
void setDebugMode(bool debugModeIn);
void setBaseOptions(const ImageDisplayOptions &baseOptionsIn); void setBaseOptions(const ImageDisplayOptions &baseOptionsIn);
const ImageDisplayOptions &getBaseOptions(); const ImageDisplayOptions &getBaseOptions();
void setImageSwitcher(ImageSwitcher *switcherIn); void setImageSwitcher(ImageSwitcher *switcherIn);
@@ -50,7 +49,6 @@ private:
QByteArray downloadedData; QByteArray downloadedData;
QNetworkAccessManager *networkManager = nullptr; QNetworkAccessManager *networkManager = nullptr;
QNetworkReply *pendingReply = nullptr; QNetworkReply *pendingReply = nullptr;
bool debugMode = false;
QSize lastScreenSize = {0,0}; QSize lastScreenSize = {0,0};
std::unique_ptr<Overlay> overlay; std::unique_ptr<Overlay> overlay;

View File

@@ -1,4 +1,5 @@
#include "overlay.h" #include "overlay.h"
#include "logger.h"
#include <QString> #include <QString>
#include <QDateTime> #include <QDateTime>
#include <libexif/exif-data.h> #include <libexif/exif-data.h>
@@ -19,11 +20,6 @@ Overlay::Overlay(const std::string overlayInput):
Overlay::~Overlay() {} Overlay::~Overlay() {}
void Overlay::setDebugMode(const bool debugModeIn)
{
debugMode = debugModeIn;
}
void Overlay::parseInput() { void Overlay::parseInput() {
QString str = QString(overlayInput.c_str()); QString str = QString(overlayInput.c_str());
QStringList corners = str.split(QLatin1Char(';')); QStringList corners = str.split(QLatin1Char(';'));
@@ -55,10 +51,7 @@ void Overlay::parseInput() {
QString Overlay::getTemplate(QStringList components){ QString Overlay::getTemplate(QStringList components){
if (components.size()>3) { if (components.size()>3) {
if(debugMode) Log("template: ", components[3].toStdString());
{
std::cout << "template: " << components[3].toStdString() << std::endl;
}
return components[3]; return components[3];
} }
return ""; return "";
@@ -66,10 +59,7 @@ QString Overlay::getTemplate(QStringList components){
int Overlay::getMargin(QStringList components){ int Overlay::getMargin(QStringList components){
if (components.size()>1) { if (components.size()>1) {
if(debugMode) Log("margin: ", components[1].toStdString());
{
std::cout << "margin: " << components[1].toStdString() << std::endl;
}
int num = components[1].toInt(); int num = components[1].toInt();
if (num > 0) { if (num > 0) {
return num; return num;
@@ -81,10 +71,7 @@ int Overlay::getMargin(QStringList components){
int Overlay::getFontsize(QStringList components){ int Overlay::getFontsize(QStringList components){
if (components.size()>2) { if (components.size()>2) {
if(debugMode) Log("fontsize: ", components[2].toStdString());
{
std::cout << "fontsize: " << components[2].toStdString() << std::endl;
}
int num = components[2].toInt(); int num = components[2].toInt();
if (num > 0) { if (num > 0) {
return num; return num;

View File

@@ -27,13 +27,10 @@ class Overlay
int getMarginBottomRight(); int getMarginBottomRight();
int getFontsizeBottomRight(); int getFontsizeBottomRight();
void setDebugMode(const bool debugModeIn);
private: private:
const std::string overlayInput; const std::string overlayInput;
int margin; int margin;
int fontsize; int fontsize;
bool debugMode = false;
QString topLeftTemplate; QString topLeftTemplate;
QString topRightTemplate; QString topRightTemplate;

View File

@@ -1,6 +1,7 @@
#include "pathtraverser.h" #include "pathtraverser.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "appconfig.h" #include "appconfig.h"
#include "logger.h"
#include <QDirIterator> #include <QDirIterator>
#include <QDir> #include <QDir>
@@ -11,8 +12,8 @@
#include <stdlib.h> /* srand, rand */ #include <stdlib.h> /* srand, rand */
PathTraverser::PathTraverser(const std::string path, bool debugModeIn): PathTraverser::PathTraverser(const std::string path):
path(path), debugMode(debugModeIn) path(path)
{} {}
PathTraverser::~PathTraverser() {} PathTraverser::~PathTraverser() {}
@@ -28,11 +29,11 @@ ImageDisplayOptions PathTraverser::LoadOptionsForDirectory(const std::string &di
{ {
Config baseConfig; Config baseConfig;
baseConfig.baseDisplayOptions = baseOptions; baseConfig.baseDisplayOptions = baseOptions;
return getConfigurationForFolder(directoryPath, baseConfig, debugMode).baseDisplayOptions; return getConfigurationForFolder(directoryPath, baseConfig).baseDisplayOptions;
} }
RecursivePathTraverser::RecursivePathTraverser(const std::string path,bool debugMode): RecursivePathTraverser::RecursivePathTraverser(const std::string path):
PathTraverser(path,debugMode) PathTraverser(path)
{} {}
RecursivePathTraverser::~RecursivePathTraverser() {} RecursivePathTraverser::~RecursivePathTraverser() {}
@@ -61,8 +62,8 @@ ImageDisplayOptions RecursivePathTraverser::UpdateOptionsForImage(const std::str
return LoadOptionsForDirectory(d.absolutePath().toStdString(), baseOptions); return LoadOptionsForDirectory(d.absolutePath().toStdString(), baseOptions);
} }
DefaultPathTraverser::DefaultPathTraverser(const std::string path,bool debugMode): DefaultPathTraverser::DefaultPathTraverser(const std::string path):
PathTraverser(path,debugMode), PathTraverser(path),
directory(path.c_str()) directory(path.c_str())
{} {}
@@ -85,8 +86,8 @@ ImageDisplayOptions DefaultPathTraverser::UpdateOptionsForImage(const std::strin
return LoadOptionsForDirectory(directory.absolutePath().toStdString(), baseOptions); return LoadOptionsForDirectory(directory.absolutePath().toStdString(), baseOptions);
} }
ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString,bool debugMode): ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString):
PathTraverser("",debugMode) PathTraverser("")
{ {
QString str = QString(imageListString.c_str()); QString str = QString(imageListString.c_str());
imageList = str.split(QLatin1Char(',')); imageList = str.split(QLatin1Char(','));
@@ -114,8 +115,8 @@ ImageDisplayOptions ImageListPathTraverser::UpdateOptionsForImage(const std::str
} }
RedditRSSFeedPathTraverser::RedditRSSFeedPathTraverser(const std::string& rssFeedURLIn, QNetworkAccessManager& networkManager, bool debugModeIn) : RedditRSSFeedPathTraverser::RedditRSSFeedPathTraverser(const std::string& rssFeedURLIn, QNetworkAccessManager& networkManager) :
PathTraverser("",debugModeIn), rssFeedURL(rssFeedURLIn), webCtrl(networkManager) PathTraverser(""), rssFeedURL(rssFeedURLIn), webCtrl(networkManager)
{ {
connect( &webCtrl, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*))); connect( &webCtrl, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*)));
RequestRSSFeed(); RequestRSSFeed();
@@ -131,10 +132,7 @@ void RedditRSSFeedPathTraverser::RequestRSSFeed()
{ {
pendingReply->abort(); pendingReply->abort();
} }
if (debugMode) Log("Requesting RSS feed:", rssFeedURL);
{
std::cout << "Requesting RSS feed:" << rssFeedURL << std::endl;
}
rssRequestedTime = QDateTime::currentDateTime(); rssRequestedTime = QDateTime::currentDateTime();
QNetworkRequest request(QUrl(rssFeedURL.c_str())); QNetworkRequest request(QUrl(rssFeedURL.c_str()));
pendingReply = webCtrl.get(request); pendingReply = webCtrl.get(request);
@@ -159,10 +157,7 @@ void RedditRSSFeedPathTraverser::fileDownloaded(QNetworkReply* netReply)
netReply->deleteLater(); netReply->deleteLater();
if (!vt.isNull()) if (!vt.isNull())
{ {
if (debugMode) Log("Redirected to:", vt.toUrl().toString().toStdString());
{
std::cout << "Redirected to:" << vt.toUrl().toString().toStdString() << std::endl;
}
webCtrl.get(QNetworkRequest(vt.toUrl())); webCtrl.get(QNetworkRequest(vt.toUrl()));
} }
else else
@@ -171,10 +166,7 @@ void RedditRSSFeedPathTraverser::fileDownloaded(QNetworkReply* netReply)
QString error; QString error;
if (!doc.setContent(str, false, &error)) if (!doc.setContent(str, false, &error))
{ {
if (debugMode) Log("Failed to load page:", error.toStdString());
{
std::cout << "Failed to load page:" << error.toStdString() << std::endl;
}
} }
else else
{ {

View File

@@ -15,7 +15,7 @@ class MainWindow;
class PathTraverser class PathTraverser
{ {
public: public:
PathTraverser(const std::string path, bool debugModeIn); PathTraverser(const std::string path);
virtual ~PathTraverser(); virtual ~PathTraverser();
virtual QStringList getImages() const = 0; virtual QStringList getImages() const = 0;
virtual const std::string getImagePath(const std::string image) const = 0; virtual const std::string getImagePath(const std::string image) const = 0;
@@ -23,7 +23,6 @@ class PathTraverser
protected: protected:
const std::string path; const std::string path;
bool debugMode = false;
QStringList getImageFormats() const; QStringList getImageFormats() const;
ImageDisplayOptions LoadOptionsForDirectory(const std::string &directoryPath, const ImageDisplayOptions &baseOptions) const; ImageDisplayOptions LoadOptionsForDirectory(const std::string &directoryPath, const ImageDisplayOptions &baseOptions) const;
}; };
@@ -31,7 +30,7 @@ class PathTraverser
class RecursivePathTraverser : public PathTraverser class RecursivePathTraverser : public PathTraverser
{ {
public: public:
RecursivePathTraverser(const std::string path, bool debugModeIn); RecursivePathTraverser(const std::string path);
virtual ~RecursivePathTraverser(); virtual ~RecursivePathTraverser();
QStringList getImages() const; QStringList getImages() const;
virtual const std::string getImagePath(const std::string image) const; virtual const std::string getImagePath(const std::string image) const;
@@ -41,7 +40,7 @@ class RecursivePathTraverser : public PathTraverser
class DefaultPathTraverser : public PathTraverser class DefaultPathTraverser : public PathTraverser
{ {
public: public:
DefaultPathTraverser(const std::string path, bool debugModeIn); DefaultPathTraverser(const std::string path);
virtual ~DefaultPathTraverser(); virtual ~DefaultPathTraverser();
QStringList getImages() const; QStringList getImages() const;
virtual const std::string getImagePath(const std::string image) const; virtual const std::string getImagePath(const std::string image) const;
@@ -53,7 +52,7 @@ class DefaultPathTraverser : public PathTraverser
class ImageListPathTraverser : public PathTraverser class ImageListPathTraverser : public PathTraverser
{ {
public: public:
ImageListPathTraverser(const std::string &imageListString, bool debugModeIn); ImageListPathTraverser(const std::string &imageListString);
virtual ~ImageListPathTraverser(); virtual ~ImageListPathTraverser();
QStringList getImages() const; QStringList getImages() const;
virtual const std::string getImagePath(const std::string image) const; virtual const std::string getImagePath(const std::string image) const;
@@ -66,7 +65,7 @@ class RedditRSSFeedPathTraverser: public QObject, public PathTraverser
{ {
Q_OBJECT Q_OBJECT
public: public:
RedditRSSFeedPathTraverser(const std::string& rSSFeedURL,QNetworkAccessManager& networkManager, bool debugModeIn); RedditRSSFeedPathTraverser(const std::string& rSSFeedURL,QNetworkAccessManager& networkManager);
virtual ~RedditRSSFeedPathTraverser(); virtual ~RedditRSSFeedPathTraverser();
virtual QStringList getImages() const; virtual QStringList getImages() const;

View File

@@ -5,7 +5,9 @@
#------------------------------------------------- #-------------------------------------------------
QT += core gui network xml QT += core gui network xml
CONFIG += qt debug CONFIG += qt
CONFIG += debug
CONFIG += c++1z
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@@ -35,7 +37,8 @@ SOURCES += \
pathtraverser.cpp \ pathtraverser.cpp \
overlay.cpp \ overlay.cpp \
imageselector.cpp \ imageselector.cpp \
appconfig.cpp appconfig.cpp \
logger.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
@@ -44,7 +47,8 @@ HEADERS += \
overlay.h \ overlay.h \
imageswitcher.h \ imageswitcher.h \
imagestructs.h \ imagestructs.h \
appconfig.h appconfig.h \
logger.h
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui