Преглед изворни кода

Use CoreAboutDialogModel for licences.

pull/151/head
Greg Holmes пре 9 година
родитељ
комит
221fb04444

freedesktop_notifications/res/META-INF/licenses/Apache Commons - ASF 2.0 → freedesktop_notifications/res/META-INF/licences/Apache Commons - ASF 2.0 Прегледај датотеку


ui_swing/res/META-INF/licenses/JXLayer - BSD → ui_swing/res/META-INF/licences/JXLayer - BSD Прегледај датотеку


ui_swing/res/META-INF/licenses/Menu Scrolling - Public domain → ui_swing/res/META-INF/licences/Menu Scrolling - Public domain Прегледај датотеку


ui_swing/res/META-INF/licenses/MigLayout - BSD → ui_swing/res/META-INF/licences/MigLayout - BSD Прегледај датотеку


ui_swing/res/META-INF/licenses/Single line JEditorPane - Public domain → ui_swing/res/META-INF/licences/Single line JEditorPane - Public domain Прегледај датотеку


ui_swing/res/META-INF/licenses/Tracing Event Queue - BSD → ui_swing/res/META-INF/licences/Tracing Event Queue - BSD Прегледај датотеку


+ 11
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/AboutDialog.java Прегледај датотеку

@@ -22,11 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.about;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.DMDircMBassador;
26 27
 import com.dmdirc.addons.ui_swing.SwingController;
27 28
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
28 29
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
29 30
 import com.dmdirc.events.ClientInfoRequestEvent;
31
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 32
 import com.dmdirc.interfaces.ui.AboutDialogModel;
31 33
 import com.dmdirc.ui.core.about.InfoItem;
32 34
 import com.dmdirc.ui.core.util.URLHandler;
@@ -52,27 +54,31 @@ public class AboutDialog extends StandardDialog {
52 54
     private final URLHandler urlHandler;
53 55
     private final AboutDialogModel model;
54 56
     private final SwingController controller;
57
+    private final DMDircMBassador eventBus;
58
+    private final AggregateConfigProvider config;
55 59
 
56 60
     @Inject
57 61
     public AboutDialog(
62
+            @GlobalConfig final AggregateConfigProvider config,
58 63
             @MainWindow final Window parentWindow,
59 64
             final AboutDialogModel model,
60 65
             final URLHandler urlHandler,
61 66
             final DMDircMBassador eventBus,
62
-            final SwingController controller,
63
-            final LicencesPanel licensesPanel) {
67
+            final SwingController controller) {
64 68
         super(parentWindow, ModalityType.MODELESS);
65 69
         this.urlHandler = urlHandler;
66 70
         this.model = model;
67 71
         this.controller = controller;
72
+        this.eventBus = eventBus;
73
+        this.config = config;
68 74
 
69 75
         eventBus.subscribe(this);
70 76
         model.load();
71
-        initComponents(licensesPanel);
77
+        initComponents();
72 78
     }
73 79
 
74 80
     /** Initialises the main UI components. */
75
-    private void initComponents(final LicencesPanel licensesPanel) {
81
+    private void initComponents() {
76 82
         final JTabbedPane tabbedPane = new JTabbedPane();
77 83
 
78 84
         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
@@ -86,7 +92,7 @@ public class AboutDialog extends StandardDialog {
86 92
 
87 93
         tabbedPane.add("About", new AboutPanel(urlHandler, model));
88 94
         tabbedPane.add("Credits", new CreditsPanel(urlHandler, model));
89
-        tabbedPane.add("Licences", licensesPanel);
95
+        tabbedPane.add("Licences", new LicencesPanel(model, config, eventBus));
90 96
         tabbedPane.add("Information", new InfoPanel(model));
91 97
 
92 98
         getContentPane().setLayout(new MigLayout("ins rel, wrap 1, fill, "

+ 0
- 106
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/Licence.java Прегледај датотеку

@@ -1,106 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.about;
24
-
25
-/**
26
- * Simple class to describe a licence.
27
- */
28
-public class Licence {
29
-
30
-    private String name;
31
-    private String component;
32
-    private String body;
33
-
34
-    /**
35
-     * Instantiates a new licence with the specified attributes.
36
-     *
37
-     * @param name      Name of the licence
38
-     * @param component Component the licence applies to
39
-     * @param body      Body of the licence
40
-     */
41
-    public Licence(final String name, final String component, final String body) {
42
-        this.name = name;
43
-        this.component = component;
44
-        this.body = body;
45
-    }
46
-
47
-    /**
48
-     * Get the value of body.
49
-     *
50
-     * @return the value of body
51
-     */
52
-    public String getBody() {
53
-        return body;
54
-    }
55
-
56
-    /**
57
-     * Set the value of body.
58
-     *
59
-     * @param body new value of body
60
-     */
61
-    public void setBody(final String body) {
62
-        this.body = body;
63
-    }
64
-
65
-    /**
66
-     * Get the value of component.
67
-     *
68
-     * @return the value of component
69
-     */
70
-    public String getComponent() {
71
-        return component;
72
-    }
73
-
74
-    /**
75
-     * Set the value of component.
76
-     *
77
-     * @param component new value of component
78
-     */
79
-    public void setComponent(final String component) {
80
-        this.component = component;
81
-    }
82
-
83
-    /**
84
-     * Get the value of name.
85
-     *
86
-     * @return the value of name
87
-     */
88
-    public String getName() {
89
-        return name;
90
-    }
91
-
92
-    /**
93
-     * Set the value of name.
94
-     *
95
-     * @param name new value of name
96
-     */
97
-    public void setName(final String name) {
98
-        this.name = name;
99
-    }
100
-
101
-    @Override
102
-    public String toString() {
103
-        return getComponent();
104
-    }
105
-
106
-}

+ 16
- 91
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/LicenceLoader.java Прегледај датотеку

@@ -23,19 +23,12 @@
23 23
 package com.dmdirc.addons.ui_swing.dialogs.about;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.addons.ui_swing.UIUtilities;
27 26
 import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
28
-import com.dmdirc.plugins.PluginInfo;
27
+import com.dmdirc.interfaces.ui.AboutDialogModel;
28
+import com.dmdirc.ui.core.about.LicensedComponent;
29 29
 import com.dmdirc.util.resourcemanager.ResourceManager;
30 30
 
31
-import java.io.BufferedReader;
32 31
 import java.io.IOException;
33
-import java.io.InputStream;
34
-import java.io.InputStreamReader;
35
-import java.util.Collection;
36
-import java.util.Map;
37
-import java.util.Map.Entry;
38
-import java.util.TreeMap;
39 32
 
40 33
 import javax.swing.JTree;
41 34
 import javax.swing.tree.DefaultMutableTreeNode;
@@ -52,117 +45,49 @@ public class LicenceLoader extends LoggingSwingWorker<Void, Void> {
52 45
 
53 46
     /** Tree to add licenses to. */
54 47
     private final JTree tree;
48
+    private final AboutDialogModel model;
55 49
     /** Model to load licences into. */
56
-    private final DefaultTreeModel model;
57
-    /** List of plugins to get licenses for. */
58
-    private final Collection<PluginInfo> plugins;
50
+    private final DefaultTreeModel treeModel;
59 51
 
60 52
     /**
61 53
      * Instantiates a new licence loader.
62 54
      *
63
-     * @param plugins  List of plugins to get licenses from
64 55
      * @param tree     Tree to add licenses to
65 56
      * @param model    Model to load licences into
66 57
      * @param eventBus The event bus to post errors to
67 58
      */
68
-    public LicenceLoader(final Collection<PluginInfo> plugins, final JTree tree,
69
-            final DefaultTreeModel model, final DMDircMBassador eventBus) {
59
+    public LicenceLoader(final AboutDialogModel model, final JTree tree,
60
+            final DefaultTreeModel treeModel, final DMDircMBassador eventBus) {
70 61
         super(eventBus);
71
-        this.plugins = plugins;
72 62
         this.tree = tree;
73 63
         this.model = model;
64
+        this.treeModel = treeModel;
74 65
     }
75 66
 
76 67
     @Override
77 68
     protected Void doInBackground() throws IOException {
78 69
         final ResourceManager rm = ResourceManager.getResourceManager();
79 70
         checkNotNull(rm, "Unable to find resource manager");
80
-        addCoreLicences(rm);
81
-        for (PluginInfo pi : plugins) {
82
-            addPluginLicences(pi);
83
-        }
71
+        model.getLicensedComponents().forEach(this::addLicensedComponent);
84 72
         return null;
85 73
     }
86 74
 
87
-    private Licence createLicence(final Entry<String, InputStream> entry) {
88
-        final String licenceString = entry.getKey().substring(entry.getKey().
89
-                lastIndexOf('/') + 1);
90
-        if (licenceString.length() > 1) {
91
-            final String[] licenceStringParts = licenceString.split(" - ");
92
-            return new Licence(licenceStringParts[1], licenceStringParts[0],
93
-                    "<html><h1>" + licenceStringParts[1] + "</h1><p>" +
94
-                            readInputStream(entry.getValue()).replace("\n", "<br>") +
95
-                            "</p></html>");
96
-        } else {
97
-            return null;
98
-        }
99
-    }
100
-
101
-    private void addCoreLicences(final ResourceManager rm) {
102
-        final DefaultMutableTreeNode root = new DefaultMutableTreeNode("DMDirc");
103
-        final Map<String, InputStream> licences = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
104
-        licences.putAll(rm.getResourcesStartingWithAsInputStreams("com/dmdirc/licences/"));
105
-        addLicensesToNode(licences, root);
106
-    }
107
-
108
-    private void addPluginLicences(final PluginInfo pi) throws IOException {
109
-        final Map<String, InputStream> licences = pi.getLicenceStreams();
110
-
111
-        if (licences.isEmpty()) {
112
-            return;
113
-        }
114
-
115
-        final DefaultMutableTreeNode root = new DefaultMutableTreeNode(pi);
116
-        addLicensesToNode(licences, root);
117
-    }
118
-
119
-    private void addLicensesToNode(final Map<String, InputStream> licences,
120
-            final DefaultMutableTreeNode root) {
121
-        UIUtilities.invokeAndWait(() -> model.insertNodeInto(root,
122
-                (MutableTreeNode) model.getRoot(), model.getChildCount(model.getRoot())));
123
-        for (Entry<String, InputStream> entry : licences.entrySet()) {
124
-            final Licence licence = createLicence(entry);
125
-            if (licence == null) {
126
-                continue;
127
-            }
128
-            UIUtilities.invokeAndWait(
129
-                    () -> model.insertNodeInto(new DefaultMutableTreeNode(licence), root,
130
-                            model.getChildCount(root)));
131
-        }
75
+    private void addLicensedComponent(final LicensedComponent component) {
76
+        final MutableTreeNode componentNode = new DefaultMutableTreeNode(component);
77
+        treeModel.insertNodeInto(componentNode, (MutableTreeNode) treeModel.getRoot(),
78
+                treeModel.getChildCount(treeModel.getRoot()));
79
+        component.getLicences().forEach(l -> treeModel.insertNodeInto(
80
+                new DefaultMutableTreeNode(l), componentNode,
81
+                treeModel.getChildCount(componentNode)));
132 82
     }
133 83
 
134 84
     @Override
135 85
     protected void done() {
136
-        model.nodeStructureChanged((TreeNode) model.getRoot());
86
+        treeModel.nodeStructureChanged((TreeNode) treeModel.getRoot());
137 87
         for (int i = 0; i < tree.getRowCount(); i++) {
138 88
             tree.expandRow(i);
139 89
         }
140 90
         tree.setSelectionRow(0);
141 91
         super.done();
142 92
     }
143
-
144
-    /**
145
-     * Converts an input stream into a string.
146
-     *
147
-     * @param stream Stream to convert
148
-     *
149
-     * @return Contents of the input stream
150
-     */
151
-    private String readInputStream(final InputStream stream) {
152
-        String line;
153
-        final StringBuilder text = new StringBuilder();
154
-
155
-        try (BufferedReader input = new BufferedReader(new InputStreamReader(stream))) {
156
-            line = input.readLine();
157
-            while (line != null) {
158
-                text.append(line).append('\n');
159
-                line = input.readLine();
160
-            }
161
-        } catch (IOException ex) {
162
-            //Ignore
163
-        }
164
-
165
-        return text.toString();
166
-    }
167
-
168 93
 }

+ 10
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/LicenceRenderer.java Прегледај датотеку

@@ -22,7 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.about;
24 24
 
25
-import com.dmdirc.plugins.PluginInfo;
25
+import com.dmdirc.ui.core.about.Licence;
26
+import com.dmdirc.ui.core.about.LicensedComponent;
26 27
 
27 28
 import java.awt.Color;
28 29
 import java.awt.Component;
@@ -48,9 +49,14 @@ public class LicenceRenderer extends DefaultTreeCellRenderer {
48 49
                 value, sel, expanded, leaf, row, hasFocus);
49 50
         label.setIcon(null);
50 51
         label.setOpaque(false);
51
-        if (((DefaultMutableTreeNode) value).getUserObject() instanceof PluginInfo) {
52
-            setText(((PluginInfo) ((DefaultMutableTreeNode) value)
53
-                    .getUserObject()).getMetaData().getFriendlyName());
52
+        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
53
+        final Object nodeValue = node.getUserObject();
54
+        if (nodeValue instanceof Licence) {
55
+            setText(((Licence) nodeValue).getComponent());
56
+        } else if (nodeValue instanceof LicensedComponent) {
57
+            setText(((LicensedComponent) nodeValue).getName());
58
+        } else {
59
+            setText(value.toString());
54 60
         }
55 61
         return label;
56 62
     }

+ 18
- 25
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/LicencesPanel.java Прегледај датотеку

@@ -22,18 +22,20 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.about;
24 24
 
25
-import com.dmdirc.ClientModule.GlobalConfig;
26 25
 import com.dmdirc.DMDircMBassador;
27 26
 import com.dmdirc.addons.ui_swing.UIUtilities;
28 27
 import com.dmdirc.addons.ui_swing.components.TreeScroller;
29 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-import com.dmdirc.plugins.PluginInfo;
31
-import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.interfaces.ui.AboutDialogModel;
30
+import com.dmdirc.ui.core.about.Licence;
31
+import com.dmdirc.ui.core.about.LicensedComponent;
32
+
33
+import com.google.common.base.Joiner;
34
+import com.google.common.base.Splitter;
32 35
 
33 36
 import java.awt.Font;
34 37
 import java.awt.Rectangle;
35 38
 
36
-import javax.inject.Inject;
37 39
 import javax.swing.BorderFactory;
38 40
 import javax.swing.JEditorPane;
39 41
 import javax.swing.JPanel;
@@ -69,20 +71,12 @@ public class LicencesPanel extends JPanel implements TreeSelectionListener {
69 71
     /** Licence list. */
70 72
     private JTree list;
71 73
 
72
-    /**
73
-     * Creates a new instance of LicencesPanel.
74
-     *
75
-     * @param globalConfig  The config to read settings from.
76
-     * @param pluginManager The manager to use to find plugins (to display their licenses).
77
-     * @param eventBus      The event bus to post errors to.
78
-     */
79
-    @Inject
80
-    public LicencesPanel(
81
-            @GlobalConfig final AggregateConfigProvider globalConfig,
82
-            final PluginManager pluginManager, final DMDircMBassador eventBus) {
74
+    public LicencesPanel(final AboutDialogModel model,
75
+            final AggregateConfigProvider globalConfig,
76
+            final DMDircMBassador eventBus) {
83 77
         config = globalConfig;
84 78
         initComponents();
85
-        new LicenceLoader(pluginManager.getPluginInfos(), list, listModel, eventBus).execute();
79
+        new LicenceLoader(model, list, listModel, eventBus).execute();
86 80
         addListeners();
87 81
         layoutComponents();
88 82
     }
@@ -148,16 +142,15 @@ public class LicencesPanel extends JPanel implements TreeSelectionListener {
148 142
         final Object userObject = ((DefaultMutableTreeNode) e.getPath().
149 143
                 getLastPathComponent()).getUserObject();
150 144
         if (userObject instanceof Licence) {
151
-            licence.setText(((Licence) userObject).getBody());
152
-        } else if (userObject instanceof PluginInfo) {
153
-            final PluginInfo pi = (PluginInfo) userObject;
145
+            licence.setText(
146
+                    "<h3 style='margin: 3px; padding: 0px 0px 5px 0px;'>"
147
+                            + ((Licence) userObject).getName() + "</h3>"
148
+                            + Joiner.on("<br>").join(
149
+                            Splitter.on('\n').split(((Licence) userObject).getBody())));
150
+        } else if (userObject instanceof LicensedComponent) {
151
+            final LicensedComponent lc = (LicensedComponent) userObject;
154 152
             licence.setText("<b>Name:</b> "
155
-                    + pi.getMetaData().getFriendlyName() + "<br>"
156
-                    + "<b>Version:</b> "
157
-                    + pi.getMetaData().getFriendlyVersion() + "<br>"
158
-                    + "<b>Author:</b> " + pi.getMetaData().getAuthor() + "<br>"
159
-                    + "<b>Description:</b> "
160
-                    + pi.getMetaData().getDescription() + "<br>");
153
+                    + lc.getName() + "<br>");
161 154
         } else {
162 155
             licence.setText("<b>Name:</b> DMDirc<br>"
163 156
                     + "<b>Version:</b> " + config

Loading…
Откажи
Сачувај