aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/panel-plugins/systemdashboard/LSysDashboard.cpp
blob: 8f663b0f2ccfa046527561491c4b32b72c291488 (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
86
87
88
89
90
//===========================================
//  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);
  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<1){ button->setIcon( LXDG::findIcon("battery-missing","") ); QTimer::singleShot(5000, this, SLOT(resetIcon()));}
	else if(bat < 15){ button->setIcon( LXDG::findIcon("battery-low","") ); QTimer::singleShot(5000, this, SLOT(resetIcon())); }
	else if(bat < 30){ 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