"Fossies" - the Fresh Open Source Software Archive

Member "opengroupware-5.5rc3/WebUI/Common/BaseUI/LSWSkyrixFrame.m" (5 Dec 2015, 12648 Bytes) of package /linux/privat/opengroupware-5.5rc3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "LSWSkyrixFrame.m" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.5rc2_vs_5.5rc3.

    1 /*
    2   Copyright (C) 2000-2005 SKYRIX Software AG
    3 
    4   This file is part of OpenGroupware.org.
    5 
    6   OGo is free software; you can redistribute it and/or modify it under
    7   the terms of the GNU Lesser General Public License as published by the
    8   Free Software Foundation; either version 2, or (at your option) any
    9   later version.
   10 
   11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
   12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   14   License for more details.
   15 
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with OGo; see the file COPYING.  If not, write to the
   18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   19   02111-1307, USA.
   20 */
   21 
   22 #include <OGoFoundation/OGoComponent.h>
   23 
   24 @class NSArray, NSMutableArray;
   25 
   26 @interface LSWSkyrixFrame : OGoComponent
   27 {
   28   BOOL isRoot;
   29 @private
   30   int idx;
   31   id  item; // non-retained
   32 
   33   /* dock stuff */
   34   NSArray *dockedPages;
   35 
   36   /* tmp */
   37   NSMutableArray *dndSelection;
   38 }
   39 
   40 - (BOOL)isInternetExplorer;
   41 
   42 @end /* LSWSkyrixFrame */
   43 
   44 #include <NGObjWeb/WEClientCapabilities.h>
   45 #include <OGoFoundation/LSWEditorPage.h>
   46 #include <OGoFoundation/OGoClipboard.h>
   47 #include "common.h"
   48 
   49 #define LSWSkyrixFrame_CtxKey @"__LSWSkyrixFrame"
   50 
   51 @interface WORequest(UsedPrivates)
   52 - (NSCalendarDate *)startDate;
   53 @end
   54 
   55 @implementation LSWSkyrixFrame
   56 
   57 static NSNumber *yesNum = nil;
   58 static int  Timeout          = -1;
   59 static int  editTimeOut      = -1;
   60 static BOOL showTimings      = NO;
   61 static BOOL debugDnD         = NO;
   62 static BOOL debugPageRefresh = NO;
   63 
   64 + (void)initialize {
   65   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
   66   static BOOL didInit = NO;
   67 
   68   if (didInit) return;
   69   didInit = YES;
   70   
   71   showTimings      = [ud boolForKey:@"SkyShowPageTimings"];
   72   debugDnD         = [ud boolForKey:@"OGoDebugDnD"];
   73   debugPageRefresh = [ud boolForKey:@"OGoDebugPageRefresh"];
   74   
   75   if (yesNum == nil) yesNum = [[NSNumber numberWithBool:YES] retain];
   76   
   77   Timeout = [[ud objectForKey:@"SkyPageRefreshTimeout"] intValue];
   78   if (Timeout <= 0) {
   79     Timeout = [[WOApplication sessionTimeOut] intValue];
   80     Timeout = (Timeout < 300) ? 300 : (Timeout - 300);
   81   }
   82   
   83   editTimeOut = [[ud objectForKey:@"SkyEditorPageTimeOut"] intValue];
   84   if (editTimeOut <= 0) {
   85     editTimeOut = Timeout;
   86     if (editTimeOut < 3600)
   87       editTimeOut = 3600; /* at least one hour */
   88   }
   89   
   90   if (debugPageRefresh)
   91     NSLog(@"OGoDebugPageRefresh: timeout=%is edit=%is", Timeout, editTimeOut);
   92 }
   93 
   94 - (void)dealloc {
   95   [self->dockedPages release];
   96   
   97   /* tmp */ // hh: what does the comment say ??
   98   [self->dndSelection release];
   99   [super dealloc];
  100 }
  101 
  102 /* notifications */
  103 
  104 - (void)awake {
  105   [super awake];
  106   self->isRoot = [[self session] activeAccountIsRoot];
  107 }
  108 
  109 - (void)sleep {
  110   self->item = nil;
  111   [super sleep];
  112 }
  113 
  114 /* error strings */
  115 
  116 - (BOOL)pageHasErrorToShow {
  117   return [[[[self context] page] valueForKey:@"hasErrorString"] boolValue];
  118 }
  119 - (BOOL)showErrorBar {
  120   return [self pageHasErrorToShow];
  121 }
  122 
  123 - (BOOL)shouldEscapePanelErrorString {
  124   /*
  125     For Mozilla we cannot escape the parameter of the JavaScript popup, it
  126     will show the HTML entities.
  127     TODO: find out what is correct here and whether other browsers show
  128           the same behaviour.
  129   */
  130   WEClientCapabilities *ccaps;
  131   
  132   if ((ccaps = [[[self context] request] clientCapabilities]) == nil)
  133     return YES;
  134   
  135   if ([ccaps isMozilla])
  136     return NO;
  137   
  138   return YES;
  139 }
  140 - (NSString *)panelErrorString {
  141   NSString *errorString;
  142   
  143   errorString = [[[self context] page] valueForKey:@"errorString"];
  144   if ([errorString length] == 0) return nil;
  145 
  146   if ([errorString rangeOfString:@"\n"].length > 0) {
  147     errorString = [[errorString componentsSeparatedByString:@"\n"]
  148                                 componentsJoinedByString:@"\\n"];
  149   }
  150   if ([errorString rangeOfString:@"\""].length > 0) {
  151     errorString = [[errorString componentsSeparatedByString:@"\""]
  152                                 componentsJoinedByString:@"'"];
  153   }
  154   return errorString;
  155 }
  156 
  157 /* confirm strings */
  158 
  159 - (BOOL)pageHasConfirmToShow {
  160   return ([[[self context] page] valueForKey:@"confirmString"] != nil);
  161 }
  162 - (BOOL)showConfirmBar {
  163   return [self pageHasConfirmToShow];
  164 }
  165 
  166 - (NSString *)panelConfirmString {
  167   NSString *confirmString;
  168 
  169   confirmString = [[[self context] page] valueForKey:@"confirmString"];
  170   if ([confirmString length] == 0) return nil;
  171 
  172   if ([confirmString rangeOfString:@"\n"].length > 0) {
  173     confirmString = [[confirmString componentsSeparatedByString:@"\n"]
  174                                     componentsJoinedByString:@"\\n"];
  175   }
  176   if ([confirmString rangeOfString:@"\""].length > 0) {
  177     confirmString = [[confirmString componentsSeparatedByString:@"\""]
  178                                     componentsJoinedByString:@"'"];
  179   }
  180   return confirmString;
  181 }
  182 
  183 - (id)confirmAction {
  184   id       page       = [[self context] page];
  185   NSString *actionStr = [page valueForKey:@"confirmAction"];
  186 
  187   if ([actionStr length] == 0)
  188     return nil;
  189   else if ([page respondsToSelector:NSSelectorFromString(actionStr)])
  190     return [page performSelector:NSSelectorFromString(actionStr)];
  191   else
  192     return nil;
  193 }
  194 
  195 
  196 /* URLs */
  197 
  198 - (NSString *)urlForResourceNamed:(NSString *)_name {
  199   WOResourceManager *rm;
  200   NSString *url;
  201   NSArray  *langs;
  202 
  203   langs = [self hasSession]
  204     ? [[self session] languages]
  205     : [[[self context] request] browserLanguages];
  206   
  207   rm = [[self application] resourceManager];
  208   url = [rm urlForResourceNamed:_name inFramework:nil
  209         languages:langs request:[[self context] request]];
  210   return url;
  211 }
  212 
  213 - (NSString *)shortcutLink {
  214   return [NSString stringWithFormat:
  215                      @"<link rel=\"shortcut icon\" href=\"%@\" />",
  216                      [self urlForResourceNamed:@"favicon.ico"]];
  217 }
  218 - (NSString *)stylesheetURL {
  219   return [self urlForResourceNamed:@"OGo.css"];
  220 }
  221 
  222 - (NSString *)coloredScrollBars {
  223   // TODO: uses "config" mechanism
  224   // TODO: use a references stylesheet ?
  225   id cfg;
  226   
  227   cfg = [self valueForKey:@"config"];
  228   return [NSString stringWithFormat:
  229                    @"<style type=\"text/css\">\n"
  230                    @"<!--\n"
  231                    @"BODY {\n"
  232                    @"scrollbar-face-color:%@;\n"
  233                    @"scrollbar-arrow-color:%@;\n"
  234                    @"scrollbar-track-color:%@;\n"
  235                    @"scrollbar-3dlight-color:%@;\n"
  236                    @"scrollbar-darkshadow-color:%@;\n"
  237                    @"}\n"
  238                    @"-->\n"
  239                    @"</style>",
  240                    [cfg valueForKey:@"colors_headerCell"],
  241                    [cfg valueForKey:@"colors_textColor"],
  242                    [cfg valueForKey:@"colors_bgColor"],
  243                    @"#ffffff",
  244                    @"#000000"];
  245 }
  246 
  247 /* expiration */
  248 
  249 - (id)expirePage {
  250   /* keeps the session alive */
  251   // TODO: this should be done using a direct action !
  252   id page;
  253   
  254   if (![self hasSession]) {
  255     [self debugWithFormat:@"expirePage called, but no session active ?"];
  256     return nil;
  257   }
  258   
  259   if (debugPageRefresh) [self logWithFormat:@"expire page called ..."];
  260   page = [[[self session] navigation] activePage];
  261   if (debugPageRefresh) [self logWithFormat:@"  page: %@", page];
  262   return page;
  263 }
  264 - (int)pageExpireTimeout {
  265   return Timeout;
  266 }
  267 
  268 - (BOOL)pageIsExpirable {
  269   return [[[self context] page] isEditorPage] ? NO : YES;
  270 }
  271 
  272 - (NSTimeInterval)activeSessionTimeOut {
  273   return [self pageIsExpirable]
  274     ? [[WOApplication sessionTimeOut] intValue]
  275     : editTimeOut;
  276 }
  277 
  278 - (NSString *)sessionExpireInfo {
  279   static int showAMPM = -1;
  280   NSCalendarDate *d;
  281   NSTimeZone     *tz;
  282 
  283   if (showAMPM == -1) {
  284     id ud = [[self session] userDefaults];
  285     showAMPM = [ud boolForKey:@"scheduler_AMPM_dates"] ? 1 : 0;
  286   }
  287   
  288   tz = [[self session] timeZone];
  289   d  = [NSCalendarDate dateWithTimeIntervalSinceNow:
  290                          [self activeSessionTimeOut]];
  291   [d setTimeZone:tz];
  292   if (showAMPM) {
  293     NSInteger  hour;
  294     BOOL am = YES;
  295     hour = [d hourOfDay];
  296     if (hour > 11) am = NO;
  297     hour = hour % 12;
  298     if (!hour) hour = 12;
  299     return [NSString stringWithFormat:@"%02"PRIiPTR":%02"PRIiPTR" %@ %@",
  300                    hour, [d minuteOfHour], am ? @"AM" : @"PM",
  301                      [tz abbreviation]];
  302   }
  303   return [NSString stringWithFormat:@"%02"PRIiPTR":%02"PRIiPTR" %@",
  304                    [d hourOfDay], [d minuteOfHour], [tz abbreviation]];
  305 }
  306 
  307 /* actions */
  308 
  309 - (id)logout {
  310   NSUserDefaults *ud;
  311   BOOL logLogout;
  312   
  313   ud = [[self session] userDefaults];
  314   logLogout = [[ud objectForKey:@"LSSessionAccountLogEnabled"] boolValue];
  315   if (logLogout) {
  316     id account = [[self session] activeAccount];
  317     [[self session] runCommand:@"sessionlog::add",
  318                     @"account", account,
  319                     @"action",  @"logout", nil];
  320   }
  321   [[self session] terminate];
  322   return [[self application] pageWithName:@"OGoLogoutPage"];
  323 }
  324 
  325 - (id)clearErrorString {
  326   [[[self context] page] takeValue:nil forKey:@"errorString"];
  327   return nil;
  328 }
  329 
  330 - (id)newFavoriteDropped {
  331   static Class EOGenericRecordClass = Nil;
  332   id object;
  333 
  334   object = [self valueForKey:@"newFavoriteObject"];
  335   if (debugDnD)
  336     [self logWithFormat:@"dropped object %@", object];
  337   
  338   if (EOGenericRecordClass == Nil)
  339     EOGenericRecordClass = [EOGenericRecord class];
  340   
  341   // what is this good for?
  342   // was an empty if statement before commenting out completely
  343   //if (![object isKindOfClass:EOGenericRecordClass])
  344     //object = [object valueForKey:@"globalID"];
  345     //;
  346   
  347   if (object == nil)
  348     return nil;
  349   
  350   [[[self session] favorites] addObject:object];
  351   return nil;
  352 }
  353 
  354 - (id)deleteDroppedObject {
  355   id obj;
  356 
  357   obj = [self valueForKey:@"droppedObject"];
  358   if ([obj isKindOfClass:[NSDictionary class]]) {
  359     id tmp;
  360 
  361     tmp = [obj valueForKey:@"globalID"];
  362     obj = ([tmp isNotNull]) ? tmp : obj;
  363   }
  364   
  365   return [self activateObject:obj withVerb:@"delete"];
  366 }
  367 
  368 - (BOOL)showTrash {
  369   WEClientCapabilities *ccaps;
  370   
  371   if ((ccaps = [[[self context] request] clientCapabilities]) == nil)
  372     return NO;
  373 
  374   return [ccaps doesSupportDHTMLDragAndDrop];
  375 }
  376 
  377 - (int)colspanDependingOnTrash {
  378   return (![self showTrash]) ? 2 : 1;
  379 }
  380 
  381 /* common accessors */
  382 
  383 - (void)setItem:(id)_item {
  384   self->item = _item;
  385 }
  386 - (id)item {
  387   return self->item;
  388 }
  389 
  390 - (void)setIndex:(int)_idx {
  391   self->idx = _idx;
  392 }
  393 - (int)index {
  394   return self->idx;
  395 }
  396 
  397 - (BOOL)isRoot {
  398   return self->isRoot;
  399 }
  400 
  401 - (BOOL)smallFont {
  402   WEClientCapabilities *ccaps;
  403   
  404   if ((ccaps = [[[self context] request] clientCapabilities]) == nil)
  405     return NO;
  406 
  407   if ([ccaps isX11Browser]) {
  408     if ([ccaps isNetscape])
  409       return NO;
  410     if ([ccaps isMozilla])
  411       return NO;
  412   }
  413   return YES;
  414 }
  415 
  416 /* navigation */
  417 
  418 - (BOOL)isNavLinkClickable {
  419   int count;
  420   count = [[[(OGoSession *)[self session] navigation] pageStack] count];
  421   return (self->idx == (count - 1)) ? NO : YES;
  422 }
  423 
  424 - (id)navigate { // a navigation link was clicked
  425   id            newPage;
  426   NSArray       *pageStack;
  427   OGoNavigation *navigation;
  428   
  429   navigation = [(OGoSession *)[self session] navigation];
  430   pageStack  = [navigation pageStack];
  431   newPage    = [pageStack objectAtIndex:idx];
  432 
  433   [navigation enterPage:newPage];
  434 
  435   return newPage;
  436 }
  437 
  438 /* responder */
  439 
  440 - (void)appendToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
  441   
  442   if ([_ctx objectForKey:LSWSkyrixFrame_CtxKey])
  443     return;
  444   
  445   [_ctx setObject:yesNum forKey:LSWSkyrixFrame_CtxKey];
  446   if ([_ctx hasSession])
  447     [[_ctx session] setTimeOut:[self activeSessionTimeOut]];
  448   
  449   [super appendToResponse:_r inContext:_ctx];
  450 }
  451 
  452 /* tmp */
  453 
  454 - (void)setDndSelection:(NSMutableArray *)_ma {
  455   ASSIGN(self->dndSelection,_ma);
  456 }
  457 - (NSMutableArray *)dndSelection {
  458   return self->dndSelection;
  459 }
  460 
  461 - (id)init {
  462   if ((self = [super init])) {
  463     self->dndSelection = [[NSMutableArray alloc] init];
  464   }
  465   return self;
  466 }
  467 
  468 - (BOOL)doesSupportDHTMLDragAndDrop {
  469   return [[[[self context] request]
  470                   clientCapabilities]
  471                   doesSupportDHTMLDragAndDrop];
  472 }
  473 - (BOOL)isInternetExplorer {
  474   // DEPRECATED, TODO: fix in templates ...
  475   return [self doesSupportDHTMLDragAndDrop];
  476 }
  477 
  478 /* timings */
  479 
  480 - (NSString *)timingsString {
  481   NSTimeInterval duration;
  482   NSDate         *rStartDate;
  483   NSDate         *now;
  484   char buf[16];
  485   
  486   if (!showTimings)
  487     return @"";
  488   
  489   if ((rStartDate = [[[self context] request] startDate]) == nil)
  490     return @"";
  491   
  492   now      = [NSDate date];
  493   duration = [now timeIntervalSinceDate:rStartDate];
  494   sprintf(buf, " (%.3fs)", duration);
  495   return [NSString stringWithCString:buf];
  496 }
  497 
  498 @end /* LSWSkyrixFrame */