blob: c148256eece7f16fe0f560e87170fe2a1d261276 [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 @"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 Lision91d11e52015-03-20 17:42:05 -040038#import <audio/codecmodel.h>
39#import <accountmodel.h>
Alexandre Lision7f3164c2015-06-12 11:45:37 -040040#import <qitemselectionmodel.h>
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040041
42#import "QNSTreeController.h"
43
44@interface AccVideoVC ()
45
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040046@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;
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040056@synthesize videoPanelContainer;
57@synthesize toggleVideoButton;
58
59- (void)awakeFromNib
60{
61 NSLog(@"INIT Video VC");
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040062 QObject::connect(AccountModel::instance().selectionModel(),
Alexandre Lision7f3164c2015-06-12 11:45:37 -040063 &QItemSelectionModel::currentChanged,
64 [=](const QModelIndex &current, const QModelIndex &previous) {
65 if(!current.isValid())
66 return;
67 [self loadAccount];
68 });
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040069}
70
Alexandre Lision7f3164c2015-06-12 11:45:37 -040071- (Account*) currentAccount
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040072{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040073 auto accIdx = AccountModel::instance().selectionModel()->currentIndex();
74 return AccountModel::instance().getAccountByModelIndex(accIdx);
Alexandre Lision7f3164c2015-06-12 11:45:37 -040075}
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040076
Alexandre Lision7f3164c2015-06-12 11:45:37 -040077- (void)loadAccount
78{
79 auto account = [self currentAccount];
80
Alexandre Lision81c97212015-06-17 15:51:53 -040081 treeController = [[QNSTreeController alloc] initWithQModel:account->codecModel()->videoCodecs()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040082 [treeController setAvoidsEmptySelection:NO];
83 [treeController setChildrenKeyPath:@"children"];
84
85 [codecsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
86 [codecsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
87 [codecsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
Alexandre Lision81c97212015-06-17 15:51:53 -040088 [videoPanelContainer setHidden:!account->isVideoEnabled()];
89 [toggleVideoButton setState:account->isVideoEnabled()?NSOnState:NSOffState];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040090}
91
92- (IBAction)toggleVideoEnabled:(id)sender {
Alexandre Lision7f3164c2015-06-12 11:45:37 -040093 [self currentAccount]->setVideoEnabled([sender state] == NSOnState);
94 [videoPanelContainer setHidden:![self currentAccount]->isVideoEnabled()];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -040095}
96
97- (IBAction)toggleCodec:(NSOutlineView*)sender {
98 NSInteger row = [sender clickedRow];
99 NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE];
100 NSButtonCell *cell = [col dataCellForRow:row];
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400101 [self currentAccount]->codecModel()->videoCodecs()->setData([self currentAccount]->codecModel()->videoCodecs()->index(row, 0, QModelIndex()),
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400102 cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
103}
104
Alexandre Lisione1e9e6a2015-03-20 17:51:21 -0400105- (IBAction)moveUp:(id)sender {
106
107 if([[treeController selectedNodes] count] > 0) {
108 QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
109 if(!qIdx.isValid())
110 return;
111
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400112 QMimeData* mime = [self currentAccount]->codecModel()->mimeData(QModelIndexList() << qIdx);
113 [self currentAccount]->codecModel()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex());
Alexandre Lisione1e9e6a2015-03-20 17:51:21 -0400114 }
115}
116
117- (IBAction)moveDown:(id)sender {
118 if([[treeController selectedNodes] count] > 0) {
119 QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
120 if(!qIdx.isValid())
121 return;
122
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400123 QMimeData* mime = [self currentAccount]->codecModel()->mimeData(QModelIndexList() << qIdx);
124 [self currentAccount]->codecModel()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex());
Alexandre Lisione1e9e6a2015-03-20 17:51:21 -0400125 }
126}
127
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400128#pragma mark - NSOutlineViewDelegate methods
129
130// -------------------------------------------------------------------------------
131// shouldSelectItem:item
132// -------------------------------------------------------------------------------
133- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
134{
135 return YES;
136}
137
138// -------------------------------------------------------------------------------
139// dataCellForTableColumn:tableColumn:item
140// -------------------------------------------------------------------------------
141- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
142{
143 NSCell *returnCell = [tableColumn dataCell];
144
145 if(item == nil)
146 return returnCell;
147 return returnCell;
148}
149
150// -------------------------------------------------------------------------------
151// textShouldEndEditing:fieldEditor
152// -------------------------------------------------------------------------------
153- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
154{
155 if ([[fieldEditor string] length] == 0)
156 {
157 // don't allow empty node names
158 return NO;
159 }
160 else
161 {
162 return YES;
163 }
164}
165
166// -------------------------------------------------------------------------------
167// shouldEditTableColumn:tableColumn:item
168//
169// Decide to allow the edit of the given outline view "item".
170// -------------------------------------------------------------------------------
171- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
172{
173 return NO;
174}
175
176// -------------------------------------------------------------------------------
177// outlineView:willDisplayCell:forTableColumn:item
178// -------------------------------------------------------------------------------
179- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
180{
181 QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
182 if(!qIdx.isValid())
183 return;
184
185 if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400186 [cell setState:[self currentAccount]->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400187 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS])
188 {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400189 cell.title = [self currentAccount]->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString();
190 [cell setState:[self currentAccount]->codecModel()->videoCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400191 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ])
192 {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400193 cell.title = [self currentAccount]->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString();
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400194 } else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE])
195 {
Alexandre Lision7f3164c2015-06-12 11:45:37 -0400196 cell.title = [self currentAccount]->codecModel()->videoCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString();
Alexandre Lisionf5fc4792015-03-17 09:15:43 -0400197 }
198}
199
200// -------------------------------------------------------------------------------
201// outlineViewSelectionDidChange:notification
202// -------------------------------------------------------------------------------
203- (void)outlineViewSelectionDidChange:(NSNotification *)notification
204{
205 // ask the tree controller for the current selection
206}
207
208@end