home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbMetadataLookupJob.js < prev    next >
Text File  |  2012-06-08  |  4KB  |  119 lines

  1. /*
  2.  *=BEGIN SONGBIRD GPL
  3.  *
  4.  * This file is part of the Songbird web player.
  5.  *
  6.  * Copyright(c) 2005-2009 POTI, Inc.
  7.  * http://www.songbirdnest.com
  8.  *
  9.  * This file may be licensed under the terms of of the
  10.  * GNU General Public License Version 2 (the "GPL").
  11.  *
  12.  * Software distributed under the License is distributed
  13.  * on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
  14.  * express or implied. See the GPL for the specific language
  15.  * governing rights and limitations.
  16.  *
  17.  * You should have received a copy of the GPL along with this
  18.  * program. If not, go to http://www.gnu.org/licenses/gpl.html
  19.  * or write to the Free Software Foundation, Inc.,
  20.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21.  *
  22.  *=END SONGBIRD GPL
  23.  */
  24.  
  25. const Cc = Components.classes;
  26. const Ci = Components.interfaces;
  27. const Cr = Components.results;
  28. const Ce = Components.Exception;
  29. const Cu = Components.utils;
  30.  
  31. // Timeout a job after 30s
  32. const JOB_TIMEOUT = 30;
  33.  
  34. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
  35. Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
  36. Cu.import("resource://app/jsmodules/WindowUtils.jsm");
  37. Cu.import("resource://app/jsmodules/SBTimer.jsm");
  38. Cu.import("resource://app/jsmodules/SBJobUtils.jsm");
  39.  
  40. function sbMLJob() {
  41.   SBJobUtils.JobBase.call(this);
  42.  
  43.   // where we'll be storing our results
  44.   this._mlResults = [];
  45.  
  46.   // our timeout counter
  47.   this._mlJobTimeoutTimer = Cc["@mozilla.org/timer;1"]
  48.                               .createInstance(Ci.nsITimer);
  49. }
  50.  
  51. sbMLJob.prototype = {
  52.   __proto__: SBJobUtils.JobBase.prototype,
  53.  
  54.   classDescription : 'Songbird Metadata Lookup Job Implementation',
  55.   classID          : Components.ID("e4fd9496-1dd1-11b2-93ca-d33e8cc507ba"),
  56.   contractID       : "@songbirdnest.com/Songbird/MetadataLookup/job;1",
  57.   QueryInterface   : XPCOMUtils.generateQI(
  58.       [Ci.sbIMetadataLookupJob, Ci.sbIJobProgress, Ci.sbIJobCancelable, 
  59.        Ci.sbIJobProgressListener, Ci.nsIClassInfo, Ci.nsITimerCallback]),
  60.  
  61.   _mlNumResults        : 0,
  62.   _mlJobType           : Ci.sbIMetadataLookupJob.JOB_DISC_LOOKUP,
  63.   _mlJobTimedOut       : false,
  64.  
  65.   /** sbIMetadataLookupJob **/
  66.   get mlJobType() {
  67.     return this._mlJobType;
  68.   },
  69.  
  70.   get mlNumResults() {
  71.     return this._mlNumResults;
  72.   },
  73.  
  74.   init: function(jobType, status) {
  75.     this._mlJobType = jobType;
  76.     this._status = status;
  77.  
  78.     // start our timer
  79.     this._mlJobTimeoutTimer.initWithCallback(this, JOB_TIMEOUT*1000,
  80.                                              Ci.nsITimer.TYPE_ONE_SHOT);
  81.   },
  82.  
  83.   appendResult: function(album) {
  84.     this._mlResults.push(album);
  85.     this._mlNumResults++;
  86.   },
  87.  
  88.   changeStatus: function(status) {
  89.     if (this._mlJobTimedOut) {
  90.       Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService)
  91.          .logStringMessage("Attempted to change status on an " +
  92.                            "already timed out lookup job.");
  93.       return;
  94.     }
  95.     this._status = status;
  96.     this.notifyJobProgressListeners();
  97.     if (this._mlJobTimeoutTimer)
  98.       this._mlJobTimeoutTimer.cancel();
  99.   },
  100.  
  101.   getMetadataResults: function() {
  102.     return ArrayConverter.enumerator(this._mlResults);
  103.   },
  104.  
  105.   /** nsITimerCallback **/
  106.   notify: function(timer) {
  107.     // only timeout if we're still running
  108.     if (this.status == Ci.sbIMetadataLookupJob.STATUS_RUNNING) {
  109.       // set our status to indicate we've failed
  110.       this.changeStatus(Ci.sbIMetadataLookupJob.STATUS_FAILED);
  111.       this._mlJobTimedOut = true;
  112.     }
  113.   }
  114. }
  115.  
  116. function NSGetModule(compMgr, fileSpec) {
  117.   return XPCOMUtils.generateModule([sbMLJob]);
  118. }
  119.