Bug 10385 fixed: it was not possible to configure default web browser 90/7790/5
Calixte DENIZET [Fri, 6 Jul 2012 13:43:21 +0000 (15:43 +0200)]
Change-Id: I9f2ba00e1ace5ead7e835cb5987286b86543e483

scilab/CHANGES_5.4.X
scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/etc/XConfiguration-web.xml [new file with mode: 0644]
scilab/modules/gui/etc/XConfiguration-web.xsl [new file with mode: 0644]
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/WebBrowser.java
scilab/modules/preferences/etc/XConfiguration.xml

index a03171b..30c3888 100644 (file)
@@ -1,4 +1,4 @@
-            Changes between version 5.4.0-beta-1 and 5.4.0-beta-2 of Scilab
+            Changes between version 5.4.0-beta-1 and 5.4.0-beta-2 of Scilab
             ===============================================================
 
 
@@ -124,6 +124,8 @@ Bug Fixes
 * Bug #10184 fixed - In messagebox, focus was not set by default on yes or ok
                      button.
 
+* Bug #10385 fixed - It was not possible to configure default web browser.
+
 * Bug #10479 fixed - The max and min functions where incorrect for N-D arrays.
 
 * Bug #10497 fixed - Some special characters were causing issues in the phaseplot
index 98c8248..4ee1c88 100644 (file)
@@ -39,6 +39,8 @@ libscigui_la_etc_DATA = \
        etc/XConfiguration-colors.xsl \
        etc/XConfiguration-font.xml \
        etc/XConfiguration-font.xsl \
+       etc/XConfiguration-web.xml \
+       etc/XConfiguration-web.xsl \
        etc/XConfiguration-toolbars.xml \
        etc/XConfiguration-toolbars.xsl
 
index 024510b..e2be1b1 100644 (file)
@@ -555,6 +555,8 @@ libscigui_la_etc_DATA = \
        etc/XConfiguration-colors.xsl \
        etc/XConfiguration-font.xml \
        etc/XConfiguration-font.xsl \
+       etc/XConfiguration-web.xml \
+       etc/XConfiguration-web.xsl \
        etc/XConfiguration-toolbars.xml \
        etc/XConfiguration-toolbars.xsl
 
diff --git a/scilab/modules/gui/etc/XConfiguration-web.xml b/scilab/modules/gui/etc/XConfiguration-web.xml
new file mode 100644 (file)
index 0000000..8836463
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<web title="Web">
+  <body>
+    <web default-browser="true" default-mailer="true" command-browser="" command-mailer=""/>
+  </body>
+</web>
diff --git a/scilab/modules/gui/etc/XConfiguration-web.xsl b/scilab/modules/gui/etc/XConfiguration-web.xsl
new file mode 100644 (file)
index 0000000..9f5a8f3
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                >
+  <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
+       ::
+       ::     M A I N   P A N E L   :   W E B
+       ::
+  -->
+
+  <xsl:template match="web">
+    <Title text="Web browser and mailer">
+      <Grid>
+        <Checkbox checked="{@default-browser}" selected-value="true" unselected-value="false" listener="ActionListener" text="Use default web browser" gridx="1" gridy="1" fill="none" weightx="0" anchor="west">
+          <actionPerformed choose="default-browser">
+            <xsl:call-template name="context"/>
+          </actionPerformed>
+        </Checkbox>
+        <Panel gridx="2" gridy="1" weightx="1"/>
+        <Label gridx="1" gridy="2" weightx="0" text="Command for web browser: "/>
+        <FileSelector gridx="2" gridy="2" weightx="1" anchor="above_baseline"
+                      listener="EntryListener"
+                      href="{@command-browser}"
+                      dir-selection="false"
+                      check-entry="false">
+          <xsl:attribute name="enable">
+            <xsl:if test="@default-browser='false'">
+              <xsl:text>true</xsl:text>
+            </xsl:if>
+          </xsl:attribute>
+          <entryChanged choose="command-browser">
+            <xsl:call-template name="context"/>
+          </entryChanged>
+        </FileSelector>
+        <Label gridx="2" gridy="3" text="(Don't forget to quote path containing white spaces)">
+          <xsl:attribute name="enable">
+            <xsl:if test="@default-browser='false'">
+              <xsl:text>true</xsl:text>
+            </xsl:if>
+          </xsl:attribute>
+        </Label>
+        <Panel height="5" gridx="1" gridy="4">
+          <VSpace height="5"/>
+        </Panel>
+        <Checkbox checked="{@default-mailer}" selected-value="true" unselected-value="false" listener="ActionListener" text="Use default mailer" gridx="1" gridy="5" fill="none" weightx="0" anchor="west">
+          <actionPerformed choose="default-mailer">
+            <xsl:call-template name="context"/>
+          </actionPerformed>
+        </Checkbox>
+        <Panel gridx="2" gridy="5" weightx="1"/>
+        <Label gridx="1" gridy="6" weightx="0" text="Command for mailer: "/>
+        <FileSelector gridx="2" gridy="6" weightx="1" anchor="above_baseline"
+                      listener="EntryListener"
+                      href="{@command-mailer}"
+                      dir-selection="false"
+                      check-entry="false">
+          <xsl:attribute name="enable">
+            <xsl:if test="@default-mailer='false'">
+              <xsl:text>true</xsl:text>
+            </xsl:if>
+          </xsl:attribute>
+          <entryChanged choose="command-mailer">
+            <xsl:call-template name="context"/>
+          </entryChanged>
+        </FileSelector>
+        <Label gridx="2" gridy="7" text="(Don't forget to quote path containing white spaces)">
+          <xsl:attribute name="enable">
+            <xsl:if test="@default-mailer='false'">
+              <xsl:text>true</xsl:text>
+            </xsl:if>
+          </xsl:attribute>
+        </Label>
+      </Grid>
+    </Title>
+  </xsl:template>
+</xsl:stylesheet>
index 264e447..d18d440 100644 (file)
@@ -17,24 +17,51 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Set;
 
 import javax.swing.JOptionPane;
 
+import org.w3c.dom.Document;
+
+import static org.scilab.modules.commons.xml.XConfiguration.XConfAttribute;
+import org.scilab.modules.commons.xml.XConfiguration;
+import org.scilab.modules.commons.xml.XConfigurationEvent;
+import org.scilab.modules.commons.xml.XConfigurationListener;
 import org.scilab.modules.localization.Messages;
 
+
 /**
  * Class used to launch a Web Browser from Scilab
  * @author Vincent COUVERT
  */
-public final class WebBrowser {
+public final class WebBrowser implements XConfigurationListener {
 
     private static final String ERROR_MSG = Messages.gettext("Could not open: ");
+    public static final String WEBPATH = "//web/body/web";
+
+    private static WebPreferences webprefs;
+    private static Document doc;
+
+    static {
+        XConfiguration.addXConfigurationListener(new WebBrowser());
+    }
 
     /**
      * Constructor
      */
-    private WebBrowser() {
-        throw new UnsupportedOperationException();
+    private WebBrowser() { }
+
+    /**
+     * Prevent the listener that configuration has changed
+     *
+     * @param e the event
+     */
+    public void configurationChanged(XConfigurationEvent e) {
+        Set<String> path = e.getModifiedPaths();
+        if (path.contains("ALL") || path.contains(WEBPATH)) {
+            webprefs = null;
+            doc = null;
+        }
     }
 
     /**
@@ -46,13 +73,7 @@ public final class WebBrowser {
         if (url == null) {
             JOptionPane.showMessageDialog(null, ERROR_MSG + description);
         } else {
-            try {
-                Desktop.getDesktop().browse(url.toURI());
-            } catch (IOException e) {
-                JOptionPane.showMessageDialog(null, ERROR_MSG + url);
-            } catch (URISyntaxException e) {
-                JOptionPane.showMessageDialog(null, ERROR_MSG + url);
-            }
+            openUrl(url.toString());
         }
     }
 
@@ -65,19 +86,52 @@ public final class WebBrowser {
             return;
         }
 
+        if (webprefs == null) {
+            if (doc == null) {
+                doc = XConfiguration.getXConfigurationDocument();
+            }
+            webprefs = XConfiguration.get(WebBrowser.WebPreferences.class, doc, WEBPATH)[0];
+        }
+
         try {
             if (url.charAt(0) == 'h' || url.charAt(0) == 'f') {
                 // We have something like http://... or file://
-                Desktop.getDesktop().browse(new URI(url));
+                if (webprefs.defaultBrowser) {
+                    Desktop.getDesktop().browse(new URI(url));
+                } else {
+                    Runtime.getRuntime().exec(webprefs.cmdBrowser + " " + new URI(url).toString());
+                }
             } else {
                 // We have <pierre.marechal@scilab.org>
                 String mail = "mailto:" + url.substring(1, url.length() - 1);
-                Desktop.getDesktop().mail(new URI(mail));
+                if (webprefs.defaultMailer) {
+                    Desktop.getDesktop().mail(new URI(mail));
+                } else {
+                    Runtime.getRuntime().exec(webprefs.cmdMailer + " " + new URI(mail).toString());
+                }
             }
-        } catch (IOException e) {
-            JOptionPane.showMessageDialog(null, ERROR_MSG + url);
-        } catch (URISyntaxException e) {
+        } catch (Exception e) {
             JOptionPane.showMessageDialog(null, ERROR_MSG + url);
         }
     }
+
+    /* web */
+    @XConfAttribute
+    static class WebPreferences {
+
+        boolean defaultBrowser;
+        boolean defaultMailer;
+        String cmdBrowser;
+        String cmdMailer;
+
+        private WebPreferences() { }
+
+        @XConfAttribute(tag = "web", attributes = {"default-browser", "default-mailer", "command-browser", "command-mailer"})
+        private void set(boolean defaultBrowser, boolean defaultMailer, String cmdBrowser, String cmdMailer) {
+            this.defaultBrowser = defaultBrowser;
+            this.defaultMailer = defaultMailer;
+            this.cmdBrowser = cmdBrowser;
+            this.cmdMailer = cmdMailer;
+        }
+    }
 }
index 6ab63ed..d1c3e8b 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <interface version="0.03" path="1/" width="800" height="550">
   <general/>
+  <web/>
   <preference/>
   <fonts/>
   <colors/>