Subbed Kdb3 Entry attachment handling.

This commit is contained in:
michael starke
2013-07-19 22:45:04 +02:00
parent efa727eaba
commit 86d983f776
6 changed files with 73 additions and 6 deletions

View File

@@ -232,6 +232,7 @@
4CF7805F176E75110032EE71 /* ServerSettings.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CF7805E176E75110032EE71 /* ServerSettings.xib */; };
4CF78064176E75AD0032EE71 /* MPServerSettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF78063176E75AD0032EE71 /* MPServerSettingsController.m */; };
4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC53BE16E94729007396BE /* MPShadowBox.m */; };
4CFEB36E1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFEB36D1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -659,6 +660,8 @@
4CF78063176E75AD0032EE71 /* MPServerSettingsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPServerSettingsController.m; sourceTree = "<group>"; };
4CFC53BD16E94729007396BE /* MPShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPShadowBox.h; sourceTree = "<group>"; };
4CFC53BE16E94729007396BE /* MPShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPShadowBox.m; sourceTree = "<group>"; };
4CFEB36C1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Kdb3Entry+KVOAdditions.h"; sourceTree = "<group>"; };
4CFEB36D1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Kdb3Entry+KVOAdditions.m"; sourceTree = "<group>"; };
6E719715172058BA00E4C5FC /* MPDatabaseVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPDatabaseVersion.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -933,6 +936,8 @@
4C36E5B3177CD4FB00152132 /* Kdb4Tree+KVOAdditions.m */,
4C4FCE16177D03D700BBF7AE /* Kdb4Entry+KVOAdditions.h */,
4C4FCE17177D03D700BBF7AE /* Kdb4Entry+KVOAdditions.m */,
4CFEB36C1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.h */,
4CFEB36D1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.m */,
4C83F4A81774B155006C5FC0 /* Kdb3Tree+NewTree.h */,
4C83F4A91774B155006C5FC0 /* Kdb3Tree+NewTree.m */,
4C83F4AB1774B25F006C5FC0 /* Kdb4Tree+NewTree.h */,
@@ -1832,6 +1837,7 @@
4C67D33317981ABA00A7BDFC /* HNHTokenFieldCell.m in Sources */,
4C4510091798C53700219998 /* StringField+Validation.m in Sources */,
4C45100C1798C65C00219998 /* Kdb4Entry+MPAdditions.m in Sources */,
4CFEB36E1799D9CF00AF1868 /* Kdb3Entry+KVOAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,18 @@
//
// Kdb3Entry+KVOAdditions.h
// MacPass
//
// Created by Michael Starke on 19.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "Kdb3Node.h"
@interface Kdb3Entry (KVOAdditions)
- (NSUInteger)countOfBinaries;
- (id)objectInBinariesAtIndex:(NSUInteger)index;
- (void)removeObjectFromBinariesAtIndex:(NSUInteger)index;
- (void)insertObject:(id)binary inBinariesAtIndex:(NSUInteger)index;
@end

View File

@@ -0,0 +1,31 @@
//
// Kdb3Entry+KVOAdditions.m
// MacPass
//
// Created by Michael Starke on 19.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "Kdb3Entry+KVOAdditions.h"
@implementation Kdb3Entry (KVOAdditions)
- (NSUInteger)countOfBinaries {
return (self.binary != nil ? 1 : 0);
}
- (id)objectInBinariesAtIndex:(NSUInteger)index {
if(self.binary) {
return @"Dummy";
}
return nil;
}
- (void)removeObjectFromBinariesAtIndex:(NSUInteger)index {
return; // Stubb
}
- (void)insertObject:(id)binary inBinariesAtIndex:(NSUInteger)index {
return; //Stubb
}
@end

View File

@@ -12,6 +12,7 @@
#import "MPSelectedAttachmentTableCellView.h"
#import "Kdb4Node.h"
#import "Kdb3Node.h"
#import "HNHTableRowView.h"
@@ -20,9 +21,16 @@
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
NSTableView *tableView = [notification object];
NSIndexSet *allColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[tableView tableColumns] count])];
Kdb4Entry *entryv4 = (Kdb4Entry *)self.viewController.selectedEntry;
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [entryv4.binaries count] )];
[tableView reloadDataForRowIndexes:indexSet columnIndexes:allColumns];
if([self.viewController.selectedEntry isKindOfClass:[Kdb4Entry class]]) {
Kdb4Entry *entryv4 = (Kdb4Entry *)self.viewController.selectedEntry;
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [entryv4.binaries count] )];
[tableView reloadDataForRowIndexes:indexSet columnIndexes:allColumns];
}
if([self.viewController.selectedEntry isKindOfClass:[Kdb3Entry class]]) {
Kdb3Entry *entryv3 = (Kdb3Entry *)self.viewController.selectedEntry;
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, (entryv3.binary ? 1 : 0 ))];
[tableView reloadDataForRowIndexes:indexSet columnIndexes:allColumns];
}
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
@@ -50,7 +58,9 @@
[[view imageView] setImage:[[NSWorkspace sharedWorkspace] iconForFileType:[binaryRef.key pathExtension]]];
}
else {
// Create view to support only one binary!
Kdb3Entry *entry= (Kdb3Entry *)self.viewController.selectedEntry;
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"binaryDesc" options:nil];
[[view imageView] setImage:[[NSWorkspace sharedWorkspace] iconForFileType:[entry.binaryDesc pathExtension]]];
}
return view;
}

View File

@@ -12,6 +12,7 @@
#import "NSData+Gzip.h"
#import "Kdb3Node.h"
#import "Kdb3Entry+KVOAdditions.h"
#import "Kdb4Node.h"
#import "Kdb4Entry+KVOAdditions.h"
@@ -31,6 +32,7 @@
}
entry.binary = binaryData;
entry.binaryDesc = fileName;
[entry insertObject:@"" inBinariesAtIndex:1];
}
if( [anEntry isKindOfClass:[Kdb4Entry class]]) {
Kdb4Entry *entry = (Kdb4Entry *)anEntry;

View File

@@ -185,7 +185,7 @@ enum {
[_attachmentsController bind:NSContentArrayBinding toObject:self.selectedEntry withKeyPath:@"binaries" options:nil];
}
else {
/* Use binary from Kdb3Entry */
[_attachmentsController bind:NSContentArrayBinding toObject:self.selectedEntry withKeyPath:@"binaries" options:nil];
}
}
else if([_attachmentsController content] != nil){
@@ -384,7 +384,7 @@ enum {
- (IBAction)removeAttachment:(id)sender {
MPDocument *document = [[self windowController] document];
if(document.version == MPDatabaseVersion3) {
// Uhhhh :D
// Handle entry
}
if(document.version == MPDatabaseVersion4) {
Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry;