[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfdefs_mac.mm
Go to the documentation of this file.
1/***************************************************************************
2 * file klfdefs_mac.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 <Cocoa/Cocoa.h>
30
31#import <IOKit/ps/IOPowerSources.h>
32#import <IOKit/ps/IOPSKeys.h>
33
34#include <klfdefs.h>
35#include <klfsysinfo.h>
36
37
39{
40 static bool is_64 = (sizeof(void*) == 8);
41
42 SInt32 x;
43 Gestalt(gestaltSysArchitecture, &x);
44 if (x == gestaltPowerPC) {
45 return is_64 ? QString::fromLatin1("ppc64") : QString::fromLatin1("ppc");
46 } else if (x == gestaltIntel) {
47 return is_64 ? QString::fromLatin1("x86_64") : QString::fromLatin1("x86");
48 }
49 return QString::fromLatin1("unknown");
50}
51
52
53static bool init_power_sources_info(CFTypeRef *blobptr, CFArrayRef *sourcesptr)
54{
55 *blobptr = IOPSCopyPowerSourcesInfo();
56 *sourcesptr = IOPSCopyPowerSourcesList(*blobptr);
57 if (CFArrayGetCount(*sourcesptr) == 0) {
58 klfDbg("Could not retrieve battery information. May be a system without battery.") ;
59 return false; // Could not retrieve battery information. System may not have a battery.
60 }
61 // we have a battery.
62 return true;
63}
64
66{
67 CFTypeRef blob;
68 CFArrayRef sources;
69
70 klfDbg("_klf_mac_battery_info()") ;
71
72 bool have_battery = init_power_sources_info(&blob, &sources);
73
75
76 if(!have_battery) {
77 klfDbg("_klf_mac_battery_info(): unable to get battery info. Probably don't have a battery.") ;
78 info.islaptop = false;
79 info.onbatterypower = false;
80 return info;
81 }
82
83 CFDictionaryRef pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, 0));
84
85 bool powerConnected = [(NSString*)[(NSDictionary*)pSource objectForKey:@kIOPSPowerSourceStateKey]
86 isEqualToString:@kIOPSACPowerValue];
87 klfDbg("power is connected?: "<<(bool)powerConnected) ;
88
89 //BOOL outputCharging = [[(NSDictionary*)pSource objectForKey:@kIOPSIsChargingKey] boolValue];
90
91 // bool outputInstalled = [[(NSDictionary*)pSource objectForKey:@kIOPSIsPresentKey] boolValue];
92 // bool outputConnected = [(NSString*)[(NSDictionary*)pSource objectForKey:@kIOPSPowerSourceStateKey] isEqualToString:@kIOPSACPowerValue];
93 // //BOOL outputCharging = [[(NSDictionary*)pSource objectForKey:@kIOPSIsChargingKey] boolValue];
94 // double outputCurrent = [[(NSDictionary*)pSource objectForKey:@kIOPSCurrentKey] doubleValue];
95 // double outputVoltage = [[(NSDictionary*)pSource objectForKey:@kIOPSVoltageKey] doubleValue];
96 // double outputCapacity = [[(NSDictionary*)pSource objectForKey:@kIOPSCurrentCapacityKey] doubleValue];
97 // double outputMaxCapacity = [[(NSDictionary*)pSource objectForKey:@kIOPSMaxCapacityKey] doubleValue];
98
99 // klfDbg("battery status: installed="<<outputInstalled<<"; connected="<<outputConnected<<"; charging="<<outputCharging<<"; current="<<outputCurrent<<"; voltage="<<outputVoltage<<"; capacity="<<outputCapacity<<"; outputMaxCapacity="<<outputMaxCapacity);
100
101 CFRelease(blob);
102 CFRelease(sources);
103
104 info.islaptop = true;
105 info.onbatterypower = !powerConnected;
106
107 return info;
108}
109
111{
112 CFTypeRef blob;
113 CFArrayRef sources;
114
115 bool have_battery = init_power_sources_info(&blob, &sources);
116
117 CFRelease(blob);
118 CFRelease(sources);
119 return have_battery;
120}
121
127
#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 QString klf_defs_sysinfo_arch()
KLF_EXPORT bool _klf_mac_is_on_battery_power()
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_mac_battery_info()
KLF_EXPORT bool _klf_mac_is_laptop()
QString fromLatin1(const char *str, int size)

Generated by doxygen 1.12.0