2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
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.
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.
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.
17 #import <Adium/AIChatControllerProtocol.h>
18 #import <Adium/AIContentControllerProtocol.h>
19 #import "ESFileTransferMessagesPlugin.h"
20 #import <Adium/AIChat.h>
21 #import <Adium/AIContentEvent.h>
22 #import <Adium/AIListContact.h>
23 #import <Adium/ESFileTransfer.h>
25 @interface ESFileTransferMessagesPlugin (PRIVATE)
26 - (void)statusMessage:(NSString *)message forContact:(AIListContact *)contact withType:(NSString *)type;
30 * @class ESFileTransferMessagesPlugin
31 * @brief Component which handles sending file transfer status messages
33 @implementation ESFileTransferMessagesPlugin
40 //Install our observers
41 [[adium notificationCenter] addObserver:self
42 selector:@selector(handleFileTransferEvent:)
43 name:FILE_TRANSFER_CANCELLED
46 [[adium notificationCenter] addObserver:self
47 selector:@selector(handleFileTransferEvent:)
48 name:FILE_TRANSFER_COMPLETE
51 [[adium notificationCenter] addObserver:self
52 selector:@selector(handleFileTransferEvent:)
53 name:FILE_TRANSFER_WAITING_REMOTE
56 [[adium notificationCenter] addObserver:self
57 selector:@selector(handleFileTransferEvent:)
58 name:FILE_TRANSFER_BEGAN
61 [[adium notificationCenter] addObserver:self
62 selector:@selector(handleFileTransferEvent:)
63 name:FILE_TRANSFER_FAILED
70 - (void)uninstallPlugin
72 [[adium notificationCenter] removeObserver:self];
76 * @brief A file transfer event occurred
78 - (void)handleFileTransferEvent:(NSNotification *)notification
80 ESFileTransfer *fileTransfer = (ESFileTransfer *)[notification userInfo];
82 if ([[fileTransfer account] accountDisplaysFileTransferMessages]) return;
84 AIListContact *listContact = [notification object];
85 NSString *notificationName = [notification name];
88 if (!(filename = [[fileTransfer localFilename] lastPathComponent])) {
89 filename = [[fileTransfer remoteFilename] lastPathComponent];
93 NSString *message = nil;
96 if ([notificationName isEqualToString:FILE_TRANSFER_CANCELLED]) {
97 type = @"fileTransferAborted";
98 message = [NSString stringWithFormat:AILocalizedString(@"%@ cancelled the transfer of %@",nil),[listContact formattedUID],filename];
100 } else if ([notificationName isEqualToString:FILE_TRANSFER_FAILED]) {
101 type = @"fileTransferAborted";
102 message = [NSString stringWithFormat:AILocalizedString(@"The transfer of %@ failed",nil),filename];
103 }else if ([notificationName isEqualToString:FILE_TRANSFER_COMPLETE]) {
104 type = @"fileTransferCompleted";
105 if ([fileTransfer fileTransferType] == Incoming_FileTransfer) {
106 message = [NSString stringWithFormat:AILocalizedString(@"Successfully received %@",nil),filename];
108 message = [NSString stringWithFormat:AILocalizedString(@"Successfully sent %@",nil),filename];
110 } else if ([notificationName isEqualToString:FILE_TRANSFER_BEGAN]) {
111 type = @"fileTransferStarted";
112 if ([fileTransfer fileTransferType] == Incoming_FileTransfer) {
113 message = [NSString stringWithFormat:AILocalizedString(@"Began receiving %@",nil),filename];
115 message = [NSString stringWithFormat:AILocalizedString(@"Began sending %@",nil),filename];
117 } else if ([notificationName isEqualToString:FILE_TRANSFER_WAITING_REMOTE]) {
118 type = @"fileTransferWaitingRemote";
119 //We should only receive this notification upon sending a file
120 message = [NSString stringWithFormat:AILocalizedString(@"Offering to send %@ to %@",nil),filename,[listContact formattedUID]];
123 [self statusMessage:message forContact:listContact withType:type];
128 * @brief Post a status message on all active chats for this object
130 - (void)statusMessage:(NSString *)message forContact:(AIListContact *)contact withType:(NSString *)type
132 NSEnumerator *enumerator;
134 NSAttributedString *attributedMessage = [[NSAttributedString alloc] initWithString:message
135 attributes:[[adium contentController] defaultFormattingAttributes]];
137 enumerator = [[[adium chatController] allChatsWithContact:contact] objectEnumerator];
138 while ((chat = [enumerator nextObject])) {
139 AIContentEvent *content;
141 //Create our content object
142 content = [AIContentEvent statusInChat:chat
144 destination:[chat account]
146 message:attributedMessage
150 [[adium contentController] receiveContentObject:content];
153 [attributedMessage release];