Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MKChannel.m « src - github.com/mumble-voip/mumblekit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e8f623cbd74d1a59585e0cfa94ab3adb5b981d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2010-2012 The MumbleKit Developers. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#import <MumbleKit/MKChannel.h>
#import "MKChannelPrivate.h"

#import <MumbleKit/MKUser.h>
#import "MKUserPrivate.h"

@interface MKChannel () {
    MKChannel        *_parent;
    NSUInteger       _channelId;
    NSString         *_channelName;
    BOOL             _temporary;
    NSInteger        _position;
    NSMutableArray   *_channels;
    NSMutableArray   *_users;
    NSMutableArray   *_linked;
    NSData           *_channelDescriptionHash;
    NSString         *_channelDescription;
}
@end

@implementation MKChannel

- (id) init {
    if (self = [super init]) {
        _channels = [[NSMutableArray alloc] init];
        _users = [[NSMutableArray alloc] init];
        _linked = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void) dealloc {
    [self removeFromParent];
    [self removeAllUsers];

    [_channelName release];

    [_channels release];
    [_users release];
    [_linked release];

    [super dealloc];
}

#pragma mark -

- (void) removeFromParent {
    [_parent removeChannel:self];
    [_parent release];
    _parent = nil;
}

- (void) addChannel:(MKChannel *)child {
    [child setParent:self];
    [_channels addObject:child];
}

- (void) removeChannel:(MKChannel *)child {
    [child setParent:nil];
    [_channels removeObject:child];
}

- (void) addUser:(MKUser *)user {
    MKChannel *chan = [user channel];
    [chan removeUser:user];
    [user setChannel:self];
    [_users addObject:user];
}

- (void) removeUser:(MKUser *)user {
    [user setChannel:nil];
    [_users removeObject:user];
}

- (void) removeAllUsers {
    for (MKUser *user in _users) {
        [user setChannel:nil];
    }
    [_users removeAllObjects];
}

- (NSArray *) channels {
    return _channels;
}

- (NSArray *) users {
    return _users;
}

- (NSArray *) linkedChannels {
    return _linked;
}

- (BOOL) isLinkedToChannel:(MKChannel*)chan {
    return [_linked containsObject:chan];
}

- (void) linkToChannel:(MKChannel *)chan {
    if ([self isLinkedToChannel:chan])
        return;

    [_linked addObject:chan];
    [chan linkToChannel:self];
}

- (void) unlinkFromChannel:(MKChannel *)chan {
    if ([self isLinkedToChannel:chan]) {
        [_linked removeObject:chan];
        [chan unlinkFromChannel:self];
    }
}

- (void) unlinkAll {
    NSArray *linkedChannels = [[_linked copy] autorelease];
    for (MKChannel *chan in linkedChannels) {
        [self unlinkFromChannel:chan];
    }
}

- (void) setChannelName:(NSString *)name {
    [_channelName release];
    _channelName = [name copy];
}

- (NSString *) channelName {
    return _channelName;
}

- (void) setParent:(MKChannel *)chan {
    _parent = [chan retain];
}

- (MKChannel *) parent {
    return _parent;
}

- (void) setChannelId:(NSUInteger)channelId {
    _channelId = channelId;
}

- (NSUInteger) channelId {
    return _channelId;
}

- (void) setTemporary:(BOOL)flag {
    _temporary = flag;
}

- (BOOL) isTemporary {
    return _temporary;
}

- (void) setPosition:(NSInteger)pos {
    _position = pos;
}

- (NSInteger) position {
    return _position;
}

- (void) setChannelDescriptionHash:(NSData *)hash {
    [_channelDescriptionHash release];
    _channelDescriptionHash = [hash copy];
}

- (NSData *) channelDescriptionHash {
    return _channelDescriptionHash;
}

- (void) setChannelDescription:(NSString *)desc {
    [_channelDescription release];
    _channelDescription = [desc copy];
}

- (NSString *) channelDescription {
    return _channelDescription;
}

@end