5 // Created by Evan Schoenberg on 9/10/05.
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
18 * @brief Our parent controller loaded
20 * Register the events we generate with the contactAlertsController.
21 * Assumption: The contactAlertController already loaded
23 - (void)controllerDidLoad
25 //Register the events we generate
26 [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_JOINED_CHAT
28 inGroup:AIMessageEventHandlerGroup
30 [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_LEFT_CHAT
32 inGroup:AIMessageEventHandlerGroup
37 * @brief A group chat added a contact
39 - (void)chat:(AIChat *)chat addedListContact:(AIListContact *)inContact
41 [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_JOINED_CHAT
42 forListObject:inContact
43 userInfo:[NSDictionary dictionaryWithObject:chat
45 previouslyPerformedActionIDs:nil];
49 * @brief A group chat removed a contact
51 - (void)chat:(AIChat *)chat removedListContact:(AIListContact *)inContact
53 [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_LEFT_CHAT
54 forListObject:inContact
55 userInfo:[NSDictionary dictionaryWithObject:chat
57 previouslyPerformedActionIDs:nil];
60 #pragma mark Event descriptions
61 - (NSString *)shortDescriptionForEventID:(NSString *)eventID
63 NSString *description;
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);
76 - (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
78 NSString *description;
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);
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;
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";
108 - (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
110 NSString *description = nil;
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);
125 name = ([listObject isKindOfClass:[AIListGroup class]] ?
126 [NSString stringWithFormat:AILocalizedString(@"a member of %@",nil),[listObject displayName]] :
127 [listObject displayName]);
129 description = [NSString stringWithFormat:format, name];
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);
143 - (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
144 listObject:(AIListObject *)listObject
145 userInfo:(id)userInfo
146 includeSubject:(BOOL)includeSubject
148 NSString *description = nil;
151 NSParameterAssert([userInfo isKindOfClass:[NSDictionary class]]);
153 chat = [(NSDictionary *)userInfo objectForKey:@"AIChat"];
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],
162 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
163 description = [NSString stringWithFormat:
164 AILocalizedString(@"%@ left %@","Contact left Chat Name"),
165 [listObject displayName],
170 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
171 description = [NSString stringWithFormat:
172 AILocalizedString(@"joined %@","Contact joined Chat Name"),
175 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
176 description = [NSString stringWithFormat:
177 AILocalizedString(@"left %@","Contact left Chat Name"),
185 - (NSImage *)imageForEventID:(NSString *)eventID
187 static NSImage *eventImage = nil;
188 if (!eventImage) eventImage = [[NSImage imageNamed:@"message" forClass:[self class]] retain];