Skip to content

Commit 2b28448

Browse files
committed
battery icon added, keyboard settings revised
1 parent b4c6ada commit 2b28448

10 files changed

+134
-9
lines changed

src/hvl-lightdm-greeter.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@
1717
<file>resources/keyboard.png</file>
1818
<file>resources/restart.png</file>
1919
<file>resources/sleep.png</file>
20+
<file>resources/battery_critical.png</file>
21+
<file>resources/battery_full.png</file>
22+
<file>resources/battery_good.png</file>
23+
<file>resources/battery_low.png</file>
24+
<file>resources/battery_normal.png</file>
2025
</qresource>
2126
</RCC>

src/resources/battery_critical.png

31.6 KB
Loading

src/resources/battery_full.png

3.79 KB
Loading

src/resources/battery_good.png

3.78 KB
Loading

src/resources/battery_low.png

8.54 KB
Loading

src/resources/battery_normal.png

5.99 KB
Loading

src/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Cache : public QSettings
1919
void setLastUser(QString userId) { setValue("last-user", userId); }
2020
QString getLastSession(QString userId) { return value(userId + "/last-session").toString(); }
2121
void setLastSession(QString userId, QString session) { setValue(userId + "/last-session", session); }
22+
void setUserKeyboard(QString keyboard) { setValue("keyboard", keyboard); }
23+
QString getUserKeyboard() { return value("keyboard").toString(); }
2224
};
2325

2426
#define CONFIG_FILE "/usr/share/lightdm/lightdm-hvl-greeter.conf.d/hvl-lightdm-greeter.conf"

src/settingsform.cpp

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <QApplication>
1313
#include <QThread>
1414
#include <QMessageBox>
15+
#include <QDir>
1516

1617
#include "settings.h"
1718
#include "networkdialog.h"
@@ -50,13 +51,13 @@ SettingsForm::SettingsForm(QWidget *parent) :
5051

5152
//ui->sessioncomboBox->setModel(&sessionsModel);
5253

53-
// qDebug() <<"---"<< sessionsModel.rowCount(QModelIndex());
54+
// qDebug() <<"---"<< sessionsModel.rowCount(QModelIndex());
5455

5556
//qm.setPixel(1,qRgba(33, 67, 106, 100));
5657
//QPixmap iconsession(":/resources/login_1_1_bos.png");
5758
QPixmap iconsession(2,30);
5859

59-
// iconsession.fill(qRgba(0x1B, 0x6C, 0xBD, 0xFF));
60+
// iconsession.fill(qRgba(0x1B, 0x6C, 0xBD, 0xFF));
6061
iconsession.fill(QColor(0x1B, 0x6C, 0xBD, 0));
6162

6263
for(i = 0; i< sessionsModel.rowCount(QModelIndex()); i++){
@@ -65,9 +66,9 @@ SettingsForm::SettingsForm(QWidget *parent) :
6566

6667
}
6768

68-
// ui->sessioncomboBox->setItemIcon(1, QIcon(iconsession));
69+
// ui->sessioncomboBox->setItemIcon(1, QIcon(iconsession));
6970
//ui->sessioncomboBox->setItemIcon(0, QIcon(iconsession));
70-
//ui->sessioncomboBox->setItemIcon(-1, QIcon(iconsession));
71+
//ui->sessioncomboBox->setItemIcon(-1, QIcon(iconsession));
7172

7273

7374
user = Cache().getLastUser();
@@ -112,6 +113,7 @@ SettingsForm::SettingsForm(QWidget *parent) :
112113

113114
connect(this, SIGNAL(selectKeyboard(int)), this, SLOT(setKeyboardLayout(int)));
114115

116+
batteryInit();
115117

116118
checkNetwork();
117119
}
@@ -127,12 +129,10 @@ SettingsForm::~SettingsForm()
127129

128130
void SettingsForm::initialize(){
129131

130-
131132
serviceList = Settings().getservices();
132-
133-
getKeyboardLayouts();
134-
ui->kybrdcomboBox->setCurrentText("tr");
135133
connect(ui->kybrdcomboBox, SIGNAL(activated(int)), this, SLOT(setKeyboardLayout(int)));
134+
getKeyboardLayouts();
135+
136136
nwButtonPressed = false;
137137
}
138138

@@ -216,6 +216,8 @@ void SettingsForm::checkNetwork(){
216216
uint ip_count = 0;
217217
int res;
218218

219+
220+
checkBattery();
219221
int runningServices = 0;
220222

221223
ip_string += " IP:\n";
@@ -352,6 +354,7 @@ void SettingsForm::getKeyboardLayouts(){
352354
QString tmpstring;
353355
QString outstr;
354356
int read_size;
357+
QString cachedlayout;
355358

356359
tmpstring = "";
357360

@@ -393,11 +396,29 @@ void SettingsForm::getKeyboardLayouts(){
393396
ui->kybrdcomboBox->addItem(iconx, "Türkçe F", "tr f");
394397
ui->kybrdcomboBox->addItem(iconx, "English Q", "us");
395398

399+
cachedlayout = Cache().getUserKeyboard();
400+
401+
if(!cachedlayout.isEmpty() && !cachedlayout.isNull())
402+
tmpstring = cachedlayout;
396403

397404
qInfo() << "Current Keyboard layout is: " + tmpstring;
398405
emit sendKeyboardLayout(tmpstring);
399406
current_layout = tmpstring;
400407

408+
QByteArray ba;
409+
char *setcommand;
410+
char cmd_array[256];
411+
412+
ba = tmpstring.toLatin1();
413+
414+
setcommand = ba.data();
415+
416+
sprintf(cmd_array, "/usr/bin/setxkbmap %s &",setcommand);
417+
418+
system(cmd_array);
419+
420+
Cache().setUserKeyboard(tmpstring);
421+
401422

402423
if(ui->kybrdcomboBox->findData(tmpstring) == -1){
403424

@@ -434,6 +455,8 @@ void SettingsForm::setKeyboardLayout(int index){
434455

435456
system(cmd_array);
436457

458+
Cache().setUserKeyboard(actionName);
459+
437460
//set onscreen keyboard layout
438461
emit sendKeyboardLayout(actionName);
439462
}
@@ -593,3 +616,70 @@ void SettingsForm::on_sessioncomboBox_activated(int index)
593616
QString sessionname = ui->sessioncomboBox->itemData(index).toString();
594617
emit sendSessionInfo(sessionname);
595618
}
619+
620+
621+
622+
void SettingsForm::batteryInit(void){
623+
624+
QDir pathDir("/sys/class/power_supply/BAT0");
625+
if (pathDir.exists()){
626+
627+
ui->Batterybutton->setToolTipDuration(10000);
628+
batteryExist = true;
629+
ui->Batterybutton->show();
630+
}else{
631+
batteryExist = false;
632+
ui->Batterybutton->hide();
633+
}
634+
}
635+
636+
void SettingsForm::checkBattery(void){
637+
638+
QFile file("/sys/class/power_supply/BAT0/capacity");
639+
int level;
640+
641+
if(batteryExist){
642+
643+
if(!file.open(QIODevice::ReadOnly))
644+
{
645+
return;
646+
}
647+
648+
QTextStream instream(&file);
649+
QString line = instream.readLine();
650+
651+
level = line.toInt();
652+
653+
if(level == 100){
654+
655+
QPixmap iconx(":/resources/battery_full.png");
656+
ui->Batterybutton->setIcon(iconx);
657+
}else if(level <= 15){
658+
659+
QPixmap iconx(":/resources/battery_critical.png");
660+
ui->Batterybutton->setIcon(iconx);
661+
662+
}else if (level <= 35){
663+
664+
QPixmap iconx(":/resources/battery_low.png");
665+
ui->Batterybutton->setIcon(iconx);
666+
667+
}else if(level <= 65){
668+
QPixmap iconx(":/resources/battery_normal.png");
669+
ui->Batterybutton->setIcon(iconx);
670+
671+
672+
}else if(level <= 90){
673+
674+
QPixmap iconx(":/resources/battery_good.png");
675+
ui->Batterybutton->setIcon(iconx);
676+
677+
}
678+
679+
ui->Batterybutton->setToolTip("%" + line);
680+
681+
file.close();
682+
683+
}
684+
685+
}

src/settingsform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public slots:
8787
#define SERVICE_NOT_WORKING -1
8888
#define SERVICE_NOT_EXIST -2
8989
int CheckService(QString Service);
90-
90+
void batteryInit(void);
91+
void checkBattery(void);
9192

9293

9394

@@ -108,6 +109,7 @@ public slots:
108109
bool networkOK;
109110
NetworkDialog *nwDialog;
110111
bool ctrlClicked;
112+
bool batteryExist;
111113

112114

113115

src/settingsform.ui

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,32 @@ QComboBox::down-arrow {
443443
<bool>false</bool>
444444
</property>
445445
</widget>
446+
<widget class="QPushButton" name="Batterybutton">
447+
<property name="enabled">
448+
<bool>false</bool>
449+
</property>
450+
<property name="geometry">
451+
<rect>
452+
<x>50</x>
453+
<y>115</y>
454+
<width>60</width>
455+
<height>45</height>
456+
</rect>
457+
</property>
458+
<property name="text">
459+
<string/>
460+
</property>
461+
<property name="icon">
462+
<iconset resource="hvl-lightdm-greeter.qrc">
463+
<normaloff>:/resources/battery_critical.png</normaloff>:/resources/battery_critical.png</iconset>
464+
</property>
465+
<property name="iconSize">
466+
<size>
467+
<width>35</width>
468+
<height>35</height>
469+
</size>
470+
</property>
471+
</widget>
446472
</widget>
447473
</item>
448474
</layout>

0 commit comments

Comments
 (0)