Hack around issues with the settings screen. t20
authorStefane Fermigier <sfermigier@nuxeo.com>
Tue, 09 Mar 2010 12:31:58 +0100
brancht20
changeset 391e221a5b27f2
parent 38 66ef59e17ee3
child 40 d63a83dcca61
Hack around issues with the settings screen.
Classes/CmisClient.h
Classes/CmisClient.m
Classes/FolderViewController.h
Classes/FolderViewController.m
Classes/SettingsViewController.m
ROADMAP.txt
     1.1 --- a/Classes/CmisClient.h
     1.2 +++ b/Classes/CmisClient.h
     1.3 @@ -26,5 +26,6 @@
     1.4  - (NSURL*)fetchDocumentAt:(NSURL*)url;
     1.5  - (NSMutableURLRequest *)makeRequestForURL:(NSURL *)url consumes:(NSString*)mimeType;
     1.6  - (void)fetchServiceDocument;
     1.7 +- (void)connect;
     1.8  
     1.9  @end
     2.1 --- a/Classes/CmisClient.m
     2.2 +++ b/Classes/CmisClient.m
     2.3 @@ -30,25 +30,19 @@
     2.4  
     2.5  - (id)init {
     2.6      [super init];
     2.7 -    
     2.8 +    [self connect];
     2.9 +    return self;
    2.10 +}
    2.11 +
    2.12 +- (void)connect {
    2.13      self.username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username"];
    2.14  	self.password = [[NSUserDefaults standardUserDefaults] stringForKey:@"password"];
    2.15 -
    2.16 -    if (self.username == nil) {
    2.17 -        self.username = @"Administrator";
    2.18 +    NSString *serviceUrlStr = [[NSUserDefaults standardUserDefaults] stringForKey:@"serviceUrl"];
    2.19 +    NSLog(@"serviceUrl = %@", serviceUrlStr);
    2.20 +    if (serviceUrlStr != nil) {
    2.21 +        self.serviceUrl = [NSURL URLWithString:serviceUrlStr];
    2.22 +        [self fetchServiceDocument];
    2.23      }
    2.24 -    if (self.password == nil) {
    2.25 -        self.password = @"Administrator";
    2.26 -    }
    2.27 -    NSString *defaultUrl = [[NSUserDefaults standardUserDefaults] stringForKey:@"serviceUrl"];
    2.28 -    if (defaultUrl == nil) {
    2.29 -        defaultUrl = @"http://cmis.demo.nuxeo.org/nuxeo/site/cmis/repository";
    2.30 -    }
    2.31 -    
    2.32 -    self.serviceUrl = [NSURL URLWithString:defaultUrl];
    2.33 -
    2.34 -    [self fetchServiceDocument];
    2.35 -    return self;
    2.36  }
    2.37  
    2.38  - (NXFolder*)getFolderInfoAt:(NSURL*)url {
    2.39 @@ -119,10 +113,20 @@
    2.40      // Parse service document
    2.41      NSString *query = @"//*[local-name()='collection' and child::*[local-name()='collectionType' and text()='root']]/@href";
    2.42      NSString *result = [self queryXPath:data withQuery:query];
    2.43 -    self.rootCollectionUrl = [NSURL URLWithString:result];
    2.44 +    if (result == nil) {
    2.45 +        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error fetching remote repository info"
    2.46 +                                                            message:@""
    2.47 +                                                           delegate:nil
    2.48 +                                                  cancelButtonTitle:@"OK?"
    2.49 +                                                  otherButtonTitles:nil];
    2.50 +        [alertView show];
    2.51 +    } else {
    2.52 +        self.rootCollectionUrl = [NSURL URLWithString:result];
    2.53 +    }
    2.54  }
    2.55  
    2.56  - (NSData *)get:(NSURL*)url consumes:(NSString*)mimeType {
    2.57 +    NSLog(@"URL: %@", url);
    2.58      NSMutableURLRequest *request = [self makeRequestForURL:url consumes:mimeType];
    2.59      NSHTTPURLResponse *response;
    2.60      NSError *error;
    2.61 @@ -130,13 +134,15 @@
    2.62      NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    2.63      [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    2.64      if ([response statusCode] != 200) {
    2.65 -        NSString *msg = [NSString stringWithFormat:@"URL: %@\n", url];
    2.66 +        NSLog(@"Status code: %d", [response statusCode]);
    2.67 +        NSString *msg = [NSString stringWithFormat:@"URL: %@\nPlease check or update settings.", url];
    2.68          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error fetching remote object"
    2.69                                                              message:msg
    2.70                                                             delegate:nil
    2.71 -                                                  cancelButtonTitle:@"Retry?"
    2.72 +                                                  cancelButtonTitle:@"OK?"
    2.73                                                    otherButtonTitles:nil];
    2.74          [alertView show];
    2.75 +        return nil;
    2.76      }
    2.77      return data;
    2.78  }    
     3.1 --- a/Classes/FolderViewController.h
     3.2 +++ b/Classes/FolderViewController.h
     3.3 @@ -19,5 +19,6 @@
     3.4  @property (nonatomic, retain) NXFolder *folder;
     3.5  @property (nonatomic, retain) NSURL *url;
     3.6  
     3.7 +- (void)refresh;
     3.8  
     3.9  @end
     4.1 --- a/Classes/FolderViewController.m
     4.2 +++ b/Classes/FolderViewController.m
     4.3 @@ -19,7 +19,7 @@
     4.4  - (void)viewDidLoad {
     4.5      [super viewDidLoad];
     4.6      
     4.7 -    self.navigationItem.rightBarButtonItem = infoButton;
     4.8 +    //self.navigationItem.rightBarButtonItem = infoButton;
     4.9  
    4.10      CmisClient *client = [CmisClient sharedClient];
    4.11      if (self.url == nil) {
    4.12 @@ -28,6 +28,14 @@
    4.13      self.folder = [client getFolderInfoAt:self.url];
    4.14  }
    4.15  
    4.16 +// TODO: hack for now
    4.17 +- (void)refresh {
    4.18 +    CmisClient *client = [CmisClient sharedClient];
    4.19 +    self.url = client.rootCollectionUrl;
    4.20 +    self.folder = [client getFolderInfoAt:self.url];
    4.21 +    [self.tableView reloadData]; 
    4.22 +}
    4.23 +    
    4.24  - (void)dealloc {
    4.25      [folder release];
    4.26      [url release];
    4.27 @@ -46,6 +54,7 @@
    4.28  
    4.29  // Customize the number of rows in the table view.
    4.30  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    4.31 +    NSLog(@"numberOfRowsInSection called, url = %@", self.url);
    4.32      return [self.folder.children count];
    4.33  }
    4.34  
     5.1 --- a/Classes/SettingsViewController.m
     5.2 +++ b/Classes/SettingsViewController.m
     5.3 @@ -7,6 +7,8 @@
     5.4  //
     5.5  
     5.6  #import "SettingsViewController.h"
     5.7 +#import "CmisClient.h"
     5.8 +#import "FolderViewController.h"
     5.9  
    5.10  @interface SettingsViewController (Private)
    5.11  - (void)enableSaveButtonIfNeeded;
    5.12 @@ -21,6 +23,7 @@
    5.13      self.navigationItem.leftBarButtonItem = cancelButton;
    5.14      
    5.15      NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    5.16 +    NSLog(@"serviceUrl = %@", [userDefaults stringForKey:@"serviceUrl"]);
    5.17      serviceUrlField.text = [userDefaults stringForKey:@"serviceUrl"];
    5.18      usernameField.text = [userDefaults stringForKey:@"username"];
    5.19      passwordField.text = [userDefaults stringForKey:@"password"];
    5.20 @@ -55,10 +58,25 @@
    5.21  }
    5.22  
    5.23  - (IBAction)cancel {
    5.24 +    self.tabBarController.selectedIndex = 0;
    5.25  }
    5.26      
    5.27  - (IBAction)save {
    5.28 -    [self showSpinner];
    5.29 +    // TODO: validate values
    5.30 +    //[self showSpinner];
    5.31 +    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    5.32 +    [userDefaults setObject:usernameField.text forKey:@"username"];
    5.33 +    [userDefaults setObject:passwordField.text forKey:@"password"];
    5.34 +    [userDefaults setObject:serviceUrlField.text forKey:@"serviceUrl"];
    5.35 +    [userDefaults synchronize];
    5.36 +    
    5.37 +    [[CmisClient sharedClient] connect];
    5.38 +
    5.39 +    self.tabBarController.selectedIndex = 0;
    5.40 +    UINavigationController *browseController = (UINavigationController *) self.tabBarController.selectedViewController;
    5.41 +    [browseController popToRootViewControllerAnimated:YES];
    5.42 +    UIViewController *topFolderController = browseController.topViewController;
    5.43 +    [(FolderViewController *) browseController.topViewController refresh];
    5.44  }
    5.45  
    5.46  #pragma mark -
     6.1 --- a/ROADMAP.txt
     6.2 +++ b/ROADMAP.txt
     6.3 @@ -14,15 +14,17 @@
     6.4    + size
     6.5    + Creator
     6.6  + Order folders in a predictable way
     6.7 -- Implement settings screen
     6.8 ++ Implement settings screen
     6.9  
    6.10  v 0.1.5:
    6.11  
    6.12 +- Improve settings and refresh
    6.13  - Implement search
    6.14  - Add bottom bar to splash view
    6.15  - Proper memory management
    6.16  - Better Logo / splashscreen
    6.17    See: <http://blog.cocoia.com/2007/making-iphone-icons/> for tips
    6.18 +- Investigate why it doesn't work w/ MS Office documents
    6.19  
    6.20  V 0.2:
    6.21