Imports instead of include
Category for NSString instead of using Utils Speed string in NSString additions
This commit is contained in:
parent
fd57b4a56f
commit
390b3e0466
|
@ -23,9 +23,9 @@
|
|||
#ifndef CONTROLLER_H
|
||||
#define CONTROLLER_H
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <transmission.h>
|
||||
#include "PrefsController.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
#import "PrefsController.h"
|
||||
|
||||
@class TorrentTableView;
|
||||
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <IOKit/IOMessage.h>
|
||||
#import <IOKit/IOMessage.h>
|
||||
|
||||
#include "NameCell.h"
|
||||
#include "ProgressCell.h"
|
||||
#include "Utils.h"
|
||||
#include "TorrentTableView.h"
|
||||
#import "NameCell.h"
|
||||
#import "ProgressCell.h"
|
||||
#import "StringAdditions.h"
|
||||
#import "Utils.h"
|
||||
#import "TorrentTableView.h"
|
||||
|
||||
#import "PrefsController.h"
|
||||
|
||||
|
@ -556,19 +557,17 @@ static void sleepCallBack( void * controller, io_service_t y,
|
|||
|
||||
//Update the global DL/UL rates
|
||||
tr_torrentRates( fHandle, &dl, &ul );
|
||||
[fTotalDLField setStringValue: [NSString stringWithFormat:
|
||||
@"Total DL: %.2f KB/s", dl]];
|
||||
[fTotalULField setStringValue: [NSString stringWithFormat:
|
||||
@"Total UL: %.2f KB/s", ul]];
|
||||
[fTotalDLField setStringValue: [NSString stringForSpeed: dl]];
|
||||
[fTotalULField setStringValue: [NSString stringForSpeed: ul]];
|
||||
|
||||
//Update DL/UL totals in the Info panel
|
||||
row = [fTableView selectedRow];
|
||||
if( row >= 0 )
|
||||
{
|
||||
[fInfoDownloaded setStringValue:
|
||||
stringForFileSize( fStat[row].downloaded )];
|
||||
[NSString stringForFileSize: fStat[row].downloaded]];
|
||||
[fInfoUploaded setStringValue:
|
||||
stringForFileSize( fStat[row].uploaded )];
|
||||
[NSString stringForFileSize: fStat[row].uploaded]];
|
||||
}
|
||||
|
||||
//check if torrents have recently ended.
|
||||
|
@ -663,11 +662,11 @@ static void sleepCallBack( void * controller, io_service_t y,
|
|||
[fInfoAnnounce setStringValue: [NSString stringWithCString:
|
||||
fStat[row].info.trackerAnnounce]];
|
||||
[fInfoSize setStringValue:
|
||||
stringForFileSize( fStat[row].info.totalSize )];
|
||||
[NSString stringForFileSize: fStat[row].info.totalSize]];
|
||||
[fInfoPieces setStringValue: [NSString stringWithFormat: @"%d",
|
||||
fStat[row].info.pieceCount]];
|
||||
[fInfoPieceSize setStringValue:
|
||||
stringForFileSize( fStat[row].info.pieceSize )];
|
||||
[NSString stringForFileSize: fStat[row].info.pieceSize]];
|
||||
[fInfoFolder setStringValue: [[NSString stringWithUTF8String:
|
||||
tr_torrentGetFolder( fHandle, row )] lastPathComponent]];
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#ifndef NAMECELL_H
|
||||
#define NAMECELL_H
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <transmission.h>
|
||||
#include "Controller.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
#import "Controller.h"
|
||||
|
||||
@interface NameCell : NSCell
|
||||
{
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "NameCell.h"
|
||||
#include "Utils.h"
|
||||
#import "NameCell.h"
|
||||
#import "StringAdditions.h"
|
||||
#import "Utils.h"
|
||||
|
||||
@implementation NameCell
|
||||
|
||||
|
@ -31,7 +32,7 @@
|
|||
|
||||
fNameString = [NSString stringWithUTF8String: stat->info.name];
|
||||
fSizeString = [NSString stringWithFormat: @" (%@)",
|
||||
stringForFileSize( stat->info.totalSize )];
|
||||
[NSString stringForFileSize: stat->info.totalSize]];
|
||||
fTimeString = @"";
|
||||
fPeersString = @"";
|
||||
|
||||
|
@ -105,9 +106,9 @@
|
|||
forKey: NSFontAttributeName];
|
||||
|
||||
pen.x += 5; pen.y += 5;
|
||||
string = [NSString stringWithFormat: @"%@%@",
|
||||
stringFittingInWidth( fNameString, cellFrame.size.width -
|
||||
35 - widthForString( fSizeString, 12 ), 12 ), fSizeString];
|
||||
string = [[fNameString stringFittingInWidth: cellFrame.size.width -
|
||||
35 - [fSizeString sizeWithAttributes: attributes].width
|
||||
withAttributes: attributes] stringByAppendingString: fSizeString];
|
||||
[string drawAtPoint: pen withAttributes: attributes];
|
||||
|
||||
[attributes setObject: [NSFont messageFontOfSize: 10.0]
|
||||
|
@ -117,8 +118,8 @@
|
|||
[fTimeString drawAtPoint: pen withAttributes: attributes];
|
||||
|
||||
pen.x += 0; pen.y += 15;
|
||||
string = stringFittingInWidth( fPeersString,
|
||||
cellFrame.size.width - 40, 10 );
|
||||
string = [fPeersString stringFittingInWidth: cellFrame.size.width -
|
||||
40 withAttributes: attributes];
|
||||
[string drawAtPoint: pen withAttributes: attributes];
|
||||
|
||||
[view unlockFocus];
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <transmission.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@interface PrefsController : NSObject
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "PrefsController.h"
|
||||
#import "PrefsController.h"
|
||||
|
||||
#define DEFAULT_UPLOAD @"20"
|
||||
#define MIN_PORT 1
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#ifndef PROGRESSCELL_H
|
||||
#define PROGRESSCELL_H
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <transmission.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@interface ProgressCell : NSCell
|
||||
{
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "ProgressCell.h"
|
||||
#import "ProgressCell.h"
|
||||
#import "StringAdditions.h"
|
||||
|
||||
@implementation ProgressCell
|
||||
|
||||
|
@ -121,10 +122,10 @@ static uint32_t kGreen[] =
|
|||
fWhiteText = w;
|
||||
|
||||
/* Update the strings to be displayed */
|
||||
fDlString = [NSString stringWithFormat:
|
||||
@"DL: %.2f KB/s", fStat->rateDownload];
|
||||
fUlString = [NSString stringWithFormat:
|
||||
@"UL: %.2f KB/s", fStat->rateUpload];
|
||||
fDlString = [@"DL: " stringByAppendingString:
|
||||
[NSString stringForSpeed: fStat->rateDownload]];
|
||||
fUlString = [@"UL: " stringByAppendingString:
|
||||
[NSString stringForSpeed: fStat->rateUpload]];
|
||||
|
||||
/* Reset our bitmap to the background image... */
|
||||
in = [fBackgroundBmp bitmapData];
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// StringAdditions.h
|
||||
// Transmission
|
||||
//
|
||||
// Created by Mitchell Livingston on 1/16/06.
|
||||
// Copyright 2006 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSString (StringAdditions)
|
||||
|
||||
+ (NSString *) stringForFileSize: (uint64_t) size;
|
||||
+ (NSString *) stringForSpeed: (float) speed;
|
||||
- (NSString *) stringFittingInWidth: (float) width
|
||||
withAttributes: (NSDictionary *) attributes;
|
||||
|
||||
@end
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// StringAdditions.m
|
||||
// Transmission
|
||||
//
|
||||
// Created by Mitchell Livingston on 1/16/06.
|
||||
// Copyright 2006 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "StringAdditions.h"
|
||||
#import "Utils.h"
|
||||
|
||||
@implementation NSString (StringAdditions)
|
||||
|
||||
+ (NSString *) stringForFileSize: (uint64_t) size
|
||||
{
|
||||
if (size < 1024)
|
||||
return [NSString stringWithFormat: @"%lld bytes", size];
|
||||
else if (size < 1048576)
|
||||
return [NSString stringWithFormat: @"%lld.%lld KB",
|
||||
size / 1024, ( size % 1024 ) / 103];
|
||||
else if (size < 1073741824)
|
||||
return [NSString stringWithFormat: @"%lld.%lld MB",
|
||||
size / 1048576, ( size % 1048576 ) / 104858];
|
||||
else
|
||||
return [NSString stringWithFormat: @"%lld.%lld GB",
|
||||
size / 1073741824, ( size % 1073741824 ) / 107374183];
|
||||
}
|
||||
|
||||
+ (NSString *) stringForSpeed: (float) speed
|
||||
{
|
||||
if (speed < 1024)
|
||||
return [NSString stringWithFormat: @"%.1f KB/s", speed];
|
||||
else if (speed < 1048576)
|
||||
return [NSString stringWithFormat: @"%.2f MB/s", speed / 1024];
|
||||
else
|
||||
return [NSString stringWithFormat: @"%.2f GB/s", speed / 1048576];
|
||||
}
|
||||
|
||||
- (NSString *) stringFittingInWidth: (float) width
|
||||
withAttributes: (NSDictionary *) attributes
|
||||
{
|
||||
NSString * newString = self;
|
||||
|
||||
unsigned i;
|
||||
for (i = [self length]; [newString sizeWithAttributes: attributes].width > width; i--)
|
||||
newString = [[self substringToIndex: i] stringByAppendingString: NS_ELLIPSIS];
|
||||
|
||||
return newString;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,5 +1,5 @@
|
|||
#include <Cocoa/Cocoa.h>
|
||||
#include <transmission.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@class Controller;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "TorrentTableView.h"
|
||||
#include "Controller.h"
|
||||
#import "TorrentTableView.h"
|
||||
#import "Controller.h"
|
||||
|
||||
@implementation TorrentTableView
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
4DA6FDBB0911233800450CB1 /* PauseOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDB90911233800450CB1 /* PauseOff.png */; };
|
||||
4DA6FDC5091141AD00450CB1 /* ResumeOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC3091141AD00450CB1 /* ResumeOff.png */; };
|
||||
4DA6FDC6091141AD00450CB1 /* ResumeOn.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC4091141AD00450CB1 /* ResumeOn.png */; };
|
||||
4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DE5CC9C0980656F00BE280E /* StringAdditions.m */; };
|
||||
4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; };
|
||||
4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; };
|
||||
4DF7500C08A103AD007B0D70 /* Open.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500708A103AD007B0D70 /* Open.png */; };
|
||||
|
@ -90,6 +91,8 @@
|
|||
4DA6FDB90911233800450CB1 /* PauseOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseOff.png; path = Images/PauseOff.png; sourceTree = "<group>"; };
|
||||
4DA6FDC3091141AD00450CB1 /* ResumeOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeOff.png; path = Images/ResumeOff.png; sourceTree = "<group>"; };
|
||||
4DA6FDC4091141AD00450CB1 /* ResumeOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeOn.png; path = Images/ResumeOn.png; sourceTree = "<group>"; };
|
||||
4DE5CC9B0980656F00BE280E /* StringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StringAdditions.h; sourceTree = "<group>"; };
|
||||
4DE5CC9C0980656F00BE280E /* StringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = StringAdditions.m; sourceTree = "<group>"; };
|
||||
4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
|
||||
4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
|
||||
4DF0C5AD08991C1600DD8943 /* libtransmission.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtransmission.a; path = ../libtransmission/libtransmission.a; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -127,6 +130,8 @@
|
|||
4D118E1908CB46B20033958F /* PrefsController.m */,
|
||||
4D364D9E091FBB2C00377D12 /* TorrentTableView.h */,
|
||||
4D364D9F091FBB2C00377D12 /* TorrentTableView.m */,
|
||||
4DE5CC9B0980656F00BE280E /* StringAdditions.h */,
|
||||
4DE5CC9C0980656F00BE280E /* StringAdditions.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
|
@ -303,6 +308,7 @@
|
|||
4D096C13089FB4E20091B166 /* ProgressCell.m in Sources */,
|
||||
4D118E1A08CB46B20033958F /* PrefsController.m in Sources */,
|
||||
4D364DA0091FBB2C00377D12 /* TorrentTableView.m in Sources */,
|
||||
4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -20,54 +20,4 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
static NSString * stringForFileSize( uint64_t size )
|
||||
{
|
||||
if( size < 1024 )
|
||||
{
|
||||
return [NSString stringWithFormat: @"%lld bytes", size];
|
||||
}
|
||||
if( size < 1048576 )
|
||||
{
|
||||
return [NSString stringWithFormat: @"%lld.%lld KB",
|
||||
size / 1024, ( size % 1024 ) / 103];
|
||||
}
|
||||
if( size < 1073741824 )
|
||||
{
|
||||
return [NSString stringWithFormat: @"%lld.%lld MB",
|
||||
size / 1048576, ( size % 1048576 ) / 104858];
|
||||
}
|
||||
return [NSString stringWithFormat: @"%lld.%lld GB",
|
||||
size / 1073741824, ( size % 1073741824 ) / 107374183];
|
||||
}
|
||||
|
||||
static float widthForString( NSString * string, float fontSize )
|
||||
{
|
||||
NSMutableDictionary * attributes =
|
||||
[NSMutableDictionary dictionaryWithCapacity: 1];
|
||||
[attributes setObject: [NSFont messageFontOfSize: fontSize]
|
||||
forKey: NSFontAttributeName];
|
||||
|
||||
return [string sizeWithAttributes: attributes].width;
|
||||
}
|
||||
|
||||
#define NS_ELLIPSIS [NSString stringWithUTF8String: "\xE2\x80\xA6"]
|
||||
|
||||
static NSString * stringFittingInWidth( NSString * oldString, float width,
|
||||
float fontSize )
|
||||
{
|
||||
NSString * newString = NULL;
|
||||
unsigned i;
|
||||
|
||||
for( i = 0; i < [oldString length]; i++ )
|
||||
{
|
||||
newString = [NSString stringWithFormat: @"%@%@",
|
||||
[oldString substringToIndex: [oldString length] - i],
|
||||
i ? NS_ELLIPSIS : @""];
|
||||
|
||||
if( widthForString( newString, fontSize ) <= width )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return newString;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue