1 #import "SourceViewController.h"
3 @implementation BaseItem
5 +(BaseItem*)initWithText:(NSString *)text withViewId:(NSString *) viewId {
6 BaseItem *node = [[BaseItem alloc] init];
7 node->m_text = [NSString stringWithString:text];
10 node->m_subitems = [NSMutableArray arrayWithCapacity:16];
11 [node->m_subitems retain];
12 node->m_subitems_count = 0;
14 node->m_view_id = viewId;
15 if ( viewId != nil ) {
16 [node->m_view_id retain];
20 // NSString* imageName = [[NSBundle mainBundle] pathForResource:@"Client_Transfer" ofType:@"png"];
21 // NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];
22 NSString *imageName = @"Client_Transfer";
23 NSImage* imageObj = [NSImage imageNamed:imageName];
26 node->m_icon = imageObj;
40 return m_subitems_count;
47 - (NSString *)viewId {
55 - (BaseItem*)itemAtIndex: (int) index {
56 if ( m_subitems_count ) {
57 return [m_subitems objectAtIndex:index];
62 - (void)activateView:(NSTabView *) view {
65 - (void)addSubItem:(BaseItem *) item {
66 [m_subitems insertObject:item atIndex:m_subitems_count];
72 @implementation CategoryItemFactory
74 + (BaseItem *)initFilesItem {
75 BaseItem *it = [BaseItem initWithText:@"Files" withViewId:nil];
77 BaseItem *all = [BaseItem initWithText:@"All files" withViewId:@"all"];
78 BaseItem *dl = [BaseItem initWithText:@"Downloads" withViewId:@"downloads"];
79 BaseItem *ul = [BaseItem initWithText:@"Uploads" withViewId:@"upload"];
80 BaseItem *sh = [BaseItem initWithText:@"Shared" withViewId:@"shared"];
90 + (BaseItem *)initNetworksItem {
91 BaseItem *it = [BaseItem initWithText:@"Networks" withViewId:nil];
95 + (BaseItem *)initSearchItem {
96 BaseItem *it = [BaseItem initWithText:@"Search" withViewId:nil];
103 @implementation amuleSourceListDataSource
105 + (amuleSourceListDataSource *)initWithData {
106 amuleSourceListDataSource *obj = [[amuleSourceListDataSource alloc] init];
107 obj->g_root_items[RootItemFiles] = [CategoryItemFactory initFilesItem];
108 obj->g_root_items[RootItemNetwork] = [CategoryItemFactory initNetworksItem];
109 obj->g_root_items[RootItemSearch] = [CategoryItemFactory initSearchItem];
114 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
119 return [item subitemsCount];
122 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
127 return [item subitemsCount] ? YES : NO;
130 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
133 return g_root_items[index];
135 return [item itemAtIndex: index];
138 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
140 NSString *columnId = [tableColumn identifier];
141 if ( [columnId compare:@"status"] == NSOrderedSame ) {
144 NSString *s = [item text];
150 @implementation CellWithIcon
155 [self setLineBreakMode:NSLineBreakByTruncatingTail];
160 - (id)initWithCoder:(NSCoder *)aDecoder {
161 self = [super initWithCoder:aDecoder];
165 - (id)copyWithZone:(NSZone *)zone {
166 CellWithIcon *result = [super copyWithZone:zone];
168 result->m_icon = nil;
169 [result setIcon:[self icon]];
183 - (void)setIcon:(NSImage *)icon {
184 if (icon != m_icon) {
186 m_icon = [icon retain];
191 #define PADDING_BEFORE_IMAGE 5.0
192 #define PADDING_BETWEEN_TITLE_AND_IMAGE 4.0
195 - (NSRect)imageRectForBounds:(NSRect)bounds {
196 NSRect result = bounds;
198 result.origin.x += PADDING_BEFORE_IMAGE;
200 result.size = [m_icon size];
205 - (NSRect)titleRectForBounds:(NSRect)bounds {
206 NSAttributedString *text = [self attributedStringValue];
207 NSRect result = bounds;
209 icon_size.size = [m_icon size];
211 result.origin.x += PADDING_BEFORE_IMAGE + icon_size.size.width + PADDING_BETWEEN_TITLE_AND_IMAGE;
214 result.size = [text size];
216 result.size = NSZeroSize;
219 CGFloat maxX = NSMaxX(bounds) - icon_size.size.height;
220 CGFloat maxWidth = maxX - NSMinX(result);
224 result.size.width = MIN(NSWidth(result), maxWidth);
228 - (void)drawInteriorWithFrame:(NSRect)bounds inView:(NSView *)controlView {
230 NSRect imageRect = [self imageRectForBounds:bounds];
232 [m_icon setFlipped:[controlView isFlipped]];
233 [m_icon drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
235 NSRect titleRect = [self titleRectForBounds:bounds];
236 NSAttributedString *title = [self attributedStringValue];
237 if ([title length] > 0) {
238 [title drawInRect:titleRect];
245 @implementation SourceViewController
247 - (void)awakeFromNib {
248 [m_outline_view setDelegate:self];
250 id datasource = [amuleSourceListDataSource initWithData];
252 [m_outline_view setDataSource:datasource];
253 [m_outline_view reloadData];
256 for(i = 0; i < [m_outline_view numberOfRows];i++) {
257 id item = [m_outline_view itemAtRow:i];
258 [m_outline_view expandItem:item];
263 - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
264 int selRow = [m_outline_view selectedRow];
265 id item = [m_outline_view itemAtRow:selRow];
266 id viewId = [item viewId];
267 NSLog(@"select tab=%@\n", viewId);
269 [m_tab_view selectTabViewItemWithIdentifier:viewId];
272 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
273 id viewId = [item viewId];
274 return (viewId == nil) ? NO : YES;
277 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
278 // if (tableColumn && [[tableColumn identifier] isEqualToString:@"status"]) {
279 NSImage *icon = [item icon];
280 if ( [cell isKindOfClass:[CellWithIcon class]] ) {