summaryrefslogtreecommitdiff
path: root/MobileCydia.mm
diff options
context:
space:
mode:
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r--MobileCydia.mm113
1 files changed, 113 insertions, 0 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 272d73a..e6e6949 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -126,10 +126,12 @@ extern "C" {
#include <CydiaSubstrate/CydiaSubstrate.h>
#include "Menes/Menes.h"
+#include "CyteKit/IndirectDelegate.h"
#include "CyteKit/PerlCompatibleRegEx.hpp"
#include "CyteKit/TableViewCell.h"
#include "CyteKit/WebScriptObject-Cyte.h"
#include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
#include "CyteKit/stringWithUTF8Bytes.h"
#include "Cydia/MIMEAddress.h"
@@ -247,6 +249,8 @@ union SplitHash {
};
// }}}
+static bool ShowPromoted_;
+
static NSString *Colon_;
NSString *Elision_;
static NSString *Error_;
@@ -4117,6 +4121,8 @@ static _H<NSMutableSet> Diversions_;
return @"setMetadataValue";
else if (selector == @selector(setSessionValue::))
return @"setSessionValue";
+ else if (selector == @selector(setShowPromoted:))
+ return @"setShowPromoted";
else if (selector == @selector(substitutePackageNames:))
return @"substitutePackageNames";
else if (selector == @selector(scrollToBottom:))
@@ -4232,6 +4238,15 @@ static _H<NSMutableSet> Diversions_;
return [Values_ allKeys];
} }
+- (void) _setShowPromoted:(NSNumber *)value {
+ [Metadata_ setObject:value forKey:@"ShowPromoted"];
+ Changed_ = true;
+}
+
+- (void) setShowPromoted:(NSNumber *)value {
+ [self performSelectorOnMainThread:@selector(_setShowPromoted:) withObject:value waitUntilDone:NO];
+}
+
- (id) getMetadataValue:(NSString *)key {
@synchronized (Values_) {
return [Values_ objectForKey:key];
@@ -7198,7 +7213,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
/* Section Controller {{{ */
@interface SectionController : FilteredPackageListController {
+ _H<IndirectDelegate, 1> indirect_;
+ _H<CydiaObject> cydia_;
_H<NSString> section_;
+ std::vector< _H<CyteWebViewTableViewCell, 1> > promoted_;
}
- (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7225,10 +7243,102 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
title = UCLocalize("NO_SECTION");
if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) {
+ indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+ cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
section_ = name;
} return self;
}
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
+ return [super numberOfSectionsInTableView:list] + 1;
+}
+
+- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
+ return section == 0 ? nil : [super tableView:list titleForHeaderInSection:(section - 1)];
+}
+
+- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
+ return section == 0 ? promoted_.size() : [super tableView:list numberOfRowsInSection:(section - 1)];
+}
+
++ (NSIndexPath *) adjustedIndexPath:(NSIndexPath *)path {
+ return [NSIndexPath indexPathForRow:[path row] inSection:([path section] - 1)];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table cellForRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+
+ return promoted_[[path row]];
+}
+
+- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table didSelectRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+}
+
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+ NSInteger section([super tableView:tableView sectionForSectionIndexTitle:title atIndex:index]);
+ return section == 0 ? 0 : section + 1;
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+ NSURL *url([request URL]);
+ if (url == nil)
+ return;
+
+ if ([frame isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else {
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ [controller setDelegate:delegate_];
+ [[self navigationController] pushViewController:controller animated:YES];
+ }
+
+ [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+ return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) loadView {
+ [super loadView];
+
+ // XXX: this code is horrible. I mean, wtf Jay?
+ if (ShowPromoted_ && [[Metadata_ objectForKey:@"ShowPromoted"] boolValue]) {
+ promoted_.resize(1);
+
+ for (unsigned i(0); i != promoted_.size(); ++i) {
+ CyteWebViewTableViewCell *promoted([CyteWebViewTableViewCell cellWithRequest:[NSURLRequest
+ requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sectionhead/%u/%@",
+ UI_, i, section_ == nil ? @"" : [section_ stringByAddingPercentEscapesIncludingReserved]]
+ ]]
+
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:120
+ ]]);
+
+ [promoted setDelegate:self];
+ promoted_[i] = promoted;
+ }
+ }
+}
+
+- (void) setDelegate:(id)delegate {
+ [super setDelegate:delegate];
+ [cydia_ setDelegate:delegate];
+}
+
+- (void) releaseSubviews {
+ promoted_.clear();
+ [super releaseSubviews];
+}
+
@end
/* }}} */
/* Sections Controller {{{ */
@@ -10523,6 +10633,9 @@ int main(int argc, char *argv[]) {
//UIKeyboardDisableAutomaticAppearance();
/* }}} */
+ BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+ ShowPromoted_ = GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("armv7"));
+
Colon_ = UCLocalize("COLON_DELIMITED");
Elision_ = UCLocalize("ELISION");
Error_ = UCLocalize("ERROR");