diff options
author | Ken Moore <ken@ixsystems.com> | 2017-08-30 05:22:30 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-08-30 05:22:30 -0400 |
commit | 50384966b759498167365867d49a5df120b1fe26 (patch) | |
tree | 145a68394d8070f7bb0a0938c46cf898987c99d1 /src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h | |
parent | Make sure the context menu label is center-aligned (diff) | |
download | lumina-50384966b759498167365867d49a5df120b1fe26.tar.gz lumina-50384966b759498167365867d49a5df120b1fe26.tar.bz2 lumina-50384966b759498167365867d49a5df120b1fe26.zip |
Clean up the use of the settings files within the entire screensaver system.
Also fix some minor whitespace/alignment in code, and add fallback routines to a couple screensavers which need external files (so they don't crash if nothing was setup or a directory is empty)
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h')
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h index a64144ac..c040c7ac 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h @@ -40,30 +40,27 @@ private: } void chooseImage() { - QString randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; - - //Choose a new file if the chosen one is not an image - while(QImageReader::imageFormat(randomFile).isEmpty()) - randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; - if(scriptLoad){ - QProcess process; - process.start("/home/zwelch/test.sh"); - process.waitForFinished(1000); - QByteArray output = process.readAllStandardOutput(); - qDebug() << output; - pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); - }else{ - pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); - } + QString randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; + if(scriptLoad){ + QProcess process; + process.start("/home/zwelch/test.sh"); + process.waitForFinished(1000); + QByteArray output = process.readAllStandardOutput(); + //qDebug() << output; + pixmap.load(randomFile); + }else{ + pixmap.load(randomFile); + } //If the image is larger than the screen, then shrink the image down to 3/4 it's size (so there's still some bounce) //Scale the pixmap to keep the aspect ratio instead of resizing the label itself - if(pixmap.width() > screenSize.width() or pixmap.height() > screenSize.height()) - pixmap = pixmap.scaled(screenSize*(3.0/4.0), Qt::KeepAspectRatio); + if(pixmap.width() > screenSize.width() or pixmap.height() > screenSize.height()){ + pixmap = pixmap.scaled(screenSize*(3.0/4.0), Qt::KeepAspectRatio); + } - //Set pixmap to the image label - image->setPixmap(pixmap); - image->resize(pixmap.size()); + //Set pixmap to the image label + image->setPixmap(pixmap); + image->resize(pixmap.size()); } private slots: @@ -80,20 +77,25 @@ public: image = new QLabel(parent); screenSize = parent->size(); this->animate = animate; - this->scriptLoad = scriptLoad; - this->scriptPath = scriptPath; - + this->scriptLoad = scriptLoad; + this->scriptPath = scriptPath; + //Generate the list of files in the directory imageFiles = QDir(imagePath).entryList(QDir::Files); - if(imageFiles.empty()) - qDebug() << "Current image file path has no files."; - - //Change some default settings for the image. If scaledContents is false, the image will be cut off if resized - image->setScaledContents(true); - image->setAlignment(Qt::AlignHCenter); - - //Load a random initial image - chooseImage(); + //Ensure all the files are actually images + for(int i=0; i<imageFiles.length(); i++){ + if(QImageReader::imageFormat(imagePath+"/"+imageFiles[i]).isEmpty()){ imageFiles.removeAt(i); i--; } + } + if(imageFiles.empty()){ + qDebug() << "Current image file path has no files."; + image->setText("No image files found:\n"+imagePath); + }else{ + //Change some default settings for the image. If scaledContents is false, the image will be cut off if resized + image->setScaledContents(true); + image->setAlignment(Qt::AlignHCenter); + //Load a random initial image + chooseImage(); + } //Create the animation that moves the image across the screen bounce = new QPropertyAnimation(image, "pos", parent); @@ -132,7 +134,7 @@ public: class ImageAnimation: public BaseAnimGroup{ Q_OBJECT public: - ImageAnimation(QWidget *parent, QSettings *set) : BaseAnimGroup(parent, set){} + ImageAnimation(QWidget *parent) : BaseAnimGroup(parent){} ~ImageAnimation(){ this->stop(); } @@ -140,13 +142,14 @@ public: void LoadAnimations(){ canvas->setStyleSheet("background: black;"); //Load the path of the images from the configuration file (default /usr/local/backgrounds/) - QString imagePath = settings->value("imageSlideshow/path","/usr/local/backgrounds/").toString(); + QString imagePath = readSetting("path", LOS::LuminaShare()+"../wallpapers/").toString(); //Load whether to animate the image (default true) - bool animate = settings->value("imageSlideshow/animate", true).toBool(); - bool scriptLoad = settings->value("imageSlideshow/scriptLoad", true).toBool(); - QString scriptPath; - if(scriptLoad) - scriptPath = settings->value("imageSlideshow/scriptPath", "/usr/local/backgrounds/script.sh").toString(); + bool animate = readSetting("animate", true).toBool(); + bool scriptLoad = readSetting("scriptLoad", true).toBool(); + QString scriptPath; + if(scriptLoad){ + scriptPath = readSetting("scriptPath", "/usr/local/backgrounds/script.sh").toString(); + } ImageSlideshow *tmp = new ImageSlideshow(canvas, imagePath, animate, scriptLoad, scriptPath); this->addAnimation(tmp); } |