//# 0 errors, 125 messages
//#
/*
    //#NoatunSource.java:1:1: class: com.dmdirc.addons.mediasource_dcop.NoatunSource
    //#NoatunSource.java:1:1: method: com.dmdirc.addons.mediasource_dcop.NoatunSource.com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.mediasource_dcop;

import com.dmdirc.addons.nowplaying.MediaSource;
import com.dmdirc.addons.nowplaying.MediaSourceState;

import java.util.List;

/**
 * Uses DCOP to retrieve now playing info from Noatun.
 *
 * @author chris
 */
public class NoatunSource implements MediaSource {
    
    /** Instantiates the media source. */
    public NoatunSource() {
    //#NoatunSource.java:38: method: void com.dmdirc.addons.mediasource_dcop.NoatunSource.com.dmdirc.addons.mediasource_dcop.NoatunSource()
        //Do nothing
    }
    //#NoatunSource.java:40: end of method: void com.dmdirc.addons.mediasource_dcop.NoatunSource.com.dmdirc.addons.mediasource_dcop.NoatunSource()
    
    /** {@inheritDoc} */
    @Override
    public MediaSourceState getState() {
        final List<String> res = DcopMediaSourcePlugin.getDcopResult("dcop noatun Noatun state");
    //#NoatunSource.java:45: method: MediaSourceState com.dmdirc.addons.mediasource_dcop.NoatunSource.getState()
    //#input(MediaSourceState getState()): com/dmdirc/addons/nowplaying/MediaSourceState.CLOSED
    //#input(MediaSourceState getState()): com/dmdirc/addons/nowplaying/MediaSourceState.NOTKNOWN
    //#input(MediaSourceState getState()): com/dmdirc/addons/nowplaying/MediaSourceState.PAUSED
    //#input(MediaSourceState getState()): com/dmdirc/addons/nowplaying/MediaSourceState.PLAYING
    //#input(MediaSourceState getState()): com/dmdirc/addons/nowplaying/MediaSourceState.STOPPED
    //#output(MediaSourceState getState()): return_value
    //#presumption(MediaSourceState getState()): com.dmdirc.plugins.ExportedService:execute(...)@61 != null
    //#presumption(MediaSourceState getState()): java.util.List:get(...)@47 != null
    //#post(MediaSourceState getState()): return_value in Addr_Set{&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#1),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#2),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#3),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#4),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#5)}
    //#unanalyzed(MediaSourceState getState()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getPluginManager
    //#unanalyzed(MediaSourceState getState()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getExportedService
    //#unanalyzed(MediaSourceState getState()): Effects-of-calling:com.dmdirc.plugins.ExportedService:execute
    //#test_vector(MediaSourceState getState()): java.lang.Integer:parseInt(...)@49: {0}, {1}, {2}, {-2_147_483_648..-1, 3..4_294_967_295}
    //#test_vector(MediaSourceState getState()): java.util.List:size(...)@46: {-2_147_483_648..0}, {1..4_294_967_295}
        if (res.size() > 0) {
            final String result = res.get(0).trim();
            try {
                final int status = (Integer.parseInt(result));
                switch (status) {
                    case 0:
                        return MediaSourceState.STOPPED;
                    case 1:
                        return MediaSourceState.PAUSED;
                    case 2:
                        return MediaSourceState.PLAYING;
                    default:
                        return MediaSourceState.NOTKNOWN;
                }
            } catch (NumberFormatException nfe) {
                return MediaSourceState.CLOSED;
            }
        } else {
            return MediaSourceState.CLOSED;
    //#NoatunSource.java:64: end of method: MediaSourceState com.dmdirc.addons.mediasource_dcop.NoatunSource.getState()
        }
    }
    
    /** {@inheritDoc} */
    @Override
    public String getAppName() {
        return "Noatun";
    //#NoatunSource.java:71: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getAppName()
    //#output(String getAppName()): return_value
    //#post(String getAppName()): return_value == &"Noatun"
    //#NoatunSource.java:71: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getAppName()
    }
    
    /** {@inheritDoc} */
    @Override
    public String getArtist() {
        final String result = DcopMediaSourcePlugin.getDcopResult(
    //#NoatunSource.java:77: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getArtist()
    //#output(String getArtist()): java.lang.String:substring(...)._tainted
    //#output(String getArtist()): return_value
    //#new obj(String getArtist()): java.lang.String:substring(...)
    //#presumption(String getArtist()): com.dmdirc.plugins.ExportedService:execute(...)@61 != null
    //#presumption(String getArtist()): java.util.List:get(...)@77 != null
    //#post(String getArtist()): java.lang.String:substring(...)._tainted == 0
    //#post(String getArtist()): return_value in Addr_Set{&java.lang.String:substring(...),&""}
    //#unanalyzed(String getArtist()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getPluginManager
    //#unanalyzed(String getArtist()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getExportedService
    //#unanalyzed(String getArtist()): Effects-of-calling:com.dmdirc.plugins.ExportedService:execute
    //#test_vector(String getArtist()): java.lang.String:indexOf(...)@79: {-2_147_483_648..-2, 0..4_294_967_295}, {-1}
                "dcop noatun Noatun title").get(0);
        if (result.indexOf(" - ") == -1) {
            return "";
        }
        return result.substring(0, result.indexOf(" - "));
    //#NoatunSource.java:82: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getArtist()
    }

    /** {@inheritDoc} */
    @Override
    public String getTitle() {
        final String result = DcopMediaSourcePlugin.getDcopResult(
    //#NoatunSource.java:88: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getTitle()
    //#output(String getTitle()): java.lang.String:substring(...)._tainted
    //#output(String getTitle()): return_value
    //#new obj(String getTitle()): java.lang.String:substring(...)
    //#presumption(String getTitle()): com.dmdirc.plugins.ExportedService:execute(...)@61 != null
    //#presumption(String getTitle()): java.lang.String:indexOf(...)@93 <= 4_294_967_292
    //#presumption(String getTitle()): java.util.List:get(...)@88 != null
    //#post(String getTitle()): java.lang.String:substring(...)._tainted == 0
    //#post(String getTitle()): return_value in Addr_Set{&java.lang.String:substring(...),&""}
    //#unanalyzed(String getTitle()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getPluginManager
    //#unanalyzed(String getTitle()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getExportedService
    //#unanalyzed(String getTitle()): Effects-of-calling:com.dmdirc.plugins.ExportedService:execute
    //#test_vector(String getTitle()): java.lang.String:indexOf(...)@90: {-2_147_483_648..-2, 0..4_294_967_295}, {-1}
                "dcop noatun Noatun title").get(0);
        if (result.indexOf(" - ") == -1) {
            return "";
        }
        return result.substring(result.indexOf(" - ") + 3, result.length());
    //#NoatunSource.java:93: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getTitle()
    }

    /** {@inheritDoc} */
    @Override
    public String getAlbum() {
        return null;
    //#NoatunSource.java:99: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getAlbum()
    //#output(String getAlbum()): return_value
    //#post(String getAlbum()): return_value == null
    //#NoatunSource.java:99: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getAlbum()
    }

    /** {@inheritDoc} */
    @Override
    public String getLength() {
        return DcopMediaSourcePlugin.getDcopResult(
    //#NoatunSource.java:105: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getLength()
    //#output(String getLength()): return_value
    //#presumption(String getLength()): com.dmdirc.plugins.ExportedService:execute(...)@61 != null
    //#post(String getLength()): init'ed(return_value)
    //#unanalyzed(String getLength()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getPluginManager
    //#unanalyzed(String getLength()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getExportedService
    //#unanalyzed(String getLength()): Effects-of-calling:com.dmdirc.plugins.ExportedService:execute
    //#NoatunSource.java:105: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getLength()
                "dcop noatun Noatun lengthString").get(0);
    }

    /** {@inheritDoc} */
    @Override
    public String getTime() {
        return duration(Integer.parseInt(DcopMediaSourcePlugin.getDcopResult(
    //#NoatunSource.java:112: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getTime()
    //#input(String getTime()): ":"._tainted
    //#input(String getTime()): this
    //#output(String getTime()): java.lang.StringBuilder:toString(...)._tainted
    //#output(String getTime()): return_value
    //#new obj(String getTime()): java.lang.StringBuilder:toString(...)
    //#presumption(String getTime()): com.dmdirc.plugins.ExportedService:execute(...)@61 != null
    //#post(String getTime()): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(String getTime()): return_value == &java.lang.StringBuilder:toString(...)
    //#unanalyzed(String getTime()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getPluginManager
    //#unanalyzed(String getTime()): Effects-of-calling:com.dmdirc.plugins.PluginManager:getExportedService
    //#unanalyzed(String getTime()): Effects-of-calling:com.dmdirc.plugins.ExportedService:execute
    //#unanalyzed(String getTime()): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(String getTime()): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(String getTime()): Effects-of-calling:java.lang.StringBuilder:toString
    //#NoatunSource.java:112: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getTime()
                "dcop noatun Noatun position").get(0)) /1000);
    }

    /** {@inheritDoc} */
    @Override
    public String getFormat() {
        return null;
    //#NoatunSource.java:119: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getFormat()
    //#output(String getFormat()): return_value
    //#post(String getFormat()): return_value == null
    //#NoatunSource.java:119: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getFormat()
    }

    /** {@inheritDoc} */
    @Override
    public String getBitrate() {
        return null;
    //#NoatunSource.java:125: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getBitrate()
    //#output(String getBitrate()): return_value
    //#post(String getBitrate()): return_value == null
    //#NoatunSource.java:125: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.getBitrate()
    }
    
    /**
     * Get the duration in seconds as a string.
     *
     * @param secondsInput to get duration for
     *
     * @return Duration as a string
     */
    private String duration(final long secondsInput) {
        final StringBuilder result = new StringBuilder();
    //#NoatunSource.java:136: method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.duration(long)
    //#input(String duration(long)): ":"._tainted
    //#input(String duration(long)): secondsInput
    //#output(String duration(long)): java.lang.StringBuilder:toString(...)._tainted
    //#output(String duration(long)): return_value
    //#new obj(String duration(long)): java.lang.StringBuilder:toString(...)
    //#post(String duration(long)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(String duration(long)): return_value == &java.lang.StringBuilder:toString(...)
    //#test_vector(String duration(long)): secondsInput: {-9_223_372_036_854_775_808..3_599}, {3_600..18_446_744_073_709_551_615}
    //#test_vector(String duration(long)): secondsInput/3_600: {-2_562_047_788_015_215..0}, {1..5_124_095_576_030_431}
    //#test_vector(String duration(long)): secondsInput/60: {-153_722_867_280_912_930..59}, {60..307_445_734_561_825_860}
        final long hours = secondsInput / 3600;
        final long minutes = secondsInput / 60 % 60;
        final long seconds = secondsInput % 60;
        
        if (hours > 0) { 
            result.append(hours).append(":");
        }
        
        result.append(minutes).append(":");
        result.append(seconds).append(":");
        
        return result.toString();
    //#NoatunSource.java:148: end of method: String com.dmdirc.addons.mediasource_dcop.NoatunSource.duration(long)
    }
    
}
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource]
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.duration(J)Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getAlbum()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getAppName()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getArtist()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getBitrate()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getFormat()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getLength()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getState()Lcom/dmdirc/addons/nowplaying/MediaSourceState;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getTime()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getTitle()Ljava/lang/String;
    //#output(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource]
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource] == &__Dispatch_Table
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource] == &__Dispatch_Table
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.duration(J)Ljava/lang/String; == &duration
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getAlbum()Ljava/lang/String; == &getAlbum
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getAppName()Ljava/lang/String; == &getAppName
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getArtist()Ljava/lang/String; == &getArtist
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getBitrate()Ljava/lang/String; == &getBitrate
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getFormat()Ljava/lang/String; == &getFormat
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getLength()Ljava/lang/String; == &getLength
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getState()Lcom/dmdirc/addons/nowplaying/MediaSourceState; == &getState
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getTime()Ljava/lang/String; == &getTime
    //#post(com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init): __Dispatch_Table.getTitle()Ljava/lang/String; == &getTitle
    //#NoatunSource.java:: end of method: com.dmdirc.addons.mediasource_dcop.NoatunSource.com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init
    //#NoatunSource.java:: end of class: com.dmdirc.addons.mediasource_dcop.NoatunSource
