// $Id$

#include <SOGoUI/UIxComponent.h>

@interface UIxPageFrame : UIxComponent
{
    NSString *title;
    NSString *rootURL;
    NSString *userRootURL;
}

- (NSString *)rootURL;
- (NSString *)userRootURL;
- (NSString *)calendarRootURL;

@end

#include "common.h"
#include <NGObjWeb/SoComponent.h>

@implementation UIxPageFrame

- (void)dealloc {
  [self->title release];
  [self->rootURL release];
  [self->userRootURL release];
  [super dealloc];
}

/* accessors */

- (void)setTitle:(NSString *)_value {
  ASSIGN(self->title, _value);
}
- (NSString *)title {
  if([self isUIxDebugEnabled])
    return self->title;
    return [self labelForKey:@"OpenGroupware.org"];
}

/* URL generation */

- (NSString *)rootURL {
  WOContext *ctx;
  NSArray   *traversalObjects;

  if (self->rootURL)
    return self->rootURL;

  ctx = [self context];
  traversalObjects = [ctx objectTraversalStack];
  self->rootURL = [[[traversalObjects objectAtIndex:0]
                                      rootURLInContext:ctx]
                                      retain];
  return self->rootURL;
}

- (NSString *)userRootURL {
  WOContext *ctx;
  NSArray   *traversalObjects;

  if (self->userRootURL)
    return self->userRootURL;

  ctx = [self context];
  traversalObjects = [ctx objectTraversalStack];
  self->userRootURL = [[[[traversalObjects objectAtIndex:1]
                                           baseURLInContext:ctx]
                                           stringByAppendingString:@"/"]
                                           retain];
  return self->userRootURL;
}

- (NSString *)calendarRootURL {
  return [[self userRootURL] stringByAppendingString:@"Calendar/"];
}
- (NSString *)contactsRootURL {
  return [[self userRootURL] stringByAppendingString:@"Contacts/"];
}

@end /* UIxPageFrame */
