* Adium is the legal property of its developers, whose names are listed in the copyright file included * with this source distribution. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * This program 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 General * Public License for more details. * You should have received a copy of the GNU General Public License along with this program; if not, * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #import "AIContactAwayPlugin.h" #import <Adium/AIInterfaceControllerProtocol.h> #import "AIStatusController.h" #import <Adium/AIListObject.h> #import <AIUtilities/AIAttributedStringAdditions.h> #import <Adium/AIListBookmark.h> #define AWAY AILocalizedString(@"Away",nil) #define AWAY_MESSAGE_LABEL AILocalizedString(@"Away Message",nil) #define STATUS_LABEL AILocalizedString(@"Status",nil) * @class AIContactAwayPlugin * @brief Tooltip component: Away messages and states @implementation AIContactAwayPlugin //Install our tooltip entry [adium.interfaceController registerContactListTooltipEntry:self secondaryEntry:YES]; * @brief Return the description of the object's status to show after Status: * If a statusName exists for the object's status, its localized description will be shown. * If the object is away and no statusName is set, Away will be shown. - (NSString *)awayDescriptionForObject:(AIListObject *)inObject NSString *awayDescriptionString = nil; NSString *statusName = inObject.statusName; AIStatusType statusType = inObject.statusType; awayDescriptionString = [adium.statusController localizedDescriptionForStatusName:statusName if (!statusName && (statusType == AIAwayStatusType)) { awayDescriptionString = AWAY; return awayDescriptionString; * @result A label, or nil if no tooltip entry should be shown - (NSString *)labelForObject:(AIListObject *)inObject NSAttributedString *statusMessage = nil; away = (inObject.statusType == AIAwayStatusType); statusMessage = inObject.statusMessage; //Return the correct string if (statusMessage != nil && [statusMessage length] != 0) { if ([inObject isKindOfClass:[AIListBookmark class]]) { /* It's actually a bookmark, show "Topic: " instead */ label = AILocalizedString(@"Topic", nil); /* Away with a status message */ //Check to make sure we're not duplicating server display name information NSString *serverDisplayName = [inObject valueForProperty:@"serverDisplayName"]; if ([serverDisplayName isEqualToString:[statusMessage string]]) { /* If the server display name is the status message, awayDescriptionForObject: will be the entry */ label = [self awayDescriptionForObject:inObject]; /* Available with a status message */ /* Away without a status message */ * @result The tooltip entry, or nil if no tooltip should be shown - (NSAttributedString *)entryForObject:(AIListObject *)inObject NSAttributedString *entry = nil; NSAttributedString *statusMessage = nil; NSString *serverDisplayName = nil; statusMessage = inObject.statusMessage; //Check to make sure we're not duplicating server display name information serverDisplayName = [inObject valueForProperty:@"serverDisplayName"]; //Return the correct string if ([serverDisplayName isEqualToString:[statusMessage string]]) { /* If the status and server display name are the same, just display the status as appropriate since * we'll display the server display name itself in the proper place. NSString *awayDescription = [self awayDescriptionForObject:inObject]; entry = (awayDescription ? [[[NSAttributedString alloc] initWithString:awayDescription] autorelease] : if (statusMessage != nil && [statusMessage length] != 0) { if ([[statusMessage string] rangeOfString:@"\t" options:NSLiteralSearch].location == NSNotFound) { /* We don't display tabs well in the tooltips because we use them for alignment, so * turn them into 4 spaces. */ NSMutableAttributedString *mutableStatusMessage = [[statusMessage mutableCopy] autorelease]; [mutableStatusMessage replaceOccurrencesOfString:@"\t" range:NSMakeRange(0, [mutableStatusMessage length])]; entry = mutableStatusMessage; NSString *awayDescription = [self awayDescriptionForObject:inObject]; entry = (awayDescription ? [[[NSAttributedString alloc] initWithString:awayDescription] autorelease] : - (BOOL)shouldDisplayInContactInspector /* Accounts should be including this information in the profile already */