summaryrefslogtreecommitdiff
path: root/Cydia.mm
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2008-04-30 04:58:19 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2008-04-30 04:58:19 +0000
commit7e9a36b640f18febaa4d1beeda6e0f55749cd2b2 (patch)
tree04f662e583f70175503cdf5e0393cbd3eaccb7cb /Cydia.mm
parentd36e83a374d0d26a145e9cba631dd984578ee571 (diff)
Began factoring out some common tools.
Diffstat (limited to 'Cydia.mm')
-rw-r--r--Cydia.mm330
1 files changed, 7 insertions, 323 deletions
diff --git a/Cydia.mm b/Cydia.mm
index 71ab876..06b6323 100644
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -42,6 +42,9 @@
#include <UIKit/UIKit.h>
#include <WebCore/DOMHTML.h>
+#import "RVBook.h"
+#import "RVPage.h"
+
#include <WebKit/WebFrame.h>
#include <WebKit/WebView.h>
@@ -79,20 +82,6 @@ extern "C" {
#include <errno.h>
#include <pcre.h>
/* }}} */
-/* Extension Keywords {{{ */
-#define _trace() fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
-
-#define _assert(test) do \
- if (!(test)) { \
- fprintf(stderr, "_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
- exit(-1); \
- } \
-while (false)
-
-#define _not(type) ((type) ~ (type) 0)
-
-#define _transient
-/* }}} */
/* Miscellaneous Messages {{{ */
@interface NSString (Cydia)
@@ -1495,315 +1484,6 @@ NSString *Scour(const char *field, const char *begin, const char *end) {
@end
/* }}} */
-/* RVPage Interface {{{ */
-@class RVBook;
-
-@interface RVPage : UIView {
- _transient RVBook *book_;
- _transient id delegate_;
-}
-
-- (NSString *) title;
-- (NSString *) backButtonTitle;
-- (NSString *) rightButtonTitle;
-- (NSString *) leftButtonTitle;
-- (UIView *) accessoryView;
-
-- (void) _rightButtonClicked;
-- (void) _leftButtonClicked;
-
-- (void) setPageActive:(BOOL)active;
-- (void) resetViewAnimated:(BOOL)animated;
-
-- (void) setTitle:(NSString *)title;
-- (void) setBackButtonTitle:(NSString *)title;
-
-- (void) reloadButtons;
-- (void) reloadData;
-
-- (id) initWithBook:(RVBook *)book;
-
-- (void) setDelegate:(id)delegate;
-
-@end
-/* }}} */
-/* Reset View {{{ */
-@protocol RVDelegate
-- (void) setPageActive:(BOOL)active with:(id)object;
-- (void) resetViewAnimated:(BOOL)animated with:(id)object;
-- (void) reloadDataWith:(id)object;
-@end
-
-@interface RVBook : UIView {
- NSMutableArray *pages_;
- UINavigationBar *navbar_;
- UITransitionView *transition_;
- BOOL resetting_;
- _transient id delegate_;
-}
-
-- (id) initWithFrame:(CGRect)frame;
-- (void) setDelegate:(id)delegate;
-
-- (void) setPage:(RVPage *)page;
-
-- (void) pushPage:(RVPage *)page;
-- (void) popPages:(unsigned)pages;
-
-- (void) setPrompt:(NSString *)prompt;
-
-- (void) resetViewAnimated:(BOOL)animated;
-- (void) resetViewAnimated:(BOOL)animated toPage:(RVPage *)page;
-
-- (void) setTitle:(NSString *)title forPage:(RVPage *)page;
-- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page;
-- (void) reloadButtonsForPage:(RVPage *)page;
-
-- (void) reloadData;
-
-- (CGRect) pageBounds;
-
-@end
-
-@implementation RVBook
-
-- (void) dealloc {
- [navbar_ setDelegate:nil];
-
- [pages_ release];
- [navbar_ release];
- [transition_ release];
- [super dealloc];
-}
-
-- (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
- _assert([pages_ count] != 0);
- RVPage *page = [pages_ lastObject];
- switch (button) {
- case 0: [page _rightButtonClicked]; break;
- case 1: [page _leftButtonClicked]; break;
- }
-}
-
-- (void) navigationBar:(UINavigationBar *)navbar poppedItem:(UINavigationItem *)item {
- _assert([pages_ count] != 0);
- if (!resetting_)
- [[pages_ lastObject] setPageActive:NO];
- [pages_ removeLastObject];
- if (!resetting_)
- [self resetViewAnimated:YES toPage:[pages_ lastObject]];
-}
-
-- (id) initWithFrame:(CGRect)frame {
- if ((self = [super initWithFrame:frame]) != nil) {
- pages_ = [[NSMutableArray arrayWithCapacity:4] retain];
-
- struct CGRect bounds = [self bounds];
- CGSize navsize = [UINavigationBar defaultSizeWithPrompt];
- CGRect navrect = {{0, 0}, navsize};
-
- navbar_ = [[UINavigationBar alloc] initWithFrame:navrect];
- [self addSubview:navbar_];
-
- [navbar_ setBarStyle:1];
- [navbar_ setDelegate:self];
-
- [navbar_ setPrompt:@""];
-
- transition_ = [[UITransitionView alloc] initWithFrame:CGRectMake(
- bounds.origin.x, bounds.origin.y + navsize.height, bounds.size.width, bounds.size.height - navsize.height
- )];
-
- [self addSubview:transition_];
- } return self;
-}
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}
-
-- (void) setPage:(RVPage *)page {
- if ([pages_ count] != 0)
- [[pages_ lastObject] setPageActive:NO];
-
- [navbar_ disableAnimation];
- resetting_ = true;
- for (unsigned i(0), pages([pages_ count]); i != pages; ++i)
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self pushPage:page];
- [navbar_ enableAnimation];
-}
-
-- (void) pushPage:(RVPage *)page {
- if ([pages_ count] != 0)
- [[pages_ lastObject] setPageActive:NO];
-
- NSString *title = Simplify([page title]);
-
- NSString *backButtonTitle = [page backButtonTitle];
- if (backButtonTitle == nil)
- backButtonTitle = title;
-
- UINavigationItem *navitem = [[[UINavigationItem alloc] initWithTitle:title] autorelease];
- [navitem setBackButtonTitle:backButtonTitle];
- [navbar_ pushNavigationItem:navitem];
-
- BOOL animated = [pages_ count] == 0 ? NO : YES;
- [transition_ transition:(animated ? 1 : 0) toView:page];
- [page setPageActive:YES];
-
- [pages_ addObject:page];
- [self reloadButtonsForPage:page];
-
- [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:NO];
-}
-
-- (void) popPages:(unsigned)pages {
- if (pages == 0)
- return;
-
- [[pages_ lastObject] setPageActive:NO];
-
- resetting_ = true;
- for (unsigned i(0); i != pages; ++i)
- [navbar_ popNavigationItem];
- resetting_ = false;
-
- [self resetViewAnimated:YES toPage:[pages_ lastObject]];
-}
-
-- (void) setPrompt:(NSString *)prompt {
- [navbar_ setPrompt:prompt];
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
- resetting_ = true;
-
- if ([pages_ count] > 1) {
- [navbar_ disableAnimation];
- while ([pages_ count] != (animated ? 2 : 1))
- [navbar_ popNavigationItem];
- [navbar_ enableAnimation];
- if (animated)
- [navbar_ popNavigationItem];
- }
-
- resetting_ = false;
-
- [self resetViewAnimated:animated toPage:[pages_ lastObject]];
-}
-
-- (void) resetViewAnimated:(BOOL)animated toPage:(RVPage *)page {
- [page resetViewAnimated:animated];
- [transition_ transition:(animated ? 2 : 0) toView:page];
- [page setPageActive:YES];
- [self reloadButtonsForPage:page];
- [navbar_ setAccessoryView:[page accessoryView] animate:animated goingBack:YES];
-}
-
-- (void) setTitle:(NSString *)title forPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- [navitem setTitle:title];
-}
-
-- (void) setBackButtonTitle:(NSString *)title forPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- UINavigationItem *navitem = [navbar_ topItem];
- [navitem setBackButtonTitle:title];
-}
-
-- (void) reloadButtonsForPage:(RVPage *)page {
- if ([pages_ count] == 0 || page != [pages_ lastObject])
- return;
- NSString *leftButtonTitle([pages_ count] == 1 ? [page leftButtonTitle] : nil);
- [navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle]];
-}
-
-- (void) reloadData {
- for (int i(0), e([pages_ count]); i != e; ++i) {
- RVPage *page([pages_ objectAtIndex:(e - i - 1)]);
- [page reloadData];
- }
-}
-
-- (CGRect) pageBounds {
- return [transition_ bounds];
-}
-
-@end
-/* }}} */
-/* RVPage Implementation {{{ */
-@implementation RVPage
-
-- (NSString *) title {
- [self doesNotRecognizeSelector:_cmd];
- return nil;
-}
-
-- (NSString *) backButtonTitle {
- return nil;
-}
-
-- (NSString *) leftButtonTitle {
- return nil;
-}
-
-- (NSString *) rightButtonTitle {
- return nil;
-}
-
-- (void) _rightButtonClicked {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (void) _leftButtonClicked {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (UIView *) accessoryView {
- return nil;
-}
-
-- (void) setPageActive:(BOOL)active {
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
- [self doesNotRecognizeSelector:_cmd];
-}
-
-- (void) setTitle:(NSString *)title {
- [book_ setTitle:title forPage:self];
-}
-
-- (void) setBackButtonTitle:(NSString *)title {
- [book_ setBackButtonTitle:title forPage:self];
-}
-
-- (void) reloadButtons {
- [book_ reloadButtonsForPage:self];
-}
-
-- (void) reloadData {
-}
-
-- (id) initWithBook:(RVBook *)book {
- if ((self = [super initWithFrame:[book pageBounds]]) != nil) {
- book_ = book;
- } return self;
-}
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}
-
-@end
-/* }}} */
-
/* Confirmation View {{{ */
void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString *key) {
if ([packages count] == 0)
@@ -3893,6 +3573,10 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
[super dealloc];
}
+- (NSString *) getTitleForPage:(RVPage *)page {
+ return Simplify([super getTitleForPage:page]);
+}
+
- (BOOL) updating {
return updating_;
}