Upstream tarball 9689
[amule.git] / cocoa-mule / DownloadsViewController.mm
blob243de0d732106d9e48ec5bc74931c65eabdeab83
1 #import "DownloadsViewController.h"
4 @implementation DownloadsViewController
6 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
7         id value = nil;
8         NSString *columnId = [aTableColumn identifier];
9         DownloadingFile *i = [m_fileset objectAtIndex:rowIndex];
10 //      if ( [columnId compare:@"filename"] == NSOrderedSame ) {
11 //              value = @"val-for-filename";
12 //      } else if ( [columnId compare:@"progress"] == NSOrderedSame ) {
13 //              value = @"val-for-progress";
14 //      } else if ( [columnId compare:@"size"] == NSOrderedSame ) {
15 //              value = @"val-for-name";
16 //      } else if ( [columnId compare:@"xferred"] == NSOrderedSame ) {
17 //              value = @"val-for-size";
18 //      } else if ( [columnId compare:@"completed"] == NSOrderedSame ) {
19 //              value = @"val-for-completed";
20 //      } else if ( [columnId compare:@"speed"] == NSOrderedSame ) {
21 //              value = @"val-for-speed";
22 //      } else if ( [columnId compare:@"prio"] == NSOrderedSame ) {
23 //              value = @"val-for-prio";
24 //      } else if ( [columnId compare:@"timerem"] == NSOrderedSame ) {
25 //              value = @"val-for-timerem";
26 //      } else if ( [columnId compare:@"lastcomp"] == NSOrderedSame ) {
27 //              value = @"val-for-lastcomp";
28 //      } else if ( [columnId compare:@"lastrx"] == NSOrderedSame ) {
29 //              value = @"val-for-lastrx";
30 //      } else {
31 //              value = @"ERROR: bad column id";
32 //      }
33         if ( [columnId compare:@"filename"] == NSOrderedSame ) {
34                 value = i.name;
35         } else if ( [columnId compare:@"progress"] == NSOrderedSame ) {
36                 value = @"progress-colored-bar";
37         } else if ( [columnId compare:@"size"] == NSOrderedSame ) {
38                 value = [i convertWithPrefix: i.size];
39         } else if ( [columnId compare:@"xferred"] == NSOrderedSame ) {
40                 value = [i convertWithPrefix: i.size_xfer];
41         } else if ( [columnId compare:@"completed"] == NSOrderedSame ) {
42                 value = [i convertWithPrefix: i.size_done];
43         } else if ( [columnId compare:@"speed"] == NSOrderedSame ) {
44                 value = ( i.speed ) ?
45                         [[i convertWithPrefix: i.speed] stringByAppendingString: @"/sec"] : @"";
46         } else if ( [columnId compare:@"prio"] == NSOrderedSame ) {
47                 value = i.sprio;
48         } else if ( [columnId compare:@"timerem"] == NSOrderedSame ) {
49                 value = @"val-for-timerem";
50         } else if ( [columnId compare:@"lastcomp"] == NSOrderedSame ) {
51                 value = @"val-for-lastcomp";
52         } else if ( [columnId compare:@"lastrx"] == NSOrderedSame ) {
53                 value = @"val-for-lastrx";
54         } else {
55                 value = @"ERROR: bad column id";
56         }
57         return value;
60 - (int)numberOfRowsInTableView:(NSTableView *)aTableView {
61 //      return 3;
62         return [m_fileset count];
65 - (void)linkAmuleData:(amuleData *)amuledata {
66         m_amuledata = amuledata;
67         m_fileset = m_amuledata.downloads;
68         [amuledata.downloads setGuiController:self];
71 - (void)reload {
72         [m_tableview reloadData];
75 - (void)awakeFromNib {
76         [m_tableview setDelegate:self];
77         [m_tableview setDataSource:self];
78         
79         //
80         // load column status
81         //
82         for (NSTableColumn *c in [m_tableview tableColumns]) {
83                 NSString *columnId = [c identifier];
84                 NSString *keyWidth = [NSString stringWithFormat:@"DownloadView.Column_%@_Width", columnId];
85                 int width = [[NSUserDefaults standardUserDefaults] integerForKey:keyWidth];
86                 if ( width ) {
87                         NSLog(@"Column %@ setting width %d\n", columnId, width);
88                         [c setWidth:width];
89                 }
90                 NSString *keyHide = [NSString stringWithFormat:@"DownloadView.Column_%@_Hide", columnId];
91                 int hide = [[NSUserDefaults standardUserDefaults] integerForKey:keyHide];
92                 [c setHidden:hide];
93         }
96 - (void)saveGui {
97         for (NSTableColumn *c in [m_tableview tableColumns]) {
98                 NSString *columnId = [c identifier];
100                 NSString *keyWidth = [NSString stringWithFormat:@"DownloadView.Column_%@_Width", columnId];
101                 [[NSUserDefaults standardUserDefaults] setInteger:c.width forKey:keyWidth];
103                 NSString *keyHide = [NSString stringWithFormat:@"DownloadView.Column_%@_Hide", columnId];
104                 [[NSUserDefaults standardUserDefaults] setInteger:[c isHidden] forKey:keyHide];
105         }
108 @end