macosx: rename to VLCDebugMessageWindowController
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Mon, 8 Aug 2016 16:00:38 +0000 (18:00 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Mon, 8 Aug 2016 16:47:29 +0000 (18:47 +0200)
extras/package/macosx/Resources/English.lproj/DebugMessageVisualizer.xib
extras/package/macosx/vlc.xcodeproj/project.pbxproj
modules/gui/macosx/DebugMessageVisualizer.h [deleted file]
modules/gui/macosx/DebugMessageVisualizer.m [deleted file]
modules/gui/macosx/MainMenu.m
modules/gui/macosx/Makefile.am
modules/gui/macosx/VLCDebugMessageWindowController.h [new file with mode: 0644]
modules/gui/macosx/VLCDebugMessageWindowController.m [new file with mode: 0644]
modules/gui/macosx/intf.h
modules/gui/macosx/intf.m

index d29add9..f0982fd 100644 (file)
@@ -1,12 +1,11 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
-        <deployment identifier="macosx"/>
         <development version="7000" identifier="xcode"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="VLCDebugMessageVisualizer">
+        <customObject id="-2" userLabel="File's Owner" customClass="VLCDebugMessageWindowController">
             <connections>
                 <outlet property="clearButton" destination="RCj-GY-IGn" id="bi1-74-dyp"/>
                 <outlet property="messageTable" destination="6" id="BzW-Qh-PMq"/>
@@ -73,7 +72,7 @@
                             <color key="backgroundColor" name="controlDarkShadowColor" catalog="System" colorSpace="catalog"/>
                         </clipView>
                         <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="7">
-                            <rect key="frame" x="1" y="299.97265625" width="597.5" height="15"/>
+                            <rect key="frame" x="1" y="299.97265625" width="598" height="15"/>
                             <autoresizingMask key="autoresizingMask"/>
                         </scroller>
                         <scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="8">
index fba1faf..270d00c 100644 (file)
                1CCB5F651A62A724004C3E90 /* VLCCoreDialogProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = CC4A33210F8CB017000FC4A7 /* VLCCoreDialogProvider.m */; };
                1CCB5F661A62A724004C3E90 /* CoreInteraction.h in Sources */ = {isa = PBXBuildFile; fileRef = CC448A6013B68A0B009F72E0 /* CoreInteraction.h */; };
                1CCB5F671A62A724004C3E90 /* CoreInteraction.m in Sources */ = {isa = PBXBuildFile; fileRef = CC448A6113B68A0B009F72E0 /* CoreInteraction.m */; };
-               1CCB5F681A62A724004C3E90 /* DebugMessageVisualizer.h in Sources */ = {isa = PBXBuildFile; fileRef = 7D8BB0B318302AC000FAE9B7 /* DebugMessageVisualizer.h */; };
-               1CCB5F691A62A724004C3E90 /* DebugMessageVisualizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D8BB0B418302AC000FAE9B7 /* DebugMessageVisualizer.m */; };
+               1CCB5F681A62A724004C3E90 /* VLCDebugMessageWindowController.h in Sources */ = {isa = PBXBuildFile; fileRef = 7D8BB0B318302AC000FAE9B7 /* VLCDebugMessageWindowController.h */; };
+               1CCB5F691A62A724004C3E90 /* VLCDebugMessageWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D8BB0B418302AC000FAE9B7 /* VLCDebugMessageWindowController.m */; };
                1CCB5F6A1A62A724004C3E90 /* ExtensionsDialogProvider.h in Sources */ = {isa = PBXBuildFile; fileRef = 5CCED71014C0D4A90057F8D1 /* ExtensionsDialogProvider.h */; };
                1CCB5F6B1A62A724004C3E90 /* ExtensionsDialogProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 5CCED71114C0D4A90057F8D1 /* ExtensionsDialogProvider.m */; };
                1CCB5F6C1A62A724004C3E90 /* ExtensionsManager.h in Sources */ = {isa = PBXBuildFile; fileRef = 5CCED71214C0D4A90057F8D1 /* ExtensionsManager.h */; };
                7D871D371B5E6844000B56C0 /* intf-prefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "intf-prefs.h"; path = "../../../modules/gui/macosx/intf-prefs.h"; sourceTree = "<group>"; };
                7D871D381B5E6844000B56C0 /* intf-prefs.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "intf-prefs.m"; path = "../../../modules/gui/macosx/intf-prefs.m"; sourceTree = "<group>"; };
                7D871D391B5E684D000B56C0 /* helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = helpers.h; path = ../../../modules/gui/macosx/helpers.h; sourceTree = "<group>"; };
-               7D8BB0B318302AC000FAE9B7 /* DebugMessageVisualizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DebugMessageVisualizer.h; path = ../../../modules/gui/macosx/DebugMessageVisualizer.h; sourceTree = SOURCE_ROOT; };
-               7D8BB0B418302AC000FAE9B7 /* DebugMessageVisualizer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = DebugMessageVisualizer.m; path = ../../../modules/gui/macosx/DebugMessageVisualizer.m; sourceTree = SOURCE_ROOT; };
+               7D8BB0B318302AC000FAE9B7 /* VLCDebugMessageWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VLCDebugMessageWindowController.h; path = ../../../modules/gui/macosx/VLCDebugMessageWindowController.h; sourceTree = SOURCE_ROOT; };
+               7D8BB0B418302AC000FAE9B7 /* VLCDebugMessageWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = VLCDebugMessageWindowController.m; path = ../../../modules/gui/macosx/VLCDebugMessageWindowController.m; sourceTree = SOURCE_ROOT; };
                7D8BB0B61830311300FAE9B7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Resources/English.lproj/DebugMessageVisualizer.xib; sourceTree = "<group>"; };
                7D8BB0B91830367200FAE9B7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Resources/English.lproj/PlaylistMenu.xib; sourceTree = "<group>"; };
                7D8BB0BF1830393300FAE9B7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Resources/English.lproj/MainWindow.xib; sourceTree = "<group>"; };
                                CC4A33210F8CB017000FC4A7 /* VLCCoreDialogProvider.m */,
                                CC448A6013B68A0B009F72E0 /* CoreInteraction.h */,
                                CC448A6113B68A0B009F72E0 /* CoreInteraction.m */,
-                               7D8BB0B318302AC000FAE9B7 /* DebugMessageVisualizer.h */,
-                               7D8BB0B418302AC000FAE9B7 /* DebugMessageVisualizer.m */,
+                               7D8BB0B318302AC000FAE9B7 /* VLCDebugMessageWindowController.h */,
+                               7D8BB0B418302AC000FAE9B7 /* VLCDebugMessageWindowController.m */,
                                5CCED71014C0D4A90057F8D1 /* ExtensionsDialogProvider.h */,
                                5CCED71114C0D4A90057F8D1 /* ExtensionsDialogProvider.m */,
                                5CCED71214C0D4A90057F8D1 /* ExtensionsManager.h */,
                                1CCB5F661A62A724004C3E90 /* CoreInteraction.h in Sources */,
                                6BBBB8AA1D108A17001BD9BA /* VLCRendererDialog.m in Sources */,
                                1CCB5F671A62A724004C3E90 /* CoreInteraction.m in Sources */,
-                               1CCB5F681A62A724004C3E90 /* DebugMessageVisualizer.h in Sources */,
-                               1CCB5F691A62A724004C3E90 /* DebugMessageVisualizer.m in Sources */,
+                               1CCB5F681A62A724004C3E90 /* VLCDebugMessageWindowController.h in Sources */,
+                               1CCB5F691A62A724004C3E90 /* VLCDebugMessageWindowController.m in Sources */,
                                6B846FE51CF5D88C00112E54 /* VLCHUDCheckboxCell.m in Sources */,
                                1CCB5F6A1A62A724004C3E90 /* ExtensionsDialogProvider.h in Sources */,
                                7DBB06641CC2314D004C74D2 /* caopengllayer.m in Sources */,
diff --git a/modules/gui/macosx/DebugMessageVisualizer.h b/modules/gui/macosx/DebugMessageVisualizer.h
deleted file mode 100644 (file)
index 83bd570..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*****************************************************************************
- * DebugMessageVisualizer.h: Mac OS X interface crash reporter
- *****************************************************************************
- * Copyright (C) 2004-2013 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
- *          Pierre d'Herbemont <pdherbemont # videolan org>
- *          Derk-Jan Hartman <hartman at videolan.org>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#import <Cocoa/Cocoa.h>
-
-@interface VLCDebugMessageVisualizer : NSWindowController
-
-@property (assign) IBOutlet NSTableView *messageTable;
-@property (assign) IBOutlet NSButton *saveButton;
-@property (assign) IBOutlet NSButton *clearButton;
-@property (assign) IBOutlet NSButton *refreshButton;
-
-- (void)showWindow:(id)sender;
-
-- (IBAction)updateMessagesPanel:(id)sender;
-- (IBAction)saveDebugLog:(id)sender;
-- (IBAction)clearLog:(id)sender;
-
-@end
diff --git a/modules/gui/macosx/DebugMessageVisualizer.m b/modules/gui/macosx/DebugMessageVisualizer.m
deleted file mode 100644 (file)
index 348d1be..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*****************************************************************************
- * DebugMessageVisualizer.m: Mac OS X interface crash reporter
- *****************************************************************************
- * Copyright (C) 2004-2013 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
- *          Pierre d'Herbemont <pdherbemont # videolan org>
- *          Derk-Jan Hartman <hartman at videolan.org>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#import "DebugMessageVisualizer.h"
-#import "intf.h"
-#import <vlc_common.h>
-
-static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap);
-
-/*****************************************************************************
- * MsgCallback: Callback triggered by the core once a new debug message is
- * ready to be displayed. We store everything in a NSArray in our Cocoa part
- * of this file.
- *****************************************************************************/
-
-@interface VLCDebugMessageVisualizer () <NSWindowDelegate>
-{
-    NSMutableArray * _messageArray;
-}
-- (void)appendMessage:(NSMutableAttributedString *) message;
-
-@end
-
-static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap)
-{
-    @autoreleasepool {
-
-        VLCDebugMessageVisualizer *visualizer = (__bridge VLCDebugMessageVisualizer*)data;
-
-        int canc = vlc_savecancel();
-        char *str;
-        if (vasprintf(&str, format, ap) == -1) {
-            vlc_restorecancel(canc);
-            return;
-        }
-
-        if (!item->psz_module)
-            return;
-        if (!str)
-            return;
-
-        NSColor *_white = [NSColor whiteColor];
-        NSColor *_red = [NSColor redColor];
-        NSColor *_yellow = [NSColor yellowColor];
-        NSColor *_gray = [NSColor grayColor];
-
-        NSColor * pp_color[4] = { _white, _red, _yellow, _gray };
-        static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
-
-
-        NSString *firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[type]];
-        NSString *secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
-
-        NSDictionary *colorAttrib = [NSDictionary dictionaryWithObject: pp_color[type]  forKey: NSForegroundColorAttributeName];
-        NSMutableAttributedString *coloredMsg = [[NSMutableAttributedString alloc] initWithString: secondString attributes: colorAttrib];
-        colorAttrib = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
-        [coloredMsg setAttributes: colorAttrib range: NSMakeRange(0, [firstString length])];
-
-        [visualizer performSelectorOnMainThread:@selector(appendMessage:) withObject:coloredMsg waitUntilDone:NO];
-
-        vlc_restorecancel(canc);
-        free(str);
-    }
-}
-
-@implementation VLCDebugMessageVisualizer
-
-- (id)init
-{
-    self = [super initWithWindowNibName:@"DebugMessageVisualizer"];
-    if (self) {
-        _messageArray = [NSMutableArray arrayWithCapacity:600];
-    }
-    return self;
-}
-
-- (void)dealloc
-{
-    vlc_LogSet( getIntf()->obj.libvlc, NULL, NULL );
-}
-
-- (void)windowDidLoad
-{
-    [self.window setExcludedFromWindowsMenu: YES];
-    [self.window setDelegate: self];
-    [self.window setTitle: _NS("Messages")];
-    [_saveButton setTitle: _NS("Save this Log...")];
-    [_clearButton setTitle:_NS("Clear")];
-    [_refreshButton setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
-}
-
-#pragma mark - UI interaction
-
-- (void)showWindow:(id)sender
-{
-    /* subscribe to LibVLCCore's messages */
-    vlc_LogSet(getIntf()->obj.libvlc, MsgCallback, (__bridge void*)self);
-
-    [super showWindow:sender];
-}
-
-- (IBAction)updateMessagesPanel:(id)sender
-{
-    [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidBecomeKeyNotification object:self.window];
-}
-
-- (void)windowDidBecomeKey:(NSNotification *)notification
-{
-    [_messageTable reloadData];
-    [_messageTable scrollRowToVisible: [_messageArray count] - 1];
-}
-
-- (void)windowWillClose:(NSNotification *)notification
-{
-    /* unsubscribe from LibVLCCore's messages */
-    vlc_LogSet( getIntf()->obj.libvlc, NULL, NULL );
-    [_messageArray removeAllObjects];
-}
-
-- (IBAction)saveDebugLog:(id)sender
-{
-    NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
-
-    [saveFolderPanel setCanSelectHiddenExtension: NO];
-    [saveFolderPanel setCanCreateDirectories: YES];
-    [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"txt"]];
-    [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).txt"), VERSION_MESSAGE]];
-    [saveFolderPanel beginSheetModalForWindow: self.window completionHandler:^(NSInteger returnCode) {
-        if (returnCode == NSOKButton) {
-            NSUInteger count = [_messageArray count];
-            NSMutableString *string = [[NSMutableString alloc] init];
-            for (NSUInteger i = 0; i < count; i++)
-                [string appendString: [[_messageArray objectAtIndex:i] string]];
-
-            NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
-            if ([data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO)
-                msg_Warn(getIntf(), "Error while saving the debug log");
-        }
-    }];
-}
-
-- (IBAction)clearLog:(id)sender
-{
-    [_messageArray removeAllObjects];
-
-    // Reregister handler, to write new header to log
-    vlc_LogSet(getIntf()->obj.libvlc, NULL, NULL);
-    vlc_LogSet(getIntf()->obj.libvlc, MsgCallback, (__bridge void*)self);
-
-    [_messageTable reloadData];
-}
-
-#pragma mark - data handling
-
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
-{
-    return [_messageArray count];
-}
-
-- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
-{
-    return [_messageArray objectAtIndex:rowIndex];
-}
-
-- (void)appendMessage:(NSMutableAttributedString *) message
-{
-    if ([_messageArray count] > 1000000) {
-        [_messageArray removeObjectAtIndex: 0];
-        [_messageArray removeObjectAtIndex: 1];
-    }
-
-    [_messageArray addObject:message];
-}
-
-@end
index e04c39d..1c0f45d 100644 (file)
@@ -44,7 +44,7 @@
 #import "ControlsBar.h"
 #import "ExtensionsManager.h"
 #import "ConvertAndSave.h"
-#import "DebugMessageVisualizer.h"
+#import "VLCDebugMessageWindowController.h"
 #import "AddonsWindowController.h"
 #import "VLCTimeSelectionPanelController.h"
 #import "VLCRendererDialog.h"
index a7eaaaa..b6fb7dd 100644 (file)
@@ -31,7 +31,6 @@ libmacosx_plugin_la_SOURCES = \
        ControlsBar.m ControlsBar.h \
        ConvertAndSave.h ConvertAndSave.m \
        CoreInteraction.h CoreInteraction.m \
-       DebugMessageVisualizer.h DebugMessageVisualizer.m \
        ExtensionsDialogProvider.h ExtensionsDialogProvider.m \
        ExtensionsManager.h ExtensionsManager.m \
        fspanel.h fspanel.m \
@@ -72,6 +71,7 @@ libmacosx_plugin_la_SOURCES = \
        VLCAudioEffectsWindowController.h VLCAudioEffectsWindowController.m \
        VLCBookmarksWindowController.h VLCBookmarksWindowController.m \
        VLCCoreDialogProvider.h VLCCoreDialogProvider.m \
+       VLCDebugMessageWindowController.h VLCDebugMessageWindowController.m \
        VLCEyeTvController.h VLCEyeTvController.m \
        VLCHUDSliderCell.h VLCHUDSliderCell.m \
        VLCHUDButtonCell.h VLCHUDButtonCell.m \
diff --git a/modules/gui/macosx/VLCDebugMessageWindowController.h b/modules/gui/macosx/VLCDebugMessageWindowController.h
new file mode 100644 (file)
index 0000000..a06318d
--- /dev/null
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * VLCDebugMessageWindowController.m: Mac OS X interface crash reporter
+ *****************************************************************************
+ * Copyright (C) 2004-2013 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *          Pierre d'Herbemont <pdherbemont # videolan org>
+ *          Derk-Jan Hartman <hartman at videolan.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+@interface VLCDebugMessageWindowController : NSWindowController
+
+@property (assign) IBOutlet NSTableView *messageTable;
+@property (assign) IBOutlet NSButton *saveButton;
+@property (assign) IBOutlet NSButton *clearButton;
+@property (assign) IBOutlet NSButton *refreshButton;
+
+- (void)showWindow:(id)sender;
+
+- (IBAction)updateMessagesPanel:(id)sender;
+- (IBAction)saveDebugLog:(id)sender;
+- (IBAction)clearLog:(id)sender;
+
+@end
diff --git a/modules/gui/macosx/VLCDebugMessageWindowController.m b/modules/gui/macosx/VLCDebugMessageWindowController.m
new file mode 100644 (file)
index 0000000..c870c5c
--- /dev/null
@@ -0,0 +1,197 @@
+/*****************************************************************************
+ * VLCDebugMessageWindowController.m: Mac OS X interface crash reporter
+ *****************************************************************************
+ * Copyright (C) 2004-2013 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *          Pierre d'Herbemont <pdherbemont # videolan org>
+ *          Derk-Jan Hartman <hartman at videolan.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCDebugMessageWindowController.h"
+#import "intf.h"
+#import <vlc_common.h>
+
+static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap);
+
+/*****************************************************************************
+ * MsgCallback: Callback triggered by the core once a new debug message is
+ * ready to be displayed. We store everything in a NSArray in our Cocoa part
+ * of this file.
+ *****************************************************************************/
+
+@interface VLCDebugMessageWindowController () <NSWindowDelegate>
+{
+    NSMutableArray * _messageArray;
+}
+- (void)appendMessage:(NSMutableAttributedString *) message;
+
+@end
+
+static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap)
+{
+    @autoreleasepool {
+
+        VLCDebugMessageWindowController *visualizer = (__bridge VLCDebugMessageWindowController*)data;
+
+        int canc = vlc_savecancel();
+        char *str;
+        if (vasprintf(&str, format, ap) == -1) {
+            vlc_restorecancel(canc);
+            return;
+        }
+
+        if (!item->psz_module)
+            return;
+        if (!str)
+            return;
+
+        NSColor *_white = [NSColor whiteColor];
+        NSColor *_red = [NSColor redColor];
+        NSColor *_yellow = [NSColor yellowColor];
+        NSColor *_gray = [NSColor grayColor];
+
+        NSColor * pp_color[4] = { _white, _red, _yellow, _gray };
+        static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
+
+
+        NSString *firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[type]];
+        NSString *secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
+
+        NSDictionary *colorAttrib = [NSDictionary dictionaryWithObject: pp_color[type]  forKey: NSForegroundColorAttributeName];
+        NSMutableAttributedString *coloredMsg = [[NSMutableAttributedString alloc] initWithString: secondString attributes: colorAttrib];
+        colorAttrib = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
+        [coloredMsg setAttributes: colorAttrib range: NSMakeRange(0, [firstString length])];
+
+        [visualizer performSelectorOnMainThread:@selector(appendMessage:) withObject:coloredMsg waitUntilDone:NO];
+
+        vlc_restorecancel(canc);
+        free(str);
+    }
+}
+
+@implementation VLCDebugMessageWindowController
+
+- (id)init
+{
+    self = [super initWithWindowNibName:@"DebugMessageVisualizer"];
+    if (self) {
+        _messageArray = [NSMutableArray arrayWithCapacity:600];
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    vlc_LogSet( getIntf()->obj.libvlc, NULL, NULL );
+}
+
+- (void)windowDidLoad
+{
+    [self.window setExcludedFromWindowsMenu: YES];
+    [self.window setDelegate: self];
+    [self.window setTitle: _NS("Messages")];
+    [_saveButton setTitle: _NS("Save this Log...")];
+    [_clearButton setTitle:_NS("Clear")];
+    [_refreshButton setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
+}
+
+#pragma mark - UI interaction
+
+- (void)showWindow:(id)sender
+{
+    /* subscribe to LibVLCCore's messages */
+    vlc_LogSet(getIntf()->obj.libvlc, MsgCallback, (__bridge void*)self);
+
+    [super showWindow:sender];
+}
+
+- (IBAction)updateMessagesPanel:(id)sender
+{
+    [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidBecomeKeyNotification object:self.window];
+}
+
+- (void)windowDidBecomeKey:(NSNotification *)notification
+{
+    [_messageTable reloadData];
+    [_messageTable scrollRowToVisible: [_messageArray count] - 1];
+}
+
+- (void)windowWillClose:(NSNotification *)notification
+{
+    /* unsubscribe from LibVLCCore's messages */
+    vlc_LogSet( getIntf()->obj.libvlc, NULL, NULL );
+    [_messageArray removeAllObjects];
+}
+
+- (IBAction)saveDebugLog:(id)sender
+{
+    NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
+
+    [saveFolderPanel setCanSelectHiddenExtension: NO];
+    [saveFolderPanel setCanCreateDirectories: YES];
+    [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"txt"]];
+    [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).txt"), VERSION_MESSAGE]];
+    [saveFolderPanel beginSheetModalForWindow: self.window completionHandler:^(NSInteger returnCode) {
+        if (returnCode == NSOKButton) {
+            NSUInteger count = [_messageArray count];
+            NSMutableString *string = [[NSMutableString alloc] init];
+            for (NSUInteger i = 0; i < count; i++)
+                [string appendString: [[_messageArray objectAtIndex:i] string]];
+
+            NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
+            if ([data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO)
+                msg_Warn(getIntf(), "Error while saving the debug log");
+        }
+    }];
+}
+
+- (IBAction)clearLog:(id)sender
+{
+    [_messageArray removeAllObjects];
+
+    // Reregister handler, to write new header to log
+    vlc_LogSet(getIntf()->obj.libvlc, NULL, NULL);
+    vlc_LogSet(getIntf()->obj.libvlc, MsgCallback, (__bridge void*)self);
+
+    [_messageTable reloadData];
+}
+
+#pragma mark - data handling
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+    return [_messageArray count];
+}
+
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+    return [_messageArray objectAtIndex:rowIndex];
+}
+
+- (void)appendMessage:(NSMutableAttributedString *) message
+{
+    if ([_messageArray count] > 1000000) {
+        [_messageArray removeObjectAtIndex: 0];
+        [_messageArray removeObjectAtIndex: 1];
+    }
+
+    [_messageArray addObject:message];
+}
+
+@end
index 5c7ed33..9505bd8 100644 (file)
@@ -66,7 +66,7 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 @class VLCCoreDialogProvider;
 @class VLCBookmarksWindowController;
 @class VLCOpen;
-@class VLCDebugMessageVisualizer;
+@class VLCDebugMessageWindowController;
 @class VLCTrackSynchronizationWindowController;
 @class VLCAudioEffectsWindowController;
 @class VLCVideoEffectsWindowController;
@@ -97,7 +97,7 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 - (ExtensionsManager *)extensionsManager;
 - (VLCStatusBarIcon *)statusBarIcon;
 
-- (VLCDebugMessageVisualizer *)debugMsgPanel;
+- (VLCDebugMessageWindowController *)debugMsgPanel;
 
 - (VLCTrackSynchronizationWindowController *)trackSyncPanel;
 - (VLCAudioEffectsWindowController *)audioEffectsPanel;
index ea86317..e39cda9 100644 (file)
@@ -59,7 +59,7 @@
 #import "ExtensionsManager.h"
 #import "BWQuincyManager.h"
 #import "VLCResumeDialogController.h"
-#import "DebugMessageVisualizer.h"
+#import "VLCDebugMessageWindowController.h"
 #import "ConvertAndSave.h"
 
 #import "VLCVideoEffectsWindowController.h"
@@ -174,7 +174,7 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
     VLCResumeDialogController *_resume_dialog;
     VLCInputManager *_input_manager;
     VLCPlaylist *_playlist;
-    VLCDebugMessageVisualizer *_messagePanelController;
+    VLCDebugMessageWindowController *_messagePanelController;
     VLCStatusBarIcon *_statusBarIcon;
     VLCTrackSynchronizationWindowController *_trackSyncPanel;
     VLCAudioEffectsWindowController *_audioEffectsPanel;
@@ -536,10 +536,10 @@ static VLCMain *sharedInstance = nil;
     return _extensionsManager;
 }
 
-- (VLCDebugMessageVisualizer *)debugMsgPanel
+- (VLCDebugMessageWindowController *)debugMsgPanel
 {
     if (!_messagePanelController)
-        _messagePanelController = [[VLCDebugMessageVisualizer alloc] init];
+        _messagePanelController = [[VLCDebugMessageWindowController alloc] init];
 
     return _messagePanelController;
 }