[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klftools/klfsysinfo.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfsysinfo.cpp
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2014 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
00023 
00024 #include <stdlib.h>
00025 
00026 #include <QDebug>
00027 #include <QString>
00028 #include <QStringList>
00029 
00030 #include "klfdefs.h"
00031 #include "klfsysinfo.h"
00032 
00033 
00034 // declared in klfdefs_<OS>.{mm|cpp}
00035 QString klf_defs_sysinfo_arch();
00036 
00037 KLF_EXPORT QString KLFSysInfo::arch()
00038 {
00039   return klf_defs_sysinfo_arch();
00040 }
00041 
00042 KLF_EXPORT QString KLFSysInfo::makeSysArch(const QString& os, const QString& arch)
00043 {
00044   return os+":"+arch;
00045 }
00046 KLF_EXPORT bool KLFSysInfo::isCompatibleSysArch(const QString& systemarch)
00047 {
00048   QString sysarch = systemarch;
00049 
00050   // on Windows, we use -- instead of ':' because ':' is an illegal char for a file name.
00051   sysarch.replace("--", ":");
00052 
00053   int ic = sysarch.indexOf(':');
00054   if (ic == -1) {
00055     qWarning()<<KLF_FUNC_NAME<<": Invalid sysarch string "<<sysarch;
00056     return false;
00057   }
00058   QString thisos = osString();
00059   if (thisos != sysarch.left(ic)) {
00060     klfDbg("incompatible architectures (this one)="<<thisos<<" and (tested)="<<sysarch) ;
00061     return false;
00062   }
00063   QStringList archlist = sysarch.mid(ic+1).split(',');
00064   QString thisarch = arch();
00065   klfDbg("testing if our arch="<<thisarch<<" is in the compatible arch list="<<archlist) ;
00066   return KLF_DEBUG_TEE( archlist.contains(thisarch) );
00067 }
00068 
00069 KLF_EXPORT KLFSysInfo::Os KLFSysInfo::os()
00070 {
00071 #if defined(Q_OS_LINUX)
00072   return Linux;
00073 #elif defined(Q_OS_DARWIN)
00074   return MacOsX;
00075 #elif defined(Q_OS_WIN32)
00076   return Win32;
00077 #else
00078   return OtherOs;
00079 #endif
00080 }
00081 
00082 KLF_EXPORT QString KLFSysInfo::osString(Os sysos)
00083 {
00084   switch (sysos) {
00085   case Linux: return QLatin1String("linux");
00086   case MacOsX: return QLatin1String("macosx");
00087   case Win32: return QLatin1String("win32");
00088   case OtherOs: return QString();
00089   default: ;
00090   }
00091   qWarning("KLFSysInfo::osString: unknown OS: %d", sysos);
00092   return QString();
00093 }
00094 
00095 
00096 #ifdef Q_OS_DARWIN
00097  bool _klf_mac_is_laptop();
00098  bool _klf_mac_is_on_battery_power();
00099  KLFSysInfo::BatteryInfo _klf_mac_battery_info();
00100 #elif defined(Q_OS_LINUX)
00101  bool _klf_linux_is_laptop();
00102  bool _klf_linux_is_on_battery_power();
00103  KLFSysInfo::BatteryInfo _klf_linux_battery_info();
00104 #elif defined(Q_OS_WIN32)
00105  bool _klf_win_is_laptop();
00106  bool _klf_win_is_on_battery_power();
00107  KLFSysInfo::BatteryInfo _klf_win_battery_info();
00108 #else
00109  bool _klf_otheros_is_laptop();
00110  bool _klf_otheros_is_on_battery_power();
00111  KLFSysInfo::BatteryInfo _klf_otheros_battery_info();
00112 #endif
00113 
00114 KLF_EXPORT KLFSysInfo::BatteryInfo KLFSysInfo::batteryInfo()
00115 {
00116 #if defined(Q_OS_DARWIN)
00117   return _klf_mac_battery_info();
00118 #elif defined(Q_OS_LINUX)
00119   return _klf_linux_battery_info();
00120 #elif defined(Q_OS_WIN32)
00121   return _klf_win_battery_info();
00122 #else
00123   return _klf_otheros_battery_info();
00124 #endif
00125 }
00126 
00127 
00128 static int _klf_cached_islaptop = -1;
00129 
00130 KLF_EXPORT bool KLFSysInfo::isLaptop()
00131 {
00132   if (_klf_cached_islaptop >= 0)
00133     return (bool) _klf_cached_islaptop;
00134 
00135 #if defined(Q_OS_DARWIN)
00136   _klf_cached_islaptop = (int) _klf_mac_is_laptop();
00137 #elif defined(Q_OS_LINUX)
00138   _klf_cached_islaptop = (int) _klf_linux_is_laptop();
00139 #elif defined(Q_OS_WIN32)
00140   _klf_cached_islaptop = (int) _klf_win_is_laptop();
00141 #else
00142   _klf_cached_islaptop = (int) _klf_otheros_is_laptop();
00143 #endif
00144 
00145   return (bool) _klf_cached_islaptop;
00146 }
00147 
00148 KLF_EXPORT bool KLFSysInfo::isOnBatteryPower()
00149 {
00150 #if defined(Q_OS_DARWIN)
00151   return _klf_mac_is_on_battery_power();
00152 #elif defined(Q_OS_LINUX)
00153   return _klf_linux_is_on_battery_power();
00154 #elif defined(Q_OS_WIN32)
00155   return _klf_win_is_on_battery_power();
00156 #else
00157   return _klf_otheros_is_on_battery_power();
00158 #endif
00159 }
00160 
00161 
00162 
00163 // ----------------------------------------

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net