-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPBackgroundImageTransfer.m
70 lines (54 loc) · 1.8 KB
/
TPBackgroundImageTransfer.m
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
//
// TPBackgroundImageTransfer.m
// teleport
//
// Created by JuL on 10/05/06.
// Copyright 2006 abyssoft. All rights reserved.
//
#import "TPBackgroundImageTransfer.h"
#import "TPTransfer_Private.h"
#import "TPHostsManager.h"
#import "TPLocalHost.h"
#import "TPRemoteHost.h"
NSString * TPBackgroundImageTransferIdentifierKey = @"TPBackgroundImageTransferIdentifier";
NSString * TPBackgroundImageTransferDataKey = @"TPBackgroundImageTransferData";
#define ENABLE_BACKGROUND_IMAGE_TRANSFER 1
@implementation TPOutgoingBackgroundImageTransfer
- (NSString*)type
{
return @"TPIncomingBackgroundImageTransfer";
}
- (NSData*)dataToTransfer
{
#if ENABLE_BACKGROUND_IMAGE_TRANSFER
NSDictionary * dict = @{TPBackgroundImageTransferIdentifierKey: [[TPLocalHost localHost] identifier],
TPBackgroundImageTransferDataKey: [[TPLocalHost localHost] backgroundImageData]};
return [NSKeyedArchiver archivedDataWithRootObject:dict];
#else
return nil;
#endif
}
@end
@implementation TPIncomingBackgroundImageTransfer
- (void)_receiverDataTransferCompleted
{
DebugLog(@"_receiverDataTransferCompleted %@ on thread %@", self, [NSThread currentThread]);
NSMutableDictionary * dict = nil;
@try {
dict = [NSKeyedUnarchiver unarchiveObjectWithData:_data];
}
@catch(NSException *e) {
DebugLog(@"exception when unarchiving dictionary: %@", e);
}
if(dict != nil) {
NSString * identifier = dict[TPBackgroundImageTransferIdentifierKey];
NSData * backgroundImageData = dict[TPBackgroundImageTransferDataKey];
TPRemoteHost * host = [[TPHostsManager defaultManager] hostWithIdentifier:identifier];
if(host != nil && backgroundImageData != nil) {
NSImage * backgroundImage = [[NSImage alloc] initWithData:backgroundImageData];
[host setBackgroundImage:backgroundImage];
}
}
[super _receiverDataTransferCompleted];
}
@end