home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / audio-video / songbird / Songbird_0.3_windows-i686.exe / components / sbLibraryUtils.jsm < prev    next >
Text File  |  2007-10-27  |  2KB  |  103 lines

  1. /*
  2. //
  3. // BEGIN SONGBIRD GPL
  4. //
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2007 POTI, Inc.
  8. // http://songbirdnest.com
  9. //
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. //
  13. // Software distributed under the License is distributed
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
  15. // express or implied. See the GPL for the specific language
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc.,
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. //
  23. // END SONGBIRD GPL
  24. //
  25. */
  26.  
  27. EXPORTED_SYMBOLS = ["BatchHelper", "MultiBatchHelper"];
  28.  
  29. function BatchHelper() {
  30.   this._depth = 0;
  31. }
  32.  
  33. BatchHelper.prototype.begin =
  34. function BatchHelper_begin()
  35. {
  36.   this._depth++;
  37. }
  38.  
  39. BatchHelper.prototype.end =
  40. function BatchHelper_end()
  41. {
  42.   this._depth--;
  43.   if (this._depth < 0) {
  44.     throw new Error("Invalid batch depth!");
  45.   }
  46. }
  47.  
  48. BatchHelper.prototype.depth =
  49. function BatchHelper_depth()
  50. {
  51.   return this._depth;
  52. }
  53.  
  54. BatchHelper.prototype.isActive =
  55. function BatchHelper_isActive()
  56. {
  57.   return this._depth > 0;
  58. }
  59.  
  60. function MultiBatchHelper() {
  61.   this._libraries = {};
  62. }
  63.  
  64. MultiBatchHelper.prototype.get =
  65. function MultiBatchHelper_get(aLibrary)
  66. {
  67.   var batch = this._libraries[aLibrary.guid];
  68.   if (!batch) {
  69.     batch = new BatchHelper();
  70.     this._libraries[aLibrary.guid] = batch;
  71.   }
  72.   return batch;
  73. }
  74.  
  75. MultiBatchHelper.prototype.begin =
  76. function MultiBatchHelper_begin(aLibrary)
  77. {
  78.   var batch = this.get(aLibrary);
  79.   batch.begin();
  80. }
  81.  
  82. MultiBatchHelper.prototype.end =
  83. function MultiBatchHelper_end(aLibrary)
  84. {
  85.   var batch = this.get(aLibrary);
  86.   batch.end();
  87. }
  88.  
  89. MultiBatchHelper.prototype.depth =
  90. function MultiBatchHelper_depth(aLibrary)
  91. {
  92.   var batch = this.get(aLibrary);
  93.   return batch.depth();
  94. }
  95.  
  96. MultiBatchHelper.prototype.isActive =
  97. function MultiBatchHelper_isActive(aLibrary)
  98. {
  99.   var batch = this.get(aLibrary);
  100.   return batch.isActive();
  101. }
  102.  
  103.