Commit 859d98f7 authored by Alexandre Lision's avatar Alexandre Lision

audio prefs: refresh codec list ui

Tuleap: #338
Change-Id: I29ce733106935e4a0e7402f6ed79c8b5552e7fd4
parent 9601ed06
......@@ -16,11 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define COLUMNID_STATE @"AudioStateColumn"
#define COLUMNID_CODECS @"AudioCodecsColumn"
#define COLUMNID_FREQ @"AudioFrequencyColumn"
#define COLUMNID_BITRATE @"AudioBitrateColumn"
#import "AccAudioVC.h"
///Qt
......@@ -48,8 +43,13 @@
@synthesize codecsView;
@synthesize ringtonePopUpButton, enableRingtone, playRingtone;
- (void)awakeFromNib
NSInteger const TAG_CHECK = 100;
NSInteger const TAG_NAME = 200;
NSInteger const TAG_FREQUENCY = 300;
- (void) loadView
{
[super loadView];
NSLog(@"INIT Audio VC");
QObject::connect(AccountModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
......@@ -75,15 +75,9 @@
});
}
- (Account*) currentAccount
{
auto accIdx = AccountModel::instance().selectionModel()->currentIndex();
return AccountModel::instance().getAccountByModelIndex(accIdx);
}
- (void)loadAccount
{
auto account = [self currentAccount];
auto account = AccountModel::instance().selectedAccount();
treeController = [[QNSTreeController alloc] initWithQModel:account->codecModel()->audioCodecs()];
[treeController setAvoidsEmptySelection:NO];
......@@ -102,19 +96,19 @@
}
- (IBAction)startStopRingtone:(id)sender {
auto qIdx = RingtoneModel::instance().selectionModel([self currentAccount])->currentIndex();
auto qIdx = RingtoneModel::instance().selectionModel(AccountModel::instance().selectedAccount())->currentIndex();
RingtoneModel::instance().play(qIdx);
}
- (IBAction)toggleRingtoneEnabled:(id)sender {
[self currentAccount]->setRingtoneEnabled([sender state]);
AccountModel::instance().selectedAccount()->setRingtoneEnabled([sender state]);
[ringtonePopUpButton setEnabled:[sender state]];
}
- (IBAction)chooseRingtone:(id)sender {
int index = [sender indexOfSelectedItem];
QModelIndex qIdx = RingtoneModel::instance().index(index, 0);
RingtoneModel::instance().selectionModel([self currentAccount])->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect);
RingtoneModel::instance().selectionModel(AccountModel::instance().selectedAccount())->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect);
}
- (IBAction)moveUp:(id)sender {
......@@ -123,8 +117,8 @@
if(!qIdx.isValid())
return;
QMimeData* mime = [self currentAccount]->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
[self currentAccount]->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex());
QMimeData* mime = AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() - 1, 0, QModelIndex());
}
}
......@@ -134,88 +128,39 @@
if(!qIdx.isValid())
return;
QMimeData* mime = [self currentAccount]->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
[self currentAccount]->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex());
QMimeData* mime = AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->mimeData(QModelIndexList() << qIdx);
AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->dropMimeData(mime, Qt::MoveAction, qIdx.row() + 1, 0, QModelIndex());
}
}
- (IBAction)toggleCodec:(NSOutlineView*)sender {
NSInteger row = [sender clickedRow];
NSTableColumn *col = [sender tableColumnWithIdentifier:COLUMNID_STATE];
NSButtonCell *cell = [col dataCellForRow:row];
QModelIndex qIdx = [self currentAccount]->codecModel()->audioCodecs()->index(row, 0, QModelIndex());
[self currentAccount]->codecModel()->audioCodecs()->setData(qIdx, cell.state == NSOnState ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
- (IBAction)toggleCodec:(NSButton*)sender {
NSInteger row = [codecsView rowForView:sender];
QModelIndex qIdx = AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->index(row, 0, QModelIndex());
AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->setData(qIdx, sender.state == NSOnState ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
}
#pragma mark - NSOutlineViewDelegate methods
// -------------------------------------------------------------------------------
// shouldSelectItem:item
// -------------------------------------------------------------------------------
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
{
return YES;
}
// -------------------------------------------------------------------------------
// dataCellForTableColumn:tableColumn:item
// -------------------------------------------------------------------------------
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
NSCell *returnCell = [tableColumn dataCell];
NSTableView* result = [outlineView makeViewWithIdentifier:@"CodecView" owner:self];
if(item == nil)
return returnCell;
return returnCell;
}
// -------------------------------------------------------------------------------
// textShouldEndEditing:fieldEditor
// -------------------------------------------------------------------------------
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
if ([[fieldEditor string] length] == 0)
{
// don't allow empty node names
return NO;
}
else
{
return YES;
}
}
// -------------------------------------------------------------------------------
// shouldEditTableColumn:tableColumn:item
//
// Decide to allow the edit of the given outline view "item".
// -------------------------------------------------------------------------------
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return NO;
}
// -------------------------------------------------------------------------------
// outlineView:willDisplayCell:forTableColumn:item
// -------------------------------------------------------------------------------
- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
if(!qIdx.isValid())
return;
if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) {
[cell setState:[self currentAccount]->codecModel()->audioCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_CODECS])
{
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString();
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_FREQ])
{
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString();
} else if ([[tableColumn identifier] isEqualToString:COLUMNID_BITRATE])
{
cell.title = [self currentAccount]->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::BITRATE).toString().toNSString();
}
return result;
NSTextField* name = [result viewWithTag:TAG_NAME];
NSTextField* frequency = [result viewWithTag:TAG_FREQUENCY];
NSButton* check = [result viewWithTag:TAG_CHECK];
[name setStringValue:AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::NAME).toString().toNSString()];
[frequency setStringValue:[NSString stringWithFormat:@"%@ Hz", AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->data(qIdx, CodecModel::Role::SAMPLERATE).toString().toNSString()]];
[check setState:AccountModel::instance().selectedAccount()->codecModel()->audioCodecs()->data(qIdx, Qt::CheckStateRole).value<BOOL>()?NSOnState:NSOffState];
return result;
}
#pragma mark - NSMenuDelegate methods
......@@ -226,7 +171,7 @@
qIdx = RingtoneModel::instance().index(index, 0);
[item setTitle:RingtoneModel::instance().data(qIdx, Qt::DisplayRole).toString().toNSString()];
if (qIdx == RingtoneModel::instance().selectionModel([self currentAccount])->currentIndex()) {
if (qIdx == RingtoneModel::instance().selectionModel(AccountModel::instance().selectedAccount())->currentIndex()) {
[ringtonePopUpButton selectItem:item];
}
return YES;
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AccGeneralVC">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment