1 #include "pcdm-logindelay.h"
2 #include "ui_pcdm-logindelay.h"
3 
4 #include <QPoint>
5 #include <QDesktopWidget>
6 #include <QFile>
7 
loginDelay(int seconds,QString username,QString wallpaper)8 loginDelay::loginDelay(int seconds, QString username, QString wallpaper) : QDialog(0, Qt::Dialog | Qt::WindowStaysOnTopHint), ui(new Ui::loginDelay){
9   ui->setupUi(this); //load the designer files
10   continueLogin = false; //in case it is closed early somehow
11   backgroundImage = wallpaper; //save for later
12   //Now setup the display
13   ui->label_username->setText(username);
14   ui->progressBar->setRange(0,seconds);
15   ui->progressBar->setValue(0);
16   //Now setup the internal timer
17   delay = new QTimer(this);
18 	delay->setInterval(1000); //1 second intervals
19 	connect(delay, SIGNAL(timeout()), this, SLOT(updateTimer()) );
20   //Now connect the pushbuttons
21   connect(ui->pushCancel, SIGNAL(clicked()), this, SLOT(cancelLogin()) );
22   connect(ui->pushContinue, SIGNAL(clicked()), this, SLOT(startLogin()) );
23   //Center the dialog on the screen
24   fillScreens();
25 }
26 
~loginDelay()27 loginDelay::~loginDelay(){
28   //Also clean up all the background fillers
29   for(int i=0; i<screens.length(); i++){
30     delete screens[i];
31   }
32 }
33 
start()34 void loginDelay::start(){
35   this->show();
36   this->raise();
37   delay->start();
38 }
39 
updateTimer()40 void loginDelay::updateTimer(){
41   ui->progressBar->setValue( ui->progressBar->value()+1 );
42   //Check if the timer reached the end yet
43   if(ui->progressBar->value() >= ui->progressBar->maximum()){
44     delay->stop();
45     startLogin();
46   }
47 }
48 
cancelLogin()49 void loginDelay::cancelLogin(){
50   delay->stop();
51   continueLogin = false;
52   this->close();
53 }
54 
startLogin()55 void loginDelay::startLogin(){
56   delay->stop();
57   continueLogin = true;
58   this->close();
59 }
60 
fillScreens()61 void loginDelay::fillScreens(){
62     //Set a background image on any other available screens
63     QDesktopWidget *DE = QApplication::desktop();
64     screens.clear();
65     //Generate the background style sheet
66     QString tmpIcon = ":/images/backgroundimage.jpg"; //the defult PCDM image (don't load theme for auto-login fallback)
67     QString bgstyle = "QWidget#BGSCREEN{border-image: url(BGIMAGE) stretch;}";
68       //Now apply the default/desired wallpaper image as needed
69       if(backgroundImage.isEmpty() || !QFile::exists(backgroundImage)){ bgstyle.replace("BGIMAGE", tmpIcon);}
70       else{ bgstyle.replace("BGIMAGE", backgroundImage);}
71     //Now apply the background to all the screens
72     for(int i=0; i<DE->screenCount(); i++){
73         //Just show a generic QWidget with the proper background image on every screen
74 	QWidget *screen = new QWidget(0, Qt::Window | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus | Qt::WindowStaysOnBottomHint);
75 	screen->setObjectName("BGSCREEN");
76 	screen->setGeometry( DE->screenGeometry(i) );
77 	screen->setStyleSheet(bgstyle);
78 	screen->show();
79 	screens << screen;
80     }
81     //Now center the login delay widget on the screen
82     QPoint ctr = DE->screenGeometry(0).center();
83     this->move( ctr.x()-(this->width()/2), ctr.y()-(this->height()/2) );
84     QCursor::setPos( ctr );
85 }
86