Added Australian English translation to adium-0.8
[adiumx.git] / Source / AIContactAwayPlugin.m
blob188fba3cf141bda4cc13b7ea0c637cdecfa4f77d
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
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)
26 /*!
27  * @class AIContactAwayPlugin
28  * @brief Tooltip component: Away messages and states
29  */
30 @implementation AIContactAwayPlugin
32 /*!
33  * @brief Install
34  */
35 - (void)installPlugin
37     //Install our tooltip entry
38     [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];
41 /*!
42  * @brief Tooltip label
43  *
44  * @result A label, or nil if no tooltip entry should be shown
45  */
46 - (NSString *)labelForObject:(AIListObject *)inObject
48     NSString                    *label = nil;
49     NSAttributedString  *statusMessage = nil;
50     BOOL                                away;
51     
52     away = ([inObject statusType] == AIAwayStatusType);
53     
54     //Get the status message
55     statusMessage = [inObject statusMessage];
56     
57     //Return the correct string
58     if(statusMessage != nil && [statusMessage length] != 0){
59                 if (away) {
60                         /* Away with a status message */
61                         
62                         //Check to make sure we're not duplicating server display name information
63                         NSString        *serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
64                         
65                         //Return the correct string
66                         if ([serverDisplayName isEqualToString:[statusMessage string]]) {
67                                 label = STATUS_LABEL;
68                         } else {
69                                 label = AWAY_MESSAGE_LABEL;
70                         }
71                         
72                 } else {
73                         /* Available with a status message */
74                         label = STATUS_LABEL;
75                 }
76     } else if (away) {
77                 /* Away without a status message */
78                 label = STATUS_LABEL;
79     }
80     
81     return(label);
84 /*!
85  * @brief Return the description of the object's status to show after Status:
86  *
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.
89  */
90 - (NSAttributedString *)awayDescriptionForObject:(AIListObject *)inObject
92         NSString *awayDescriptionString = nil;
93         NSString *statusName = [inObject statusName];
94         AIStatusType statusType = [inObject statusType];
95         
96         if (statusName) {
97                 awayDescriptionString = [[adium statusController] localizedDescriptionForStatusName:statusName
98                                                                                                                                                                  statusType:statusType];
99         }
100         
101         if (!statusName && (statusType == AIAwayStatusType)) {
102                 awayDescriptionString = AWAY;
103         }
104         
105         return (awayDescriptionString ?
106                         [[[NSAttributedString alloc] initWithString:awayDescriptionString] autorelease] :
107                         nil);
111  * @brief Tooltip entry
113  * @result The tooltip entry, or nil if no tooltip should be shown
114  */
115 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
117     NSAttributedString  *entry = nil;
118     NSAttributedString  *statusMessage = nil;
119         NSString                        *serverDisplayName = nil;
120     BOOL                                away;
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.
132                  */
133                 entry = [self awayDescriptionForObject:inObject];
135         } else {
136                 if (statusMessage != nil && [statusMessage length] != 0) {
137                         if ([[statusMessage string] rangeOfString:@"\t" options:NSLiteralSearch].location == NSNotFound) {
138                                 entry = statusMessage;
139                                 
140                         } else {
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"
145                                                                                                           withString:@"    "
146                                                                                                                  options:NSLiteralSearch
147                                                                                                                    range:NSMakeRange(0, [mutableStatusMessage length])];
148                                 entry = mutableStatusMessage;
149                         }
150                         
151                         
152                         
153                 } else {
154                         entry = [self awayDescriptionForObject:inObject];
155                 }
156         }
157         
158     return(entry);
161 @end