|
@@ -34,9 +34,9 @@ import com.dmdirc.plugins.Plugin;
|
34
|
34
|
import com.dmdirc.plugins.PluginManager;
|
35
|
35
|
import com.dmdirc.ui.interfaces.PreferencesInterface;
|
36
|
36
|
import com.dmdirc.ui.interfaces.PreferencesPanel;
|
37
|
|
-import java.util.ArrayList;
|
38
|
37
|
|
39
|
|
-import java.util.LinkedList;
|
|
38
|
+import java.util.ArrayList;
|
|
39
|
+import java.util.Collections;
|
40
|
40
|
import java.util.List;
|
41
|
41
|
import java.util.Properties;
|
42
|
42
|
|
|
@@ -55,6 +55,9 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
55
|
55
|
/** Config panel. */
|
56
|
56
|
private ConfigPanel configPanel;
|
57
|
57
|
|
|
58
|
+ /** The user's preferred order for source usage. */
|
|
59
|
+ private List<String> order;
|
|
60
|
+
|
58
|
61
|
public NowPlayingPlugin() {
|
59
|
62
|
super();
|
60
|
63
|
|
|
@@ -71,6 +74,8 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
71
|
74
|
protected void onActivate() {
|
72
|
75
|
sources.clear();
|
73
|
76
|
|
|
77
|
+ loadSettings();
|
|
78
|
+
|
74
|
79
|
for (Plugin target : PluginManager.getPluginManager().getPlugins()) {
|
75
|
80
|
if (target.isActive()) {
|
76
|
81
|
addPlugin(target);
|
|
@@ -78,7 +83,6 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
78
|
83
|
}
|
79
|
84
|
|
80
|
85
|
command = new NowPlayingCommand(this);
|
81
|
|
- loadSettings();
|
82
|
86
|
}
|
83
|
87
|
|
84
|
88
|
/** {@inheritDoc} */
|
|
@@ -110,12 +114,15 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
110
|
114
|
}
|
111
|
115
|
|
112
|
116
|
/** {@inheritDoc} */
|
113
|
|
- public boolean isConfigurable() { return true; }
|
|
117
|
+ public boolean isConfigurable() {
|
|
118
|
+ return true;
|
|
119
|
+ }
|
114
|
120
|
|
115
|
121
|
/** {@inheritDoc} */
|
116
|
122
|
public void showConfig() {
|
117
|
123
|
final PreferencesPanel preferencesPanel = Main.getUI().getPreferencesPanel(this, "Now playing Plugin - Config");
|
118
|
|
- configPanel = new ConfigPanel(sources);
|
|
124
|
+
|
|
125
|
+ configPanel = new ConfigPanel(order);
|
119
|
126
|
|
120
|
127
|
preferencesPanel.addCategory("General", "General options for the plugin.");
|
121
|
128
|
|
|
@@ -126,8 +133,8 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
126
|
133
|
|
127
|
134
|
/** {@inheritDoc} */
|
128
|
135
|
public void configClosed(final Properties properties) {
|
129
|
|
- //save settings
|
130
|
|
- sources = configPanel.getSources();
|
|
136
|
+ order = configPanel.getSources();
|
|
137
|
+
|
131
|
138
|
saveSettings();
|
132
|
139
|
}
|
133
|
140
|
|
|
@@ -138,16 +145,16 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
138
|
145
|
|
139
|
146
|
/** Saves the plugins settings. */
|
140
|
147
|
private void saveSettings() {
|
141
|
|
- final List<String> values = new LinkedList<String>();
|
142
|
|
- for (final MediaSource source : sources) {
|
143
|
|
- values.add(source.getName());
|
144
|
|
- }
|
145
|
|
- Config.setOption(DOMAIN, "sourceOrder", values);
|
|
148
|
+ Config.setOption(DOMAIN, "sourceOrder", order);
|
146
|
149
|
}
|
147
|
150
|
|
148
|
151
|
/** Loads the plugins settings. */
|
149
|
152
|
private void loadSettings() {
|
150
|
|
- final List<String> values = Config.getOptionList(DOMAIN, "sourceOrder");
|
|
153
|
+ if (Config.hasOption(DOMAIN, "sourceOrder")) {
|
|
154
|
+ order = Config.getOptionList(DOMAIN, "sourceOrder");
|
|
155
|
+ } else {
|
|
156
|
+ order = new ArrayList<String>();
|
|
157
|
+ }
|
151
|
158
|
}
|
152
|
159
|
|
153
|
160
|
/** {@inheritDoc} */
|
|
@@ -169,10 +176,27 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
169
|
176
|
private void addPlugin(final Plugin target) {
|
170
|
177
|
if (target instanceof MediaSource) {
|
171
|
178
|
sources.add((MediaSource) target);
|
|
179
|
+ addSourceToOrder((MediaSource) target);
|
172
|
180
|
}
|
173
|
181
|
|
174
|
182
|
if (target instanceof MediaSourceManager) {
|
175
|
183
|
sources.addAll(((MediaSourceManager) target).getSources());
|
|
184
|
+
|
|
185
|
+ for (MediaSource source : ((MediaSourceManager) target).getSources()) {
|
|
186
|
+ addSourceToOrder(source);
|
|
187
|
+ }
|
|
188
|
+ }
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ /**
|
|
192
|
+ * Checks to see if the specified media source needs to be added to our
|
|
193
|
+ * order list, and adds it if neccessary.
|
|
194
|
+ *
|
|
195
|
+ * @param source The media source to be tested
|
|
196
|
+ */
|
|
197
|
+ private void addSourceToOrder(final MediaSource source) {
|
|
198
|
+ if (!order.contains(source.getName())) {
|
|
199
|
+ order.add(source.getName());
|
176
|
200
|
}
|
177
|
201
|
}
|
178
|
202
|
|
|
@@ -219,6 +243,8 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
|
219
|
243
|
public MediaSource getBestSource() {
|
220
|
244
|
MediaSource paused = null;
|
221
|
245
|
|
|
246
|
+ Collections.sort(sources, new MediaSourceComparator(order));
|
|
247
|
+
|
222
|
248
|
for (final MediaSource source : sources) {
|
223
|
249
|
if (source.isRunning()) {
|
224
|
250
|
if (source.isPlaying()) {
|