⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempsessionimcontainercontroller.mm

📁 lumaqq
💻 MM
📖 第 1 页 / 共 2 页
字号:
/*
 * LumaQQ - Cross platform QQ client, special edition for Mac
 *
 * Copyright (C) 2007 luma <stubma@163.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#import "TempSessionIMContainerController.h"
#import "MainWindowController.h"
#import "TimerTaskManager.h"
#import "PreferenceCache.h"
#import "Constants.h"
#import "ImageTool.h"
#import "NSString-Validate.h"
#import "AlertTool.h"
#import "TextTool.h"
#import "FontTool.h"
#import "TempSessionOpReplyPacket.h"
#import "TempSessionOpPacket.h"
#import "AuthInfoOpReplyPacket.h"

@implementation TempSessionIMContainerController

- (void) dealloc {
	if(m_verifyCodeHelper) {
		[m_verifyCodeHelper cancel];
		[m_verifyCodeHelper release];
		m_verifyCodeHelper = nil;
	}
	[super dealloc];
}

#pragma mark -
#pragma mark IMContainer protocol

- (id)initWithObject:(id)obj mainWindow:(MainWindowController*)mainWindowController {
	m_user = (User*)obj;
	m_verifyCodeHelper = [[VerifyCodeHelper alloc] initWithQQ:[m_user QQ] delegate:self];
	return [super initWithObject:obj mainWindow:mainWindowController];
}

- (void)walkMessageQueue:(MessageQueue*)queue {
	if(queue == nil)
		return;
	
	while(InPacket* packet = [queue getTempSessionMessage:[m_user QQ] remove:YES]) {
		[self appendPacket:packet];
	}
	
	// refresh dock icon
	[m_mainWindowController refreshDockIcon];
	
	// adjust message count, stop blink if necessary
	if([m_user tempSessionMessageCount] > 0) {
		Group* g = [[m_mainWindowController groupManager] group:[m_user groupIndex]];
		if(g)
			[g setMessageCount:([g messageCount] - [m_user tempSessionMessageCount])];			
		[m_user setTempSessionMessageCount:0];
	}
}

- (NSString*)owner {
	return [NSString stringWithFormat:@"%u_tempsession", [m_user QQ]];
}

- (id)windowKey {
	return [NSNumber numberWithUnsignedInt:[m_user QQ]];
}

- (NSString *)description {
	PreferenceCache* cache = [PreferenceCache cache:[m_user QQ]];
	NSString* name = [m_user nick];
	if([cache showRealName]) {
		if(![[m_user remarkName] isEmpty])
			name = [m_user remarkName];
	}
	return [NSString stringWithFormat:L(@"LQTitle", @"TempSessionIMContainer"), name, [m_user QQ]];
}

- (NSString*)shortDescription {
	PreferenceCache* cache = [PreferenceCache cache:[m_user QQ]];
	NSString* name = [m_user nick];
	if([cache showRealName]) {
		if(![[m_user remarkName] isEmpty])
			name = [m_user remarkName];
	}
	return name;
}

- (NSImage*)ownerImage {
	return [ImageTool headWithId:[m_user head]];
}

- (void)refreshHeadControl:(HeadControl*)headControl {
	[headControl setOwner:[[m_mainWindowController me] QQ]];
	[headControl setObjectValue:m_obj];
}

- (NSArray*)actionIds {
	if(m_actionIds == nil) {
		m_actionIds = [[NSArray arrayWithObjects:kToolbarItemFont, 
			kToolbarItemColor, 
			NSToolbarSeparatorItemIdentifier,
			kToolbarItemSmiley,
			nil] retain];
	}
	return m_actionIds;
}

- (void)handleIMContainerAttachedToWindow:(NSNotification*)notification {
	if(m_imView == [notification object]) {
		[m_split setDelegate:self];
		
		// get input box proportion
		float proportion = [m_user inputBoxProportion];
		
		// get split view bound
		NSRect bound = [m_split bounds];
		
		// set input box size
		NSRect frame;
		frame.origin = NSZeroPoint;
		frame.size = bound.size;
		frame.size.height = bound.size.height * (1.0 - proportion);
		frame.size.height = MAX(20.0, frame.size.height);
		frame.size.height = MIN(bound.size.height - 20.0, frame.size.height);
		[(NSView*)[[m_split subviews] objectAtIndex:0] setFrame:frame];
		
		// set output box size
		frame.origin.y = frame.size.height + [m_split dividerThickness];
		frame.size.height = bound.size.height - frame.origin.y;
		[(NSView*)[[m_split subviews] objectAtIndex:1] setFrame:frame];
		
		[m_split adjustSubviews];
	}
}

- (NSString*)canSend {
	// get max byte can be sent
	int fontStyleBytes = [[FontTool chatFontStyleWithPreference:[[m_mainWindowController me] QQ]] byteCount];
	int max = kQQMaxMessageFragmentLength - fontStyleBytes;
	
	// get message data
	if(m_data) 
		[m_data release];
	m_data = [TextTool getTextData:[m_txtInput textStorage] faceList:nil];
	
	// check length
	if([m_data length] > max) {
		m_data = nil;
		return L(@"LqWarningTooLong", @"BaseIMContainer");
	} else {
		m_data = nil;
		return nil;
	}
}

- (BOOL)allowCustomFace {
	return NO;
}

#pragma mark -
#pragma mark PSMTabModel protocol

- (int)objectCount {
	return [m_user tempSessionMessageCount];
}

#pragma mark -
#pragma mark actions

- (IBAction)showOwnerInfo:(id)sender {
	[[m_mainWindowController windowRegistry] showUserInfoWindow:m_user mainWindow:m_mainWindowController];
}

#pragma mark -
#pragma mark initialization

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

#pragma mark -
#pragma mark split view delegate

- (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset {
	return 20;
}

- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset {
	return [sender bounds].size.height - 20 - [sender dividerThickness];
}

- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification {
	NSView* view = [[m_split subviews] objectAtIndex:1];
	float newProp = ([view bounds].size.height + [m_split dividerThickness]) / [m_split bounds].size.height;
	[m_user setInputBoxProportion:newProp];
}

#pragma mark -
#pragma mark helper

- (void)appendPacket:(QQTextView*)textView packet:(InPacket*)inPacket {
	ReceivedIMPacket* packet = (ReceivedIMPacket*)inPacket;		
	TempSessionIM* im = [packet tempSessionIM];
	[self appendMessage:textView 
				   nick:[im nick]
				   data:[im messageData] 
				  style:[im fontStyle] 
				   date:[NSDate dateWithTimeIntervalSince1970:[im sendTime]]
			customFaces:nil];
}

- (UInt16)doSend:(NSData*)data style:(FontStyle*)style fragmentCount:(int)fragmentCount fragmentIndex:(int)fragmentIndex {
	/*
	 * the doSend doesn't do send stuff for temp session im
	 */
	return [[m_mainWindowController client] getUserTempSessionIMAuthInfo:[m_user QQ]];
}

- (void)sendNextMessage {	
	// check queue
	if([m_sendQueue count] == 0) {
		m_sending = NO;
		return;
	}
	
	// temp session im doesn't support fragment, so don't check
	if(m_sending)
		return;
	m_sending = YES;
	
	// get next message
	NSAttributedString* message = [m_sendQueue objectAtIndex:0];
	
	// release old data
	if(m_data) {
		[m_data release];
		m_data = nil;
	}
	
	// get message data
	m_data = [[TextTool getTextData:message faceList:nil] retain];
	
	// send message
	m_waitingSequence = [self doSend:m_data
							   style:nil
					   fragmentCount:1
					   fragmentIndex:0];
}

- (void)handleHistoryDidSelected:(NSNotification*)notification {
	History* history = [[notification userInfo] objectForKey:kUserInfoHistory];
	if(history == m_history) {
		id object = [notification object];
		if([object isKindOfClass:[SentIM class]]) {
			[self appendMessageHint:m_txtInput
							   nick:[[m_mainWindowController me] nick]
							   date:[NSDate dateWithTimeIntervalSince1970:[(SentIM*)object sendTime]]
						 attributes:m_myHintAttributes];
			[[m_txtInput textStorage] appendAttributedString:[(SentIM*)object message]];
			if(![m_txtInput allowMultiFont])
				[m_txtInput changeAttributesOfAllText:[m_txtInput typingAttributes]];
		} else if([object isKindOfClass:[InPacket class]]) {
			[self appendPacket:m_txtInput packet:(InPacket*)object];
		}
	}
}

- (void)showVerifyCodePanel {
	[NSApp beginSheet:m_verifyCodeWindow
	   modalForWindow:[m_imView window]
		modalDelegate:self
	   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -