[vlc-commits] macosx: Add option to enable http server from simple prefs

David Fuhrmann git at videolan.org
Mon Sep 18 15:30:23 CEST 2017


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Mon Sep 18 13:35:05 2017 +0200| [f611e83908e1073bf7e67dbfe8fa29e1003e68d5] | committer: David Fuhrmann

macosx: Add option to enable http server from simple prefs

In addition to the existing password field, add a checkbox to
enable the http module.
Refactor code to enable / disable modules.

closes #17914

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f611e83908e1073bf7e67dbfe8fa29e1003e68d5
---

 modules/gui/macosx/UI/SimplePreferences.xib   | 41 ++++++++++-----
 modules/gui/macosx/VLCSimplePrefsController.h |  1 +
 modules/gui/macosx/VLCSimplePrefsController.m | 76 ++++++++++++++++-----------
 3 files changed, 74 insertions(+), 44 deletions(-)

diff --git a/modules/gui/macosx/UI/SimplePreferences.xib b/modules/gui/macosx/UI/SimplePreferences.xib
index de1a4a7585..4e5ee01d0e 100644
--- a/modules/gui/macosx/UI/SimplePreferences.xib
+++ b/modules/gui/macosx/UI/SimplePreferences.xib
@@ -68,9 +68,11 @@
                 <outlet property="intf_continueplaybackLabel" destination="3919" id="ZJO-qY-UCq"/>
                 <outlet property="intf_continueplaybackPopup" destination="3920" id="dZ3-SI-SCp"/>
                 <outlet property="intf_enableNotificationsCheckbox" destination="3564" id="IIA-ce-g61"/>
+                <outlet property="intf_enableluahttpCheckbox" destination="lpZ-9y-Vfn" id="ieR-ZH-mcd"/>
                 <outlet property="intf_languageLabel" destination="3892" id="klM-r2-XKf"/>
                 <outlet property="intf_languagePopup" destination="3900" id="USp-A1-Aut"/>
                 <outlet property="intf_last_updateLabel" destination="3560" id="9TG-0W-rqH"/>
+                <outlet property="intf_luahttpBox" destination="drh-ot-Vyn" id="YKi-8n-s8a"/>
                 <outlet property="intf_luahttppwdLabel" destination="3875" id="zl0-da-lHe"/>
                 <outlet property="intf_luahttppwdTextField" destination="3884" id="dxk-zl-ZLZ"/>
                 <outlet property="intf_mediakeysCheckbox" destination="3543" id="qh4-7b-Dff"/>
@@ -246,11 +248,11 @@ Gw
         </window>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="2311" userLabel="Interface">
-            <rect key="frame" x="0.0" y="0.0" width="570" height="571"/>
+            <rect key="frame" x="0.0" y="0.0" width="570" height="597"/>
             <autoresizingMask key="autoresizingMask"/>
             <subviews>
                 <box title="General Settings" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="kup-aY-Wqq">
-                    <rect key="frame" x="18" y="433" width="536" height="117"/>
+                    <rect key="frame" x="18" y="459" width="536" height="117"/>
                     <view key="contentView" id="wFl-aV-3Hn">
                         <rect key="frame" x="1" y="1" width="534" height="101"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -352,7 +354,7 @@ Gw
                     </constraints>
                 </box>
                 <box title="Privacy / Network Interaction" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="2318">
-                    <rect key="frame" x="18" y="86" width="532" height="107"/>
+                    <rect key="frame" x="18" y="112" width="532" height="107"/>
                     <view key="contentView" id="nnH-Tj-ON7">
                         <rect key="frame" x="1" y="1" width="530" height="91"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -403,7 +405,7 @@ Gw
                     </constraints>
                 </box>
                 <box title="Playback control" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="CZP-ZN-k6p">
-                    <rect key="frame" x="18" y="287" width="532" height="142"/>
+                    <rect key="frame" x="18" y="313" width="532" height="142"/>
                     <view key="contentView" id="gj4-zO-E26">
                         <rect key="frame" x="1" y="1" width="530" height="126"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -480,7 +482,7 @@ Gw
                     </constraints>
                 </box>
                 <box title="Playback behaviour" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="EKZ-iB-CMo">
-                    <rect key="frame" x="18" y="197" width="532" height="86"/>
+                    <rect key="frame" x="18" y="223" width="532" height="86"/>
                     <view key="contentView" id="BMS-wa-oJS">
                         <rect key="frame" x="1" y="1" width="530" height="70"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -530,14 +532,14 @@ Gw
                         <constraint firstAttribute="height" constant="82" id="rRS-wr-FCF"/>
                     </constraints>
                 </box>
-                <box title="lua" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="drh-ot-Vyn">
-                    <rect key="frame" x="16" y="15" width="536" height="64"/>
+                <box title="HTTP Server" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="drh-ot-Vyn">
+                    <rect key="frame" x="16" y="16" width="536" height="89"/>
                     <view key="contentView" id="Who-VF-GbQ">
-                        <rect key="frame" x="1" y="1" width="534" height="48"/>
+                        <rect key="frame" x="1" y="1" width="534" height="73"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="3875">
-                                <rect key="frame" x="18" y="16" width="63" height="17"/>
+                                <rect key="frame" x="18" y="20" width="63" height="17"/>
                                 <textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Password" id="3876">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -545,7 +547,7 @@ Gw
                                 </textFieldCell>
                             </textField>
                             <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3884" customClass="NSSecureTextField">
-                                <rect key="frame" x="225" y="13" width="288" height="22"/>
+                                <rect key="frame" x="225" y="17" width="288" height="22"/>
                                 <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="3885">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@@ -556,15 +558,28 @@ Gw
                                     <outlet property="delegate" destination="-2" id="CTK-cN-vZp"/>
                                 </connections>
                             </textField>
+                            <button translatesAutoresizingMaskIntoConstraints="NO" id="lpZ-9y-Vfn">
+                                <rect key="frame" x="14" y="47" width="187" height="18"/>
+                                <buttonCell key="cell" type="check" title="Enable VLC HTTP interface" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Nby-oq-jkQ">
+                                    <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="interfaceSettingChanged:" target="-2" id="dVG-jB-ra3"/>
+                                </connections>
+                            </button>
                         </subviews>
                         <constraints>
+                            <constraint firstItem="3884" firstAttribute="leading" secondItem="3875" secondAttribute="trailing" constant="146" id="5vp-F0-WQz"/>
                             <constraint firstItem="3875" firstAttribute="centerY" secondItem="3884" secondAttribute="centerY" id="8EM-8N-p6j"/>
                             <constraint firstItem="3884" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="3875" secondAttribute="trailing" constant="17" id="Fcc-mA-ItG"/>
-                            <constraint firstItem="3884" firstAttribute="centerY" secondItem="Who-VF-GbQ" secondAttribute="centerY" id="iq0-gO-Orm"/>
+                            <constraint firstItem="lpZ-9y-Vfn" firstAttribute="leading" secondItem="Who-VF-GbQ" secondAttribute="leading" constant="16" id="PWI-C5-4nk"/>
+                            <constraint firstItem="lpZ-9y-Vfn" firstAttribute="top" secondItem="Who-VF-GbQ" secondAttribute="top" constant="10" id="VqA-8L-DMQ"/>
+                            <constraint firstItem="3875" firstAttribute="top" secondItem="lpZ-9y-Vfn" secondAttribute="bottom" constant="12" id="g8b-hJ-m2Y"/>
                         </constraints>
                     </view>
                     <constraints>
-                        <constraint firstAttribute="height" constant="60" id="Hpz-Ev-sCZ"/>
+                        <constraint firstAttribute="height" constant="85" id="Hpz-Ev-sCZ"/>
                         <constraint firstAttribute="width" constant="530" id="yQf-88-Z0F"/>
                     </constraints>
                 </box>
@@ -591,7 +606,7 @@ Gw
                 <constraint firstItem="3892" firstAttribute="leading" secondItem="3919" secondAttribute="leading" id="vfy-GO-DCp"/>
                 <constraint firstItem="kup-aY-Wqq" firstAttribute="leading" secondItem="2311" secondAttribute="leading" constant="21" id="xN8-XW-D0e"/>
             </constraints>
-            <point key="canvasLocation" x="245" y="252.5"/>
+            <point key="canvasLocation" x="245" y="265.5"/>
         </customView>
         <customView id="2330" userLabel="Audio">
             <rect key="frame" x="0.0" y="0.0" width="569" height="432"/>
diff --git a/modules/gui/macosx/VLCSimplePrefsController.h b/modules/gui/macosx/VLCSimplePrefsController.h
index 7c0e66e1cb..0ac59019a5 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.h
+++ b/modules/gui/macosx/VLCSimplePrefsController.h
@@ -114,6 +114,7 @@
 
 // intf pane - http interface box
 @property (readwrite, weak) IBOutlet NSBox *intf_luahttpBox;
+ at property (readwrite, weak) IBOutlet NSButton *intf_enableluahttpCheckbox;
 @property (readwrite, weak) IBOutlet NSTextField *intf_luahttppwdLabel;
 @property (readwrite, weak) IBOutlet NSTextField *intf_luahttppwdTextField;
 @property (readwrite, weak) IBOutlet NSView *intfView;
diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m
index 55928e39f6..40b59afc67 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/VLCSimplePrefsController.m
@@ -324,6 +324,7 @@ create_toolbar_item(NSString *itemIdent, NSString *name, NSString *desc, NSStrin
     [_intf_last_updateLabel setStringValue: @""];
 
     [_intf_luahttpBox setTitle:_NS("HTTP web interface")];
+    [_intf_enableluahttpCheckbox setTitle: _NS("Enable HTTP web interface")];
     [_intf_luahttppwdLabel setStringValue:_NS("Password")];
 
     /* Subtitles and OSD */
@@ -490,6 +491,36 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
     free(psz_tmp);
 }
 
+- (BOOL)hasModule:(NSString *)moduleName inConfig:(NSString *)config
+{
+    char *value = config_GetPsz(p_intf, [config UTF8String]);
+    NSString *modules = toNSStr(value);
+    free(value);
+
+    return [[modules componentsSeparatedByString:@":"] containsObject:moduleName];
+}
+
+- (void)changeModule:(NSString *)moduleName inConfig:(NSString *)config enable:(BOOL)enable
+{
+    char *value = config_GetPsz(p_intf, [config UTF8String]);
+    NSString *modules = toNSStr(value);
+    free(value);
+
+    NSMutableArray *components = [[modules componentsSeparatedByString:@":"] mutableCopy];
+    if (enable) {
+        if (![components containsObject:moduleName]) {
+            [components addObject:moduleName];
+        }
+    } else {
+        [components removeObject:moduleName];
+    }
+
+    // trim empty entries
+    [components removeObject:@""];
+
+    config_PutPsz(p_intf, [config UTF8String], [[components componentsJoinedByString:@":"] UTF8String]);
+}
+
 - (void)resetControls
 {
     module_config_t *p_item;
@@ -539,12 +570,9 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
         [_intf_last_updateLabel setStringValue: _NS("No check was performed yet.")];
 #endif
 
-    psz_tmp = config_GetPsz(p_intf, "control");
-    if (psz_tmp) {
-        [_intf_enableNotificationsCheckbox setState: (NSInteger)strstr(psz_tmp, "growl")];
-        free(psz_tmp);
-    } else
-        [_intf_enableNotificationsCheckbox setState: NSOffState];
+    BOOL growlEnabled = [self hasModule:@"growl" inConfig:@"control"];
+    [_intf_enableNotificationsCheckbox setState: growlEnabled ? NSOnState : NSOffState];
+
     if (config_GetInt(p_intf, "macosx-interfacestyle")) {
         [_intf_style_darkButtonCell setState: YES];
         [_intf_style_brightButtonCell setState: NO];
@@ -553,6 +581,10 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
         [_intf_style_brightButtonCell setState: YES];
     }
 
+    BOOL httpEnabled = [self hasModule:@"http" inConfig:@"extraintf"];
+    [_intf_enableluahttpCheckbox setState: httpEnabled ? NSOnState : NSOffState];
+    _intf_luahttppwdTextField.enabled = httpEnabled;
+
     [self setupField:_intf_luahttppwdTextField forOption: "http-password"];
 
     /******************
@@ -859,16 +891,11 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
 
 - (void)saveChangedSettings
 {
-    NSString *tmpString;
-    NSRange tmpRange;
-
 #define SaveIntList(object, name) save_int_list(p_intf, object, name)
 
 #define SaveStringList(object, name) save_string_list(p_intf, object, name)
 #define SaveModuleList(object, name) SaveStringList(object, name)
 
-#define getString(name) [NSString stringWithFormat:@"%s", config_GetPsz(p_intf, name)]
-
     /**********************
      * interface settings *
      **********************/
@@ -887,26 +914,9 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
         config_PutInt(p_intf, "macosx-mediakeys", [_intf_mediakeysCheckbox state]);
         config_PutInt(p_intf, "macosx-interfacestyle", [_intf_style_darkButtonCell state]);
 
-        if ([_intf_enableNotificationsCheckbox state] == NSOnState) {
-            tmpString = getString("control");
-            tmpRange = [tmpString rangeOfString:@"growl"];
-            if ([tmpString length] > 0 && tmpRange.location == NSNotFound)
-            {
-                tmpString = [tmpString stringByAppendingString: @":growl"];
-                config_PutPsz(p_intf, "control", [tmpString UTF8String]);
-            }
-            else
-                config_PutPsz(p_intf, "control", "growl");
-        } else {
-            tmpString = getString("control");
-            if (! [tmpString isEqualToString:@""])
-            {
-                tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
-                tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
-                tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
-                config_PutPsz(p_intf, "control", [tmpString UTF8String]);
-            }
-        }
+        [self changeModule:@"growl" inConfig:@"control" enable:[_intf_enableNotificationsCheckbox state] == NSOnState];
+
+        [self changeModule:@"http" inConfig:@"extraintf" enable:[_intf_enableluahttpCheckbox state] == NSOnState];
         config_PutPsz(p_intf, "http-password", [[_intf_luahttppwdTextField stringValue] UTF8String]);
 
         SaveIntList(_intf_pauseitunesPopup, "macosx-control-itunes");
@@ -1109,6 +1119,10 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
 
 - (IBAction)interfaceSettingChanged:(id)sender
 {
+    if (sender == _intf_enableluahttpCheckbox) {
+        _intf_luahttppwdTextField.enabled = [sender state] == NSOnState;
+    }
+
     _intfSettingChanged = YES;
 }
 



More information about the vlc-commits mailing list