"Fossies" - the Fresh Open Source Software Archive

Member "opengroupware-5.5rc3/ZideStore/Protocols/zOGI/zOGIAction+Defaults.m" (5 Dec 2015, 9667 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. See also the latest Fossies "Diffs" side-by-side code changes report for "zOGIAction+Defaults.m": 5.5rc2_vs_5.5rc3.

    1 /*
    2   Copyright (C) 2006-2007 Whitemice Consulting
    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 "zOGIAction.h"
   23 #include "zOGIAction+Account.h"
   24 #include "zOGIAction+Contact.h"
   25 #include "zOGIAction+Defaults.h"
   26 #include "zOGIAction+Object.h"
   27 #include "zOGIAction+Resource.h"
   28 
   29 @implementation zOGIAction(Defaults)
   30 
   31 - (id)_storeDefaults:(NSDictionary *)_defaults
   32            withFlags:(NSArray *)_flags
   33 {
   34   NSUserDefaults *defaults;
   35   id              tmp;
   36 
   37   defaults = [self _getDefaults];
   38 
   39   /* store time zone if provided */
   40   if ([[_defaults objectForKey:@"timeZone"] isNotNull]) 
   41     [defaults setObject:[_defaults objectForKey:@"timeZone"] 
   42                  forKey:@"timezone"];
   43 
   44   /* store notification cc address if provided */
   45   if ([[_defaults objectForKey:@"notificationCC"] isNotNull])
   46     [defaults setObject:[_defaults objectForKey:@"notificationCC"]
   47                  forKey:@"scheduler_ccForNotificationMails"];
   48 
   49   /* store calendar panel if provided */
   50   tmp = [_defaults objectForKey:@"calendarPanelObjectIds"];
   51   if ([tmp isNotNull]) {
   52     NSEnumerator   *enumerator;
   53     id              object;
   54     NSString       *entityName;
   55     NSMutableArray *accounts, *persons, *resourceNames, *teams;
   56    
   57     accounts      = [NSMutableArray arrayWithCapacity:32];
   58     persons       = [NSMutableArray arrayWithCapacity:32];
   59     resourceNames = [NSMutableArray arrayWithCapacity:32];
   60     teams         = [NSMutableArray arrayWithCapacity:32]; 
   61     enumerator = [tmp objectEnumerator];
   62     while((object = [enumerator nextObject]) != nil) {
   63       entityName = [self _getEntityNameForPKey:object];
   64       if ([entityName isEqualToString:@"Person"]) {
   65         object = [self _getUnrenderedContactForKey:object];
   66         if ([object isNotNull]) {
   67           if ([[object objectForKey:@"isAccount"] intValue]) {
   68             [accounts addObject:[object objectForKey:@"companyId"]];
   69           } else {
   70               [persons addObject:[object objectForKey:@"companyId"]];
   71             }
   72         }
   73       } else if ([entityName isEqualToString:@"Team"]) {
   74         if ([object isKindOfClass:[NSNumber class]]) {
   75           [teams addObject:object];
   76         } else
   77           [teams addObject:[NSNumber numberWithInt:[object intValue]]];
   78       } else if ([entityName isEqualToString:@"AppointmentResource"]) {
   79           object = [self _getUnrenderedResourceForKey:object];
   80           if ([object isNotNull])
   81             [resourceNames addObject:[object objectForKey:@"name"]];
   82           else
   83             [self warnWithFormat:@"Unable to retrieve resource by objectId"];
   84       }
   85     } /* end while */
   86     [defaults setObject:accounts forKey:@"scheduler_panel_accounts"];
   87     [defaults setObject:persons forKey:@"scheduler_panel_persons"];
   88     [defaults setObject:resourceNames forKey:@"scheduler_panel_resourceNames"];
   89     [defaults setObject:teams forKey:@"scheduler_panel_teams"];
   90     accounts = nil;
   91     persons = nil;
   92     resourceNames = nil;
   93     teams = nil;
   94   } /* end store panel */
   95 
   96   /* store default read access, if provided */
   97   tmp = [_defaults objectForKey:@"appointmentReadAccessTeam"];
   98   if ([tmp isNotNull]) {
   99     [defaults setObject:tmp forKey:@"scheduler_default_readaccessteam"];
  100   }
  101 
  102   /* store default write access, if provided */
  103   tmp = [_defaults objectForKey:@"appointmentWriteAccess"];
  104   if ([tmp isNotNull]) {
  105     NSEnumerator   *enumerator;
  106     id              object;
  107     NSString       *entityName;
  108     NSMutableArray *accounts, *teams;
  109 
  110     accounts      = [NSMutableArray arrayWithCapacity:32];
  111     teams         = [NSMutableArray arrayWithCapacity:32];
  112     enumerator = [tmp objectEnumerator];
  113     while((object = [enumerator nextObject]) != nil) {
  114       entityName = [self _getEntityNameForPKey:object];
  115       if ([entityName isEqualToString:@"Person"]) {
  116         [accounts addObject:[object stringValue]];
  117       } else if ([entityName isEqualToString:@"Team"]) {
  118           [teams addObject:[object stringValue]];
  119         }
  120     }
  121     [defaults setObject:accounts
  122                  forKey:@"scheduler_write_access_accounts"];
  123     [defaults setObject:teams
  124                  forKey:@"scheduler_write_access_teams"];
  125     enumerator = nil;
  126     accounts = nil;
  127     teams = nil;
  128   }
  129  
  130   [defaults synchronize];
  131   return [self _getLoginAccount:arg1];
  132 } /* end _storeDefaults */
  133 
  134 
  135 /* Get the defaults structure from the command context */
  136 - (NSUserDefaults *)_getDefaults
  137 {
  138   return [[self getCTX] userDefaults];
  139 }
  140 
  141 /* Get the specified string value from the defaults */
  142 - (id)_getDefault:(NSString *)_value
  143 {
  144   id value;
  145 
  146   value = [[self _getDefaults] valueForKey:_value];
  147   return value;
  148 }
  149 
  150 /* Load the defaults file for the specified account (companyId) from
  151    the filesystem and return it as a dictionary.  If the user has
  152    noo defaults and empty dictionary is returned */
  153 - (NSDictionary *)_getDefaultsForAccount:(id)_account {
  154   return [NSDictionary dictionaryWithContentsOfFile:
  155               [NSString stringWithFormat:@"%@/%@.defaults",
  156                  [[self _getDefault:@"LSAttachmentPath"] stringValue],
  157                  [_account stringValue]]];
  158 } /* End _getDefaultsForAccount */
  159 
  160 -(NSArray *)_getDefaultWriteAccessFromDefaults:(NSUserDefaults *)_ud {
  161    NSMutableArray                               *objectIds;
  162    NSEnumerator                                 *e;
  163    id                                            tmp;
  164 
  165    objectIds = [NSMutableArray arrayWithCapacity:32];
  166    e = [[_ud arrayForKey:@"scheduler_write_access_teams"] objectEnumerator];
  167    while ((tmp = [e nextObject]) != nil) {
  168      [objectIds addObject:intObj([tmp intValue])];
  169    }
  170    e = nil;
  171    e = [[_ud arrayForKey:@"scheduler_write_access_accounts"] objectEnumerator];
  172    while ((tmp = [e nextObject]) != nil) {
  173      [objectIds addObject:intObj([tmp intValue])];
  174    }
  175    e = nil;
  176 
  177    return objectIds;
  178 }
  179 
  180 -(NSArray *)_getSchedularPanel {
  181   id            calendarPanel;
  182   NSEnumerator *enumerator;
  183   id            tmp;
  184 
  185   if (([[self _getDefault:@"scheduler_panel_accounts"] isNotNull]) ||
  186       ([[self _getDefault:@"scheduler_panel_persons"] isNotNull]) ||
  187       ([[self _getDefault:@"scheduler_panel_teams"] isNotNull])) {
  188     calendarPanel = [NSMutableArray arrayWithCapacity:32];
  189     if ([[self _getDefault:@"scheduler_panel_accounts"] isNotNull]) {
  190       tmp = [self _getDefault:@"scheduler_panel_accounts"];
  191       enumerator = [tmp objectEnumerator];
  192       while ((tmp = [enumerator nextObject]) != nil) {
  193         [calendarPanel addObject:[NSNumber numberWithInt:[tmp intValue]]];
  194       }
  195     } /* end accounts-in-panel */
  196     if ([[self _getDefault:@"scheduler_panel_persons"] isNotNull]) {
  197       tmp = [self _getDefault:@"scheduler_panel_persons"];
  198       enumerator = [tmp objectEnumerator];
  199       while ((tmp = [enumerator nextObject]) != nil) {
  200         [calendarPanel addObject:[NSNumber numberWithInt:[tmp intValue]]];
  201       }
  202     } /* end persons-in-panel */
  203     if ([[self _getDefault:@"scheduler_panel_teams"] isNotNull]) {
  204       tmp = [self _getDefault:@"scheduler_panel_teams"];
  205       enumerator = [tmp objectEnumerator];
  206       while ((tmp = [enumerator nextObject]) != nil) {
  207         [calendarPanel addObject:[NSNumber numberWithInt:[tmp intValue]]];
  208       }
  209     } /* end teams-in-panel */
  210     if ([[self _getDefault:@"scheduler_panel_resourceNames"] isNotNull]) {
  211       tmp = [self _getDefault:@"scheduler_panel_resourceNames"];
  212       if ([tmp count] > 0) {
  213         NSEnumerator *enumerator;
  214      
  215         enumerator = [tmp objectEnumerator];
  216         while ((tmp = [enumerator nextObject]) != nil) {
  217           tmp = [self _getResourceByName:tmp];
  218           if ([tmp isNotNull])
  219             [calendarPanel addObject:[tmp objectForKey:@"appointmentResourceId"]];
  220         } /* end while */
  221       } /* end array-has-contents */
  222     } /* end there-are-resources-in-the-panel */
  223   } else {
  224       if ([self isDebug])
  225         [self logWithFormat:@"sending empty calendar panel - no defaults"];
  226       calendarPanel = [NSArray arrayWithObjects:nil];
  227     }
  228   return calendarPanel;
  229 }
  230 
  231 /* Retrieve the time zone for the specified account Id (companyID), this
  232    method retrieves the time zone from _getDefaultsForAccount; if the
  233    account has not time zone defined we return GMT. */
  234 - (NSTimeZone *)_getTimeZoneForAccount:(id)_account {
  235   NSDictionary  *defaults;
  236 
  237   defaults = [self _getDefaultsForAccount:_account];
  238   if ([[defaults valueForKey:@"timezone"] isNotNull]) {
  239     return [NSTimeZone timeZoneWithAbbreviation:
  240               [[defaults valueForKey:@"timezone"] stringValue]];
  241   }
  242   return [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  243 } /* End _getTimeZoneForAccount */
  244 
  245 - (NSString *)_getCCAddressForAccount:(id)_account {
  246   NSDictionary  *defaults;
  247 
  248   defaults = [self _getDefaultsForAccount:_account];
  249   if ([[defaults objectForKey:@"scheduler_ccForNotificationMails"] isNotNull])
  250     return [defaults objectForKey:@"scheduler_ccForNotificationMails"];
  251   return @"";
  252 } /* End _getCCAddressForAccount */
  253 
  254 @end /* end zOGIAction(Defaults) */