simple_prefs.m 63.8 KB
Newer Older
1 2 3
/*****************************************************************************
* simple_prefs.m: Simple Preferences for Mac OS X
*****************************************************************************
4
* Copyright (C) 2008-2014 VLC authors and VideoLAN
5
* $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
*
* Authors: Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
23 24 25
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
26

27
#import "CompatibilityFixes.h"
28 29
#import "simple_prefs.h"
#import "prefs.h"
30
#import <vlc_keys.h>
31
#import <vlc_interface.h>
32
#import <vlc_dialog.h>
33
#import <vlc_modules.h>
34
#import <vlc_plugin.h>
35
#import <vlc_config_cat.h>
36
#import "misc.h"
37 38
#import "intf.h"
#import "AppleRemote.h"
39
#import "CoreInteraction.h"
40

Rafaël Carré's avatar
Rafaël Carré committed
41
#import <Sparkle/Sparkle.h>                        //for o_intf_last_update_lbl
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
static const char *const ppsz_language[] =
{
    "auto",
    "en",
    "ar",
    "bn",
    "pt_BR",
    "en_GB",
    "el",
    "bg",
    "ca",
    "zh_TW",
    "cs",
    "cy",
    "da",
    "nl",
    "fi",
    "et",
    "eu",
    "fr",
    "ga",
    "gd",
    "gl",
    "ka",
    "de",
    "he",
    "hr",
    "hu",
    "hy",
    "is",
    "id",
    "it",
    "ja",
    "ko",
    "lt",
    "mn",
    "ms",
    "nb",
    "nn",
    "kk",
    "km",
    "ne",
    "oc",
    "fa",
    "pl",
    "pt_PT",
    "pa",
    "ro",
    "ru",
    "zh_CN",
    "si",
    "sr",
    "sk",
    "sl",
    "ckb",
    "es",
    "sv",
    "te",
    "tr",
    "uk",
    "vi",
    "wa",
    NULL,
};

static const char *const ppsz_language_text[] =
{
    N_("Auto"),
    "American English",
    "ﻉﺮﺒﻳ",
    "বাংলা",
    "Português Brasileiro",
    "British English",
    "Νέα Ελληνικά",
    "български език",
    "Català",
    "正體中文",
    "Čeština",
    "Cymraeg",
    "Dansk",
    "Nederlands",
    "Suomi",
    "eesti keel",
    "Euskara",
    "Français",
    "Gaeilge",
    "Gàidhlig",
    "Galego",
    "ქართული",
    "Deutsch",
    "עברית",
    "hrvatski",
    "Magyar",
    "հայերեն",
    "íslenska",
    "Bahasa Indonesia",
    "Italiano",
    "日本語",
    "한국어",
    "lietuvių",
    "Монгол хэл",
    "Melayu",
    "Bokmål",
    "Nynorsk",
    "Қазақ тілі",
    "ភាសាខ្មែរ",
    "नेपाली",
    "Occitan",
    "ﻑﺍﺮﺳی",
    "Polski",
    "Português",
    "ਪੰਜਾਬੀ",
    "Română",
    "Русский",
    "简体中文",
    "සිංහල",
    "српски",
    "Slovensky",
    "slovenščina",
    "کوردیی سۆرانی",
    "Español",
    "Svenska",
    "తెలుగు",
    "Türkçe",
    "украї́нська мо́ва",
    "tiếng Việt",
    "Walon",
};

172 173 174
static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
175
static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
176 177 178
static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
179 180 181 182 183

@implementation VLCSimplePrefs

static VLCSimplePrefs *_o_sharedInstance = nil;

184 185
#pragma mark Initialisation

186 187 188 189 190 191 192
+ (VLCSimplePrefs *)sharedInstance
{
    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
}

- (id)init
{
193
    if (_o_sharedInstance)
194
        [self dealloc];
195
    else {
196
        _o_sharedInstance = [super init];
197
        p_intf = VLCIntf;
198
    }
199

200 201 202 203 204 205
    return _o_sharedInstance;
}

- (void)dealloc
{
    [o_currentlyShownCategoryView release];
206 207 208

    [o_hotkeySettings release];
    [o_hotkeyDescriptions release];
209
    [o_hotkeyNames release];
210 211
    [o_hotkeysNonUseableKeys release];

212
    [o_keyInTransition release];
213

214 215 216 217 218 219
    [super dealloc];
}

- (void)awakeFromNib
{
    [self initStrings];
220

221
    /* setup the toolbar */
222
    NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
223 224 225 226 227
    [o_sprefs_toolbar setAllowsUserCustomization: NO];
    [o_sprefs_toolbar setAutosavesConfiguration: NO];
    [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
    [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
    [o_sprefs_toolbar setDelegate: self];
228
    [o_sprefs_win setToolbar: o_sprefs_toolbar];
229

230
    if (!OSX_SNOW_LEOPARD)
231 232
        [o_sprefs_win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];

233 234 235
    [o_hotkeys_listbox setTarget:self];
    [o_hotkeys_listbox setDoubleAction:@selector(hotkeyTableDoubleClick:)];

236
    /* setup useful stuff */
237
    o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:@"Command-c", @"Command-x", @"Command-v", @"Command-a", @"Command-," , @"Command-h", @"Command-Alt-h", @"Command-Shift-o", @"Command-o", @"Command-d", @"Command-n", @"Command-s", @"Command-l", @"Command-r", @"Command-3", @"Command-m", @"Command-w", @"Command-Shift-w", @"Command-Shift-c", @"Command-Shift-p", @"Command-i", @"Command-e", @"Command-Shift-e", @"Command-b", @"Command-Shift-m", @"Command-Ctrl-m", @"Command-?", @"Command-Alt-?", nil] retain];
238 239
}

240
#define CreateToolbarItem(o_name, o_desc, o_img, sel) \
241 242
    o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
static inline NSToolbarItem *
243
create_toolbar_item(NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector)
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
{
    NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \

    [o_toolbarItem setLabel: o_name];
    [o_toolbarItem setPaletteLabel: o_desc];

    [o_toolbarItem setToolTip: o_desc];
    [o_toolbarItem setImage: [NSImage imageNamed: o_img]];

    [o_toolbarItem setTarget: target];
    [o_toolbarItem setAction: selector];

    [o_toolbarItem setEnabled: YES];
    [o_toolbarItem setAutovalidates: YES];

    return o_toolbarItem;
}

262 263
- (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
      itemForItemIdentifier: (NSString *)o_itemIdent
264 265 266
  willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
{
    NSToolbarItem *o_toolbarItem = nil;
267

268 269 270
    if ([o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier]) {
        CreateToolbarItem(_NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings);
    } else if ([o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier]) {
271
        CreateToolbarItem(_NS("Audio"), _NS("Audio Settings"), @"spref_cone_Audio_64", showAudioSettings);
272
    } else if ([o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier]) {
273
        CreateToolbarItem(_NS("Video"), _NS("Video Settings"), @"spref_cone_Video_64", showVideoSettings);
274
    } else if ([o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier]) {
275
        CreateToolbarItem(_NS(SUBPIC_TITLE), _NS("Subtitle & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings);
276
    } else if ([o_itemIdent isEqual: VLCInputSettingToolbarIdentifier]) {
277
        CreateToolbarItem(_NS(INPUT_TITLE), _NS("Input & Codec Settings"), @"spref_cone_Input_64", showInputSettings);
278 279
    } else if ([o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier]) {
        CreateToolbarItem(_NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings);
280 281
    }

282 283 284 285 286
    return o_toolbarItem;
}

- (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
{
287
    return [NSArray arrayWithObjects:VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
288
             VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier,
289
             NSToolbarFlexibleSpaceItemIdentifier, nil];
290 291 292 293
}

- (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
{
294
    return [NSArray arrayWithObjects:VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
295
             VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier,
296
             NSToolbarFlexibleSpaceItemIdentifier, nil];
297 298 299 300
}

- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
301 302
    return [NSArray arrayWithObjects:VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
             VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
303 304 305 306
}

- (void)initStrings
{
307
    /* audio */
308
    [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
David Fuhrmann's avatar
David Fuhrmann committed
309
    [o_audio_effects_box setTitle: _NS("Audio Effects")];
310
    [o_audio_enable_ckb setTitle: _NS("Enable audio")];
311 312 313 314 315 316 317
    [o_audio_general_box setTitle: _NS("General Audio")];
    [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
    [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
    [o_audio_lastpwd_txt setStringValue: _NS("Password")];
    [o_audio_lastuser_txt setStringValue: _NS("User name")];
    [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
    [o_audio_visual_txt setStringValue: _NS("Visualization")];
318 319
    [o_audio_autosavevol_yes_bcell setTitle: _NS("Keep audio level between sessions")];
    [o_audio_autosavevol_no_bcell setTitle: _NS("Always reset audio start level to:")];
320 321 322 323 324 325 326 327 328 329 330 331

    /* hotkeys */
    [o_hotkeys_change_btn setTitle: _NS("Change")];
    [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
    [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
    [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
    [o_hotkeys_clear_btn setTitle: _NS("Clear")];
    [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
    [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
    [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];

    /* input */
332 333 334
    [o_input_record_box setTitle: _NS("Record directory or filename")];
    [o_input_record_btn setTitle: _NS("Browse...")];
    [o_input_record_btn setToolTip: _NS("Directory or filename where the records will be stored")];
335 336 337
    [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
    [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
    [o_input_caching_box setTitle: _NS("Caching")];
338
    [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
339 340
    [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
    [o_input_net_box setTitle: _NS("Network")];
341
    [o_input_avcodec_hw_txt setStringValue: _NS("Hardware Acceleration")];
342 343
    [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
    [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
344
    [o_input_skipLoop_txt setStringValue: _NS("Skip the loop filter for H.264 decoding")];
345
    [o_input_mkv_preload_dir_ckb setTitle: _NS("Preload MKV files in the same directory")];
346 347 348 349 350 351 352
    [o_input_urlhandler_btn setTitle: _NS("Edit default application settings for network protocols")];

    /* url handler */
    [o_urlhandler_title_txt setStringValue: _NS("Open network streams using the following protocols")];
    [o_urlhandler_subtitle_txt setStringValue: _NS("Note that these are system-wide settings.")];
    [o_urlhandler_save_btn setTitle: _NS("Save")];
    [o_urlhandler_cancel_btn setTitle: _NS("Cancel")];
353 354

    /* interface */
355
    [o_intf_language_txt setStringValue: _NS("Language")];
356 357 358
    [o_intf_style_txt setStringValue: _NS("Interface style")];
    [o_intf_style_dark_bcell setTitle: _NS("Dark")];
    [o_intf_style_bright_bcell setTitle: _NS("Bright")];
359
    [o_intf_embedded_ckb setTitle: _NS("Show video within the main window")];
360
    [o_intf_nativefullscreen_ckb setTitle: _NS("Use the native fullscreen mode")];
361 362
    [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
    [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
363
    [o_intf_appleremote_ckb setTitle: _NS("Control playback with the Apple Remote")];
364
    [o_intf_appleremote_sysvol_ckb setTitle: _NS("Control system volume with the Apple Remote")];
365
    [o_intf_mediakeys_ckb setTitle: _NS("Control playback with media keys")];
366
    [o_intf_art_ckb setTitle: _NS("Allow metadata network access")];
367 368
    [o_intf_update_ckb setTitle: _NS("Automatically check for updates")];
    [o_intf_last_update_lbl setStringValue: @""];
369
    [o_intf_enableGrowl_ckb setTitle: _NS("Enable Growl notifications (on playlist item change)")];
370 371
    [o_intf_autoresize_ckb setTitle: _NS("Resize interface to the native video size")];
    [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
372 373
    [o_intf_luahttp_box setTitle:_NS("Lua HTTP")];
    [o_intf_luahttppwd_lbl setStringValue:_NS("Password")];
374
    [o_intf_pauseitunes_lbl setStringValue:_NS("Control external music players")];
375
    [o_intf_continueplayback_lbl setStringValue:_NS("Continue playback")];
376

377 378 379
    /* Subtitles and OSD */
    [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
    [o_osd_font_box setTitle: _NS("Display Settings")];
Pierre d'Herbemont's avatar
Pierre d'Herbemont committed
380
    [o_osd_font_btn setTitle: _NS("Choose...")];
381 382
    [o_osd_font_color_txt setStringValue: _NS("Font color")];
    [o_osd_font_size_txt setStringValue: _NS("Font size")];
383
    [o_osd_font_txt setStringValue: _NS("Font")];
384 385
    [o_osd_lang_box setTitle: _NS("Subtitle languages")];
    [o_osd_lang_txt setStringValue: _NS("Preferred subtitle language")];
386 387
    [o_osd_osd_box setTitle: _NS("On Screen Display")];
    [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
388
    [o_osd_opacity_txt setStringValue: _NS("Opacity")];
389 390 391
    [o_osd_forcebold_ckb setTitle: _NS("Force bold")];
    [o_osd_outline_color_txt setStringValue: _NS("Outline color")];
    [o_osd_outline_thickness_txt setStringValue: _NS("Outline thickness")];
392 393 394

    /* video */
    [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
395
    [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
396
    [o_video_display_box setTitle: _NS("Display")];
397
    [o_video_enable_ckb setTitle: _NS("Enable video")];
398
    [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
399
    [o_video_videodeco_ckb setTitle: _NS("Window decorations")];
400
    [o_video_onTop_ckb setTitle: _NS("Float on Top")];
401 402 403 404 405 406 407
    [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
    [o_video_snap_box setTitle: _NS("Video snapshots")];
    [o_video_snap_folder_btn setTitle: _NS("Browse...")];
    [o_video_snap_folder_txt setStringValue: _NS("Folder")];
    [o_video_snap_format_txt setStringValue: _NS("Format")];
    [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
    [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
408 409 410
    [o_video_deinterlace_txt setStringValue: _NS("Deinterlace")];
    [o_video_deinterlace_mode_txt setStringValue: _NS("Deinterlace mode")];
    [o_video_video_box setTitle: _NS("Video")];
411

412
    /* generic stuff */
413
    [o_sprefs_showAll_btn setTitle: _NS("Show All")];
414
    [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
415
    [o_sprefs_reset_btn setTitle: _NS("Reset All")];
416 417
    [o_sprefs_save_btn setTitle: _NS("Save")];
    [o_sprefs_win setTitle: _NS("Preferences")];
418 419
}

420 421
/* TODO: move this part to core */
#define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
422
static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_name)
423 424 425
{
    module_config_t *p_config;

426
    p_config = config_FindConfig(p_this, psz_name);
427 428

    /* sanity checks */
429 430
    if (!p_config) {
        msg_Err(p_this, "option %s does not exist", psz_name);
431 432 433
        return NULL;
    }

434
    if (p_config->psz_longtext)
435
        return p_config->psz_longtext;
436
    else if (p_config->psz_text)
437 438
        return p_config->psz_text;
    else
439
        msg_Warn(p_this, "option %s does not include any help", psz_name);
440 441 442 443

    return NULL;
}

444 445 446
#pragma mark -
#pragma mark Setup controls

447 448 449 450 451
- (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
{
    module_config_t *p_item;

    [object removeAllItems];
452
    p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
453
    /* serious problem, if no item found */
454
    assert(p_item);
455

456 457 458 459 460 461 462 463 464
    char **values, **texts;
    ssize_t count = config_GetPszChoices(VLC_OBJECT(VLCIntf), name,
                                         &values, &texts);
    if (count < 0) {
        msg_Err(p_intf, "Cannot get choices for %s", name);
        return;
    }
    for (ssize_t i = 0; i < count && texts; i++) {
        if (texts[i] == NULL || values[i] == NULL)
465
            continue;
466 467 468 469 470 471 472 473 474 475 476

        if (strcmp(texts[i], "") != 0) {
            NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle: toNSStr(texts[i]) action: NULL keyEquivalent: @""];
            [mi setRepresentedObject: toNSStr(values[i])];
            [[object menu] addItem: [mi autorelease]];

            if (p_item->value.psz && !strcmp(p_item->value.psz, values[i]))
                [object selectItem: [object lastItem]];
            
        } else {
            [[object menu] addItem: [NSMenuItem separatorItem]];
477
        }
478 479 480

        free(texts[i]);
        free(values[i]);
481
    }
482 483 484 485 486 487 488 489 490 491 492 493

    free(texts);
    free(values);

    if (p_item->psz_longtext)
        [object setToolTip: _NS(p_item->psz_longtext)];
}

// just for clarification that this is a module list
- (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
{
    [self setupButton: object forStringList: name];
494 495 496 497 498 499 500
}

- (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
{
    module_config_t *p_item;

    [object removeAllItems];
501
    p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
502 503

    /* serious problem, if no item found */
504
    assert(p_item);
505

506 507 508 509 510 511
    int64_t *values;
    char **texts;
    ssize_t count = config_GetIntChoices(VLC_OBJECT(VLCIntf), name, &values, &texts);
    for (ssize_t i = 0; i < count; i++) {
        NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle: toNSStr(texts[i]) action: NULL keyEquivalent: @""];
        [mi setRepresentedObject:[NSNumber numberWithInt:values[i]]];
512
        [[object menu] addItem: [mi autorelease]];
513 514

        if (p_item->value.i == values[i])
515
            [object selectItem:[object lastItem]];
516 517

        free(texts[i]);
518
    }
519 520 521 522
    free(texts);

    if (p_item->psz_longtext)
        [object setToolTip: _NS(p_item->psz_longtext)];
523 524
}

525 526
- (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
{
527
    [object setState: config_GetInt(p_intf, name)];
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
528
    [object setToolTip: _NS(config_GetLabel(p_intf, name))];
529 530
}

531 532
- (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
{
533
    char *psz_tmp = config_GetPsz(p_intf, psz_option);
534
    [o_object setStringValue: [NSString stringWithUTF8String:psz_tmp ?: ""]];
535 536
    [o_object setToolTip: _NS(config_GetLabel(p_intf, psz_option))];
    free(psz_tmp);
537 538
}

539 540 541
- (void)resetControls
{
    module_config_t *p_item;
542
    int i, y = 0;
543 544 545 546 547
    char *psz_tmp;

    /**********************
     * interface settings *
     **********************/
548 549 550 551 552 553 554 555 556 557 558 559
    NSUInteger sel = 0;
    const char *pref = NULL;
    pref = [[[NSUserDefaults standardUserDefaults] objectForKey:@"language"] UTF8String];
    for (int x = 0; ppsz_language[x] != NULL; x++) {
        [o_intf_language_pop addItemWithTitle:[NSString stringWithUTF8String:ppsz_language_text[x]]];
        if (pref) {
            if (!strcmp(ppsz_language[x], pref))
                sel = x;
        }
    }
    [o_intf_language_pop selectItemAtIndex:sel];

560
    [self setupButton: o_intf_art_ckb forBoolValue: "metadata-network-access"];
561

562
    [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
563

564
    [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
565 566 567 568
    BOOL b_correct_sdk = NO;
#ifdef MAC_OS_X_VERSION_10_7
    b_correct_sdk = YES;
#endif
569
    if (!(b_correct_sdk && !OSX_SNOW_LEOPARD)) {
570 571 572 573
        [o_intf_nativefullscreen_ckb setState: NSOffState];
        [o_intf_nativefullscreen_ckb setEnabled: NO];
    }

574
    [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
575

576
    [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
577
    [self setupButton: o_intf_appleremote_sysvol_ckb forBoolValue: "macosx-appleremote-sysvol"];
578

579
    [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
580
    if ([[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL)
581 582 583
        [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
    else
        [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
584
    psz_tmp = config_GetPsz(p_intf, "control");
585
    if (psz_tmp) {
586 587 588
        [o_intf_enableGrowl_ckb setState: (NSInteger)strstr(psz_tmp, "growl")];
        free(psz_tmp);
    } else
589
        [o_intf_enableGrowl_ckb setState: NSOffState];
590
    if (config_GetInt(p_intf, "macosx-interfacestyle")) {
591
        [o_intf_style_dark_bcell setState: YES];
592
        [o_intf_style_bright_bcell setState: NO];
593
    } else {
594
        [o_intf_style_dark_bcell setState: NO];
595 596
        [o_intf_style_bright_bcell setState: YES];
    }
597 598
    [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
    [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
599
    [self setupField: o_intf_luahttppwd_fld forOption: "http-password"];
600
    [self setupButton: o_intf_pauseitunes_pop forIntList: "macosx-control-itunes"];
601
    [self setupButton: o_intf_continueplayback_pop forIntList: "macosx-continue-playback"];
602 603 604 605

    /******************
     * audio settings *
     ******************/
606
    [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
607

608
    if (config_GetInt(p_intf, "volume-save")) {
609 610 611 612 613 614 615
        [o_audio_autosavevol_yes_bcell setState: NSOnState];
        [o_audio_autosavevol_no_bcell setState: NSOffState];
        [o_audio_vol_fld setEnabled: NO];
        [o_audio_vol_sld setEnabled: NO];

        [o_audio_vol_sld setIntValue: 100];
        [o_audio_vol_fld setIntValue: 100];
616
    } else {
617 618 619 620 621
        [o_audio_autosavevol_yes_bcell setState: NSOffState];
        [o_audio_autosavevol_no_bcell setState: NSOnState];
        [o_audio_vol_fld setEnabled: YES];
        [o_audio_vol_sld setEnabled: YES];

622
        i = var_InheritInteger(p_intf, "auhal-volume");
623
        i = i * 200. / AOUT_VOLUME_MAX;
624 625 626
        [o_audio_vol_sld setIntValue: i];
        [o_audio_vol_fld setIntValue: i];
    }
627

628
    [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
629

630
    [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
631
    [self setupField: o_audio_lang_fld forOption: "audio-language"];
632

633
    [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
634

635
    /* Last.FM is optional */
636
    if (module_exists("audioscrobbler")) {
637 638
        [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
        [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
639

640
        if (config_ExistIntf(VLC_OBJECT(p_intf), "audioscrobbler")) {
641
            [o_audio_last_ckb setState: NSOnState];
642
            [o_audio_lastuser_fld setEnabled: YES];
643
            [o_audio_lastpwd_sfld setEnabled: YES];
644
        } else {
645
            [o_audio_last_ckb setState: NSOffState];
646
            [o_audio_lastuser_fld setEnabled: NO];
647
            [o_audio_lastpwd_sfld setEnabled: NO];
648
        }
649
    } else
650
        [o_audio_last_ckb setEnabled: NO];
651 652 653 654

    /******************
     * video settings *
     ******************/
655 656 657 658 659
    [self setupButton: o_video_enable_ckb forBoolValue: "video"];
    [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
    [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
    [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
    [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
660
    [self setupButton: o_video_videodeco_ckb forBoolValue: "video-deco"];
661

662
    [o_video_device_pop removeAllItems];
663 664 665 666
    i = 0;
    y = [[NSScreen screens] count];
    [o_video_device_pop addItemWithTitle: _NS("Default")];
    [[o_video_device_pop lastItem] setTag: 0];
667
    while (i < y) {
668
        NSRect s_rect = [[[NSScreen screens] objectAtIndex:i] frame];
669
        [o_video_device_pop addItemWithTitle:
670 671
         [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
                   (int)s_rect.size.width, (int)s_rect.size.height]];
672
        [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex:i] displayID]];
673 674 675
        i++;
    }
    [o_video_device_pop selectItemAtIndex: 0];
676
    [o_video_device_pop selectItemWithTag: config_GetInt(p_intf, "macosx-vdev")];
677

678 679 680
    [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
    [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
    [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
681
    [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
682 683
    [self setupButton: o_video_deinterlace_pop forIntList: "deinterlace"];
    [self setupButton: o_video_deinterlace_mode_pop forStringList: "deinterlace-mode"];
684

685 686 687
    // set lion fullscreen mode restrictions
    [self enableLionFullscreenMode: [o_intf_nativefullscreen_ckb state]];

688 689 690
    /***************************
     * input & codecs settings *
     ***************************/
691
    [self setupField: o_input_record_fld forOption:"input-record-path"];
692 693
    [o_input_postproc_fld setIntValue: config_GetInt(p_intf, "postproc-q")];
    [o_input_postproc_fld setToolTip: _NS(config_GetLabel(p_intf, "postproc-q"))];
694
    [self setupButton: o_input_avcodec_hw_pop forModuleList: "avcodec-hw"];
695

696
    [self setupButton: o_input_avi_pop forIntList: "avi-index"];
697

698
    [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
Rafaël Carré's avatar
Rafaël Carré committed
699
    [self setupButton: o_input_skipLoop_pop forIntList: "avcodec-skiploopfilter"];
700

701 702
    [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];

703
    [o_input_cachelevel_pop removeAllItems];
704 705
    [o_input_cachelevel_pop addItemsWithTitles: [NSArray arrayWithObjects:_NS("Custom"), _NS("Lowest latency"),
     _NS("Low latency"), _NS("Normal"), _NS("High latency"), _NS("Higher latency"), nil]];
706 707 708 709
    [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
    [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
    [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
    [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
710 711
    [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
    [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
712

713
    #define TestCaC(name, factor) \
714
    b_cache_equal =  b_cache_equal && \
715
    (i_cache * factor == config_GetInt(p_intf, name));
716 717 718

    /* Select the accurate value of the PopupButton */
    bool b_cache_equal = true;
719
    int i_cache = config_GetInt(p_intf, "file-caching");
720

721 722 723 724
    TestCaC("network-caching", 10/3);
    TestCaC("disc-caching", 1);
    TestCaC("live-caching", 1);
    if (b_cache_equal) {
725
        [o_input_cachelevel_pop selectItemWithTag: i_cache];
726
        [o_input_cachelevel_custom_txt setHidden: YES];
727
    } else {
728
        [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
729 730
        [o_input_cachelevel_custom_txt setHidden: NO];
    }
731
    #undef TestCaC
732 733 734 735

    /*********************
     * subtitle settings *
     *********************/
736
    [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
737

738
    [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
739
    [self setupField: o_osd_lang_fld forOption: "sub-language" ];
740

741 742 743
    [self setupField: o_osd_font_fld forOption: "freetype-font"];
    [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
    [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
744
    i = config_GetInt(p_intf, "freetype-opacity") * 100.0 / 255.0 + 0.5;
745 746
    [o_osd_opacity_fld setIntValue: i];
    [o_osd_opacity_sld setIntValue: i];
747
    [o_osd_opacity_sld setToolTip: _NS(config_GetLabel(p_intf, "freetype-opacity"))];
748 749
    [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
    [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
750 751
    [self setupButton: o_osd_outline_color_pop forIntList: "freetype-outline-color"];
    [self setupButton: o_osd_outline_thickness_pop forIntList: "freetype-outline-thickness"];
752

753 754 755
    /********************
     * hotkeys settings *
     ********************/
756
    const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
hartman's avatar
hartman committed
757
    [o_hotkeySettings release];
758 759
    o_hotkeySettings = [[NSMutableArray alloc] init];
    NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
760
    NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
761

762 763
    /* Get the main Module */
    module_t *p_main = module_get_main();
764
    assert(p_main);
765 766
    unsigned confsize;
    module_config_t *p_config;
767

768
    p_config = module_config_get (p_main, &confsize);
769

770
    for (size_t i = 0; i < confsize; i++) {
771
        module_config_t *p_item = p_config + i;
772

773 774 775 776
        if (CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
           && !strncmp(p_item->psz_name , "key-", 4)
           && !EMPTY_STR(p_item->psz_text)) {
            [o_tempArray_desc addObject: _NS(p_item->psz_text)];
777
            [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
778
            if (p_item->value.psz)
779
                [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
780 781 782
            else
                [o_hotkeySettings addObject: [NSString string]];
        }
783
    }
784
    module_config_free (p_config);
785

786
    [o_hotkeyDescriptions release];
787 788
    o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
    [o_tempArray_desc release];
789 790 791
    [o_hotkeyNames release];
    o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
    [o_tempArray_names release];
792
    [o_hotkeys_listbox reloadData];
793 794
}

795 796 797
#pragma mark -
#pragma mark General actions

798 799 800
- (void)showSimplePrefs
{
    /* we want to show the interface settings, if no category was chosen */
801
    if ([[o_sprefs_win toolbar] selectedItemIdentifier] == nil) {
802
        [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
803 804
        [self showInterfaceSettings];
    }
805

806
    [self resetControls];
807

808
    [o_sprefs_win center];
809 810 811
    [o_sprefs_win makeKeyAndOrderFront: self];
}

812 813 814 815 816 817
- (void)showSimplePrefsWithLevel:(NSInteger)i_window_level
{
    [o_sprefs_win setLevel: i_window_level];
    [self showSimplePrefs];
}

818 819
- (IBAction)buttonAction:(id)sender
{
820
    if (sender == o_sprefs_cancel_btn) {
821
        [[NSFontPanel sharedFontPanel] close];
822
        [o_sprefs_win orderOut: sender];
823
    } else if (sender == o_sprefs_save_btn) {
824
        [self saveChangedSettings];
825
        [[NSFontPanel sharedFontPanel] close];
826
        [o_sprefs_win orderOut: sender];
827
    } else if (sender == o_sprefs_showAll_btn) {
828
        [o_sprefs_win orderOut: self];