FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
QLColorCode/GeneratePreviewForURL.m at master · n8gray/QLColorCode · GitHub
n8gray
/
QLColorCode
Public
Notifications
You must be signed in to change notification settings
Fork
88
Star
290
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
QLColorCode
/
GeneratePreviewForURL.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (54 loc) · 2.31 KB
Breadcrumbs
QLColorCode
/
GeneratePreviewForURL.m
Copy path
File metadata and controls
64 lines (54 loc) · 2.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
This code is copyright Nathaniel Gray, licensed under the GPL v2.
See LICENSE.txt for details.
*/
#
import
<
CoreFoundation/CoreFoundation.h
>
#
import
<
CoreServices/CoreServices.h
>
#
import
<
Foundation/Foundation.h
>
#
import
<
QuickLook/QuickLook.h
>
#
import
"
Common.h
"
/*
-----------------------------------------------------------------------------
Generate a preview for file
This function's job is to create preview for designated file
-----------------------------------------------------------------------------
*/
OSStatus
GeneratePreviewForURL
(
void
*thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
#
ifdef
DEBUG
NSDate
*startDate = [
NSDate
date
];
#
endif
n8log
(
@"
Generating Preview
"
);
if
(
QLPreviewRequestIsCancelled
(preview))
return
noErr;
NSAutoreleasePool
*pool = [[
NSAutoreleasePool
alloc
]
init
];
//
Invoke colorize.sh
CFBundleRef bundle =
QLPreviewRequestGetGeneratorBundle
(preview);
int
status;
NSData
*output =
colorizeURL
(bundle, url, &status,
0
);
n8log
(
@"
Generated preview html page in
%.3f
sec
"
,
-[startDate
timeIntervalSinceNow
] );
if
(status !=
0
||
QLPreviewRequestIsCancelled
(preview)) {
#
ifndef
DEBUG
goto
done;
#
endif
}
//
Now let WebKit do its thing
NSString
*textEncoding = [[
NSUserDefaults
standardUserDefaults
]
stringForKey:
@"
webkitTextEncoding
"
];
if
(!textEncoding || [textEncoding
length
] ==
0
)
textEncoding =
@"
UTF-8
"
;
CFDictionaryRef properties =
(CFDictionaryRef)[
NSDictionary
dictionaryWithObject:
textEncoding
forKey:
(
NSString
*)
kQLPreviewPropertyTextEncodingNameKey
];
QLPreviewRequestSetDataRepresentation
(preview, (CFDataRef)output,
//
kUTTypePlainText,
kUTTypeHTML
,
properties);
done:
n8log
(
@"
Finished preview in
%.3f
sec
"
, -[startDate
timeIntervalSinceNow
] );
[pool
release
];
return
noErr;
}
void
CancelPreviewGeneration
(
void
* thisInterface, QLPreviewRequestRef preview)
{
//
implement only if supported
}
Back
|
FazBrowse Home
|
New Git URL