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 | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame^] | 30 | #import "HistoryVC.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 | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 33 | #import <QSortFilterProxyModel> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 34 | #import <callmodel.h> |
| 35 | #import <call.h> |
| 36 | #import <contactmethod.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 37 | |
Alexandre Lision | 7d2a48b | 2015-03-30 14:59:58 -0400 | [diff] [blame] | 38 | #import "backends/MinimalHistoryBackend.h" |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 39 | #import "QNSTreeController.h" |
| 40 | |
| 41 | #define COLUMNID_DAY @"DayColumn" // the single column name in our outline view |
| 42 | #define COLUMNID_CONTACTMETHOD @"ContactMethodColumn" // the single column name in our outline view |
| 43 | #define COLUMNID_DATE @"DateColumn" // the single column name in our outline view |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 44 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame^] | 45 | @interface HistoryVC() |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 46 | |
| 47 | @property NSTreeController *treeController; |
| 48 | @property (assign) IBOutlet NSOutlineView *historyView; |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 49 | @property QSortFilterProxyModel *historyProxyModel; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 50 | @end |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 51 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame^] | 52 | @implementation HistoryVC |
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 | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 55 | @synthesize historyProxyModel; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 56 | |
| 57 | - (id)initWithCoder:(NSCoder *)aDecoder |
| 58 | { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 59 | if (self = [super initWithCoder:aDecoder]) { |
| 60 | NSLog(@"INIT HVC"); |
| 61 | |
| 62 | } |
| 63 | return self; |
| 64 | } |
| 65 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 66 | - (void)awakeFromNib |
| 67 | { |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 68 | historyProxyModel = new QSortFilterProxyModel(CategorizedHistoryModel::instance()); |
| 69 | historyProxyModel->setSourceModel(CategorizedHistoryModel::instance()); |
| 70 | historyProxyModel->setSortRole(static_cast<int>(Call::Role::Date)); |
| 71 | historyProxyModel->sort(0,Qt::DescendingOrder); |
| 72 | treeController = [[QNSTreeController alloc] initWithQModel:historyProxyModel]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 73 | |
| 74 | [treeController setAvoidsEmptySelection:NO]; |
| 75 | [treeController setChildrenKeyPath:@"children"]; |
| 76 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 77 | [historyView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 78 | [historyView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 79 | [historyView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 80 | [historyView setTarget:self]; |
Alexandre Lision | 3b0bd33 | 2015-03-15 18:43:07 -0400 | [diff] [blame] | 81 | [historyView setDoubleAction:@selector(placeHistoryCall:)]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 82 | |
Alexandre Lision | e33b5ac | 2015-03-19 20:13:45 -0400 | [diff] [blame] | 83 | CategorizedHistoryModel::instance()->addCollection<MinimalHistoryBackend>(LoadOptions::FORCE_ENABLED); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 84 | } |
| 85 | |
Alexandre Lision | 3b0bd33 | 2015-03-15 18:43:07 -0400 | [diff] [blame] | 86 | - (void)placeHistoryCall:(id)sender |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 87 | { |
| 88 | if([[treeController selectedNodes] count] > 0) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 89 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 90 | QVariant var = historyProxyModel->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 | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 158 | cell.title = historyProxyModel->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 | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 161 | cell.title = historyProxyModel->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 | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 164 | cell.title = historyProxyModel->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 |