Plugins/Purple Service/DCPurpleYahooJoinChatViewController.m
branchadium-1.5.11
changeset 6014 fcb71cb71a3d
parent 5941 307f53385811
parent 6013 f8d0dc659e3f
child 6016 325e2ab3406f
equal deleted inserted replaced
5941:307f53385811 6014:fcb71cb71a3d
     1 /* 
       
     2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
       
     3  * with this source distribution.
       
     4  * 
       
     5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
       
     6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
       
     7  * or (at your option) any later version.
       
     8  * 
       
     9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
       
    10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       
    11  * Public License for more details.
       
    12  * 
       
    13  * You should have received a copy of the GNU General Public License along with this program; if not,
       
    14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
       
    15  */
       
    16 
       
    17 #import <Adium/AIContactControllerProtocol.h>
       
    18 #import "DCPurpleYahooJoinChatViewController.h"
       
    19 #import "DCJoinChatWindowController.h"
       
    20 #import <AIUtilities/AICompletingTextField.h>
       
    21 #import <Adium/AIAccount.h>
       
    22 #import <Adium/AIListContact.h>
       
    23 
       
    24 @interface DCPurpleYahooJoinChatViewController ()
       
    25 - (void)validateEnteredText;
       
    26 - (void)_configureTextField;
       
    27 @end
       
    28 
       
    29 @implementation DCPurpleYahooJoinChatViewController
       
    30 
       
    31 - (id)init
       
    32 {
       
    33 	if ((self = [super init]))
       
    34 	{
       
    35 		[textField_inviteUsers setDragDelegate:self];
       
    36 		[textField_inviteUsers registerForDraggedTypes:[NSArray arrayWithObjects:@"AIListObject", @"AIListObjectUniqueIDs", nil]];
       
    37 	}
       
    38 	
       
    39 	return self;
       
    40 }
       
    41 
       
    42 - (void)configureForAccount:(AIAccount *)inAccount
       
    43 {
       
    44 	[super configureForAccount:inAccount];
       
    45 
       
    46 	[textField_inviteUsers setMinStringLength:2];
       
    47 	[textField_inviteUsers setCompletesOnlyAfterSeparator:YES];
       
    48 	[self _configureTextField];
       
    49 	
       
    50 	[self validateEnteredText];
       
    51 	[[view window] makeFirstResponder:textField_roomName];
       
    52 }
       
    53 
       
    54 - (void)joinChatWithAccount:(AIAccount *)inAccount
       
    55 {	
       
    56 	NSString		*room = [textField_roomName stringValue];
       
    57 	
       
    58 	/* Yahoo group chats always have a colon and then a number. If none is specified, add :1.  The server would do this for us
       
    59 	 * automagically... but then we have a spare AIChat lying around, and that's no good.
       
    60 	 */	
       
    61 	if ([room rangeOfString:@":"].location == NSNotFound) {
       
    62 		room = [room stringByAppendingString:@":1"];
       
    63 	}
       
    64 
       
    65 	NSDictionary *chatCreationInfo = [NSDictionary dictionaryWithObjectsAndKeys:room,@"room",nil];
       
    66 	
       
    67 	[self doJoinChatWithName:room
       
    68 				   onAccount:inAccount
       
    69 			chatCreationInfo:chatCreationInfo
       
    70 			invitingContacts:[self contactsFromNamesSeparatedByCommas:[textField_inviteUsers stringValue] onAccount:inAccount]
       
    71 	   withInvitationMessage:[textField_inviteMessage stringValue]];
       
    72 	
       
    73 }
       
    74 
       
    75 - (NSString *)nibName
       
    76 {
       
    77 	return @"DCPurpleYahooJoinChatView";
       
    78 }
       
    79 
       
    80 //Entered text is changing
       
    81 - (void)controlTextDidChange:(NSNotification *)notification
       
    82 {
       
    83 	if ([notification object] == textField_roomName) {
       
    84 		[self validateEnteredText];
       
    85 	}
       
    86 }
       
    87 
       
    88 - (void)validateEnteredText
       
    89 {
       
    90 	if (delegate)
       
    91 		[(DCJoinChatWindowController *)delegate setJoinChatEnabled:[textField_roomName stringValue].length > 0];
       
    92 }
       
    93 
       
    94 - (NSString *)impliedCompletion:(NSString *)aString
       
    95 {
       
    96 	return [textField_inviteUsers impliedStringValueForString:aString];
       
    97 }
       
    98 
       
    99 - (void)_configureTextField
       
   100 {
       
   101 	//Clear the completing strings
       
   102 	[textField_inviteUsers setCompletingStrings:nil];
       
   103 	
       
   104 	//Configure the auto-complete view to autocomplete for contacts matching the selected account's service
       
   105 	for (AIListContact *contact in adium.contactController.allContacts) {
       
   106 		if (contact.service == account.service) {
       
   107 			NSString *UID = contact.UID;
       
   108 			[textField_inviteUsers addCompletionString:contact.formattedUID withImpliedCompletion:UID];
       
   109 			[textField_inviteUsers addCompletionString:contact.displayName withImpliedCompletion:UID];
       
   110 			[textField_inviteUsers addCompletionString:UID];
       
   111 		}
       
   112 	}
       
   113 }
       
   114 
       
   115 #pragma mark Dragging Delegate
       
   116 
       
   117 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
       
   118 {
       
   119 	return YES;
       
   120 }
       
   121 
       
   122 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
       
   123 {
       
   124 	return [super doPerformDragOperation:sender toField:textField_inviteUsers];
       
   125 }
       
   126 
       
   127 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
       
   128 {
       
   129 	return [super doDraggingEntered:sender];
       
   130 }
       
   131 
       
   132 @end