forked from orta/tumblrclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageController.m
113 lines (89 loc) · 3.54 KB
/
ImageController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// ImageController.m
// Tumblor
//
// Created by orta on 19/07/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "ImageController.h"
@implementation ImageController
- (void) hasBecomeKeyView{
if(!_photosViewActive){
photosView = [[iMBPhotosView alloc] initWithFrame:[photosContainerView bounds]];
[photosContainerView addSubview:(NSView *)photosView];
[(NSView *)photosView setAutoresizingMask:(NSViewHeightSizable|NSViewWidthSizable)];
[NSThread detachNewThreadSelector:@selector(activateMediaView) toTarget:self withObject:nil];
}
[mainWindow setInitialFirstResponder:descriptionTextField];
}
- (void)photoView:(MUPhotoView *)view doubleClickOnPhotoAtIndex:(unsigned)index withFrame:(NSRect)frame{
}
- (void) activateMediaView{
[photosView willActivate];
_photosViewActive = true;
[[NSNotificationCenter defaultCenter] postNotificationName:@"ORAniMediaViewActivated" object:nil];
}
- (void) resignedAsKeyView{
}
- (IBAction)browseForFile:(id)sender{
log(@"%s Hi", _cmd);
}
-(IBAction) pictureTaker:(id)sender{
IKPictureTaker * pic = [IKPictureTaker pictureTaker];
[pic setMirroring:true];
[pic setTitle:@"Tumblg Cam-shot"];
NSImage * image;
//TODO : Set Max Size
if(filepath){
image = [[NSImage alloc] initWithContentsOfURL:[NSURL fileURLWithPath: filepath]];
}else{
image = [NSImage imageNamed:@"photoplaceholder"];
}
[pic setInputImage:image];
[pic beginPictureTakerWithDelegate:self didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:) contextInfo:nil];
}
- (void)pictureTakerDidEnd:(IKPictureTaker *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
if(returnCode == NSOKButton){
// IKImageView doesn't have an accept NSImage, so we write out a png and then load that in
IKPictureTaker * pic = [IKPictureTaker pictureTaker];
NSImage * image = [pic outputImage];
NSBitmapImageRep *bitmapRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
NSData * pngData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];
NSString *fullPath = [@"/tmp" stringByAppendingPathComponent:@"newpic.png"];
[pngData writeToFile:fullPath atomically:YES];
[self setSource:fullPath];
}
}
- (void) setSource : (NSString *) path{
NSString * type = [[path componentsSeparatedByString:@"."] lastObject];
if( [type compare:@"pdf"] == NSOrderedSame){
log(@"path = %@", [NSURL fileURLWithPath: path]);
NSImage * image = [[NSImage alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path]];
NSBitmapImageRep *bitmapRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
NSData * pngData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];
NSString *fullPath = [@"/tmp" stringByAppendingPathComponent:@"pdfpic.png"];
[pngData writeToFile:fullPath atomically:YES];
path = fullPath;
}
filepath = path;
[imageView setImageWithURL:[NSURL fileURLWithPath:path]];
}
- (void) setCaption : (NSString *) caption{
[descriptionTextField setStringValue:caption];
}
- (void) clear{
[self setCaption: @""];
}
- (IBAction)mediaBroswerForFile:(id)sender{
[[iMediaBrowser sharedBrowserWithDelegate:self] showWindow:self];
}
- (BOOL)iMediaBrowser:(iMediaBrowser *)browser willLoadBrowser:(NSString *)browserClassname{
return YES;
}
- (NSDictionary *) values{
return [NSDictionary dictionaryWithObjectsAndKeys:
filepath, @"filepath",
[descriptionTextField stringValue], @"caption",
nil];
}
@end