Changeset 34
- Timestamp:
- Jan 20, 2006, 1:13:21 AM (16 years ago)
- Location:
- trunk/macosx
- Files:
-
- 1 added
- 13 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.h
r19 r34 24 24 #define CONTROLLER_H 25 25 26 #i nclude<Cocoa/Cocoa.h>27 #i nclude<transmission.h>28 #i nclude"PrefsController.h"26 #import <Cocoa/Cocoa.h> 27 #import <transmission.h> 28 #import "PrefsController.h" 29 29 30 30 @class TorrentTableView; -
trunk/macosx/Controller.m
r29 r34 21 21 *****************************************************************************/ 22 22 23 #include <IOKit/IOMessage.h> 24 25 #include "NameCell.h" 26 #include "ProgressCell.h" 27 #include "Utils.h" 28 #include "TorrentTableView.h" 23 #import <IOKit/IOMessage.h> 24 25 #import "NameCell.h" 26 #import "ProgressCell.h" 27 #import "StringAdditions.h" 28 #import "Utils.h" 29 #import "TorrentTableView.h" 29 30 30 31 #import "PrefsController.h" … … 557 558 //Update the global DL/UL rates 558 559 tr_torrentRates( fHandle, &dl, &ul ); 559 [fTotalDLField setStringValue: [NSString stringWithFormat: 560 @"Total DL: %.2f KB/s", dl]]; 561 [fTotalULField setStringValue: [NSString stringWithFormat: 562 @"Total UL: %.2f KB/s", ul]]; 560 [fTotalDLField setStringValue: [NSString stringForSpeed: dl]]; 561 [fTotalULField setStringValue: [NSString stringForSpeed: ul]]; 563 562 564 563 //Update DL/UL totals in the Info panel … … 567 566 { 568 567 [fInfoDownloaded setStringValue: 569 stringForFileSize( fStat[row].downloaded )];568 [NSString stringForFileSize: fStat[row].downloaded]]; 570 569 [fInfoUploaded setStringValue: 571 stringForFileSize( fStat[row].uploaded )];570 [NSString stringForFileSize: fStat[row].uploaded]]; 572 571 } 573 572 … … 664 663 fStat[row].info.trackerAnnounce]]; 665 664 [fInfoSize setStringValue: 666 stringForFileSize( fStat[row].info.totalSize )];665 [NSString stringForFileSize: fStat[row].info.totalSize]]; 667 666 [fInfoPieces setStringValue: [NSString stringWithFormat: @"%d", 668 667 fStat[row].info.pieceCount]]; 669 668 [fInfoPieceSize setStringValue: 670 stringForFileSize( fStat[row].info.pieceSize )];669 [NSString stringForFileSize: fStat[row].info.pieceSize]]; 671 670 [fInfoFolder setStringValue: [[NSString stringWithUTF8String: 672 671 tr_torrentGetFolder( fHandle, row )] lastPathComponent]]; -
trunk/macosx/NameCell.h
r15 r34 24 24 #define NAMECELL_H 25 25 26 #i nclude<Cocoa/Cocoa.h>27 #i nclude<transmission.h>28 #i nclude"Controller.h"26 #import <Cocoa/Cocoa.h> 27 #import <transmission.h> 28 #import "Controller.h" 29 29 30 30 @interface NameCell : NSCell -
trunk/macosx/NameCell.m
r15 r34 21 21 *****************************************************************************/ 22 22 23 #include "NameCell.h" 24 #include "Utils.h" 23 #import "NameCell.h" 24 #import "StringAdditions.h" 25 #import "Utils.h" 25 26 26 27 @implementation NameCell … … 32 33 fNameString = [NSString stringWithUTF8String: stat->info.name]; 33 34 fSizeString = [NSString stringWithFormat: @" (%@)", 34 stringForFileSize( stat->info.totalSize )];35 [NSString stringForFileSize: stat->info.totalSize]]; 35 36 fTimeString = @""; 36 37 fPeersString = @""; … … 106 107 107 108 pen.x += 5; pen.y += 5; 108 string = [ NSString stringWithFormat: @"%@%@",109 stringFittingInWidth( fNameString, cellFrame.size.width -110 35 - widthForString( fSizeString, 12 ), 12 ),fSizeString];109 string = [[fNameString stringFittingInWidth: cellFrame.size.width - 110 35 - [fSizeString sizeWithAttributes: attributes].width 111 withAttributes: attributes] stringByAppendingString: fSizeString]; 111 112 [string drawAtPoint: pen withAttributes: attributes]; 112 113 … … 118 119 119 120 pen.x += 0; pen.y += 15; 120 string = stringFittingInWidth( fPeersString,121 cellFrame.size.width - 40, 10 );121 string = [fPeersString stringFittingInWidth: cellFrame.size.width - 122 40 withAttributes: attributes]; 122 123 [string drawAtPoint: pen withAttributes: attributes]; 123 124 -
trunk/macosx/PrefsController.h
r20 r34 21 21 *****************************************************************************/ 22 22 23 #i nclude<Cocoa/Cocoa.h>24 #i nclude<transmission.h>23 #import <Cocoa/Cocoa.h> 24 #import <transmission.h> 25 25 26 26 @interface PrefsController : NSObject -
trunk/macosx/PrefsController.m
r20 r34 21 21 *****************************************************************************/ 22 22 23 #i nclude"PrefsController.h"23 #import "PrefsController.h" 24 24 25 25 #define DEFAULT_UPLOAD @"20" -
trunk/macosx/ProgressCell.h
r15 r34 24 24 #define PROGRESSCELL_H 25 25 26 #i nclude<Cocoa/Cocoa.h>27 #i nclude<transmission.h>26 #import <Cocoa/Cocoa.h> 27 #import <transmission.h> 28 28 29 29 @interface ProgressCell : NSCell -
trunk/macosx/ProgressCell.m
r25 r34 21 21 *****************************************************************************/ 22 22 23 #include "ProgressCell.h" 23 #import "ProgressCell.h" 24 #import "StringAdditions.h" 24 25 25 26 @implementation ProgressCell … … 122 123 123 124 /* Update the strings to be displayed */ 124 fDlString = [ NSString stringWithFormat:125 @"DL: %.2f KB/s", fStat->rateDownload];126 fUlString = [ NSString stringWithFormat:127 @"UL: %.2f KB/s", fStat->rateUpload];125 fDlString = [@"DL: " stringByAppendingString: 126 [NSString stringForSpeed: fStat->rateDownload]]; 127 fUlString = [@"UL: " stringByAppendingString: 128 [NSString stringForSpeed: fStat->rateUpload]]; 128 129 129 130 /* Reset our bitmap to the background image... */ -
trunk/macosx/StringAdditions.m
r33 r34 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 *****************************************************************************/ 1 // 2 // StringAdditions.m 3 // Transmission 4 // 5 // Created by Mitchell Livingston on 1/16/06. 6 // Copyright 2006 __MyCompanyName__. All rights reserved. 7 // 22 8 23 static NSString * stringForFileSize( uint64_t size ) 9 #import "StringAdditions.h" 10 #import "Utils.h" 11 12 @implementation NSString (StringAdditions) 13 14 + (NSString *) stringForFileSize: (uint64_t) size 24 15 { 25 if( size < 1024 ) 26 { 16 if (size < 1024) 27 17 return [NSString stringWithFormat: @"%lld bytes", size]; 28 } 29 if( size < 1048576 ) 30 { 18 else if (size < 1048576) 31 19 return [NSString stringWithFormat: @"%lld.%lld KB", 32 20 size / 1024, ( size % 1024 ) / 103]; 33 } 34 if( size < 1073741824 ) 35 { 21 else if (size < 1073741824) 36 22 return [NSString stringWithFormat: @"%lld.%lld MB", 37 23 size / 1048576, ( size % 1048576 ) / 104858]; 38 }39 return [NSString stringWithFormat: @"%lld.%lld GB",40 size / 1073741824, ( size % 1073741824 ) / 107374183];24 else 25 return [NSString stringWithFormat: @"%lld.%lld GB", 26 size / 1073741824, ( size % 1073741824 ) / 107374183]; 41 27 } 42 28 43 static float widthForString( NSString * string, float fontSize ) 29 + (NSString *) stringForSpeed: (float) speed 44 30 { 45 NSMutableDictionary * attributes =46 [NSMutableDictionary dictionaryWithCapacity: 1];47 [attributes setObject: [NSFont messageFontOfSize: fontSize]48 forKey: NSFontAttributeName];49 50 return [string sizeWithAttributes: attributes].width;31 if (speed < 1024) 32 return [NSString stringWithFormat: @"%.1f KB/s", speed]; 33 else if (speed < 1048576) 34 return [NSString stringWithFormat: @"%.2f MB/s", speed / 1024]; 35 else 36 return [NSString stringWithFormat: @"%.2f GB/s", speed / 1048576]; 51 37 } 52 38 53 #define NS_ELLIPSIS [NSString stringWithUTF8String: "\xE2\x80\xA6"] 54 55 static NSString * stringFittingInWidth( NSString * oldString, float width, 56 float fontSize ) 39 - (NSString *) stringFittingInWidth: (float) width 40 withAttributes: (NSDictionary *) attributes 57 41 { 58 NSString * newString = NULL; 59 unsigned i; 60 61 for( i = 0; i < [oldString length]; i++ ) 62 { 63 newString = [NSString stringWithFormat: @"%@%@", 64 [oldString substringToIndex: [oldString length] - i], 65 i ? NS_ELLIPSIS : @""]; 66 67 if( widthForString( newString, fontSize ) <= width ) 68 { 69 break; 70 } 71 } 42 NSString * newString = self; 43 44 unsigned i; 45 for (i = [self length]; [newString sizeWithAttributes: attributes].width > width; i--) 46 newString = [[self substringToIndex: i] stringByAppendingString: NS_ELLIPSIS]; 47 72 48 return newString; 73 49 } 50 51 @end -
trunk/macosx/TorrentTableView.h
r19 r34 1 #i nclude<Cocoa/Cocoa.h>2 #i nclude<transmission.h>1 #import <Cocoa/Cocoa.h> 2 #import <transmission.h> 3 3 4 4 @class Controller; -
trunk/macosx/TorrentTableView.m
r19 r34 1 #i nclude"TorrentTableView.h"2 #i nclude"Controller.h"1 #import "TorrentTableView.h" 2 #import "Controller.h" 3 3 4 4 @implementation TorrentTableView -
trunk/macosx/Transmission.xcodeproj/project.pbxproj
r19 r34 24 24 4DA6FDC5091141AD00450CB1 /* ResumeOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC3091141AD00450CB1 /* ResumeOff.png */; }; 25 25 4DA6FDC6091141AD00450CB1 /* ResumeOn.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC4091141AD00450CB1 /* ResumeOn.png */; }; 26 4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DE5CC9C0980656F00BE280E /* StringAdditions.m */; }; 26 27 4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; }; 27 28 4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; }; … … 91 92 4DA6FDC3091141AD00450CB1 /* ResumeOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeOff.png; path = Images/ResumeOff.png; sourceTree = "<group>"; }; 92 93 4DA6FDC4091141AD00450CB1 /* ResumeOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeOn.png; path = Images/ResumeOn.png; sourceTree = "<group>"; }; 94 4DE5CC9B0980656F00BE280E /* StringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StringAdditions.h; sourceTree = "<group>"; }; 95 4DE5CC9C0980656F00BE280E /* StringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = StringAdditions.m; sourceTree = "<group>"; }; 93 96 4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; }; 94 97 4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; }; … … 128 131 4D364D9E091FBB2C00377D12 /* TorrentTableView.h */, 129 132 4D364D9F091FBB2C00377D12 /* TorrentTableView.m */, 133 4DE5CC9B0980656F00BE280E /* StringAdditions.h */, 134 4DE5CC9C0980656F00BE280E /* StringAdditions.m */, 130 135 ); 131 136 name = Classes; … … 304 309 4D118E1A08CB46B20033958F /* PrefsController.m in Sources */, 305 310 4D364DA0091FBB2C00377D12 /* TorrentTableView.m in Sources */, 311 4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */, 306 312 ); 307 313 runOnlyForDeploymentPostprocessing = 0; -
trunk/macosx/Utils.h
r3 r34 21 21 *****************************************************************************/ 22 22 23 static NSString * stringForFileSize( uint64_t size )24 {25 if( size < 1024 )26 {27 return [NSString stringWithFormat: @"%lld bytes", size];28 }29 if( size < 1048576 )30 {31 return [NSString stringWithFormat: @"%lld.%lld KB",32 size / 1024, ( size % 1024 ) / 103];33 }34 if( size < 1073741824 )35 {36 return [NSString stringWithFormat: @"%lld.%lld MB",37 size / 1048576, ( size % 1048576 ) / 104858];38 }39 return [NSString stringWithFormat: @"%lld.%lld GB",40 size / 1073741824, ( size % 1073741824 ) / 107374183];41 }42 43 static float widthForString( NSString * string, float fontSize )44 {45 NSMutableDictionary * attributes =46 [NSMutableDictionary dictionaryWithCapacity: 1];47 [attributes setObject: [NSFont messageFontOfSize: fontSize]48 forKey: NSFontAttributeName];49 50 return [string sizeWithAttributes: attributes].width;51 }52 53 23 #define NS_ELLIPSIS [NSString stringWithUTF8String: "\xE2\x80\xA6"] 54 55 static NSString * stringFittingInWidth( NSString * oldString, float width,56 float fontSize )57 {58 NSString * newString = NULL;59 unsigned i;60 61 for( i = 0; i < [oldString length]; i++ )62 {63 newString = [NSString stringWithFormat: @"%@%@",64 [oldString substringToIndex: [oldString length] - i],65 i ? NS_ELLIPSIS : @""];66 67 if( widthForString( newString, fontSize ) <= width )68 {69 break;70 }71 }72 return newString;73 } -
trunk/macosx/main.m
r1 r34 21 21 *****************************************************************************/ 22 22 23 #i nclude<Cocoa/Cocoa.h>23 #import <Cocoa/Cocoa.h> 24 24 25 25 int main( int argc, char ** argv )
Note: See TracChangeset
for help on using the changeset viewer.