[KLF Backend]
[KLF Tools]
[KLF Home]
KLatexFormula Project
src
klftools
klfdefs_linux.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* file klfdefs_linux.cpp
3
* This file is part of the KLatexFormula Project.
4
* Copyright (C) 2011 by Philippe Faist
5
* philippe.faist at bluewin.ch
6
* *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, write to the *
19
* Free Software Foundation, Inc., *
20
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
***************************************************************************/
22
/* $Id$ */
23
29
#include <sys/utsname.h>
30
31
#include <
klfdefs.h
>
32
#include <
klfsysinfo.h
>
33
34
#include <QFileInfo>
35
#include <QFile>
36
37
38
KLF_EXPORT
QString
klf_defs_sysinfo_arch
()
39
{
40
static
bool
is_64 = (
sizeof
(
void
*) == 8);
41
42
struct
utsname d;
43
uname(&d);
44
45
if
(d.machine[0] ==
'i'
&& d.machine[2] ==
'8'
&& d.machine[3] ==
'6'
) {
46
// i?86
47
return
QString::fromLatin1
(
"x86"
);
48
}
49
if
(!strcmp(d.machine,
"x86_64"
)) {
50
// we could still be a 32-bit application run on a 64-bit machine
51
return
is_64 ?
QString::fromLatin1
(
"x86_64"
) :
QString::fromLatin1
(
"x86"
);
52
}
53
if
(!strncmp(d.machine,
"ppc"
, strlen(
"ppc"
))) {
54
return
is_64 ?
QString::fromLatin1
(
"ppc64"
) :
QString::fromLatin1
(
"ppc"
);
55
}
56
return
QString::fromLatin1
(
"unknown"
);
57
}
58
59
60
61
62
// access sys info in /sys/class/power_supply/ADP0/online
63
64
#define SYSINFO_FILE "/sys/class/power_supply/ADP0/online"
65
66
KLF_EXPORT
KLFSysInfo::BatteryInfo
_klf_linux_battery_info
(
bool
want_info_onbatterypower)
67
{
68
KLFSysInfo::BatteryInfo
info;
69
70
if
(!
QFile::exists
(
SYSINFO_FILE
)) {
71
info.
islaptop
=
false
;
72
info.
onbatterypower
=
false
;
73
return
info;
74
}
75
76
if
(want_info_onbatterypower) {
77
QFile
file(
SYSINFO_FILE
);
78
if
(!file.
open
(QIODevice::ReadOnly)) {
79
klfWarning
(
"Can't open file "
<<
SYSINFO_FILE
);
80
return
info;
81
}
82
QTextStream
tstr(&file);
83
84
int
val;
85
tstr >> val;
86
// val == 1 -> power online
87
// val == 0 -> on battery power
88
info.
onbatterypower
= ! (bool)val;
89
}
90
91
info.
islaptop
=
true
;
92
93
return
info;
94
}
95
96
KLF_EXPORT
KLFSysInfo::BatteryInfo
_klf_linux_battery_info
()
97
{
98
return
_klf_linux_battery_info
(
true
);
99
}
100
101
KLF_EXPORT
bool
_klf_linux_is_laptop
()
102
{
103
KLFSysInfo::BatteryInfo
info;
104
info =
_klf_linux_battery_info
(
false
);
105
return
info.
islaptop
;
106
}
107
108
KLF_EXPORT
bool
_klf_linux_is_on_battery_power
()
109
{
110
KLFSysInfo::BatteryInfo
info;
111
info =
_klf_linux_battery_info
(
true
);
112
return
info.
onbatterypower
;
113
}
114
_klf_linux_is_laptop
KLF_EXPORT bool _klf_linux_is_laptop()
Definition:
klfdefs_linux.cpp:101
KLFSysInfo::BatteryInfo
Definition:
klfsysinfo.h:65
QFile::open
virtual bool open(OpenMode mode)
KLFSysInfo::BatteryInfo::islaptop
bool islaptop
Definition:
klfsysinfo.h:68
klfsysinfo.h
QFile::exists
bool exists() const
QString
QTextStream
KLF_EXPORT
#define KLF_EXPORT
Definition:
klfdefs.h:41
_klf_linux_is_on_battery_power
KLF_EXPORT bool _klf_linux_is_on_battery_power()
Definition:
klfdefs_linux.cpp:108
klfWarning
#define klfWarning(streamableItems)
KLFSysInfo::BatteryInfo::onbatterypower
bool onbatterypower
Definition:
klfsysinfo.h:69
QString::fromLatin1
QString fromLatin1(const char *str, int size)
klf_defs_sysinfo_arch
KLF_EXPORT QString klf_defs_sysinfo_arch()
Definition:
klfdefs_linux.cpp:38
_klf_linux_battery_info
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_linux_battery_info(bool want_info_onbatterypower)
Definition:
klfdefs_linux.cpp:66
klfdefs.h
Base declarations for klatexformula and some utilities.
QFile
SYSINFO_FILE
#define SYSINFO_FILE
Definition:
klfdefs_linux.cpp:64
Generated by
doxygen
1.8.17