A couple more modifications, as well as some comments to ease others'
[MenuTunes.git] / iTunesRemote.m
1 /* Copyright (c) 2002 - 2003 by iThink Software. All Rights Reserved. */
2
3 #import "iTunesRemote.h"
4
5
6 @implementation iTunesRemote
7
8 + (id)remote {
9     return [[[iTunesRemote alloc] init] autorelease];
10 }
11
12 - (id)valueOfProperty:(ITMTRemoteProperty)property {
13     // Get from Info.plist
14     return nil;
15 }
16
17 - (NSDictionary *)propertiesAndValues {
18     // Get from Info.plist
19     return nil;
20 }
21
22 - (ITMTPlayerStyle)playerStyle {
23     return ITMTSinglePlayerStyle;
24 }
25
26 - (BOOL)activate {
27     if ( !_activated ) {
28         if ( [self iTunesIsRunning] ) {
29             _currentPSN = [self iTunesPSN];
30         } else {
31             if ( [self launchiTunes] ) {
32                 _currentPSN = [self iTunesPSN];
33             } else {
34                 return NO;
35             }
36         }
37         if ( ( _player = [iTunesPlayer sharedPlayerForRemote:self] ) ) {
38             _activated = YES;
39             return YES;
40         }
41     } else {
42         return NO;
43     }
44 }
45
46 - (BOOL)deactivate {
47     if ( _activated ) {
48         _currentPSN = kNoProcess;
49         _player = nil;
50         _activated = NO;
51         return YES;
52     } else {
53         return NO;
54     }
55 }
56
57 - (ITMTPlayer *)currentPlayer {
58     if (_activated) {
59         return _player;
60     } else {
61         return nil;
62     }
63 }
64
65 - (NSArray *)players {
66     if (_activated) {
67         return [NSArray arrayWithObject:_player];
68     } else {
69         return nil;
70     }
71 }
72
73 #pragma mark -
74 #pragma mark INTERNAL METHODS
75 #pragma mark -
76
77 - (BOOL)launchiTunes {
78     return NO;
79 }
80
81 - (BOOL)iTunesIsRunning {
82     return NO;
83 }
84
85 - (ProcessSerialNumber)iTunesPSN
86 {
87     ProcessSerialNumber number;
88     number.highLongOfPSN = kNoProcess;
89     number.lowLongOfPSN = 0;
90     
91     while ( (GetNextProcess(&number) == noErr) ) 
92     {
93         CFStringRef name;
94         if ( (CopyProcessName(&number, &name) == noErr) )
95         {
96             if ([(NSString *)name isEqualToString:@"iTunes"])
97             {
98                 return number;
99             }
100             [(NSString *)name release];
101         }
102     }
103     return number;
104 }
105
106 @end