From 6b4b3beeb28081c69323b76acd72dd7d53d9b086 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 14 Oct 2008 22:53:14 +0000 Subject: [PATCH] Sections should have icons displayed, too. --- Cydia.app/package.html | 1 + Cydia.app/package.js | 6 ++++-- Cydia.mm | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Cydia.app/package.html b/Cydia.app/package.html index 710b87a9..46da6adf 100644 --- a/Cydia.app/package.html +++ b/Cydia.app/package.html @@ -231,6 +231,7 @@
+
diff --git a/Cydia.app/package.js b/Cydia.app/package.js index e409aa98..762167af 100644 --- a/Cydia.app/package.js +++ b/Cydia.app/package.js @@ -142,8 +142,10 @@ $(function () { var section = package.section; if (section == null) $(".section").remove(); - else - $("#section").html(package.section); + else { + $("#section-src").src("cydia://section-icon/" + encodeURIComponent(section)); + $("#section").html(section); + } var size = package.size; if (size == 0) diff --git a/Cydia.mm b/Cydia.mm index 8d48ac06..f94557ab 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -1170,6 +1170,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) { - (pkgCache::PkgIterator) iterator; - (NSString *) section; +- (NSString *) simpleSection; + - (Address *) maintainer; - (size_t) size; - (NSString *) description; @@ -1425,6 +1427,14 @@ NSString *Scour(const char *field, const char *begin, const char *end) { return section_; } +- (NSString *) simpleSection { + if (NSString *section = [self section]) + return Simplify(section); + else + return nil; + +} + - (Address *) maintainer { if (file_.end()) return nil; @@ -1594,9 +1604,7 @@ NSString *Scour(const char *field, const char *begin, const char *end) { } - (UIImage *) icon { - NSString *section = [self section]; - if (section != nil) - section = Simplify(section); + NSString *section = [self simpleSection]; UIImage *icon(nil); if (NSString *icon = icon_) @@ -3366,9 +3374,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self clearPackage]; Source *source = [package source]; - NSString *section = [package section]; - if (section != nil) - section = Simplify(section); + NSString *section = [package simpleSection]; icon_ = [[package icon] retain]; @@ -5447,15 +5453,32 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ([command isEqualToString:@"package-icon"]) { if (path == nil) goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; Package *package([database packageWithName:path]); if (package == nil) goto fail; + UIImage *icon([package icon]); + + NSData *data(UIImagePNGRepresentation(icon)); + NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); + [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; + [client URLProtocol:self didLoadData:data]; + [client URLProtocolDidFinishLoading:self]; + } else if ([command isEqualToString:@"section-icon"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *section(Simplify(path)); + + UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]]); + if (icon == nil) + icon = [UIImage applicationImageNamed:@"unknown.png"]; - UIImage *icon([package icon]); NSData *data(UIImagePNGRepresentation(icon)); + NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; [client URLProtocol:self didLoadData:data]; [client URLProtocolDidFinishLoading:self]; -- 2.45.2