When we receive a distributed notification, any objects added to the autorelease...
[adiumx.git] / Source / AIChatCommandsController.m
blob9a9ca7177abab228d556b5a8743ea5f952e2c14e
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 #warning Wrong location - move to frameworks folder
11 #import "AIChatCommandsController.h"
12 @implementation AIChatCommandsController
14 /* @name        verifyCommand
15  * @param       command: command picked by the user
16  *                      AIChat: the chat the command was issued from
17  * @brief       the method shows the user a sheet to input the 
18  *                      appropriate information. 
19  */
21 -(void)verifyCommand:(NSString*)command forChat:(AIChat*)chat;
23         parameters = [[NSMutableDictionary alloc] init];
24         [parameters setObject:chat forKey:@"chat"];
25         [parameters setObject:[chat account] forKey:@"account"];
26         [parameters setObject:[command stringByAppendingString:@" "] forKey:@"command"];
27         
29         //check what command was given & set proper label
30         if([command isEqualTo:@"kick"]) {
31                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
32                 [textField_comment setStringValue:@"(optional)"];
33         } else if ([command isEqualTo:@"Ban User:"]) {
34                 [NSBundle loadNibNamed:@"ChatPrompt" owner:self];
35                 [label_target setStringValue:@"Ban:"];
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         [self showWindow:[self window]];
76         [[self window] center];
79 /* @name        ok
80  * @brief       method  called when the user presses ok
81  *                      on the input sheet. This method calls
82  *                      "doCommand" on the delegate. 
83  */
84 -(IBAction)ok:(id)sender
86         /* the proper command string is in the form:
87         * "/ command target"
88         * make sure this is the form "totalCommandString has"
89         */
90         NSString *command = [[NSString alloc] init];
91         NSString *totalCommandString = [[NSString alloc] init];
92         command = [@"/" stringByAppendingString:[parameters objectForKey:@"command"]];
93         totalCommandString = [command stringByAppendingString:[textField_target stringValue]];
94                 
95         if([textField_comment stringValue] != nil){
96                 command = [totalCommandString stringByAppendingString:@" "];
97                 totalCommandString = [command stringByAppendingString:[textField_comment stringValue]];
98         }
99                 
100         [parameters setObject:totalCommandString forKey:@"totalCommandString"]; 
101         [delegate executeCommandWithParameters:parameters];
102         
103         [sheet orderOut:nil];
104         [NSApp endSheet:sheet];
107 /* @name        cancel
108  * @brief       method called when user presses cancel on the sheet
109  *                      dismisses the sheet
110  */
111 -(IBAction)cancel:(id)sender
113         [sheet orderOut:nil];
114         [NSApp endSheet:sheet];
118 // @brief accessor methods for the delegate
119 -(id)delegate
121         return delegate;
124 -(void)setDelegate:(id)newDelegate
126         if(delegate != newDelegate){
127                 [delegate release];
128                 delegate = [newDelegate retain];
129         }
134 @end