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 "ESDebugController.h"
18 #import "ESDebugWindowController.h"
19 #import <Adium/AIPreferenceControllerProtocol.h>
20 #import <AIUtilities/AIAutoScrollView.h>
22 #define KEY_DEBUG_WINDOW_FRAME @"Debug Window Frame"
23 #define DEBUG_WINDOW_NIB @"DebugWindow"
25 @implementation ESDebugWindowController
28 static ESDebugWindowController *sharedDebugWindowInstance = nil;
30 //Return the shared contact info window
34 if (!sharedDebugWindowInstance) {
35 sharedDebugWindowInstance = [[self alloc] initWithWindowNibName:DEBUG_WINDOW_NIB];
38 //Configure and show window
39 [sharedDebugWindowInstance showWindow:nil];
41 return sharedDebugWindowInstance;
44 + (BOOL)debugWindowIsOpen
46 return sharedDebugWindowInstance != nil;
51 NSEnumerator *enumerator = [fullDebugLogArray objectEnumerator];
52 NSString *aDebugString;
54 [mutableDebugString setString:@""];
55 while ((aDebugString = [enumerator nextObject])) {
57 [aDebugString rangeOfString:filter options:NSCaseInsensitiveSearch].location != NSNotFound) {
58 [mutableDebugString appendString:aDebugString];
63 [[textView_debug textStorage] addAttribute:NSParagraphStyleAttributeName
64 value:debugParagraphStyle
65 range:NSMakeRange(0, [mutableDebugString length])];
67 // [fullDebugLogArray removeAllObjects];
69 // [[adium debugController] clearDebugLogArray];
71 [scrollView_debug scrollToBottom];
74 - (void)addedDebugMessage:(NSString *)aDebugString
76 [fullDebugLogArray addObject:aDebugString];
79 [aDebugString rangeOfString:filter options:NSCaseInsensitiveSearch].location != NSNotFound) {
80 unsigned int aDebugStringLength = [aDebugString length];
82 [mutableDebugString appendString:aDebugString];
84 [[textView_debug textStorage] addAttribute:NSParagraphStyleAttributeName
85 value:debugParagraphStyle
86 range:NSMakeRange([mutableDebugString length] - aDebugStringLength, aDebugStringLength)];
89 + (void)addedDebugMessage:(NSString *)aDebugString
91 if (sharedDebugWindowInstance) [sharedDebugWindowInstance addedDebugMessage:aDebugString];
94 - (NSString *)adiumFrameAutosaveName
96 return KEY_DEBUG_WINDOW_FRAME;
99 //Setup the window before it is displayed
100 - (void)windowDidLoad
102 NSEnumerator *enumerator;
103 NSString *aDebugString;
105 [super windowDidLoad];
107 //We store the reference to the mutableString of the textStore for efficiency
108 mutableDebugString = [[[textView_debug textStorage] mutableString] retain];
109 fullDebugLogArray = [[NSMutableArray alloc] init];
111 debugParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
112 [debugParagraphStyle setHeadIndent:12];
113 [debugParagraphStyle setFirstLineHeadIndent:2];
115 [scrollView_debug setAutoScrollToBottom:YES];
117 //Load the logs which were added before the window was loaded
118 enumerator = [[[adium debugController] debugLogArray] objectEnumerator];
119 while ((aDebugString = [enumerator nextObject])) {
120 [mutableDebugString appendString:aDebugString];
121 if ((![aDebugString hasSuffix:@"\n"]) && (![aDebugString hasSuffix:@"\r"])) {
122 [mutableDebugString appendString:@"\n"];
124 [fullDebugLogArray addObject:aDebugString];
128 [[self window] setTitle:AILocalizedString(@"Adium Debug Log","Debug window title")];
129 [checkBox_logWriting setLocalizedString:AILocalizedString(@"Log to ~/Library/Logs/Adium Debug", "Logging checkbox in the Adium Debug Window")];
131 //On the next run loop, scroll to the bottom
132 [scrollView_debug performSelector:@selector(scrollToBottom)
136 [checkBox_logWriting setState:[[[adium preferenceController] preferenceForKey:KEY_DEBUG_WRITE_LOG
137 group:GROUP_DEBUG] boolValue]];
140 //Close the debug window
141 + (void)closeDebugWindow
143 if (sharedDebugWindowInstance) {
144 [sharedDebugWindowInstance closeWindow:nil];
148 //called as the window closes
149 - (void)windowWillClose:(id)sender
151 [super windowWillClose:sender];
154 [mutableDebugString release]; mutableDebugString = nil;
155 [fullDebugLogArray release]; fullDebugLogArray = nil;
156 [debugParagraphStyle release]; debugParagraphStyle = nil;
157 [self autorelease]; sharedDebugWindowInstance = nil;
160 - (IBAction)toggleLogWriting:(id)sender
162 [[adium preferenceController] setPreference:[NSNumber numberWithBool:[sender state]]
163 forKey:KEY_DEBUG_WRITE_LOG
167 - (IBAction)clearLog:(id)sender
169 [mutableDebugString setString:@""];
170 [fullDebugLogArray removeAllObjects];
172 [[adium debugController] clearDebugLogArray];
174 [scrollView_debug scrollToTop];
177 - (void)setFilter:(NSString *)inFilter
179 if (inFilter != filter) {
181 filter = [inFilter copy];
183 [self performFilter];