Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / AdiumChatEvents.m
blob1e86ec7e1a5dc93e0ab56c5074ebfad364ab99a2
1 //
2 //  AdiumChatEvents.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 9/10/05.
6 //
8 #import "AdiumChatEvents.h"
9 #import "ESContactAlertsController.h"
10 #import <Adium/AIChat.h>
11 #import <Adium/AIListContact.h>
12 #import <Adium/AIListObject.h>
13 #import <AIUtilities/ESImageAdditions.h>
15 @implementation AdiumChatEvents
17 /*!
18  * @brief Our parent controller loaded
19  *
20  * Register the events we generate with the contactAlertsController.
21  * Assumption: The contactAlertController already loaded
22  */
23 - (void)controllerDidLoad
25         //Register the events we generate
26         [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_JOINED_CHAT
27                                                                                  withHandler:self 
28                                                                                          inGroup:AIMessageEventHandlerGroup
29                                                                                   globalOnly:NO];
30         [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_LEFT_CHAT
31                                                                                  withHandler:self 
32                                                                                          inGroup:AIMessageEventHandlerGroup
33                                                                                   globalOnly:NO];       
37  * @brief A group chat added a contact
38  */
39 - (void)chat:(AIChat *)chat addedListContact:(AIListContact *)inContact
41         [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_JOINED_CHAT
42                                                                          forListObject:inContact
43                                                                                   userInfo:[NSDictionary dictionaryWithObject:chat
44                                                                                                                                                            forKey:@"AIChat"]
45                                           previouslyPerformedActionIDs:nil];
49  * @brief A group chat removed a contact
50  */
51 - (void)chat:(AIChat *)chat removedListContact:(AIListContact *)inContact
53         [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_LEFT_CHAT
54                                                                          forListObject:inContact
55                                                                                   userInfo:[NSDictionary dictionaryWithObject:chat
56                                                                                                                                                            forKey:@"AIChat"]
57                                           previouslyPerformedActionIDs:nil];
60 #pragma mark Event descriptions
61 - (NSString *)shortDescriptionForEventID:(NSString *)eventID
63         NSString        *description;
64         
65         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
66                 description = AILocalizedString(@"Joins a group chat",nil);
67         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
68                 description = AILocalizedString(@"Leaves a group chat",nil);
69         } else {
70                 description = @"";
71         }
72         
73         return description;
76 - (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
78         NSString        *description;
79         
80         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
81                 description = AILocalizedString(@"Contact joins a group chat",nil);
82         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
83                 description = AILocalizedString(@"Contact leaves a group chat",nil);
84         } else {
85                 description = @"";
86         }
87         
88         return description;
91 //Evan: This exists because old X(tras) relied upon matching the description of event IDs, and I don't feel like making
92 //a converter for old packs.  If anyone wants to fix this situation, please feel free :)
93 - (NSString *)englishGlobalShortDescriptionForEventID:(NSString *)eventID
95         NSString        *description;
96         
97         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
98                 description = @"Contact Joins";
99         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
100                 description = @"Contact Leaves";
101         } else {
102                 description = @"";
103         }
104         
105         return description;
108 - (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
110         NSString        *description = nil;
111         
112         if (listObject) {
113                 NSString        *name;
114                 NSString        *format;
115                 
116                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
117                         format = AILocalizedString(@"When %@ joins a group chat",nil);
118                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
119                         format = AILocalizedString(@"When %@ leaves a group chat",nil);
120                 } else {
121                         format = nil;
122                 }
123                 
124                 if (format) {
125                         name = ([listObject isKindOfClass:[AIListGroup class]] ?
126                                         [NSString stringWithFormat:AILocalizedString(@"a member of %@",nil),[listObject displayName]] :
127                                         [listObject displayName]);
128                         
129                         description = [NSString stringWithFormat:format, name];
130                 }
131                 
132         } else {
133                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
134                         description = AILocalizedString(@"When a contact joins a group chat",nil);
135                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
136                         description = AILocalizedString(@"When a contact leaves a group chat",nil);
137                 }
138         }
139         
140         return description;
143 - (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
144                                                                                 listObject:(AIListObject *)listObject
145                                                                                   userInfo:(id)userInfo
146                                                                         includeSubject:(BOOL)includeSubject
148         NSString                *description = nil;
149         AIChat                  *chat;
150         
151         NSParameterAssert([userInfo isKindOfClass:[NSDictionary class]]);
152         
153         chat = [(NSDictionary *)userInfo objectForKey:@"AIChat"];
154         
155         if (includeSubject) {           
156                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
157                         description = [NSString stringWithFormat:
158                                 AILocalizedString(@"%@ joined %@","Contact joined Chat Name"),
159                                 [listObject displayName],
160                                 [chat displayName]];
161                         
162                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
163                         description = [NSString stringWithFormat:
164                                 AILocalizedString(@"%@ left %@","Contact left Chat Name"),
165                                 [listObject displayName],
166                                 [chat displayName]];
167                 }       
168                 
169         } else {
170                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
171                         description = [NSString stringWithFormat:
172                                 AILocalizedString(@"joined %@","Contact joined Chat Name"),
173                                 [chat displayName]];
174                         
175                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
176                         description = [NSString stringWithFormat:
177                                 AILocalizedString(@"left %@","Contact left Chat Name"),
178                                 [chat displayName]];
179                 }       
180         }
181         
182         return description;
185 - (NSImage *)imageForEventID:(NSString *)eventID
187         static NSImage  *eventImage = nil;
188         if (!eventImage) eventImage = [[NSImage imageNamed:@"message" forClass:[self class]] retain];
189         return eventImage;
192 @end