aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2016-04-25 13:08:12 -0400
committerKen Moore <moorekou@gmail.com>2016-04-25 13:08:12 -0400
commited5ecf7ea7a482b4649e66ecb35fbc60af680684 (patch)
treeacc0fa17d228259e847f55c678db9fb0a9b50f0c /src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp
parentMerge branch 'master' of github.com:pcbsd/lumina (diff)
downloadlumina-ed5ecf7ea7a482b4649e66ecb35fbc60af680684.tar.gz
lumina-ed5ecf7ea7a482b4649e66ecb35fbc60af680684.tar.bz2
lumina-ed5ecf7ea7a482b4649e66ecb35fbc60af680684.zip
Rearrange the Lumina source tree quite a bit:
Now the utilites are arranged by category (core, core-utils, desktop-utils), so all the -utils may be excluded by a package system (or turned into separate packages) as needed.
Diffstat (limited to 'src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp')
-rw-r--r--src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp b/src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp
new file mode 100644
index 00000000..267a7cb0
--- /dev/null
+++ b/src-qt5/core/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp
@@ -0,0 +1,91 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2014, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "LSysDashboard.h"
+
+LSysDashboard::LSysDashboard(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){
+ upTimer = new QTimer(this);
+ upTimer->setInterval(10000); //10 second update ping
+ connect(upTimer, SIGNAL(timeout()), this, SLOT(updateIcon()));
+ button = new QToolButton(this);
+ button->setAutoRaise(true);
+ button->setToolButtonStyle(Qt::ToolButtonIconOnly);
+ button->setPopupMode(QToolButton::DelayedPopup); //make sure it runs the update routine first
+ connect(button, SIGNAL(clicked()), this, SLOT(openMenu()));
+ this->layout()->setContentsMargins(0,0,0,0);
+ this->layout()->addWidget(button);
+ menu = new QMenu(this);
+ connect(menu, SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed()));
+ sysmenu = new LSysMenuQuick(this);
+ connect(sysmenu, SIGNAL(CloseMenu()), this, SLOT(closeMenu()) );
+ mact = new QWidgetAction(this);
+ mact->setDefaultWidget(sysmenu);
+ menu->addAction(mact);
+
+ button->setMenu(menu);
+ QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes
+}
+
+LSysDashboard::~LSysDashboard(){
+
+}
+
+// ========================
+// PRIVATE FUNCTIONS
+// ========================
+void LSysDashboard::updateIcon(bool force){
+ //For the visual, show battery state only if important
+ static bool batcharging = false;
+ QPixmap pix;
+ button->setToolTip(tr("System Dashboard"));
+ if(LOS::hasBattery()){
+ int bat = LOS::batteryCharge();
+ bool charging = LOS::batteryIsCharging();
+ //Set the icon as necessary
+ if(charging && !batcharging){
+ //Charging and just plugged in
+ if(bat < 15){ button->setIcon( LXDG::findIcon("battery-charging-low","") ); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(bat < 30){ button->setIcon( LXDG::findIcon("battery-charging-caution","") ); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(force || button->icon().isNull()){ resetIcon(); }
+ }else if(!charging){
+ //Not charging (critical level or just unplugged)
+ if(bat<5){ button->setIcon( LXDG::findIcon("battery-missing","") ); }
+ else if(bat < 15){ button->setIcon( LXDG::findIcon("battery-low","") ); QTimer::singleShot(5000, this, SLOT(resetIcon())); }
+ else if(bat < 30 && batcharging){ button->setIcon( LXDG::findIcon("battery-caution","") ); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(bat < 50 && batcharging){ button->setIcon( LXDG::findIcon("battery-040","")); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(bat < 70 && batcharging){ button->setIcon( LXDG::findIcon("battery-060","")); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(bat < 90 && batcharging){ button->setIcon( LXDG::findIcon("battery-080","")); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(batcharging){ button->setIcon( LXDG::findIcon("battery-100","")); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
+ else if(force || button->icon().isNull()){ resetIcon(); }
+ }else if(force || button->icon().isNull()){
+ //Otherwise just use the default icon
+ resetIcon();
+ }
+ //Save the values for comparison later
+ batcharging = charging;
+ if( !upTimer->isActive() ){ upTimer->start(); } //only use the timer if a battery is present
+
+ // No battery - just use/set the normal icon
+ }else if(force || button->icon().isNull()){
+ resetIcon();
+ if(upTimer->isActive() ){ upTimer->stop(); } //no battery available - no refresh timer needed
+ }
+
+}
+
+void LSysDashboard::resetIcon(){
+ button->setIcon( LXDG::findIcon("dashboard-show",""));
+}
+
+void LSysDashboard::openMenu(){
+ sysmenu->UpdateMenu();
+ button->showMenu();
+}
+
+void LSysDashboard::closeMenu(){
+ menu->hide();
+}
+
bgstack15