Fixed line width in the messages advanced prefs
[adiumx.git] / Source / AIContactAwayPlugin.m
blobb7627fc8f10f899b697b4f1b5bd03120106f1f5f
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 <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)
27 /*!
28  * @class AIContactAwayPlugin
29  * @brief Tooltip component: Away messages and states
30  */
31 @implementation AIContactAwayPlugin
33 /*!
34  * @brief Install
35  */
36 - (void)installPlugin
38     //Install our tooltip entry
39     [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];
42 /*!
43  * @brief Tooltip label
44  *
45  * @result A label, or nil if no tooltip entry should be shown
46  */
47 - (NSString *)labelForObject:(AIListObject *)inObject
49     NSString                    *label = nil;
50     NSAttributedString  *statusMessage = nil;
51     BOOL                                away;
52     
53     away = ([inObject statusType] == AIAwayStatusType);
54     
55     //Get the status message
56     statusMessage = [inObject statusMessage];
57     
58     //Return the correct string
59     if(statusMessage != nil && [statusMessage length] != 0){
60                 if (away) {
61                         /* Away with a status message */
62                         
63                         //Check to make sure we're not duplicating server display name information
64                         NSString        *serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
65                         
66                         //Return the correct string
67                         if ([serverDisplayName isEqualToString:[statusMessage string]]) {
68                                 label = STATUS_LABEL;
69                         } else {
70                                 label = AWAY_MESSAGE_LABEL;
71                         }
72                         
73                 } else {
74                         /* Available with a status message */
75                         label = STATUS_LABEL;
76                 }
77     } else if (away) {
78                 /* Away without a status message */
79                 label = STATUS_LABEL;
80     }
81     
82     return label;
85 /*!
86  * @brief Return the description of the object's status to show after Status:
87  *
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.
90  */
91 - (NSAttributedString *)awayDescriptionForObject:(AIListObject *)inObject
93         NSString *awayDescriptionString = nil;
94         NSString *statusName = [inObject statusName];
95         AIStatusType statusType = [inObject statusType];
96         
97         if (statusName) {
98                 awayDescriptionString = [[adium statusController] localizedDescriptionForStatusName:statusName
99                                                                                                                                                                  statusType:statusType];
100         }
101         
102         if (!statusName && (statusType == AIAwayStatusType)) {
103                 awayDescriptionString = AWAY;
104         }
105         
106         return (awayDescriptionString ?
107                         [[[NSAttributedString alloc] initWithString:awayDescriptionString] autorelease] :
108                         nil);
112 * @brief Tooltip entry
114  * @result The tooltip entry, or nil if no tooltip should be shown
115  */
116 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
118     NSAttributedString  *entry = nil;
119     NSAttributedString  *statusMessage = nil;
120         NSString                        *serverDisplayName = nil;
121         
122     //Get the status message
123     statusMessage = [inObject statusMessage];
124         
125         //Check to make sure we're not duplicating server display name information
126         serverDisplayName = [inObject statusObjectForKey:@"Server Display Name"];
127         
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];
134                 
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