2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIContactAwayPlugin.h"
18 #import "AIInterfaceController.h"
19 #import <Adium/AIListObject.h>
20 #import <AIUtilities/AIAttributedStringAdditions.h>
22 #define AWAY AILocalizedString(@"Away",nil)
23 #define AWAY_MESSAGE_LABEL AILocalizedString(@"Away Message",nil)
24 #define STATUS_LABEL AILocalizedString(@"Status",nil)
27 * @class AIContactAwayPlugin
28 * @brief Tooltip component: Away messages and states
30 @implementation AIContactAwayPlugin
37 //Install our tooltip entry
38 [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];
42 * @brief Tooltip label
44 * @result A label, or nil if no tooltip entry should be shown
46 - (NSString *)labelForObject:(AIListObject *)inObject
48 NSString *label = nil;
49 NSAttributedString *statusMessage = nil;
52 away = ([inObject statusType] == AIAwayStatusType);
54 //Get the status message
55 statusMessage = [inObject statusMessage];
57 //Return the correct string
58 if(statusMessage != nil && [statusMessage length] != 0){
60 /* Away with a status message */
62 //Check to make sure we're not duplicating server display name information
63 NSString *serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
65 //Return the correct string
66 if ([serverDisplayName isEqualToString:[statusMessage string]]) {
69 label = AWAY_MESSAGE_LABEL;
73 /* Available with a status message */
77 /* Away without a status message */
85 * @brief Return the description of the object's status to show after Status:
87 * If a statusName exists for the object's status, its localized description will be shown.
88 * If the object is away and no statusName is set, Away will be shown.
90 - (NSAttributedString *)awayDescriptionForObject:(AIListObject *)inObject
92 NSString *awayDescriptionString = nil;
93 NSString *statusName = [inObject statusName];
94 AIStatusType statusType = [inObject statusType];
97 awayDescriptionString = [[adium statusController] localizedDescriptionForStatusName:statusName
98 statusType:statusType];
101 if (!statusName && (statusType == AIAwayStatusType)) {
102 awayDescriptionString = AWAY;
105 return (awayDescriptionString ?
106 [[[NSAttributedString alloc] initWithString:awayDescriptionString] autorelease] :
111 * @brief Tooltip entry
113 * @result The tooltip entry, or nil if no tooltip should be shown
115 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
117 NSAttributedString *entry = nil;
118 NSAttributedString *statusMessage = nil;
119 NSString *serverDisplayName = nil;
122 //Get the status message
123 statusMessage = [inObject statusMessage];
125 //Check to make sure we're not duplicating server display name information
126 serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
128 //Return the correct string
129 if ([serverDisplayName isEqualToString:[statusMessage string]]) {
130 /* If the status and server display name are the same, just display the status as appropriate since
131 * we'll display the server display name itself in the proper place.
133 entry = [self awayDescriptionForObject:inObject];
136 if (statusMessage != nil && [statusMessage length] != 0) {
137 if ([[statusMessage string] rangeOfString:@"\t" options:NSLiteralSearch].location == NSNotFound) {
138 entry = statusMessage;
141 /* We don't display tabs well in the tooltips because we use them for alignment, so
142 * turn them into 4 spaces. */
143 NSMutableAttributedString *mutableStatusMessage = [[statusMessage mutableCopy] autorelease];
144 [mutableStatusMessage replaceOccurrencesOfString:@"\t"
146 options:NSLiteralSearch
147 range:NSMakeRange(0, [mutableStatusMessage length])];
148 entry = mutableStatusMessage;
154 entry = [self awayDescriptionForObject:inObject];