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 <Adium/AIInterfaceControllerProtocol.h>
19 #import "AIStatusController.h"
20 #import <Adium/AIListObject.h>
21 #import <AIUtilities/AIAttributedStringAdditions.h>
23 #define AWAY AILocalizedString(@"Away",nil)
24 #define AWAY_MESSAGE_LABEL AILocalizedString(@"Away Message",nil)
25 #define STATUS_LABEL AILocalizedString(@"Status",nil)
28 * @class AIContactAwayPlugin
29 * @brief Tooltip component: Away messages and states
31 @implementation AIContactAwayPlugin
38 //Install our tooltip entry
39 [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];
43 * @brief Tooltip label
45 * @result A label, or nil if no tooltip entry should be shown
47 - (NSString *)labelForObject:(AIListObject *)inObject
49 NSString *label = nil;
50 NSAttributedString *statusMessage = nil;
53 away = ([inObject statusType] == AIAwayStatusType);
55 //Get the status message
56 statusMessage = [inObject statusMessage];
58 //Return the correct string
59 if(statusMessage != nil && [statusMessage length] != 0){
61 /* Away with a status message */
63 //Check to make sure we're not duplicating server display name information
64 NSString *serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
66 //Return the correct string
67 if ([serverDisplayName isEqualToString:[statusMessage string]]) {
70 label = AWAY_MESSAGE_LABEL;
74 /* Available with a status message */
78 /* Away without a status message */
86 * @brief Return the description of the object's status to show after Status:
88 * If a statusName exists for the object's status, its localized description will be shown.
89 * If the object is away and no statusName is set, Away will be shown.
91 - (NSAttributedString *)awayDescriptionForObject:(AIListObject *)inObject
93 NSString *awayDescriptionString = nil;
94 NSString *statusName = [inObject statusName];
95 AIStatusType statusType = [inObject statusType];
98 awayDescriptionString = [[adium statusController] localizedDescriptionForStatusName:statusName
99 statusType:statusType];
102 if (!statusName && (statusType == AIAwayStatusType)) {
103 awayDescriptionString = AWAY;
106 return (awayDescriptionString ?
107 [[[NSAttributedString alloc] initWithString:awayDescriptionString] autorelease] :
112 * @brief Tooltip entry
114 * @result The tooltip entry, or nil if no tooltip should be shown
116 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
118 NSAttributedString *entry = nil;
119 NSAttributedString *statusMessage = nil;
120 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];