diff options
author | Ken Moore <ken@ixsystems.com> | 2017-01-04 16:44:55 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-01-04 16:44:55 -0500 |
commit | 25b2e77aa2395ba9143683a5ce1a27b99ee7a211 (patch) | |
tree | bbd732bb72689b9b46dfc619d3d0e1748f7e435b /src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp | |
parent | Tag version 1.2.1 on the master branch in preparation for new changes from th... (diff) | |
download | lumina-25b2e77aa2395ba9143683a5ce1a27b99ee7a211.tar.gz lumina-25b2e77aa2395ba9143683a5ce1a27b99ee7a211.tar.bz2 lumina-25b2e77aa2395ba9143683a5ce1a27b99ee7a211.zip |
Create a new "lumina-desktop-unified" core subproject (DO NOT USE)
This is just a staging area for the merging of the desktop, window manager, etc.. into a single unified application. It is highly fragmented right now and will not build *AT ALL* for a while.
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp')
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp b/src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp new file mode 100644 index 00000000..1c0b59a5 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-DE/SystemWindow.cpp @@ -0,0 +1,104 @@ +#include "SystemWindow.h" +#include "ui_SystemWindow.h" + +#include "LSession.h" +#include <LuminaOS.h> +#include <QPoint> +#include <QCursor> +#include <QDebug> +#include <QProcess> +#include <QDesktopWidget> +#include <QMessageBox> + +SystemWindow::SystemWindow() : QDialog(), ui(new Ui::SystemWindow){ + ui->setupUi(this); //load the designer file + //Setup the window flags + this->setWindowFlags( Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + //Setup the icons based on the current theme + ui->tool_logout->setIcon( LXDG::findIcon("system-log-out","") ); + ui->tool_restart->setIcon( LXDG::findIcon("system-reboot","") ); + ui->tool_shutdown->setIcon( LXDG::findIcon("system-shutdown","") ); + ui->tool_suspend->setIcon( LXDG::findIcon("system-suspend","") ); + ui->push_cancel->setIcon( LXDG::findIcon("dialog-cancel","") ); + ui->push_lock->setIcon( LXDG::findIcon("system-lock-screen","") ); + //Connect the signals/slots + connect(ui->tool_logout, SIGNAL(clicked()), this, SLOT(sysLogout()) ); + connect(ui->tool_restart, SIGNAL(clicked()), this, SLOT(sysRestart()) ); + connect(ui->tool_shutdown, SIGNAL(clicked()), this, SLOT(sysShutdown()) ); + connect(ui->tool_suspend, SIGNAL(clicked()), this, SLOT(sysSuspend()) ); + connect(ui->push_cancel, SIGNAL(clicked()), this, SLOT(sysCancel()) ); + connect(ui->push_lock, SIGNAL(clicked()), this, SLOT(sysLock()) ); + //Disable buttons if necessary + updateWindow(); + ui->tool_suspend->setVisible(LOS::systemCanSuspend()); //does not change with time - just do a single check + connect(QApplication::instance(), SIGNAL(LocaleChanged()), this, SLOT(updateWindow()) ); + connect(QApplication::instance(), SIGNAL(IconThemeChanged()), this, SLOT(updateWindow()) ); +} + +SystemWindow::~SystemWindow(){ + +} + +void SystemWindow::updateWindow(){ + //Disable the shutdown/restart buttons if necessary + ui->retranslateUi(this); + bool ok = LOS::userHasShutdownAccess(); + ui->tool_restart->setEnabled(ok); + ui->tool_shutdown->setEnabled(ok); + //Center this window on the current screen + QPoint center = QApplication::desktop()->screenGeometry(QCursor::pos()).center(); //get the center of the current screen + this->move(center.x() - this->width()/2, center.y() - this->height()/2); +} + +bool SystemWindow::promptAboutUpdates(bool &skip){ + QString pending = LOS::systemPendingUpdates(); + if(pending.isEmpty()){ skip = false; } //continue without skip + else{ + QMessageBox dlg(QMessageBox::Question, tr("Apply Updates?"), tr("You have system updates waiting to be applied! Do you wish to install them now?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, this); + dlg.setDetailedText(pending); + dlg.setDefaultButton(QMessageBox::Yes); + dlg.show(); + int ret = dlg.exec(); + if(ret == QMessageBox::Cancel){ return false; } //do not continue + else{ skip = (ret==QMessageBox::No); } + } + return true; +} + +void SystemWindow::sysLogout(){ + this->close(); + LSession::processEvents(); + QTimer::singleShot(0, LSession::handle(), SLOT(StartLogout()) ); +} + +void SystemWindow::sysRestart(){ + bool skip = false; + if(!promptAboutUpdates(skip)){ this->close(); return; } //cancelled + this->close(); + LSession::processEvents(); + LSession::handle()->StartReboot(skip); +} + +void SystemWindow::sysShutdown(){ + bool skip = false; + if(!promptAboutUpdates(skip)){ this->close(); return; } //cancelled + this->close(); + LSession::processEvents(); + LSession::handle()->StartShutdown(skip); +} + +void SystemWindow::sysSuspend(){ + this->hide(); + LSession::processEvents(); + //Make sure to lock the system first (otherwise anybody can access it again) + LUtils::runCmd("xscreensaver-command -lock"); + //Now suspend the system + LOS::systemSuspend(); +} + +void SystemWindow::sysLock(){ + this->hide(); + LSession::processEvents(); + qDebug() << "Locking the desktop..."; + QProcess::startDetached("xscreensaver-command -lock"); +} |