Skip to content

Commit

Permalink
add quicklook to sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
kolyvan committed Oct 6, 2015
1 parent 989e776 commit d458955
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions KxSMBSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
871CC5751774589C00EDD76D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 87085F8E1705D46C009CD258 /* Foundation.framework */; };
871CC580177458AD00EDD76D /* KxSMBProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 87085FB31705D494009CD258 /* KxSMBProvider.m */; };
EAC6EFEE179A4133005AC807 /* libtevent.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EAC6EFED179A4133005AC807 /* libtevent.a */; };
F992AF0C1BC3D3CC0063A4B3 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F992AF0B1BC3D3CC0063A4B3 /* QuickLook.framework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -79,13 +80,15 @@
871CC5741774589C00EDD76D /* libKxSMB.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libKxSMB.a; sourceTree = BUILT_PRODUCTS_DIR; };
871CC5781774589C00EDD76D /* KxSMB-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KxSMB-Prefix.pch"; sourceTree = "<group>"; };
EAC6EFED179A4133005AC807 /* libtevent.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtevent.a; path = libs/libtevent.a; sourceTree = "<group>"; };
F992AF0B1BC3D3CC0063A4B3 /* QuickLook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLook.framework; path = System/Library/Frameworks/QuickLook.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
87085F861705D46C009CD258 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F992AF0C1BC3D3CC0063A4B3 /* QuickLook.framework in Frameworks */,
87085FCD1705D509009CD258 /* libresolv.dylib in Frameworks */,
87085FCB1705D503009CD258 /* libiconv.dylib in Frameworks */,
87085FC91705D4FD009CD258 /* libz.dylib in Frameworks */,
Expand Down Expand Up @@ -136,6 +139,7 @@
87085F8B1705D46C009CD258 /* Frameworks */ = {
isa = PBXGroup;
children = (
F992AF0B1BC3D3CC0063A4B3 /* QuickLook.framework */,
87085FCC1705D509009CD258 /* libresolv.dylib */,
87085FCA1705D503009CD258 /* libiconv.dylib */,
87085FC81705D4FD009CD258 /* libz.dylib */,
Expand Down
33 changes: 26 additions & 7 deletions KxSMBSample/FileViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

#import "FileViewController.h"
#import "KxSMBProvider.h"
#import <QuickLook/QuickLook.h>

@interface FileViewController ()
@interface FileViewController () <QLPreviewControllerDelegate, QLPreviewControllerDataSource>
@end

@implementation FileViewController {
Expand Down Expand Up @@ -261,16 +262,22 @@ -(void) updateDownloadStatus: (id) result
[_fileHandle writeData:data];

if(_downloadedBytes == _smbFile.stat.size) {

[self closeFiles];

// If file is recognized as an image, creates an Image View to show it
if([@[@"png",@"jpg",@"gif"] containsObject:[[_smbFile.path pathExtension] lowercaseString]]) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:_filePath]];
imageView.frame = CGRectMake(0, 220, self.view.frame.size.width, self.view.frame.size.height-220);
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
[_downloadButton setTitle:@"Done" forState:UIControlStateNormal];
_downloadButton.enabled = NO;

if ([QLPreviewController canPreviewItem:[NSURL fileURLWithPath:_filePath]]) {

QLPreviewController *vc = [QLPreviewController new];
vc.delegate = self;
vc.dataSource = self;
[self.navigationController pushViewController:vc animated:YES];
}

} else {

[self download];
}
}
Expand All @@ -295,4 +302,16 @@ - (void) download
}];
}

#pragma mark - QLPreviewController

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:_filePath];
}

@end

0 comments on commit d458955

Please sign in to comment.