File Source: KaffeineSource.java

         /* 
    P/P   *  Method: com.dmdirc.addons.mediasource_dcop.KaffeineSource__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     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.mediasource_dcop;
    24  
    25  import com.dmdirc.addons.nowplaying.MediaSource;
    26  import com.dmdirc.addons.nowplaying.MediaSourceState;
    27  
    28  import java.util.List;
    29  
    30  /**
    31   * Uses DCOP to retrieve now playing info from Kaffeine.
    32   *
    33   * @author chris
    34   */
    35  public class KaffeineSource implements MediaSource {
    36      
    37      /** Instantiates the media source. */
             /* 
    P/P       *  Method: void com.dmdirc.addons.mediasource_dcop.KaffeineSource()
              */
    38      public KaffeineSource() {
    39          //Do nothing
    40      }
    41      
    42      /** {@inheritDoc} */
    43      @Override
    44      public MediaSourceState getState() {
                 /* 
    P/P           *  Method: MediaSourceState getState()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    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#4)}
                  * 
                  *  Test Vectors:
                  *    java.lang.Boolean:parseBoolean(...)@48: {0}, {1}
                  *    java.util.List:size(...)@46: {-231..0}, {1..232-1}
                  */
    45          final List<String> res = DcopMediaSourcePlugin.getDcopResult("dcop kaffeine KaffeineIface isPlaying");
    46          if (res.size() > 0) {
    47              final String result = res.get(0);
    48              if (Boolean.parseBoolean(result)) {
    49                  return MediaSourceState.PLAYING;
    50              } else {
    51                  return MediaSourceState.CLOSED;
    52              }
    53          } else {
    54              return MediaSourceState.CLOSED;
    55          }
    56      }
    57      
    58      /** {@inheritDoc} */
    59      @Override
    60      public String getAppName() {
                 /* 
    P/P           *  Method: String getAppName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"Kaffeine"
                  */
    61          return "Kaffeine";
    62      }
    63      
    64      /** {@inheritDoc} */
    65      @Override
    66      public String getArtist() {
                 /* 
    P/P           *  Method: String getArtist()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    67          return DcopMediaSourcePlugin.getDcopResult(
    68                  "dcop kaffeine KaffeineIface artist").get(0);
    69      }
    70  
    71      /** {@inheritDoc} */
    72      @Override
    73      public String getTitle() {
                 /* 
    P/P           *  Method: String getTitle()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    74          return DcopMediaSourcePlugin.getDcopResult(
    75                  "dcop kaffeine KaffeineIface title").get(0);
    76      }
    77  
    78      /** {@inheritDoc} */
    79      @Override
    80      public String getAlbum() {
                 /* 
    P/P           *  Method: String getAlbum()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    81          return DcopMediaSourcePlugin.getDcopResult(
    82                  "dcop kaffeine KaffeineIface album").get(0);
    83      }
    84  
    85      /** {@inheritDoc} */
    86      @Override
    87      public String getLength() {
                 /* 
    P/P           *  Method: String getLength()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
    88          return duration(Integer.parseInt(DcopMediaSourcePlugin.getDcopResult(
    89                  "dcop kaffeine KaffeineIface getLength").get(0)));
    90      }
    91  
    92      /** {@inheritDoc} */
    93      @Override
    94      public String getTime() {
                 /* 
    P/P           *  Method: String getTime()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
    95          return duration(Integer.parseInt(DcopMediaSourcePlugin.getDcopResult(
    96                  "dcop kaffeine KaffeineIface getTimePos").get(0)));
    97      }
    98  
    99      /** {@inheritDoc} */
   100      @Override
   101      public String getFormat() {
                 /* 
    P/P           *  Method: String getFormat()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
   102          return null;
   103      }
   104  
   105      /** {@inheritDoc} */
   106      @Override
   107      public String getBitrate() {
                 /* 
    P/P           *  Method: String getBitrate()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
   108          return null;
   109      }
   110      
   111      /**
   112       * Get the duration in seconds as a string.
   113       *
   114       * @param secondsInput to get duration for
   115       *
   116       * @return Duration as a string
   117       */
   118      private String duration(final long secondsInput) {
                 /* 
    P/P           *  Method: String duration(long)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  * 
                  *  Test Vectors:
                  *    (secondsInput/60)%60: {10..59}, {-59..9}
                  *    secondsInput: {-263..3_599}, {36_000..264-1}, {3_600..35_999}
                  *    secondsInput%60: {10..59}, {-59..9}
                  *    secondsInput/3_600: {-2_562_047_788_015_215..0}, {10..5_124_095_576_030_431}, {1..9}
                  *    secondsInput/60: {-153_722_867_280_912_930..59}, {600..307_445_734_561_825_860}, {60..599}
                  */
   119          final StringBuilder result = new StringBuilder();
   120          final long hours = secondsInput / 3600;
   121          final long minutes = secondsInput / 60 % 60;
   122          final long seconds = secondsInput % 60;
   123          
   124          if (hours > 0) {
   125              if (hours < 10) {
   126                  result.append('0');
   127              }
   128  
   129              result.append(hours).append(":");
   130          }
   131  
   132          if (minutes < 10) {
   133              result.append('0');
   134          }
   135          
   136          result.append(minutes).append(":");
   137  
   138          if (seconds < 10) {
   139              result.append('0');
   140          }
   141  
   142          result.append(seconds);
   143          
   144          return result.toString();
   145      }
   146      
   147  }








SofCheck Inspector Build Version : 2.17854
KaffeineSource.java 2009-Jun-25 01:54:24
KaffeineSource.class 2009-Sep-02 17:04:15