Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -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 | */ |
| 30 | #define COLUMNID_STATE @"VideoStateColumn" |
| 31 | #define COLUMNID_CODECS @"VideoCodecsColumn" |
| 32 | #define COLUMNID_FREQ @"VideoFrequencyColumn" |
| 33 | #define COLUMNID_BITRATE @"VideoBitrateColumn" |
| 34 | |
| 35 | #import "AccVideoVC.h" |
| 36 | |
| 37 | #include <QtCore/QSortFilterProxyModel> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame^] | 38 | #import <audio/codecmodel.h> |
| 39 | #import <accountmodel.h> |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 40 | |
| 41 | #import "QNSTreeController.h" |
| 42 | |
| 43 | @interface AccVideoVC () |
| 44 | |
| 45 | @property Account* privateAccount; |
| 46 | @property QNSTreeController *treeController; |
| 47 | @property (assign) IBOutlet NSOutlineView *codecsView; |
| 48 | @property (assign) IBOutlet NSView *videoPanelContainer; |
| 49 | @property (assign) IBOutlet NSButton *toggleVideoButton; |
| 50 | |
| 51 | @end |
| 52 | |
| 53 | @implementation AccVideoVC |
| 54 | @synthesize treeController; |
| 55 | @synthesize codecsView; |
| 56 | @synthesize privateAccount; |
| 57 | @synthesize videoPanelContainer; |
| 58 | @synthesize toggleVideoButton; |
| 59 | |
| 60 | - (void)awakeFromNib |
| 61 | { |
| 62 | NSLog(@"INIT Video VC"); |
| 63 | } |
| 64 | |
| 65 | - (void)loadAccount:(Account *)account |
| 66 | { |
| 67 | privateAccount = account; |
| 68 | |
| 69 | treeController = [[QNSTreeController alloc] initWithQModel:privateAccount->codecModel()->videoCodecs()]; |
| 70 | [treeController setAvoidsEmptySelection:NO]; |
| 71 | [treeController setChildrenKeyPath:@"children"]; |
| 72 | |
| 73 | [codecsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 74 | [codecsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 75 | [codecsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 76 | [videoPanelContainer setHidden:!privateAccount->isVideoEnabled()]; |
| 77 | [toggleVideoButton setState:privateAccount->isVideoEnabled()?NSOnState:NSOffState]; |
| 78 | } |
| 79 | |
| 80 | - (IBAction)toggleVideoEnabled:(id)sender { |
| 81 | privateAccount->setVideoEnabled([sender state] == NSOnState); |
| 82 | [videoPanelContainer setHidden:!privateAccount->isVideoEnabled()]; |
| 83 | } |
| 84 | |
| 85 | - (IBAction)toggleCodec:(NSOutlineView*)sender { |
| 86 | NSInteger row = [sender clickedRow]; |
| 87 | NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE]; |
| 88 | NSButtonCell *cell = [col dataCellForRow:row]; |
| 89 | privateAccount->codecModel()->videoCodecs()->setData(privateAccount->codecModel()->videoCodecs()->index(row, 0, QModelIndex()), |
| 90 | cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole); |
| 91 | } |
| 92 | |
| 93 | #pragma mark - NSOutlineViewDelegate methods |
| 94 | |
| 95 | // ------------------------------------------------------------------------------- |
| 96 | // shouldSelectItem:item |
| 97 | // ------------------------------------------------------------------------------- |
| 98 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 99 | { |
| 100 | return YES; |
| 101 | } |
| 102 | |
| 103 | // ------------------------------------------------------------------------------- |
| 104 | // dataCellForTableColumn:tableColumn:item |
| 105 | // ------------------------------------------------------------------------------- |
| 106 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 107 | { |
| 108 | NSCell *returnCell = [tableColumn dataCell]; |
| 109 | |
| 110 | if(item == nil) |
| 111 | return returnCell; |
| 112 | return returnCell; |
| 113 | } |
| 114 | |
| 115 | // ------------------------------------------------------------------------------- |
| 116 | // textShouldEndEditing:fieldEditor |
| 117 | // ------------------------------------------------------------------------------- |
| 118 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 119 | { |
| 120 | if ([[fieldEditor string] length] == 0) |
| 121 | { |
| 122 | // don't allow empty node names |
| 123 | return NO; |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | return YES; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // ------------------------------------------------------------------------------- |
| 132 | // shouldEditTableColumn:tableColumn:item |
| 133 | // |
| 134 | // Decide to allow the edit of the given outline view "item". |
| 135 | // ------------------------------------------------------------------------------- |
| 136 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 137 | { |
| 138 | return NO; |
| 139 | } |
| 140 | |
| 141 | // ------------------------------------------------------------------------------- |
| 142 | // outlineView:willDisplayCell:forTableColumn:item |
| 143 | // ------------------------------------------------------------------------------- |
| 144 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 145 | { |
| 146 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 147 | if(!qIdx.isValid()) |
| 148 | return; |
| 149 | |
| 150 | if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) { |
| 151 | [cell setState:privateAccount->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState]; |
| 152 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS]) |
| 153 | { |
| 154 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString(); |
| 155 | [cell setState:privateAccount->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState]; |
| 156 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ]) |
| 157 | { |
| 158 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString(); |
| 159 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE]) |
| 160 | { |
| 161 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString(); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // ------------------------------------------------------------------------------- |
| 166 | // outlineViewSelectionDidChange:notification |
| 167 | // ------------------------------------------------------------------------------- |
| 168 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 169 | { |
| 170 | // ask the tree controller for the current selection |
| 171 | } |
| 172 | |
| 173 | @end |