• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
  • private
kopeteidleplatform_mac.cpp
Go to the documentation of this file.
1 /*
2  kopeteidleplatform_mac.cpp - Kopete Idle Platform
3 
4  Copyright (C) 2003 by Tarkvara Design Inc. (from KVIrc source code)
5  Copyright (c) 2008 by Roman Jarosz <kedgedev@centrum.cz>
6  Kopete (c) 2008 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2 of the License, or (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "kopeteidleplatform_p.h"
19 #include <Carbon/Carbon.h>
20 
21 // Why does Apple have to make this so complicated?
22 static OSStatus LoadFrameworkBundle( CFStringRef framework, CFBundleRef *bundlePtr )
23 {
24  OSStatus err;
25  FSRef frameworksFolderRef;
26  CFURLRef baseURL;
27  CFURLRef bundleURL;
28 
29  if ( bundlePtr == nil )
30  return( -1 );
31 
32  *bundlePtr = nil;
33 
34  baseURL = nil;
35  bundleURL = nil;
36 
37  err = FSFindFolder( kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef );
38  if ( err == noErr )
39  {
40  baseURL = CFURLCreateFromFSRef( kCFAllocatorSystemDefault, &frameworksFolderRef );
41  if ( baseURL == nil )
42  err = coreFoundationUnknownErr;
43  }
44 
45  if ( err == noErr )
46  {
47  bundleURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, baseURL, framework, false );
48  if ( bundleURL == nil )
49  err = coreFoundationUnknownErr;
50  }
51 
52  if ( err == noErr )
53  {
54  *bundlePtr = CFBundleCreate( kCFAllocatorSystemDefault, bundleURL );
55  if ( *bundlePtr == nil )
56  err = coreFoundationUnknownErr;
57  }
58 
59  if ( err == noErr )
60  {
61  if ( !CFBundleLoadExecutable( *bundlePtr ) )
62  err = coreFoundationUnknownErr;
63  }
64 
65  // Clean up.
66  if ( err != noErr && *bundlePtr != nil )
67  {
68  CFRelease( *bundlePtr );
69  *bundlePtr = nil;
70  }
71 
72  if ( bundleURL != nil )
73  CFRelease( bundleURL );
74 
75  if ( baseURL != nil )
76  CFRelease( baseURL );
77 
78  return err;
79 }
80 
81 
82 class Kopete::IdlePlatform::Private
83 {
84 public:
85  EventLoopTimerRef mTimerRef;
86  int mSecondsIdle;
87 
88  Private() : mTimerRef(0), mSecondsIdle(0) {}
89 
90  static pascal void IdleTimerAction( EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData );
91 
92 };
93 
94 
95 pascal void Kopete::IdlePlatform::Private::IdleTimerAction( EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData )
96 {
97  switch (inState)
98  {
99  case kEventLoopIdleTimerStarted:
100  case kEventLoopIdleTimerStopped:
101  // Get invoked with this constant at the start of the idle period,
102  // or whenever user activity cancels the idle.
103  ((Kopete::IdlePlatform::Private*)inUserData)->mSecondsIdle = 0;
104  break;
105  case kEventLoopIdleTimerIdling:
106  // Called every time the timer fires (i.e. every second).
107  ((Kopete::IdlePlatform::Private*)inUserData)->mSecondsIdle++;
108  break;
109  }
110 }
111 
112 
113 Kopete::IdlePlatform::IdlePlatform()
114 : d(new Private())
115 {
116 }
117 
118 Kopete::IdlePlatform::~IdlePlatform()
119 {
120  RemoveEventLoopTimer( d->mTimerRef );
121  delete d;
122 }
123 
124 // Typedef for the function we're getting back from CFBundleGetFunctionPointerForName.
125 typedef OSStatus (*InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop,
126  EventTimerInterval inFireDelay,
127  EventTimerInterval inInterval,
128  EventLoopIdleTimerUPP inTimerProc,
129  void * inTimerData,
130  EventLoopTimerRef * outTimer);
131 
132 bool Kopete::IdlePlatform::init()
133 {
134  // May already be init'ed.
135  if ( d->mTimerRef )
136  return true;
137 
138  // According to the docs, InstallEventLoopIdleTimer is new in 10.2.
139  // According to the headers, it has been around since 10.0.
140  // One of them is lying. We'll play it safe and weak-link the function.
141 
142  // Load the "Carbon.framework" bundle.
143  CFBundleRef carbonBundle;
144  if ( LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) != noErr )
145  return false;
146 
147  // Load the Mach-O function pointers for the routine we will be using.
148  InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName( carbonBundle, CFSTR("InstallEventLoopIdleTimer") );
149  if ( myInstallEventLoopIdleTimer == 0 )
150  return false;
151 
152  EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP( Private::IdleTimerAction );
153  if ( (*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef) )
154  return true;
155 
156  return false;
157 }
158 
159 int Kopete::IdlePlatform::secondsIdle()
160 {
161  return d->mSecondsIdle;
162 }
Kopete::IdlePlatform::~IdlePlatform
~IdlePlatform()
Definition: kopeteidleplatform_dummy.cpp:23
Kopete::IdlePlatform::IdlePlatform
IdlePlatform()
Definition: kopeteidleplatform_dummy.cpp:19
Kopete::IdlePlatform::secondsIdle
int secondsIdle()
Definition: kopeteidleplatform_dummy.cpp:33
LoadFrameworkBundle
static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
Definition: kopeteidleplatform_mac.cpp:22
InstallEventLoopIdleTimerPtr
OSStatus(* InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop, EventTimerInterval inFireDelay, EventTimerInterval inInterval, EventLoopIdleTimerUPP inTimerProc, void *inTimerData, EventLoopTimerRef *outTimer)
Definition: kopeteidleplatform_mac.cpp:125
Kopete::IdlePlatform::init
bool init()
Definition: kopeteidleplatform_dummy.cpp:28
kopeteidleplatform_p.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal