From 635071315f940d08c2c9ec7adbeb1b46a5b03883 Mon Sep 17 00:00:00 2001 From: rpechayr Date: Tue, 16 Nov 2010 10:29:45 +0000 Subject: [PATCH] [iphone/Barcodes] archive functionnality now works! Sometimes, delete archive will cause a crash, but I cannot reliably reproduce the bug. Also, another little bug is that all scans in archive are of type ABC (text), even though we scan a URL or something git-svn-id: https://zxing.googlecode.com/svn/trunk@1656 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../Barcodes.xcodeproj/project.pbxproj | 6 ++++++ iphone/Barcodes/Classes/ArchiveController.h | 7 +++---- iphone/Barcodes/Classes/ArchiveController.m | 21 ++++++++++++------- .../Barcodes/Classes/MessageViewController.h | 9 ++++---- .../Barcodes/Classes/MessageViewController.m | 2 +- .../Classes/ModalViewControllerDelegate.h | 15 +++++++++++++ .../Barcodes/Classes/ZXMainViewController.h | 3 ++- .../Barcodes/Classes/ZXMainViewController.mm | 3 ++- 8 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 iphone/Barcodes/Classes/ModalViewControllerDelegate.h diff --git a/iphone/Barcodes/Barcodes.xcodeproj/project.pbxproj b/iphone/Barcodes/Barcodes.xcodeproj/project.pbxproj index d6dea7234..28c625200 100755 --- a/iphone/Barcodes/Barcodes.xcodeproj/project.pbxproj +++ b/iphone/Barcodes/Barcodes.xcodeproj/project.pbxproj @@ -139,6 +139,7 @@ 1FB4369512918FF0002D63E8 /* ScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScanViewController.m; sourceTree = ""; }; 1FB4369912919014002D63E8 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; 1FB436DE129194E7002D63E8 /* scans.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = scans.db; sourceTree = ""; }; + 1FB437B612928EDA002D63E8 /* ModalViewControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModalViewControllerDelegate.h; sourceTree = ""; }; 288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = ""; }; 29B97316FDCFA39411CA2CEA /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; }; @@ -189,6 +190,7 @@ 1FB430341290002C002D63E8 /* ZXMainViewController.h */, 1FB430351290002C002D63E8 /* ZXMainViewController.mm */, 1FB430361290002C002D63E8 /* ZXMainViewController.xib */, + 1FB437B612928EDA002D63E8 /* ModalViewControllerDelegate.h */, ); path = Classes; sourceTree = ""; @@ -507,6 +509,10 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Barcodes_Prefix.pch; INFOPLIST_FILE = "Barcodes-Info.plist"; + OTHER_LDFLAGS = ( + "-all_load", + "-Objc", + ); PRODUCT_NAME = Barcodes; }; name = Debug; diff --git a/iphone/Barcodes/Classes/ArchiveController.h b/iphone/Barcodes/Classes/ArchiveController.h index c8ee5e5df..530d16bd2 100644 --- a/iphone/Barcodes/Classes/ArchiveController.h +++ b/iphone/Barcodes/Classes/ArchiveController.h @@ -20,19 +20,18 @@ */ #import - -//@class DecoderViewController; +#import "ModalViewControllerDelegate.h" @interface ArchiveController : UITableViewController { NSMutableArray *scans; NSMutableArray *results; -// DecoderViewController *decoderViewController; NSDateFormatter *dateFormatter; + id delegate; } @property (nonatomic, retain) NSMutableArray *scans; @property (nonatomic, retain) NSMutableArray *results; -//@property (nonatomic, retain) DecoderViewController *decoderViewController; +@property (nonatomic, assign) id delegate; @property (nonatomic, retain) NSDateFormatter *dateFormatter; - (NSInteger)scanIndexForRow:(NSInteger)row; diff --git a/iphone/Barcodes/Classes/ArchiveController.m b/iphone/Barcodes/Classes/ArchiveController.m index eafab1ccd..10dd8e44b 100644 --- a/iphone/Barcodes/Classes/ArchiveController.m +++ b/iphone/Barcodes/Classes/ArchiveController.m @@ -24,7 +24,6 @@ #import "Scan.h" #import "ResultParser.h" #import "ParsedResult.h" -//#import "DecoderViewController.h" #import "ScanViewController.h" #import "ScanCell.h" @@ -32,7 +31,7 @@ @synthesize scans; @synthesize results; -//@synthesize decoderViewController; +@synthesize delegate; @synthesize dateFormatter; - (id)init { @@ -114,7 +113,7 @@ - (void)dealloc { [scans release]; [results release]; - //[decoderViewController release]; + delegate = nil; [dateFormatter release]; [super dealloc]; } @@ -124,11 +123,8 @@ [super viewDidLoad]; self.title = NSLocalizedString(@"ScanArchiveTitle", @"Scan Archive"); self.navigationItem.rightBarButtonItem = [self editButtonItem]; -} - - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; + self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)] autorelease]; + self.scans = [NSMutableArray arrayWithArray:[[Database sharedDatabase] scans]]; self.results = [NSMutableArray arrayWithCapacity:self.scans.count]; for (Scan *scan in scans) { @@ -136,6 +132,15 @@ } } +-(void)done:(id)sender { + [delegate modalViewControllerWantsToBeDismissed:self]; +} + + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } diff --git a/iphone/Barcodes/Classes/MessageViewController.h b/iphone/Barcodes/Classes/MessageViewController.h index a1a7be3d8..1d963870d 100644 --- a/iphone/Barcodes/Classes/MessageViewController.h +++ b/iphone/Barcodes/Classes/MessageViewController.h @@ -20,11 +20,10 @@ */ #import +#import "ModalViewControllerDelegate.h" @class MessageViewController; -@protocol MessageViewControllerDelegate -- (void)messageViewControllerWantsToBeDispissed:(MessageViewController *)controller; -@end + @interface MessageViewController : UIViewController { // id callbackTarget; @@ -32,7 +31,7 @@ // SEL callbackSelectorFailure; NSURL *contentURL; IBOutlet UIWebView *webView; - id delegate; + id delegate; } //@property (nonatomic, retain) id callbackTarget; @@ -40,7 +39,7 @@ //@property (nonatomic, assign) SEL callbackSelectorFailure; @property (nonatomic,retain) IBOutlet UIWebView *webView; -@property (nonatomic,assign) id delegate; +@property (nonatomic,assign) id delegate; @property (nonatomic, retain) NSURL *contentURL; - (id)initWithMessageFilename:(NSString *)filename; diff --git a/iphone/Barcodes/Classes/MessageViewController.m b/iphone/Barcodes/Classes/MessageViewController.m index 47741ecbd..53b8b0a80 100644 --- a/iphone/Barcodes/Classes/MessageViewController.m +++ b/iphone/Barcodes/Classes/MessageViewController.m @@ -44,7 +44,7 @@ } - (IBAction)dismiss:(id)sender { - [delegate messageViewControllerWantsToBeDispissed:self]; + [delegate modalViewControllerWantsToBeDismissed:self]; } - (void)loadView { diff --git a/iphone/Barcodes/Classes/ModalViewControllerDelegate.h b/iphone/Barcodes/Classes/ModalViewControllerDelegate.h new file mode 100644 index 000000000..0b7ac91de --- /dev/null +++ b/iphone/Barcodes/Classes/ModalViewControllerDelegate.h @@ -0,0 +1,15 @@ +// +// ModalViewControllerDelegate.h +// Barcodes +// +// Created by Romain Pechayre on 11/16/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import + + +@protocol ModalViewControllerDelegate +- (void)modalViewControllerWantsToBeDismissed:(UIViewController *)controller; + +@end diff --git a/iphone/Barcodes/Classes/ZXMainViewController.h b/iphone/Barcodes/Classes/ZXMainViewController.h index 5caac0c7a..44b5d6fca 100644 --- a/iphone/Barcodes/Classes/ZXMainViewController.h +++ b/iphone/Barcodes/Classes/ZXMainViewController.h @@ -9,12 +9,13 @@ #import #import "ZXingWidgetController.h" #import "MessageViewController.h" +#import "ModalViewControllerDelegate.h" @class UniversalResultParser; @class ParsedResult; -@interface ZXMainViewController : UIViewController { +@interface ZXMainViewController : UIViewController { UniversalResultParser *resultParser; NSArray *actions; ParsedResult *result; diff --git a/iphone/Barcodes/Classes/ZXMainViewController.mm b/iphone/Barcodes/Classes/ZXMainViewController.mm index cb2f911ea..31a1a8094 100644 --- a/iphone/Barcodes/Classes/ZXMainViewController.mm +++ b/iphone/Barcodes/Classes/ZXMainViewController.mm @@ -88,13 +88,14 @@ - (IBAction)showArchive:(id)sender { ArchiveController *archiveController = [[ArchiveController alloc] init]; + archiveController.delegate = self; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:archiveController]; [self presentModalViewController:navController animated:YES]; [navController release]; [archiveController release]; } -- (void)messageViewControllerWantsToBeDispissed:(MessageViewController *)controller { +- (void)modalViewControllerWantsToBeDismissed:(UIViewController *)controller { [self dismissModalViewControllerAnimated:YES]; }