[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: klfsysinfo.cpp 978 2016-12-31 05:16:11Z phfaist $ */
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 
38 {
39  return klf_defs_sysinfo_arch();
40 }
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)
101  bool _klf_linux_is_laptop();
104 #elif defined(Q_OS_WIN32)
105  bool _klf_win_is_laptop();
108 #endif
109 
111 {
112 #if defined(Q_OS_DARWIN)
113  return _klf_mac_battery_info();
114 #elif defined(Q_OS_LINUX)
115  return _klf_linux_battery_info();
116 #elif defined(Q_OS_WIN32)
117  return _klf_win_battery_info();
118 #endif
119  return BatteryInfo();
120 }
121 
122 
123 static int _klf_cached_islaptop = -1;
124 
126 {
127  if (_klf_cached_islaptop >= 0)
128  return (bool) _klf_cached_islaptop;
129 
130 #if defined(Q_OS_DARWIN)
131  _klf_cached_islaptop = (int) _klf_mac_is_laptop();
132 #elif defined(Q_OS_LINUX)
133  _klf_cached_islaptop = (int) _klf_linux_is_laptop();
134 #elif defined(Q_OS_WIN32)
135  _klf_cached_islaptop = (int) _klf_win_is_laptop();
136 #endif
137  return (bool) _klf_cached_islaptop;
138 }
139 
141 {
142 #if defined(Q_OS_DARWIN)
144 #elif defined(Q_OS_LINUX)
146 #elif defined(Q_OS_WIN32)
148 #endif
149  return false;
150 }
151 
152 
153 
154 // ----------------------------------------
KLF_EXPORT bool _klf_mac_is_on_battery_power()
Definition: klfdefs_mac.mm:119
systems on which neither Q_OS_{LINUX|WIN32|DARWIN} is defined
Definition: klfsysinfo.h:32
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KLF_EXPORT QString makeSysArch(const QString &os, const QString &arch)
Definition: klfsysinfo.cpp:42
Os
List of known operating systems.
Definition: klfsysinfo.h:32
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_win_battery_info()
Definition: klfdefs_win.cpp:51
KLF_EXPORT bool _klf_linux_is_laptop()
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
#define KLF_DEBUG_TEE(expr)
Print the value of expression and return it.
Base declarations for klatexformula and some utilities.
KLF_EXPORT bool _klf_linux_is_on_battery_power()
bool contains(const QString &str, Qt::CaseSensitivity cs) const
#define klfDbg(streamableItems)
print debug stream items
KLF_EXPORT bool _klf_win_is_laptop()
Definition: klfdefs_win.cpp:72
systems on which Q_OS_DARWIN is defined
Definition: klfsysinfo.h:32
#define KLF_EXPORT
Definition: klfdefs.h:41
KLF_EXPORT QString arch()
The architecture of this sytem.
Definition: klfsysinfo.cpp:37
KLF_EXPORT bool isLaptop()
Definition: klfsysinfo.cpp:125
KLF_EXPORT BatteryInfo batteryInfo()
Definition: klfsysinfo.cpp:110
KLF_EXPORT bool isOnBatteryPower()
Definition: klfsysinfo.cpp:140
#define KLF_FUNC_NAME
QString & replace(int position, int n, QChar after)
QString mid(int position, int n) const
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_linux_battery_info(bool want_info_onbatterypower)
QString klf_defs_sysinfo_arch()
KLF_EXPORT KLFSysInfo::Os os()
Which operating system this system is running.
Definition: klfsysinfo.cpp:69
QString left(int n) const
KLF_EXPORT bool isCompatibleSysArch(const QString &sysarch)
Definition: klfsysinfo.cpp:46
KLF_EXPORT bool _klf_win_is_on_battery_power()
Definition: klfdefs_win.cpp:79
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_mac_battery_info()
Definition: klfdefs_mac.mm:65
systems on which Q_OS_WIN32 is defined
Definition: klfsysinfo.h:32
systems on which Q_OS_LINUX is defined
Definition: klfsysinfo.h:32
KLF_EXPORT QString osString(KLFSysInfo::Os sysos=os())
The operating system we are running, returned as a string.
Definition: klfsysinfo.cpp:82
KLF_EXPORT bool _klf_mac_is_laptop()
Definition: klfdefs_mac.mm:107

Generated by doxygen 1.8.13