Fixed the state for the playlists menu item to show the currently playing playlist.
[MenuTunes.git] / NetworkObject.m
1 /*
2  *  MenuTunes
3  *  NetworkObject
4  *    Remote network object that is vended
5  *
6  *  Original Author : Kent Sutherland <ksutherland@ithinksw.com>
7  *   Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
8  *
9  *  Copyright (c) 2002 - 2003 iThink Software.
10  *  All Rights Reserved
11  *
12  *      This header defines the Objective-C protocol which all MenuTunes Remote
13  *  plugins must implement.  To build a remote, create a subclass of this
14  *  object, and implement each method in the @protocol below.
15  *
16  */
17
18 #import "NetworkObject.h"
19 #import "MainController.h"
20 #import <ITMTRemote/ITMTRemote.h>
21
22 @implementation NetworkObject
23
24 - (id)init
25 {
26     if ( (self = [super init]) ) {
27         _valid = YES;
28         if (![self requiresPassword]) {
29             _authenticated = YES;
30         } else {
31             _authenticated = NO;
32         }
33     }
34     return self;
35 }
36
37 - (ITMTRemote *)remote
38 {
39     if (_authenticated && _valid) {
40         return [[MainController sharedController] currentRemote];
41     } else {
42         return nil;
43     }
44 }
45
46 - (NSString *)serverName
47 {
48     NSString *name = [[NSUserDefaults standardUserDefaults] stringForKey:@"sharedPlayerName"];
49     if (!name)
50         name = @"MenuTunes Shared Player";
51     return name;
52 }
53
54 - (BOOL)requiresPassword
55 {
56     return ([[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"] length] > 0);
57 }
58
59 - (BOOL)sendPassword:(NSData *)password
60 {
61     if ([password isEqualToData:[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"]]) {
62         _authenticated = YES;
63         return YES;
64     } else {
65         _authenticated = NO;
66         return NO;
67     }
68 }
69
70 - (void)invalidate
71 {
72     _valid = NO;
73 }
74
75 - (void)makeValid
76 {
77     _valid = YES;
78 }
79
80 - (BOOL)isValid
81 {
82     return _valid;
83 }
84
85 @end