public
Description: A Mac OS X photo uploader program for my photo album.
Homepage: http://bleu.west.spy.net/~dustin/projects/photoupload/
Clone URL: git://github.com/dustin/photoupload.git
Search Repo:
photoupload / DumpTable.m
100644 117 lines (102 sloc) 3.396 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// DumpTable.m
// PhotoUpload
//
// Created by Dustin Sallings on 2005/11/23/.
// Copyright 2005 Dustin Sallings <dustin@spy.net>. All rights reserved.
//
 
#import "DumpTable.h"
#import "PUImageList.h"
 
@implementation DumpTable
 
-(BOOL)isImage: (NSString *)file
{
    BOOL rv=false;
    NSString *ext=[[file pathExtension] lowercaseString];
 
    rv|=[ext isEqualToString: @"jpg"];
    rv|=[ext isEqualToString: @"jpeg"];
    rv|=[ext isEqualToString: @"gif"];
    rv|=[ext isEqualToString: @"png"];
 
    return(rv);
}
 
-(NSArray *)getImages: (NSString *)file
{
    NSMutableArray *justFiles=[[NSMutableArray alloc] init];
 
    // Figure out if it's a directory or a file.
    // If it's a directory, recurse. If it's a file, just use it.
    BOOL isDir=FALSE;
    NSFileManager *manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:file isDirectory:&isDir]) {
        if (isDir) {
            NSArray *subpaths = [manager subpathsAtPath:file];
            int i=0;
            for(i=0; i<[subpaths count]; i++) {
                NSString *fullpath=[file
                    stringByAppendingPathComponent: [subpaths objectAtIndex: i]];
                if ([manager fileExistsAtPath:file isDirectory:&isDir]) {
                    [justFiles addObject: fullpath];
                }
            }
        } else {
            [justFiles addObject: file];
        }
    }
 
    NSMutableArray *rv=[[NSMutableArray alloc] init];
    [rv autorelease];
 
    NSEnumerator *nse=[justFiles objectEnumerator];
    id object=nil;
    while(object = [nse nextObject]) {
        // NSLog(@"--- %@\n", object);
        if([self isImage: object]) {
            [rv addObject: object];
        }
    }
    // pathExtension
 
    [justFiles release];
    return(rv);
}
 
- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info
  row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
  NSLog(@"Accepting drop...");
  return YES;
}
 
- (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info
  proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
{
  NSLog(@"Asking to validate info.");
  NSDragOperation rv=NSDragOperationNone;
    NSDragOperation sourceDragMask = [info draggingSourceOperationMask];
    if (sourceDragMask & NSDragOperationLink) {
        rv=NSDragOperationLink;
    } else if (sourceDragMask & NSDragOperationCopy) {
        rv=NSDragOperationCopy;
    }
    return rv;
}
 
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
  NSLog(@"Performing dragging operation.");
    NSPasteboard *pboard=[sender draggingPasteboard];
    NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
    int i=0;
    for(i=0; i<[files count]; i++) {
        NSString *filename=[files objectAtIndex: i];
        NSArray *subfilenames=[self getImages: filename];
        int j=0;
        for(j=0; j<[subfilenames count]; j++) {
            id subfilename=[subfilenames objectAtIndex: j];
            [imgStorage addPath: subfilename];
            // NSLog(@"Subfile %@\n", subfilename);
        }
        // NSLog(@"Got %@\n", filename);
    }
    return (TRUE);
}
 
-(void)awakeFromNib
{
  NSLog(@"Awakened from nib, registering for dragging.");
  [self registerForDraggedTypes:[NSArray arrayWithObjects:
        NSFilenamesPboardType, nil]];
  [self setDataSource: self];
}
 
@end