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 | |
Alexandre Lision | e1e9e6a | 2015-03-20 17:51:21 -0400 | [diff] [blame] | 93 | - (IBAction)moveUp:(id)sender { |
| 94 | |
| 95 | if([[treeController selectedNodes] count] > 0) { |
| 96 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 97 | if(!qIdx.isValid()) |
| 98 | return; |
| 99 | |
| 100 | QMimeData* mime = privateAccount->codecModel()->mimeData(QModelIndexList() << qIdx); |
| 101 | privateAccount->codecModel()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex()); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | - (IBAction)moveDown:(id)sender { |
| 106 | if([[treeController selectedNodes] count] > 0) { |
| 107 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 108 | if(!qIdx.isValid()) |
| 109 | return; |
| 110 | |
| 111 | QMimeData* mime = privateAccount->codecModel()->mimeData(QModelIndexList() << qIdx); |
| 112 | privateAccount->codecModel()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex()); |
| 113 | } |
| 114 | } |
| 115 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 116 | #pragma mark - NSOutlineViewDelegate methods |
| 117 | |
| 118 | // ------------------------------------------------------------------------------- |
| 119 | // shouldSelectItem:item |
| 120 | // ------------------------------------------------------------------------------- |
| 121 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 122 | { |
| 123 | return YES; |
| 124 | } |
| 125 | |
| 126 | // ------------------------------------------------------------------------------- |
| 127 | // dataCellForTableColumn:tableColumn:item |
| 128 | // ------------------------------------------------------------------------------- |
| 129 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 130 | { |
| 131 | NSCell *returnCell = [tableColumn dataCell]; |
| 132 | |
| 133 | if(item == nil) |
| 134 | return returnCell; |
| 135 | return returnCell; |
| 136 | } |
| 137 | |
| 138 | // ------------------------------------------------------------------------------- |
| 139 | // textShouldEndEditing:fieldEditor |
| 140 | // ------------------------------------------------------------------------------- |
| 141 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 142 | { |
| 143 | if ([[fieldEditor string] length] == 0) |
| 144 | { |
| 145 | // don't allow empty node names |
| 146 | return NO; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | return YES; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // ------------------------------------------------------------------------------- |
| 155 | // shouldEditTableColumn:tableColumn:item |
| 156 | // |
| 157 | // Decide to allow the edit of the given outline view "item". |
| 158 | // ------------------------------------------------------------------------------- |
| 159 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 160 | { |
| 161 | return NO; |
| 162 | } |
| 163 | |
| 164 | // ------------------------------------------------------------------------------- |
| 165 | // outlineView:willDisplayCell:forTableColumn:item |
| 166 | // ------------------------------------------------------------------------------- |
| 167 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 168 | { |
| 169 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 170 | if(!qIdx.isValid()) |
| 171 | return; |
| 172 | |
| 173 | if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) { |
| 174 | [cell setState:privateAccount->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState]; |
| 175 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS]) |
| 176 | { |
| 177 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString(); |
| 178 | [cell setState:privateAccount->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState]; |
| 179 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ]) |
| 180 | { |
| 181 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString(); |
| 182 | } else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE]) |
| 183 | { |
| 184 | cell.title = privateAccount->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // ------------------------------------------------------------------------------- |
| 189 | // outlineViewSelectionDidChange:notification |
| 190 | // ------------------------------------------------------------------------------- |
| 191 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 192 | { |
| 193 | // ask the tree controller for the current selection |
| 194 | } |
| 195 | |
| 196 | @end |