aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core')
-rw-r--r--src-qt5/core/lumina-desktop/LSession.cpp58
-rw-r--r--src-qt5/core/lumina-desktop/LSession.h2
-rw-r--r--src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp75
-rw-r--r--src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.h2
-rw-r--r--src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp16
5 files changed, 83 insertions, 70 deletions
diff --git a/src-qt5/core/lumina-desktop/LSession.cpp b/src-qt5/core/lumina-desktop/LSession.cpp
index 5de7850a..1e686e51 100644
--- a/src-qt5/core/lumina-desktop/LSession.cpp
+++ b/src-qt5/core/lumina-desktop/LSession.cpp
@@ -95,6 +95,64 @@ LSession::~LSession(){
}
}
+//Static function so everything can get the same icon name
+QString LSession::batteryIconName(int charge, bool charging){
+ int icon = -1;
+ if (charge > 90) { icon = 4; }
+ else if (charge > 70) { icon = 3; }
+ else if (charge > 20) { icon = 2; }
+ else if (charge > 5) { icon = 1; }
+ else if (charge > 0 ) { icon = 0; }
+ if(charging){ icon = icon+10; }
+ QStringList iconList;
+ switch (icon) {
+ case 0:
+ iconList << "battery-20" << "battery-020" << "battery-empty" << "battery-caution";
+ break;
+ case 1:
+ iconList << "battery-40" << "battery-040" << "battery-low" << "battery-caution";
+ break;
+ case 2:
+ iconList << "battery-60" << "battery-060" << "battery-good";
+ break;
+ case 3:
+ iconList << "battery-80" << "battery-080" << "battery-good";
+ break;
+ case 4:
+ iconList << "battery-100" << "battery-full";
+ break;
+ case 10:
+ iconList << "battery-20-charging" << "battery-020-charging" << "battery-empty-charging" << "battery-caution-charging"
+ << "battery-charging-20" << "battery-charging-020" << "battery-charging-empty" << "battery-charging-caution";
+ break;
+ case 11:
+ iconList << "battery-40-charging" << "battery-040-charging" << "battery-low-charging" << "battery-caution-charging"
+ << "battery-charging-40" << "battery-charging-040" << "battery-charging-low" << "battery-charging-caution";
+ break;
+ case 12:
+ iconList << "battery-60-charging" << "battery-060-charging" << "battery-good-charging"
+ << "battery-charging-60" << "battery-charging-060" << "battery-charging-good";
+ break;
+ case 13:
+ iconList << "battery-80-charging" << "battery-080-charging" << "battery-good-charging"
+ << "battery-charging-80" << "battery-charging-080" << "battery-charging-good";
+ break;
+ case 14:
+ if(charge==100){ iconList << "battery-full-charged"; }
+ iconList << "battery-100-charging" << "battery-full-charging"
+ << "battery-charging-100" << "battery-charging-full";
+ break;
+ default:
+ iconList << "battery-unknown" << "battery-missing";
+ break;
+ }
+ iconList << "battery"; //generic battery icon
+ for(int i=0; i<iconList.length(); i++){
+ if( QIcon::hasThemeIcon(iconList[i]) ){ return iconList[i]; }
+ }
+ return ""; //no icon found
+}
+
void LSession::setupSession(){
//Seed random number generator (if needed)
qsrand( QTime::currentTime().msec() );
diff --git a/src-qt5/core/lumina-desktop/LSession.h b/src-qt5/core/lumina-desktop/LSession.h
index 824eede7..bc36b6b8 100644
--- a/src-qt5/core/lumina-desktop/LSession.h
+++ b/src-qt5/core/lumina-desktop/LSession.h
@@ -53,6 +53,8 @@ public:
LSession(int &argc, char **argv);
~LSession();
+ static QString batteryIconName(int charge, bool charging);
+
static bool checkUserFiles();
//Functions to be called during startup
void setupSession();
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp
index 1870eefb..10ac2507 100644
--- a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp
+++ b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.cpp
@@ -30,72 +30,31 @@ LBattery::~LBattery(){
void LBattery::updateBattery(bool force){
// Get current state of charge
- //QStringList result = LUtils::getCmdOutput("/usr/sbin/apm", QStringList() << "-al");
- int charge = LOS::batteryCharge(); //result.at(1).toInt();
-//qDebug() << "1: " << result.at(0).toInt() << " 2: " << result.at(1).toInt();
- int icon = -1;
- if (charge > 90) { icon = 4; }
- else if (charge > 70) { icon = 3; }
- else if (charge > 20) { icon = 2; }
- else if (charge > 5) { icon = 1; }
- else if (charge > 0 ) { icon = 0; }
- if(LOS::batteryIsCharging()){ icon = icon+10; }
- //icon = icon + result.at(0).toInt() * 10;
- if (icon != iconOld || force) {
- switch (icon) {
- case 0:
- label->setPixmap( LXDG::findIcon("battery-20","battery-caution").pixmap(label->size()) );
- break;
- case 1:
- label->setPixmap( LXDG::findIcon("battery-40", "battery-040").pixmap(label->size()) );
- break;
- case 2:
- label->setPixmap( LXDG::findIcon("battery-60", "battery-060").pixmap(label->size()) );
- break;
- case 3:
- label->setPixmap( LXDG::findIcon("battery-80", "battery-080").pixmap(label->size()) );
- break;
- case 4:
- label->setPixmap( LXDG::findIcon("battery-100", "battery").pixmap(label->size()) );
- break;
- case 10:
- label->setPixmap( LXDG::findIcon("battery-charging-20", "battery-charging-caution").pixmap(label->size()) );
- break;
- case 11:
- label->setPixmap( LXDG::findIcon("battery-charging-40", "battery-charging-040").pixmap(label->size()) );
- break;
- case 12:
- label->setPixmap( LXDG::findIcon("battery-charging-60", "battery-charging-060").pixmap(label->size()) );
- break;
- case 13:
- label->setPixmap( LXDG::findIcon("battery-charging-80", "battery-charging-080").pixmap(label->size()) );
- break;
- case 14:
- label->setPixmap( LXDG::findIcon("battery-charging-100", "battery-charging").pixmap(label->size()) );
- break;
- default:
- label->setPixmap( LXDG::findIcon("battery-unknown", "battery-missing").pixmap(label->size()) );
- break;
- }
- }
- if(icon<iconOld && icon==0){
- //Play some audio warning chime when
- bool playaudio = sessionsettings->value("PlayBatteryLowAudio",true).toBool();
- if( playaudio ){
- QString sfile = LSession::handle()->sessionSettings()->value("audiofiles/batterylow", LOS::LuminaShare()+"low-battery.ogg").toString();
- LSession::handle()->playAudioFile(sfile);
+ int charge = LOS::batteryCharge();
+ bool charging = LOS::batteryIsCharging();
+ QString batt_icon = LSession::batteryIconName(charge, charging);
+ if(iconOld != batt_icon){
+ label->setPixmap( QIcon::fromTheme(batt_icon).pixmap(label->size()) );
+ if(charge <= 5 && !charging){
+ //Play some audio warning chime when
+ bool playaudio = sessionsettings->value("PlayBatteryLowAudio",true).toBool();
+ if( playaudio ){
+ QString sfile = LSession::handle()->sessionSettings()->value("audiofiles/batterylow", "").toString();
+ if(sfile.isEmpty()){ sfile = LOS::LuminaShare()+"low-battery.ogg"; }
+ LSession::handle()->playAudioFile(sfile);
+ }
}
+ iconOld = batt_icon; //save for later
}
- if(icon==0){ label->setStyleSheet("QLabel{ background: red;}"); }
- else if(icon==14 && charge>98){ label->setStyleSheet("QLabel{ background: green;}"); }
+ if(charge<=5 && !charging){ label->setStyleSheet("QLabel{ background: red;}"); }
+ else if(charge>98 && charging){ label->setStyleSheet("QLabel{ background: green;}"); }
else{ label->setStyleSheet("QLabel{ background: transparent;}"); }
- iconOld = icon;
//Now update the display
QString tt;
//Make sure the tooltip can be properly translated as necessary (Ken Moore 5/9/14)
- if(icon > 9 && icon < 15){ tt = QString(tr("%1 % (Charging)")).arg(QString::number(charge)); }
+ if(charging){ tt = QString(tr("%1 % (Charging)")).arg(QString::number(charge)); }
else{ tt = QString( tr("%1 % (%2 Remaining)") ).arg(QString::number(charge), getRemainingTime() ); }
label->setToolTip(tt);
}
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.h b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.h
index 3c23be1c..e2fa411d 100644
--- a/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.h
+++ b/src-qt5/core/lumina-desktop/panel-plugins/battery/LBattery.h
@@ -29,7 +29,7 @@ public:
private:
QTimer *timer;
QLabel *label;
- int iconOld;
+ QString iconOld;
QSettings *sessionsettings;
private slots:
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp
index ee3e0f80..e0ac6639 100644
--- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp
+++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp
@@ -465,24 +465,18 @@ void StartMenu::on_stackedWidget_currentChanged(int val){
if(!ui->label_status_battery->whatsThis().isEmpty()){
//Battery available - update the status button
int charge = LOS::batteryCharge();
- QString TT, ICON;
- if(charge<=5){ ICON="-20"; }
- else if(charge<=20){ ICON="-40"; }
- else if(charge<=70){ ICON="-60"; }
- else if(charge<=90){ ICON="-80"; }
- else{ ICON="-100"; }
- if(LOS::batteryIsCharging()){
- if(charge>=80){ ICON.clear(); } //for charging, there is no suffix to the icon name over 80%
- ICON.prepend("battery-charging");
+ bool charging = LOS::batteryIsCharging();
+ QString batt_icon = LSession::batteryIconName(charge, charging);
+ QString TT;
+ if(charging){
TT = QString(tr("%1% (Plugged In)")).arg(QString::number(charge));
}else{
- ICON.prepend("battery");
int secs = LOS::batterySecondsLeft();
if(secs>1){ TT = QString(tr("%1% (%2 Estimated)")).arg(QString::number(charge), LUtils::SecondsToDisplay(secs)); }
else{ TT = QString(tr("%1% Remaining")).arg(QString::number(charge)); }
}
//qDebug() << " Battery Icon:" << ICON << val << TT
- ui->label_status_battery->setPixmap( LXDG::findIcon(ICON,"").pixmap(ui->tool_goto_apps->iconSize()/2) );
+ ui->label_status_battery->setPixmap( QIcon::fromTheme(batt_icon).pixmap(ui->tool_goto_apps->iconSize()/2) );
ui->label_status_battery->setToolTip(TT);
}
//Network Status
bgstack15