Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Creating Plugins    Meeting Minutes in Cocoa
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Apprentice
Posted
I am trying to write a plug in for Daylite that adds a timeblock with meeting minutes. I created the timeblock, but can't seem to get the meeting minutes added. Here's what I got;

MCPDocument *doc = [NSApp firstDocumentWithKindOfClassNamed:@"MCPDocument"];
MCPObjectContext *oc = [doc objectContext];
MCCreationContext *cc = [oc creationContext];


MCPObject *new_appointment = [cc createObjectForEntityNamed:@"Timeblock" addToObjectContext:YES];

[new_appointment setValue:@"This is an appointment made with Cocoa." forKey:@"Subject"];
[new_appointment setValue:@"This is details field" forKey:@"Details"];
[new_appointment setValue:[NSNumber numberWithInt:4] forKey:@"StatusCode"];
[new_appointment setValue:[NSNumber numberWithInt:6] forKey:@"TypeCode"];

MCPObject *meeting_minutes = [cc createObjectForEntityNamed:@"LargeData" addToObjectContext:NO];
NSAttributedString *mmStr = [[NSAttributedString alloc] initWithString:@"yo these are the minutes"];
[meeting_minutes setValue:mmStr forKey:@"AttributedStringRepresentation"];
[mmStr release];


[oc saveChanges];


The first part creating the new_appointment works fine, but the meeting minutes stuff crashes Daylite. Any ideas or help on how I go about creating the meeting minutes. AJ helped me do it F-Script but it turns out I need it in Cocoa.

Thanks for the help.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Ali Lalani
Posted Hide Post
For attributes you don't want to capitalize the key name, for that we use "camel case" which means the first letter is lowercase then upper case for the start of each subsequent word.

So what you'd want is this:

[new_appointment setValue:@"This is an appointment made with Cocoa." forKey:@"subject"];
[new_appointment setValue:@"This is details field" forKey:@"details"];
[new_appointment setValue:[NSNumber numberWithInt:4] forKey:@"statusCode"];
[new_appointment setValue:[NSNumber numberWithInt:6] forKey:@"typeCode"];

For getting the meeting minutes you can do it like this:

MCPObject *meeting_minutes = [new_appointment createAndSetMeetingMinutesIfNeeded];

And then, to set a value to it, more or less like you've done it but with the lowercase attribute name:

NSAttributedString *mmStr = [[NSAttributedString alloc] initWithString:@"yo these are the minutes"];
[meeting_minutes setValue:mmStr forKey:@"attributedStringRepresentation"];
[mmStr release];


That should get it to work properly, let us know if it doesn't.
 
Posts: 108 | Registered: June 15, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
It Xcode gives me a warning when I try build it but it still builds.

It still crashes Daylite. Here is the crash message it sends me;

[<GWLargeData 0x17c88540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key attributedStringRepresentation.
NSExceptionHandlerExceptionRaiser (in ExceptionHandling)
objc_exception_throw (in libobjc.A.dylib)
-[NSException raise] (in CoreFoundation)
_NSSetUsingKeyValueSetter (in Foundation)
-[NSObject(NSKeyValueCoding) setValue:forKey:] (in Foundation)
-[iChatAppointmentCommand __iChatAppointmentCommand:] (in iChatAppointment)
__invoking___ (in CoreFoundation)
-[NSInvocation invoke] (in CoreFoundation)
-[NSInvocation invokeWithTarget:] (in CoreFoundation)
-[MCMenuManager originatingController:forwardInvocation:forObjectsrazzarentObjects:] (in MCApplication)
-[MCMainWindowController forwardInvocation:] (in MCApplication)
___forwarding___ (in CoreFoundation)
_CF_forwarding_prep_0 (in CoreFoundation)
-[NSApplication sendAction:to:from:] (in AppKit)
-[NSMenu performActionForItemAtIndex:] (in AppKit)
-[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit)
AppKitMenuEventHandler (in AppKit)
DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) (in HIToolbox)
SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) (in HIToolbox)
SendEventToEventTarget (in HIToolbox)
SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) (in HIToolbox)
SendMenuCommandWithContextAndModifiers (in HIToolbox)
SendMenuItemSelectedEvent (in HIToolbox)
FinishMenuSelection(MenuData*, MenuData*, MenuResult*, MenuResult*, unsigned long, unsigned long, unsigned long, unsigned char) (in HIToolbox)
MenuSelectCore(MenuData*, Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) (in HIToolbox)
_HandleMenuSelection2 (in HIToolbox)
_HandleMenuSelection (in HIToolbox)
_NSHandleCarbonMenuEvent (in AppKit)
_DPSNextEvent (in AppKit)
-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
-[NSApplication run] (in AppKit)
NSApplicationMain (in AppKit)
_start (in Daylite)
start (in Daylite)
0x2

Thanks for your help. I appreciate it.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
I forgot to list the compiler warning message;

warning: 'MCPObject' may not respond to '-createAndSetMeetingMinutesIfNeeded'
(Messages without a matching method signature will be assumd to return 'id' and accept '...' as arguments.)

Thanks.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Ali Lalani
Posted Hide Post
My bad, actually it is a bit more complicated than this since it seems we don't have an easy convenience for setting an NSAttributedString. What we save to the database is an NSData, so you have to convert the attributed string to NSData. Try this out:

NSAttributedString *mmStr = [[NSAttributedString alloc] initWithString:@"yo these are the minutes"];

// Get an NSData from the attributed string
NSError *error = nil;
NSData *strData = [mmStr dataFromRange:NSMakeRange(0,[mmstr length]) documentAttributes:nil error:&error];

// if there was an error creating an NSData from the string, should probably be handled gracefully somehow
if (error) {
NSLog(@"Error: %@",error);
}
else {
[meeting_minutes setValue:strData forKey:@"rawData"];
}

[mmStr release];
 
Posts: 108 | Registered: June 15, 2006Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Ali Lalani
Posted Hide Post
Regarding the warning, it's harmless, but you can get around it by wrapping the call in a valueForKey:

MCPObject *meeting_minutes = [new_appointment valueForKey:@"createAndSetMeetingMinutesIfNeeded"];
 
Posts: 108 | Registered: June 15, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
Ali,

Thank you very much for your help. I was able to compile and run the plugin without crashing Daylite. When I run the plug-in the text does not get added to the appointment.

I checked the Console since we sent an error to NSLog and it says;

5/5/08 6:55:41 PM Daylite[8063] Error: Error Domain=NSCocoaErrorDomain Code=66062 "File could not be saved because the specified format is not supported."

Here's my total code so far;

MCPDocument *doc = [NSApp firstDocumentWithKindOfClassNamed:@"MCPDocument"];
MCPObjectContext *oc = [doc objectContext];
MCCreationContext *cc = [oc creationContext];


MCPObject *new_appointment = [cc createObjectForEntityNamed:@"Timeblock" addToObjectContext:YES];

[new_appointment setValue:@"This is an appointment made with Cocoa." forKey:@"subject"];
[new_appointment setValue:@"This is details field" forKey:@"details"];
[new_appointment setValue:[NSNumber numberWithInt:4] forKey:@"statusCode"];
[new_appointment setValue:[NSNumber numberWithInt:6] forKey:@"typeCode"];


MCPObject *meeting_minutes = [new_appointment valueForKey:@"createAndSetMeetingMinutesIfNeeded"];

NSAttributedString *mmStr = [[NSAttributedString alloc] initWithString:@"yo these are the minutes"];

// Get an NSData from the attributed string
NSError *error = nil;
NSData *strData = [mmStr dataFromRange:NSMakeRange(0,[mmStr length]) documentAttributes:nil error:&error];

// if there was an error creating an NSData from the string, should probably be handled gracefully somehow
if (error) {
NSLog(@"Error: %@",error);
}
else {
[meeting_minutes setValue:strData forKey:@"rawData"];
}

[mmStr release];

[oc saveChanges];

So something is happening with the string.


Thanks for your help, I really appreciate it very much.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Ali Lalani
Posted Hide Post
Yeah, it looks like that method to encode the attributed string as NSData requires that you pass in document attributes. Try this:

NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
NSRTFTextDocumentType, NSDocumentTypeDocumentAttribute,
nil];

NSData *strData = [mmStr dataFromRange:NSMakeRange(0,[mmStr length]) documentAttributes:attr error:&error];
 
Posts: 108 | Registered: June 15, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
Ali,

Thank you so much for your help. It worked perfectly. No errors at all.

Thank you so much for your help and to AJ as well.

Thanks
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Creating Plugins    Meeting Minutes in Cocoa

© Copyright 2006 Marketcircle Inc. All rights reserved.