blob: 8581ce3a732189023b9e1c7fb95f291237550fa0 [file] [log] [blame]
Alexandre Lision5855b6a2015-02-03 11:31:05 -05001//
2// ConversationsViewController.m
3// Ring
4//
5// Created by Alexandre Lision on 2015-02-02.
6//
7//
8
9#import "ConversationsViewController.h"
10#import <callmodel.h>
11
12#define COLUMNID_CONVERSATIONS @"ConversationsColumn" // the single column name in our outline view
13
14@interface ConversationsViewController ()
15
16@end
17
18@implementation ConversationsViewController
19@synthesize conversationsView;
20@synthesize treeController;
21
22- (id)initWithCoder:(NSCoder *)aDecoder
23{
24 if (self = [super initWithCoder:aDecoder]) {
25 NSLog(@"INIT Conversations VC");
26 }
27 return self;
28}
29
30
31
32- (void)awakeFromNib
33{
34 NSLog(@"awakeFromNib");
35
36 treeController = [[QNSTreeController alloc] initWithQModel:CallModel::instance()];
37
38 [treeController setAvoidsEmptySelection:NO];
39 [treeController setChildrenKeyPath:@"children"];
40
41 [self.conversationsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
42 [self.conversationsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
43 [self.conversationsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
44
45 NSInteger idx = [conversationsView columnWithIdentifier:COLUMNID_CONVERSATIONS];
46 [[[[self.conversationsView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Conversations"];
47}
48
49#pragma mark - NSOutlineViewDelegate methods
50
51// -------------------------------------------------------------------------------
52// shouldSelectItem:item
53// -------------------------------------------------------------------------------
54- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
55{
56 return YES;
57}
58
59// -------------------------------------------------------------------------------
60// dataCellForTableColumn:tableColumn:item
61// -------------------------------------------------------------------------------
62- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
63{
64 NSCell *returnCell = [tableColumn dataCell];
65
66
67 if(item == nil)
68 return returnCell;
69 if ([[tableColumn identifier] isEqualToString:COLUMNID_CONVERSATIONS])
70 {
71
72 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
73 NSUInteger myArray[[idx length]];
74 [idx getIndexes:myArray];
75
76 NSLog(@"dataCellForTableColumn, indexPath: %lu", (unsigned long)myArray[0]);
77
78 QModelIndex qIdx = CallModel::instance()->index(myArray[0], 0);
79
80 QVariant test = CallModel::instance()->data(qIdx, Qt::DisplayRole);
81 }
82
83 return returnCell;
84}
85
86// -------------------------------------------------------------------------------
87// textShouldEndEditing:fieldEditor
88// -------------------------------------------------------------------------------
89- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
90{
91 if ([[fieldEditor string] length] == 0)
92 {
93 // don't allow empty node names
94 return NO;
95 }
96 else
97 {
98 return YES;
99 }
100}
101
102// -------------------------------------------------------------------------------
103// shouldEditTableColumn:tableColumn:item
104//
105// Decide to allow the edit of the given outline view "item".
106// -------------------------------------------------------------------------------
107- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
108{
109 return NO;
110}
111
112// -------------------------------------------------------------------------------
113// outlineView:willDisplayCell:forTableColumn:item
114// -------------------------------------------------------------------------------
115- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
116{
117 if ([[tableColumn identifier] isEqualToString:COLUMNID_CONVERSATIONS])
118 {
119 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
120 NSUInteger myArray[[idx length]];
121 [idx getIndexes:myArray];
122 NSLog(@"array:%@", idx);
123
124 QModelIndex qIdx;
125 if(idx.length == 2)
126 qIdx = CallModel::instance()->index(myArray[1], 0, CallModel::instance()->index(myArray[0], 0));
127 else
128 qIdx = CallModel::instance()->index(myArray[0], 0);
129
130
131 if(qIdx.isValid())
132 cell.title = CallModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString();
133 }
134}
135
136// -------------------------------------------------------------------------------
137// outlineViewSelectionDidChange:notification
138// -------------------------------------------------------------------------------
139- (void)outlineViewSelectionDidChange:(NSNotification *)notification
140{
141 // ask the tree controller for the current selection
142 NSLog(@"outlineViewSelectionDidChange!!");
143}
144
145
146@end