Commit 04cb7d2a authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: split crash log handling both from VLCMain and the Main Menu nib file

parent 35deef06
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
7D8BB0B21830244B00FAE9B7 /* CrashReporter.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D8BB0B01830244B00FAE9B7 /* CrashReporter.xib */; };
7DFFA16C16124F38001AF89F /* effects-one-button-pressed-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DFFA16A16124F38001AF89F /* effects-one-button-pressed-dark.png */; }; 7DFFA16C16124F38001AF89F /* effects-one-button-pressed-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DFFA16A16124F38001AF89F /* effects-one-button-pressed-dark.png */; };
7DFFA16D16124F38001AF89F /* effects-one-button-pressed-dark@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DFFA16B16124F38001AF89F /* effects-one-button-pressed-dark@2x.png */; }; 7DFFA16D16124F38001AF89F /* effects-one-button-pressed-dark@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DFFA16B16124F38001AF89F /* effects-one-button-pressed-dark@2x.png */; };
CC04323D13B246DF00D7D52E /* effects-double-buttons_dark.png in Resources */ = {isa = PBXBuildFile; fileRef = CC04321313B246DF00D7D52E /* effects-double-buttons_dark.png */; }; CC04323D13B246DF00D7D52E /* effects-double-buttons_dark.png in Resources */ = {isa = PBXBuildFile; fileRef = CC04321313B246DF00D7D52E /* effects-double-buttons_dark.png */; };
...@@ -465,7 +466,10 @@ ...@@ -465,7 +466,10 @@
5CCED71314C0D4A90057F8D1 /* ExtensionsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ExtensionsManager.m; path = ../../../modules/gui/macosx/ExtensionsManager.m; sourceTree = SOURCE_ROOT; }; 5CCED71314C0D4A90057F8D1 /* ExtensionsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ExtensionsManager.m; path = ../../../modules/gui/macosx/ExtensionsManager.m; sourceTree = SOURCE_ROOT; };
5CCED71414C0D4A90057F8D1 /* VLCUIWidgets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCUIWidgets.h; path = ../../../modules/gui/macosx/VLCUIWidgets.h; sourceTree = SOURCE_ROOT; }; 5CCED71414C0D4A90057F8D1 /* VLCUIWidgets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCUIWidgets.h; path = ../../../modules/gui/macosx/VLCUIWidgets.h; sourceTree = SOURCE_ROOT; };
5CCED71514C0D4A90057F8D1 /* VLCUIWidgets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCUIWidgets.m; path = ../../../modules/gui/macosx/VLCUIWidgets.m; sourceTree = SOURCE_ROOT; }; 5CCED71514C0D4A90057F8D1 /* VLCUIWidgets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCUIWidgets.m; path = ../../../modules/gui/macosx/VLCUIWidgets.m; sourceTree = SOURCE_ROOT; };
7D5B7B1F182FDA0300DB4869 /* CrashReporter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CrashReporter.h; path = ../../../modules/gui/macosx/CrashReporter.h; sourceTree = "<group>"; };
7D5B7B20182FDA0300DB4869 /* CrashReporter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CrashReporter.m; path = ../../../modules/gui/macosx/CrashReporter.m; sourceTree = "<group>"; };
7D7DC2CA182E86D9008C9E3E /* darwinvlc.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = darwinvlc.c; path = ../../../bin/darwinvlc.c; sourceTree = "<group>"; }; 7D7DC2CA182E86D9008C9E3E /* darwinvlc.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = darwinvlc.c; path = ../../../bin/darwinvlc.c; sourceTree = "<group>"; };
7D8BB0B11830244B00FAE9B7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Resources/English.lproj/CrashReporter.xib; sourceTree = "<group>"; };
7DFFA16A16124F38001AF89F /* effects-one-button-pressed-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "effects-one-button-pressed-dark.png"; path = "Resources/mainwindow_dark/effects-one-button-pressed-dark.png"; sourceTree = "<group>"; }; 7DFFA16A16124F38001AF89F /* effects-one-button-pressed-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "effects-one-button-pressed-dark.png"; path = "Resources/mainwindow_dark/effects-one-button-pressed-dark.png"; sourceTree = "<group>"; };
7DFFA16B16124F38001AF89F /* effects-one-button-pressed-dark@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "effects-one-button-pressed-dark@2x.png"; path = "Resources/mainwindow_dark/effects-one-button-pressed-dark@2x.png"; sourceTree = "<group>"; }; 7DFFA16B16124F38001AF89F /* effects-one-button-pressed-dark@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "effects-one-button-pressed-dark@2x.png"; path = "Resources/mainwindow_dark/effects-one-button-pressed-dark@2x.png"; sourceTree = "<group>"; };
8E49720006417F6800370C9F /* playlistinfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = playlistinfo.h; path = ../../../modules/gui/macosx/playlistinfo.h; sourceTree = SOURCE_ROOT; }; 8E49720006417F6800370C9F /* playlistinfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = playlistinfo.h; path = ../../../modules/gui/macosx/playlistinfo.h; sourceTree = SOURCE_ROOT; };
...@@ -1061,6 +1065,8 @@ ...@@ -1061,6 +1065,8 @@
8ED6C27E03E2EB1C0059A3A7 /* macosx.m */, 8ED6C27E03E2EB1C0059A3A7 /* macosx.m */,
8ED6C27C03E2EB1C0059A3A7 /* intf.h */, 8ED6C27C03E2EB1C0059A3A7 /* intf.h */,
8ED6C27D03E2EB1C0059A3A7 /* intf.m */, 8ED6C27D03E2EB1C0059A3A7 /* intf.m */,
7D5B7B1F182FDA0300DB4869 /* CrashReporter.h */,
7D5B7B20182FDA0300DB4869 /* CrashReporter.m */,
CC448A5A13B61D49009F72E0 /* MainMenu.h */, CC448A5A13B61D49009F72E0 /* MainMenu.h */,
CC448A5B13B61D49009F72E0 /* MainMenu.m */, CC448A5B13B61D49009F72E0 /* MainMenu.m */,
CC448A6013B68A0B009F72E0 /* CoreInteraction.h */, CC448A6013B68A0B009F72E0 /* CoreInteraction.h */,
...@@ -1776,6 +1782,7 @@ ...@@ -1776,6 +1782,7 @@
CCD83E2B13FE9B90004F1652 /* MainMenu.xib */, CCD83E2B13FE9B90004F1652 /* MainMenu.xib */,
CC0663371566CD5A003A411C /* ConvertAndSave.xib */, CC0663371566CD5A003A411C /* ConvertAndSave.xib */,
CC461F73160084A10022423C /* SharedDialogs.xib */, CC461F73160084A10022423C /* SharedDialogs.xib */,
7D8BB0B01830244B00FAE9B7 /* CrashReporter.xib */,
); );
name = xibs; name = xibs;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -2228,6 +2235,7 @@ ...@@ -2228,6 +2235,7 @@
CC166FE115F5136B0088201B /* previous-6btns-dark-pressed.png in Resources */, CC166FE115F5136B0088201B /* previous-6btns-dark-pressed.png in Resources */,
CC166FE215F5136B0088201B /* previous-6btns-dark-pressed@2x.png in Resources */, CC166FE215F5136B0088201B /* previous-6btns-dark-pressed@2x.png in Resources */,
CC166FE315F5136B0088201B /* previous-6btns-dark.png in Resources */, CC166FE315F5136B0088201B /* previous-6btns-dark.png in Resources */,
7D8BB0B21830244B00FAE9B7 /* CrashReporter.xib in Resources */,
CC166FE415F5136B0088201B /* previous-6btns-dark@2x.png in Resources */, CC166FE415F5136B0088201B /* previous-6btns-dark@2x.png in Resources */,
CC166FE915F517660088201B /* backward-6btns-pressed.png in Resources */, CC166FE915F517660088201B /* backward-6btns-pressed.png in Resources */,
CC166FEA15F517660088201B /* backward-6btns-pressed@2x.png in Resources */, CC166FEA15F517660088201B /* backward-6btns-pressed@2x.png in Resources */,
...@@ -2257,6 +2265,14 @@ ...@@ -2257,6 +2265,14 @@
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXVariantGroup section */ /* Begin PBXVariantGroup section */
7D8BB0B01830244B00FAE9B7 /* CrashReporter.xib */ = {
isa = PBXVariantGroup;
children = (
7D8BB0B11830244B00FAE9B7 /* English */,
);
name = CrashReporter.xib;
sourceTree = "<group>";
};
CC0663371566CD5A003A411C /* ConvertAndSave.xib */ = { CC0663371566CD5A003A411C /* ConvertAndSave.xib */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (
......
/*****************************************************************************
* CrashReporter.h: Mac OS X interface crash reporter
*****************************************************************************
* Copyright (C) 2009-2013 VLC authors and VideoLAN
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne at videolan dot org>
* Pierre d'Herbemont <pdherbemont # 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>
@class VLCCrashReporter;
@protocol VLCCrashReporterDelegate <NSObject>
@required
- (void)reporterFinishedAction:(VLCCrashReporter *)reporter;
@end
@interface VLCCrashReporter : NSObject
{
IBOutlet NSButton * _crashrep_dontSend_btn;
IBOutlet NSButton * _crashrep_send_btn;
IBOutlet NSTextView * _crashrep_fld;
IBOutlet NSTextField * _crashrep_title_txt;
IBOutlet NSTextField * _crashrep_desc_txt;
IBOutlet NSWindow * _crashrep_win;
IBOutlet NSButton * _crashrep_includeEmail_ckb;
IBOutlet NSButton * _crashrep_dontaskagain_ckb;
IBOutlet NSTextField * _crashrep_includeEmail_txt;
NSURLConnection * _crashLogURLConnection;
}
+ (VLCCrashReporter *)sharedInstance;
@property (retain) id delegate;
- (void)showDialogAndSendLogIfDesired;
- (IBAction)buttonAction:(id)sender;
@end
/*****************************************************************************
* CrashReporter.h: Mac OS X interface crash reporter
*****************************************************************************
* Copyright (C) 2009-2013 VLC authors and VideoLAN
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne at videolan dot org>
* Pierre d'Herbemont <pdherbemont # 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 "CrashReporter.h"
#import "intf.h"
#import <AddressBook/AddressBook.h>
@implementation VLCCrashReporter
#pragma mark - init
static VLCCrashReporter *_sharedMainInstance = nil;
+ (VLCCrashReporter *)sharedInstance
{
return _sharedMainInstance ? _sharedMainInstance : [[self alloc] init];
}
- (id)init
{
if (_sharedMainInstance)
[self dealloc];
else
_sharedMainInstance = [super init];
return _sharedMainInstance;
}
- (void)awakeFromNib
{
[_crashrep_send_btn setTitle: _NS("Send")];
[_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
[_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
[_crashrep_win setTitle: _NS("VLC crashed previously")];
[_crashrep_desc_txt setStringValue: _NS("Do you want to send details on the crash to VLC's development team?\n\nIf you want, you can enter a few lines on what you did before VLC crashed along with other helpful information: a link to download a sample file, a URL of a network stream, ...")];
[_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
[_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
[_crashrep_dontaskagain_ckb setTitle: _NS("Don't ask again")];
}
- (void)dealloc
{
[_crashLogURLConnection cancel];
[_crashLogURLConnection release];
[super dealloc];
}
#pragma mark - inter-object services
- (NSString *)_latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
{
NSString * crashReporter;
if (OSX_MOUNTAIN_LION || OSX_MAVERICKS)
crashReporter = [@"~/Library/Logs/DiagnosticReports" stringByExpandingTildeInPath];
else
crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
NSString *fname;
NSString * latestLog = nil;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
int year = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportYear"] : 0;
int month = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportMonth"]: 0;
int day = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportDay"] : 0;
int hours = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportHours"]: 0;
while (fname = [direnum nextObject]) {
[direnum skipDescendents];
if ([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"]) {
NSArray * compo = [fname componentsSeparatedByString:@"_"];
if ([compo count] < 3)
continue;
compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
if ([compo count] < 4)
continue;
// Dooh. ugly.
if (year < [[compo objectAtIndex:0] intValue] ||
(year ==[[compo objectAtIndex:0] intValue] &&
(month < [[compo objectAtIndex:1] intValue] ||
(month ==[[compo objectAtIndex:1] intValue] &&
(day < [[compo objectAtIndex:2] intValue] ||
(day ==[[compo objectAtIndex:2] intValue] &&
hours < [[compo objectAtIndex:3] intValue])))))) {
year = [[compo objectAtIndex:0] intValue];
month = [[compo objectAtIndex:1] intValue];
day = [[compo objectAtIndex:2] intValue];
hours = [[compo objectAtIndex:3] intValue];
latestLog = [crashReporter stringByAppendingPathComponent:fname];
}
}
}
if (!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
return nil;
if (!previouslySeen) {
[defaults setInteger:year forKey:@"LatestCrashReportYear"];
[defaults setInteger:month forKey:@"LatestCrashReportMonth"];
[defaults setInteger:day forKey:@"LatestCrashReportDay"];
[defaults setInteger:hours forKey:@"LatestCrashReportHours"];
}
return latestLog;
}
- (NSString *)_latestCrashLogPath
{
return [self _latestCrashLogPathPreviouslySeen:YES];
}
- (void)showDialogAndSendLogIfDesired
{
// This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
BOOL areCrashLogsTooOld = ![defaults integerForKey:@"LatestCrashReportYear"];
NSString * latestLog = [self _latestCrashLogPathPreviouslySeen:NO];
if (latestLog && !areCrashLogsTooOld) {
if ([defaults integerForKey:@"AlwaysSendCrashReports"] > 0)
[self _sendCrashLog:[NSString stringWithContentsOfFile: [self _latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [_crashrep_fld string]];
else if ([defaults integerForKey:@"AlwaysSendCrashReports"] == 0) {
[NSBundle loadNibNamed:@"CrashReporter" owner:self];
[NSApp runModalForWindow:_crashrep_win];
} else {
if ([self.delegate respondsToSelector: @selector(reporterFinishedAction:)])
[self.delegate reporterFinishedAction: self];
}
}
}
#pragma mark - UI interaction
- (IBAction)buttonAction:(id)sender
{
[NSApp stopModal];
[_crashrep_win orderOut: sender];
if (sender == _crashrep_send_btn) {
[self _sendCrashLog:[NSString stringWithContentsOfFile: [self _latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [_crashrep_fld string]];
if ([_crashrep_dontaskagain_ckb state])
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AlwaysSendCrashReports"];
} else {
if ([_crashrep_dontaskagain_ckb state])
[[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:@"AlwaysSendCrashReports"];
if ([self.delegate respondsToSelector: @selector(reporterFinishedAction:)])
[self.delegate reporterFinishedAction: self];
}
}
#pragma mark - network handling
- (void)_sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
{
NSString *urlStr = @"http://crash.videolan.org/crashlog/sendcrashreport.php";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
NSString * email;
if ([_crashrep_includeEmail_ckb state] == NSOnState) {
ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
email = [emails valueAtIndex:[emails indexForIdentifier:
[emails primaryIdentifier]]];
}
else
email = [NSString string];
NSString *postBody;
postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
[crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
/* Released from delegate */
_crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
msg_Dbg(VLCIntf, "crash report successfully sent");
[_crashLogURLConnection release];
_crashLogURLConnection = nil;
if ([self.delegate respondsToSelector: @selector(reporterFinishedAction:)])
[self.delegate reporterFinishedAction: self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
msg_Warn(VLCIntf, "Error when sending the crash report: %s (%li)", [[error localizedDescription] UTF8String], [error code]);
[_crashLogURLConnection release];
_crashLogURLConnection = nil;
if ([self.delegate respondsToSelector: @selector(reporterFinishedAction:)])
[self.delegate reporterFinishedAction: self];
}
@end
...@@ -83,5 +83,7 @@ SOURCES_macosx = \ ...@@ -83,5 +83,7 @@ SOURCES_macosx = \
ControlsBar.h \ ControlsBar.h \
VLCVoutWindowController.m \ VLCVoutWindowController.m \
VLCVoutWindowController.h \ VLCVoutWindowController.h \
CrashReporter.m \
CrashReporter.h \
iTunes.h \ iTunes.h \
$(NULL) $(NULL)
...@@ -115,23 +115,10 @@ struct intf_sys_t ...@@ -115,23 +115,10 @@ struct intf_sys_t
NSMutableArray * o_msg_arr; /* messages array */ NSMutableArray * o_msg_arr; /* messages array */
NSLock * o_msg_lock; /* messages lock */ NSLock * o_msg_lock; /* messages lock */
BOOL b_msg_arr_changed; /* did the array change? */ BOOL b_msg_arr_changed; /* did the array change? */
IBOutlet NSButton * o_msgs_crashlog_btn; /* messages open crashlog */
IBOutlet NSButton * o_msgs_save_btn; /* save the log as rtf */ IBOutlet NSButton * o_msgs_save_btn; /* save the log as rtf */
IBOutlet NSButton * o_msgs_refresh_btn; /* update the panel */ IBOutlet NSButton * o_msgs_refresh_btn; /* update the panel */
IBOutlet id o_msgs_table; IBOutlet id o_msgs_table;
/* CrashReporter panel */
IBOutlet NSButton * o_crashrep_dontSend_btn;
IBOutlet NSButton * o_crashrep_send_btn;
IBOutlet NSTextView * o_crashrep_fld;
IBOutlet NSTextField * o_crashrep_title_txt;
IBOutlet NSTextField * o_crashrep_desc_txt;
IBOutlet NSWindow * o_crashrep_win;
IBOutlet NSButton * o_crashrep_includeEmail_ckb;
IBOutlet NSButton * o_crashrep_dontaskagain_ckb;
IBOutlet NSTextField * o_crashrep_includeEmail_txt;
NSURLConnection * crashLogURLConnection;
AppleRemote * o_remote; AppleRemote * o_remote;
BOOL b_remote_button_hold; /* true as long as the user holds the left,right,plus or minus on the remote control */ BOOL b_remote_button_hold; /* true as long as the user holds the left,right,plus or minus on the remote control */
...@@ -200,8 +187,6 @@ struct intf_sys_t ...@@ -200,8 +187,6 @@ struct intf_sys_t
- (void)updateDelays; - (void)updateDelays;
- (void)initStrings; - (void)initStrings;
- (IBAction)crashReporterAction:(id)sender;
- (IBAction)openCrashLog:(id)sender;
- (IBAction)saveDebugLog:(id)sender; - (IBAction)saveDebugLog:(id)sender;
- (IBAction)showMessagesPanel:(id)sender; - (IBAction)showMessagesPanel:(id)sender;
- (IBAction)updateMessagesPanel:(id)sender; - (IBAction)updateMessagesPanel:(id)sender;
......
...@@ -64,11 +64,11 @@ ...@@ -64,11 +64,11 @@
#import "TrackSynchronization.h" #import "TrackSynchronization.h"
#import "VLCVoutWindowController.h" #import "VLCVoutWindowController.h"
#import "ExtensionsManager.h" #import "ExtensionsManager.h"
#import "CrashReporter.h"
#import "VideoEffects.h" #import "VideoEffects.h"
#import "AudioEffects.h" #import "AudioEffects.h"
#import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
#import <Sparkle/Sparkle.h> /* we're the update delegate */ #import <Sparkle/Sparkle.h> /* we're the update delegate */
#import "iTunes.h" #import "iTunes.h"
...@@ -618,7 +618,7 @@ audio_output_t *getAout(void) ...@@ -618,7 +618,7 @@ audio_output_t *getAout(void)
#pragma mark - #pragma mark -
#pragma mark Private #pragma mark Private
@interface VLCMain () @interface VLCMain () <VLCCrashReporterDelegate>
- (void)removeOldPreferences; - (void)removeOldPreferences;
@end @end
...@@ -815,7 +815,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -815,7 +815,7 @@ static VLCMain *_o_sharedMainInstance = nil;
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:) [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
name:NSWorkspaceWillSleepNotification object:nil]; name:NSWorkspaceWillSleepNotification object:nil];
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(lookForCrashLog) withObject:nil waitUntilDone:NO]; [self performSelector:@selector(lookForCrashLog) withObject:nil afterDelay:1.5];
/* we will need this, so let's load it here so the interface appears to be more responsive */ /* we will need this, so let's load it here so the interface appears to be more responsive */
nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp]; nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
...@@ -840,18 +840,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -840,18 +840,7 @@ static VLCMain *_o_sharedMainInstance = nil;
/* messages panel */ /* messages panel */
[o_msgs_panel setTitle: _NS("Messages")]; [o_msgs_panel setTitle: _NS("Messages")];
[o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
[o_msgs_save_btn setTitle: _NS("Save this Log...")]; [o_msgs_save_btn setTitle: _NS("Save this Log...")];
/* crash reporter panel */
[o_crashrep_send_btn setTitle: _NS("Send")];
[o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
[o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
[o_crashrep_win setTitle: _NS("VLC crashed previously")];
[o_crashrep_desc_txt setStringValue: _NS("Do you want to send details on the crash to VLC's development team?\n\nIf you want, you can enter a few lines on what you did before VLC crashed along with other helpful information: a link to download a sample file, a URL of a network stream, ...")];
[o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
[o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
[o_crashrep_dontaskagain_ckb setTitle: _NS("Don't ask again")];
} }
#pragma mark - #pragma mark -
...@@ -949,9 +938,6 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -949,9 +938,6 @@ static VLCMain *_o_sharedMainInstance = nil;
if (o_wizard) if (o_wizard)
[o_wizard release]; [o_wizard release];
[crashLogURLConnection cancel];
[crashLogURLConnection release];
[o_coredialogs release]; [o_coredialogs release];
[o_eyetv release]; [o_eyetv release];
...@@ -1730,152 +1716,18 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -1730,152 +1716,18 @@ static VLCMain *_o_sharedMainInstance = nil;
} }
#pragma mark - #pragma mark -
#pragma mark Crash Log #pragma mark Crash Log handling
- (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
{
NSString *urlStr = @"http://crash.videolan.org/crashlog/sendcrashreport.php";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
NSString * email;
if ([o_crashrep_includeEmail_ckb state] == NSOnState) {
ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
email = [emails valueAtIndex:[emails indexForIdentifier:
[emails primaryIdentifier]]];
}
else
email = [NSString string];
NSString *postBody;
postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
[crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
/* Released from delegate */
crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
msg_Dbg(p_intf, "crash report successfully sent");
[crashLogURLConnection release];
crashLogURLConnection = nil;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
msg_Warn (p_intf, "Error when sending the crash report: %s (%li)", [[error localizedDescription] UTF8String], [error code]);
[crashLogURLConnection release];
crashLogURLConnection = nil;
}
- (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
{
NSString * crashReporter;
if (OSX_MOUNTAIN_LION || OSX_MAVERICKS)
crashReporter = [@"~/Library/Logs/DiagnosticReports" stringByExpandingTildeInPath];
else
crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
NSString *fname;
NSString * latestLog = nil;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
int year = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportYear"] : 0;
int month = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportMonth"]: 0;
int day = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportDay"] : 0;
int hours = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportHours"]: 0;
while (fname = [direnum nextObject]) {
[direnum skipDescendents];
if ([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"]) {
NSArray * compo = [fname componentsSeparatedByString:@"_"];
if ([compo count] < 3)
continue;
compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
if ([compo count] < 4)
continue;
// Dooh. ugly.
if (year < [[compo objectAtIndex:0] intValue] ||
(year ==[[compo objectAtIndex:0] intValue] &&
(month < [[compo objectAtIndex:1] intValue] ||
(month ==[[compo objectAtIndex:1] intValue] &&
(day < [[compo objectAtIndex:2] intValue] ||
(day ==[[compo objectAtIndex:2] intValue] &&
hours < [[compo objectAtIndex:3] intValue])))))) {
year = [[compo objectAtIndex:0] intValue];
month = [[compo objectAtIndex:1] intValue];
day = [[compo objectAtIndex:2] intValue];
hours = [[compo objectAtIndex:3] intValue];
latestLog = [crashReporter stringByAppendingPathComponent:fname];
}
}
}
if (!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
return nil;
if (!previouslySeen) {
[defaults setInteger:year forKey:@"LatestCrashReportYear"];
[defaults setInteger:month forKey:@"LatestCrashReportMonth"];
[defaults setInteger:day forKey:@"LatestCrashReportDay"];
[defaults setInteger:hours forKey:@"LatestCrashReportHours"];
}
return latestLog;
}
- (NSString *)latestCrashLogPath
{
return [self latestCrashLogPathPreviouslySeen:YES];
}
- (void)lookForCrashLog - (void)lookForCrashLog
{ {
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; VLCCrashReporter *reporter = [[VLCCrashReporter alloc] init];
// This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version reporter.delegate = self;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; [reporter showDialogAndSendLogIfDesired];
BOOL areCrashLogsTooOld = ![defaults integerForKey:@"LatestCrashReportYear"];
NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
if (latestLog && !areCrashLogsTooOld) {
if ([defaults integerForKey:@"AlwaysSendCrashReports"] > 0)
[self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
else if ([defaults integerForKey:@"AlwaysSendCrashReports"] == 0)
[NSApp runModalForWindow: o_crashrep_win];
// bail out, the user doesn't want us to send reports
}
[o_pool release];
}
- (IBAction)crashReporterAction:(id)sender
{
if (sender == o_crashrep_send_btn) {
[self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
if ([o_crashrep_dontaskagain_ckb state])
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AlwaysSendCrashReports"];
} else {
if ([o_crashrep_dontaskagain_ckb state])
[[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:@"AlwaysSendCrashReports"];
}
[NSApp stopModal];
[o_crashrep_win orderOut: sender];
} }
- (IBAction)openCrashLog:(id)sender - (void)reporterFinishedAction:(VLCCrashReporter *)reporter
{ {
NSString * latestLog = [self latestCrashLogPath]; [reporter release];
if (latestLog) {
[[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
} else {
NSBeginInformationalAlertSheet(_NS("No CrashLog found"), _NS("Continue"), nil, nil, o_msgs_panel, self, NULL, NULL, nil, @"%@", _NS("Couldn't find any trace of a previous crash."));
}
} }
#pragma mark - #pragma mark -
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment