-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPBezelController.m
129 lines (102 loc) · 2.98 KB
/
TPBezelController.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
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
//
// TPBezelController.m
// teleport
//
// Created by JuL on 27/07/05.
// Copyright 2005 abyssoft. All rights reserved.
//
#import "TPBezelController.h"
#import "TPBezelWindow.h"
#import "TPBezelView.h"
#import "TPTransfersManager.h"
#import "TPTransfer.h"
#import "TPRemoteHost.h"
#define TEXT_DURATION 5.0
static TPBezelController * _defaultController = nil;
@implementation TPBezelController
+ (TPBezelController*)defaultController
{
if(_defaultController == nil)
_defaultController = [[TPBezelController alloc] init];
return _defaultController;
}
- (instancetype) init
{
self = [super init];
_bezelWindow = nil;
_bezelView = nil;
_textTimer = nil;
return self;
}
- (void)showBezelWithControlledHost:(TPRemoteHost*)host
{
NSRect localFrame = [[host localScreen] frame];
if(_bezelWindow == nil) {
_bezelWindow = [[TPBezelWindow alloc] initWithContentRect:localFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
_bezelView = [[TPBezelView alloc] init];
[_bezelWindow setContentView:_bezelView];
}
[_bezelView setRemoteHost:host];
[_bezelView setShowProgress:NO];
[_bezelWindow orderFront:nil];
[_bezelWindow orderFrontRegardless];
if([_bezelWindow respondsToSelector:@selector(setCollectionBehavior:)]) {
[_bezelWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorStationary];
}
}
- (void)hideBezel
{
[_bezelWindow orderOut:self];
if(_textTimer != nil) {
[_textTimer invalidate];
_textTimer = nil;
}
[_bezelView setText:nil];
}
- (void)showText:(NSString*)text withDuration:(NSTimeInterval)duration
{
[_bezelView setText:text];
if(_textTimer != nil)
[_textTimer invalidate];
_textTimer = [NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(_removeText:) userInfo:nil repeats:NO];
}
- (void)_removeText:(NSTimer*)timer
{
[_bezelView setText:nil];
_textTimer = nil;
}
#pragma mark -
#pragma mark TPTransfersManager delegate
- (void)transfersManager:(TPTransfersManager*)transfersManager beginNewTransfer:(TPTransfer*)transfer
{
if(![transfer isIncoming]) {
[_bezelView setShowProgress:YES];
[_bezelView setProgress:0.0];
}
}
- (void)transfersManager:(TPTransfersManager*)transfersManager transfer:(TPTransfer*)transfer didProgress:(float)progress
{
if(![transfer isIncoming]) {
[_bezelView setShowProgress:YES];
[_bezelView setProgress:progress];
}
}
- (void)transfersManager:(TPTransfersManager*)transfersManager completeTransfer:(TPTransfer*)transfer
{
if(![transfer isIncoming]) {
[_bezelView setShowProgress:NO];
NSString * message = [transfer completionMessage];
if(message != nil)
[self showText:message withDuration:TEXT_DURATION];
}
}
- (void)transfersManager:(TPTransfersManager*)transfersManager cancelTransfer:(TPTransfer*)transfer
{
if(![transfer isIncoming]) {
[_bezelView setShowProgress:NO];
NSString * message = [transfer errorMessage];
if(message != nil)
[self showText:message withDuration:TEXT_DURATION];
}
}
@end