aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop/src-screensaver/animations/VideoSlideshow.h
blob: 358b4bfb34931d8e4fa4bf95cde5b569bd7fd2b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2015, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#ifndef _LUMINA_DESKTOP_SCREEN_SAVER_VIDEOSLIDESHOW_ANIMATION_H
#define _LUMINA_DESKTOP_SCREEN_SAVER_VIDEOSLIDESHOW_ANIMATION_H

#include "global-includes.h"
#include "BaseAnimGroup.h"

class VideoAnimation: public BaseAnimGroup{
	Q_OBJECT
private:
	QString videoPath, singleVideo;
	QVideoWidget *videoWidget;
	QMediaPlayer *video;
	QStringList videoFiles;
	bool multiple;

private slots:

public:
	VideoAnimation(QWidget *parent) : BaseAnimGroup(parent){}

	~VideoAnimation(){
	  this->stop();
	}

	void LoadAnimations(){
	  canvas->setStyleSheet("background: black;");

	  //Load the path of the videos from the configuration file (default /usr/local/videos/)
	  videoPath = readSetting("path","/usr/local/videos").toString();
    singleVideo = readSetting("videoLocation","").toString();
    multiple = readSetting("multiple",true).toBool();
	  if(!videoPath.endsWith("/")){ videoPath.append("/"); }

	  //Set whether to copy videos on two monitors or play different videos
	  //multimonitor = settings->value("videoSlideshow/multimonitor",true).toBool();

    //Set up the VideoWidget
	  video = new QMediaPlayer(canvas, QMediaPlayer::VideoSurface);
	  videoWidget = new QVideoWidget(canvas);
	  video->setVideoOutput(videoWidget);
	  videoWidget->setGeometry(QRect(QPoint(0,0), canvas->size()));

	  //Generate the list of files in the directory
	  videoFiles = QDir(videoPath).entryList(QDir::Files);
	  if(videoFiles.empty()){
	    qDebug() << "Current video file path has no files:" << videoPath;
	    return;
	  }

    if(singleVideo.isNull())
      singleVideo = videoPath+videoFiles[0];

	  //Loading a random file from a directory
	  QDesktopWidget *dw = new QDesktopWidget();
    QMediaPlaylist *playlist = new QMediaPlaylist();
    if(multiple) {
      for(int i = 0; i < videoFiles.size(); i++){
        playlist->addMedia(QUrl::fromLocalFile(videoPath+videoFiles[i]));
      }
      playlist->shuffle();
    }else{
      playlist->addMedia(QUrl::fromLocalFile(singleVideo));
      playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
    }
	  videoWidget->show();
    if(multiple)
      video->setPlaylist(playlist);

	  //Only play sound for one monitor to prevent messed up audio
	  if(dw->screenNumber(canvas) == 0)
	    video->setVolume(100);
	  else
	    video->setVolume(0);

	  video->play();
	}

};
#endif
bgstack15