13static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
16 FSRef frameworksFolderRef;
20 if (bundlePtr == nil) {
29 err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType,
true, &frameworksFolderRef);
31 baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
33 err = coreFoundationUnknownErr;
38 bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework,
false);
39 if (bundleURL == nil) {
40 err = coreFoundationUnknownErr;
45 *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
46 if (*bundlePtr == nil) {
47 err = coreFoundationUnknownErr;
52 if (!CFBundleLoadExecutable(*bundlePtr)) {
53 err = coreFoundationUnknownErr;
58 if (err != noErr && *bundlePtr != nil) {
59 CFRelease(*bundlePtr);
63 if (bundleURL != nil) {
74pascal
void MacPoller::IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState,
void *inUserData)
78 case kEventLoopIdleTimerStarted:
79 case kEventLoopIdleTimerStopped:
82 ((MacPoller *)inUserData)->m_secondsIdle = 0;
83 ((MacPoller *)inUserData)->triggerResume();
85 case kEventLoopIdleTimerIdling:
87 ((MacPoller *)inUserData)->m_secondsIdle++;
88 ((MacPoller *)inUserData)->poll();
94typedef OSStatus (*InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop,
95 EventTimerInterval inFireDelay,
96 EventTimerInterval inInterval,
97 EventLoopIdleTimerUPP inTimerProc,
99 EventLoopTimerRef *outTimer);
101MacPoller::MacPoller(
QObject *parent)
102 : KAbstractIdleTimePoller(parent)
109MacPoller::~MacPoller()
113void MacPoller::unloadPoller()
115 RemoveEventLoopTimer(m_timerRef);
118bool MacPoller::isAvailable()
123bool MacPoller::setUpPoller()
135 CFBundleRef carbonBundle;
137 if (LoadFrameworkBundle(CFSTR(
"Carbon.framework"), &carbonBundle) != noErr) {
142 InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer =
143 (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR(
"InstallEventLoopIdleTimer"));
145 if (myInstallEventLoopIdleTimer == 0) {
149 EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(IdleTimerAction);
150 if ((*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP,
this, &m_timerRef)) {
162void MacPoller::addTimeout(
int nextTimeout)
164 m_timeouts.
append(nextTimeout);
170 int idle = m_secondsIdle * 1000;
173 for (
int i : std::as_const(m_timeouts)) {
174 if ((i - idle < 1000 && i > idle) || (idle - i < 1000 && idle > i)) {
176 Q_EMIT timeoutReached(i);
183int MacPoller::forcePollRequest()
188void MacPoller::removeTimeout(
int timeout)
194void MacPoller::catchIdleEvent()
199void MacPoller::stopCatchingIdleEvents()
204void MacPoller::triggerResume()
207 Q_EMIT resumingFromIdle();
208 stopCatchingIdleEvents();
212void MacPoller::simulateUserActivity()
217#include "moc_macpoller.cpp"
void append(QList< T > &&value)
bool removeOne(const AT &t)