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