William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "ESFileTransferProgressRow.h"
#import "ESFileTransferProgressView.h"
#import <AIUtilities/AIParagraphStyleAdditions.h>
#import <AIUtilities/AIRolloverButton.h>
#import <AIUtilities/AIImageAdditions.h>
#import <AIUtilities/AIStringAdditions.h>
#define NORMAL_TEXT_COLOR [NSColor controlTextColor]
#define SELECTED_TEXT_COLOR [NSColor whiteColor]
#define TRANSFER_STATUS_COLOR [NSColor disabledControlTextColor]
@interface ESFileTransferProgressView ()
- (void)updateButtonReveal;
- (void)updateButtonStopResume;
@end
@implementation ESFileTransferProgressView
- (void)awakeFromNib
{
if ([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) {
[super awakeFromNib];
}
[progressIndicator setUsesThreadedAnimation:YES];
[progressIndicator setIndeterminate:YES];
progressVisible = YES;
showingDetails = NO;
[view_details retain];
[button_stopResume setDelegate:self];
[button_reveal setDelegate:self];
buttonStopResumeIsHovered = NO;
buttonStopResumeIsResend = NO;
buttonRevealIsHovered = NO;
}
- (void)dealloc
{
[view_details release];
[super dealloc];
}
#pragma mark Source and destination
- (void)setSourceName:(NSString *)inSourceName
{
[textField_source setStringValue:(inSourceName ? inSourceName : @"")];
}
- (void)setSourceIcon:(NSImage *)inSourceIcon
{
[imageView_source setImage:inSourceIcon];
}
- (void)setDestinationName:(NSString *)inDestinationName
{
[textField_destination setStringValue:(inDestinationName ? inDestinationName : @"")];
}
- (void)setDestinationIcon:(NSImage *)inDestinationIcon
{
[imageView_destination setImage:inDestinationIcon];
}
#pragma mark File and its icon
- (void)setFileName:(NSString *)inFileName
{
[textField_fileName setStringValue:(inFileName ?
inFileName :
[AILocalizedString(@"Initializing transfer",nil) stringByAppendingEllipsis])];
}
- (void)setIconImage:(NSImage *)inIconImage
{
[button_icon setImage:inIconImage];
}
#pragma mark Progress
- (void)setProgressDoubleValue:(double)inPercent
{
[progressIndicator setDoubleValue:inPercent];
}
- (void)setProgressIndeterminate:(BOOL)flag
{
[progressIndicator setIndeterminate:flag];
}
- (void)setProgressAnimation:(BOOL)flag
{
if (flag) {
[progressIndicator startAnimation:self];
} else {
[progressIndicator stopAnimation:self];
}
}
- (void)setProgressVisible:(BOOL)flag
{
if (flag != progressVisible) {
progressVisible = flag;
if (progressVisible) {
//Redisplay the progress bar. We never do this at present, so unimplemented for now.
} else {
NSRect progressRect = [progressIndicator frame];
NSRect frame;
CGFloat distanceToMove = progressRect.size.height / 2;
[progressIndicator setDisplayedWhenStopped:NO];
[progressIndicator setIndeterminate:YES];
[progressIndicator stopAnimation:self];
[progressIndicator setHidden:YES];
//Top objects moving down
{
frame = [textField_fileName frame];
frame.origin.y -= distanceToMove;
//Don't let it be any further right than the progress bar used to be to avoid our buttons
frame.size.width = (progressRect.origin.x + progressRect.size.width) - frame.origin.x;
[textField_fileName setFrame:frame];
}
//Bottom objects moving up
{
frame = [twiddle_details frame];
frame.origin.y += distanceToMove;
[twiddle_details setFrame:frame];
frame = [textField_detailsLabel frame];
frame.origin.y += distanceToMove;
[textField_detailsLabel setFrame:frame];
frame = [box_transferStatusFrame frame];
frame.origin.y += distanceToMove;
//Don't let it be any further right than the progress bar used to be to avoid our buttons
frame.size.width = (progressRect.origin.x + progressRect.size.width) - frame.origin.x;
[box_transferStatusFrame setFrame:frame];
}
}
}
}
- (void)setButtonStopResumeVisible:(BOOL)flag
{
[button_stopResume setHidden:!flag];
}
- (void)setButtonStopResumeIsResend:(BOOL)flag
{
buttonStopResumeIsResend = flag;
[self updateButtonStopResume];
}
- (BOOL)buttonStopResumeIsResend
{
return buttonStopResumeIsResend;
}
- (void)setTransferBytesStatus:(NSString *)inTransferBytesStatus
remainingStatus:(NSString *)inTransferRemainingStatus
speedStatus:(NSString *)inTransferSpeedStatus
{
[transferStatus release];
if (inTransferBytesStatus && inTransferRemainingStatus) {
transferStatus = [NSString stringWithFormat:@"%@ - %@",
inTransferBytesStatus,
inTransferRemainingStatus];
} else if (inTransferBytesStatus) {
transferStatus = inTransferBytesStatus;
} else if (inTransferRemainingStatus) {
transferStatus = inTransferRemainingStatus;
} else {
transferStatus = @"";
}
[transferStatus retain];
// [textField_transferStatus setStringValue:transferStatus];
[self setNeedsDisplayInRect:[box_transferStatusFrame frame]];
[textField_rate setStringValue:(inTransferSpeedStatus ? inTransferSpeedStatus : @"")];
}
#pragma mark Details
//Sent when the details twiddle is clicked
- (IBAction)toggleDetails:(id)sender
{
NSRect detailsFrame = [view_details frame];
NSRect primaryControlsFrame = [box_primaryControls frame];
NSRect oldFrame = [self frame];
NSRect newFrame = oldFrame;
showingDetails = !showingDetails;
if (showingDetails) {
//Increase our height to make space
newFrame.size.height += detailsFrame.size.height;
newFrame.origin.y -= detailsFrame.size.height;
[self setFrame:newFrame];
//Move the box with our primary controls up
primaryControlsFrame.origin.y += detailsFrame.size.height;
[box_primaryControls setFrame:primaryControlsFrame];
//Add the details subview
[self addSubview:view_details];
//Line up the details frame with the twiddle which revealed it
detailsFrame.origin.x = [twiddle_details frame].origin.x;
detailsFrame.origin.y = 0;
[view_details setFrame:detailsFrame];
//Update the twiddle
[twiddle_details setState:NSOnState];
} else {
newFrame.size.height -= detailsFrame.size.height;
newFrame.origin.y += detailsFrame.size.height;
[self setFrame:newFrame];
//Move the box with our primary controls back down
primaryControlsFrame.origin.y -= detailsFrame.size.height;
[box_primaryControls setFrame:primaryControlsFrame];
[view_details removeFromSuperview];
//Update the twiddle
[twiddle_details setState:NSOffState];
}
//Let the owner know our height changed so other rows can be adjusted accordingly
[owner fileTransferProgressView:self
heightChangedFrom:oldFrame.size.height
to:newFrame.size.height];
}
- (void)setShowsDetails:(BOOL)flag
{
if (showingDetails != flag) {
[self toggleDetails:nil];
}
}
- (void)setAllowsCancel:(BOOL)flag
{
[button_stopResume setEnabled:flag];
}
- (void)updateColors
{
NSColor *newColor;
if (isSelected && [[self window] isKeyWindow]) {
newColor = SELECTED_TEXT_COLOR;
} else {
newColor = NORMAL_TEXT_COLOR;
}
[textField_rate setTextColor:newColor];
[textField_source setTextColor:newColor];
[textField_destination setTextColor:newColor];
[textField_fileName setTextColor:newColor];
[textField_detailsLabel setTextColor:newColor];
[self updateButtonStopResume];
[self updateButtonReveal];
[self setNeedsDisplay:YES];
}
- (void)windowDidChangeKey:(NSNotification *)notification
{
[self updateColors];
}
- (void)viewDidMoveToWindow
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowDidBecomeKeyNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowDidResignKeyNotification
object:nil];
if ([self window]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidChangeKey:)
name:NSWindowDidBecomeKeyNotification
object:[self window]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidChangeKey:)
name:NSWindowDidResignKeyNotification
object:[self window]];
}
}
#pragma mark Selection
- (void)setIsHighlighted:(BOOL)flag
{
if (isSelected != flag) {
isSelected = flag;
[self updateButtonStopResume];
[self updateColors];
}
}
- (void)updateButtonStopResume
{
if (buttonStopResumeIsResend) {
[button_stopResume setKeyEquivalent:@""];
if (isSelected) {
[button_stopResume setImage:[NSImage imageNamed:(buttonStopResumeIsHovered ? @"FTProgressResendRollover_Selected" : @"FTProgressResend_Selected")
forClass:[self class]]];
[button_stopResume setAlternateImage:[NSImage imageNamed:@"FTProgressResendPressed_Selected" forClass:[self class]]];
} else {
[button_stopResume setImage:[NSImage imageNamed:(buttonStopResumeIsHovered ? @"FTProgressResendRollover" : @"FTProgressResend")
forClass:[self class]]];
[button_stopResume setAlternateImage:[NSImage imageNamed:@"FTProgressResendPressed" forClass:[self class]]];
}
} else {
if (isSelected) {
[button_stopResume setKeyEquivalent:@"."];
[button_stopResume setKeyEquivalentModifierMask:NSCommandKeyMask];
[button_stopResume setImage:[NSImage imageNamed:(buttonStopResumeIsHovered ? @"FTProgressStopRollover_Selected" : @"FTProgressStop_Selected")
forClass:[self class]]];
[button_stopResume setAlternateImage:[NSImage imageNamed:@"FTProgressStopPressed_Selected" forClass:[self class]]];
} else {
[button_stopResume setKeyEquivalent:@""];
[button_stopResume setImage:[NSImage imageNamed:(buttonStopResumeIsHovered ? @"FTProgressStopRollover" : @"FTProgressStop")
forClass:[self class]]];
[button_stopResume setAlternateImage:[NSImage imageNamed:@"FTProgressStopPressed" forClass:[self class]]];
}
}
}
- (void)updateButtonReveal
{
if (isSelected) {
[button_reveal setImage:[NSImage imageNamed:(buttonRevealIsHovered ? @"FTProgressRevealRollover_Selected" : @"FTProgressReveal_Selected")
forClass:[self class]]];
[button_reveal setAlternateImage:[NSImage imageNamed:@"FTProgressRevealPressed_Selected" forClass:[self class]]];
} else {
[button_reveal setImage:[NSImage imageNamed:(buttonRevealIsHovered ? @"FTProgressRevealRollover" : @"FTProgressReveal")
forClass:[self class]]];
[button_reveal setAlternateImage:[NSImage imageNamed:@"FTProgressRevealPressed" forClass:[self class]]];
}
}
- (void)rolloverButton:(AIRolloverButton *)inButton mouseChangedToInsideButton:(BOOL)isInside
{
if (inButton == button_stopResume) {
buttonStopResumeIsHovered = isInside;
[self updateButtonStopResume];
} else if (inButton == button_reveal) {
buttonRevealIsHovered = isInside;
[self updateButtonReveal];
}
}
static NSDictionary *transferStatusAttributes = nil;
static NSDictionary *transferStatusSelectedAttributes = nil;
//Draw the transfer status after other views draw. This lets us use custom drawing behavior including the
//NSLineBreakByTruncatingTail paragraph style. We draw into a frame reserved for us by box_transferStatusFrame;
//this lets us not worry about autosizing and positioning since the view takes care of that for us.
- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
NSDictionary *attributes;
NSRect primaryControlsRect = [box_primaryControls frame];
NSRect targetRect = [box_transferStatusFrame frame];
targetRect.origin.x += primaryControlsRect.origin.x;
targetRect.origin.y += primaryControlsRect.origin.y;
if (isSelected && [[self window] isKeyWindow]) {
if (!transferStatusSelectedAttributes) {
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle styleWithAlignment:NSLeftTextAlignment
lineBreakMode:NSLineBreakByTruncatingTail];
[paragraphStyle setMaximumLineHeight:[box_transferStatusFrame frame].size.height];
transferStatusSelectedAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
paragraphStyle, NSParagraphStyleAttributeName,
[NSFont systemFontOfSize:9], NSFontAttributeName,
SELECTED_TEXT_COLOR, NSForegroundColorAttributeName, nil] retain];
}
attributes = transferStatusSelectedAttributes;
} else {
if (!transferStatusAttributes) {
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle styleWithAlignment:NSLeftTextAlignment
lineBreakMode:NSLineBreakByTruncatingTail];
[paragraphStyle setMaximumLineHeight:[box_transferStatusFrame frame].size.height];
transferStatusAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
paragraphStyle, NSParagraphStyleAttributeName,
[NSFont systemFontOfSize:9], NSFontAttributeName,
TRANSFER_STATUS_COLOR, NSForegroundColorAttributeName, nil] retain];
}
attributes = transferStatusAttributes;
}
[transferStatus drawInRect:targetRect
withAttributes:attributes];
}
#pragma mark Menu
- (NSMenu *)menuForEvent:(NSEvent *)inEvent
{
return [owner menuForEvent:inEvent];
}
#pragma mark Accessibility
- (id)accessibilityAttributeValue:(NSString *)attribute
{
id value;
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
value = NSAccessibilityRowRole;
} else if ([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
if (![progressIndicator isIndeterminate]) {
//We are in the concrete phase of an active transfer
value = [NSString stringWithFormat:
AILocalizedString(@"Transferring %@ from %@ to %@ at %@ : %@", "e.g: Transferring file.zip from Evan to Joel at 45 kb/sec : 5 minutes remaining. Keep the spaces around the colon."),
[textField_fileName stringValue],
[textField_source stringValue],
[textField_destination stringValue],
[textField_rate stringValue],
(transferStatus ? transferStatus : @"")];
} else {
value = [NSString stringWithFormat:
AILocalizedString(@"Transfer of %@ from %@ to %@ : %@", "e.g: Transfer of file.zip from Evan to Joel : Upload complete. Keep the spaces around the colon"),
[textField_fileName stringValue],
[textField_source stringValue],
[textField_destination stringValue],
(transferStatus ? transferStatus : @"")];
}
} else if ([attribute isEqualToString:NSAccessibilityTitleAttribute]) {
value = AILocalizedString(@"File transfer", nil);
} else if ([attribute isEqualToString:NSAccessibilityEnabledAttribute]) {
//Never report as disabled, so we don't say 'dimmed' all the time
value = [NSNumber numberWithBool:YES];
} else {
value = [super accessibilityAttributeValue:attribute];
}
return value;
}
@end
|