sorted mode
This commit is contained in:
@@ -91,3 +91,52 @@ std::string ShuffleImageSelector::getNextImage()
|
||||
current_image_shuffle = current_image_shuffle + 1;
|
||||
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;
|
||||
};
|
||||
|
||||
class SortedImageSelector : public ImageSelector
|
||||
{
|
||||
public:
|
||||
SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser);
|
||||
virtual ~SortedImageSelector();
|
||||
virtual std::string getNextImage();
|
||||
|
||||
private:
|
||||
QStringList images;
|
||||
};
|
||||
#endif // IMAGESELECTOR_H
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -27,7 +27,8 @@ int main(int argc, char *argv[])
|
||||
int opt;
|
||||
bool recursive = 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) {
|
||||
case 'p':
|
||||
path = optarg;
|
||||
@@ -48,6 +49,9 @@ int main(int argc, char *argv[])
|
||||
shuffle = true;
|
||||
std::cout << "Shuffle mode is on." << std::endl;
|
||||
break;
|
||||
case 'S':
|
||||
sorted = true;
|
||||
break;
|
||||
default: /* '?' */
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
@@ -72,7 +76,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user