Fuse-PDF
view release on metacpan or search on metacpan
example/Fuse-PDF-App/FPAppWindow.m view on Meta::CPAN
//
// FPAppWindow.m
// Fuse-PDF-App
//
// Created by Chris Dolan on 11/29/07.
// Copyright 2007, All rights reserved.
//
#import "AppDelegate.h"
#import "BundledTask.h"
#import "FPAppWindow.h"
@interface NSAttributedString (Hyperlink)
+(id)hyperlinkFromString:(NSString*)inString withURL:(NSURL*)aURL;
@end
@implementation NSAttributedString (Hyperlink)
+(id)hyperlinkFromString:(NSString*)inString withURL:(NSURL*)aURL
{
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: inString];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:[aURL absoluteString] range:range];
// make the text appear in blue
[attrString addAttribute:NSForegroundColorAttributeName value:[NSColor blueColor] range:range];
// next make the text appear with an underline
[attrString addAttribute:
NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:range];
[attrString endEditing];
return [attrString autorelease];
}
@end
@implementation FPAppWindow
static FPAppWindow *sharedController = nil;
+ (id)sharedController {
if (!sharedController)
sharedController = [[FPAppWindow allocWithZone:nil] init];
[sharedController showWindow:nil];
return sharedController;
}
- (id)init {
self = [self initWithWindowNibName:@"FPAppWindow"];
return self;
}
- (void)windowDidLoad {
printf("window loaded\n");
[[self window] setExcludedFromWindowsMenu:YES];
[[NSApplication sharedApplication] removeWindowsItem:[self window]];
[super windowDidLoad];
[self setup];
}
-(void) parseVersion: (NSString*)result {
//printf("result: %s\n", result ? [result UTF8String] : [@"nil" UTF8String]);
if (result) {
NSRange versionLoc = [result rangeOfString:@"version "];
if (NSNotFound != versionLoc.location) {
NSRange near = {versionLoc.location - 10, versionLoc.length + 50};
printf("found version near '%s'\n", [[result substringWithRange: near] UTF8String]);
NSRange spaceSearch = {versionLoc.location + versionLoc.length, 100};
printf("looking for space at %d+%d\n", spaceSearch.location, spaceSearch.length);
if (spaceSearch.location >= [result length]) {
printf("end of string\n");
return;
}
NSRange nextSpace = [result rangeOfString:@"\n" options:0 range:spaceSearch];
if (NSNotFound != nextSpace.location) {
NSRange numberLoc = {spaceSearch.location, nextSpace.location - spaceSearch.location};
[fuseVersion release];
fuseVersion = [result substringWithRange:numberLoc];
[fuseVersion retain];
printf("number version = %s\n", [fuseVersion UTF8String]);
[fuseStatus setObjectValue:[@"present, v" stringByAppendingString:fuseVersion]];
return;
} else {printf("missing space\n");}
} else {printf("missing versionloc\n");}
} else {printf("nil result\n");}
}
-(void)getFuseVersion {
Callback *callback = [Callback create:self method:@selector(parseVersion:)];
NSArray *cmd = [NSArray arrayWithObjects:@"/System/Library/Filesystems/fusefs.fs/Support/mount_fusefs", @"-v", nil];
[BundledTask run:cmd callback:callback];
}
-(void)parseArch:(NSString*)arch {
NSRange r = [arch rangeOfString:@"\n"];
if (NSNotFound != r.location) {
NSRange begin = {0, r.location};
arch = [arch substringWithRange:begin];
}
printf("arch: %s\n", [arch UTF8String]);
archext = [[@"." stringByAppendingString:arch] retain];
}
-(void)getPerlArch {
Callback *callback = [Callback create:self method:@selector(parseArch:)];
//NSArray *cmd = [NSArray arrayWithObjects:@"/usr/bin/perl", @"-e", @"use Config; print @Config{myarchname}", nil];
NSArray *cmd = [NSArray arrayWithObject:@"/usr/bin/arch"];
[BundledTask run:cmd callback:callback];
}
-(void)setup {
[self getPerlArch];
[unmountButton setEnabled:NO];
( run in 0.645 second using v1.01-cache-2.11-cpan-140bd7fdf52 )