-#pragma mark -
-#pragma mark Errors, warnings and messages
-- (IBAction)updateMessagesPanel:(id)sender
-{
- [self windowDidBecomeKey:nil];
-}
-
-- (IBAction)showMessagesPanel:(id)sender
-{
- [o_msgs_panel makeKeyAndOrderFront: sender];
-}
-
-- (void)windowDidBecomeKey:(NSNotification *)o_notification
-{
- [o_msgs_table reloadData];
- [o_msgs_table scrollRowToVisible: [o_msg_arr count] - 1];
-}
-
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
-{
- if (aTableView == o_msgs_table)
- return [o_msg_arr count];
- return 0;
-}
-
-- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
-{
- NSMutableAttributedString *result = NULL;
-
- [o_msg_lock lock];
- if (rowIndex < [o_msg_arr count])
- result = [o_msg_arr objectAtIndex: rowIndex];
- [o_msg_lock unlock];
-
- if (result != NULL)
- return result;
- else
- return @"";
-}
-
-- (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str
-{
- if (o_msg_arr) {
- NSColor *o_white = [NSColor whiteColor];
- NSColor *o_red = [NSColor redColor];
- NSColor *o_yellow = [NSColor yellowColor];
- NSColor *o_gray = [NSColor grayColor];
- NSString * firstString, * secondString;
-
- NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
- static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
-
- NSDictionary *o_attr;
- NSMutableAttributedString *o_msg_color;
-
- [o_msg_lock lock];
-
- if ([o_msg_arr count] > 600) {
- [o_msg_arr removeObjectAtIndex: 0];
- [o_msg_arr removeObjectAtIndex: 1];
- }
- firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[i_type]];
- secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
-
- o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
- o_msg_color = [[NSMutableAttributedString alloc] initWithString: secondString attributes: o_attr];
- o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
- [o_msg_color setAttributes: o_attr range: NSMakeRange(0, [firstString length])];
- [o_msg_arr addObject: [o_msg_color autorelease]];
-
- b_msg_arr_changed = YES;
- [o_msg_lock unlock];
- }
-}
-
-- (IBAction)saveDebugLog:(id)sender
-{
- NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
-
- [saveFolderPanel setCanSelectHiddenExtension: NO];
- [saveFolderPanel setCanCreateDirectories: YES];
- [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"rtf"]];
- [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).rtf"), VERSION_MESSAGE]];
- [saveFolderPanel beginSheetModalForWindow: o_msgs_panel completionHandler:^(NSInteger returnCode) {
- if (returnCode == NSOKButton) {
- NSUInteger count = [o_msg_arr count];
- NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
- for (NSUInteger i = 0; i < count; i++)
- [string appendAttributedString: [o_msg_arr objectAtIndex: i]];
-
- NSData *data = [string RTFFromRange:NSMakeRange(0, [string length])
- documentAttributes:[NSDictionary dictionaryWithObject: NSRTFTextDocumentType forKey: NSDocumentTypeDocumentAttribute]];
-
- if ([data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO)
- msg_Warn(p_intf, "Error while saving the debug log");
-
- [string release];
- }
- }];
- [saveFolderPanel release];
-}
-