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_BEGAN
55 [[adium notificationCenter] addObserver:self
56 selector:@selector(handleFileTransferEvent:)
57 name:FILE_TRANSFER_FAILED
64 - (void)uninstallPlugin
66 [[adium notificationCenter] removeObserver:self];
70 * @brief A file transfer event occurred
72 - (void)handleFileTransferEvent:(NSNotification *)notification
74 ESFileTransfer *fileTransfer = (ESFileTransfer *)[notification userInfo];
75 AIListContact *listContact = [notification object];
76 NSString *notificationName = [notification name];
79 if (!(filename = [[fileTransfer localFilename] lastPathComponent])) {
80 filename = [[fileTransfer remoteFilename] lastPathComponent];
84 NSString *message = nil;
87 if ([notificationName isEqualToString:FILE_TRANSFER_CANCELLED]) {
88 type = @"fileTransferAborted";
89 message = [NSString stringWithFormat:AILocalizedString(@"%@ cancelled the transfer of %@",nil),[listContact formattedUID],filename];
91 } else if ([notificationName isEqualToString:FILE_TRANSFER_FAILED]) {
92 type = @"fileTransferAborted";
93 message = [NSString stringWithFormat:AILocalizedString(@"The transfer of %@ failed",nil),filename];
94 }else if ([notificationName isEqualToString:FILE_TRANSFER_COMPLETE]) {
95 type = @"fileTransferCompleted";
96 if ([fileTransfer fileTransferType] == Incoming_FileTransfer) {
97 message = [NSString stringWithFormat:AILocalizedString(@"Successfully received %@",nil),filename];
99 message = [NSString stringWithFormat:AILocalizedString(@"Successfully sent %@",nil),filename];
102 } else if ([notificationName isEqualToString:FILE_TRANSFER_BEGAN]) {
103 type = @"fileTransferStarted";
104 if ([fileTransfer fileTransferType] == Incoming_FileTransfer) {
105 message = [NSString stringWithFormat:AILocalizedString(@"Began receiving %@",nil),filename];
107 message = [NSString stringWithFormat:AILocalizedString(@"Began sending %@",nil),filename];
111 [self statusMessage:message forContact:listContact withType:type];
116 * @brief Post a status message on all active chats for this object
118 - (void)statusMessage:(NSString *)message forContact:(AIListContact *)contact withType:(NSString *)type
120 NSEnumerator *enumerator;
122 NSAttributedString *attributedMessage = [[NSAttributedString alloc] initWithString:message
123 attributes:[[adium contentController] defaultFormattingAttributes]];
125 enumerator = [[[adium chatController] allChatsWithContact:contact] objectEnumerator];
126 while ((chat = [enumerator nextObject])) {
127 AIContentEvent *content;
129 //Create our content object
130 content = [AIContentEvent statusInChat:chat
132 destination:[chat account]
134 message:attributedMessage
138 [[adium contentController] receiveContentObject:content];
141 [attributedMessage release];