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