]> git.saurik.com Git - cydia.git/blobdiff - Cydia.mm
Added the section to the package table.
[cydia.git] / Cydia.mm
index 524ec1fc40542b124e0bddc9fcdd363ffab82f1a..e5f198c4cf7e21880a888883e503efac26bd5a9e 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
 #include <objc/objc.h>
 #include <objc/runtime.h>
 
+#include <map>
 #include <sstream>
+#include <string>
+
 #include <ext/stdio_filebuf.h>
 
 #include <apt-pkg/acquire.h>
@@ -70,12 +73,12 @@ extern "C" {
 #include <mach-o/nlist.h>
 }
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 #include <errno.h>
 #include <pcre.h>
-#include <string.h>
 /* }}} */
 /* Extension Keywords {{{ */
 #define _trace() fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
@@ -504,6 +507,17 @@ UITextView *GetTextView(NSString *value, float left, bool html) {
 
     return text;
 }
+
+NSString *Simplify(NSString *title) {
+    const char *data = [title UTF8String];
+    size_t size = [title length];
+
+    Pcre title_r("^(.*?)( \\(.*\\))?$");
+    if (title_r(data, size))
+        return title_r[1];
+    else
+        return title;
+}
 /* }}} */
 
 @class Package;
@@ -1397,6 +1411,15 @@ NSString *Scour(const char *field, const char *begin, const char *end) {
 }
 
 - (void) perform {
+    pkgSourceList list;
+    _assert(list.ReadMainList());
+
+    /*std::map<std::string> before;
+
+    for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source)
+        before.add((*source)->GetURI().c_str());
+    exit(0);*/
+
     if (fetcher_->Run(PulseInterval_) != pkgAcquire::Continue)
         return;
 
@@ -1409,6 +1432,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) {
         return;
     if (result != pkgPackageManager::Completed)
         return;
+
+    _assert(list.ReadMainList());
 }
 
 - (void) upgrade {
@@ -1616,14 +1641,7 @@ NSString *Scour(const char *field, const char *begin, const char *end) {
     if ([pages_ count] != 0)
         [[pages_ lastObject] setPageActive:NO];
 
-    NSString *title = [page title]; {
-        const char *data = [title UTF8String];
-        size_t size = [title length];
-
-        Pcre title_r("^(.*?)( \\(.*\\))?$");
-        if (title_r(data, size))
-            title = title_r[1];
-    }
+    NSString *title = Simplify([page title]);
 
     NSString *backButtonTitle = [page backButtonTitle];
     if (backButtonTitle == nil)
@@ -2360,7 +2378,6 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
         GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14);
 
         icon_ = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
-        [icon_ zoomToScale:0.5f];
 
         name_ = [[UITextLabel alloc] initWithFrame:CGRectMake(48, 8, 240, 25)];
         [name_ setBackgroundColor:Clear_];
@@ -2398,8 +2415,14 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
         image = [UIImage imageAtPath:[icon substringFromIndex:6]];
     if (image == nil)
         image = [UIImage applicationImageNamed:@"unknown.png"];
-
     [icon_ setImage:image];
+
+    if (image != nil) {
+        CGSize size = [image size];
+        float scale = 30 / std::max(size.width, size.height);
+        [icon_ zoomToScale:scale];
+    }
+
     [icon_ setFrame:CGRectMake(10, 10, 30, 30)];
 
     [name_ setText:[package name]];
@@ -2419,7 +2442,7 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
         trusted = false;
     }
 
-    [source_ setText:[NSString stringWithFormat:@"from %@", label]];
+    [source_ setText:[NSString stringWithFormat:@"from %@ (%@)", label, Simplify([package section])]];
 
     if (trusted)
         [self addSubview:trusted_];
@@ -2859,7 +2882,10 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 - (id) initWithBook:(RVBook *)book database:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object;
 
 - (void) setDelegate:(id)delegate;
+- (void) setObject:(id)object;
+
 - (void) reloadData;
+- (void) resetCursor;
 
 @end
 
@@ -2954,6 +2980,15 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     delegate_ = delegate;
 }
 
+- (void) setObject:(id)object {
+    if (object_ != nil)
+        [object_ release];
+    if (object == nil)
+        object_ = nil;
+    else
+        object_ = [object retain];
+}
+
 - (void) reloadData {
     NSArray *packages = [database_ packages];
 
@@ -2993,6 +3028,10 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     [list_ resetViewAnimated:animated];
 }
 
+- (void) resetCursor {
+    [[list_ table] scrollPointVisibleAtTopLeft:CGPointMake(0, 0) animated:NO];
+}
+
 @end
 /* }}} */
 
@@ -3274,6 +3313,23 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 @end
 /* }}} */
 
+@interface CYBook : RVBook <
+    ProgressDelegate
+> {
+    _transient Database *database_;
+    UIView *overlay_;
+    UIProgressIndicator *indicator_;
+    UITextLabel *prompt_;
+    UIProgressBar *progress_;
+    bool updating_;
+}
+
+- (id) initWithFrame:(CGRect)frame database:(Database *)database;
+- (void) update;
+- (BOOL) updating;
+
+@end
+
 /* Install View {{{ */
 @interface InstallView : RVPage {
     _transient Database *database_;
@@ -3485,6 +3541,11 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     [book_ pushPage:view];
 }
 
+- (void) _leftButtonClicked {
+    [(CYBook *)book_ update];
+    [self reloadButtons];
+}
+
 - (void) _rightButtonClicked {
     [delegate_ distUpgrade];
 }
@@ -3591,6 +3652,10 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     [list_ resetViewAnimated:animated];
 }
 
+- (NSString *) leftButtonTitle {
+    return [(CYBook *)book_ updating] ? nil : @"Refresh";
+}
+
 - (NSString *) rightButtonTitle {
     return upgrades_ == 0 ? nil : [NSString stringWithFormat:@"Upgrade All (%u)", upgrades_];
 }
@@ -3606,9 +3671,14 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 - (void) showKeyboard:(BOOL)show;
 @end
 
-@interface SearchView : PackageTable {
+@interface SearchView : RVPage {
     UIView *accessory_;
     UISearchField *field_;
+    UITransitionView *transition_;
+    PackageTable *table_;
+    UIPreferencesTable *advanced_;
+    UIView *dimmed_;
+    bool flipped_;
 }
 
 - (id) initWithBook:(RVBook *)book database:(Database *)database;
@@ -3626,19 +3696,22 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 
     [accessory_ release];
     [field_ release];
+    [transition_ release];
+    [table_ release];
+    [advanced_ release];
+    [dimmed_ release];
     [super dealloc];
 }
 
 - (void) textFieldDidBecomeFirstResponder:(UITextField *)field {
     [delegate_ showKeyboard:YES];
-    [list_ setEnabled:NO];
-
-    /*CGColor dimmed(alpha, 0, 0, 0, 0.5);
-    [editor_ setBackgroundColor:dimmed];*/
+    [table_ setEnabled:NO];
+    [self addSubview:dimmed_];
 }
 
 - (void) textFieldDidResignFirstResponder:(UITextField *)field {
-    [list_ setEnabled:YES];
+    [dimmed_ removeFromSuperview];
+    [table_ setEnabled:YES];
     [delegate_ showKeyboard:NO];
 }
 
@@ -3657,19 +3730,38 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 }
 
 - (id) initWithBook:(RVBook *)book database:(Database *)database {
-    if ((self = [super
-        initWithBook:book
-        database:database
-        title:nil
-        filter:@selector(isSearchedForBy:)
-        with:nil
-    ]) != nil) {
-        CGRect cnfrect = {{0, 36}, {17, 18}};
+    if ((self = [super initWithBook:book]) != nil) {
+        CGRect pageBounds = [book_ pageBounds];
+
+        /*UIImageView *pinstripe = [[[UIImageView alloc] initWithFrame:pageBounds] autorelease];
+        [pinstripe setImage:[UIImage applicationImageNamed:@"pinstripe.png"]];
+        [self addSubview:pinstripe];*/
+
+        dimmed_ = [[UIView alloc] initWithFrame:pageBounds];
+        CGColor dimmed(space_, 0, 0, 0, 0.5);
+        [dimmed_ setBackgroundColor:dimmed];
+
+        transition_ = [[UITransitionView alloc] initWithFrame:pageBounds];
+        [self addSubview:transition_];
+
+        advanced_ = [[UIPreferencesTable alloc] initWithFrame:pageBounds];
+
+        table_ = [[PackageTable alloc]
+            initWithBook:book
+            database:database
+            title:nil
+            filter:@selector(isSearchedForBy:)
+            with:nil
+        ];
+
+        [transition_ transition:0 toView:table_];
+
+        CGRect cnfrect = {{3, 36}, {17, 18}};
 
         CGRect area;
-        area.origin.x = cnfrect.size.width + 6;
+        area.origin.x = cnfrect.size.width + 12;
         area.origin.y = 30;
-        area.size.width = [self bounds].size.width - area.origin.x - 12;
+        area.size.width = [self bounds].size.width - area.origin.x - 18;
         area.size.height = [UISearchField defaultHeight];
 
         field_ = [[UISearchField alloc] initWithFrame:area];
@@ -3701,20 +3793,47 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     } return self;
 }
 
+- (void) flipPage {
+    LKAnimation *animation = [LKTransition animation];
+    [animation setType:@"oglFlip"];
+    [animation setTimingFunction:[LKTimingFunction functionWithName:@"easeInEaseOut"]];
+    [animation setFillMode:@"extended"];
+    [animation setTransitionFlags:3];
+    [animation setDuration:10];
+    [animation setSpeed:0.35];
+    [animation setSubtype:(flipped_ ? @"fromLeft" : @"fromRight")];
+    [[transition_ _layer] addAnimation:animation forKey:0];
+    [transition_ transition:0 toView:(flipped_ ? (UIView *) table_ : (UIView *) advanced_)];
+    flipped_ = !flipped_;
+}
+
 - (void) configurePushed {
-    // XXX: implement flippy advanced panel
+    [field_ resignFirstResponder];
+    [self flipPage];
+}
+
+- (void) resetViewAnimated:(BOOL)animated {
+    if (flipped_)
+        [self flipPage];
+    [table_ resetViewAnimated:animated];
 }
 
 - (void) reloadData {
-    object_ = [[field_ text] retain];
-    [super reloadData];
-    [[list_ table] scrollPointVisibleAtTopLeft:CGPointMake(0, 0) animated:NO];
+    if (flipped_)
+        [self flipPage];
+    [table_ setObject:[field_ text]];
+    [table_ reloadData];
+    [table_ resetCursor];
 }
 
 - (UIView *) accessoryView {
     return accessory_;
 }
 
+- (NSString *) title {
+    return nil;
+}
+
 - (NSString *) backButtonTitle {
     return @"Search";
 }
@@ -3722,21 +3841,6 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 @end
 /* }}} */
 
-@interface CYBook : RVBook <
-    ProgressDelegate
-> {
-    _transient Database *database_;
-    UIView *overlay_;
-    UIProgressIndicator *indicator_;
-    UITextLabel *prompt_;
-    UIProgressBar *progress_;
-}
-
-- (id) initWithFrame:(CGRect)frame database:(Database *)database;
-- (void) update;
-
-@end
-
 @implementation CYBook
 
 - (void) dealloc {
@@ -3747,12 +3851,19 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
     [super dealloc];
 }
 
+- (BOOL) updating {
+    return updating_;
+}
+
 - (void) update {
+    [navbar_ setPrompt:@""];
     [navbar_ addSubview:overlay_];
     [indicator_ startAnimation];
     [prompt_ setText:@"Updating Database..."];
     [progress_ setProgress:0];
 
+    updating_ = true;
+
     [NSThread
         detachNewThreadSelector:@selector(_update)
         toTarget:self
@@ -3761,6 +3872,8 @@ void AddTextView(NSMutableDictionary *fields, NSMutableArray *packages, NSString
 }
 
 - (void) _update_ {
+    updating_ = false;
+
     [overlay_ removeFromSuperview];
     [indicator_ stopAnimation];
     [delegate_ reloadData];