split switcher and traverser to prepare for shuffle mode

This commit is contained in:
Manuel
2020-02-13 21:52:17 +01:00
parent 0eb9596095
commit db09dc43f2
8 changed files with 189 additions and 77 deletions

View File

@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "imageselector.h"
#include "imageswitcher.h"
#include "pathtraverser.h"
#include <QApplication>
#include <iostream>
#include <sys/file.h>
@@ -9,6 +10,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory>
void usage(std::string programName) {
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder -r" << std::endl;
@@ -16,46 +18,57 @@ void usage(std::string programName) {
int main(int argc, char *argv[])
{
unsigned int rotationSeconds = 30;
std::string path = "";
unsigned int rotationSeconds = 30;
std::string path = "";
QApplication a(argc, argv);
QApplication a(argc, argv);
MainWindow w;
int opt;
bool recursive = false;
while ((opt = getopt(argc, argv, "b:p:t:o:r")) != -1) {
switch (opt) {
case 'p':
path = optarg;
break;
case 't':
rotationSeconds = atoi(optarg);
break;
case 'b':
w.setBlurRadius(atoi(optarg));
break;
case 'o':
w.setBackgroundOpacity(atoi(optarg));
break;
case 'r':
recursive = true;
break;
default: /* '?' */
usage(argv[0]);
return 1;
}
}
if (path.empty()) {
std::cout << "Error: Path expected." << std::endl;
MainWindow w;
int opt;
bool recursive = false;
while ((opt = getopt(argc, argv, "b:p:t:o:r")) != -1) {
switch (opt) {
case 'p':
path = optarg;
break;
case 't':
rotationSeconds = atoi(optarg);
break;
case 'b':
w.setBlurRadius(atoi(optarg));
break;
case 'o':
w.setBackgroundOpacity(atoi(optarg));
break;
case 'r':
recursive = true;
break;
default: /* '?' */
usage(argv[0]);
return 1;
}
w.show();
}
ImageSelector selector(path, recursive);
ImageSwitcher switcher(w, rotationSeconds * 1000, selector);
switcher.start();
return a.exec();
if (path.empty())
{
std::cout << "Error: Path expected." << std::endl;
usage(argv[0]);
return 1;
}
std::unique_ptr<PathTraverser> pathTraverser;
if (recursive)
{
pathTraverser = std::unique_ptr<PathTraverser>(new RecursivePathTraverser(path));
} else {
pathTraverser = std::unique_ptr<PathTraverser>(new DefaultPathTraverser(path));
}
std::unique_ptr<ImageSelector> selector = std::unique_ptr<ImageSelector>(new DefaultImageSelector(pathTraverser));
w.show();
ImageSwitcher switcher(w, rotationSeconds * 1000, selector);
switcher.start();
return a.exec();
}