aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp
blob: 7c098887a59932b952062a612f11f183bcfd0fbe (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
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2015, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================

#include "SSBaseWidget.h"

#define DEBUG 0

// ========
//   PUBLIC
// ========
SSBaseWidget::SSBaseWidget(QWidget *parent) : QQuickView(parent->windowHandle()){
  this->setObjectName("LuminaBaseSSWidget");
  this->setResizeMode(QQuickView::SizeRootObjectToView);
  this->setColor(QColor("black")); //default color for the view
  this->setCursor(Qt::BlankCursor);
  plugType="none";
  restartTimer = new QTimer(this);
    restartTimer->setInterval( DesktopSettings::instance()->value(DesktopSettings::ScreenSaver, "globals/plugin_time_seconds", 120).toInt() * 1000);
    restartTimer->setSingleShot(true);
  connect(restartTimer, SIGNAL(timeout()), this, SLOT(startPainting()) );
}

SSBaseWidget::~SSBaseWidget(){
}

void SSBaseWidget::setPlugin(QString plug){
  plugType = plug.toLower();
}

// =============
//  PUBLIC SLOTS
// =============
void SSBaseWidget::startPainting(){
  //free up any old animation instance
  stopPainting();
  //If a random plugin - grab one of the known plugins
  if(plugType=="random"){
    QList<SSPlugin> valid = SSPluginSystem::findAllPlugins();
    if(!valid.isEmpty()){ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin
  }else if(plugType!="none"){
    cplug = SSPluginSystem::findPlugin(plugType);
  }
  if(DEBUG){ qDebug() << " - Screen Saver:" << plugType << cplug.scriptURL() << cplug.isValid(); }
  if(cplug.isValid()){
    this->setSource( cplug.scriptURL() );
    if(plugType=="random"){ restartTimer->start(); }
  }

}

void SSBaseWidget::stopPainting(){
  if(!this->source().isEmpty()){
    this->setSource(QUrl());
    cplug = SSPlugin(); //empty structure
  }
  if(restartTimer->isActive()){ restartTimer->stop(); }
}
bgstack15