Update the icon in the personal preferences if it's changed elsewhere (the contact...
[adiumx.git] / Source / AdiumAuthorization.m
blob17871988908f1eda8fe1b610255d07155d2e8a4c
1 //
2 //  AdiumAuthorization.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 1/18/06.
6 //
8 #import "AdiumAuthorization.h"
9 #import "ESAuthorizationRequestWindowController.h"
10 #import <Adium/AIContactControllerProtocol.h>
11 #import <Adium/AIContactAlertsControllerProtocol.h>
12 #import <Adium/AIAccount.h>
13 #import <AIUtilities/AIImageAdditions.h>
15 #define CONTACT_REQUESTED_AUTHORIZATION @"Contact Requested Authorization"
17 @implementation AdiumAuthorization
19 - (id)init
21         if ((self = [super init])) {
22                 [[adium contactAlertsController] registerEventID:CONTACT_REQUESTED_AUTHORIZATION
23                                                                                          withHandler:self
24                                                                                                  inGroup:AIContactsEventHandlerGroup
25                                                                                           globalOnly:YES];
26         }
27         
28         return self;
31 - (id)showAuthorizationRequestWithDict:(NSDictionary *)inDict forAccount:(AIAccount *)inAccount
33         AIListContact   *listContact = [[adium contactController] contactWithService:[inAccount service]
34                                                                                                                                                  account:inAccount
35                                                                                                                                                          UID:[inDict objectForKey:@"Remote Name"]];
37         [[adium contactAlertsController] generateEvent:CONTACT_REQUESTED_AUTHORIZATION
38                                                                          forListObject:(AIListObject *)listContact
39                                                                                   userInfo:nil
40                                           previouslyPerformedActionIDs:nil];                            
41         
42         return [ESAuthorizationRequestWindowController showAuthorizationRequestWithDict:inDict forAccount:inAccount];
45 #pragma mark Event descriptions
47 - (NSString *)shortDescriptionForEventID:(NSString *)eventID
49         NSString        *description;
50         
51         if ([eventID isEqualToString:CONTACT_REQUESTED_AUTHORIZATION]) {
52                 description = AILocalizedString(@"Requests authorization",nil);
53         } else {
54                 description = @"";
55         }
56         
57         return description;
60 - (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
62         NSString        *description;
63         
64         if ([eventID isEqualToString:CONTACT_REQUESTED_AUTHORIZATION]) {
65                 description = AILocalizedString(@"Contact requests authorization",nil);
66         } else {
67                 description = @"";
68         }
69         
70         return description;
73 //Evan: This exists because old X(tras) relied upon matching the description of event IDs, and I don't feel like making
74 //a converter for old packs.  If anyone wants to fix this situation, please feel free :)
75 - (NSString *)englishGlobalShortDescriptionForEventID:(NSString *)eventID
77         NSString        *description;
78         
79         if ([eventID isEqualToString:CONTACT_REQUESTED_AUTHORIZATION]) {
80                 description = @"Authorization Requested";
81         } else {
82                 description = @"";
83         }
84         
85         return description;
88 - (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
90         NSString        *description = nil;
91         
92         if (listObject) {
93                 NSString        *name;
94                 NSString        *format;
95                 
96                 if ([eventID isEqualToString:CONTACT_REQUESTED_AUTHORIZATION]) {
97                         format = AILocalizedString(@"When %@ requests authorization",nil);
98                 } else {
99                         format = nil;
100                 }
101                 
102                 if (format) {
103                         name = ([listObject isKindOfClass:[AIListGroup class]] ?
104                                         [NSString stringWithFormat:AILocalizedString(@"a member of %@",nil),[listObject displayName]] :
105                                         [listObject displayName]);
106                         
107                         description = [NSString stringWithFormat:format, name];
108                 }
109                 
110         } else {
111                 if ([eventID isEqualToString:CONTACT_REQUESTED_AUTHORIZATION]) {
112                         description = AILocalizedString(@"When a contact requests authorization",nil);
113                 }
114         }
115         
116         return description;
119 - (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
120                                                                                 listObject:(AIListObject *)listObject
121                                                                                   userInfo:(id)userInfo
122                                                                         includeSubject:(BOOL)includeSubject
124         NSString        *description = nil;
125         
126         if (includeSubject) {
127                 description = [NSString stringWithFormat:AILocalizedString(@"%@ requested authorization", "Event: <A contact's name> requested authorization"), [listObject formattedUID]];
129         } else {
130                 description = AILocalizedString(@"requested authorization", "Event: requested authorization (follows a contact's name displayed as a header)");
131         }
132         
133         return description;
136 - (NSImage *)imageForEventID:(NSString *)eventID
138         static NSImage  *eventImage = nil;
139         if (!eventImage) eventImage = [[NSImage imageNamed:@"DefaultIcon" forClass:[self class]] retain];
140         return eventImage;
143 @end