Paste number 37299: something

Paste number 37299: something
Pasted by: akempgen
When:2 years, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+SS3
Channel:#colloquy
Paste contents:
Raw Source | XML | Display As
#import "AKAvatarPlugin.h"

#import "JVChatController.h"
#import "JVChatEvent.h"
#import "JVChatMessage.h"
#import "JVChatRoomMember.h"
#import "JVChatRoomPanel.h"
#import "JVChatTranscript.h"
#import "JVChatTranscriptPanel.h"
#import "JVChatWindowController.h"
#import "JVNotificationController.h"
#import "JVToolbarItem.h"
#import "JVSpeechController.h"
#import "MVBuddyListController.h"
#import "MVChatConnection.h"
#import "MVChatRoom.h"
#import "MVChatUser.h"
#import "MVIRCChatUser.h"
#import "MVConnectionsController.h"
#import "MVFileTransferController.h"
#import "NSAttributedStringAdditions.h"
#import "NSStringAdditions.h"

#import "MVFileTransfer.h"

@implementation AKAvatarPlugin

- (id) initWithManager:(MVChatPluginManager *)manager
{
	self = [super init];
	return self;
}

- (void) dealloc
{
	[super dealloc];
}

#pragma mark -
#pragma mark -
#pragma mark  Hooks for the MVChatPlugin protocol:

- (NSArray *) contextualMenuItemsForObject:(id)object inView:(id <JVChatViewController>)view
{
	NSMutableArray *avatarContextMenuItems = [NSMutableArray array];
	if ([object isKindOfClass:NSClassFromString(@"JVChatRoomMember")] && ! [object isLocalUser])
	{
		[avatarContextMenuItems addObject: [[[NSMenuItem alloc] initWithTitle: @"Request Avatar" action:@selector( requestAvatar ) keyEquivalent:@""] autorelease]];
		[avatarContextMenuItems addObject: [[[NSMenuItem alloc] initWithTitle: @"Send Avatar" action:@selector( sendAvatar ) keyEquivalent:@""] autorelease]];
	}
	return avatarContextMenuItems;
}

- (BOOL) processSubcodeRequest:(NSString *)command withArguments:(NSData *)arguments fromUser:(MVChatUser *)user
{
#pragma mark TODO: remove NSLog
	NSLog([@"AVATAR: Subcode Request: " stringByAppendingString:command]);
	
	if ([command isCaseInsensitiveEqualToString:@"AVATAR"])
	{
		if (arguments)
		{
			NSLog(@"das war ein angebot");
			NSArray *argumentArray = [[[[NSString alloc] initWithData:arguments encoding:[[user connection] encoding]] autorelease] componentsSeparatedByString:@" "];
		//	NSArray *argumentArray = [[[[NSString alloc] initWithData:arguments encoding:[[JVChatController defaultController] chatViewControllerForUser:user ifExists:einserstellenheißtNO]] autorelease] componentsSeparatedByString:@" "];
			NSLog(@"Arguments: %@",[argumentArray description]);
//			if (weWantToReceiveAvatarFromUser:user)
//			{
				NSLog(@"wir wollen annehmen");
				
				if ([[NSArray arrayWithObjects:@"http",@"ftp",nil] containsObject:[[NSURL URLWithString:[argumentArray objectAtIndex:0]] scheme]])
				{
				//	NSURLDownload *avatarDownload = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[argumentArray objectAtIndex:0]]] delegate:self];
				//	[avatarDownload setDestination:[@"~/dev/Colloquy\\ Plugins/Downloads" stringByExpandingTildeInPath] allowOverwrite:NO];
					// create the request
					NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:[argumentArray objectAtIndex:0]]
															  cachePolicy:NSURLRequestUseProtocolCachePolicy
														  timeoutInterval:60.0];
					NSLog([theRequest description]);
					// create the connection with the request
					// and start loading the data
					NSURLDownload  *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
					if (!theDownload) {
						NSLog(@"download failed");
					}
					NSLog([theDownload description]);
				}
				else //if (supportedfile)
				{
//					if (filesizeisokay)
//					{
						NSLog(@"DCC Filetransfer is angesagt");
					//	[18:39] <xenon> there is, just dont add it to the MVFileTransferManager
					//	MVFileTransferController
					//	MVFileTransfer
					//	filetransfer <- requestAvatarFromUser:user
//					}
				}
				
				
//			}
		}
		else
		{
			NSLog(@"das war eine anfrage");
//			if (weWantToSendAvatarToUser:user)
//			{
				NSLog(@"wir schicken unseren avatar los!");
				return YES;
//			}
		}
	}
	
	return NO;
}

#pragma mark -
#pragma mark -
#pragma mark  Programming logic for AKAvatarPlugin:

- (void) requestAvatarForMember:(MVIRCChatUser *)theMember
{
	//[theMember ];
}

#pragma mark -
#pragma mark  Storing images:

#pragma mark -
#pragma mark  Connection to JVChatRoomMember:

#pragma mark -
#pragma mark Download Delegate Stuff:
 
- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
{
	NSLog(@"Destination for %@, filename: %@", [download description], filename);
    NSString *destinationFilename;
    NSString *homeDirectory=NSHomeDirectory();
 
    destinationFilename=[[homeDirectory stringByAppendingPathComponent:@"Desktop"]
        stringByAppendingPathComponent:filename];
    [download setDestination:destinationFilename allowOverwrite:NO];
}
 
 
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
    // release the connection
    [download release];
 
    // inform the user
    NSLog(@"Download failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
 
- (void)downloadDidFinish:(NSURLDownload *)download
{
    // release the connection
    [download release];
 
    // do something with the data
    NSLog(@"%@",@"downloadDidFinish");
}
-(void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path
{
    // path now contains the destination path
    // of the download, taking into account any
    // unique naming caused by -setDestination:allowOverwrite:
    NSLog(@"Final file destination: %@",path);
}

@end

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.