/* Copyright (C) 2000-2003 SKYRIX Software AG This file is part of OGo OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include @interface SkyFavorites : LSWComponent { int index; BOOL isClickable; id favorite; int maxDockWidth; } - (void)setIndex:(int)_idx; - (int)index; - (void)setFavorite:(id)_favorite; - (id)favorite; @end #include #include #include #include #import #import @interface NSObject(gid) - (EOGlobalID *)globalID; @end @implementation SkyFavorites /* notifications */ - (void)sleep { [self setFavorite:nil]; [super sleep]; } /* accessors */ - (void)setIndex:(int)_idx { self->index = _idx; } - (int)index { return self->index; } - (void)setLinksDisabled:(BOOL)_flag { self->isClickable = !_flag; } - (BOOL)linksDisabled { return self->isClickable ? NO : YES; } - (void)setFavorite:(id)_favorite { ASSIGN(self->favorite, _favorite); } - (id)favorite { return self->favorite; } /* computed accessors */ - (int)maxDockLabelWidth { if (self->maxDockWidth == 0) { self->maxDockWidth = [[[[self session] userDefaults] objectForKey:@"OGoDockLabelWidth"] intValue]; if (self->maxDockWidth < 8) self->maxDockWidth = 16; } return self->maxDockWidth; } - (NSString *)labelForFavorite { NSString *s; int max; s = [(OGoSession *)[self session] labelForObject:[self favorite]]; max = [self maxDockLabelWidth]; if ([s length] > max) { s = [s substringToIndex:(max - 3)]; s = [s stringByAppendingString:@"..."]; } return s; } - (NSString *)favoriteDragType { id obj = [self favorite]; NSString *dragType; dragType = @"unknown"; if ([obj isKindOfClass:[EOGenericRecord class]]) dragType = [[obj entity] name]; else if ([obj isKindOfClass:[EOKeyGlobalID class]]) dragType = [obj entityName]; else if ([obj isKindOfClass:NSClassFromString(@"NGImap4Message")]) dragType = @"mail"; else if ([obj respondsToSelector:@selector(globalID)]) dragType = [[obj globalID] entityName]; else if ((obj = [obj valueForKey:@"globalID"])) dragType = [obj entityName]; dragType = [dragType lowercaseString]; if ([dragType isEqualToString:@"date"]) dragType = @"appointment"; return dragType; } /* actions */ - (id)showChoosenFavorite { static Class NGImapMsgClass = Nil; id obj; id gid; if ((obj = [self favorite]) == nil) return nil; //NSLog(@"obj is %@", obj); if (NGImapMsgClass == Nil) NGImapMsgClass = NSClassFromString(@"NGImap4Message"); if ([obj isKindOfClass:[EOGenericRecord class]]) gid = nil; else if ([obj isKindOfClass:NGImapMsgClass]) gid = nil; else gid = [obj valueForKey:@"globalID"]; // test, whether the favorite is an valid object??? if (gid) { NSArray *objs; objs = [self runCommand:@"object::get-by-globalid", @"gid", gid, nil]; if ([objs count] == 0) { [[self session] removeFavorite:obj]; [[[self context] page] takeValue:@"Object is invalid!" forKey:@"errorString"]; return nil; } } return [[(OGoSession *)[self session] navigation] activateObject:gid ? gid : obj withVerb:@"view"]; } @end /* SkyFavorites */