blob: e4292e638293b20b39d254e0339a4a4e47083af7 [file] [log] [blame]
Alexandre Lisionf5fc4792015-03-17 09:15:43 -04001/*
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 Lision91d11e52015-03-20 17:42:05 -040037#import <QSortFilterProxyModel>
38#import <audio/codecmodel.h>
39#import <accountmodel.h>
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040040
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];
70
71}
72
73- (IBAction)moveUp:(id)sender {
74
75}
76
77- (IBAction)moveDown:(id)sender {
78
79}
80
81- (IBAction)toggleCodec:(NSOutlineView*)sender {
82 NSInteger row = [sender clickedRow];
83 NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE];
84 NSButtonCell *cell = [col dataCellForRow:row];
85 QModelIndex qIdx = privateAccount->codecModel()->audioCodecs()->index(row, 0, QModelIndex());
86 privateAccount->codecModel()->audioCodecs()->setData(
87 qIdx, cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
88}
89
90#pragma mark - NSOutlineViewDelegate methods
91
92// -------------------------------------------------------------------------------
93// shouldSelectItem:item
94// -------------------------------------------------------------------------------
95- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
96{
97 return YES;
98}
99
100// -------------------------------------------------------------------------------
101// dataCellForTableColumn:tableColumn:item
102// -------------------------------------------------------------------------------
103- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
104{
105 NSCell *returnCell = [tableColumn dataCell];
106
107 if(item == nil)
108 return returnCell;
109
110 return returnCell;
111}
112
113// -------------------------------------------------------------------------------
114// textShouldEndEditing:fieldEditor
115// -------------------------------------------------------------------------------
116- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
117{
118 if ([[fieldEditor string] length] == 0)
119 {
120 // don't allow empty node names
121 return NO;
122 }
123 else
124 {
125 return YES;
126 }
127}
128
129// -------------------------------------------------------------------------------
130// shouldEditTableColumn:tableColumn:item
131//
132// Decide to allow the edit of the given outline view "item".
133// -------------------------------------------------------------------------------
134- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
135{
136 return NO;
137}
138
139// -------------------------------------------------------------------------------
140// outlineView:willDisplayCell:forTableColumn:item
141// -------------------------------------------------------------------------------
142- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
143{
144 QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
145 if(!qIdx.isValid())
146 return;
147 if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) {
148 [cell setState:privateAccount->codecModel()->audioCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
149 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS])
150 {
151 cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString();
152 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ])
153 {
154 cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString();
155 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE])
156 {
157 cell.title = privateAccount->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString();
158 }
159}
160
161// -------------------------------------------------------------------------------
162// outlineViewSelectionDidChange:notification
163// -------------------------------------------------------------------------------
164- (void)outlineViewSelectionDidChange:(NSNotification *)notification
165{
166
167}
168
169@end