12
12
#include < QApplication>
13
13
#include < QThread>
14
14
#include < QMessageBox>
15
+ #include < QDir>
15
16
16
17
#include " settings.h"
17
18
#include " networkdialog.h"
@@ -50,13 +51,13 @@ SettingsForm::SettingsForm(QWidget *parent) :
50
51
51
52
// ui->sessioncomboBox->setModel(&sessionsModel);
52
53
53
- // qDebug() <<"---"<< sessionsModel.rowCount(QModelIndex());
54
+ // qDebug() <<"---"<< sessionsModel.rowCount(QModelIndex());
54
55
55
56
// qm.setPixel(1,qRgba(33, 67, 106, 100));
56
57
// QPixmap iconsession(":/resources/login_1_1_bos.png");
57
58
QPixmap iconsession (2 ,30 );
58
59
59
- // iconsession.fill(qRgba(0x1B, 0x6C, 0xBD, 0xFF));
60
+ // iconsession.fill(qRgba(0x1B, 0x6C, 0xBD, 0xFF));
60
61
iconsession.fill (QColor (0x1B , 0x6C , 0xBD , 0 ));
61
62
62
63
for (i = 0 ; i< sessionsModel.rowCount (QModelIndex ()); i++){
@@ -65,9 +66,9 @@ SettingsForm::SettingsForm(QWidget *parent) :
65
66
66
67
}
67
68
68
- // ui->sessioncomboBox->setItemIcon(1, QIcon(iconsession));
69
+ // ui->sessioncomboBox->setItemIcon(1, QIcon(iconsession));
69
70
// ui->sessioncomboBox->setItemIcon(0, QIcon(iconsession));
70
- // ui->sessioncomboBox->setItemIcon(-1, QIcon(iconsession));
71
+ // ui->sessioncomboBox->setItemIcon(-1, QIcon(iconsession));
71
72
72
73
73
74
user = Cache ().getLastUser ();
@@ -112,6 +113,7 @@ SettingsForm::SettingsForm(QWidget *parent) :
112
113
113
114
connect (this , SIGNAL (selectKeyboard (int )), this , SLOT (setKeyboardLayout (int )));
114
115
116
+ batteryInit ();
115
117
116
118
checkNetwork ();
117
119
}
@@ -127,12 +129,10 @@ SettingsForm::~SettingsForm()
127
129
128
130
void SettingsForm::initialize (){
129
131
130
-
131
132
serviceList = Settings ().getservices ();
132
-
133
- getKeyboardLayouts ();
134
- ui->kybrdcomboBox ->setCurrentText (" tr" );
135
133
connect (ui->kybrdcomboBox , SIGNAL (activated (int )), this , SLOT (setKeyboardLayout (int )));
134
+ getKeyboardLayouts ();
135
+
136
136
nwButtonPressed = false ;
137
137
}
138
138
@@ -216,6 +216,8 @@ void SettingsForm::checkNetwork(){
216
216
uint ip_count = 0 ;
217
217
int res;
218
218
219
+
220
+ checkBattery ();
219
221
int runningServices = 0 ;
220
222
221
223
ip_string += " IP:\n " ;
@@ -352,6 +354,7 @@ void SettingsForm::getKeyboardLayouts(){
352
354
QString tmpstring;
353
355
QString outstr;
354
356
int read_size;
357
+ QString cachedlayout;
355
358
356
359
tmpstring = " " ;
357
360
@@ -393,11 +396,29 @@ void SettingsForm::getKeyboardLayouts(){
393
396
ui->kybrdcomboBox ->addItem (iconx, " Türkçe F" , " tr f" );
394
397
ui->kybrdcomboBox ->addItem (iconx, " English Q" , " us" );
395
398
399
+ cachedlayout = Cache ().getUserKeyboard ();
400
+
401
+ if (!cachedlayout.isEmpty () && !cachedlayout.isNull ())
402
+ tmpstring = cachedlayout;
396
403
397
404
qInfo () << " Current Keyboard layout is: " + tmpstring;
398
405
emit sendKeyboardLayout (tmpstring);
399
406
current_layout = tmpstring;
400
407
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
+
401
422
402
423
if (ui->kybrdcomboBox ->findData (tmpstring) == -1 ){
403
424
@@ -434,6 +455,8 @@ void SettingsForm::setKeyboardLayout(int index){
434
455
435
456
system (cmd_array);
436
457
458
+ Cache ().setUserKeyboard (actionName);
459
+
437
460
// set onscreen keyboard layout
438
461
emit sendKeyboardLayout (actionName);
439
462
}
@@ -593,3 +616,70 @@ void SettingsForm::on_sessioncomboBox_activated(int index)
593
616
QString sessionname = ui->sessioncomboBox ->itemData (index).toString ();
594
617
emit sendSessionInfo (sessionname);
595
618
}
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
+ }
0 commit comments