Changeset 2108


Ignore:
Timestamp:
Jun 17, 2007, 12:26:52 AM (15 years ago)
Author:
livings124
Message:

get the basics of file creation working, some better error checking, and combine the name and location fields

Location:
branches/file_selection/macosx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/macosx/Controller.m

    r2100 r2108  
    934934- (void) createFile: (id) sender
    935935{
    936     [CreatorWindowController createTorrentFile];
     936    [CreatorWindowController createTorrentFile: fLib];
    937937}
    938938
  • branches/file_selection/macosx/CreatorWindowController.h

    r2102 r2108  
    2424
    2525#import <Cocoa/Cocoa.h>
     26#import "transmission.h"
    2627#import "makemeta.h"
    2728
     
    2930{
    3031    IBOutlet NSImageView * fIcon, * fLocationIcon;
    31     IBOutlet NSTextField * fNameField, * fStatusField, * fPiecesField, * fLocationField,
    32                 * fTrackerField, * fTorrentNameField;
     32    IBOutlet NSTextField * fNameField, * fStatusField, * fPiecesField, * fTrackerField, * fLocationField;
    3333    IBOutlet NSTextView * fCommentView;
    3434    IBOutlet NSButton * fPrivateCheck;
    3535   
    36     meta_info_builder_t * fInfo;
     36    IBOutlet NSWindow * fProgressWindow;
     37    IBOutlet NSProgressIndicator * fProgressIndicator;
     38   
     39    tr_metainfo_builder_t * fInfo;
    3740    NSString * fPath, * fLocation;
    3841}
    3942
    40 + (void) createTorrentFile;
     43+ (void) createTorrentFile: (tr_handle_t *) handle;
     44
     45- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle path: (NSString *) path;
    4146
    4247- (void) setLocation: (id) sender;
  • branches/file_selection/macosx/CreatorWindowController.m

    r2106 r2108  
    2828#define DEFAULT_SAVE_LOCATION @"~/Desktop/"
    2929
    30 #warning rename?
    3130@interface CreatorWindowController (Private)
    3231
    3332+ (NSString *) chooseFile;
    34 - (void) setPath: (NSString *) path;
    35 - (void) locationSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
     33- (void) locationSheetClosed: (NSSavePanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    3634
    3735@end
     
    3937@implementation CreatorWindowController
    4038
    41 + (void) createTorrentFile
     39+ (void) createTorrentFile: (tr_handle_t *) handle
    4240{
    4341    //get file/folder for torrent
     
    4644        return;
    4745   
    48     CreatorWindowController * creator = [[self alloc] initWithWindowNibName: @"Creator"];
    49     [creator setPath: path];
     46    CreatorWindowController * creator = [[self alloc] initWithWindowNibName: @"Creator" handle: handle path: path];
    5047    [creator showWindow: nil];
    5148}
    5249
     50- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle path: (NSString *) path
     51{
     52    if ((self = [super initWithWindowNibName: name]))
     53    {
     54        fPath = [path retain];
     55        fInfo = tr_metaInfoBuilderCreate(handle, [fPath UTF8String]);
     56        if (fInfo->fileCount == 0)
     57        {
     58            NSAlert * alert = [[[NSAlert alloc] init] autorelease];
     59            [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> no files -> button")];
     60            [alert setMessageText: NSLocalizedString(@"This folder contains no files.",
     61                                                    "Create torrent -> no files -> title")];
     62            [alert setInformativeText: NSLocalizedString(@"There must be at least one file in a folder to create a torrent file.",
     63                                                        "Create torrent -> no files -> warning")];
     64            [alert setAlertStyle: NSWarningAlertStyle];
     65           
     66            [alert runModal];
     67           
     68            [self release];
     69            return nil;
     70        }
     71    }
     72    return self;
     73}
     74
    5375- (void) awakeFromNib
    5476{
    55     fInfo = tr_metaInfoBuilderCreate([fPath UTF8String]);
    56    
    57     #warning if count == 0, end
    58    
    5977    NSString * name = [fPath lastPathComponent];
    6078   
     
    7593    {
    7694        NSString * fileString;
    77    
    7895        int count = fInfo->fileCount;
    7996        if (count != 1)
     
    88105                                    fInfo->pieceCount, [NSString stringForFileSize: fInfo->pieceSize]]];
    89106   
    90     fLocation = [[DEFAULT_SAVE_LOCATION stringByExpandingTildeInPath] retain];
    91     [fLocationIcon setImage: [[NSWorkspace sharedWorkspace] iconForFile: fLocation]];
     107    fLocation = [[[DEFAULT_SAVE_LOCATION stringByAppendingPathComponent: [name stringByAppendingPathExtension: @"torrent"]]
     108                                            stringByExpandingTildeInPath] retain];
     109    [fLocationIcon setImage: [[NSWorkspace sharedWorkspace] iconForFile: [fLocation stringByDeletingLastPathComponent]]];
    92110    [fLocationField setStringValue: [fLocation stringByAbbreviatingWithTildeInPath]];
    93111    [fLocationField setToolTip: fLocation];
    94    
    95     [fTorrentNameField setStringValue: [name stringByAppendingPathExtension: @"torrent"]];
    96112}
    97113
     
    110126- (void) setLocation: (id) sender
    111127{
    112     NSOpenPanel * panel = [NSOpenPanel openPanel];
     128    NSSavePanel * panel = [NSSavePanel savePanel];
    113129
    114130    [panel setPrompt: @"Select"];
    115     [panel setAllowsMultipleSelection: NO];
    116     [panel setCanChooseFiles: NO];
    117     [panel setCanChooseDirectories: YES];
    118     [panel setCanCreateDirectories: YES];
    119 
    120     [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: [self window] modalDelegate: self
     131    [panel setRequiredFileType: @"torrent"];
     132    [panel setCanSelectHiddenExtension: YES];
     133
     134    [panel beginSheetForDirectory: nil file: [fLocation lastPathComponent] modalForWindow: [self window] modalDelegate: self
    121135            didEndSelector: @selector(locationSheetClosed:returnCode:contextInfo:) contextInfo: nil];
    122136}
     
    145159        trackerString = [@"http://" stringByAppendingString: trackerString];
    146160   
    147     NSString * torrentName = [fTorrentNameField stringValue];
    148     if ([[torrentName pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
    149     {
    150         NSAlert * alert = [[[NSAlert alloc] init] autorelease];
    151         [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> torrent extension warning -> button")];
    152         [alert setMessageText: NSLocalizedString(@"Torrents must end in \".torrent\".",
    153                                                 "Create torrent -> torrent extension warning -> title")];
    154         [alert setInformativeText: NSLocalizedString(@"Add this file extension to create the torrent.",
    155                                                     "Create torrent -> torrent extension warning -> warning")];
    156         [alert setAlertStyle: NSWarningAlertStyle];
    157        
    158         [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil];
    159         return;
    160     }
     161    //[NSApp beginSheet: fProgressWindow modalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil];
    161162   
    162163    #warning fix
    163     tr_makeMetaInfo(fInfo, NULL, self, [[fLocation stringByAppendingPathComponent: torrentName] UTF8String],
    164             [trackerString UTF8String], [[fCommentView string] UTF8String], [fPrivateCheck state] == NSOnState);
    165    
    166     #warning add to T
    167 
    168     [[self window] close];
     164    tr_makeMetaInfo(fInfo, [fLocation UTF8String], [trackerString UTF8String], [[fCommentView string] UTF8String],
     165                    [fPrivateCheck state] == NSOnState);
     166   
     167    #warning move to "check" method
     168    /*#warning add to T
     169
     170    [[self window] close];*/
    169171}
    170172
     
    199201}
    200202
    201 - (void) setPath: (NSString *) path
    202 {
    203     fPath = [path retain];
    204 }
    205 
    206 - (void) locationSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
     203- (void) locationSheetClosed: (NSSavePanel *) panel returnCode: (int) code contextInfo: (void *) info
    207204{
    208205    if (code == NSOKButton)
    209206    {
    210207        [fLocation release];
    211         fLocation = [[[openPanel filenames] objectAtIndex: 0] retain];
     208        fLocation = [[panel filename] retain];
    212209       
    213         [fLocationIcon setImage: [[NSWorkspace sharedWorkspace] iconForFile: fLocation]];
     210        [fLocationIcon setImage: [[NSWorkspace sharedWorkspace] iconForFile: [fLocation stringByDeletingLastPathComponent]]];
    214211        [fLocationField setStringValue: [fLocation stringByAbbreviatingWithTildeInPath]];
    215212        [fLocationField setToolTip: fLocation];
  • branches/file_selection/macosx/English.lproj/Creator.nib/classes.nib

    r2101 r2108  
    1313                fPiecesField = NSTextField;
    1414                fPrivateCheck = NSButton;
     15                fProgressIndicator = NSProgressIndicator;
     16                fProgressWindow = NSWindow;
    1517                fStatusField = NSTextField;
    16                 fTorrentNameField = NSTextField;
    1718                fTrackerField = NSTextField;
    1819            };
  • branches/file_selection/macosx/English.lproj/Creator.nib/info.nib

    r2101 r2108  
    99        <key>IBOpenObjects</key>
    1010        <array>
     11                <integer>45</integer>
    1112                <integer>5</integer>
    1213        </array>
Note: See TracChangeset for help on using the changeset viewer.