sorted mode
This commit is contained in:
@@ -19,6 +19,7 @@ slide [-t rotation_seconds] [-o background_opacity(0..255)] [-b blur_radius] -p
|
|||||||
* `image_folder`: where to search for images (.jpg files)
|
* `image_folder`: where to search for images (.jpg files)
|
||||||
* `-r` for recursive traversal of `image_folder`
|
* `-r` for recursive traversal of `image_folder`
|
||||||
* `-s` for shuffle instead of random image rotation
|
* `-s` for shuffle instead of random image rotation
|
||||||
|
* `-S` for sorted rotation (files ordered by name, first images then subfolders)
|
||||||
* `rotation_seconds(default=30)`: time until next random image is chosen from the given folder
|
* `rotation_seconds(default=30)`: time until next random image is chosen from the given folder
|
||||||
* `background_opacity(default=150)`: opacity of the background filling image between 0 (black background) and 255
|
* `background_opacity(default=150)`: opacity of the background filling image between 0 (black background) and 255
|
||||||
* `blur_radius(default=20)`: blur radius of the background filling image
|
* `blur_radius(default=20)`: blur radius of the background filling image
|
||||||
|
|||||||
@@ -91,3 +91,52 @@ std::string ShuffleImageSelector::getNextImage()
|
|||||||
current_image_shuffle = current_image_shuffle + 1;
|
current_image_shuffle = current_image_shuffle + 1;
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SortedImageSelector::SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser):
|
||||||
|
ImageSelector(pathTraverser),
|
||||||
|
images()
|
||||||
|
{
|
||||||
|
srand (time(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
SortedImageSelector::~SortedImageSelector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const QString& lhs, const QString& rhs) noexcept{
|
||||||
|
if (lhs.count(QLatin1Char('/')) < rhs.count(QLatin1Char('/'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (lhs.count(QLatin1Char('/')) > rhs.count(QLatin1Char('/'))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lhs.toStdString() < rhs.toStdString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SortedImageSelector::getNextImage()
|
||||||
|
{
|
||||||
|
if (images.size() == 0)
|
||||||
|
{
|
||||||
|
images = pathTraverser->getImages();
|
||||||
|
std::sort(images.begin(), images.end());
|
||||||
|
std::cout << "read " << images.size() << " images." << std::endl;
|
||||||
|
for (int i = 0;i <images.size();i++){
|
||||||
|
|
||||||
|
std::cout << images[i].toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (images.size() == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string filename = pathTraverser->getImagePath(images.takeFirst().toStdString());
|
||||||
|
if(!QFileInfo::exists(QString(filename.c_str())))
|
||||||
|
{
|
||||||
|
std::cout << "file not found: " << filename << std::endl;
|
||||||
|
return getNextImage();
|
||||||
|
}
|
||||||
|
std::cout << "updating image: " << filename << std::endl;
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,4 +42,14 @@ private:
|
|||||||
QStringList images;
|
QStringList images;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SortedImageSelector : public ImageSelector
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser);
|
||||||
|
virtual ~SortedImageSelector();
|
||||||
|
virtual std::string getNextImage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList images;
|
||||||
|
};
|
||||||
#endif // IMAGESELECTOR_H
|
#endif // IMAGESELECTOR_H
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@@ -27,7 +27,8 @@ int main(int argc, char *argv[])
|
|||||||
int opt;
|
int opt;
|
||||||
bool recursive = false;
|
bool recursive = false;
|
||||||
bool shuffle = false;
|
bool shuffle = false;
|
||||||
while ((opt = getopt(argc, argv, "b:p:t:o:rs")) != -1) {
|
bool sorted = false;
|
||||||
|
while ((opt = getopt(argc, argv, "b:p:t:o:rsS")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'p':
|
case 'p':
|
||||||
path = optarg;
|
path = optarg;
|
||||||
@@ -48,6 +49,9 @@ int main(int argc, char *argv[])
|
|||||||
shuffle = true;
|
shuffle = true;
|
||||||
std::cout << "Shuffle mode is on." << std::endl;
|
std::cout << "Shuffle mode is on." << std::endl;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
sorted = true;
|
||||||
|
break;
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -72,7 +76,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ImageSelector> selector;
|
std::unique_ptr<ImageSelector> selector;
|
||||||
if (shuffle)
|
if (sorted)
|
||||||
|
{
|
||||||
|
selector = std::unique_ptr<ImageSelector>(new SortedImageSelector(pathTraverser));
|
||||||
|
}
|
||||||
|
else if (shuffle)
|
||||||
{
|
{
|
||||||
selector = std::unique_ptr<ImageSelector>(new ShuffleImageSelector(pathTraverser));
|
selector = std::unique_ptr<ImageSelector>(new ShuffleImageSelector(pathTraverser));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user