Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / AdiumChatEvents.m
blob1a9a5a2da823fce658c9be734e41f465517006e3
1 //
2 //  AdiumChatEvents.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 9/10/05.
6 //
8 #import "AdiumChatEvents.h"
9 #import <Adium/AIContactAlertsControllerProtocol.h>
10 #import <Adium/AIChat.h>
11 #import <Adium/AIListContact.h>
12 #import <Adium/AIListObject.h>
13 #import <AIUtilities/AIImageAdditions.h>
14 #import <Adium/AIListGroup.h>
16 @implementation AdiumChatEvents
18 /*!
19  * @brief Our parent controller loaded
20  *
21  * Register the events we generate with the contactAlertsController.
22  * Assumption: The contactAlertController already loaded
23  */
24 - (void)controllerDidLoad
26         //Register the events we generate
27         [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_JOINED_CHAT
28                                                                                  withHandler:self 
29                                                                                          inGroup:AIMessageEventHandlerGroup
30                                                                                   globalOnly:NO];
31         [[adium contactAlertsController] registerEventID:CONTENT_CONTACT_LEFT_CHAT
32                                                                                  withHandler:self 
33                                                                                          inGroup:AIMessageEventHandlerGroup
34                                                                                   globalOnly:NO];       
35         [[adium contactAlertsController] registerEventID:CONTENT_GROUP_CHAT_INVITE
36                                                                                  withHandler:self 
37                                                                                          inGroup:AIMessageEventHandlerGroup
38                                                                                   globalOnly:NO];       
41 /*!
42  * @brief A group chat added a contact
43  */
44 - (void)chat:(AIChat *)chat addedListContact:(AIListContact *)inContact
46         [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_JOINED_CHAT
47                                                                          forListObject:inContact
48                                                                                   userInfo:[NSDictionary dictionaryWithObject:chat
49                                                                                                                                                            forKey:@"AIChat"]
50                                           previouslyPerformedActionIDs:nil];
53 /*!
54  * @brief A group chat removed a contact
55  */
56 - (void)chat:(AIChat *)chat removedListContact:(AIListContact *)inContact
58         [[adium contactAlertsController] generateEvent:CONTENT_CONTACT_LEFT_CHAT
59                                                                          forListObject:inContact
60                                                                                   userInfo:[NSDictionary dictionaryWithObject:chat
61                                                                                                                                                            forKey:@"AIChat"]
62                                           previouslyPerformedActionIDs:nil];
65 #pragma mark Event descriptions
66 - (NSString *)shortDescriptionForEventID:(NSString *)eventID
68         NSString        *description;
69         
70         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
71                 description = AILocalizedString(@"Joins a group chat",nil);
72         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
73                 description = AILocalizedString(@"Leaves a group chat",nil);
74         } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
75                 description = AILocalizedString(@"Invites you to a group chat",nil);
76         } else {
77                 description = @"";
78         }
79         
80         return description;
83 - (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
85         NSString        *description;
86         
87         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
88                 description = AILocalizedString(@"Contact joins a group chat",nil);
89         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
90                 description = AILocalizedString(@"Contact leaves a group chat",nil);
91         } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
92                 description = AILocalizedString(@"Contact invites you to a group chat",nil);
93         } else {
94                 description = @"";
95         }
96         
97         return description;
100 //Evan: This exists because old X(tras) relied upon matching the description of event IDs, and I don't feel like making
101 //a converter for old packs.  If anyone wants to fix this situation, please feel free :)
102 - (NSString *)englishGlobalShortDescriptionForEventID:(NSString *)eventID
104         NSString        *description;
105         
106         if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
107                 description = @"Contact Joins";
108         } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
109                 description = @"Contact Leaves";
110         } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
111                 description = @"Contact Invites You to Chat";
112         } else {
113                 description = @"";
114         }
115         
116         return description;
119 - (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
121         NSString        *description = nil;
122         
123         if (listObject) {
124                 NSString        *name;
125                 NSString        *format;
126                 
127                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
128                         format = AILocalizedString(@"When %@ joins a group chat",nil);
129                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
130                         format = AILocalizedString(@"When %@ leaves a group chat",nil);
131                 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
132                         format = AILocalizedString(@"When %@ invites you to a group chat",nil);
133                 } else {
134                         format = nil;
135                 }
136                 
137                 if (format) {
138                         name = ([listObject isKindOfClass:[AIListGroup class]] ?
139                                         [NSString stringWithFormat:AILocalizedString(@"a member of %@",nil),[listObject displayName]] :
140                                         [listObject displayName]);
141                         
142                         description = [NSString stringWithFormat:format, name];
143                 }
144                 
145         } else {
146                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
147                         description = AILocalizedString(@"When a contact joins a group chat",nil);
148                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
149                         description = AILocalizedString(@"When a contact leaves a group chat",nil);
150                 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
151                         description = AILocalizedString(@"When a contact invites you to a group chat",nil);
152                 }
153         }
154         
155         return description;
158 - (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
159                                                                                 listObject:(AIListObject *)listObject
160                                                                                   userInfo:(id)userInfo
161                                                                         includeSubject:(BOOL)includeSubject
163         NSString                *description = nil;
164         AIChat                  *chat;
165         
166         NSParameterAssert([userInfo isKindOfClass:[NSDictionary class]]);
167         
168         chat = [(NSDictionary *)userInfo objectForKey:@"AIChat"];
169         
170         if (includeSubject) {           
171                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
172                         description = [NSString stringWithFormat:
173                                 AILocalizedString(@"%@ joined %@","Contact joined Chat Name"),
174                                 [listObject displayName],
175                                 [chat displayName]];
176                         
177                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
178                         description = [NSString stringWithFormat:
179                                 AILocalizedString(@"%@ left %@","Contact left Chat Name"),
180                                 [listObject displayName],
181                                 [chat displayName]];
182                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
183                         description = [NSString stringWithFormat:
184                                                    AILocalizedString(@"%@ left %@","Contact left Chat Name"),
185                                                    [listObject displayName],
186                                                    [chat displayName]];
187                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
188                         description = [NSString stringWithFormat:
189                                                    AILocalizedString(@"%@ invites you to a group chat","Contact invites you to a group chat"),
190                                                    [listObject displayName],
191                                                    [chat displayName]];
192                 }       
193                 
194         } else {
195                 if ([eventID isEqualToString:CONTENT_CONTACT_JOINED_CHAT]) {
196                         description = [NSString stringWithFormat:
197                                 AILocalizedString(@"joined %@","Contact joined Chat Name"),
198                                 [chat displayName]];
199                         
200                 } else if ([eventID isEqualToString:CONTENT_CONTACT_LEFT_CHAT]) {
201                         description = [NSString stringWithFormat:
202                                 AILocalizedString(@"left %@","Contact left Chat Name"),
203                                 [chat displayName]];
204                 } else if ([eventID isEqualToString:CONTENT_GROUP_CHAT_INVITE]) {
205                         description = [NSString stringWithFormat:
206                                                    AILocalizedString(@"invites you to a group chat","Contact left Chat Name"),
207                                                    [chat displayName]];
208                 }               }
209         
210         return description;
213 - (NSImage *)imageForEventID:(NSString *)eventID
215         static NSImage  *eventImage = nil;
216         if (!eventImage) eventImage = [[NSImage imageNamed:@"message" forClass:[self class]] retain];
217         return eventImage;
220 @end