[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfsysinfo.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * file klfsysinfo.cpp
3 * This file is part of the KLatexFormula Project.
4 * Copyright (C) 2014 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
24#include <stdlib.h>
25
26#include <QDebug>
27#include <QString>
28#include <QStringList>
29
30#include "klfdefs.h"
31#include "klfsysinfo.h"
32
33
34// declared in klfdefs_<OS>.{mm|cpp}
36
41
43{
44 return os+":"+arch;
45}
47{
48 QString sysarch = systemarch;
49
50 // on Windows, we use -- instead of ':' because ':' is an illegal char for a file name.
51 sysarch.replace("--", ":");
52
53 int ic = sysarch.indexOf(':');
54 if (ic == -1) {
55 qWarning()<<KLF_FUNC_NAME<<": Invalid sysarch string "<<sysarch;
56 return false;
57 }
58 QString thisos = osString();
59 if (thisos != sysarch.left(ic)) {
60 klfDbg("incompatible architectures (this one)="<<thisos<<" and (tested)="<<sysarch) ;
61 return false;
62 }
63 QStringList archlist = sysarch.mid(ic+1).split(',');
64 QString thisarch = arch();
65 klfDbg("testing if our arch="<<thisarch<<" is in the compatible arch list="<<archlist) ;
66 return KLF_DEBUG_TEE( archlist.contains(thisarch) );
67}
68
70{
71#if defined(Q_OS_LINUX)
72 return Linux;
73#elif defined(Q_OS_DARWIN)
74 return MacOsX;
75#elif defined(Q_OS_WIN32)
76 return Win32;
77#else
78 return OtherOs;
79#endif
80}
81
83{
84 switch (sysos) {
85 case Linux: return QLatin1String("linux");
86 case MacOsX: return QLatin1String("macosx");
87 case Win32: return QLatin1String("win32");
88 case OtherOs: return QString();
89 default: ;
90 }
91 qWarning("KLFSysInfo::osString: unknown OS: %d", sysos);
92 return QString();
93}
94
95
96#ifdef Q_OS_DARWIN
97 bool _klf_mac_is_laptop();
100#elif defined(Q_OS_LINUX)
104#elif defined(Q_OS_WIN32)
105 bool _klf_win_is_laptop();
108#else
112#endif
113
115{
116#if defined(Q_OS_DARWIN)
117 return _klf_mac_battery_info();
118#elif defined(Q_OS_LINUX)
120#elif defined(Q_OS_WIN32)
121 return _klf_win_battery_info();
122#else
124#endif
125}
126
127
128static int _klf_cached_islaptop = -1;
129
131{
132 if (_klf_cached_islaptop >= 0)
133 return (bool) _klf_cached_islaptop;
134
135#if defined(Q_OS_DARWIN)
136 _klf_cached_islaptop = (int) _klf_mac_is_laptop();
137#elif defined(Q_OS_LINUX)
138 _klf_cached_islaptop = (int) _klf_linux_is_laptop();
139#elif defined(Q_OS_WIN32)
140 _klf_cached_islaptop = (int) _klf_win_is_laptop();
141#else
142 _klf_cached_islaptop = (int) _klf_otheros_is_laptop();
143#endif
144
145 return (bool) _klf_cached_islaptop;
146}
147
149{
150#if defined(Q_OS_DARWIN)
152#elif defined(Q_OS_LINUX)
154#elif defined(Q_OS_WIN32)
156#else
158#endif
159}
160
161
162
163// ----------------------------------------
#define KLF_DEBUG_TEE(expr)
Print the value of expression and return it.
Definition klfdebug.h:154
#define klfDbg(streamableItems)
print debug stream items
Definition klfdebug.h:158
Base declarations for klatexformula and some utilities.
#define KLF_EXPORT
Definition klfdefs.h:41
KLF_EXPORT bool _klf_linux_is_laptop()
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_linux_battery_info()
KLF_EXPORT bool _klf_linux_is_on_battery_power()
KLF_EXPORT bool _klf_mac_is_on_battery_power()
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_mac_battery_info()
KLF_EXPORT bool _klf_mac_is_laptop()
KLF_EXPORT bool _klf_win_is_on_battery_power()
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_win_battery_info()
KLF_EXPORT bool _klf_win_is_laptop()
KLFSysInfo::BatteryInfo _klf_otheros_battery_info()
bool _klf_otheros_is_on_battery_power()
bool _klf_otheros_is_laptop()
QString klf_defs_sysinfo_arch()
KLF_EXPORT QString osString(KLFSysInfo::Os sysos=os())
The operating system we are running, returned as a string.
Os
List of known operating systems.
Definition klfsysinfo.h:32
@ MacOsX
systems on which Q_OS_DARWIN is defined
Definition klfsysinfo.h:32
@ OtherOs
systems on which neither Q_OS_{LINUX|WIN32|DARWIN} is defined
Definition klfsysinfo.h:32
@ Win32
systems on which Q_OS_WIN32 is defined
Definition klfsysinfo.h:32
@ Linux
systems on which Q_OS_LINUX is defined
Definition klfsysinfo.h:32
KLF_EXPORT bool isCompatibleSysArch(const QString &sysarch)
KLF_EXPORT bool isLaptop()
KLF_EXPORT QString makeSysArch(const QString &os, const QString &arch)
KLF_EXPORT BatteryInfo batteryInfo()
KLF_EXPORT KLFSysInfo::Os os()
Which operating system this system is running.
KLF_EXPORT QString arch()
The architecture of this sytem.
KLF_EXPORT bool isOnBatteryPower()
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString left(int n) const
QString mid(int position, int n) const
QString & replace(int position, int n, QChar after)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const

Generated by doxygen 1.11.0