firstRuniTunes.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 //
38 // First-run wizard iTunes import/export widget services.
39 //
40 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
42 
43 //------------------------------------------------------------------------------
44 //
45 // First-run wizard iTunes import/export widget imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Songbird imports.
50 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
51 
52 
53 //------------------------------------------------------------------------------
54 //
55 // First-run wizard iTunes import/export widget services defs.
56 //
57 //------------------------------------------------------------------------------
58 
59 // Component manager defs.
60 if (typeof(Cc) == "undefined")
61  var Cc = Components.classes;
62 if (typeof(Ci) == "undefined")
63  var Ci = Components.interfaces;
64 if (typeof(Cr) == "undefined")
65  var Cr = Components.results;
66 if (typeof(Cu) == "undefined")
67  var Cu = Components.utils;
68 
69 
70 //------------------------------------------------------------------------------
71 //
72 // First-run wizard iTunes import/export widget services.
73 //
74 //------------------------------------------------------------------------------
75 
83 function firstRuniTunesSvc(aWidget) {
84  this._widget = aWidget;
85 }
86 
87 // Define the object.
88 firstRuniTunesSvc.prototype = {
89  // Set the constructor.
91 
92  //
93  // Widget services fields.
94  //
95  // _widget First-run wizard iTunes import/export widget.
96  // _domEventListenerSet Set of DOM event listeners.
97  // _libraryImporter Library importer object.
98  //
99 
100  _widget: null,
101  _domEventListenerSet: null,
102  _libraryImporter: null,
103 
104 
105  //----------------------------------------------------------------------------
106  //
107  // Widget services.
108  //
109  //----------------------------------------------------------------------------
110 
115  initialize: function firstRuniTunesSvc_initialize() {
116  // Get the library importer.
117  this._libraryImporter = Cc["@songbirdnest.com/Songbird/ITunesImporter;1"]
118  .getService(Ci.sbILibraryImporter);
119  },
120 
121 
126  finalize: function firstRuniTunesSvc_finalize() {
127  // Remove DOM event listeners.
128  if (this._domEventListenerSet)
129  this._domEventListenerSet.removeAll();
130  this._domEventListenerSet = null;
131 
132  // Clear object fields.
133  this._widget = null;
134  },
135 
136 
141  saveSettings: function firstRuniTunesSvc_saveSettings() {
142  // Dispatch processing of the import/export checkboxes
143  this._saveITunesSettings();
144  },
145 
146 
147 
148  //----------------------------------------------------------------------------
149  //
150  // Internal widget services.
151  //
152  //----------------------------------------------------------------------------
153 
158  _saveITunesSettings:
159  function firstRuniTunesSvc__saveITunesImportSettings() {
160  // Get the iTunes import settings.
161  var importCheckbox = this._getElement("itunes_import_checkbox");
162  var importEnabled = importCheckbox.checked;
163  var importLibraryFilePath = this._libraryImporter.libraryDefaultFilePath;
164 
165  // If we don't have a valid iTunes Library path then iTunes isn't installed
166  // and this wizard was in fact skipped, so no need to save any preferences
167  if (!importLibraryFilePath)
168  return;
169 
170  // Save the iTunes import settings.
171  Application.prefs.setValue
172  ("songbird.library_importer.library_file_path",
173  importLibraryFilePath);
174  Application.prefs.setValue("songbird.firstrun.do_import_library", true);
175  Application.prefs.setValue("songbird.library_importer.import_tracks",
176  importEnabled);
177  Application.prefs.setValue("songbird.library_importer.import_playlists",
178  importEnabled);
179 
180  // Get the iTunes export settings.
181  var exportCheckbox = this._getElement("itunes_export_checkbox");
182  var exportEnabled = exportCheckbox.checked;
183 
184  // Save the iTunes export settings.
185  Application.prefs.setValue("songbird.library_exporter.export_tracks",
186  exportEnabled);
187  Application.prefs.setValue("songbird.library_exporter.export_playlists",
188  exportEnabled);
189  Application.prefs.setValue
190  ("songbird.library_exporter.export_smartplaylists",
191  exportEnabled);
192 
193 #ifdef METRICS_ENABLED
194  // Set the selected media import type for metrics collection.
195  var metrics = Cc["@songbirdnest.com/Songbird/Metrics;1"]
196  .createInstance(Ci.sbIMetrics);
197  if (importEnabled) {
198  // Update metrics here. If the user opts not to import the iTunes
199  // library, the next firstrun wizard will take care of the case where
200  // the firstrun.mediaimport metric should be 'filescan' or 'none'
201  metrics.metricsInc("firstrun", "mediaimport", "itunes");
202  }
203 
204  if (exportEnabled) {
205  metrics.metricsInc("firstrun", "mediaexport", "itunes");
206  }
207 #endif
208 
209  },
210 
211 
221  _getElement: function firstRuniTunesSvc__getElement(aElementID) {
222  return document.getAnonymousElementByAttribute(this._widget,
223  "anonid",
224  aElementID);
225  }
226 };
227 
const Cu
function Fx prototype initialize
const Cc
var Application
Definition: sbAboutDRM.js:37
function firstRuniTunesSvc(aWidget)
DataRemote prototype constructor
return null
Definition: FeedWriter.js:1143
const Cr
const Ci