#include <CoreFoundation/CFPriv.h>
#include <CoreFoundation/CFUniChar.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
#include <UIKit/UIKit.h>
#include "iPhonePrivate.h"
#include <ext/hash_map>
#include "UICaboodle/BrowserView.h"
-#include "UICaboodle/ResetView.h"
#include "substrate.h"
-
-// Apple's sample Reachability code, ASPL licensed.
-#include "Reachability.h"
/* }}} */
/* Profiler {{{ */
} return self;
}
-- (void)_updateFrameForDisplay {
+- (void) _updateFrameForDisplay {
[super _updateFrameForDisplay];
if ([self cancelButtonIndex] == -1) {
NSArray *buttons = [self buttons];
#define ShowInternals (0 && !ForRelease)
#define IgnoreInstall (0 && !ForRelease)
#define RecycleWebViews 0
-#define RecyclePackageViews (1 && ForRelease)
+#define RecyclePackageViews (0 && ForRelease)
#define AlwaysReload (1 && !ForRelease)
#if !TraceLogging
@end
/* }}} */
-NSUInteger WebScriptObject$countByEnumeratingWithState$objects$count$(WebScriptObject *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
+@implementation WebScriptObject (NSFastEnumeration)
+
+- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count {
size_t length([self count] - state->state);
if (length <= 0)
return 0;
return length;
}
+@end
+
NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
size_t length([self length] - state->state);
if (length <= 0)
@end
/* }}} */
/* CoreGraphics Primitives {{{ */
-class CGColor {
+class CYColor {
private:
CGColorRef color_;
public:
- CGColor() :
+ CYColor() :
color_(NULL)
{
}
- CGColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) :
+ CYColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) :
color_(NULL)
{
Set(space, red, green, blue, alpha);
CGColorRelease(color_);
}
- ~CGColor() {
+ ~CYColor() {
Clear();
}
void Set(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
Clear();
float color[] = {red, green, blue, alpha};
- color_ = CGColorCreate(space, color);
+ color_ = CGColorCreate(space, (CGFloat *) color);
}
operator CGColorRef() {
static bool Queuing_;
-static CGColor Blue_;
-static CGColor Blueish_;
-static CGColor Black_;
-static CGColor Off_;
-static CGColor White_;
-static CGColor Gray_;
-static CGColor Green_;
-static CGColor Purple_;
-static CGColor Purplish_;
+static CYColor Blue_;
+static CYColor Blueish_;
+static CYColor Black_;
+static CYColor Off_;
+static CYColor White_;
+static CYColor Gray_;
+static CYColor Green_;
+static CYColor Purple_;
+static CYColor Purplish_;
static UIColor *InstallingColor_;
static UIColor *RemovingColor_;
static UIFont *Font22Bold_;
static const char *Machine_ = NULL;
-static const NSString *System_ = NULL;
-static const NSString *SerialNumber_ = nil;
-static const NSString *ChipID_ = nil;
-static const NSString *Token_ = nil;
-static const NSString *UniqueID_ = nil;
-static const NSString *Build_ = nil;
-static const NSString *Product_ = nil;
-static const NSString *Safari_ = nil;
+static NSString *System_ = nil;
+static NSString *SerialNumber_ = nil;
+static NSString *ChipID_ = nil;
+static NSString *Token_ = nil;
+static NSString *UniqueID_ = nil;
+static NSString *Build_ = nil;
+static NSString *Product_ = nil;
+static NSString *Safari_ = nil;
static CFLocaleRef Locale_;
static NSArray *Languages_;
- (void) setProgressError:(NSString *)error forPackage:(NSString *)id {
Package *package = id == nil ? nil : [[Database sharedInstance] packageWithName:id];
- // XXX: holy typecast batman!
- [(id<ProgressDelegate>)self setProgressError:error withTitle:(package == nil ? id : [package name])];
+
+ [self performSelector:@selector(setProgressError:withTitle:)
+ withObject:error
+ withObject:(package == nil ? id : [package name])
+ ];
}
@end
}
- (NSString *) depictionForPackage:(NSString *)package {
- return depiction_.empty() ? nil : [depiction_ stringByReplacingOccurrencesOfString:@"*" withString:package];
+ return depiction_.empty() ? nil : [static_cast<id>(depiction_) stringByReplacingOccurrencesOfString:@"*" withString:package];
}
- (NSString *) supportForPackage:(NSString *)package {
- return support_.empty() ? nil : [support_ stringByReplacingOccurrencesOfString:@"*" withString:package];
+ return support_.empty() ? nil : [static_cast<id>(support_) stringByReplacingOccurrencesOfString:@"*" withString:package];
}
- (NSDictionary *) record {
_end
bool changed(false);
- NSString *key([id_ lowercaseString]);
+ NSString *key([static_cast<id>(id_) lowercaseString]);
_profile(Package$initWithVersion$Metadata)
metadata_ = [Packages_ objectForKey:key];
UIImage *icon(nil);
if (!icon_.empty())
- if ([icon_ hasPrefix:@"file:///"])
+ if ([static_cast<id>(icon_) hasPrefix:@"file:///"])
// XXX: correct escaping
- icon = [UIImage imageAtPath:[icon_ substringFromIndex:7]];
+ icon = [UIImage imageAtPath:[static_cast<id>(icon_) substringFromIndex:7]];
if (icon == nil) if (section != nil)
icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]];
if (icon == nil) if (source_ != nil) if (NSString *dicon = [source_ defaultIcon])
return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self];
} }
-- (Database *) init {
+- (id) init {
if ((self = [super init]) != nil) {
policy_ = NULL;
records_ = NULL;
return;
if ([self popErrorWithTitle:title forOperation:ListUpdate(status, list, PulseInterval_)])
- /* XXX: ignore this because users suck and don't understand why refreshing is important: return */;
+ /* XXX: ignore this because users suck and don't understand why refreshing is important: return */
+ /* XXX: why the hell is an empty if statement a clang error? */ (void) 0;
[Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"];
Changed_ = true;
id values[count];
for (unsigned i(0); i != count; ++i)
values[i] = [arguments objectAtIndex:i];
- return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast<va_list>(values)] autorelease];
+ return [[[NSString alloc] initWithFormat:format arguments:*(reinterpret_cast<va_list *>(&values))] autorelease];
}
- (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table {
[super dealloc];
}
-- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section {
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return files_ == nil ? 0 : [files_ count];
}
[[self navigationController] pushViewController:view animated:YES];
}
-- (id) title { return title_; }
+- (NSString *) title { return title_; }
- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object {
if ((self = [super init]) != nil) {
[list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
}
-- (int) numberOfSectionsInTableView:(UITableView *)tableView {
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return offset_ == 0 ? 1 : 2;
}
-- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section {
+- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section + (offset_ == 0 ? 1 : 0)) {
case 0: return UCLocalize("ENTERED_BY_USER");
case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
}
}
-- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section {
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = [sources_ count];
switch (section) {
case 0: return (offset_ == 0 ? count : offset_);
[self _endConnection:connection];
}
-- (id)title { return UCLocalize("SOURCES"); }
+- (NSString *) title { return UCLocalize("SOURCES"); }
- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method {
NSMutableURLRequest *request = [NSMutableURLRequest
[super dealloc];
}
-- (id) title { return UCLocalize("INSTALLED"); }
+- (NSString *) title { return UCLocalize("INSTALLED"); }
- (id) initWithDatabase:(Database *)database {
if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndVisible:) with:[NSNumber numberWithBool:YES]]) != nil) {
/* Cydia Navigation Controller {{{ */
@interface CYNavigationController : UINavigationController {
_transient Database *database_;
- id delegate_;
+ id<UINavigationControllerDelegate> delegate_;
}
- (id) initWithDatabase:(Database *)database;
}
}
-- (void) setDelegate:(id)delegate {
+- (void) setDelegate:(id<UINavigationControllerDelegate>)delegate {
delegate_ = delegate;
}
return section;
}
-- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section {
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return editing_ ? [sections_ count] : [filtered_ count] + 1;
}
[[self navigationController] pushViewController:table animated:YES];
}
-- (id) title { return UCLocalize("SECTIONS"); }
+- (NSString *) title { return UCLocalize("SECTIONS"); }
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
[delegate_ distUpgrade];
}
-- (id) title { return UCLocalize("CHANGES"); }
+- (NSString *) title { return UCLocalize("CHANGES"); }
- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
if ((self = [super init]) != nil) {
[super dealloc];
}
-- (void) searchBarSearchButtonClicked:(id)searchBar {
+- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
[search_ resignFirstResponder];
[self reloadData];
}
-- (void) searchBar:(id)searchBar textDidChange:(NSString *)text {
+- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
[packages_ setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)];
[self reloadData];
}
-- (id) title { return nil; }
+- (NSString *) title { return nil; }
- (id) initWithDatabase:(Database *)database {
return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil];
return nil;
}
-- (id) title { return UCLocalize("SETTINGS"); }
+- (NSString *) title { return UCLocalize("SETTINGS"); }
- (id) initWithDatabase:(Database *)database package:(NSString *)package {
if ((self = [super init])) {
- (void) dropBar:(BOOL)animated;
- (void) beginUpdate;
- (void) raiseBar:(BOOL)animated;
+- (BOOL) updating;
@end
@implementation CYContainer
+- (BOOL) _reallyWantsFullScreenLayout {
+ return YES;
+}
+
// NOTE: UIWindow only sends the top controller these messages,
// So we have to forward them on.
updatedelegate_ = delegate;
}
+- (CGFloat) statusBarHeight {
+ if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
+ return [[UIApplication sharedApplication] statusBarFrame].size.height;
+ } else {
+ return [[UIApplication sharedApplication] statusBarFrame].size.width;
+ }
+}
+
- (void) dropBar:(BOOL)animated {
if (dropped_) return;
dropped_ = true;
[[self view] addSubview:refreshbar_];
+ CGFloat sboffset = [self statusBarHeight];
+
+ CGRect barframe = [refreshbar_ frame];
+ barframe.origin.y = sboffset;
+ [refreshbar_ setFrame:barframe];
+
if (animated) [UIView beginAnimations:nil context:NULL];
- CGRect barframe = [refreshbar_ frame];
CGRect viewframe = [[root_ view] frame];
- viewframe.origin.y += barframe.size.height;
- viewframe.size.height -= barframe.size.height;
+ viewframe.origin.y += barframe.size.height + sboffset;
+ viewframe.size.height -= barframe.size.height + sboffset;
[[root_ view] setFrame:viewframe];
if (animated) [UIView commitAnimations];
[refreshbar_ removeFromSuperview];
+ CGFloat sboffset = [self statusBarHeight];
+
if (animated) [UIView beginAnimations:nil context:NULL];
CGRect barframe = [refreshbar_ frame];
CGRect viewframe = [[root_ view] frame];
- viewframe.origin.y -= barframe.size.height;
- viewframe.size.height += barframe.size.height;
+ viewframe.origin.y -= barframe.size.height + sboffset;
+ viewframe.size.height += barframe.size.height + sboffset;
[[root_ view] setFrame:viewframe];
if (animated) [UIView commitAnimations];
[[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
}
+- (void) statusBarFrameChanged:(NSNotification *)notification {
+ if (dropped_) {
+ [self raiseBar:NO];
+ [self dropBar:NO];
+ }
+}
+
- (void) dealloc {
[refreshbar_ release];
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
-- (id) initWithDatabase: (Database *)database {
+- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self];
} return self;
@interface Cydia : UIApplication <
ConfirmationControllerDelegate,
ProgressControllerDelegate,
- CydiaDelegate
+ CydiaDelegate,
+ UINavigationControllerDelegate
> {
UIWindow *window_;
CYContainer *container_;
- (void) _refreshIfPossible {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- Reachability* reachability = [Reachability reachabilityWithHostName:@"cydia.saurik.com"];
- NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
+ SCNetworkReachabilityFlags flags; {
+ SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com"));
+ SCNetworkReachabilityGetFlags(reachability, &flags);
+ CFRelease(reachability);
+ }
+
+ // XXX: this elaborate mess is what Apple is using to determine this? :(
+ // XXX: do we care if the user has to intervene? maybe that's ok?
+ bool reachable(
+ (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
+ (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
+ (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
+ (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
+ ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
+ (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
+ )
+ );
- if (loaded_ || ManualRefresh || remoteHostStatus == NotReachable) loaded:
+ if (loaded_ || ManualRefresh || !reachable) loaded:
[self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO];
else {
loaded_ = true;
[self _saveConfig];
ProgressController *progress = [[[ProgressController alloc] initWithDatabase:database_ delegate:self] autorelease];
- UINavigationController *navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease];
+ CYNavigationController *navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease];
if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
[container_ presentModalViewController:navigation animated:YES];
ConfirmationController *page([[[ConfirmationController alloc] initWithDatabase:database_] autorelease]);
[page setDelegate:self];
- id confirm_ = [[CYNavigationController alloc] initWithRootViewController:page];
+ CYNavigationController *confirm_ = [[CYNavigationController alloc] initWithRootViewController:page];
[confirm_ setDelegate:self];
if (IsWildcat_) [confirm_ setModalPresentationStyle:UIModalPresentationFormSheet];
[page setDelegate:self];
CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController];
- [navController setViewControllers:[NSArray arrayWithObject:page] animated:NO];
+ [navController setViewControllers:[NSArray arrayWithObject:page]];
for (CYNavigationController *page in [tabbar_ viewControllers]) {
if (page != navController) [page setViewControllers:nil];
}
#endif
}
+// Returns the navigation controller for the queuing badge.
+- (id) queueBadgeController {
+ int index = [self indexOfTabWithTag:kManageTag];
+ if (index == -1) index = [self indexOfTabWithTag:kInstalledTag];
+
+ return [[tabbar_ viewControllers] objectAtIndex:index];
+}
+
- (void) cancelAndClear:(bool)clear {
@synchronized (self) {
if (clear) {
- /* XXX: clear marks instead of reloading data */
- /*pkgCacheFile &cache([database_ cache]);
+ // Clear all marks.
+ pkgCacheFile &cache([database_ cache]);
for (pkgCache::PkgIterator iterator = cache->PkgBegin(); !iterator.end(); ++iterator) {
- if (!cache[iterator].Keep()) cache->MarkKeep(iterator, false, false);
+ // Unmark method taken from Synaptic Package Manager.
+ // Thanks for being sane, unlike Aptitude.
+ if (!cache[iterator].Keep()) {
+ cache->MarkKeep(iterator, false);
+ cache->SetReInstall(iterator, false);
+ }
}
- [self updateData];
-
+ // Stop queuing.
Queuing_ = false;
- [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:nil];
- [queueDelegate_ queueStatusDidChange];*/
- [self reloadData];
+ [[[self queueBadgeController] tabBarItem] setBadgeValue:nil];
} else {
+ // Start queuing.
Queuing_ = true;
-
- [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:UCLocalize("Q_D")];
- [(CYNavigationController *)[tabbar_ selectedViewController] reloadData];
-
- [queueDelegate_ queueStatusDidChange];
- }
+ [[[self queueBadgeController] tabBarItem] setBadgeValue:UCLocalize("Q_D")];
+ }
+
+ // Show the changes in the current view.
+ [(CYNavigationController *) [tabbar_ selectedViewController] reloadData];
+ [queueDelegate_ queueStatusDidChange];
}
}
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
/* Library Hacks {{{ */
- class_addMethod(objc_getClass("WebScriptObject"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &WebScriptObject$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
$WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");