Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / EBChatCommandsController.m
blob08d525b84002e9a9443722964afad2a0d58fd80a
1 //
2 //  EBChatCommandsController.m
3 //  Adium
4 //
5 //  Created by Erik Beerepoot on 11/07/07.
6 //  Copyright 2007 Adium. All rights reserved.
7 //
9 #import "EBChatCommandsController.h"
11 @implementation EBChatCommandsController
12 +(id)init;
14         
15         return [[super alloc] init];
18 /* @name        verifyCommand
19  * @param       command: command picked by the user
20  *                      AIChat: the chat the command was issued from
21  * @brief       the method shows the user a sheet to input the 
22  *                      appropriate information. 
23  */
25 -(void)verifyCommand:(NSString*)command forChat:(AIChat*)chat;
27         parameters = [[NSMutableDictionary alloc] init];
28         [parameters setObject:chat forKey:@"chat"];
29         [parameters setObject:[chat account] forKey:@"account"];
30         [parameters setObject:[command stringByAppendingString:@" "] forKey:@"command"];
31         
33         //check what command was given & set proper label
34         if([command isEqualTo:@"kick"] || [command isEqualTo:@"ban"])   {
35                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
36                 [textField_comment setStringValue:@"(optional)"];
37         } else if([command isEqualTo:@"topic"]) {
38                 [NSBundle loadNibNamed:@"BanPrompt" owner:self];
39                 [label_target setStringValue:@"Set topic:"];
40         } else if([command isEqualTo:@"invite"]) {
41                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
42                 [label_target setStringValue:@"Invite User:"];
43                 [textField_comment setStringValue:@"(optional)"];
44         } else if([command isEqualTo:@"msg"]) {
45                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
46                 [label_target setStringValue:@"Message User:"];
47                 [label_comment setStringValue:@"Message:"];
48         } else if([command isEqualTo:@"part"]) {
49                 [NSBundle loadNibNamed:@"BanPrompt" owner:self];
50                 [label_target setStringValue:@"Leave room with comment:"];
51         } else if([command isEqualTo:@"nick"]) {
52                 [NSBundle loadNibNamed:@"BanPrompt" owner:self];
53                 [label_target setStringValue:@"Enter new handle:"];
54         } else if([command isEqualTo:@"msg"]) {
55                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
56                 [label_target setStringValue:@"Join room:"];
57                 [label_comment setStringValue:@"Password:"];
58                 [textField_comment setStringValue:@"(optional)"];
59         } else if([command isEqualTo:@"role"]) {
60                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
61                 [label_target setStringValue:@"Set role for user:"];
62                 [label_comment setStringValue:@"Role:"];
63         } else if([command isEqualTo:@"affiliate"]) {
64                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
65                 [label_target setStringValue:@"Set affiliation for user:"];
66                 [label_comment setStringValue:@"Affiliation:"];
67         } else if([command isEqualTo:@"join"]) {
68                 [NSBundle loadNibNamed:@"BanPrompt" owner:self];
69                 [label_target setStringValue:@"Join room:"];
70         } else {
71                 NSRunAlertPanel(@"Command not supported", @"This command is not supported at this time",@"Cancel",@"OK",nil);
72         }
73         
74         //show sheet
75         [NSApp beginSheet:sheet
76                                 modalForWindow:[NSApp keyWindow]
77                                 modalDelegate:self
78                                 didEndSelector:nil
79                                 contextInfo:nil];
83 /* @name        ok
84  * @brief       method  called when the user presses ok
85  *                      on the input sheet. This method calls
86  *                      "doCommand" on the delegate. 
87  */
88 -(IBAction)ok:(id)sender
90                 /* the proper command string is in the form:
91                  * "/ command target"
92                  * make sure this is the form "totalCommandString has"
93                  */
94         NSString *command = [[NSString alloc] init];
95         NSString *totalCommandString = [[NSString alloc] init];
96         command = [@"/" stringByAppendingString:[parameters objectForKey:@"command"]];
97         totalCommandString = [command stringByAppendingString:[textField_target stringValue]];
98                 
99         if([textField_comment stringValue] != nil){
100                 command = [totalCommandString stringByAppendingString:@" "];
101                 totalCommandString = [command stringByAppendingString:[textField_comment stringValue]];
102         }
103                 
104         [parameters setObject:totalCommandString forKey:@"totalCommandString"]; 
105         [delegate executeCommandWithParameters:parameters];
106         
107         [sheet orderOut:nil];
108         [NSApp endSheet:sheet];
111 /* @name        cancel
112  * @brief       method called when user presses cancel on the sheet
113  *                      dismisses the sheet
114  */
115 -(IBAction)cancel:(id)sender
117         [sheet orderOut:nil];
118         [NSApp endSheet:sheet];
122 // @brief accessor methods for the delegate
123 -(id)delegate
125         return delegate;
128 -(void)setDelegate:(id)newDelegate
130         if(delegate != newDelegate){
131         [delegate release];
132         delegate = [newDelegate retain];
133         }
138 @end