Permalink
Browse files

Fixing iPhoneXMPP xcode project.

  • Loading branch information...
1 parent 6776b24 commit f160d2ce04fcf8857f225cb888d87bf1a4318b01 @robbiehanson committed Aug 30, 2011
@@ -3,10 +3,9 @@
#import "XMPPRoster.h"
#import "XMPPCoreDataStorage.h"
-
-@class XMPPUserCoreDataStorageObject;
-@class XMPPGroupCoreDataStorageObject;
-@class XMPPResourceCoreDataStorageObject;
+#import "XMPPUserCoreDataStorageObject.h"
+#import "XMPPGroupCoreDataStorageObject.h"
+#import "XMPPResourceCoreDataStorageObject.h"
/**
* This class is an example implementation of XMPPRosterStorage using core data.
@@ -200,7 +200,7 @@
DC84BB55124408EC0055A459 /* XMPPTransports.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPTransports.h; path = "../../Extensions/XEP-0100/XMPPTransports.h"; sourceTree = SOURCE_ROOT; };
DC84BB56124408EC0055A459 /* XMPPTransports.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPTransports.m; path = "../../Extensions/XEP-0100/XMPPTransports.m"; sourceTree = SOURCE_ROOT; };
DC84BB5A1244090D0055A459 /* XMPPCapabilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPCapabilities.h; path = "../../Extensions/XEP-0115/XMPPCapabilities.h"; sourceTree = SOURCE_ROOT; };
- DC84BB5B1244090D0055A459 /* XMPPCapabilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = XMPPCapabilities.m; path = "../../Extensions/XEP-0115/XMPPCapabilities.m"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
+ DC84BB5B1244090D0055A459 /* XMPPCapabilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; name = XMPPCapabilities.m; path = "../../Extensions/XEP-0115/XMPPCapabilities.m"; sourceTree = SOURCE_ROOT; };
DC84BB771244095D0055A459 /* XMPPPing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPPing.h; path = "../../Extensions/XEP-0199/XMPPPing.h"; sourceTree = SOURCE_ROOT; };
DC84BB781244095D0055A459 /* XMPPPing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPPing.m; path = "../../Extensions/XEP-0199/XMPPPing.m"; sourceTree = SOURCE_ROOT; };
DCA614ED1250034B00C75522 /* XMPPDateTimeProfiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPDateTimeProfiles.h; path = "../../Extensions/XEP-0082/XMPPDateTimeProfiles.h"; sourceTree = SOURCE_ROOT; };
@@ -2,12 +2,8 @@
#import <CoreData/CoreData.h>
-@class iPhoneXMPPAppDelegate;
-
-
@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate>
{
- NSManagedObjectContext *managedObjectContext;
NSFetchedResultsController *fetchedResultsController;
}
@@ -1,18 +1,16 @@
#import "RootViewController.h"
-#import "SettingsViewController.h"
#import "iPhoneXMPPAppDelegate.h"
+#import "SettingsViewController.h"
-#import "XMPP.h"
-#import "XMPPRosterCoreDataStorage.h"
-#import "XMPPUserCoreDataStorageObject.h"
-#import "XMPPResourceCoreDataStorageObject.h"
-#import "XMPPvCardAvatarModule.h"
-
+#import "XMPPFramework.h"
#import "DDLog.h"
// Log levels: off, error, warn, info, verbose
-static const int ddLogLevel = LOG_LEVEL_VERBOSE;
-
+#if DEBUG
+ static const int ddLogLevel = LOG_LEVEL_VERBOSE;
+#else
+ static const int ddLogLevel = LOG_LEVEL_INFO;
+#endif
@implementation RootViewController
@@ -25,21 +23,6 @@ - (iPhoneXMPPAppDelegate *)appDelegate
return (iPhoneXMPPAppDelegate *)[[UIApplication sharedApplication] delegate];
}
-- (XMPPStream *)xmppStream
-{
- return [[self appDelegate] xmppStream];
-}
-
-- (XMPPRoster *)xmppRoster
-{
- return [[self appDelegate] xmppRoster];
-}
-
-- (XMPPRosterCoreDataStorage *)xmppRosterStorage
-{
- return [[self xmppRoster] xmppRosterStorage];
-}
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark View lifecycle
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -78,44 +61,6 @@ - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark Core Data
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-- (NSManagedObjectContext *)managedObjectContext
-{
- if (managedObjectContext == nil)
- {
- managedObjectContext = [[NSManagedObjectContext alloc] init];
-
- NSPersistentStoreCoordinator *psc = [[self xmppRosterStorage] persistentStoreCoordinator];
- [managedObjectContext setPersistentStoreCoordinator:psc];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(contextDidSave:)
- name:NSManagedObjectContextDidSaveNotification
- object:nil];
- }
-
- return managedObjectContext;
-}
-
-- (void)contextDidSave:(NSNotification *)notification
-{
- NSManagedObjectContext *sender = (NSManagedObjectContext *)[notification object];
-
- if (sender != managedObjectContext &&
- [sender persistentStoreCoordinator] == [managedObjectContext persistentStoreCoordinator])
- {
- DDLogError(@"%@: %@", THIS_FILE, THIS_METHOD);
-
- [managedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
- withObject:notification
- waitUntilDone:NO];
- }
-}
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark NSFetchedResultsController
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -124,8 +69,10 @@ - (NSFetchedResultsController *)fetchedResultsController
{
if (fetchedResultsController == nil)
{
+ NSManagedObjectContext *moc = [[self appDelegate] managedObjectContext_roster];
+
NSEntityDescription *entity = [NSEntityDescription entityForName:@"XMPPUserCoreDataStorageObject"
- inManagedObjectContext:[self managedObjectContext]];
+ inManagedObjectContext:moc];
NSSortDescriptor *sd1 = [[NSSortDescriptor alloc] initWithKey:@"sectionNum" ascending:YES];
NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"displayName" ascending:YES];
@@ -138,7 +85,7 @@ - (NSFetchedResultsController *)fetchedResultsController
[fetchRequest setFetchBatchSize:10];
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
- managedObjectContext:[self managedObjectContext]
+ managedObjectContext:moc
sectionNameKeyPath:@"sectionNum"
cacheName:nil];
[fetchedResultsController setDelegate:self];
@@ -167,24 +114,24 @@ - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
#pragma mark UITableViewCell helpers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- (void)configurePhotoForCell:(UITableViewCell *)cell user:(id <XMPPUser>)user
+- (void)configurePhotoForCell:(UITableViewCell *)cell user:(XMPPUserCoreDataStorageObject *)user
{
- // XMPPRoster will cache photos as they arrive from the xmppvCardAvatarModule, we only need to
- // ask the avatar module for a photo, if the roster doesn't have it.
- if (user.photo != nil)
- {
- cell.imageView.image = user.photo;
- }
- else
- {
- NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
-
- if (photoData != nil) {
- cell.imageView.image = [UIImage imageWithData:photoData];
- } else {
- cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
- }
- }
+ // Our xmppRosterStorage will cache photos as they arrive from the xmppvCardAvatarModule.
+ // We only need to ask the avatar module for a photo, if the roster doesn't have it.
+
+ if (user.photo != nil)
+ {
+ cell.imageView.image = user.photo;
+ }
+ else
+ {
+ NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
+
+ if (photoData != nil)
+ cell.imageView.image = [UIImage imageWithData:photoData];
+ else
+ cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
+ }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -243,18 +190,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
cell.textLabel.text = user.displayName;
-
- [self configurePhotoForCell:cell user:user];
-
+ [self configurePhotoForCell:cell user:user];
+
return cell;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Actions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- (IBAction)settings:(id)sender {
- [self.navigationController presentModalViewController:[[self appDelegate] settingsViewController] animated:YES];
+- (IBAction)settings:(id)sender
+{
+ [self.navigationController presentModalViewController:[[self appDelegate] settingsViewController] animated:YES];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,37 @@
+//
+// This file is designed to be customized by YOU.
+//
+// As you pick and choose which parts of the framework you need for your application, add them to this header file.
+//
+// Various modules available within the framework optionally interact with each other.
+// E.g. The XMPPPing module utilizes the XMPPCapabilities module to advertise support XEP-0199.
+//
+// However, the modules can only interact if they're both added to your xcode project.
+// E.g. If XMPPCapabilities isn't a part of your xcode project, then XMPPPing shouldn't attempt to reference it.
+//
+// So how do the individual modules know if other modules are available?
+// Via this header file.
+//
+// If you #import "XMPPCapabilities.h" in this file, then _XMPP_CAPABILITIES_H will be defined for other modules.
+// And they can automatically take advantage of it.
+//
+
+
+// CUSTOMIZE ME !
+//
+// THIS HEADER FILE SHOULD BE TAILORED TO MATCH YOUR APPLICATION.
+
+
+#import "XMPP.h"
+
+// List the modules you're using here.
+
+#import "XMPPReconnect.h"
+#import "XMPPRoster.h"
+#import "XMPPRosterCoreDataStorage.h"
+#import "XMPPvCardTempModule.h"
+#import "XMPPvCardCoreDataStorage.h"
+#import "XMPPCapabilities.h"
+#import "XMPPCapabilitiesCoreDataStorage.h"
+#import "XMPPvCardAvatarModule.h"
+
@@ -1,33 +1,32 @@
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
-#import "XMPPRoster.h"
+#import "XMPPFramework.h"
@class SettingsViewController;
-@class XMPPStream;
-@class XMPPReconnect;
-@class XMPPCapabilities;
-@class XMPPRosterCoreDataStorage;
-@class XMPPvCardAvatarModule;
-@class XMPPvCardTempModule;
@interface iPhoneXMPPAppDelegate : NSObject <UIApplicationDelegate, XMPPRosterDelegate>
{
XMPPStream *xmppStream;
XMPPReconnect *xmppReconnect;
- XMPPCapabilities *xmppCapabilities;
- XMPPRoster *xmppRoster;
-
- XMPPvCardAvatarModule *xmppvCardAvatarModule;
- XMPPvCardTempModule *xmppvCardTempModule;
+ XMPPRoster *xmppRoster;
+ XMPPRosterCoreDataStorage *xmppRosterStorage;
+ XMPPvCardCoreDataStorage *xmppvCardStorage;
+ XMPPvCardTempModule *xmppvCardTempModule;
+ XMPPvCardAvatarModule *xmppvCardAvatarModule;
+ XMPPCapabilities *xmppCapabilities;
+ XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;
+
+ NSManagedObjectContext *managedObjectContext_roster;
+ NSManagedObjectContext *managedObjectContext_capabilities;
NSString *password;
BOOL allowSelfSignedCertificates;
BOOL allowSSLHostNameMismatch;
- BOOL isOpen;
+ BOOL isXmppConnected;
UIWindow *window;
UINavigationController *navigationController;
@@ -37,16 +36,21 @@
@property (nonatomic, readonly) XMPPStream *xmppStream;
@property (nonatomic, readonly) XMPPReconnect *xmppReconnect;
-@property (nonatomic, readonly) XMPPCapabilities *xmppCapabilities;
@property (nonatomic, readonly) XMPPRoster *xmppRoster;
-@property (nonatomic, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
+@property (nonatomic, readonly) XMPPRosterCoreDataStorage *xmppRosterStorage;
@property (nonatomic, readonly) XMPPvCardTempModule *xmppvCardTempModule;
+@property (nonatomic, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
+@property (nonatomic, readonly) XMPPCapabilities *xmppCapabilities;
+@property (nonatomic, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet SettingsViewController *settingsViewController;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *loginButton;
+- (NSManagedObjectContext *)managedObjectContext_roster;
+- (NSManagedObjectContext *)managedObjectContext_capabilities;
+
- (BOOL)connect;
- (void)disconnect;
Oops, something went wrong.

0 comments on commit f160d2c

Please sign in to comment.