Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 30 | #import "HistoryViewController.h" |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 31 | |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 32 | #import <categorizedhistorymodel.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 33 | #import <callmodel.h> |
| 34 | #import <call.h> |
| 35 | #import <contactmethod.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 36 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 37 | #import "MinimalHistoryBackend.h" |
| 38 | #import "QNSTreeController.h" |
| 39 | |
| 40 | #define COLUMNID_DAY @"DayColumn" // the single column name in our outline view |
| 41 | #define COLUMNID_CONTACTMETHOD @"ContactMethodColumn" // the single column name in our outline view |
| 42 | #define COLUMNID_DATE @"DateColumn" // the single column name in our outline view |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 43 | |
| 44 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 45 | @interface HistoryViewController() |
| 46 | |
| 47 | @property NSTreeController *treeController; |
| 48 | @property (assign) IBOutlet NSOutlineView *historyView; |
| 49 | |
| 50 | @end |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 51 | |
| 52 | @implementation HistoryViewController |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 53 | @synthesize treeController; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 54 | @synthesize historyView; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 55 | |
| 56 | - (id)initWithCoder:(NSCoder *)aDecoder |
| 57 | { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 58 | if (self = [super initWithCoder:aDecoder]) { |
| 59 | NSLog(@"INIT HVC"); |
| 60 | |
| 61 | } |
| 62 | return self; |
| 63 | } |
| 64 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 65 | - (void)awakeFromNib |
| 66 | { |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 67 | treeController = [[QNSTreeController alloc] initWithQModel:CategorizedHistoryModel::instance()]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 68 | |
| 69 | [treeController setAvoidsEmptySelection:NO]; |
| 70 | [treeController setChildrenKeyPath:@"children"]; |
| 71 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 72 | [historyView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 73 | [historyView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 74 | [historyView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 75 | [historyView setTarget:self]; |
| 76 | [historyView setDoubleAction:@selector(placeCall:)]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 77 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 78 | NSInteger idx = [historyView columnWithIdentifier:COLUMNID_DAY]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 79 | [[[[self.historyView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Name"]; |
| 80 | |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 81 | CategorizedHistoryModel::instance()->addCollection<MinimalHistoryBackend>(LoadOptions::FORCE_ENABLED); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 82 | |
| 83 | } |
| 84 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 85 | - (void)placeCall:(id)sender |
| 86 | { |
| 87 | if([[treeController selectedNodes] count] > 0) { |
| 88 | Call* c = CallModel::instance()->dialingCall(); |
| 89 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 90 | QVariant var = CategorizedHistoryModel::instance()->data(qIdx, (int)Call::Role::ContactMethod); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 91 | ContactMethod* m = qvariant_cast<ContactMethod*>(var); |
| 92 | if(m){ |
| 93 | Call* c = CallModel::instance()->dialingCall(); |
| 94 | c->setDialNumber(m); |
| 95 | c << Call::Action::ACCEPT; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 100 | #pragma mark - NSOutlineViewDelegate methods |
| 101 | |
| 102 | // ------------------------------------------------------------------------------- |
| 103 | // shouldSelectItem:item |
| 104 | // ------------------------------------------------------------------------------- |
| 105 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 106 | { |
| 107 | return YES; |
| 108 | } |
| 109 | |
| 110 | // ------------------------------------------------------------------------------- |
| 111 | // dataCellForTableColumn:tableColumn:item |
| 112 | // ------------------------------------------------------------------------------- |
| 113 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 114 | { |
| 115 | NSCell *returnCell = [tableColumn dataCell]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 116 | if(item == nil) |
| 117 | return returnCell; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 118 | return returnCell; |
| 119 | } |
| 120 | |
| 121 | // ------------------------------------------------------------------------------- |
| 122 | // textShouldEndEditing:fieldEditor |
| 123 | // ------------------------------------------------------------------------------- |
| 124 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 125 | { |
| 126 | if ([[fieldEditor string] length] == 0) |
| 127 | { |
| 128 | // don't allow empty node names |
| 129 | return NO; |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | return YES; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // ------------------------------------------------------------------------------- |
| 138 | // shouldEditTableColumn:tableColumn:item |
| 139 | // |
| 140 | // Decide to allow the edit of the given outline view "item". |
| 141 | // ------------------------------------------------------------------------------- |
| 142 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 143 | { |
| 144 | return NO; |
| 145 | } |
| 146 | |
| 147 | // ------------------------------------------------------------------------------- |
| 148 | // outlineView:willDisplayCell:forTableColumn:item |
| 149 | // ------------------------------------------------------------------------------- |
| 150 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 151 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 152 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 153 | if(!qIdx.isValid()) |
| 154 | return; |
| 155 | |
| 156 | if ([[tableColumn identifier] isEqualToString:COLUMNID_DAY]) |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 157 | { |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 158 | cell.title = CategorizedHistoryModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString(); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 159 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_CONTACTMETHOD]) |
| 160 | { |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 161 | cell.title = CategorizedHistoryModel::instance()->data(qIdx, (int)Call::Role::Number).toString().toNSString(); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 162 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_DATE]) |
| 163 | { |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame^] | 164 | cell.title = CategorizedHistoryModel::instance()->data(qIdx, (int)Call::Role::FormattedDate).toString().toNSString(); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | // ------------------------------------------------------------------------------- |
| 169 | // outlineViewSelectionDidChange:notification |
| 170 | // ------------------------------------------------------------------------------- |
| 171 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 172 | { |
| 173 | // ask the tree controller for the current selection |
| 174 | //NSLog(@"outlineViewSelectionDidChange!!"); |
| 175 | } |
| 176 | |
| 177 | @end |