Detect battery presence on Mac.
This commit is contained in:
parent
1abf059d16
commit
62ea8bd4eb
|
@ -441,4 +441,9 @@ QKeySequence KeySequenceFromNSEvent(NSEvent* event) {
|
||||||
return QKeySequence(key);
|
return QKeySequence(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DumpDictionary(CFDictionaryRef dict) {
|
||||||
|
NSDictionary* d = (NSDictionary*)dict;
|
||||||
|
NSLog(@"%@", d);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
|
|
|
@ -15,14 +15,19 @@
|
||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Only include this from Objective-C++ files
|
|
||||||
|
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
|
||||||
|
#include <CoreFoundation/CFDictionary.h>
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
@class NSEvent;
|
@class NSEvent;
|
||||||
|
#else
|
||||||
|
class NSEvent;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
QKeySequence KeySequenceFromNSEvent(NSEvent* event);
|
QKeySequence KeySequenceFromNSEvent(NSEvent* event);
|
||||||
|
void DumpDictionary(CFDictionaryRef dict);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,11 @@
|
||||||
|
|
||||||
#ifdef Q_OS_DARWIN
|
#ifdef Q_OS_DARWIN
|
||||||
# include "core/mac_startup.h"
|
# include "core/mac_startup.h"
|
||||||
|
# include "core/mac_utilities.h"
|
||||||
|
# include "core/scoped_cftyperef.h"
|
||||||
# include "CoreServices/CoreServices.h"
|
# include "CoreServices/CoreServices.h"
|
||||||
|
# include "IOKit/ps/IOPowerSources.h"
|
||||||
|
# include "IOKit/ps/IOPSKeys.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/scoped_array.hpp>
|
#include <boost/scoped_array.hpp>
|
||||||
|
@ -495,7 +499,18 @@ bool IsLaptop() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
Q_ASSERT("Fixit John" == 0);
|
ScopedCFTypeRef<CFTypeRef> power_sources(IOPSCopyPowerSourcesInfo());
|
||||||
|
ScopedCFTypeRef<CFArrayRef> power_source_list(
|
||||||
|
IOPSCopyPowerSourcesList(power_sources.get()));
|
||||||
|
for (CFIndex i = 0; i < CFArrayGetCount(power_source_list.get()); ++i) {
|
||||||
|
CFTypeRef ps = CFArrayGetValueAtIndex(power_source_list.get(), i);
|
||||||
|
CFDictionaryRef description = IOPSGetPowerSourceDescription(
|
||||||
|
power_sources.get(), ps);
|
||||||
|
|
||||||
|
if (CFDictionaryContainsKey(description, CFSTR(kIOPSBatteryHealthKey))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue