Changeset 34


Ignore:
Timestamp:
Jan 20, 2006, 1:13:21 AM (15 years ago)
Author:
titer
Message:

Imports instead of include
Category for NSString instead of using Utils
Speed string in NSString additions

Location:
trunk/macosx
Files:
1 added
13 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r19 r34  
    2424#define CONTROLLER_H
    2525
    26 #include <Cocoa/Cocoa.h>
    27 #include <transmission.h>
    28 #include "PrefsController.h"
     26#import <Cocoa/Cocoa.h>
     27#import <transmission.h>
     28#import "PrefsController.h"
    2929
    3030@class TorrentTableView;
  • trunk/macosx/Controller.m

    r29 r34  
    2121 *****************************************************************************/
    2222
    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"
    2930
    3031#import "PrefsController.h"
     
    557558    //Update the global DL/UL rates
    558559    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]];
    563562
    564563    //Update DL/UL totals in the Info panel
     
    567566    {
    568567        [fInfoDownloaded setStringValue:
    569             stringForFileSize( fStat[row].downloaded )];
     568            [NSString stringForFileSize: fStat[row].downloaded]];
    570569        [fInfoUploaded setStringValue:
    571             stringForFileSize( fStat[row].uploaded )];
     570            [NSString stringForFileSize: fStat[row].uploaded]];
    572571    }
    573572   
     
    664663        fStat[row].info.trackerAnnounce]];
    665664    [fInfoSize setStringValue:
    666         stringForFileSize( fStat[row].info.totalSize )];
     665        [NSString stringForFileSize: fStat[row].info.totalSize]];
    667666    [fInfoPieces setStringValue: [NSString stringWithFormat: @"%d",
    668667        fStat[row].info.pieceCount]];
    669668    [fInfoPieceSize setStringValue:
    670         stringForFileSize( fStat[row].info.pieceSize )];
     669        [NSString stringForFileSize: fStat[row].info.pieceSize]];
    671670    [fInfoFolder setStringValue: [[NSString stringWithUTF8String:
    672671        tr_torrentGetFolder( fHandle, row )] lastPathComponent]];
  • trunk/macosx/NameCell.h

    r15 r34  
    2424#define NAMECELL_H
    2525
    26 #include <Cocoa/Cocoa.h>
    27 #include <transmission.h>
    28 #include "Controller.h"
     26#import <Cocoa/Cocoa.h>
     27#import <transmission.h>
     28#import "Controller.h"
    2929
    3030@interface NameCell : NSCell
  • trunk/macosx/NameCell.m

    r15 r34  
    2121 *****************************************************************************/
    2222
    23 #include "NameCell.h"
    24 #include "Utils.h"
     23#import "NameCell.h"
     24#import "StringAdditions.h"
     25#import "Utils.h"
    2526
    2627@implementation NameCell
     
    3233    fNameString  = [NSString stringWithUTF8String: stat->info.name];
    3334    fSizeString  = [NSString stringWithFormat: @" (%@)",
    34                     stringForFileSize( stat->info.totalSize )];
     35                    [NSString stringForFileSize: stat->info.totalSize]];
    3536    fTimeString  = @"";
    3637    fPeersString = @"";
     
    106107
    107108    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];
    111112    [string drawAtPoint: pen withAttributes: attributes];
    112113
     
    118119
    119120    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];
    122123    [string drawAtPoint: pen withAttributes: attributes];
    123124
  • trunk/macosx/PrefsController.h

    r20 r34  
    2121 *****************************************************************************/
    2222
    23 #include <Cocoa/Cocoa.h>
    24 #include <transmission.h>
     23#import <Cocoa/Cocoa.h>
     24#import <transmission.h>
    2525
    2626@interface PrefsController : NSObject
  • trunk/macosx/PrefsController.m

    r20 r34  
    2121 *****************************************************************************/
    2222
    23 #include "PrefsController.h"
     23#import "PrefsController.h"
    2424
    2525#define DEFAULT_UPLOAD      @"20"
  • trunk/macosx/ProgressCell.h

    r15 r34  
    2424#define PROGRESSCELL_H
    2525
    26 #include <Cocoa/Cocoa.h>
    27 #include <transmission.h>
     26#import <Cocoa/Cocoa.h>
     27#import <transmission.h>
    2828
    2929@interface ProgressCell : NSCell
  • trunk/macosx/ProgressCell.m

    r25 r34  
    2121 *****************************************************************************/
    2222
    23 #include "ProgressCell.h"
     23#import "ProgressCell.h"
     24#import "StringAdditions.h"
    2425
    2526@implementation ProgressCell
     
    122123
    123124    /* 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]];
    128129
    129130    /* 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//
    228
    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
    2415{
    25     if( size < 1024 )
    26     {
     16    if (size < 1024)
    2717        return [NSString stringWithFormat: @"%lld bytes", size];
    28     }
    29     if( size < 1048576 )
    30     {
     18    else if (size < 1048576)
    3119        return [NSString stringWithFormat: @"%lld.%lld KB",
    3220                size / 1024, ( size % 1024 ) / 103];
    33     }
    34     if( size < 1073741824 )
    35     {
     21    else if (size < 1073741824)
    3622        return [NSString stringWithFormat: @"%lld.%lld MB",
    3723                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];
    4127}
    4228
    43 static float widthForString( NSString * string, float fontSize )
     29+ (NSString *) stringForSpeed: (float) speed
    4430{
    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];
    5137}
    5238
    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
    5741{
    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   
    7248    return newString;
    7349}
     50
     51@end
  • trunk/macosx/TorrentTableView.h

    r19 r34  
    1 #include <Cocoa/Cocoa.h>
    2 #include <transmission.h>
     1#import <Cocoa/Cocoa.h>
     2#import <transmission.h>
    33
    44@class Controller;
  • trunk/macosx/TorrentTableView.m

    r19 r34  
    1 #include "TorrentTableView.h"
    2 #include "Controller.h"
     1#import "TorrentTableView.h"
     2#import "Controller.h"
    33
    44@implementation TorrentTableView
  • trunk/macosx/Transmission.xcodeproj/project.pbxproj

    r19 r34  
    2424                4DA6FDC5091141AD00450CB1 /* ResumeOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC3091141AD00450CB1 /* ResumeOff.png */; };
    2525                4DA6FDC6091141AD00450CB1 /* ResumeOn.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDC4091141AD00450CB1 /* ResumeOn.png */; };
     26                4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DE5CC9C0980656F00BE280E /* StringAdditions.m */; };
    2627                4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; };
    2728                4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; };
     
    9192                4DA6FDC3091141AD00450CB1 /* ResumeOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeOff.png; path = Images/ResumeOff.png; sourceTree = "<group>"; };
    9293                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>"; };
    9396                4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
    9497                4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
     
    128131                                4D364D9E091FBB2C00377D12 /* TorrentTableView.h */,
    129132                                4D364D9F091FBB2C00377D12 /* TorrentTableView.m */,
     133                                4DE5CC9B0980656F00BE280E /* StringAdditions.h */,
     134                                4DE5CC9C0980656F00BE280E /* StringAdditions.m */,
    130135                        );
    131136                        name = Classes;
     
    304309                                4D118E1A08CB46B20033958F /* PrefsController.m in Sources */,
    305310                                4D364DA0091FBB2C00377D12 /* TorrentTableView.m in Sources */,
     311                                4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */,
    306312                        );
    307313                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/macosx/Utils.h

    r3 r34  
    2121 *****************************************************************************/
    2222
    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 
    5323#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  
    2121 *****************************************************************************/
    2222
    23 #include <Cocoa/Cocoa.h>
     23#import <Cocoa/Cocoa.h>
    2424
    2525int main( int argc, char ** argv )
Note: See TracChangeset for help on using the changeset viewer.