#include <SOGoUI/UIxComponent.h>
+/*
+ UIxMailEditor
+
+ An mail editor component which works on SOGoDraftObject's.
+*/
+
+@class NSArray, NSString;
+
@interface UIxMailEditor : UIxComponent
{
+ NSArray *to;
+ NSArray *cc;
+ NSArray *bcc;
+ NSString *subject;
+ NSString *text;
}
@end
@implementation UIxMailEditor
+- (void)dealloc {
+ [self->text release];
+ [self->subject release];
+ [self->to release];
+ [self->cc release];
+ [self->bcc release];
+ [super dealloc];
+}
+
+/* accessors */
+
+- (void)setSubject:(NSString *)_value {
+ ASSIGNCOPY(self->subject, _value);
+}
+- (NSString *)subject {
+ return self->subject;
+}
+
+- (void)setText:(NSString *)_value {
+ ASSIGNCOPY(self->text, _value);
+}
+- (NSString *)text {
+ return self->text;
+}
+
+- (void)setTo:(NSArray *)_value {
+ ASSIGNCOPY(self->to, _value);
+}
+- (NSArray *)to {
+ return self->to;
+}
+
+- (void)setCc:(NSArray *)_value {
+ ASSIGNCOPY(self->cc, _value);
+}
+- (NSArray *)cc {
+ return self->cc;
+}
+
+- (void)setBcc:(NSArray *)_value {
+ ASSIGNCOPY(self->bcc, _value);
+}
+- (NSArray *)bcc {
+ return self->bcc;
+}
+
/* requests */
- (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{
#include <SOGoUI/UIxComponent.h>
/*
- UIxMailToSelection
-
- Select a set of address headers for composing an email.
-
- Bindings:
- to - array of strings suitable for placement in a To: header
- cc - array of strings suitable for placement in a Cc: header
- bcc - array of strings suitable for placement in a Bcc: header
-
- Sample:
- <var:component className="UIxMailToSelection"
- to="to"
- cc="cc"
- bcc="bcc"
- />
- */
+ UIxMailToSelection
+
+ Select a set of address headers for composing an email.
+
+ Bindings:
+ to - array of strings suitable for placement in a To: header
+ cc - array of strings suitable for placement in a Cc: header
+ bcc - array of strings suitable for placement in a Bcc: header
+
+ Sample:
+ <var:component className="UIxMailToSelection"
+ to="to"
+ cc="cc"
+ bcc="bcc"
+ />
+*/
@class NSArray;
NSArray *to;
NSArray *cc;
NSArray *bcc;
- id item;
- id address;
+ id item;
+ id address;
NSArray *addressList;
- int currentIndex;
+ int currentIndex;
}
- (void)setTo:(NSArray *)_to;
+ (void)initialize {
static BOOL didInit = NO;
- if(didInit)
+ if (didInit)
return;
-
+
didInit = YES;
headers = [[NSArray alloc] initWithObjects:@"to", @"cc", @"bcc", nil];
}
}
- (void)dealloc {
- [self->to release];
- [self->cc release];
- [self->bcc release];
-
+ [self->to release];
+ [self->cc release];
+ [self->bcc release];
[self->item release];
[self->address release];
[self->addressList release];
- (void)setTo:(NSArray *)_to {
_to = [self properlySplitAddresses:_to];
- ASSIGN(self->to, _to);
+ ASSIGNCOPY(self->to, _to);
}
- (NSArray *)to {
return self->to;
- (void)setCc:(NSArray *)_cc {
_cc = [self properlySplitAddresses:_cc];
- ASSIGN(self->cc, _cc);
+ ASSIGNCOPY(self->cc, _cc);
}
- (NSArray *)cc {
return self->cc;
- (void)setBcc:(NSArray *)_bcc {
_bcc = [self properlySplitAddresses:_bcc];
- ASSIGN(self->bcc, _bcc);
+ ASSIGNCOPY(self->bcc, _bcc);
}
- (NSArray *)bcc {
return self->bcc;
NSMutableArray *ma;
ma = [NSMutableArray arrayWithCapacity:3];
- if(self->to)
- [ma addObject:self->to];
- if(self->cc)
- [ma addObject:self->cc];
- if(self->bcc)
- [ma addObject:self->bcc];
- /* ensure that min 1 object is available */
- if([ma count] == 0) {
+ if ([self->to isNotNull]) [ma addObject:self->to];
+ if ([self->cc isNotNull]) [ma addObject:self->cc];
+ if ([self->bcc isNotNull]) [ma addObject:self->bcc];
+
+ /* ensure that at least one object is available */
+ if ([ma count] == 0) {
NSArray *tmp = [NSArray arrayWithObject:@""];
- ASSIGN(self->to, tmp);
+ ASSIGNCOPY(self->to, tmp);
[ma addObject:self->to];
}
return ma;
/* identifiers */
- (NSString *)currentRowId {
- return [NSString stringWithFormat:@"row_%d", self->currentIndex];
+ unsigned char buf[16];
+ sprintf(buf, "row_%d", self->currentIndex);
+ return [NSString stringWithCString:buf];
}
- (NSString *)currentPopUpId {
- return [NSString stringWithFormat:@"popup_%d", self->currentIndex];
+ unsigned char buf[16];
+ sprintf(buf, "popup_%d", self->currentIndex);
+ return [NSString stringWithCString:buf];
}
- (NSString *)currentAddressId {
- return [NSString stringWithFormat:@"addr_%d", self->currentIndex];
+ unsigned char buf[16];
+ sprintf(buf, "addr_%d", self->currentIndex);
+ return [NSString stringWithCString:buf];
}
- (NSString *)nextId {
/* address handling */
- (NSArray *)properlySplitAddresses:(NSArray *)_addresses {
- NSString *addrs;
+ NSString *addrs;
NGMailAddressParser *parser;
- NSArray *result;
- NSMutableArray *ma;
- unsigned i, count;
+ NSArray *result;
+ NSMutableArray *ma;
+ unsigned i, count;
if(!_addresses || [_addresses count] == 0)
return nil;
count = [result count];
ma = [NSMutableArray arrayWithCapacity:count];
- for(i = 0; i < count; i++) {
- NGMailAddress *addr;
+ for (i = 0; i < count; i++) {
+ NGMailAddress *addr;
NSMutableString *s;
BOOL hasName = NO;
NSArray *keys;
unsigned i, count;
- rawTo = [NSMutableArray array];
- rawCc = [NSMutableArray array];
- rawBcc = [NSMutableArray array];
+ rawTo = [NSMutableArray arrayWithCapacity:4];
+ rawCc = [NSMutableArray arrayWithCapacity:4];
+ rawBcc = [NSMutableArray arrayWithCapacity:2];
- keys = [_dict allKeys];
+ keys = [_dict allKeys];
count = [keys count];
- for(i = 0; i < count; i++) {
+ for (i = 0; i < count; i++) {
NSString *key;
key = [keys objectAtIndex:i];
[rawBcc addObject:addr];
}
}
-
+
[self setTo:rawTo];
[self setCc:rawCc];
[self setBcc:rawBcc];
}
- (NSString *)getIndexFromIdentifier:(NSString *)_identifier {
- NSRange r = [_identifier rangeOfString:@"_"];
+ NSRange r;
+
+ r = [_identifier rangeOfString:@"_"];
return [_identifier substringFromIndex:NSMaxRange(r)];
}
/* OK, we have a special form value processor */
NSDictionary *d;
- d = [_rq formValues];
- if(!d)
+ if ((d = [_rq formValues]) == nil)
return;
#if 0
/* response generation */
- (NSString *)jsCode {
+ // TODO: can't we put this into a resource?
+ // TODO: might be better to use -stringByReplacingBindings: etc
static NSString *script = \
@"var currentIndex = %d;\n"
@"\n"
unsigned idx;
idx = [self->to count] + [self->cc count] + [self->bcc count];
-
- return [NSString stringWithFormat:
- script,
- idx];
+
+ return [NSString stringWithFormat:script, idx];
}
-@end
+@end /* UIxMailToSelection */