From be8f615c21acbea3b338689866c62a1d1bbbe7ca Mon Sep 17 00:00:00 2001 From: Alfred Reynolds Date: Thu, 26 Aug 2021 12:13:09 +1200 Subject: [PATCH] - 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) --- src/appconfig.cpp | 14 ++++++-------- src/appconfig.h | 2 +- src/imageselector.cpp | 33 ++++++++++----------------------- src/imageselector.h | 4 +--- src/imageswitcher.cpp | 4 ++-- src/imageswitcher.h | 4 ++-- src/logger.cpp | 14 ++++++++++++++ src/logger.h | 20 ++++++++++++++++++++ src/main.cpp | 32 +++++++++++++------------------- src/mainwindow.cpp | 24 +++++------------------- src/mainwindow.h | 2 -- src/overlay.cpp | 21 ++++----------------- src/overlay.h | 3 --- src/pathtraverser.cpp | 38 +++++++++++++++----------------------- src/pathtraverser.h | 11 +++++------ src/slide.pro | 10 +++++++--- 16 files changed, 105 insertions(+), 131 deletions(-) create mode 100644 src/logger.cpp create mode 100644 src/logger.h diff --git a/src/appconfig.cpp b/src/appconfig.cpp index 5532da7..b424fee 100644 --- a/src/appconfig.cpp +++ b/src/appconfig.cpp @@ -1,4 +1,5 @@ #include "appconfig.h" +#include "logger.h" #include #include @@ -47,7 +48,7 @@ void SetJSONBool(bool &value, QJsonObject jsonDoc, const char *key) { } } -Config loadConfiguration(const std::string &configFilePath, const Config ¤tConfig, bool debugMode) { +Config loadConfiguration(const std::string &configFilePath, const Config ¤tConfig) { QString jsonFile(configFilePath.c_str()); QDir directory; if(!directory.exists(jsonFile)) @@ -57,10 +58,7 @@ Config loadConfiguration(const std::string &configFilePath, const Config ¤ Config userConfig = currentConfig; - if(debugMode) - { - std::cout << "Found options file: " << jsonFile.toStdString() << std::endl; - } + Log( "Found options file: ", jsonFile.toStdString() ); QString val; QFile file; @@ -222,7 +220,7 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) { return commandLineConfig; } - AppConfig loadedConfig = loadConfiguration(jsonFile.toStdString(), commandLineConfig, commandLineConfig.debugMode); + AppConfig loadedConfig = loadConfiguration(jsonFile.toStdString(), commandLineConfig); QString val; QFile file; @@ -273,12 +271,12 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) { return loadedConfig; } -Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig, bool debugMode) { +Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig) { QDir directory(folderPath.c_str()); QString jsonFile = directory.filePath(QString("options.json")); if(directory.exists(jsonFile)) { - return loadConfiguration(jsonFile.toStdString(), currentConfig, debugMode ); + return loadConfiguration(jsonFile.toStdString(), currentConfig ); } return currentConfig; } \ No newline at end of file diff --git a/src/appconfig.h b/src/appconfig.h index 324a055..c8e7d8e 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -77,7 +77,7 @@ struct AppConfig : public Config { }; AppConfig loadAppConfiguration(const AppConfig &commandLineConfig); -Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig, bool debugMode); +Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig); ImageAspect parseAspectFromString(char aspect); QString getAppConfigFilePath(const std::string &configPath); diff --git a/src/imageselector.cpp b/src/imageselector.cpp index bbe6fc1..a4561b6 100644 --- a/src/imageselector.cpp +++ b/src/imageselector.cpp @@ -1,6 +1,7 @@ #include "imageselector.h" #include "pathtraverser.h" #include "mainwindow.h" +#include "logger.h" #include #include #include @@ -21,11 +22,6 @@ ImageSelector::ImageSelector() {} ImageSelector::~ImageSelector(){} -void ImageSelector::setDebugMode(bool debugModeIn) -{ - debugMode = debugModeIn; -} - int ReadExifTag(ExifData* exifData, ExifTag tag, bool shortRead = false) { int value = -1; @@ -133,12 +129,12 @@ bool ImageSelector::imageInsideTimeWindow(const QVector &time 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) { - 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; @@ -151,19 +147,13 @@ bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails) if(!QFileInfo::exists(QString(imageDetails.filename.c_str()))) { - if(debugMode) - { - std::cout << "file not found: " << imageDetails.filename << std::endl; - } + Log("file not found: ", imageDetails.filename); return false; } if(!imageValidForAspect(imageDetails)) { - if(debugMode) - { - std::cout << "image aspect ratio doesn't match filter '" << imageDetails.options.onlyAspect << "' : " << imageDetails.filename << std::endl; - } + Log("image aspect ratio doesn't match filter '", imageDetails.options.onlyAspect, "' : ", imageDetails.filename); return false; } @@ -217,10 +207,7 @@ const ImageDetails RandomImageSelector::getNextImage(const ImageDisplayOptions & unsigned int RandomImageSelector::selectRandom(const QStringList& images) const { - if(debugMode) - { - std::cout << "images: " << images.size() << std::endl; - } + Log("images: ", images.size()); if (images.size() == 0) { throw std::string("No jpg images found in given folder"); @@ -335,11 +322,11 @@ void SortedImageSelector::reloadImagesIfEmpty() { images = pathTraverser->getImages(); 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 &timeWindows); std::unique_ptr pathTraverser; - bool debugMode = false; }; class RandomImageSelector : public ImageSelector diff --git a/src/imageswitcher.cpp b/src/imageswitcher.cpp index 4347af2..e0b2fa0 100644 --- a/src/imageswitcher.cpp +++ b/src/imageswitcher.cpp @@ -23,7 +23,7 @@ void ImageSwitcher::updateImage() { if(reloadConfigIfNeeded) { - reloadConfigIfNeeded(window, this, selector.get()); + reloadConfigIfNeeded(window, this); } ImageDetails imageDetails = selector->getNextImage(window.getBaseOptions()); if (imageDetails.filename == "") @@ -52,7 +52,7 @@ void ImageSwitcher::scheduleImageUpdate() QTimer::singleShot(100, this, SLOT(updateImage())); } -void ImageSwitcher::setConfigFileReloader(std::function reloadConfigIfNeededIn) +void ImageSwitcher::setConfigFileReloader(std::function reloadConfigIfNeededIn) { reloadConfigIfNeeded = reloadConfigIfNeededIn; } diff --git a/src/imageswitcher.h b/src/imageswitcher.h index ea00e49..4f501d7 100644 --- a/src/imageswitcher.h +++ b/src/imageswitcher.h @@ -16,7 +16,7 @@ public: ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::unique_ptr& selector); void start(); void scheduleImageUpdate(); - void setConfigFileReloader(std::function reloadConfigIfNeededIn); + void setConfigFileReloader(std::function reloadConfigIfNeededIn); void setRotationTime(unsigned int timeoutMsec); void setImageSelector(std::unique_ptr& selector); @@ -29,7 +29,7 @@ private: QTimer timer; const unsigned int timeoutNoContent = 5 * 1000; // 5 sec QTimer timerNoContent; - std::function reloadConfigIfNeeded; + std::function reloadConfigIfNeeded; }; #endif // IMAGESWITCHER_H diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 0000000..95bd309 --- /dev/null +++ b/src/logger.cpp @@ -0,0 +1,14 @@ +#include "logger.h" + + +static bool shouldLog = false; + +void SetupLogger(bool shouldLogIn) +{ + shouldLog = shouldLogIn; +} + +bool ShouldLog() +{ + return shouldLog; +} \ No newline at end of file diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 0000000..630411b --- /dev/null +++ b/src/logger.h @@ -0,0 +1,20 @@ +#ifndef LOGGER_H +#define LOGGER_H +#include +#include +#include + +void SetupLogger(bool shouldLog); +bool ShouldLog(); + +template +void Log(Args&& ...args) { + if(!ShouldLog()) + return; + std::ostringstream stream; + (stream << ... << std::forward(args)) << std::endl; + std::cout << stream.str(); +} + + +#endif // LOGGER_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index da5a306..3c55790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "pathtraverser.h" #include "overlay.h" #include "appconfig.h" +#include "logger.h" #include #include @@ -123,30 +124,28 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig) w.setBackgroundOpacity(appConfig.backgroundOpacity); } std::unique_ptr o = std::unique_ptr(new Overlay(appConfig.overlay)); - o->setDebugMode(appConfig.debugMode); - w.setDebugMode(appConfig.debugMode); w.setOverlay(o); w.setBaseOptions(appConfig.baseDisplayOptions); } -std::unique_ptr GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn, const bool debugMode) +std::unique_ptr GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn) { std::unique_ptr pathTraverser; if (!path.rssFeedURL.empty()) { - pathTraverser = std::unique_ptr(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn, debugMode)); + pathTraverser = std::unique_ptr(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn)); } else if (!path.imageList.empty()) { - pathTraverser = std::unique_ptr(new ImageListPathTraverser(path.imageList, debugMode)); + pathTraverser = std::unique_ptr(new ImageListPathTraverser(path.imageList)); } else if (path.recursive) { - pathTraverser = std::unique_ptr(new RecursivePathTraverser(path.path, debugMode)); + pathTraverser = std::unique_ptr(new RecursivePathTraverser(path.path)); } else { - pathTraverser = std::unique_ptr(new DefaultPathTraverser(path.path, debugMode)); + pathTraverser = std::unique_ptr(new DefaultPathTraverser(path.path)); } std::unique_ptr selector; @@ -170,14 +169,14 @@ std::unique_ptr GetSelectorForApp(const AppConfig& appConfig, QNe { if(appConfig.paths.count()==1) { - return GetSelectorForConfig(appConfig.paths[0], networkManagerIn, appConfig.debugMode); + return GetSelectorForConfig(appConfig.paths[0], networkManagerIn); } else { std::unique_ptr listSelector(new ListImageSelector()); 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); } // new things @@ -186,7 +185,7 @@ std::unique_ptr 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); QDir directory; @@ -207,7 +206,6 @@ void ReloadConfigIfNeeded(AppConfig &appConfig, MainWindow &w, ImageSwitcher *sw switcher->setImageSelector(selector); } - selector->setDebugMode(appConfig.debugMode); switcher->setRotationTime(appConfig.rotationSeconds * 1000); } } @@ -231,12 +229,9 @@ int main(int argc, char *argv[]) usage(argv[0]); return 1; } - - if(appConfig.debugMode) - { - std::cout << "Rotation Time: " << appConfig.rotationSeconds << std::endl; - std::cout << "Overlay input: " << appConfig.overlay << std::endl; - } + SetupLogger(appConfig.debugMode); + Log( "Rotation Time: ", appConfig.rotationSeconds ); + Log( "Overlay input: ", appConfig.overlay ); QNetworkAccessManager webCtrl; @@ -246,11 +241,10 @@ int main(int argc, char *argv[]) w.show(); std::unique_ptr selector = GetSelectorForApp(appConfig, webCtrl); - selector->setDebugMode(appConfig.debugMode); ImageSwitcher switcher(w, appConfig.rotationSeconds * 1000, selector); w.setImageSwitcher(&switcher); - std::function reloader = [&appConfig, &webCtrl](MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector) { ReloadConfigIfNeeded(appConfig, w, switcher, selector, webCtrl); }; + std::function reloader = [&appConfig, &webCtrl](MainWindow &w, ImageSwitcher *switcher) { ReloadConfigIfNeeded(appConfig, w, switcher, webCtrl); }; switcher.setConfigFileReloader(reloader); switcher.start(); return a.exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3f1323b..267545f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,6 +2,7 @@ #include "overlay.h" #include "ui_mainwindow.h" #include "imageswitcher.h" +#include "logger.h" #include #include #include @@ -130,10 +131,7 @@ void MainWindow::checkWindowSize() QSize screenSize = screen->geometry().size(); if(size() != screenSize) { - if(debugMode) - { - std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl; - } + Log("Resizing Window", screenSize.width(), "," , screenSize.height() ); setFixedSize(screenSize); updateImage(true); } @@ -144,10 +142,7 @@ void MainWindow::checkWindowSize() ImageAspect newAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait; if (newAspect != baseImageOptions.onlyAspect) { - if(debugMode) - { - std::cout << "Changing image orientation to " << newAspect << std::endl; - } + Log("Changing image orientation to ", newAspect); baseImageOptions.onlyAspect = newAspect; currentImage.filename = ""; warn("Monitor aspect changed, updating image..."); @@ -237,10 +232,7 @@ void MainWindow::updateImage(bool immediately) p.load( currentImage.filename.c_str() ); } - if(debugMode) - { - std::cout << "size:" << p.width() << "x" << p.height() << "(window:" << width() << "," << height() << ")" << std::endl; - } + Log("size:", p.width(), "x", p.height(), "(window:", width(), ",", height(), ")"); QPixmap rotated = getRotatedPixmap(p); 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->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); - if (debugMode) + if (ShouldLog()) { // draw a thumbnail version of the source image in the bottom left, to check for cropping issues 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) { - //std::cout << "text: " << text.toStdString() << " margin: " << margin << " fontsize: " << fontsize<< std::endl; QPainter pt(&image); pt.setPen(QPen(Qt::white)); pt.setFont(QFont("Sans", fontsize, QFont::Bold)); @@ -426,11 +417,6 @@ void MainWindow::setImageSwitcher(ImageSwitcher *switcherIn) switcher = switcherIn; } -void MainWindow::setDebugMode(bool debugModeIn) -{ - debugMode = debugModeIn; -} - const ImageDisplayOptions &MainWindow::getBaseOptions() { return baseImageOptions; diff --git a/src/mainwindow.h b/src/mainwindow.h index 3d569d7..7538b35 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,7 +30,6 @@ public: void setBackgroundOpacity(unsigned int opacity); void warn(std::string text); void setOverlay(std::unique_ptr &overlay); - void setDebugMode(bool debugModeIn); void setBaseOptions(const ImageDisplayOptions &baseOptionsIn); const ImageDisplayOptions &getBaseOptions(); void setImageSwitcher(ImageSwitcher *switcherIn); @@ -50,7 +49,6 @@ private: QByteArray downloadedData; QNetworkAccessManager *networkManager = nullptr; QNetworkReply *pendingReply = nullptr; - bool debugMode = false; QSize lastScreenSize = {0,0}; std::unique_ptr overlay; diff --git a/src/overlay.cpp b/src/overlay.cpp index f32c560..313d09f 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -1,4 +1,5 @@ #include "overlay.h" +#include "logger.h" #include #include #include @@ -19,11 +20,6 @@ Overlay::Overlay(const std::string overlayInput): Overlay::~Overlay() {} -void Overlay::setDebugMode(const bool debugModeIn) -{ - debugMode = debugModeIn; -} - void Overlay::parseInput() { QString str = QString(overlayInput.c_str()); QStringList corners = str.split(QLatin1Char(';')); @@ -55,10 +51,7 @@ void Overlay::parseInput() { QString Overlay::getTemplate(QStringList components){ if (components.size()>3) { - if(debugMode) - { - std::cout << "template: " << components[3].toStdString() << std::endl; - } + Log("template: ", components[3].toStdString()); return components[3]; } return ""; @@ -66,10 +59,7 @@ QString Overlay::getTemplate(QStringList components){ int Overlay::getMargin(QStringList components){ if (components.size()>1) { - if(debugMode) - { - std::cout << "margin: " << components[1].toStdString() << std::endl; - } + Log("margin: ", components[1].toStdString()); int num = components[1].toInt(); if (num > 0) { return num; @@ -81,10 +71,7 @@ int Overlay::getMargin(QStringList components){ int Overlay::getFontsize(QStringList components){ if (components.size()>2) { - if(debugMode) - { - std::cout << "fontsize: " << components[2].toStdString() << std::endl; - } + Log("fontsize: ", components[2].toStdString()); int num = components[2].toInt(); if (num > 0) { return num; diff --git a/src/overlay.h b/src/overlay.h index 5837cba..d11f8f2 100644 --- a/src/overlay.h +++ b/src/overlay.h @@ -27,13 +27,10 @@ class Overlay int getMarginBottomRight(); int getFontsizeBottomRight(); - void setDebugMode(const bool debugModeIn); - private: const std::string overlayInput; int margin; int fontsize; - bool debugMode = false; QString topLeftTemplate; QString topRightTemplate; diff --git a/src/pathtraverser.cpp b/src/pathtraverser.cpp index 048c37a..3ad6fc4 100644 --- a/src/pathtraverser.cpp +++ b/src/pathtraverser.cpp @@ -1,6 +1,7 @@ #include "pathtraverser.h" #include "mainwindow.h" #include "appconfig.h" +#include "logger.h" #include #include @@ -11,8 +12,8 @@ #include /* srand, rand */ -PathTraverser::PathTraverser(const std::string path, bool debugModeIn): - path(path), debugMode(debugModeIn) +PathTraverser::PathTraverser(const std::string path): + path(path) {} PathTraverser::~PathTraverser() {} @@ -28,11 +29,11 @@ ImageDisplayOptions PathTraverser::LoadOptionsForDirectory(const std::string &di { Config baseConfig; baseConfig.baseDisplayOptions = baseOptions; - return getConfigurationForFolder(directoryPath, baseConfig, debugMode).baseDisplayOptions; + return getConfigurationForFolder(directoryPath, baseConfig).baseDisplayOptions; } -RecursivePathTraverser::RecursivePathTraverser(const std::string path,bool debugMode): - PathTraverser(path,debugMode) +RecursivePathTraverser::RecursivePathTraverser(const std::string path): + PathTraverser(path) {} RecursivePathTraverser::~RecursivePathTraverser() {} @@ -61,8 +62,8 @@ ImageDisplayOptions RecursivePathTraverser::UpdateOptionsForImage(const std::str return LoadOptionsForDirectory(d.absolutePath().toStdString(), baseOptions); } -DefaultPathTraverser::DefaultPathTraverser(const std::string path,bool debugMode): - PathTraverser(path,debugMode), +DefaultPathTraverser::DefaultPathTraverser(const std::string path): + PathTraverser(path), directory(path.c_str()) {} @@ -85,8 +86,8 @@ ImageDisplayOptions DefaultPathTraverser::UpdateOptionsForImage(const std::strin return LoadOptionsForDirectory(directory.absolutePath().toStdString(), baseOptions); } -ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString,bool debugMode): - PathTraverser("",debugMode) +ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString): + PathTraverser("") { QString str = QString(imageListString.c_str()); imageList = str.split(QLatin1Char(',')); @@ -114,8 +115,8 @@ ImageDisplayOptions ImageListPathTraverser::UpdateOptionsForImage(const std::str } -RedditRSSFeedPathTraverser::RedditRSSFeedPathTraverser(const std::string& rssFeedURLIn, QNetworkAccessManager& networkManager, bool debugModeIn) : - PathTraverser("",debugModeIn), rssFeedURL(rssFeedURLIn), webCtrl(networkManager) +RedditRSSFeedPathTraverser::RedditRSSFeedPathTraverser(const std::string& rssFeedURLIn, QNetworkAccessManager& networkManager) : + PathTraverser(""), rssFeedURL(rssFeedURLIn), webCtrl(networkManager) { connect( &webCtrl, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*))); RequestRSSFeed(); @@ -131,10 +132,7 @@ void RedditRSSFeedPathTraverser::RequestRSSFeed() { pendingReply->abort(); } - if (debugMode) - { - std::cout << "Requesting RSS feed:" << rssFeedURL << std::endl; - } + Log("Requesting RSS feed:", rssFeedURL); rssRequestedTime = QDateTime::currentDateTime(); QNetworkRequest request(QUrl(rssFeedURL.c_str())); pendingReply = webCtrl.get(request); @@ -159,10 +157,7 @@ void RedditRSSFeedPathTraverser::fileDownloaded(QNetworkReply* netReply) netReply->deleteLater(); if (!vt.isNull()) { - if (debugMode) - { - std::cout << "Redirected to:" << vt.toUrl().toString().toStdString() << std::endl; - } + Log("Redirected to:", vt.toUrl().toString().toStdString()); webCtrl.get(QNetworkRequest(vt.toUrl())); } else @@ -171,10 +166,7 @@ void RedditRSSFeedPathTraverser::fileDownloaded(QNetworkReply* netReply) QString error; if (!doc.setContent(str, false, &error)) { - if (debugMode) - { - std::cout << "Failed to load page:" << error.toStdString() << std::endl; - } + Log("Failed to load page:", error.toStdString()); } else { diff --git a/src/pathtraverser.h b/src/pathtraverser.h index 9dc6425..ef65ead 100644 --- a/src/pathtraverser.h +++ b/src/pathtraverser.h @@ -15,7 +15,7 @@ class MainWindow; class PathTraverser { public: - PathTraverser(const std::string path, bool debugModeIn); + PathTraverser(const std::string path); virtual ~PathTraverser(); virtual QStringList getImages() const = 0; virtual const std::string getImagePath(const std::string image) const = 0; @@ -23,7 +23,6 @@ class PathTraverser protected: const std::string path; - bool debugMode = false; QStringList getImageFormats() const; ImageDisplayOptions LoadOptionsForDirectory(const std::string &directoryPath, const ImageDisplayOptions &baseOptions) const; }; @@ -31,7 +30,7 @@ class PathTraverser class RecursivePathTraverser : public PathTraverser { public: - RecursivePathTraverser(const std::string path, bool debugModeIn); + RecursivePathTraverser(const std::string path); virtual ~RecursivePathTraverser(); QStringList getImages() const; virtual const std::string getImagePath(const std::string image) const; @@ -41,7 +40,7 @@ class RecursivePathTraverser : public PathTraverser class DefaultPathTraverser : public PathTraverser { public: - DefaultPathTraverser(const std::string path, bool debugModeIn); + DefaultPathTraverser(const std::string path); virtual ~DefaultPathTraverser(); QStringList getImages() const; virtual const std::string getImagePath(const std::string image) const; @@ -53,7 +52,7 @@ class DefaultPathTraverser : public PathTraverser class ImageListPathTraverser : public PathTraverser { public: - ImageListPathTraverser(const std::string &imageListString, bool debugModeIn); + ImageListPathTraverser(const std::string &imageListString); virtual ~ImageListPathTraverser(); QStringList getImages() const; virtual const std::string getImagePath(const std::string image) const; @@ -66,7 +65,7 @@ class RedditRSSFeedPathTraverser: public QObject, public PathTraverser { Q_OBJECT public: - RedditRSSFeedPathTraverser(const std::string& rSSFeedURL,QNetworkAccessManager& networkManager, bool debugModeIn); + RedditRSSFeedPathTraverser(const std::string& rSSFeedURL,QNetworkAccessManager& networkManager); virtual ~RedditRSSFeedPathTraverser(); virtual QStringList getImages() const; diff --git a/src/slide.pro b/src/slide.pro index db060ef..de08fca 100644 --- a/src/slide.pro +++ b/src/slide.pro @@ -5,7 +5,9 @@ #------------------------------------------------- QT += core gui network xml -CONFIG += qt debug +CONFIG += qt +CONFIG += debug +CONFIG += c++1z greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -35,7 +37,8 @@ SOURCES += \ pathtraverser.cpp \ overlay.cpp \ imageselector.cpp \ - appconfig.cpp + appconfig.cpp \ + logger.cpp HEADERS += \ mainwindow.h \ @@ -44,7 +47,8 @@ HEADERS += \ overlay.h \ imageswitcher.h \ imagestructs.h \ - appconfig.h + appconfig.h \ + logger.h FORMS += \ mainwindow.ui