Patch: Add AddAditionalFoldersAtRoot for plugins

General discussion about PS3 Media Server (no support or requests)

Patch: Add AddAditionalFoldersAtRoot for plugins

Postby el.botijo » Thu Feb 04, 2010 10:10 pm

Hi, everyone,
my idea is to write a plugin that serves the MediaMonkey Library. My plan is to use a modified MediaLibrary class. I would like to add a new folder to the root of the UPNP root, but I do not want to make MediaMonkey part of the main code, just a plugin. The actual plugin system shows these two ExternalListeners:
  • StartStopListener, for doing things like updating playcounts
  • AdditionalResourceFolderListener, that adds a folder like the #Transcode# one.
So I extended the plugin architecture just a little bit, adding a new ExternalListener called AddAdditionalFolderAtRoot:
Code: Select all
Index: net/pms/external/AdditionalFolderAtRoot.java
===================================================================
--- net/pms/external/AdditionalFolderAtRoot.java   (revision 0)
+++ net/pms/external/AdditionalFolderAtRoot.java   (revision 0)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package net.pms.external;
+
+import net.pms.dlna.DLNAResource;
+
+/**Extends the plugin system in that it adds an extra VirtualFolder. Plugin will
+ * be instantiated like any other ExternalListener.
+ *
+ * PMS.manageroot() will call the getChild() function that returns the VirtualFolder
+ * that gets added to the root of the UPNP server.
+ *
+ * @author el.botijo
+ *
+ */
+public interface AdditionalFolderAtRoot extends ExternalListener {
+
+   public DLNAResource getChild();
+}
Index: net/pms/PMS.java
===================================================================
--- net/pms/PMS.java   (revision 386)
+++ net/pms/PMS.java   (working copy)
@@ -75,6 +75,7 @@
 import net.pms.encoders.TsMuxerAudio;
 import net.pms.encoders.VideoLanAudioStreaming;
 import net.pms.encoders.VideoLanVideoStreaming;
+import net.pms.external.AdditionalFolderAtRoot;
 import net.pms.external.ExternalFactory;
 import net.pms.external.ExternalListener;
 import net.pms.formats.DVRMS;
@@ -546,6 +547,8 @@
       }
    
       addMediaLibraryFolder(renderer);
+      
+      addAdditionalFoldersAtRoot(renderer);
    
       addVideoSettingssFolder(renderer);
       
@@ -553,6 +556,16 @@
    }
 
 
+   /**Adds a new DLNAResource at the root of the UPNP server
+    * @param renderer
+    */
+   private void addAdditionalFoldersAtRoot(RendererConfiguration renderer) {
+      for(ExternalListener listener:ExternalFactory.getExternalListeners()) {
+         if (listener instanceof AdditionalFolderAtRoot)
+            getRootFolder(renderer).addChild(((AdditionalFolderAtRoot) listener).getChild());
+      }
+   }
+
    @SuppressWarnings("unchecked")
    public void addiPhotoFolder(RendererConfiguration renderer) {
       if (Platform.isMac()) {

Compiled sucessfully, and working, as far as I have seen. Please review the code. Comments are welcome, of course. Names can change to accommodate developers naming scheme.

A plugin that uses this kind of mechanism looks like this (I left just the skel):
Code: Select all
package net.pms.external;
import net.pms.PMS;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.RealFile;
import net.pms.dlna.virtual.VirtualFolder;

public class MM_plugin implements AdditionalFolderAtRoot{
   private VirtualFolder MMroot;

   public MM_plugin() {
      this.MMroot = new VirtualFolder("MediaMonkey rules",null);
      this.MMroot.addChild( new RealFile(new File("test.mp3"))); //Dummy thing, just in case
   }

   public DLNAResource getChild(){
      return MMroot;
   }
   
   @Override
   public JComponent config() {
           // Removed code for creating buttons
      return null;
   }

   /* (non-Javadoc)
    * @see net.pms.external.ExternalListener#name()
    */
   @Override
   public String name() {
      return "Configure MediaMonkey Plugin...";
   }
   
   @Override
   public void shutdown() {
      // nothing to do yet
   }
}
I would be ashamed of such a non good looking code for the plugin. But, for the time being, it shows how to use the plugin mechanism I am proposing here.
Regards.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Patch: Add AddAditionalFoldersAtRoot for plugins

Postby shagrath » Fri Feb 05, 2010 1:23 am

I like that, simple and neat. I can merge it now if you want (well after quick tests of course :p)
shagrath
Project Lead
 
Posts: 2664
Joined: Wed Jan 14, 2009 1:39 pm

Re: Patch: Add AddAditionalFoldersAtRoot for plugins

Postby el.botijo » Fri Feb 05, 2010 9:03 am

Please do as many tests as you want to. No unverified code should ever go into the trunk.
I have not written this before, but this patch solves Issues 669 and 526. Both issues ask for the same.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Patch: Add AddAditionalFoldersAtRoot for plugins

Postby el.botijo » Sat Feb 06, 2010 5:07 pm

As I see there is a post linking to this one, I also need to state that in order to create a plugin, I had to add a file called "plugin" to the root of the JAR file:
Code: Select all
net.pms.external.MM_plugin

The last part is the name of the class I implemented in the package net.pms.external, as per the example in post #1.
Actually, I copied this over the one from the LastFM plugin. So I do not really know if it is really needed, but does not do any harm anyway.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Patch: Add AddAditionalFoldersAtRoot for plugins

Postby shagrath » Sun Feb 07, 2010 11:41 pm

It's merged !
shagrath
Project Lead
 
Posts: 2664
Joined: Wed Jan 14, 2009 1:39 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 6 guests