[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
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
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
67{
69
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
97{
98 return _klf_linux_battery_info(true);
99}
100
102{
104 info = _klf_linux_battery_info(false);
105 return info.islaptop;
106}
107
109{
111 info = _klf_linux_battery_info(true);
112 return info.onbatterypower;
113}
114
#define klfWarning(streamableItems)
Definition klfdebug.h:171
Base declarations for klatexformula and some utilities.
#define KLF_EXPORT
Definition klfdefs.h:41
KLF_EXPORT QString klf_defs_sysinfo_arch()
KLF_EXPORT bool _klf_linux_is_laptop()
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_linux_battery_info()
#define SYSINFO_FILE
KLF_EXPORT bool _klf_linux_is_on_battery_power()
bool exists() const
virtual bool open(OpenMode mode)
QString fromLatin1(const char *str, int size)

Generated by doxygen 1.9.7